00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTEXTEXPORTERFBXREADER_H
00030 #define NVBLASTEXTEXPORTERFBXREADER_H
00031
00032 #include <memory>
00033 #include "fbxsdk.h"
00034 #include <vector>
00035 #include <map>
00036 #include "NvBlastExtExporter.h"
00037 #include "NvBlastExtAuthoringTypes.h"
00038
00039 namespace Nv
00040 {
00041 namespace Blast
00042 {
00043 class Mesh;
00044
00045 class FbxFileReader : public IFbxFileReader
00046 {
00047 struct CollisionHullImpl : public Nv::Blast::CollisionHull
00048 {
00049
00050 CollisionHullImpl(const CollisionHullImpl& other) : CollisionHullImpl()
00051 {
00052 copyFrom(other);
00053 }
00054
00055 CollisionHullImpl()
00056 {
00057 pointsCount = 0;
00058 indicesCount = 0;
00059 polygonDataCount = 0;
00060 points = nullptr;
00061 indices = nullptr;
00062 polygonData = nullptr;
00063 }
00064
00065 CollisionHullImpl(CollisionHullImpl&& other)
00066 {
00067 operator=(std::move(other));
00068 }
00069
00070 CollisionHullImpl& operator=(const CollisionHullImpl& other)
00071 {
00072 if (&other != this)
00073 {
00074 delete[] points;
00075 delete[] indices;
00076 delete[] polygonData;
00077 copyFrom(other);
00078 }
00079 return *this;
00080 }
00081
00082 CollisionHullImpl& operator=(CollisionHullImpl&& other)
00083 {
00084 if (&other != this)
00085 {
00086 pointsCount = other.pointsCount;
00087 indicesCount = other.indicesCount;
00088 polygonDataCount = other.polygonDataCount;
00089 points = other.points;
00090 indices = other.indices;
00091 polygonData = other.polygonData;
00092
00093 other.pointsCount = 0;
00094 other.indicesCount = 0;
00095 other.polygonDataCount = 0;
00096 other.points = nullptr;
00097 other.indices = nullptr;
00098 other.polygonData = nullptr;
00099 }
00100 return *this;
00101 }
00102
00103 virtual ~CollisionHullImpl()
00104 {
00105 delete[] points;
00106 delete[] indices;
00107 delete[] polygonData;
00108 }
00109 private:
00110
00111 void copyFrom(const CollisionHullImpl& other)
00112 {
00113 pointsCount = other.pointsCount;
00114 indicesCount = other.indicesCount;
00115 polygonDataCount = other.polygonDataCount;
00116 points = new NvcVec3[pointsCount];
00117 indices = new uint32_t[indicesCount];
00118 polygonData = new Nv::Blast::HullPolygon[polygonDataCount];
00119 memcpy(points, other.points, sizeof(points[0]) * pointsCount);
00120 memcpy(indices, other.indices, sizeof(indices[0]) * indicesCount);
00121 memcpy(polygonData, other.polygonData, sizeof(polygonData[0]) * polygonDataCount);
00122 }
00123 };
00124
00125 public:
00126 FbxFileReader();
00127 ~FbxFileReader() = default;
00128
00129 virtual void release() override;
00130
00131
00132
00133
00134 virtual void loadFromFile(const char* filename) override;
00135
00136 virtual uint32_t getVerticesCount() const override
00137 {
00138 return mVertexPositions.size();
00139 }
00140
00141 virtual uint32_t getIndicesCount() const override
00142 {
00143 return mIndices.size();
00144 }
00145
00149 virtual bool isCollisionLoaded() override;
00150
00154 virtual uint32_t getCollision(uint32_t*& hullsOffset, Nv::Blast::CollisionHull**& hulls) override;
00155
00156 virtual uint32_t getBoneInfluences(uint32_t*& out) override;
00157
00158 virtual uint32_t getBoneCount() override;
00159
00163 virtual NvcVec3* getPositionArray() override;
00167 virtual NvcVec3* getNormalsArray() override;
00171 virtual NvcVec2* getUvArray() override;
00175 virtual uint32_t* getIndexArray() override;
00176
00180 int32_t* getMaterialIds() override;
00181
00185 int32_t* getSmoothingGroups() override;
00186
00190 const char* getMaterialName(int32_t id) override;
00191
00192
00193 int32_t getMaterialCount() override;
00194
00195 private:
00196
00197 uint32_t mMeshCount;
00198 uint32_t mChunkCount;
00199 std::vector<uint32_t> mHullsOffset;
00200 std::vector<CollisionHullImpl> mHulls;
00201 std::vector<uint32_t> mVertexToContainingChunkMap;
00202 std::multimap<uint32_t, FbxNode*> mCollisionNodes;
00203 std::vector<NvcVec3> mVertexPositions;
00204 std::vector<NvcVec3> mVertexNormals;
00205 std::vector<NvcVec2> mVertexUv;
00206 std::vector<uint32_t> mIndices;
00207 std::vector<int32_t> mSmoothingGroups;
00208 std::vector<int32_t> mMaterialIds;
00209 std::vector<std::string> mMaterialNames;
00210
00211 FbxAMatrix getTransformForNode(FbxNode* node);
00212 void getFbxMeshes(FbxDisplayLayer* collisionDisplayLayer, FbxNode* node, std::vector<FbxNode*>& meshNodes);
00213 bool getCollisionInternal();
00214 bool getBoneInfluencesInternal(FbxMesh* meshNode);
00215
00216 };
00217
00218 }
00219 }
00220
00221 #endif