Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
mesh.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/* $Header: /Commando/Code/ww3d2/mesh.cpp 69 1/19/02 1:01p Greg_h $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D engine *
25 * *
26 * File Name : MESH.CPP *
27 * *
28 * Programmer : Greg Hjelstrom *
29 * *
30 * Start Date : 06/11/97 *
31 * *
32 * Last Update : June 12, 1997 [GH] *
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * MeshClass::MeshClass -- Constructor for MeshClass *
37 * MeshClass::MeshClass -- Copy Constructor for MeshClass *
38 * MeshClass::operator == -- assignment operator for MeshClass *
39 * MeshClass::~MeshClass -- destructor *
40 * MeshClass::Contains -- Determines whether mesh contains a (worldspace) point. *
41 * MeshClass::Free -- Releases all memory/assets in use by this mesh *
42 * MeshClass::Clone -- Creates a clone of this mesh *
43 * MeshClass::Get_Name -- returns the name of the mesh *
44 * MeshClass::Set_Name -- sets the name of this mesh *
45 * MeshClass::Get_W3D_Flags -- access to the W3D flags *
46 * MeshClass::Get_User_Text -- access to the text buffer *
47 * MeshClass::Scale -- Scales the mesh *
48 * MeshClass::Scale -- Scales the mesh *
49 * MeshClass::Init -- Init the mesh from a MeshBuilder object *
50 * MeshClass::Load -- creates a mesh out of a mesh chunk in a .w3d file *
51 * MeshClass::Cast_Ray -- compute a ray intersection with this mesh *
52 * MeshClass::Cast_AABox -- cast an AABox against this mesh *
53 * MeshClass::Cast_OBBox -- Cast an obbox against this mesh *
54 * MeshClass::Intersect_AABox -- test for intersection with given AABox *
55 * MeshClass::Intersect_OBBox -- test for intersection with the given OBBox *
56 * MeshClass::Generate_Culling_Tree -- Generates a hierarchical culling tree for the mesh *
57 * MeshClass::Direct_Load -- read the w3d file directly into this mesh object *
58 * MeshClass::read_chunks -- read all of the chunks from the .wtm file *
59 * MeshClass::read_vertices -- reads the vertex chunk *
60 * MeshClass::read_texcoords -- read in the texture coordinates chunk *
61 * MeshClass::install_texture_coordinates -- installs the given u-v's in each channel that is*
62 * MeshClass::read_vertex_normals -- reads a surrender normal chunk from the wtm file *
63 * MeshClass::read_v3_materials -- Reads in version 3 materials. *
64 * MeshClass::read_map -- Reads definition of a texture map from the file *
65 * MeshClass::read_triangles -- read the triangles chunk *
66 * MeshClass::read_per_tri_materials -- read the material indices for each triangle *
67 * MeshClass::read_user_text -- read in the user text chunk *
68 * MeshClass::read_vertex_colors -- read in the vertex colors chunk *
69 * MeshClass::read_vertex_influences -- read in the vertex influences chunk *
70 * MeshClass::Get_Material_Info -- returns a pointer to the material info *
71 * MeshClass::Create_Decal -- creates a decal on this mesh *
72 * MeshClass::Delete_Decal -- removes a decal from this mesh *
73 * MeshClass::Get_Num_Polys -- returns the number of polys (tris) in this mesh *
74 * MeshClass::Render -- renders this mesh *
75 * MeshClass::Special_Render -- special render function for meshes *
76 * MeshClass::update_skin -- deforms the mesh *
77 * MeshClass::clone_materials -- clone the materials for this mesh *
78 * MeshClass::install_materials -- transfers the materials into the mesh *
79 * MeshClass::Get_Model -- user access to the mesh model *
80 * MeshClass::Get_Obj_Space_Bounding_Sphere -- returns obj-space bounding sphere *
81 * MeshClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
82 * MeshClass::Get_Deformed_Vertices -- Gets the deformed vertices for a skin *
83 * MeshClass::Get_Deformed_Vertices -- Gets the deformed vertices for a skin *
84 * MeshClass::Render_Material_Pass -- Render a procedural material pass for this mesh *
85 * MeshClass::Replace_VertexMaterial -- Replaces existing vertex material with a new one. Wi *
86 * MeshClass::Make_Unique -- Makes mesh unique in the renderer, but still shares system ram *
87 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
88
89#include "mesh.h"
90#include <assert.h>
91#include <string.h>
92#include "w3d_file.h"
93#include "assetmgr.h"
94#include "w3derr.h"
95#include "wwdebug.h"
96#include "vertmaterial.h"
97#include "shader.h"
98#include "matinfo.h"
99#include "htree.h"
100#include "meshbuild.h"
101#include "tri.h"
102#include "aaplane.h"
103#include "aabtree.h"
104#include "chunkio.h"
105#include "w3d_util.h"
106#include "meshmdl.h"
107#include "meshgeometry.h"
108#include "ww3d.h"
109#include "camera.h"
110#include "texture.h"
111#include "rinfo.h"
112#include "coltest.h"
113#include "inttest.h"
114#include "decalmsh.h"
115#include "decalsys.h"
116#include "dx8polygonrenderer.h"
117#include "dx8indexbuffer.h"
118#include "dx8renderer.h"
119#include "visrasterizer.h"
120#include "wwmemlog.h"
121#include "dx8rendererdebugger.h"
122#include <stdio.h>
123#include <wwprofile.h>
124
125static unsigned MeshDebugIdCount;
126
128static SimpleDynVecClass<uint32> temp_apt;
129
130/*
131** This #define causes the collision code to always recompute the triangle normals rather
132** than using the ones in the model.
133** TODO: ensure that the models have unit normals and start re-using them again or write
134** collision code to handle non-unit normals!
135*/
136#if (OPTIMIZE_PLANEEQ_RAM)
137#define COMPUTE_NORMALS
138#endif
139
140
141/*
142** Temporary storage used during decal creation
143*/
144static DynamicVectorClass<Vector3> _TempVertexBuffer;
145
146
147/***********************************************************************************************
148 * MeshClass::MeshClass -- Constructor for MeshClass *
149 * *
150 * Initializes an empty mesh class *
151 * *
152 * INPUT: *
153 * *
154 * OUTPUT: *
155 * *
156 * WARNINGS: *
157 * *
158 * HISTORY: *
159 * 1/6/98 GTH : Created. *
160 *=============================================================================================*/
174
175
176/***********************************************************************************************
177 * MeshClass::MeshClass -- Copy Constructor for MeshClass *
178 * *
179 * Creates a mesh which is a copy of the given mesh *
180 * *
181 * INPUT: *
182 * *
183 * OUTPUT: *
184 * *
185 * WARNINGS: *
186 * *
187 * HISTORY: *
188 *=============================================================================================*/
190 RenderObjClass(that),
191 Model(NULL),
197 MeshDebugId(MeshDebugIdCount++),
198 m_alphaOverride(1.0f),
201{
202 REF_PTR_SET(Model,that.Model); // mesh instances share models by default
203}
204
205
206/***********************************************************************************************
207 * operator == -- assignment operator for MeshClass *
208 * *
209 * INPUT: *
210 * *
211 * OUTPUT: *
212 * *
213 * WARNINGS: *
214 * *
215 * HISTORY: *
216 * 1/6/98 GTH : Created. *
217 *=============================================================================================*/
219{
220 if (this != &that) {
221
223
224 REF_PTR_SET(Model,that.Model); // mesh instances share models by default
226
227 // just dont copy the decals or light environment
230 }
231 return * this;
232}
233
234
235/***********************************************************************************************
236 * MeshClass::~MeshClass -- destructor *
237 * *
238 * INPUT: *
239 * *
240 * OUTPUT: *
241 * *
242 * WARNINGS: *
243 * *
244 * HISTORY: *
245 * 1/6/98 GTH : Created. *
246 *=============================================================================================*/
248{
249 Free();
250}
251
252
253/***********************************************************************************************
254 * MeshClass::Contains -- Determines whether mesh contains a (worldspace) point. *
255 * *
256 * INPUT: *
257 * *
258 * OUTPUT: *
259 * *
260 * WARNINGS: Assumes mesh is a closed manifold - results are undefined otherwise *
261 * This function will NOT work for skins *
262 * *
263 * HISTORY: *
264 * 8/30/00 NH : Created. *
265 *=============================================================================================*/
266bool MeshClass::Contains(const Vector3 &point)
267{
268 // Transform point to object space and pass on to model
269 Vector3 obj_point;
271 return Model->Contains(obj_point);
272}
273
274
275/***********************************************************************************************
276 * MeshClass::Free -- Releases all memory/assets in use by this mesh *
277 * *
278 * INPUT: *
279 * *
280 * OUTPUT: *
281 * *
282 * WARNINGS: *
283 * *
284 * HISTORY: *
285 * 1/6/98 GTH : Created. *
286 *=============================================================================================*/
292
293
294/***********************************************************************************************
295 * MeshClass::Clone -- Creates a clone of this mesh *
296 * *
297 * INPUT: *
298 * *
299 * OUTPUT: *
300 * *
301 * WARNINGS: *
302 * *
303 * HISTORY: *
304 * 1/6/98 GTH : Created. *
305 *=============================================================================================*/
307{
308 return NEW_REF( MeshClass, (*this));
309}
310
311
312/***********************************************************************************************
313 * MeshClass::Get_Name -- returns the name of the mesh *
314 * *
315 * INPUT: *
316 * *
317 * OUTPUT: *
318 * *
319 * WARNINGS: *
320 * *
321 * HISTORY: *
322 * 5/15/98 GTH : Created. *
323 *=============================================================================================*/
324const char * MeshClass::Get_Name(void) const
325{
326 return Model->Get_Name();
327}
328
329
330/***********************************************************************************************
331 * MeshClass::Set_Name -- sets the name of this mesh *
332 * *
333 * INPUT: *
334 * *
335 * OUTPUT: *
336 * *
337 * WARNINGS: *
338 * *
339 * HISTORY: *
340 * 3/9/99 GTH : Created. *
341 *=============================================================================================*/
342void MeshClass::Set_Name(const char * name)
343{
344 Model->Set_Name(name);
345}
346
347/***********************************************************************************************
348 * MeshClass::Get_W3D_Flags -- access to the W3D flags *
349 * *
350 * INPUT: *
351 * *
352 * OUTPUT: *
353 * *
354 * WARNINGS: *
355 * *
356 * HISTORY: *
357 * 5/15/98 GTH : Created. *
358 *=============================================================================================*/
360{
361 return Model->W3dAttributes;
362}
363
364
365/***********************************************************************************************
366 * MeshClass::Get_User_Text -- access to the text buffer *
367 * *
368 * INPUT: *
369 * *
370 * OUTPUT: *
371 * *
372 * WARNINGS: *
373 * *
374 * HISTORY: *
375 * 5/15/98 GTH : Created. *
376 *=============================================================================================*/
377const char * MeshClass::Get_User_Text(void) const
378{
379 return Model->Get_User_Text();
380}
381
382
383/***********************************************************************************************
384 * MeshClass::Get_Material_Info -- returns a pointer to the material info *
385 * *
386 * INPUT: *
387 * *
388 * OUTPUT: *
389 * *
390 * WARNINGS: *
391 * *
392 * HISTORY: *
393 * 5/20/98 GTH : Created. *
394 *=============================================================================================*/
396{
397 if (Model) {
398 if (Model->MatInfo) {
399 Model->MatInfo->Add_Ref();
400 return Model->MatInfo;
401 }
402 }
403 return NULL;
404}
405
406
407/***********************************************************************************************
408 * MeshClass::Get_Model -- user access to the mesh model *
409 * *
410 * INPUT: *
411 * *
412 * OUTPUT: *
413 * *
414 * WARNINGS: *
415 * *
416 * HISTORY: *
417 * 2/4/99 GTH : Created. *
418 *=============================================================================================*/
420{
421 if (Model != NULL) {
422 Model->Add_Ref();
423 }
424 return Model;
425}
426
427/***********************************************************************************************
428 * MeshClass::Scale -- Scales the mesh *
429 * *
430 * INPUT: *
431 * *
432 * OUTPUT: *
433 * *
434 * WARNINGS: *
435 * *
436 * HISTORY: *
437 *=============================================================================================*/
439{
440 if (scale==1.0f) return;
441
442 Vector3 sc;
443 sc.X = sc.Y = sc.Z = scale;
444 Make_Unique();
445 Model->Make_Geometry_Unique();
446 Model->Scale(sc);
447
449
450 // Now update the object space bounding volumes of this object's container:
451 RenderObjClass *container = Get_Container();
452 if (container) container->Update_Obj_Space_Bounding_Volumes();
453}
454
455
456/***********************************************************************************************
457 * MeshClass::Scale -- Scales the mesh *
458 * *
459 * INPUT: *
460 * *
461 * OUTPUT: *
462 * *
463 * WARNINGS: *
464 * *
465 * HISTORY: *
466 * 1/6/98 GTH : Created. *
467 * 12/8/98 GTH : Modified the box scaling to use the non-uniform parameters *
468 *=============================================================================================*/
469void MeshClass::Scale(float scalex, float scaley, float scalez)
470{
471 // scale the surrender mesh model
472 Vector3 sc;
473 sc.X = scalex;
474 sc.Y = scaley;
475 sc.Z = scalez;
476 Make_Unique();
477 Model->Make_Geometry_Unique();
478 Model->Scale(sc);
479
481
482 // Now update the object space bounding volumes of this object's container:
483 RenderObjClass *container = Get_Container();
484 if (container) container->Update_Obj_Space_Bounding_Volumes();
485}
486
487
488/***********************************************************************************************
489 * MeshClass::Get_Deformed_Vertices -- Gets the deformed vertices for a skin *
490 * *
491 * INPUT: *
492 * *
493 * OUTPUT: *
494 * *
495 * WARNINGS: *
496 * *
497 * HISTORY: *
498 * 3/4/2001 gth : Created. *
499 *=============================================================================================*/
501{
503 Model->get_deformed_vertices(dst_vert,dst_norm,Container->Get_HTree());
504}
505
506
507/***********************************************************************************************
508 * MeshClass::Get_Deformed_Vertices -- Gets the deformed vertices for a skin *
509 * *
510 * INPUT: *
511 * *
512 * OUTPUT: *
513 * *
514 * WARNINGS: *
515 * *
516 * HISTORY: *
517 * 3/4/2001 gth : Created. *
518 *=============================================================================================*/
520{
523 WWASSERT(Container->Get_HTree() != NULL);
524
525 Model->get_deformed_vertices(dst_vert,Container->Get_HTree());
526}
527
528/***********************************************************************************************
529 * MeshClass::Create_Decal -- creates a decal on this mesh *
530 * *
531 * INPUT: *
532 * *
533 * OUTPUT: *
534 * *
535 * WARNINGS: *
536 * *
537 * HISTORY: *
538 * 1/26/00 gth : Created. *
539 *=============================================================================================*/
541{
543
544 if (WW3D::Are_Decals_Enabled() == false) {
545 return;
546 }
547
548 if (Is_Translucent() && (generator->Is_Applied_To_Translucent_Meshes() == false)) {
549 return;
550 }
551
552 if (!Model->Get_Flag(MeshGeometryClass::SKIN)) {
553
554 // Rigid mesh
555 Matrix3D modeltm_inv;
556 OBBoxClass localbox;
557
559 OBBoxClass::Transform(modeltm_inv, generator->Get_Bounding_Volume(), &localbox);
560
561 // generate apt, if it is not empty, add a decal.
562 temp_apt.Delete_All(false); // reset contents
563 Model->Generate_Rigid_APT(localbox, temp_apt);
564
565 if (temp_apt.Count() > 0) {
566 if (DecalMesh == NULL) {
568 }
569 DecalMesh->Create_Decal(generator, localbox, temp_apt);
570 }
571
572 } else {
573
574 WWDEBUG_SAY(("PERFORMANCE WARNING: Decal being applied to a SKIN mesh!\r\n"));
575
576 // Skin
577 // The deformed worldspace vertices are used both for the APT and in Create_Decal() to
578 // generate the texture coordinates.
579 int vertex_count = Model->Get_Vertex_Count();
580 if (_TempVertexBuffer.Count() < vertex_count) _TempVertexBuffer.Resize(vertex_count);
581 Vector3 *dst_vert = &(_TempVertexBuffer[0]);
582 Get_Deformed_Vertices(dst_vert);
583
584 // generate apt, if it is not empty, add a decal.
585 temp_apt.Delete_All(false);
586
587 OBBoxClass worldbox = generator->Get_Bounding_Volume();
588
589 // We compare the worldspace box vs. the worldspace vertices
590 Model->Generate_Skin_APT(worldbox, temp_apt, dst_vert);
591
592 // if it is not empty, add a decal
593 if (temp_apt.Count() > 0) {
594 if (DecalMesh == NULL) {
595 DecalMesh = NEW_REF(SkinDecalMeshClass, (this, generator->Peek_Decal_System()));
596 }
597 DecalMesh->Create_Decal(generator, worldbox, temp_apt, &_TempVertexBuffer);
598 }
599 }
600}
601
602
603/***********************************************************************************************
604 * MeshClass::Delete_Decal -- removes a decal from this mesh *
605 * *
606 * INPUT: *
607 * *
608 * OUTPUT: *
609 * *
610 * WARNINGS: *
611 * *
612 * HISTORY: *
613 * 1/26/00 gth : Created. *
614 *=============================================================================================*/
616{
617 if (DecalMesh != NULL) {
618 DecalMesh->Delete_Decal(decal_id);
619 }
620}
621
622
623/***********************************************************************************************
624 * MeshClass::Get_Num_Polys -- returns the number of polys (tris) in this mesh *
625 * *
626 * INPUT: *
627 * *
628 * OUTPUT: *
629 * *
630 * WARNINGS: *
631 * *
632 * HISTORY: *
633 * 1/6/98 GTH : Created. *
634 *=============================================================================================*/
636{
637 if (Model) {
638 int num_passes=Model->Get_Pass_Count();
639 WWASSERT(num_passes>0);
640 int poly_count=Model->Get_Polygon_Count();
641 return num_passes*poly_count;
642 } else {
643 return 0;
644 }
645}
646
647
648/***********************************************************************************************
649 * MeshClass::Render -- renders this mesh *
650 * *
651 * INPUT: *
652 * *
653 * OUTPUT: *
654 * *
655 * WARNINGS: *
656 * *
657 * HISTORY: *
658 * 12/10/98 GTH : Created. *
659 *=============================================================================================*/
661{
662 WWPROFILE("Mesh::Render");
663 if (Is_Not_Hidden_At_All() == false) {
664 return;
665 }
666
667 // If static sort lists are enabled and this mesh has a sort level, put it on the list instead
668 // of rendering it.
669 unsigned int sort_level = (unsigned int)Model->Get_Sort_Level();
670
672
674 //Add custom alpha
678
679 WW3D::Add_To_Static_Sort_List(this, sort_level);
680 } else {
681
682 /* Commented out since we set lighting environment only on visible meshes below. -MW
683 ** Plug in the lighting environment unless we arrived here as part of the static
684 ** sorting system being flushed
685 */
686// if (WW3D::Are_Static_Sort_Lists_Enabled()) {
687// Set_Lighting_Environment(rinfo.light_environment);
688// }
689
690 const FrustumClass & frustum=rinfo.Camera.Get_Frustum();
691
692 if ( Model->Get_Flag(MeshGeometryClass::SKIN) ||
694 {
695 bool rendered_something = false;
696
697 /*
698 ** If this mesh model has never been rendered, we need to generate the DX8 datastructures
699 */
700 if (Model->PolygonRendererList.Is_Empty()) {
701 Model->Register_For_Rendering();
702 WWASSERT(!Model->PolygonRendererList.Is_Empty());
703 }
704
705 /*
706 ** Plug in lighting
707 */
708 if (sort_level == SORT_LEVEL_NONE) //sorting ones get their environment set above.
710
711 //Add custom alpha
715 }
716
717 /*
718 ** Process texture reductions:
719 */
720// Model->Process_Texture_Reduction();
721
722 /*
723 ** Look up the FVF container that this mesh is in
724 */
725 DX8FVFCategoryContainer * fvf_container = Model->PolygonRendererList.Peek_Head()->Get_Texture_Category()->Get_Container();
726
727 /*
728 ** Check if we should render the base passes. One special case here: if
729 ** the mesh is translucent (alpha) and the base passes are disabled but we
730 ** are rendering a shadow, we go ahead and render the base pass. This is an ugly way
731 ** to get our tree shadows and other alpha textured shadows to work.
732 */
733 bool render_base_passes = ((rinfo.Current_Override_Flags() & RenderInfoClass::RINFO_OVERRIDE_ADDITIONAL_PASSES_ONLY) == 0);
734 bool is_alpha = (Model->Get_Single_Shader().Get_Alpha_Test() == ShaderClass::ALPHATEST_ENABLE) ||
735 (Model->Get_Single_Shader().Get_Src_Blend_Func() == ShaderClass::SRCBLEND_SRC_ALPHA);
736
738 (is_alpha == true))
739 {
740 render_base_passes = true;
741 }
742
743 if (render_base_passes) {
744
745 /*
746 ** Link each polygon renderer for this mesh into the visible list
747 */
748 DX8PolygonRendererListIterator it(&(Model->PolygonRendererList));
749 while (!it.Is_Done()) {
750 DX8PolygonRendererClass* polygon_renderer=it.Peek_Obj();
751 polygon_renderer->Get_Texture_Category()->Add_Render_Task(polygon_renderer,this);
752 it.Next();
753 }
754
755 rendered_something = true;
756
757 }
758
759 /*
760 ** If the rendering context specifies procedural material passes, register them
761 ** for rendering
762 */
763 for (int i=0; i<rinfo.Additional_Pass_Count(); i++) {
764
765 MaterialPassClass * matpass = rinfo.Peek_Additional_Pass(i);
766
767 if ((!Is_Translucent()) || (matpass->Is_Enabled_On_Translucent_Meshes())) {
768
769 /*
770 ** If the base pass for this mesh has been disabled, we have to make sure
771 ** the procedural material pass is rendered after everything else has rendered
772 */
774 fvf_container->Add_Delayed_Visible_Material_Pass(matpass, this);
775 } else {
776 fvf_container->Add_Visible_Material_Pass(matpass,this);
777 }
778 rendered_something = true;
779 }
780 }
781
782 /*
783 ** If we rendered any base or procedural passes and this is a skin, we need
784 ** to tell the mesh rendering system to process this skin
785 */
786 if (rendered_something && Model->Get_Flag(MeshGeometryClass::SKIN)) {
787 //WWASSERT(dynamic_cast<DX8SkinFVFCategoryContainer *>(fvf_container) != NULL);
788 static_cast<DX8SkinFVFCategoryContainer*>(fvf_container)->Add_Visible_Skin(this);
789 }
790
791 /*
792 ** If we have a decal mesh, link it into the mesh rendering system
793 */
794 if ( (DecalMesh != NULL) &&
796 {
797 const SphereClass & ws_sphere = Get_Bounding_Sphere();
798 Vector3 cam_space_sphere_center;
799 rinfo.Camera.Transform_To_View_Space(cam_space_sphere_center,ws_sphere.Center);
800 if (-cam_space_sphere_center.Z - ws_sphere.Radius < WW3D::Get_Decal_Rejection_Distance()) {
801 TheDX8MeshRenderer.Add_To_Render_List(DecalMesh);
802 }
803 }
804
806 }
807 }
808}
809
810
811/***********************************************************************************************
812 * MeshClass::Render_Material_Pass -- Render a procedural material pass for this mesh *
813 * *
814 * INPUT: *
815 * *
816 * OUTPUT: *
817 * *
818 * WARNINGS: *
819 * *
820 * HISTORY: *
821 * 3/4/2001 gth : Created. *
822 *=============================================================================================*/
824{
825 //Added to allow dynamic opacity on additional render passed
826 //without having to create a new material pass per object instance. -MW
827 float oldOpacity=-1.0f;
828 Vector3 oldEmissive(-1,-1,-1);
829
830 if (LightEnvironment != NULL) {
832 }
833
834 if (Model->Get_Flag(MeshModelClass::SKIN)) {
835
836 /*
837 ** In the case of skin meshes, we need to render our polys with the identity transform
838 */
839 if (m_materialPassAlphaOverride != 1.0f)
840 { VertexMaterialClass *mat=pass->Peek_Material();
841 if (mat)
842 {
843 oldOpacity=mat->Get_Opacity();
845 }
846 }
848 { VertexMaterialClass *mat=pass->Peek_Material();
849 if (mat)
850 {
851 mat->Get_Emissive(&oldEmissive);
853 }
854 }
855 pass->Install_Materials();
857
858 SNAPSHOT_SAY(("Set_World_Identity\n"));
860
861 DX8PolygonRendererListIterator it(&Model->PolygonRendererList);
862 while (!it.Is_Done()) {
863 if (it.Peek_Obj()->Get_Pass() == 0)
865 it.Next();
866 }
867
868 if (oldOpacity >= 0)
869 { //opacity was modified for this mesh instance, so need to restore the material setting which may be shared
870 //among other instances.
871 pass->Peek_Material()->Set_Opacity(oldOpacity);
872 }
873 if (oldEmissive.X >= 0)
874 { //emissive was modified for this mesh instance, so need to restore the material setting which may be shared
875 //among other instances.
876 pass->Peek_Material()->Set_Emissive(oldEmissive);
877 }
878 //MW: Need uninstall custom materials in case they leave D3D in unknown state
879 pass->UnInstall_Materials();
880
882
883 /*
884 ** Generate the APT
885 */
886 temp_apt.Delete_All(false);
887
888 Matrix3D modeltminv;
890
891 OBBoxClass localbox;
892 OBBoxClass::Transform(modeltminv,*(pass->Get_Cull_Volume()),&localbox);
893
894 Vector3 view_dir;
895 localbox.Basis.Get_Z_Vector(&view_dir);
896 view_dir = -view_dir;
897
898 if (Model->Has_Cull_Tree()) {
899 Model->Generate_Rigid_APT(localbox,view_dir,temp_apt);
900 } else {
901 Model->Generate_Rigid_APT(view_dir,temp_apt);
902 }
903
904 if (temp_apt.Count() > 0) {
905
906 int buftype = BUFFER_TYPE_DYNAMIC_DX8;
909 }
910
911 /*
912 ** Spew triangles in the APT into the dynamic index buffer
913 */
914 int min_v = Model->Get_Vertex_Count();
915 int max_v = 0;
916
917 DynamicIBAccessClass dynamic_ib(buftype,temp_apt.Count() * 3);
918 {
919 DynamicIBAccessClass::WriteLockClass lock(&dynamic_ib);
920 unsigned short * indices = lock.Get_Index_Array();
921 const TriIndex * polys = Model->Get_Polygon_Array();
922 try {
923 for (int i=0; i < temp_apt.Count(); i++)
924 {
925 unsigned v0 = polys[temp_apt[i]].I;
926 unsigned v1 = polys[temp_apt[i]].J;
927 unsigned v2 = polys[temp_apt[i]].K;
928
929 indices[i*3 + 0] = (unsigned short)v0;
930 indices[i*3 + 1] = (unsigned short)v1;
931 indices[i*3 + 2] = (unsigned short)v2;
932
933 min_v = WWMath::Min(v0,min_v);
934 min_v = WWMath::Min(v1,min_v);
935 min_v = WWMath::Min(v2,min_v);
936
937 max_v = WWMath::Max(v0,max_v);
938 max_v = WWMath::Max(v1,max_v);
939 max_v = WWMath::Max(v2,max_v);
940 }
942 } catch(...) {
944 }
945 }
946
947 /*
948 ** Render
949 */
950 int vertex_offset = Model->PolygonRendererList.Peek_Head()->Get_Vertex_Offset();
951 pass->Install_Materials();
952
954 DX8Wrapper::Set_Index_Buffer(dynamic_ib,vertex_offset);
955
957 0,
958 temp_apt.Count(),
959 min_v,
960 max_v-min_v+1);
961 //MW: Need uninstall custom materials in case they leave D3D in unknown state
962 pass->UnInstall_Materials();
963 }
964 } else {
965
966 /*
967 ** Normal mesh case, render polys with this mesh's transform
968 */
969 if (m_materialPassAlphaOverride != 1.0f)
970 { VertexMaterialClass *mat=pass->Peek_Material();
971 if (mat)
972 {
973 oldOpacity=mat->Get_Opacity();
975 }
976 }
978 { VertexMaterialClass *mat=pass->Peek_Material();
979 if (mat)
980 {
981 mat->Get_Emissive(&oldEmissive);
983 }
984 }
985 pass->Install_Materials();
987
988 SNAPSHOT_SAY(("Set_World_Transform\n"));
990
991 DX8PolygonRendererListIterator it(&Model->PolygonRendererList);
992 while (!it.Is_Done()) {
993
994 if (it.Peek_Obj()->Get_Pass() == 0)
996 it.Next();
997 }
998
999 if (oldOpacity >= 0)
1000 { //opacity was modified for this mesh instance, so need to restore the material setting which may be shared
1001 //among other instances.
1002 pass->Peek_Material()->Set_Opacity(oldOpacity);
1003 }
1004 if (oldEmissive.X >= 0)
1005 { //emissive was modified for this mesh instance, so need to restore the material setting which may be shared
1006 //among other instances.
1007 pass->Peek_Material()->Set_Emissive(oldEmissive);
1008 }
1009 //MW: Need uninstall custom materials in case they leave D3D in unknown state
1010 pass->UnInstall_Materials();
1011 }
1012}
1013
1014
1015/***********************************************************************************************
1016 * MeshClass::Special_Render -- special render function for meshes *
1017 * *
1018 * INPUT: *
1019 * *
1020 * OUTPUT: *
1021 * *
1022 * WARNINGS: *
1023 * *
1024 * HISTORY: *
1025 * 12/10/98 GTH : Created. *
1026 *=============================================================================================*/
1028{
1030 return;
1031 }
1032
1034
1035 WWASSERT(rinfo.VisRasterizer != NULL);
1037
1038 if (Model->Get_Flag(MeshModelClass::SKIN) == 0) {
1039
1041 rinfo.VisRasterizer->Render_Triangles( Model->Get_Vertex_Array(),
1042 Model->Get_Vertex_Count(),
1043 Model->Get_Polygon_Array(),
1044 Model->Get_Polygon_Count(),
1045 Get_Bounding_Box() );
1046 } else {
1047
1048 int vertex_count = Model->Get_Vertex_Count();
1049 if (_TempVertexBuffer.Count() < vertex_count) _TempVertexBuffer.Resize(vertex_count);
1050 Vector3 *dst_vert = &(_TempVertexBuffer[0]);
1051 Get_Deformed_Vertices(dst_vert);
1052
1054 rinfo.VisRasterizer->Render_Triangles( dst_vert,
1055 Model->Get_Vertex_Count(),
1056 Model->Get_Polygon_Array(),
1057 Model->Get_Polygon_Count(),
1058 Get_Bounding_Box() );
1059 }
1061 }
1062
1064 const HTreeClass * htree = NULL;
1065 if (Container!=NULL) {
1066 htree = Container->Get_HTree();
1067 }
1068 Model->Shadow_Render(rinfo,Transform,htree);
1069 }
1070}
1071
1073{
1074 Model->Replace_Texture(texture,new_texture);
1075}
1076
1077
1078/***********************************************************************************************
1079 * MeshClass::Replace_VertexMaterial -- Replaces existing vertex material with a new one. Will *
1080 * *
1081 * *
1082 * *
1083 * *
1084 * INPUT: *
1085 * *
1086 * OUTPUT: *
1087 * *
1088 * WARNINGS: *
1089 * *
1090 * HISTORY: *
1091 * 4/2/2001 hy : Created. *
1092 *=============================================================================================*/
1094{
1095 Model->Replace_VertexMaterial(vmat,new_vmat);
1096}
1097
1098
1099/***********************************************************************************************
1100 * MeshClass::Make_Unique -- Makes mesh unique in the renderer, but still shares system ram ge *
1101 * *
1102 * *
1103 * *
1104 * *
1105 * INPUT: *
1106 * *
1107 * OUTPUT: *
1108 * *
1109 * WARNINGS: *
1110 * *
1111 * HISTORY: *
1112 * 4/2/2001 hy : Created. *
1113 *=============================================================================================*/
1114void MeshClass::Make_Unique(bool force_meshmdl_clone)
1115{
1116 // Usually we will not clone the mesh model if it is already unique - force_meshmdl_clone will
1117 // force it to be cloned in any case. This is used in some special situations, for example if we
1118 // want to change this mesh and it may have already been rendered, we need to clone the mesh
1119 // model regardless of whether there is another mesh using it.
1120 if (Model->Num_Refs()==1 && !force_meshmdl_clone) return;
1121
1123 REF_PTR_SET(Model,newmesh);
1124 REF_PTR_RELEASE(newmesh);
1125}
1126
1127/***********************************************************************************************
1128 * MeshClass::Load -- creates a mesh out of a mesh chunk in a .w3d file *
1129 * *
1130 * INPUT: *
1131 * *
1132 * OUTPUT: *
1133 * *
1134 * WARNINGS: *
1135 * *
1136 * HISTORY: *
1137 * 06/12/1997 GH : Created. *
1138 *=============================================================================================*/
1140{
1141 Vector3 boxmin,boxmax;
1142
1143 /*
1144 ** Make sure this mesh is "empty"
1145 */
1146 Free();
1147
1148 /*
1149 ** Create empty MaterialInfo and Model
1150 */
1152 if (Model == NULL) {
1153 WWDEBUG_SAY(("MeshClass::Load - Failed to allocate model\r\n"));
1155 }
1156
1157 /*
1158 ** Create and read in the model...
1159 */
1160 if (Model->Load_W3D(cload) != WW3D_ERROR_OK) {
1161 Free();
1163 }
1164
1165 /*
1166 ** Pull interesting stuff out of the w3d attributes bits
1167 */
1169 Set_Collision_Type( col_bits << 1 );
1170 Set_Hidden(Model->W3dAttributes & W3D_MESH_FLAG_HIDDEN);
1171
1172 /*
1173 ** Indicate whether this mesh is translucent. The mesh is considered translucent
1174 ** if sorting has been enabled (alpha blending on pass 0) or if pass0 contains alpha-test.
1175 ** This flag is mainly being used by visibility preprocessing code in Renegade.
1176 */
1177 int is_translucent = Model->Get_Flag(MeshModelClass::SORT);
1178 int is_alpha = 0; //keep track of alpha pieces that require sorting (including static sort lists).
1179 int is_additive = 0;
1180 if (Model->Has_Shader_Array(0)) {
1181 for (int i=0; i<Model->Get_Polygon_Count(); i++) {
1182 ShaderClass shader = Model->Get_Shader(i,0);
1183 is_translucent |= (shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_ENABLE);
1184 is_alpha |= (shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO ||
1186 is_additive |= (shader.Get_Dst_Blend_Func() == ShaderClass::DSTBLEND_ONE &&
1188 }
1189 } else {
1190 ShaderClass shader = Model->Get_Single_Shader(0);
1191 is_translucent |= (shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_ENABLE);
1192 is_alpha |= (shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO ||
1194 is_additive |= (shader.Get_Dst_Blend_Func() == ShaderClass::DSTBLEND_ONE &&
1196 }
1197 Set_Translucent(is_translucent);
1198 Set_Alpha(is_alpha);
1199 Set_Additive(is_additive);
1200
1201 return WW3D_ERROR_OK;
1202
1203}
1204
1205
1206/***********************************************************************************************
1207 * MeshClass::Cast_Ray -- compute a ray intersection with this mesh *
1208 * *
1209 * INPUT: *
1210 * *
1211 * OUTPUT: *
1212 * *
1213 * WARNINGS: *
1214 * *
1215 * HISTORY: *
1216 * 6/17/98 GTH : Created. *
1217 *=============================================================================================*/
1219{
1220 if ((Get_Collision_Type() & raytest.CollisionType) == 0) return false;
1221 //Modified for 'Generals' so we could select trees but filter out headlight beams, etc. -MW
1222 if (raytest.CheckTranslucent && Is_Alpha()!=0)
1223 return false;
1224 if (Is_Hidden() && !raytest.CheckHidden) return false;
1225 if (Is_Animation_Hidden()) return false;
1226 if (raytest.Result->StartBad) return false;
1227
1228 Matrix3D world_to_obj;
1229 Matrix3D world=Get_Transform();
1230
1231 // if aligned or oriented rotate the mesh so that it's aligned to the ray
1232 if (Model->Get_Flag(MeshModelClass::ALIGNED)) {
1233 Vector3 mesh_position;
1234 world.Get_Translation(&mesh_position);
1235 world.Obj_Look_At(mesh_position,mesh_position - raytest.Ray.Get_Dir(),0.0f);
1236 } else if (Model->Get_Flag(MeshModelClass::ORIENTED)) {
1237 Vector3 mesh_position;
1238 world.Get_Translation(&mesh_position);
1239 world.Obj_Look_At(mesh_position,raytest.Ray.Get_P0(),0.0f);
1240 }
1241
1242 world.Get_Inverse(world_to_obj);
1243 RayCollisionTestClass objray(raytest,world_to_obj);
1244
1245 WWASSERT(Model);
1246
1247 bool hit = Model->Cast_Ray(objray);
1248
1249 // transform result back into original coordinate system
1250 if (hit) {
1251 raytest.CollidedRenderObj = this;
1252 Matrix3D::Rotate_Vector(world,raytest.Result->Normal, &(raytest.Result->Normal));
1253 if (raytest.Result->ComputeContactPoint) {
1255 }
1256 }
1257
1258 return hit;
1259}
1260
1261
1262/***********************************************************************************************
1263 * MeshClass::Cast_AABox -- cast an AABox against this mesh *
1264 * *
1265 * INPUT: *
1266 * *
1267 * OUTPUT: *
1268 * *
1269 * WARNINGS: *
1270 * *
1271 * HISTORY: *
1272 * 6/17/98 GTH : Created. *
1273 *=============================================================================================*/
1275{
1276 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1277 if (boxtest.Result->StartBad) return false;
1278
1279 WWASSERT(Model);
1280
1281 // This function analyses the tranform to call optimized functions in certain cases
1282 bool hit = Model->Cast_World_Space_AABox(boxtest, Get_Transform());
1283
1284 if (hit) {
1285 boxtest.CollidedRenderObj = this;
1286 }
1287
1288 return hit;
1289}
1290
1291
1292/***********************************************************************************************
1293 * Cast_OBBox -- Cast an obbox against this mesh *
1294 * *
1295 * INPUT: *
1296 * *
1297 * OUTPUT: *
1298 * *
1299 * WARNINGS: *
1300 * *
1301 * HISTORY: *
1302 * 6/17/98 GTH : Created. *
1303 *=============================================================================================*/
1305{
1306 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1307 if (boxtest.Result->StartBad) return false;
1308
1309 /*
1310 ** transform into the local coordinate system of the mesh.
1311 */
1312 const Matrix3D & tm = Get_Transform();
1313 Matrix3D world_to_obj;
1314 tm.Get_Orthogonal_Inverse(world_to_obj);
1315 OBBoxCollisionTestClass localtest(boxtest,world_to_obj);
1316
1317 WWASSERT(Model);
1318
1319 bool hit = Model->Cast_OBBox(localtest);
1320
1321 /*
1322 ** If we hit, transform the result of the test back to the original coordinate system.
1323 */
1324 if (hit) {
1325 boxtest.CollidedRenderObj = this;
1326 Matrix3D::Rotate_Vector(tm,boxtest.Result->Normal, &(boxtest.Result->Normal));
1327 if (boxtest.Result->ComputeContactPoint) {
1329 }
1330 }
1331
1332 return hit;
1333}
1334
1335
1336/***********************************************************************************************
1337 * MeshClass::Intersect_AABox -- test for intersection with given AABox *
1338 * *
1339 * The AAbox given is assumed to be in world space. Since meshes aren't generally in world *
1340 * space, the test must be transformed into our local coordinate system (which turns it into *
1341 * an OBBox...) *
1342 * *
1343 * INPUT: *
1344 * *
1345 * OUTPUT: *
1346 * *
1347 * WARNINGS: *
1348 * *
1349 * HISTORY: *
1350 * 1/19/00 gth : Created. *
1351 *=============================================================================================*/
1353{
1354 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1355
1356 Matrix3D inv_tm;
1358 OBBoxIntersectionTestClass local_test(boxtest,inv_tm);
1359 WWASSERT(Model);
1360 return Model->Intersect_OBBox(local_test);
1361}
1362
1363
1364/***********************************************************************************************
1365 * MeshClass::Intersect_OBBox -- test for intersection with the given OBBox *
1366 * *
1367 * The given OBBox is assumed to be in world space so we need to transform it into the mesh's *
1368 * local coordinate system. *
1369 * *
1370 * INPUT: *
1371 * *
1372 * OUTPUT: *
1373 * *
1374 * WARNINGS: *
1375 * *
1376 * HISTORY: *
1377 * 1/19/00 gth : Created. *
1378 *=============================================================================================*/
1380{
1381 if ((Get_Collision_Type() & boxtest.CollisionType) == 0) return false;
1382
1383 Matrix3D inv_tm;
1385 OBBoxIntersectionTestClass local_test(boxtest,inv_tm);
1386 WWASSERT(Model);
1387 return Model->Intersect_OBBox(local_test);
1388}
1389
1390
1391/***********************************************************************************************
1392 * MeshClass::Get_Obj_Space_Bounding_Sphere -- returns obj-space bounding sphere *
1393 * *
1394 * INPUT: *
1395 * *
1396 * OUTPUT: *
1397 * *
1398 * WARNINGS: *
1399 * *
1400 * HISTORY: *
1401 * 1/19/00 gth : Created. *
1402 *=============================================================================================*/
1404{
1405 if (Model) {
1406 Model->Get_Bounding_Sphere(&sphere);
1407 } else {
1408 sphere.Center.Set(0,0,0);
1409 sphere.Radius = 1.0f;
1410 }
1411}
1412
1413
1414/***********************************************************************************************
1415 * MeshClass::Get_Obj_Space_Bounding_Box -- returns the obj-space bounding box *
1416 * *
1417 * INPUT: *
1418 * *
1419 * OUTPUT: *
1420 * *
1421 * WARNINGS: *
1422 * *
1423 * HISTORY: *
1424 * 1/19/00 gth : Created. *
1425 *=============================================================================================*/
1427{
1428 if (Model) {
1429 Model->Get_Bounding_Box(&box);
1430 } else {
1431 box.Init(Vector3(0,0,0),Vector3(1,1,1));
1432 }
1433}
1434
1435
1436/***********************************************************************************************
1437 * MeshClass::Generate_Culling_Tree -- Generates a hierarchical culling tree for the mesh *
1438 * *
1439 * INPUT: *
1440 * *
1441 * OUTPUT: *
1442 * *
1443 * WARNINGS: *
1444 * *
1445 * HISTORY: *
1446 * 6/18/98 GTH : Created. *
1447 *=============================================================================================*/
1449{
1450 Model->Generate_Culling_Tree();
1451}
1452
1453
1454/***********************************************************************************************
1455 * MeshClass::Add_Dependencies_To_List -- Add dependent files to the list. *
1456 * *
1457 * INPUT: *
1458 * *
1459 * OUTPUT: *
1460 * *
1461 * WARNINGS: *
1462 * *
1463 * HISTORY: *
1464 * 3/18/99 PDS : Created. *
1465 *=============================================================================================*/
1467(
1469 bool textures_only
1470)
1471{
1472 //
1473 // Get a pointer to this mesh's material information object
1474 //
1475 MaterialInfoClass *material = Get_Material_Info ();
1476 if (material != NULL) {
1477
1478 //
1479 // Loop through all the textures and add their filenames to our list
1480 //
1481 for (int index = 0; index < material->Texture_Count (); index ++) {
1482
1483 //
1484 // Add this texture's filename to the list
1485 //
1486 TextureClass *texture = material->Peek_Texture (index);
1487 if (texture != NULL) {
1488 file_list.Add (texture->Get_Full_Path ());
1489 }
1490 }
1491
1492 //
1493 // Release our hold on the material information object
1494 //
1495 material->Release_Ref ();
1496 }
1497
1498 RenderObjClass::Add_Dependencies_To_List (file_list, textures_only);
1499 return ;
1500}
1501
1502
1503/***********************************************************************************************
1504 * MeshClass::Update_Cached_Bounding_Volumes -- default collision sphere. *
1505 * *
1506 * INPUT: *
1507 * *
1508 * OUTPUT: *
1509 * *
1510 * WARNINGS: *
1511 * *
1512 * HISTORY: *
1513 * 5/14/2001 NH : Created. *
1514 *=============================================================================================*/
1516{
1518
1519#ifdef ALLOW_TEMPORARIES
1521#else
1523#endif
1524
1525 // If we are camera-aligned or -oriented, we don't know which way we are facing at this point,
1526 // so the box we return needs to contain the sphere. Otherewise do the normal computation.
1527 if (Model->Get_Flag(MeshModelClass::ALIGNED) || Model->Get_Flag(MeshModelClass::ORIENTED)) {
1530 } else {
1532 CachedBoundingBox.Transform(Get_Transform());
1533 }
1534
1536}
1537
1538
1539// This utility function recurses throughout the subobjects of a renderobject, and for each
1540// MeshClass it finds it sets the given MeshModel flag on its model. This is useful for stuff
1541// like making a RenderObjects' polys sort.
1542void Set_MeshModel_Flag(RenderObjClass *robj, int flag, int onoff)
1543{
1544 if (robj->Class_ID() == RenderObjClass::CLASSID_MESH) {
1545 // Set flag on model (the assumption is that meshes don't have subobjects)
1546 MeshClass *mesh = (MeshClass *)robj;
1547 MeshModelClass *model = mesh->Get_Model();
1548 model->Set_Flag((MeshModelClass::FlagsType)flag, onoff != 0);
1549 model->Release_Ref();
1550 } else {
1551 // Recurse to subobjects (if any)
1552 int num_obj = robj->Get_Num_Sub_Objects();
1553 RenderObjClass *sub_obj;
1554 for (int i = 0; i < num_obj; i++) {
1555 sub_obj = robj->Get_Sub_Object(i);
1556 if (sub_obj) {
1557 Set_MeshModel_Flag(sub_obj, flag, onoff);
1558 sub_obj->Release_Ref();
1559 }
1560 }
1561 }
1562}
1563
1565{
1566 if (Model) {
1567 return (Model->Get_Sort_Level());
1568 }
1569 return(SORT_LEVEL_NONE);
1570}
1571
1573{
1574 if (Model) {
1575 Model->Set_Sort_Level(level);
1576 }
1577}
1578
1580{
1581 if (Model != NULL) {
1582 // Prefer to return the number of polygon renderers
1583 int prcount = Model->PolygonRendererList.Count();
1584 if (prcount > 0) {
1585 return prcount;
1586 }
1587
1588 // Otherwise if we have textures, return the number of textures (e.g. dont have prs when sorting)
1589 if ((Model->MatInfo != NULL) && (Model->MatInfo->Texture_Count() > 0)) {
1590 return Model->MatInfo->Texture_Count();
1591 }
1592
1593 // Otherwise, return 1
1594 return 1;
1595
1596 } else {
1597 return 0;
1598 }
1599}
1600
1601
1602
1603
1604
#define NULL
Definition BaseType.h:92
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define WWASSERT
#define SORT_LEVEL_NONE
Definition w3d_file.h:1195
#define W3D_MESH_FLAG_COLLISION_TYPE_SHIFT
Definition w3d_file.h:1144
#define W3D_MESH_FLAG_HIDDEN
Definition w3d_file.h:1151
#define W3D_MESH_FLAG_COLLISION_TYPE_MASK
Definition w3d_file.h:1143
unsigned long uint32
Definition bittype.h:46
@ false
Definition bool.h:59
WWINLINE void Init(const Vector3 &center, const Vector3 &extent)
Definition aabox.h:101
const FrustumClass & Get_Frustum(void) const
Definition camera.h:339
void Transform_To_View_Space(Vector3 &dest, const Vector3 &ws_point) const
Definition camera.cpp:522
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
CastResultStruct * Result
Definition coltest.h:98
RenderObjClass * CollidedRenderObj
Definition coltest.h:100
void Add_Visible_Material_Pass(MaterialPassClass *pass, MeshClass *mesh)
virtual void Add_Delayed_Visible_Material_Pass(MaterialPassClass *pass, MeshClass *mesh)=0
DX8TextureCategoryClass * Get_Texture_Category()
void Render(int base_vertex_offset)
static void Add_Mesh(MeshClass *mesh)
void Add_Render_Task(DX8PolygonRendererClass *p_renderer, MeshClass *p_mesh)
static void Set_World_Identity()
static void Set_Light_Environment(LightEnvironmentClass *light_env)
Set the light environment. This is a lighting model which used up to four directional lights to produ...
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
DecalSystemClass * Peek_Decal_System(void)
Definition decalsys.h:148
bool Is_Applied_To_Translucent_Meshes(void)
Definition decalsys.h:164
bool Add(T const &object)
Definition Vector.H:671
const Vector3 & Get_Dir() const
Definition lineseg.h:73
const Vector3 & Get_P0() const
Definition lineseg.h:70
TextureClass * Peek_Texture(int index)
Definition matinfo.h:323
int Texture_Count(void) const
Definition matinfo.h:84
VertexMaterialClass * Peek_Material(void) const
Definition matpass.h:98
virtual void Install_Materials(void) const
MW: Had to make this virtual so app can perform direct/custom D3D setup.
Definition matpass.cpp:118
OBBoxClass * Get_Cull_Volume(void) const
Definition matpass.h:101
bool Is_Enabled_On_Translucent_Meshes(void)
Definition matpass.h:104
virtual void UnInstall_Materials(void) const
Definition matpass.h:87
static bool Is_Per_Polygon_Culling_Enabled(void)
Definition matpass.h:107
static WWINLINE void Inverse_Transform_Vector(const Matrix3D &tm, const Vector3 &in, Vector3 *out)
Definition matrix3d.h:1778
static const Matrix3D Identity
Definition matrix3d.h:372
Vector3 Rotate_Vector(const Vector3 &vect) const
Definition matrix3d.cpp:300
void mulVector3(const Vector3 &in, Vector3 &out) const
Definition matrix3d.h:1650
void Get_Orthogonal_Inverse(Matrix3D &set_inverse) const
Definition matrix3d.cpp:570
static WWINLINE void Transform_Vector(const Matrix3D &tm, const Vector3 &in, Vector3 *out)
Definition matrix3d.h:1742
WWINLINE Vector3 Get_Translation(void) const
Definition matrix3d.h:217
void Get_Inverse(Matrix3D &set_inverse) const
Definition matrix3d.cpp:514
void Obj_Look_At(const Vector3 &p, const Vector3 &t, float roll)
Definition matrix3d.cpp:458
WWINLINE Vector3 Get_Z_Vector(void) const
Definition matrix3.h:647
DecalMeshClass * DecalMesh
Definition mesh.h:179
virtual void Render(RenderInfoClass &rinfo)
Definition mesh.cpp:660
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition mesh.cpp:1403
virtual RenderObjClass * Clone(void) const
Definition mesh.cpp:306
void Replace_Texture(TextureClass *texture, TextureClass *new_texture)
Definition mesh.cpp:1072
float m_materialPassEmissiveOverride
Definition mesh.h:184
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
Definition mesh.cpp:1139
void Generate_Culling_Tree(void)
Definition mesh.cpp:1448
virtual void Delete_Decal(uint32 decal_id)
Definition mesh.cpp:615
void Render_Material_Pass(MaterialPassClass *pass, IndexBufferClass *ib)
Definition mesh.cpp:823
bool Contains(const Vector3 &point)
Definition mesh.cpp:266
int BaseVertexOffset
Definition mesh.h:186
void Make_Unique(bool force_meshmdl_clone=false)
Definition mesh.cpp:1114
static bool Legacy_Meshes_Fogged
Definition mesh.h:156
unsigned MeshDebugId
Definition mesh.h:189
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition mesh.cpp:1218
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
Definition mesh.cpp:1379
int Get_Draw_Call_Count(void) const
Definition mesh.cpp:1579
void Get_Deformed_Vertices(Vector3 *dst_vert, Vector3 *dst_norm)
Definition mesh.cpp:500
virtual int Get_Num_Polys(void) const
Definition mesh.cpp:635
virtual void Create_Decal(DecalGeneratorClass *generator)
Definition mesh.cpp:540
virtual void Set_Name(const char *name)
Definition mesh.cpp:342
MeshModelClass * Get_Model(void)
Definition mesh.cpp:419
MeshClass(void)
Definition mesh.cpp:161
virtual const char * Get_Name(void) const
Definition mesh.cpp:324
void Set_Lighting_Environment(LightEnvironmentClass *light_env)
Definition mesh.h:145
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition mesh.cpp:1027
virtual void Scale(float scale)
Definition mesh.cpp:438
virtual int Get_Sort_Level(void) const
Definition mesh.cpp:1564
MeshClass & operator=(const MeshClass &)
Definition mesh.cpp:218
virtual MaterialInfoClass * Get_Material_Info(void)
Definition mesh.cpp:395
void Replace_VertexMaterial(VertexMaterialClass *vmat, VertexMaterialClass *new_vmat)
Definition mesh.cpp:1093
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition mesh.cpp:1426
virtual ~MeshClass(void)
Definition mesh.cpp:247
MeshModelClass * Model
Definition mesh.h:178
virtual void Update_Cached_Bounding_Volumes(void) const
Definition mesh.cpp:1515
virtual void Add_Dependencies_To_List(DynamicVectorClass< StringClass > &file_list, bool textures_only=false)
Definition mesh.cpp:1467
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition mesh.cpp:1304
bool IsDisabledByDebugger
Definition mesh.h:190
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
Definition mesh.cpp:1352
float m_materialPassAlphaOverride
Definition mesh.h:185
float m_alphaOverride
Definition mesh.h:183
virtual void Set_Sort_Level(int level)
Definition mesh.cpp:1572
void Free(void)
Definition mesh.cpp:287
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition mesh.cpp:1274
LightEnvironmentClass * LightEnvironment
Definition mesh.h:181
MeshClass * NextVisibleSkin
Definition mesh.h:187
const char * Get_User_Text(void) const
Definition mesh.cpp:377
uint32 Get_W3D_Flags(void)
Definition mesh.cpp:359
void Set_Flag(FlagsType flag, bool onoff)
ObjectType * Peek_Obj(void)
Definition multilist.h:306
Matrix3x3 Basis
Definition obbox.h:112
static void Transform(const Matrix3D &tm, const OBBoxClass &in, OBBoxClass *out)
Definition obbox.h:161
const OBBoxClass & Get_Bounding_Volume(void) const
Definition projector.h:71
LineSegClass Ray
Definition coltest.h:139
WWINLINE void Release_Ref(void) const
Definition refcount.h:146
MaterialPassClass * Peek_Additional_Pass(int i)
Definition rinfo.cpp:107
CameraClass & Camera
Definition rinfo.h:100
RINFO_OVERRIDE_FLAGS & Current_Override_Flags(void)
Definition rinfo.cpp:126
@ RINFO_OVERRIDE_ADDITIONAL_PASSES_ONLY
Definition rinfo.h:86
@ RINFO_OVERRIDE_SHADOW_RENDERING
Definition rinfo.h:87
float alphaOverride
Definition rinfo.h:105
int Additional_Pass_Count(void)
Definition rinfo.cpp:102
float materialPassAlphaOverride
Definition rinfo.h:106
LightEnvironmentClass * light_environment
Definition rinfo.h:109
float materialPassEmissiveOverride
Definition rinfo.h:107
virtual int Is_Hidden(void) const
Definition rendobj.h:471
virtual int Is_Animation_Hidden(void) const
Definition rendobj.h:473
virtual int Is_Translucent(void) const
Definition rendobj.h:478
void Validate_Cached_Bounding_Volumes(void) const
Definition rendobj.h:524
virtual int Is_Not_Hidden_At_All(void)
Definition rendobj.h:463
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Translucent(int onoff)
Definition rendobj.h:479
virtual void Update_Obj_Space_Bounding_Volumes(void)
Definition rendobj.h:394
virtual const SphereClass & Get_Bounding_Sphere(void) const
Definition rendobj.h:567
AABoxClass CachedBoundingBox
Definition rendobj.h:553
RenderObjClass * Container
Definition rendobj.h:558
void Invalidate_Cached_Bounding_Volumes(void) const
Definition rendobj.h:523
virtual void Set_Collision_Type(int type)
Definition rendobj.h:485
virtual const AABoxClass & Get_Bounding_Box(void) const
Definition rendobj.h:575
RenderObjClass & operator=(const RenderObjClass &)
Definition rendobj.cpp:232
virtual int Class_ID(void) const
Definition rendobj.h:249
virtual void Set_Hidden(int onoff)
Definition rendobj.h:472
virtual void Set_Alpha(int onoff)
Definition rendobj.h:481
virtual void Add_Dependencies_To_List(DynamicVectorClass< StringClass > &file_list, bool textures_only=false)
Definition rendobj.cpp:1136
const Matrix3D & Get_Transform(void) const
Definition rendobj.h:617
virtual int Get_Num_Sub_Objects(void) const
Definition rendobj.h:309
virtual int Is_Alpha(void) const
Definition rendobj.h:480
RenderObjClass * Get_Container(void) const
Definition rendobj.h:291
Matrix3D Transform
Definition rendobj.h:549
virtual RenderObjClass * Get_Sub_Object(int index) const
Definition rendobj.h:310
virtual int Get_Collision_Type(void) const
Definition rendobj.h:484
virtual void Set_Additive(int onoff)
Definition rendobj.h:483
SphereClass CachedBoundingSphere
Definition rendobj.h:552
SrcBlendFuncType Get_Src_Blend_Func(void) const
Definition shader.h:319
DstBlendFuncType Get_Dst_Blend_Func(void) const
Definition shader.h:315
@ SRCBLEND_SRC_ALPHA
Definition shader.h:212
@ SRCBLEND_ONE
Definition shader.h:211
AlphaTestType Get_Alpha_Test(void) const
Definition shader.h:313
@ ALPHATEST_ENABLE
Definition shader.h:97
@ DSTBLEND_ZERO
Definition shader.h:172
@ DSTBLEND_ONE
Definition shader.h:173
VisRasterizerClass * VisRasterizer
Definition rinfo.h:153
float Radius
Definition sphere.h:91
Vector3 Center
Definition sphere.h:90
const StringClass & Get_Full_Path(void) const
Definition texture.h:113
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
WWINLINE void Set(float x, float y, float z)
Definition vector3.h:103
unsigned short K
Definition Vector3i.h:102
unsigned short J
Definition Vector3i.h:101
unsigned short I
Definition Vector3i.h:100
void Set_Emissive(const Vector3 &color)
void Get_Emissive(Vector3 *set_color) const
float Get_Opacity(void) const
void Set_Opacity(float o)
void Enable_Two_Sided_Rendering(bool onoff)
void Set_Model_Transform(const Matrix3D &model)
bool Render_Triangles(const Vector3 *verts, int vcount, const TriIndex *tris, int tcount, const AABoxClass &bounds)
static void Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
Definition ww3d.cpp:1984
static bool Are_Static_Sort_Lists_Enabled(void)
Definition ww3d.h:282
static float Get_Decal_Rejection_Distance(void)
Definition ww3d.h:272
static bool Are_Decals_Enabled(void)
Definition ww3d.h:270
static bool Is_Sorting_Enabled(void)
Definition ww3d.h:220
static float Max(float a, float b)
Definition wwmath.h:264
static float Min(float a, float b)
Definition wwmath.h:258
int IndexBufferExceptionFunc(void)
MultiListIterator< DX8PolygonRendererClass > DX8PolygonRendererListIterator
Definition dx8list.h:66
DX8MeshRendererClass TheDX8MeshRenderer
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
@ BUFFER_TYPE_DYNAMIC_SORTING
Definition dx8wrapper.h:91
void Set_MeshModel_Flag(RenderObjClass *robj, int flag, int onoff)
Definition mesh.cpp:1542
Vector3i16 TriIndex
else return(RetVal)
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define REF_PTR_SET(dst, src)
Definition refcount.h:79
#define NEW_REF(C, P)
Definition refcount.h:62
Vector3 ContactPoint
Definition castres.h:70
bool ComputeContactPoint
Definition castres.h:69
Vector3 Normal
Definition castres.h:66
unsigned char flag
Definition vchannel.cpp:273
WW3DErrorType
Definition w3derr.h:51
@ WW3D_ERROR_LOAD_FAILED
Definition w3derr.h:54
@ WW3D_ERROR_OK
Definition w3derr.h:52
#define SNAPSHOT_SAY(x)
Definition ww3d.h:68
#define WWDEBUG_SAY(x)
Definition wwdebug.h:114
@ MEM_GEOMETRY
Definition wwmemlog.h:59
#define WWMEMLOG(category)
Definition wwmemlog.h:183
#define WWPROFILE(name)
Definition wwprofile.h:270