NvBlastExtExporterFbxReader.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTEXTEXPORTERFBXREADER_H
30 #define NVBLASTEXTEXPORTERFBXREADER_H
31 
32 #include <memory>
33 #include "fbxsdk.h"
34 #include <vector>
35 #include <map>
36 #include "NvBlastExtExporter.h"
38 
39 namespace Nv
40 {
41 namespace Blast
42 {
43 class Mesh;
44 
46 {
47  struct CollisionHullImpl : public Nv::Blast::CollisionHull
48  {
49  //copy from existing
50  CollisionHullImpl(const CollisionHullImpl& other) : CollisionHullImpl()
51  {
52  copyFrom(other);
53  }
54 
55  CollisionHullImpl()
56  {
57  pointsCount = 0;
58  indicesCount = 0;
59  polygonDataCount = 0;
60  points = nullptr;
61  indices = nullptr;
62  polygonData = nullptr;
63  }
64 
65  CollisionHullImpl(CollisionHullImpl&& other)
66  {
67  operator=(std::move(other));
68  }
69 
70  CollisionHullImpl& operator=(const CollisionHullImpl& other)
71  {
72  if (&other != this)
73  {
74  delete[] points;
75  delete[] indices;
76  delete[] polygonData;
77  copyFrom(other);
78  }
79  return *this;
80  }
81 
82  CollisionHullImpl& operator=(CollisionHullImpl&& other)
83  {
84  if (&other != this)
85  {
86  pointsCount = other.pointsCount;
87  indicesCount = other.indicesCount;
88  polygonDataCount = other.polygonDataCount;
89  points = other.points;
90  indices = other.indices;
91  polygonData = other.polygonData;
92 
93  other.pointsCount = 0;
94  other.indicesCount = 0;
95  other.polygonDataCount = 0;
96  other.points = nullptr;
97  other.indices = nullptr;
98  other.polygonData = nullptr;
99  }
100  return *this;
101  }
102 
103  virtual ~CollisionHullImpl()
104  {
105  delete[] points;
106  delete[] indices;
107  delete[] polygonData;
108  }
109  private:
110 
111  void copyFrom(const CollisionHullImpl& other)
112  {
113  pointsCount = other.pointsCount;
114  indicesCount = other.indicesCount;
115  polygonDataCount = other.polygonDataCount;
116  points = new NvcVec3[pointsCount];
117  indices = new uint32_t[indicesCount];
118  polygonData = new Nv::Blast::HullPolygon[polygonDataCount];
119  memcpy(points, other.points, sizeof(points[0]) * pointsCount);
120  memcpy(indices, other.indices, sizeof(indices[0]) * indicesCount);
121  memcpy(polygonData, other.polygonData, sizeof(polygonData[0]) * polygonDataCount);
122  }
123  };
124 
125 public:
126  FbxFileReader();
127  ~FbxFileReader() = default;
128 
129  virtual void release() override;
130 
131  /*
132  Load from the specified file path, returning a mesh or nullptr if failed
133  */
134  virtual void loadFromFile(const char* filename) override;
135 
136  virtual uint32_t getVerticesCount() const override
137  {
138  return mVertexPositions.size();
139  }
140 
141  virtual uint32_t getIndicesCount() const override
142  {
143  return mIndices.size();
144  }
145 
149  virtual bool isCollisionLoaded() override;
150 
154  virtual uint32_t getCollision(uint32_t*& hullsOffset, Nv::Blast::CollisionHull**& hulls) override;
155 
156  virtual uint32_t getBoneInfluences(uint32_t*& out) override;
157 
158  virtual uint32_t getBoneCount() override;
159 
163  virtual NvcVec3* getPositionArray() override;
167  virtual NvcVec3* getNormalsArray() override;
171  virtual NvcVec2* getUvArray() override;
175  virtual uint32_t* getIndexArray() override;
176 
180  int32_t* getMaterialIds() override;
181 
185  int32_t* getSmoothingGroups() override;
186 
190  const char* getMaterialName(int32_t id) override;
191 
192 
193  int32_t getMaterialCount() override;
194 
195 private:
196 
197  uint32_t mMeshCount;
198  uint32_t mChunkCount;
199  std::vector<uint32_t> mHullsOffset;
200  std::vector<CollisionHullImpl> mHulls;
201  std::vector<uint32_t> mVertexToContainingChunkMap;
202  std::multimap<uint32_t, FbxNode*> mCollisionNodes;
203  std::vector<NvcVec3> mVertexPositions;
204  std::vector<NvcVec3> mVertexNormals;
205  std::vector<NvcVec2> mVertexUv;
206  std::vector<uint32_t> mIndices;
207  std::vector<int32_t> mSmoothingGroups;
208  std::vector<int32_t> mMaterialIds;
209  std::vector<std::string> mMaterialNames;
210 
211  FbxAMatrix getTransformForNode(FbxNode* node);
212  void getFbxMeshes(FbxDisplayLayer* collisionDisplayLayer, FbxNode* node, std::vector<FbxNode*>& meshNodes);
213  bool getCollisionInternal();
214  bool getBoneInfluencesInternal(FbxMesh* meshNode);
215 
216 };
217 
218 }
219 }
220 
221 #endif
virtual bool isCollisionLoaded() override
Definition: NvBlastExtExporterFbxReader.h:45
virtual uint32_t getBoneInfluences(uint32_t *&out) override
virtual uint32_t getCollision(uint32_t *&hullsOffset, Nv::Blast::CollisionHull **&hulls) override
virtual uint32_t * getIndexArray() override
virtual NvcVec3 * getPositionArray() override
int32_t * getMaterialIds() override
Definition: NvCTypes.h:43
const char * getMaterialName(int32_t id) override
Definition: NvBlastExtAuthoringTypes.h:120
Definition: NvBlastExtExporter.h:187
Definition: NvBlastExtAuthoringTypes.h:133
virtual void loadFromFile(const char *filename) override
int32_t getMaterialCount() override
virtual uint32_t getVerticesCount() const override
Definition: NvBlastExtExporterFbxReader.h:136
virtual NvcVec3 * getNormalsArray() override
int32_t * getSmoothingGroups() override
virtual NvcVec2 * getUvArray() override
virtual void release() override
virtual uint32_t getBoneCount() override
Definition: NvBlastArray.h:37
Definition: NvCTypes.h:49
virtual uint32_t getIndicesCount() const override
Definition: NvBlastExtExporterFbxReader.h:141