void GLTFMesh::resolveAttributes() { shared_ptr <GLTF::JSONArray> primitivesArray(new GLTF::JSONArray()); JSONValueVector primitives = this->getPrimitives()->values(); unsigned int primitivesCount = (unsigned int)primitives.size(); for (unsigned int i = 0 ; i < primitivesCount ; i++) { shared_ptr<GLTF::GLTFPrimitive> primitive = static_pointer_cast<GLTFPrimitive>(primitives[i]); shared_ptr <GLTF::JSONObject> attributes(new GLTF::JSONObject()); primitive->setValue(kAttributes, attributes); size_t count = primitive->getVertexAttributesCount(); for (size_t j = 0 ; j < count ; j++) { GLTF::Semantic semantic = primitive->getSemanticAtIndex((unsigned int)j); std::string semanticAndSet = GLTFUtils::getStringForSemantic(semantic); unsigned int indexOfSet = 0; if ((semantic == GLTF::TEXCOORD) || (semantic == GLTF::COLOR)) { indexOfSet = primitive->getIndexOfSetAtIndex((unsigned int)j); semanticAndSet += "_" + GLTFUtils::toString(indexOfSet); } attributes->setString(semanticAndSet, this->getMeshAttribute(semantic, indexOfSet)->getID()); } primitivesArray->appendValue(primitive); } }
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); } return meshObject; }
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); //meshAttributes shared_ptr <GLTF::JSONObject> meshAttributesObject(new GLTF::JSONObject()); meshObject->setValue("attributes", meshAttributesObject); shared_ptr <MeshAttributeVector> allMeshAttributes = mesh->meshAttributes(); 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]; shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices(); void *primitiveContext[2]; primitiveContext[0] = mesh; primitiveContext[1] = context; shared_ptr <GLTF::JSONObject> primitiveObject = serializePrimitive(primitive.get(), primitiveContext); primitivesArray->appendValue(primitiveObject); } vector <GLTF::Semantic> allSemantics = mesh->allSemantics(); for (unsigned int i = 0 ; i < allSemantics.size() ; i++) { GLTF::Semantic semantic = allSemantics[i]; GLTF::IndexSetToMeshAttributeHashmap::const_iterator meshAttributeIterator; GLTF::IndexSetToMeshAttributeHashmap& indexSetToMeshAttribute = mesh->getMeshAttributesForSemantic(semantic); //FIXME: consider turn this search into a method for mesh for (meshAttributeIterator = indexSetToMeshAttribute.begin() ; meshAttributeIterator != indexSetToMeshAttribute.end() ; meshAttributeIterator++) { //(*it).first; // the key value (of type Key) //(*it).second; // the mapped value (of type T) shared_ptr <GLTF::GLTFMeshAttribute> meshAttribute = (*meshAttributeIterator).second; shared_ptr <GLTF::JSONObject> meshAttributeObject = serializeMeshAttribute(meshAttribute.get(), context); meshAttributesObject->setValue(meshAttribute->getID(), meshAttributeObject); } } return meshObject; }
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 <JSONExport::JSONObject> serializeMesh(JSONMesh* mesh, void *context) { typedef map<std::string , shared_ptr<JSONExport::JSONBuffer> > IDToBufferDef; IDToBufferDef IDToBuffer; shared_ptr <JSONExport::JSONObject> meshObject(new JSONExport::JSONObject()); meshObject->setString("name", mesh->getName()); //primitives shared_ptr <JSONExport::JSONArray> primitivesArray(new JSONExport::JSONArray()); meshObject->setValue("primitives", primitivesArray); //accessors shared_ptr <JSONExport::JSONObject> accessorsObject(new JSONExport::JSONObject()); meshObject->setValue("accessors", accessorsObject); vector <shared_ptr< JSONExport::JSONAccessor> > allAccessors = mesh->remappedAccessors(); std::vector< shared_ptr<JSONExport::JSONPrimitive> > primitives = mesh->getPrimitives(); unsigned int primitivesCount = (unsigned int)primitives.size(); for (unsigned int i = 0 ; i < primitivesCount ; i++) { shared_ptr<JSONExport::JSONPrimitive> primitive = primitives[i]; shared_ptr <JSONExport::JSONIndices> uniqueIndices = primitive->getUniqueIndices(); void *primitiveContext[2]; primitiveContext[0] = mesh; primitiveContext[1] = context; shared_ptr <JSONExport::JSONObject> primitiveObject = serializePrimitive(primitive.get(), primitiveContext); primitivesArray->appendValue(primitiveObject); //FIXME: check to remove that code unsigned int indicesCount = (unsigned int)primitive->getUniqueIndices()->getCount(); if (indicesCount <= 0) { // FIXME: report error } else { size_t indicesLength = sizeof(unsigned short) * indicesCount; shared_ptr <JSONExport::JSONBuffer> indiceBuffer(new JSONExport::JSONBuffer(uniqueIndices->getBuffer()->getID(), indicesLength)); IDToBuffer[indiceBuffer->getID()] = indiceBuffer; } } vector <JSONExport::Semantic> allSemantics = mesh->allSemantics(); for (unsigned int i = 0 ; i < allSemantics.size() ; i++) { JSONExport::Semantic semantic = allSemantics[i]; JSONExport::IndexSetToAccessorHashmap::const_iterator accessorIterator; JSONExport::IndexSetToAccessorHashmap& indexSetToAccessor = mesh->getAccessorsForSemantic(semantic); //FIXME: consider turn this search into a method for mesh for (accessorIterator = indexSetToAccessor.begin() ; accessorIterator != indexSetToAccessor.end() ; accessorIterator++) { //(*it).first; // the key value (of type Key) //(*it).second; // the mapped value (of type T) shared_ptr <JSONExport::JSONAccessor> accessor = (*accessorIterator).second; shared_ptr <JSONExport::JSONObject> accessorObject = serializeAccessor(accessor.get(), context); accessorsObject->setValue(accessor->getID(), accessorObject); } } return meshObject; }