#ifndef GLTFJSONSTRUCTURE_H #define GLTFJSONSTRUCTURE_H #include "OdaCommon.h" #include "OdVector.h" #include "Ge/GeMatrix3d.h" #include "Ge/GeQuaternion.h" #include "Ge/GeScale3d.h" #define STL_USING_MAP #include "OdaSTL.h" namespace GLTFFileImport { /** \details This class represents parsed JSON structure of the glTF file */ namespace JSON { struct ColorFactor { ColorFactor() = default; ColorFactor(float r, float g, float b, float a = 1.f) { this->r = r; this->g = g; this->b = b; this->a = a; } ColorFactor(float val) { r = val; g = val; b = val; a = val; } ColorFactor(const ColorFactor& other) : r(other.r), g(other.g), b(other.b), a(other.a) {} float r = 1; float g = 1; float b = 1; float a = 1; }; struct OdSceneContent { OdSceneContent() {} OdSceneContent(const OdArray& aNodeIndices) : aNodesIdxs(aNodeIndices) {} OdSceneContent(const OdSceneContent& otherScene) : aNodesIdxs(otherScene.aNodesIdxs), name(otherScene.name) {} void AddNode(OdInt32 nodeIdx) { aNodesIdxs.append(nodeIdx); } OdArray aNodesIdxs; OdString name; }; struct OdNodeContent { OdNodeContent() = default; OdNodeContent(const OdNodeContent& otherNode); void AddMeshIdx(OdInt32 iMeshIdx) { pMeshIdx = new OdInt32(iMeshIdx); } void AddChildren(OdArray& aChildren) { aChildNodesIdxs = aChildren; } OdArray aChildNodesIdxs; OdSharedPtr pMeshIdx; OdSharedPtr transform; OdGeVector3d translation; OdGeQuaternion rotation; OdGeScale3d scale; OdInt32 skin = -1; OdString name; }; struct OdSkinContent { OdSkinContent() = default; OdSkinContent(const OdSkinContent& other); OdArray joints; OdInt32 inverseBindMatrices = -1; }; struct OdMeshContent { OdMeshContent() = default; OdMeshContent(const OdMeshContent& other); struct OdPrimitive { OdPrimitive() = default; OdPrimitive(const OdPrimitive& other); OdInt32 position; OdInt32 indices = -1; std::map mTexcoord; std::map mJoints; std::map mWeights; OdInt32 normal = -1; OdInt32 material = -1; }; OdArray aPrimitives; OdString name; }; struct OdImageContent { OdImageContent() = default; OdImageContent(const OdImageContent& other) : uri(other.uri) {} OdString uri; }; struct OdSamplerContent { enum Filter { NEAREST = 9728, LINEAR = 9729 }; enum Wrap { CLAMP_TO_EDGE = 33071, MIRRORED_REPEAT = 33648, REPEAT = 10497 }; OdSamplerContent() = default; OdSamplerContent(const OdSamplerContent& other); Filter magFilter; Filter minFilter; Wrap wrapS = REPEAT; Wrap wrapT = REPEAT; }; struct OdTextureContent { OdTextureContent() = default; OdTextureContent(const OdTextureContent& other) : source(other.source), sampler(other.sampler) {} OdInt32 source = -1; OdInt32 sampler = -1; }; struct OdTextureInformation { OdTextureInformation() = default; OdTextureInformation(const OdTextureInformation& other); OdInt32 index = -1; OdInt32 texCoord = -1; OdInt32 scale = 1; }; struct OdMaterialContent { OdMaterialContent() = default; OdMaterialContent(const OdMaterialContent& other); struct OdExtensionsContent { OdExtensionsContent() = default; OdExtensionsContent(const OdExtensionsContent& other); //extensions parameter float glosinessFactor = -1.f; ColorFactor specularFactor{ -1.f }; ColorFactor diffuseFactor{ -1.f }; OdTextureInformation specularGlosinessTexture; OdTextureInformation diffuseTexture; }; void setEmissiveFactor(OdArray aFactor) { setEmissiveFactor(aFactor.asArrayPtr()); } OdString name; ColorFactor baseColorFactor; float metallic = 1.f; float roughness = 1.f; OdTextureInformation baseColorTexture; OdTextureInformation metallicRoughnesTexture; OdTextureInformation normalTexture; OdTextureInformation occlusionTexture; OdTextureInformation emissiveTexture; float emissiveFactor[3] = { 0.f }; OdString alphaMode = "OPAQUE"; float alphaCutoff = 0.5f; OdSharedPtr extensions; private: void setEmissiveFactor(float* ptr); }; struct OdAccessorContent { enum ComponentType { kByte = 5120, kUnsignedByte = 5121, kShort = 5122, kUnsignedShort = 5123, kUnsignedInt = 5125, kFloat = 5126 }; OdAccessorContent() = default; OdAccessorContent(const OdAccessorContent& other); OdUInt32 getCompSize() const; OdInt32 bufferView = 0; OdInt32 byteOffset = 0; ComponentType compType; OdInt32 count; OdString type; }; struct OdBufferViewContent { enum TargetType { kArrayBuffer = 34962, kElementArrayBuffer = 34963 }; OdBufferViewContent() = default; OdBufferViewContent(const OdBufferViewContent& other); OdInt32 buffer; OdInt32 byteOffset; OdInt32 byteLength = -1; OdInt32 byteStride = -1; TargetType target; }; struct OdBufferContent { OdBufferContent() = default; OdBufferContent(const OdBufferContent& other); OdSharedPtr> localData; int byteLength = -1; }; class OdJsonContent { public: OdJsonContent(); void setMainScene(OdInt32 MainScene) { iMainScene = MainScene; } void AddScene(const OdSceneContent& scene) { aScenes.push_back(scene); } void AddNode(const OdNodeContent& node) { aNodes.push_back(node); } void AddMesh(const OdMeshContent& rMesh) { aMeshes.push_back(rMesh); } void AddAccessor(const OdAccessorContent& accessor) { aAccessors.push_back(accessor); } void AddBufferView(const OdBufferViewContent& bufferView) { aBufViews.push_back(bufferView); } void AddBuffer(const OdBufferContent& buffer) { aBuffers.push_back(buffer); } void setModelName(const OdString& name) { this->name = name; } OdInt32 getMainSceneIdx() const { return iMainScene; } const OdArray& getScenes() const { return aScenes; } const OdArray& getNodes() const { return aNodes; } const OdArray& getMeshes() const { return aMeshes; } const OdString& getName() const { return name; } OdString name; OdInt32 iMainScene = 0; OdArray aScenes; OdArray aNodes; OdArray aSkins; OdArray aMeshes; OdArray aTextures; OdArray aSamplers; OdArray aImages; OdArray aMaterials; OdArray aAccessors; OdArray aBufViews; OdArray aBuffers; static OdUInt32 counter; OdUInt32 handle; bool isThereBump = false; }; }//namespace JSON } #endif