Newton Dynamics  4.00
ndMeshEffect.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_MESH_EFFECT_H__
23 #define __ND_MESH_EFFECT_H__
24 
25 #include "ndCollisionStdafx.h"
26 
27 #define DG_MESH_EFFECT_PRECISION_BITS 48
28 #define DG_MESH_EFFECT_PRECISION_SCALE ndFloat64(ndInt64(1)<<DG_MESH_EFFECT_PRECISION_BITS)
29 #define DG_MESH_EFFECT_PRECISION_SCALE_INV (ndFloat64 (1.0f) / DG_MESH_EFFECT_PRECISION_SCALE)
30 
31 #define DG_VERTEXLIST_INDEXLIST_TOL (ndFloat64 (0.0f))
32 #define DG_MESH_EFFECT_POINT_SPLITED 512
33 #define DG_MESH_EFFECT_BVH_STACK_DEPTH 256
34 
35 class ndShapeInstance;
36 
38 {
39  public:
40  ndInt32 m_materialCount;
41  ndInt32 m_indexCount;
42  ndInt32 m_materials[256];
43  ndInt32 m_materialsIndexCount[256];
44  ndInt32* m_indexList;
45 };
46 
48 {
49 #if 0
50  public:
51  class dMeshBVH
52  {
53  public:
54  class dgMeshBVHNode
55  {
56  public:
57  dgMeshBVHNode (const ndMeshEffect* const mesh, dEdge* const face, void* const userData);
58  dgMeshBVHNode (dgMeshBVHNode* const left, dgMeshBVHNode* const right);
59  ~dgMeshBVHNode ();
60  void SetBox (const dVector& p0, const dVector& p1);
61 
62  DG_CLASS_ALLOCATOR(allocator)
63  dVector m_p0;
64  dVector m_p1;
65 
66  dFloat32 m_area;
67  dEdge* m_face;
68  void* m_userData;
69  dgMeshBVHNode* m_left;
70  dgMeshBVHNode* m_right;
71  dgMeshBVHNode* m_parent;
72  };
73 
74  class dgFitnessList: public dTree <dgMeshBVHNode*, dgMeshBVHNode*>
75  {
76  public:
77  dgFitnessList (dMemoryAllocator___* const allocator);
78  dFloat64 TotalCost () const;
79  };
80 
81 
82  dMeshBVH (const ndMeshEffect* const mesh);
83  virtual ~dMeshBVH();
84 
85  virtual void Build ();
86  virtual void Cleanup ();
87 
88  void FaceRayCast (const dBigVector& l0, const dBigVector& l1, void* const userData) const;
89  void GetOverlapNodes (dList<dgMeshBVHNode*>& overlapNodes, const dBigVector& p0, const dBigVector& p1) const;
90 
91  protected:
92  virtual dgMeshBVHNode* CreateLeafNode (dEdge* const face, void* const userData) = 0;
93 
94  dgMeshBVHNode* AddFaceNode (dEdge* const face, void* const userData);
95  void RemoveNode (dgMeshBVHNode* const treeNode);
96  void ImproveNodeFitness ();
97  void ImproveNodeFitness (dgMeshBVHNode* const node);
98  dFloat32 CalculateSurfaceArea (dgMeshBVHNode* const node0, dgMeshBVHNode* const node1, dVector& minBox, dVector& maxBox) const;
99  virtual bool SanityCheck() const;
100 
101  virtual dFloat64 RayFaceIntersect (const dgMeshBVHNode* const face, const dBigVector& p0, const dBigVector& p1, void* const userData) const;
102 // virtual dFloat64 VertexRayCast (const dBigVector& l0, const dBigVector& l1) const;
103 // virtual bool RayRayIntersect (dEdge* const edge, const ndMeshEffect* const otherMesh, dEdge* const otherEdge, dFloat64& param, dFloat64& otherParam) const;
104 
105  const ndMeshEffect* m_mesh;
106  dgMeshBVHNode* m_rootNode;
107  dgFitnessList m_fitness;
108  friend class ndMeshEffect;
109  };
110 
111 
112  ndMeshEffect(dMemoryAllocator___* const allocator);
113  ndMeshEffect(dgCollisionInstance* const collision);
114  ndMeshEffect(const ndMeshEffect& source);
115  ndMeshEffect (dMemoryAllocator___* const allocator, dgDeserialize deserialization, void* const userData);
116 
117  // create from OFF or PLY file format
118  ndMeshEffect(dMemoryAllocator___* const allocator, const char* const fileName);
119 
120  // Create a convex hull Mesh form point cloud
121  ndMeshEffect (dMemoryAllocator___* const allocator, const dFloat64* const vertexCloud, dInt32 count, dInt32 strideInByte, dFloat64 distTol);
122 
123  // create a planar Mesh
124  ndMeshEffect(dMemoryAllocator___* const allocator, const dMatrix& planeMatrix, dFloat32 witdth, dFloat32 breadth, dInt32 material, const dMatrix& textureMatrix0, const dMatrix& textureMatrix1);
125 
126  void Trace () const;
127  void CylindricalMapping (dInt32 cylinderMaterial, dInt32 capMaterial, const dMatrix& uvAligment);
128  void AngleBaseFlatteningMapping (dInt32 cylinderMaterial, dgReportProgress progressReportCallback, void* const userData);
129 
130  ndMeshEffect* Union (const dMatrix& matrix, const ndMeshEffect* const clipper) const;
131  ndMeshEffect* Difference (const dMatrix& matrix, const ndMeshEffect* const clipper) const;
132  ndMeshEffect* Intersection (const dMatrix& matrix, const ndMeshEffect* const clipper) const;
133  void ClipMesh (const dMatrix& matrix, const ndMeshEffect* const clipper, ndMeshEffect** const top, ndMeshEffect** const bottom) const;
134 
135  //bool PlaneClip (const dBigPlane& plane);
136 
137 
138 
139  dInt32 GetVertexBaseCount() const;
140  void SetVertexBaseCount(dInt32 count);
141 
142  dEdge* SpliteFace (dInt32 v0, dInt32 v1);
143 
144  dInt32 GetTotalFaceCount() const;
145  dInt32 GetTotalIndexCount() const;
146  void GetFaces (dInt32* const faceCount, dInt32* const materials, void** const faceNodeList) const;
147 
148  void OptimizePoints();
149  void OptimizeAttibutes();
150  const dInt32* GetIndexToVertexMap() const;
151 
152  bool HasLayersChannel() const;
153  bool HasNormalChannel() const;
154  bool HasBinormalChannel() const;
155  bool HasUV0Channel() const;
156  bool HasUV1Channel() const;
157  bool HasVertexColorChannel() const;
158 
159  dgCollisionInstance* CreateCollisionTree(dgWorld* const world, dInt32 shapeID) const;
160  ndMeshEffect* CreateSimplification (dInt32 maxVertexCount, dgReportProgress reportProgressCallback, void* const userData) const;
161  ndMeshEffect* CreateConvexApproximation (dFloat32 maxConcavity, dFloat32 backFaceDistanceFactor, dInt32 maxHullOuputCount, dInt32 maxVertexPerHull, dgReportProgress reportProgressCallback, void* const userData) const;
162 
163  ndMeshEffect* CreateTetrahedraIsoSurface() const;
164  void CreateTetrahedraLinearBlendSkinWeightsChannel (const ndMeshEffect* const tetrahedraMesh);
165 
166 
167  static ndMeshEffect* CreateFromSerialization (dMemoryAllocator___* const allocator, dgDeserialize deserialization, void* const userData);
168 
169  void LoadOffMesh (const char* const filename);
170  void LoadTetraMesh (const char* const filename);
171  void Serialize (dgSerialize callback, void* const userData) const;
172 
173  dBigVector GetVertex (dInt32 index) const;
174  dInt32 GetVertexLayer (dInt32 index) const;
175 
176  void TransformMesh (const dMatrix& matrix);
177 
178  void* GetFirstVertex () const;
179  void* GetNextVertex (const void* const vertex) const;
180  dInt32 GetVertexIndex (const void* const vertex) const;
181 
182  void* GetFirstPoint () const;
183  void* GetNextPoint (const void* const point) const;
184  dInt32 GetPointIndex (const void* const point) const;
185  dInt32 GetVertexIndexFromPoint (const void* const point) const;
186 
187  void* GetFirstEdge () const;
188  void* GetNextEdge (const void* const edge) const;
189 // void* FindEdge (dInt32 v0, dInt32 v1) const;
190  void GetEdgeIndex (const void* const edge, dInt32& v0, dInt32& v1) const;
191 // void GetEdgeAttributeIndex (const void* edge, dInt32& v0, dInt32& v1) const;
192 
193  const dEdge* GetPolyhedraEdgeFromNode(const void* const edge) const;
194 
195  void* GetFirstFace () const;
196  void* GetNextFace (const void* const face) const;
197  dInt32 IsFaceOpen (const void* const face) const;
198  dInt32 GetFaceIndexCount (const void* const face) const;
199  void GetFaceIndex (const void* const face, dInt32* const indices) const;
200  void GetFaceAttributeIndex (const void* const face, dInt32* const indices) const;
201  dBigVector CalculateFaceNormal (const void* const face) const;
202 
203  void SetFaceMaterial (const void* const face, dInt32 materialID);
204  dInt32 InterpolateVertex (const dBigVector& point, const dEdge* const face) const;
205 
206  protected:
207  dBigVector GetOrigin ()const;
208  dInt32 CalculateMaxAttributes () const;
209 // void ReverseMergeFaces (ndMeshEffect* const source);
210 
211 #endif
212 
213  enum ndChannelType
214  {
215  m_vertex,
216  m_normal,
217  m_binormal,
218  m_uv0,
219  m_uv1,
220  m_color,
221  m_material,
222  m_layer,
223  m_point,
224  };
225 
226  template<class T, ndChannelType type>
227  class ndChannel: public ndArray<T>
228  {
229  public:
230  ndChannel();
231  ndChannel(const ndChannel& source);
232  ~ndChannel();
233 
234  void Clear();
235  void PushBack(const T& element);
236 
237  ndChannelType m_type;
238  bool m_isValid;
239  };
240 
241  class ndFormat
242  {
243  public:
244  class ndSortCluster;
245 
246  class ndSortKey
247  {
248  public:
249  ndInt32 m_mask;
250  ndInt32 m_ordinal;
251  ndInt32 m_vertexIndex;
252  ndInt32 m_attibuteIndex;
253  };
254 
256  {
257  public:
258  const ndChannel<ndBigVector, m_point>* m_points;
259  ndInt32 m_vertexSortIndex;
260  };
261 
262  static ndInt32 CompareVertex(const ndSortKey* const ptr0, const ndSortKey* const ptr1, void* const context);
263  };
264 
265  class ndPointFormat: public ndFormat
266  {
267  public:
268  ndPointFormat();
269  ndPointFormat(const ndPointFormat& source);
270  ~ndPointFormat();
271 
272  void Clear();
273  void SetCount(ndInt32 count);
274  void CompactVertexData(ndInt32* const indexList, ndFloat32 tol);
275 
276  private:
277  void CompressData(ndPointFormat& output, ndInt32* const indexList, ndSortKey* const remapIndex, const ndSortCluster& batch, ndFloat32 tol);
278 
279  public:
280  ndChannel<ndInt32, m_layer> m_layers;
281  ndChannel<ndBigVector, m_point> m_vertex;
282  };
283 
284  class ndAttibutFormat: public ndFormat
285  {
286  public:
287  class dgUV
288  {
289  public:
290  ndFloat32 m_u;
291  ndFloat32 m_v;
292  };
293 
294  ndAttibutFormat();
295  ndAttibutFormat(const ndAttibutFormat& source);
296  ~ndAttibutFormat();
297 
298  void Clear();
299  void SetCount(ndInt32 count);
300  void CopyFrom(const ndAttibutFormat& source);
301  void CopyEntryFrom(ndInt32 index, const ndAttibutFormat& source, ndInt32 sourceIndex);
302  void CompactVertexData(const ndPointFormat& points, ndInt32* const indexList, ndFloat32 tol);
303 
304  private:
305  void CompressData(ndAttibutFormat& output, const ndPointFormat& points, ndInt32* const indexList, ndSortKey* const remapIndex, const ndSortCluster& batch, ndFloat32 tol);
306 
307  public:
308  ndChannel<ndInt32, m_vertex> m_pointChannel;
309  ndChannel<ndInt32, m_material> m_materialChannel;
310  ndChannel<ndTriplex, m_normal> m_normalChannel;
311  ndChannel<ndTriplex, m_binormal> m_binormalChannel;
312  ndChannel<ndVector, m_color> m_colorChannel;
313  ndChannel<dgUV, m_uv0> m_uv0Channel;
314  ndChannel<dgUV, m_uv1> m_uv1Channel;
315  };
316 
317  public:
319  {
320  public:
321  ndMaterial()
322  :m_ambient(ndFloat32(0.8f), ndFloat32(0.8f), ndFloat32(0.8f), ndFloat32(1.0f))
323  ,m_diffuse(ndFloat32(0.8f), ndFloat32(0.8f), ndFloat32(0.8f), ndFloat32(1.0f))
324  ,m_specular(ndFloat32(1.0f), ndFloat32(1.0f), ndFloat32(1.0f), ndFloat32(1.0f))
325  ,m_opacity(ndFloat32(1.0f))
326  ,m_shiness(ndFloat32 (60.0f))
327  {
328  //m_textureName[0] = 0;
329  strcpy(m_textureName, "default.tga");
330  }
331 
332  ndVector m_ambient;
333  ndVector m_diffuse;
334  ndVector m_specular;
335  ndFloat32 m_opacity;
336  ndFloat32 m_shiness;
337  char m_textureName[32];
338  };
339 
341  {
342  public:
344  {
345  public:
346  const ndFloat64* m_data;
347  const ndInt32* m_indexList;
348  ndInt32 m_strideInBytes;
349  };
350 
352  {
353  public:
354  const ndFloat32* m_data;
355  const ndInt32* m_indexList;
356  ndInt32 m_strideInBytes;
357  };
358 
360  {
361  Clear();
362  }
363 
364  void Clear()
365  {
366  memset(this, 0, sizeof(dMeshVertexFormat));
367  }
368 
369  ndInt32 m_faceCount;
370  const ndInt32* m_faceIndexCount;
371  const ndInt32* m_faceMaterial;
372  dDoubleData m_vertex;
373  dFloatData m_normal;
374  dFloatData m_binormal;
375  dFloatData m_uv0;
376  dFloatData m_uv1;
377  dFloatData m_vertexColor;
378  };
379 
381  {
382  public:
384  {
385  }
386  ndArray<ndInt32> m_vertexIndex;
387  ndArray<ndFloat32> m_vertexWeigh;
388  };
389 
390  class dClusterMap: public ndTree<dVertexCluster, const ndString>
391  {
392  };
393 
394  D_COLLISION_API ndMeshEffect();
395  D_COLLISION_API ndMeshEffect(const ndMeshEffect& source);
396  D_COLLISION_API ndMeshEffect(const ndShapeInstance& shapeInstance);
397  D_COLLISION_API ndMeshEffect(ndPolyhedra& mesh, const ndMeshEffect& source);
398 
399  // Create a convex hull Mesh from point cloud
400  D_COLLISION_API ndMeshEffect(const ndFloat64* const vertexCloud, ndInt32 count, ndInt32 strideInByte, ndFloat64 distTol);
401 
402  D_COLLISION_API virtual ~ndMeshEffect();
403 
404  void SetName (const ndString& name);
405  const ndString& GetName() const;
406 
407  ndArray<ndMaterial>& GetMaterials();
408  ndInt32 GetPropertiesCount() const;
409 
410  ndInt32 GetVertexCount() const;
411  ndInt32 GetVertexStrideInByte() const;
412  const ndFloat64* GetVertexPool() const;
413 
414  ndInt32 GetFaceMaterial(ndEdge* const faceEdge) const;
415 
416  const dClusterMap& GetCluster() const;
417  D_COLLISION_API dVertexCluster* CreateCluster(const char* const name);
418  D_COLLISION_API dVertexCluster* FindCluster(const char* const name) const;
419 
420  D_COLLISION_API ndFloat64 CalculateVolume() const;
421  D_COLLISION_API ndMatrix CalculateOOBB(ndBigVector& size) const;
422  D_COLLISION_API void CalculateAABB(ndBigVector& min, ndBigVector& max) const;
423 
424  D_COLLISION_API void ApplyTransform(const ndMatrix& matrix);
425  D_COLLISION_API void CalculateNormals(ndFloat64 angleInRadians);
426  D_COLLISION_API void BuildFromIndexList(const dMeshVertexFormat* const format);
427 
428  D_COLLISION_API void GetVertexIndexChannel(ndInt32* const bufferOut) const;
429  D_COLLISION_API void GetVertexChannel64(ndInt32 strideInByte, ndFloat64* const bufferOut) const;
430  D_COLLISION_API void GetVertexChannel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
431  D_COLLISION_API void GetNormalChannel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
432  D_COLLISION_API void GetBinormalChannel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
433  D_COLLISION_API void GetUV0Channel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
434  D_COLLISION_API void GetUV1Channel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
435  D_COLLISION_API void GetVertexColorChannel(ndInt32 strideInByte, ndFloat32* const bufferOut) const;
436 
437  D_COLLISION_API ndIndexArray* MaterialGeometryBegin();
438  D_COLLISION_API ndInt32 GetFirstMaterial(ndIndexArray* const handle) const;
439  D_COLLISION_API ndInt32 GetNextMaterial(ndIndexArray* const handle, ndInt32 materialHandle) const;
440  D_COLLISION_API ndInt32 GetMaterialID(ndIndexArray* const handle, ndInt32 materialHandle) const;
441  D_COLLISION_API ndInt32 GetMaterialIndexCount(ndIndexArray* const handle, ndInt32 materialHandle) const;
442  D_COLLISION_API void GetMaterialGetIndexStream(ndIndexArray* const handle, ndInt32 materialHandle, ndInt32* const index) const;
443  D_COLLISION_API void GetMaterialGetIndexStream(ndIndexArray* const handle, ndInt32 materialHandle, ndInt16* const index) const;
444  D_COLLISION_API void MaterialGeometryEnd(ndIndexArray* const handle);
445 
446  D_COLLISION_API void BeginBuild();
447  D_COLLISION_API void BeginBuildFace();
448  D_COLLISION_API void AddPoint(ndFloat64 x, ndFloat64 y, ndFloat64 z);
449  D_COLLISION_API void AddLayer(ndInt32 layer);
450  D_COLLISION_API void AddMaterial(ndInt32 materialIndex);
451  D_COLLISION_API void AddNormal(ndFloat32 x, ndFloat32 y, ndFloat32 z);
452  D_COLLISION_API void AddBinormal(ndFloat32 x, ndFloat32 y, ndFloat32 z);
453  D_COLLISION_API void AddVertexColor(ndFloat32 x, ndFloat32 y, ndFloat32 z, ndFloat32 w);
454  D_COLLISION_API void AddUV0(ndFloat32 u, ndFloat32 v);
455  D_COLLISION_API void AddUV1(ndFloat32 u, ndFloat32 v);
456  D_COLLISION_API void EndBuildFace();
457  D_COLLISION_API void EndBuild(bool fixTjoint = true);
458 
459  D_COLLISION_API ndBigVector GetOrigin()const;
460  D_COLLISION_API void SphericalMapping(ndInt32 materialIndex, const ndMatrix& textureMatrix);
461  D_COLLISION_API void UniformBoxMapping(ndInt32 materialIndex, const ndMatrix& textureMatrix);
462  D_COLLISION_API void BoxMapping(ndInt32 front, ndInt32 side, ndInt32 top, const ndMatrix& textureMatrix);
463  D_COLLISION_API void RepairTJoints();
464 
465  ndMeshEffect* GetFirstLayer();
466  ndMeshEffect* GetNextLayer(ndMeshEffect* const layer);
467 
468  D_COLLISION_API void FlipWinding();
469  D_COLLISION_API bool HasOpenEdges() const;
470  D_COLLISION_API void Triangulate();
471  D_COLLISION_API void ConvertToPolygons();
472  D_COLLISION_API ndEdge* InsertEdgeVertex(ndEdge* const edge, ndFloat64 param);
473  D_COLLISION_API void AddInterpolatedEdgeAttribute(ndEdge* const edge, ndFloat64 param);
474  D_COLLISION_API void RemoveUnusedVertices(ndInt32* const vertexRemapTable);
475  D_COLLISION_API ndInt32 PlaneClip(const ndMeshEffect& convexMesh, const ndEdge* const face);
476  D_COLLISION_API ndShapeInstance* CreateConvexCollision(ndFloat64 tolerance) const;
477  D_COLLISION_API ndMeshEffect* ConvexMeshIntersection(const ndMeshEffect* const convexMesh) const;
478  D_COLLISION_API ndMeshEffect* InverseConvexMeshIntersection(const ndMeshEffect* const convexMesh) const;
479  D_COLLISION_API ndMeshEffect* CreateVoronoiConvexDecomposition(const ndArray<ndVector>& pointCloud, ndInt32 interiorMaterialIndex, const ndMatrix& textureProjectionMatrix);
480 
481  protected:
482  D_COLLISION_API void Init();
483  D_COLLISION_API virtual void BeginFace();
484  D_COLLISION_API virtual bool EndFace();
485  ndFloat64 QuantizeCordinade(ndFloat64 val) const;
486 
487  bool Sanity() const;
488  void PackPoints();
489  void UnpackPoints();
490  void PackAttibuteData();
491  void UnpackAttibuteData();
492  bool SeparateDuplicateLoops(ndEdge* const face);
493  ndInt32 AddInterpolatedHalfAttribute(ndEdge* const edge, ndInt32 midPoint);
494 
495  void MergeFaces(const ndMeshEffect* const source);
496  D_COLLISION_API ndMeshEffect* GetNextLayer(ndInt32 mark);
497 
498  ndString m_name;
499  ndPointFormat m_points;
500  ndAttibutFormat m_attrib;
501  dClusterMap m_clusters;
502  ndArray<ndMaterial> m_materials;
503  ndInt32 m_vertexBaseCount;
504  ndInt32 m_constructionIndex;
505 };
506 
507 #if 0
508 
509 inline dInt32 ndMeshEffect::GetVertexBaseCount() const
510 {
511  return m_vertexBaseCount;
512 }
513 
514 inline void ndMeshEffect::SetVertexBaseCount(dInt32 count)
515 {
516  m_vertexBaseCount = count;
517 }
518 
519 
520 inline const dInt32* ndMeshEffect::GetIndexToVertexMap() const
521 {
522  return &m_attrib.m_pointChannel[0];
523 }
524 
525 inline dBigVector ndMeshEffect::GetVertex (dInt32 index) const
526 {
527  dAssert(index >= 0);
528  dAssert(index < m_points.m_vertex.m_count);
529  return m_points.m_vertex[index];
530 }
531 
532 inline bool ndMeshEffect::HasLayersChannel() const
533 {
534  return m_points.m_layers.m_count != 0;
535 }
536 
537 inline dInt32 ndMeshEffect::GetVertexLayer(dInt32 index) const
538 {
539  dAssert(index >= 0);
540  dAssert(index < m_points.m_vertex.m_count);
541  return (m_points.m_layers.m_count) ? m_points.m_layers[index] : 0;
542 }
543 #endif
544 
545 inline ndFloat64 ndMeshEffect::QuantizeCordinade(ndFloat64 x) const
546 {
547  ndInt32 exp;
548  ndFloat64 mantissa = frexp(x, &exp);
549  mantissa = DG_MESH_EFFECT_PRECISION_SCALE_INV * floor (mantissa * DG_MESH_EFFECT_PRECISION_SCALE);
550 
551  ndFloat64 x1 = ldexp(mantissa, exp);
552  return x1;
553 }
554 
555 template<class T, ndMeshEffect::ndChannelType type>
556 ndMeshEffect::ndChannel<T, type>::ndChannel()
557  :ndArray<T>()
558  ,m_type(type)
559  ,m_isValid(false)
560 {
561 }
562 
563 template<class T, ndMeshEffect::ndChannelType type>
564 ndMeshEffect::ndChannel<T, type>::ndChannel(const ndChannel& source)
565  :ndArray<T>(source)
566  ,m_type(source.m_type)
567  ,m_isValid(source.m_isValid)
568 {
569 }
570 
571 template<class T, ndMeshEffect::ndChannelType type>
572 ndMeshEffect::ndChannel<T, type>::~ndChannel()
573 {
574 }
575 
576 template<class T, ndMeshEffect::ndChannelType type>
577 void ndMeshEffect::ndChannel<T, type>::Clear()
578 {
579  m_isValid = false;
581 }
582 
583 template<class T, ndMeshEffect::ndChannelType type>
584 void ndMeshEffect::ndChannel<T, type>::PushBack(const T& element)
585 {
586  T tmp(element);
587  m_isValid = true;
589 }
590 
591 inline ndMeshEffect::ndPointFormat::ndPointFormat()
592  :m_layers()
593  ,m_vertex()
594 {
595 }
596 
597 inline ndMeshEffect::ndPointFormat::ndPointFormat(const ndPointFormat& source)
598  :m_layers(source.m_layers)
599  ,m_vertex(source.m_vertex)
600 {
601 }
602 
603 inline ndMeshEffect::ndPointFormat::~ndPointFormat()
604 {
605 }
606 
607 inline void ndMeshEffect::ndPointFormat::Clear()
608 {
609  m_layers.Clear();
610  m_vertex.Clear();
611 }
612 
613 inline void ndMeshEffect::ndPointFormat::SetCount(ndInt32 count)
614 {
615  m_vertex.Resize(count);
616  m_vertex.SetCount(count);
617 
618  m_layers.Resize(count);
619  m_layers.SetCount(count);
620 }
621 
622 inline ndMeshEffect::ndAttibutFormat::ndAttibutFormat()
623  :m_pointChannel()
624  ,m_materialChannel()
625  ,m_normalChannel()
626  ,m_binormalChannel()
627  ,m_colorChannel()
628  ,m_uv0Channel()
629  ,m_uv1Channel()
630 {
631 }
632 
633 inline ndMeshEffect::ndAttibutFormat::ndAttibutFormat(const ndAttibutFormat& source)
634  :m_pointChannel(source.m_pointChannel)
635  ,m_materialChannel(source.m_materialChannel)
636  ,m_normalChannel(source.m_normalChannel)
637  ,m_binormalChannel(source.m_binormalChannel)
638  ,m_colorChannel(source.m_colorChannel)
639  ,m_uv0Channel(source.m_uv0Channel)
640  ,m_uv1Channel(source.m_uv1Channel)
641 {
642 }
643 
644 inline ndMeshEffect::ndAttibutFormat::~ndAttibutFormat()
645 {
646 }
647 
648 inline void ndMeshEffect::ndAttibutFormat::Clear()
649 {
650  m_pointChannel.Clear();
651  m_materialChannel.Clear();
652  m_normalChannel.Clear();
653  m_binormalChannel.Clear();
654  m_colorChannel.Clear();
655  m_uv0Channel.Clear();
656  m_uv1Channel.Clear();
657 }
658 
659 inline void ndMeshEffect::ndAttibutFormat::SetCount(ndInt32 count)
660 {
661  m_pointChannel.Resize(count);
662  m_pointChannel.SetCount(count);
663 
664  m_materialChannel.Resize(count);
665  m_materialChannel.SetCount(count);
666 
667  m_normalChannel.Resize(count);
668  m_normalChannel.SetCount(count);
669 
670  m_binormalChannel.Resize(count);
671  m_binormalChannel.SetCount(count);
672 
673  m_colorChannel.Resize(count);
674  m_colorChannel.SetCount(count);
675 
676  m_uv0Channel.Resize(count);
677  m_uv0Channel.SetCount(count);
678 
679  m_uv1Channel.Resize(count);
680  m_uv1Channel.SetCount(count);
681 }
682 
683 inline ndInt32 ndMeshEffect::GetPropertiesCount() const
684 {
685  return m_attrib.m_pointChannel.GetCount();
686 }
687 
688 inline void ndMeshEffect::SetName(const ndString& name)
689 {
690  m_name = name;
691 }
692 
693 inline const ndString& ndMeshEffect::GetName() const
694 {
695  return m_name;
696 }
697 
698 inline ndArray<ndMeshEffect::ndMaterial>& ndMeshEffect::GetMaterials()
699 {
700  return m_materials;
701 }
702 
703 inline ndInt32 ndMeshEffect::GetVertexCount() const
704 {
705  return m_points.m_vertex.GetCount();
706 }
707 
708 inline ndInt32 ndMeshEffect::GetVertexStrideInByte() const
709 {
710  return sizeof(ndBigVector);
711 }
712 
713 inline const ndFloat64* ndMeshEffect::GetVertexPool() const
714 {
715  return &m_points.m_vertex[0].m_x;
716 }
717 
718 inline ndInt32 ndMeshEffect::GetFaceMaterial(ndEdge* const faceEdge) const
719 {
720  return ndInt32(m_attrib.m_materialChannel.GetCount() ? m_attrib.m_materialChannel[ndInt32(faceEdge->m_userData)] : 0);
721 }
722 
723 inline ndMeshEffect* ndMeshEffect::GetFirstLayer()
724 {
725  return GetNextLayer(IncLRU());
726 }
727 
728 inline ndMeshEffect* ndMeshEffect::GetNextLayer(ndMeshEffect* const layerSegment)
729 {
730  if (!layerSegment)
731  {
732  return nullptr;
733  }
734  return GetNextLayer(layerSegment->IncLRU() - 1);
735 }
736 
737 inline const ndMeshEffect::dClusterMap& ndMeshEffect::GetCluster() const
738 {
739  return m_clusters;
740 }
741 
742 #endif
ndMeshEffect::dVertexCluster
Definition: ndMeshEffect.h:381
ndEdge
Definition: ndPolyhedra.h:44
ndIndexArray
Definition: ndMeshEffect.h:38
ndMeshEffect::ndFormat::ndVertexSortData
Definition: ndMeshEffect.h:256
ndString
Definition: ndString.h:20
ndArray
Generic template vector.
Definition: ndArray.h:42
ndSortCluster
Definition: ndUtils.cpp:79
ndTree
Definition: ndTree.h:82
ndArray::PushBack
void PushBack(const T &element)
Add element to the end of the buffer.
Definition: ndArray.h:170
ndMeshEffect::ndFormat::ndSortCluster
Definition: ndMeshEffect1.cpp:1656
ndSortKey
Definition: ndUtils.cpp:88
ndMeshEffect::dClusterMap
Definition: ndMeshEffect.h:391
ndMeshEffect
Definition: ndMeshEffect.h:48
ndMeshEffect::dMeshVertexFormat
Definition: ndMeshEffect.h:341
ndMeshEffect::ndMaterial
Definition: ndMeshEffect.h:319
ndMeshEffect::dMeshVertexFormat::dFloatData
Definition: ndMeshEffect.h:352
ndMatrix
Definition: ndMatrix.h:42
ndMeshEffect::ndAttibutFormat::dgUV
Definition: ndMeshEffect.h:288
ndPolyhedra
Definition: ndPolyhedra.h:60
ndBigVector
Definition: ndVectorArmNeon.h:463
ndMeshEffect::ndFormat::ndSortKey
Definition: ndMeshEffect.h:247
ndMeshEffect::dMeshVertexFormat::dDoubleData
Definition: ndMeshEffect.h:344
ndShapeInstance
Definition: ndShapeInstance.h:62
ndArray::SetCount
void SetCount(ndInt32 count)
Set a new size.
Definition: ndArray.h:188
ndVector
Definition: ndVectorArmNeon.h:41