shared_ptr <GLTF::JSONObject> serializeMesh(GLTFMesh* mesh, void *context) { shared_ptr <GLTF::JSONObject> meshObject(new GLTF::JSONObject()); meshObject->setString("name", mesh->getName()); //primitives shared_ptr <GLTF::JSONArray> primitivesArray(new GLTF::JSONArray()); meshObject->setValue("primitives", primitivesArray); PrimitiveVector primitives = mesh->getPrimitives(); unsigned int primitivesCount = (unsigned int)primitives.size(); for (unsigned int i = 0 ; i < primitivesCount ; i++) { shared_ptr<GLTF::GLTFPrimitive> primitive = primitives[i]; void *primitiveContext[2]; primitiveContext[0] = mesh; primitiveContext[1] = context; shared_ptr <GLTF::JSONObject> primitiveObject = serializePrimitive(primitive.get(), primitiveContext); primitivesArray->appendValue(primitiveObject); } if (mesh->getExtensions()->getKeysCount() > 0) { meshObject->setValue("extensions", mesh->getExtensions()); if (mesh->getExtensions()->contains("won-compression")) { shared_ptr<JSONObject> compressionObject = static_pointer_cast<JSONObject>(mesh->getExtensions()->getValue("won-compression")); if (compressionObject->contains("compressedData")) { shared_ptr<JSONObject> compressionData = compressionObject->getObject("compressedData"); GLTFBufferView *bufferView = (GLTFBufferView*)((void**)context)[0]; compressionData->setString("bufferView", bufferView->getID()); } } if (mesh->getExtensions()->contains("Open3DGC-compression")) { shared_ptr<JSONObject> compressionObject = static_pointer_cast<JSONObject>(mesh->getExtensions()->getValue("Open3DGC-compression")); if (compressionObject->contains("compressedData")) { shared_ptr<JSONObject> compressionData = compressionObject->getObject("compressedData"); GLTFBufferView *bufferView = (GLTFBufferView*)((void**)context)[0]; compressionData->setString("bufferView", bufferView->getID()); } } } return meshObject; }
shared_ptr <GLTF::JSONObject> serializeMeshAttribute(GLTFMeshAttribute* meshAttribute, void *context) { shared_ptr <JSONObject> meshAttributeObject = shared_ptr<JSONObject>(new JSONObject()); meshAttributeObject->setUnsignedInt32("byteStride", (unsigned int)meshAttribute->getByteStride()); meshAttributeObject->setUnsignedInt32("byteOffset", (unsigned int)meshAttribute->getByteOffset()); meshAttributeObject->setUnsignedInt32("componentsPerAttribute", (unsigned int)meshAttribute->getElementsPerVertexAttribute()); meshAttributeObject->setUnsignedInt32("count", (unsigned int)meshAttribute->getCount()); meshAttributeObject->setString("componentType", GLTFUtils::getStringForGLType(meshAttribute->getComponentType())); void** buffers = (void**)context; GLTFBufferView *bufferView = context ? (GLTFBufferView*)buffers[0] : meshAttribute->getBufferView().get(); meshAttributeObject->setString("bufferView", bufferView->getID()); const double* min = meshAttribute->getMin(); if (min) { shared_ptr <GLTF::JSONArray> minArray(new GLTF::JSONArray()); meshAttributeObject->setValue("min", minArray); for (size_t i = 0 ; i < meshAttribute->getElementsPerVertexAttribute() ; i++) { minArray->appendValue(shared_ptr <GLTF::JSONNumber> (new GLTF::JSONNumber(min[i]))); } } const double* max = meshAttribute->getMax(); if (max) { shared_ptr <GLTF::JSONArray> maxArray(new GLTF::JSONArray()); meshAttributeObject->setValue("max", maxArray); for (size_t i = 0 ; i < meshAttribute->getElementsPerVertexAttribute() ; i++) { maxArray->appendValue(shared_ptr <GLTF::JSONNumber> (new GLTF::JSONNumber(max[i]))); } } return meshAttributeObject; }
shared_ptr <GLTF::JSONObject> serializeIndices(GLTFIndices* indices, void *context) { shared_ptr <GLTF::JSONObject> indicesObject(new GLTF::JSONObject()); void** buffers = (void**)context; GLTFBufferView *bufferView = context ? (GLTFBufferView*)buffers[1] : indices->getBufferView().get(); indicesObject->setString("type", GLTFUtils::getStringForGLType(GLTF::UNSIGNED_SHORT)); indicesObject->setString("bufferView", bufferView->getID()); indicesObject->setUnsignedInt32("byteOffset", (unsigned int)indices->getByteOffset()); indicesObject->setUnsignedInt32("count", (unsigned int)indices->getCount()); return indicesObject; }
shared_ptr <GLTF::JSONObject> serializeIndices(GLTFIndices* indices, void *context) { shared_ptr <GLTF::JSONObject> indicesObject(new GLTF::JSONObject()); void** serializationContext = (void**)context; GLTFConverterContext *converterContext = (GLTFConverterContext*)serializationContext[3]; GLTFBufferView *bufferView = (GLTFBufferView*)serializationContext[1]; indicesObject->setUnsignedInt32("type", converterContext->profile->getGLenumForString("UNSIGNED_SHORT")); indicesObject->setString("bufferView", bufferView->getID()); indicesObject->setUnsignedInt32("byteOffset", (unsigned int)indices->getByteOffset()); indicesObject->setUnsignedInt32("count", (unsigned int)indices->getCount()); return indicesObject; }