Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dynamesh.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/***************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***************************************************************************
22 * *
23 * Project Name : Commando *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/dynamesh.cpp $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 12/03/01 4:50p $*
30 * *
31 * $Revision:: 25 $*
32 * *
33 *-------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "dynamesh.h"
38#include "dx8vertexbuffer.h"
39#include "dx8indexbuffer.h"
40#include "dx8wrapper.h"
41#include "sortingrenderer.h"
42#include "rinfo.h"
43#include "camera.h"
44#include "dx8fvf.h"
45
46
47
48/*
49** DynamicMeshModel implementation
50*/
51
52DynamicMeshModel::DynamicMeshModel(unsigned int max_polys, unsigned int max_verts) :
54 DynamicMeshPNum(0),
55 DynamicMeshVNum(0),
56 MatDesc(NULL),
57 MatInfo(NULL)
58{
59 MatInfo = NEW_REF(MaterialInfoClass, ());
60
61 MatDesc = W3DNEW MeshMatDescClass;
62 MatDesc->Set_Polygon_Count(max_polys);
63 MatDesc->Set_Vertex_Count(max_verts);
64
65 Reset_Geometry(max_polys, max_verts);
66}
67
68DynamicMeshModel::DynamicMeshModel(unsigned int max_polys, unsigned int max_verts, MaterialInfoClass *mat_info) :
70 DynamicMeshPNum(0),
71 DynamicMeshVNum(0),
72 MatDesc(NULL),
73 MatInfo(NULL)
74{
75 MatInfo = mat_info;
76 MatInfo->Add_Ref();
77
78 MatDesc = W3DNEW MeshMatDescClass;
79 MatDesc->Set_Polygon_Count(max_polys);
80 MatDesc->Set_Vertex_Count(max_verts);
81
82 Reset_Geometry(max_polys, max_verts);
83}
84
87 DynamicMeshPNum(src.DynamicMeshPNum),
88 DynamicMeshVNum(src.DynamicMeshVNum),
89 MatDesc(NULL),
90 MatInfo(NULL)
91{
92 // Copy the material info structure.
93 MatInfo = NEW_REF(MaterialInfoClass, (*(src.MatInfo)));
94
95
96 // [SKB: Feb 21 2002 @ 11:47pm] :
97 // Moved before the remapping cause I don't like referencing null.
98 MatDesc = W3DNEW MeshMatDescClass;
99
100 // remap!
101 MaterialRemapperClass remapper(src.MatInfo, MatInfo);
102 remapper.Remap_Mesh(src.MatDesc, MatDesc);
103}
104
106{
107 if (MatDesc) {
108 delete MatDesc;
109 MatDesc = NULL;
110 }
111 REF_PTR_RELEASE(MatInfo);
112}
113
115{
116 // Make sure the arrays are allocated before we do this
118 Vector4 * planes = get_planes(true);
119
120 // Set the poly and vertex counts to the dynamic counts, call the base class function, then
121 // set them back.
122 int old_poly_count = PolyCount;
123 int old_vert_count = VertexCount;
124 PolyCount = DynamicMeshPNum;
125 VertexCount = DynamicMeshVNum;
126
128
129 PolyCount = old_poly_count;
130 VertexCount = old_vert_count;
131}
132
134{
135 // Make sure the arrays are allocated before we do this
136 Vector3 * vnorms = get_vert_normals();
137 get_planes(true);
138
139 // Set the poly and vertex counts to the dynamic counts, call the base class function, then
140 // set them back.
141 int old_poly_count = PolyCount;
142 int old_vert_count = VertexCount;
143 PolyCount = DynamicMeshPNum;
144 VertexCount = DynamicMeshVNum;
145
147
148 PolyCount = old_poly_count;
149 VertexCount = old_vert_count;
150}
151
153{
154 // Set the poly and vertex counts to the dynamic counts, call the base class function, then
155 // set them back.
156 int old_poly_count = PolyCount;
157 int old_vert_count = VertexCount;
158 PolyCount = DynamicMeshPNum;
159 VertexCount = DynamicMeshVNum;
160
162
163 PolyCount = old_poly_count;
164 VertexCount = old_vert_count;
165}
166
168{
169 Set_Counts(0, 0);
170 int polycount = Get_Polygon_Count();
171 int vertcount = Get_Vertex_Count();
172 Reset_Geometry(polycount, vertcount);
173 MatDesc->Reset(polycount, vertcount, 1);
174 REF_PTR_RELEASE(MatInfo);
175 MatInfo = NEW_REF(MaterialInfoClass, ());
176}
177
179{
180 // Process texture reductions:
181// MatInfo->Process_Texture_Reduction();
182
184
185 /*
186 ** Write the vertex data to the vertex buffer. We assume the FVF contains positions, normals,
187 ** one texture channel, and the diffuse color channel (color0). If it does not contain all
188 ** these components, the code will fail.
189 */
190 DynamicVBAccessClass dynamic_vb(buffer_type,dynamic_fvf_type,DynamicMeshVNum);
191 const FVFInfoClass &fvf_info = dynamic_vb.FVF_Info();
192
193 { // scope for lock
194
195 DynamicVBAccessClass::WriteLockClass lock(&dynamic_vb);
196 unsigned char *vertices = (unsigned char*)lock.Get_Formatted_Vertex_Array();
197 const Vector3 *locs = Get_Vertex_Array();
198 const Vector3 *normals = Get_Vertex_Normal_Array();
199 const Vector2 *uvs = MatDesc->Get_UV_Array_By_Index(0, false);
200 const Vector2 *uv1s = MatDesc->Get_UV_Array_By_Index(1, false);
201 const unsigned *colors = MatDesc->Get_Color_Array(0, false);
202 const static Vector3 default_normal(0.0f, 0.0f, 0.0f);
203 const static Vector2 default_uv(0.0f, 0.0f);
204 const unsigned int default_color = 0xFFFFFFFF;
205 for (int i=0; i < DynamicMeshVNum; i++)
206 {
207 *(Vector3 *)(vertices + fvf_info.Get_Location_Offset()) = locs[i];
208 *(Vector3 *)(vertices + fvf_info.Get_Normal_Offset()) = normals[i];
209 if (uvs) {
210 *(Vector2 *)(vertices + fvf_info.Get_Tex_Offset(0)) = uvs[i];
211 } else {
212 *(Vector2 *)(vertices + fvf_info.Get_Tex_Offset(0)) = default_uv;
213 }
214 if (uv1s) {
215 *(Vector2 *)(vertices + fvf_info.Get_Tex_Offset(1)) = uv1s[i];
216 } else {
217 *(Vector2 *)(vertices + fvf_info.Get_Tex_Offset(1)) = default_uv;
218 }
219
220 if (colors) {
221 *(unsigned int *)(vertices + fvf_info.Get_Diffuse_Offset()) = colors[i];
222 } else {
223 *(unsigned int *)(vertices + fvf_info.Get_Diffuse_Offset()) = default_color;
224 }
225 vertices += fvf_info.Get_FVF_Size();
226 }
227
228 } // end scope for lock
229
230 /*
231 ** Write index data to index buffers
232 */
233 DynamicIBAccessClass dynamic_ib(buffer_type,DynamicMeshPNum * 3);
234 const TriIndex *tris = Get_Polygon_Array();
235
236 { // scope for lock
237
238 DynamicIBAccessClass::WriteLockClass lock(&dynamic_ib);
239 unsigned short * indices = lock.Get_Index_Array();
240 for (int i=0; i < DynamicMeshPNum; i++)
241 {
242 indices[i*3 + 0] = (unsigned short)tris[i][0];
243 indices[i*3 + 1] = (unsigned short)tris[i][1];
244 indices[i*3 + 2] = (unsigned short)tris[i][2];
245 }
246
247 } // end scope for lock
248
249 /*
250 ** Set vertex and index buffers
251 */
253 DX8Wrapper::Set_Index_Buffer(dynamic_ib,0);
254
255 /*
256 ** Draw dynamesh, one pass at a time
257 */
258 unsigned int pass_count = Get_Pass_Count();
259 for (unsigned int pass = 0; pass < pass_count; pass++) {
260
261 /*
262 ** Set current render states (texture, vertex material, shader). Scan triangles until one
263 ** of these changes, and then draw.
264 */
265
266 // The vertex index range used
267 unsigned short min_vert_idx = DynamicMeshVNum - 1;
268 unsigned short max_vert_idx = 0;
269 unsigned short start_tri_idx = 0;
270 unsigned short cur_tri_idx = 0;
271
272 bool done = false;
273 bool texture_changed = false;
274 bool texture1_changed = false;
275 bool material_changed = false;
276 bool shader_changed = false;
277
278 TextureClass **texture_array0 = NULL;
279 TexBufferClass * tex_buf = MatDesc->Get_Texture_Array(pass, 0, false);
280 if (tex_buf) {
281 texture_array0 = tex_buf->Get_Array();
282 } else {
283 texture_array0 = NULL;
284 }
285
286 TextureClass **texture_array1 = NULL;
287 TexBufferClass * tex_buf1 = MatDesc->Get_Texture_Array(pass, 1, false);
288 if (tex_buf1) {
289 texture_array1 = tex_buf1->Get_Array();
290 } else {
291 texture_array1 = NULL;
292 }
293
294 VertexMaterialClass **material_array = NULL;
295 MatBufferClass * mat_buf = MatDesc->Get_Material_Array(pass, false);
296 if (mat_buf) {
297 material_array = mat_buf->Get_Array();
298 } else {
299 material_array = NULL;
300 }
301 ShaderClass *shader_array = MatDesc->Get_Shader_Array(pass, false);
302
303 // Set the DX8 state to the first triangle's state
304 if (texture_array0) {
305 DX8Wrapper::Set_Texture(0,texture_array0[0]);
306 } else {
307 DX8Wrapper::Set_Texture(0,MatDesc->Peek_Single_Texture(pass, 0));
308 }
309
310 if (texture_array1) {
311 DX8Wrapper::Set_Texture(1,texture_array1[0]);
312 } else {
313 DX8Wrapper::Set_Texture(1,MatDesc->Peek_Single_Texture(pass, 1));
314 }
315
316 if (material_array) {
317 DX8Wrapper::Set_Material(material_array[tris[0].I]);
318 } else {
319 DX8Wrapper::Set_Material(MatDesc->Peek_Single_Material(pass));
320 }
321 if (shader_array) {
322 DX8Wrapper::Set_Shader(shader_array[0]);
323 } else {
324 DX8Wrapper::Set_Shader(MatDesc->Get_Single_Shader(pass));
325 }
326
327 SphereClass sphere(Vector3(0.0f,0.0f,0.0f),0.0f);
328 Get_Bounding_Sphere(&sphere);
329
330 // If no texture, shader or material arrays for this pass just draw and go to next pass
331 if (!texture_array0 && !texture_array1 && !material_array && !shader_array) {
332 if (buffer_type==BUFFER_TYPE_DYNAMIC_SORTING) {
333 SortingRendererClass::Insert_Triangles(sphere,0, DynamicMeshPNum, 0, DynamicMeshVNum);
334 }
335 else {
336 DX8Wrapper::Draw_Triangles(0, DynamicMeshPNum, 0, DynamicMeshVNum);
337 }
338 continue;
339 }
340
341 while (!done) {
342
343 // Add vertex indices of tri[cur_tri_idx] to min_vert_idx, max_vert_idx
344 const TriIndex &tri = tris[cur_tri_idx];
345 unsigned short min_idx = (unsigned short)MIN(MIN(tri.I, tri.J), tri.K);
346 unsigned short max_idx = (unsigned short)MAX(MAX(tri.I, tri.J), tri.K);
347 min_vert_idx = MIN(min_vert_idx, min_idx);
348 max_vert_idx = MAX(max_vert_idx, max_idx);
349
350 // Check the next triangle to see if the current run has ended.
351 unsigned short next_tri_idx = cur_tri_idx + 1;
352 done = next_tri_idx >= DynamicMeshPNum;
353 if (done) {
354 texture_changed = false;
355 texture1_changed = false;
356 material_changed = false;
357 shader_changed = false;
358 } else {
359 texture_changed = texture_array0 && texture_array0[cur_tri_idx] != texture_array0[next_tri_idx];
360 texture1_changed = texture_array1 && texture_array1[cur_tri_idx] != texture_array1[next_tri_idx];
361 material_changed = material_array && material_array[tris[cur_tri_idx].I] != material_array[tris[next_tri_idx].I];
362 shader_changed = shader_array && shader_array[cur_tri_idx] != shader_array[next_tri_idx];
363 }
364
365 // If run ends (mesh ends or state changes) draw, reset indices, set state for next run.
366 if (done || texture_changed || material_changed || shader_changed) {
367 if (buffer_type==BUFFER_TYPE_DYNAMIC_SORTING) {
369 sphere,
370 (start_tri_idx * 3),
371 (1 + cur_tri_idx - start_tri_idx),
372 min_vert_idx,
373 1 + max_vert_idx - min_vert_idx);
374 }
375 else {
377 (start_tri_idx * 3),
378 (1 + cur_tri_idx - start_tri_idx),
379 min_vert_idx,
380 1 + max_vert_idx - min_vert_idx);
381 }
382 start_tri_idx = next_tri_idx;
383 min_vert_idx = DynamicMeshVNum - 1;
384 max_vert_idx = 0;
385 if (texture_changed) DX8Wrapper::Set_Texture(0,texture_array0[next_tri_idx]);
386 if (texture1_changed) DX8Wrapper::Set_Texture(1,texture_array1[next_tri_idx]);
387 if (material_changed) DX8Wrapper::Set_Material(material_array[tris[next_tri_idx].I]);
388 if (shader_changed) DX8Wrapper::Set_Shader(shader_array[next_tri_idx]);
389 }
390
391 cur_tri_idx = next_tri_idx;
392
393 } // while (!done)
394
395 } // for (pass)
396
397}
398
400{
401 TexBufferClass * texlist = MatDesc->Get_Texture_Array(pass, 0, true);
402 for (int lp = 0; lp < PolyCount; lp++) {
403 texlist->Set_Element(lp, texture);
404 }
405}
406
408{
409 MatBufferClass * vertmatlist = MatDesc->Get_Material_Array(pass, true);
410 for (int lp = 0; lp < VertexCount; lp++) {
411 vertmatlist->Set_Element(lp, vmat);
412 }
413}
414
416{
417 if (Is_Not_Hidden_At_All() == false) return;
418
419 // test for an empty mesh..
420 if (PolyCount == 0 ) return;
421
422 // If static sort lists are enabled and this mesh has a sort level, put it on the list instead
423 // of rendering it.
424
426
428
429 } else {
430
431 const FrustumClass & frustum = rinfo.Camera.Get_Frustum();
432
435 Model->Render(rinfo);
436 }
437 }
438}
439
441{
442 // check that we have room for a new vertex
443 WWASSERT(VertCount < Model->Get_Vertex_Count());
444
445 // if we are a multi-material object record the material
446 int pass = Get_Pass_Count();
447 while (pass--) {
448 if (MultiVertexMaterial[pass]) {
450 Model->Set_Material(VertCount, mat, pass);
451 REF_PTR_RELEASE(mat);
452 }
453
454 }
455
456 // if we are multi colored, record the color
457 for (int color_array_index = 0; color_array_index < MAX_COLOR_ARRAYS; color_array_index++) {
458 if (MultiVertexColor[color_array_index]) {
459// Vector4 * color = &((Model->Get_Color_Array(color_array_index))[VertCount]);
460// color->X = CurVertexColor[color_array_index].X;
461// color->Y = CurVertexColor[color_array_index].Y;
462// color->Z = CurVertexColor[color_array_index].Z;
463// color->W = CurVertexColor[color_array_index].W;
464 unsigned * color = &((Model->Get_Color_Array(color_array_index))[VertCount]);
465 *color=DX8Wrapper::Convert_Color_Clamp(CurVertexColor[color_array_index]);
466 }
467 }
468
469 // mark this vertex as being complete
470 VertCount++;
472
473 // if we have 3 or more vertices, add a new poly
474 if (TriVertexCount >= 3) {
475
476 // check that we have room for a new poly
477 WWASSERT(PolyCount < Model->Get_Polygon_Count());
478
479 // set vertex indices
480 TriIndex *poly = &(Model->Get_Non_Const_Polygon_Array())[PolyCount];
481 if (TriMode == TRI_MODE_STRIPS) {
482 (*poly)[0] = VertCount-3;
483 (*poly)[1] = VertCount-2;
484 (*poly)[2] = VertCount-1;
485
486 // for every other tri, reverse vertex order
487 if (Flip_Face()) {
488 (*poly)[1] = VertCount-1;
489 (*poly)[2] = VertCount-2;
490 }
491 } else {
492 (*poly)[0] = FanVertex;
493 (*poly)[1] = VertCount-2;
494 (*poly)[2] = VertCount-1;
495 }
496
497 // check each pass
498 int pass = Get_Pass_Count();
499 while (pass--) {
500
501 // If we are multi texture
502 if (MultiTexture[pass]) {
504 Model->Set_Texture(PolyCount, tex, pass);
505 REF_PTR_RELEASE(tex);
506 }
507 }
508
509 // increase the count and record that we have a new material
510 PolyCount++;
511 Model->Set_Counts(PolyCount, VertCount);
512 }
513 return true;
514}
515
516/******************************************************************
517**
518** DynamicMeshClass
519**
520*******************************************************************/
521DynamicMeshClass::DynamicMeshClass(int max_poly, int max_vert) :
522 Model(NULL),
523 PolyCount(0),
524 VertCount(0),
526 FanVertex(0),
529{
530 int pass = MAX_PASSES;
531 while (pass--) {
532 MultiTexture[pass] = false;
533 TextureIdx[pass] = -1;
534
535 MultiVertexMaterial[pass] = false;
536 VertexMaterialIdx[pass] = -1;
537 }
538
539 for (int color_array_index = 0; color_array_index < MAX_COLOR_ARRAYS; color_array_index++) {
540 MultiVertexColor[color_array_index] = false;
541 CurVertexColor[color_array_index].Set(1.0f, 1.0f, 1.0f, 1.0f);
542 }
543
544 Model = NEW_REF(DynamicMeshModel, (max_poly, max_vert));
545}
546
547DynamicMeshClass::DynamicMeshClass(int max_poly, int max_vert, MaterialInfoClass *mat_info) :
548 Model(NULL),
549 PolyCount(0),
550 VertCount(0),
552 FanVertex(0),
555{
556 int pass = MAX_PASSES;
557 while (pass--) {
558 MultiTexture[pass] = false;
559 TextureIdx[pass] = -1;
560
561 MultiVertexMaterial[pass] = false;
562 VertexMaterialIdx[pass] = -1;
563 }
564
565 for (int color_array_index = 0; color_array_index < MAX_COLOR_ARRAYS; color_array_index++) {
566 MultiVertexColor[color_array_index] = false;
567 CurVertexColor[color_array_index].Set(1.0f, 1.0f, 1.0f, 1.0f);
568 }
569
570 Model = NEW_REF(DynamicMeshModel, (max_poly, max_vert, mat_info));
571}
572
574 RenderObjClass(src),
575 Model(NULL),
576 PolyCount(src.PolyCount),
577 VertCount(src.VertCount),
579 FanVertex(src.FanVertex),
580 TriMode(src.TriMode),
582{
583 int pass = MAX_PASSES;
584 while (pass--) {
585 MultiTexture[pass] = src.MultiTexture[pass];
586 TextureIdx[pass] = src.TextureIdx[pass];
587
589 VertexMaterialIdx[pass] = src.VertexMaterialIdx[pass];
590
591 MultiVertexColor[pass] = src.MultiVertexColor[pass];
592 CurVertexColor[pass] = src.CurVertexColor[pass];
593 }
594
595 for (int color_array_index = 0; color_array_index < MAX_COLOR_ARRAYS; color_array_index++) {
596 MultiVertexColor[color_array_index] = src.MultiVertexColor[color_array_index];
597 CurVertexColor[color_array_index] = src.CurVertexColor[color_array_index];
598 }
599
600 Model = NEW_REF(DynamicMeshModel, (*(src.Model)));
601}
602
603void DynamicMeshClass::Resize(int max_polys, int max_verts)
604{
605 Reset();
606
608 Model = NEW_REF(DynamicMeshModel, (max_polys, max_verts));
609
610 // reset all the texture & vertex material indices
611 int pass = MAX_PASSES;
612 while (pass--) {
613 TextureIdx[pass] = -1;
614 VertexMaterialIdx[pass] = -1;
615 MultiVertexMaterial[pass] = false;
616 }
617}
618
623
625{
626 return NEW_REF(DynamicMeshClass, (*this));
627}
628
629void DynamicMeshClass::Location(float x, float y, float z)
630{
631 Vector3 * loc = Model->Get_Vertex_Array();
632 assert(loc);
633
634 loc[VertCount].X = x;
635 loc[VertCount].Y = y;
636 loc[VertCount].Z = z;
637}
638
639/*
640** For moving a vertex after the DynaMesh has already been created.
641*/
642void DynamicMeshClass::Move_Vertex(int index, float x, float y, float z)
643{
644 Vector3 * loc = Model->Get_Vertex_Array();
645 assert(loc);
646 loc[index][0] = x;
647 loc[index][1] = y;
648 loc[index][2] = z;
649}
650
651/*
652** Get a vertex value.
653*/
654void DynamicMeshClass::Get_Vertex(int index, float &x, float &y, float &z)
655{
656 Vector3 * loc = Model->Get_Vertex_Array();
657 assert(loc);
658 x = loc[index][0];
659 y = loc[index][1];
660 z = loc[index][2];
661}
662
663
664/*
665** Offset the entire mesh
666*/
668{
669 Vector3 * loc = Model->Get_Vertex_Array();
670 assert(loc);
671 for (int i=0; i < Get_Num_Vertices(); i++) {
672 loc[i].X += offset.X;
673 loc[i].Y += offset.Y;
674 loc[i].Z += offset.Z;
675 }
676
679}
680
682{
683 assert(idx < Peek_Material_Info()->Vertex_Material_Count());
684 VertexMaterialIdx[pass] = idx;
685 if (!MultiVertexMaterial[pass]) {
686 // WWASSERT( VertexMaterialIdx[pass] == 0);
688 Model->Set_Single_Material(mat, pass);
689 mat->Release_Ref();
690 }
691 return VertexMaterialIdx[pass];
692}
693
694int DynamicMeshClass::Set_Vertex_Material(VertexMaterialClass *material, bool dont_search, int pass)
695{
696 // Check if same as the last vertex material
697 if (Peek_Material_Info()->Vertex_Material_Count() && (VertexMaterialIdx[pass] != -1) && Peek_Material_Info()->Peek_Vertex_Material(VertexMaterialIdx[pass]) == material) {
698 return VertexMaterialIdx[pass];
699 }
700
701 // if there are vertex materials in the list then we may have just jumped
702 // to becoming a multi-vertex-material object. Take care of that here.
703 if ((!MultiVertexMaterial[pass]) && Peek_Material_Info()->Vertex_Material_Count() && (VertexMaterialIdx[pass] != -1) && Peek_Material_Info()->Peek_Vertex_Material(VertexMaterialIdx[pass]) != material) {
704
705 // allocate the array of per-vertex vertex material overrides
707 Model->Initialize_Material_Array(pass, mat);
708 mat->Release_Ref();
709
710 // flag that we need to write the per -vertex vertex material override array
711 MultiVertexMaterial[pass] = true;
712 }
713
714 // add the material to the material info class if we cant find it in the
715 // list. if we are not supposed to search the list for it then just add
716 // it.
717 if (!dont_search) {
718 for (int lp = 0, found = 0; lp < Peek_Material_Info()->Vertex_Material_Count(); lp ++) {
720 if (material == mat) {
721 VertexMaterialIdx[pass] = lp;
722 found = true;
723 mat->Release_Ref();
724 break;
725 }
726 mat->Release_Ref();
727 }
728 if (!found) {
731 }
732 } else {
735 }
736
737 if (!MultiVertexMaterial[pass]) {
738 Model->Set_Single_Material(Peek_Material_Info()->Peek_Vertex_Material(VertexMaterialIdx[pass]), pass);
739 }
740 return(VertexMaterialIdx[pass]);
741}
742
743int DynamicMeshClass::Set_Texture(int idx, int pass)
744{
745 WWASSERT(idx < Peek_Material_Info()->Texture_Count());
746 TextureIdx[pass] = idx;
747 if (!MultiTexture[pass]) {
749 Model->Set_Single_Texture(tex, pass);
750 tex->Release_Ref();
751 }
752 return TextureIdx[pass];
753}
754
755int DynamicMeshClass::Set_Texture(TextureClass *texture, bool dont_search, int pass)
756{
757 // Check if same as the last texture
758 if (Peek_Material_Info()->Texture_Count() && (TextureIdx[pass] != -1) && Peek_Material_Info()->Peek_Texture(TextureIdx[pass]) == texture) {
759 return TextureIdx[pass];
760 }
761
762 // if there are textures in the list then we may have just jumped
763 // to becoming a multi-texture object. Take care of that here.
764 if ((!MultiTexture[pass]) && Peek_Material_Info()->Texture_Count() && (TextureIdx[pass] != -1) && Peek_Material_Info()->Peek_Texture(TextureIdx[pass]) != texture) {
765
766 // allocate the array of per polygon material over-rides
768 Model->Initialize_Texture_Array(pass, 0, tex);
769 tex->Release_Ref();
770
771 // flag that we need to write the per polygon material overide array
772 MultiTexture[pass] = true;
773 }
774
775 // add the material to the material info class if we cant find it in the
776 // list. if we are not supposed to search the list for it then just add
777 // it.
778 if (!dont_search) {
779 for (int lp = 0, found = 0; lp < Peek_Material_Info()->Texture_Count(); lp ++) {
781 if (texture == tex) {
782 TextureIdx[pass] = lp;
783 found = true;
784 tex->Release_Ref();
785 break;
786 }
787 tex->Release_Ref();
788 }
789 if (!found) {
792 }
793 } else {
796 }
797
798 if (!MultiTexture[pass]) {
800 Model->Set_Single_Texture(tex, pass);
801 tex->Release_Ref();
802 }
803 return(TextureIdx[pass]);
804}
805
806/*
807**
808*/
809// Remap locations to match a screen
810void DynamicScreenMeshClass::Location( float x, float y, float z)
811{
812 DynamicMeshClass::Location( (x * 2) - 1, Aspect - (y * 2 * Aspect), 0);
813}
814
815// For moving a vertex after the DynaMesh has already been created.
816void DynamicScreenMeshClass::Move_Vertex(int index, float x, float y, float z)
817{
818 DynamicMeshClass::Move_Vertex( index, (x * 2) - 1, Aspect - (y * 2 * Aspect), 0);
819}
820
821// Set position
826
832
833
#define NULL
Definition BaseType.h:92
#define WWASSERT
#define SORT_LEVEL_NONE
Definition w3d_file.h:1195
#define MIN(a, b)
Definition always.h:189
#define W3DNEW
Definition always.h:109
#define MAX(a, b)
Definition always.h:185
const FrustumClass & Get_Frustum(void) const
Definition camera.h:339
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static unsigned int Convert_Color_Clamp(const Vector4 &color)
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_Material(const VertexMaterialClass *material)
static void Set_Shader(const ShaderClass &shader)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
virtual void Location(float x, float y, float z)
Definition dynamesh.cpp:629
DynamicMeshClass(int max_poly, int max_vert)
Definition dynamesh.cpp:521
bool End_Vertex(void)
Definition dynamesh.cpp:440
virtual void Get_Vertex(int index, float &x, float &y, float &z)
Definition dynamesh.cpp:654
int TextureIdx[MAX_PASSES]
Definition dynamesh.h:423
virtual RenderObjClass * Clone(void) const
Definition dynamesh.cpp:624
void Set_Dirty_Bounds(void)
Definition dynamesh.h:378
virtual void Render(RenderInfoClass &rinfo)
Definition dynamesh.cpp:415
void Reset_Mesh_Counters()
Definition dynamesh.h:210
int VertexMaterialIdx[MAX_PASSES]
Definition dynamesh.h:421
int Get_Pass_Count()
Definition dynamesh.h:176
bool MultiVertexMaterial[MAX_PASSES]
Definition dynamesh.h:422
bool MultiTexture[MAX_PASSES]
Definition dynamesh.h:424
virtual void Reset(void)
Definition dynamesh.h:220
virtual int Get_Num_Vertices(void) const
Definition dynamesh.h:160
bool MultiVertexColor[MAX_COLOR_ARRAYS]
Definition dynamesh.h:427
Vector4 CurVertexColor[MAX_COLOR_ARRAYS]
Definition dynamesh.h:426
void Translate_Vertices(const Vector3 &offset)
Definition dynamesh.cpp:667
void Resize(int max_polys, int max_verts)
Definition dynamesh.cpp:603
void Reset_Flags()
Definition dynamesh.h:204
virtual bool Flip_Face(void)
Definition dynamesh.h:416
DynamicMeshModel * Model
Definition dynamesh.h:419
virtual void Move_Vertex(int index, float x, float y, float z)
Definition dynamesh.cpp:642
virtual ~DynamicMeshClass(void)
Definition dynamesh.cpp:619
int Set_Texture(int idx, int pass=0)
Definition dynamesh.cpp:743
void Set_Dirty_Planes(void)
Definition dynamesh.h:380
virtual MaterialInfoClass * Peek_Material_Info(void)
Definition dynamesh.h:151
int Set_Vertex_Material(int idx, int pass=0)
Definition dynamesh.cpp:681
void Set_Counts(int pnum, int vnum)
Definition dynamesh.h:82
void Initialize_Texture_Array(int pass, int stage, TextureClass *texture=NULL)
Definition dynamesh.cpp:399
virtual void Compute_Vertex_Normals(void)
Definition dynamesh.cpp:133
DynamicMeshModel(unsigned int max_polys, unsigned int max_verts)
Definition dynamesh.cpp:52
void Reset(void)
Definition dynamesh.cpp:167
virtual void Compute_Plane_Equations(void)
Definition dynamesh.cpp:114
virtual void Compute_Bounds(Vector3 *verts)
Definition dynamesh.cpp:152
~DynamicMeshModel(void)
Definition dynamesh.cpp:105
void Initialize_Material_Array(int pass, VertexMaterialClass *vmat=NULL)
Definition dynamesh.cpp:407
int Get_Pass_Count(void) const
Definition dynamesh.h:96
void Render(RenderInfoClass &rinfo)
Definition dynamesh.cpp:178
virtual void Location(float x, float y, float z=0.0f)
Definition dynamesh.cpp:810
virtual void Set_Position(const Vector3 &v)
Definition dynamesh.cpp:822
virtual void Move_Vertex(int index, float x, float y, float z=0.0f)
Definition dynamesh.cpp:816
virtual void Reset(void)
Definition dynamesh.cpp:827
VertexFormatXYZNDUV2 * Get_Formatted_Vertex_Array()
const FVFInfoClass & FVF_Info() const
unsigned Get_Tex_Offset(unsigned int n) const
Definition dx8fvf.h:274
unsigned Get_FVF_Size() const
Definition dx8fvf.h:280
unsigned Get_Diffuse_Offset() const
Definition dx8fvf.h:277
unsigned Get_Location_Offset() const
Definition dx8fvf.h:269
unsigned Get_Normal_Offset() const
Definition dx8fvf.h:270
void Set_Element(int index, VertexMaterialClass *mat)
int Add_Vertex_Material(VertexMaterialClass *vmat)
Definition matinfo.h:226
int Vertex_Material_Count(void) const
Definition matinfo.h:83
int Texture_Count(void) const
Definition matinfo.h:84
TextureClass * Get_Texture(int index)
Definition matinfo.cpp:93
VertexMaterialClass * Get_Vertex_Material(int index)
Definition matinfo.h:246
int Add_Texture(TextureClass *tex)
Definition matinfo.cpp:74
void Remap_Mesh(const MeshMatDescClass *srcmeshmatdesc, MeshMatDescClass *destmeshmatdesc)
Definition matinfo.cpp:216
void Get_Bounding_Sphere(SphereClass *set_sphere)
void Reset_Geometry(int polycount, int vertcount)
virtual void Compute_Plane_Equations(Vector4 *array)
virtual void Compute_Bounds(Vector3 *verts)
const Vector3 * Get_Vertex_Normal_Array(void)
int Get_Vertex_Count(void) const
const TriIndex * Get_Polygon_Array(void)
virtual void Compute_Vertex_Normals(Vector3 *array)
Vector4 * get_planes(bool create=true)
Vector3 * Get_Vertex_Array(void)
int Get_Polygon_Count(void) const
int Get_Flag(FlagsType flag)
Vector3 * get_vert_normals(void)
void Set_Polygon_Count(int polycount)
Definition meshmatdesc.h:94
WWINLINE void Release_Ref(void) const
Definition refcount.h:146
void Add_Ref(void) const
Definition refcount.cpp:171
CameraClass & Camera
Definition rinfo.h:100
virtual int Is_Not_Hidden_At_All(void)
Definition rendobj.h:463
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Position(const Vector3 &v)
Definition rendobj.cpp:444
virtual const AABoxClass & Get_Bounding_Box(void) const
Definition rendobj.h:575
Matrix3D Transform
Definition rendobj.h:549
T * Get_Array(void)
Definition sharebuf.h:63
static void Insert_Triangles(const SphereClass &bounding_sphere, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
void Set_Element(int index, TextureClass *mat)
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
unsigned short K
Definition Vector3i.h:102
unsigned short J
Definition Vector3i.h:101
unsigned short I
Definition Vector3i.h:100
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 bool Is_Sorting_Enabled(void)
Definition ww3d.h:220
const unsigned dynamic_fvf_type
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
@ BUFFER_TYPE_DYNAMIC_SORTING
Definition dx8wrapper.h:91
#define I(x, y, z)
Definition md5.cpp:89
Vector3i16 TriIndex
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define NEW_REF(C, P)
Definition refcount.h:62