shared_ptr <JSONExport::JSONObject> serializePrimitive(JSONPrimitive* primitive, void *context) { void** primitiveContext = (void**)context; shared_ptr <JSONExport::JSONObject> primitiveObject(new JSONExport::JSONObject()); JSONMesh* mesh = (JSONMesh*)primitiveContext[0]; primitiveObject->setString("primitive", primitive->getType()); primitiveObject->setString("material", primitive->getMaterialID()); shared_ptr <JSONExport::JSONArray> vertexAttributesArray(new JSONExport::JSONArray()); primitiveObject->setValue("vertexAttributes", vertexAttributesArray); size_t count = primitive->allIndices().size(); for (size_t j = 0 ; j < count ; j++) { shared_ptr <JSONExport::JSONObject> indicesObject(new JSONExport::JSONObject()); shared_ptr <JSONExport::JSONIndices> indices = primitive->allIndices()[j]; JSONExport::Semantic semantic = indices->getSemantic(); vertexAttributesArray->appendValue(indicesObject); indicesObject->setString("semantic", JSONUtils::getStringForSemantic(semantic)); unsigned int indexOfSet = 0; if (mesh->getAccessorsForSemantic(semantic).size() > 1) { indexOfSet = indices->getIndexOfSet(); indicesObject->setString("set", JSONUtils::toString(indices->getIndexOfSet())); } indicesObject->setString("accessor", mesh->getAccessorsForSemantic(semantic)[indexOfSet]->getID()); } shared_ptr <JSONExport::JSONIndices> uniqueIndices = primitive->getUniqueIndices(); shared_ptr <JSONExport::JSONObject> serializedIndices = serializeIndices(uniqueIndices.get(), primitiveContext[1]); primitiveObject->setValue("indices", serializedIndices); return primitiveObject; }
shared_ptr <GLTF::JSONObject> serializePrimitive(GLTFPrimitive* primitive, void *context) { void** primitiveContext = (void**)context; shared_ptr <GLTF::JSONObject> primitiveObject(new GLTF::JSONObject()); GLTFMesh* mesh = (GLTFMesh*)primitiveContext[0]; primitiveObject->setString("primitive", primitive->getType()); primitiveObject->setString("material", primitive->getMaterialID()); shared_ptr <GLTF::JSONObject> semantics(new GLTF::JSONObject()); primitiveObject->setValue("semantics", semantics); size_t count = primitive->getIndicesInfosCount(); for (size_t j = 0 ; j < count ; j++) { GLTF::Semantic semantic = primitive->getSemanticAtIndex(j); std::string semanticAndSet = GLTFUtils::getStringForSemantic(semantic); unsigned int indexOfSet = 0; if ((semantic != GLTF::POSITION) && (semantic != GLTF::NORMAL)) { indexOfSet = primitive->getIndexOfSetAtIndex(j); semanticAndSet += "_" + GLTFUtils::toString(indexOfSet); } semantics->setString(semanticAndSet, mesh->getMeshAttributesForSemantic(semantic)[indexOfSet]->getID()); } shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices(); shared_ptr <GLTF::JSONObject> serializedIndices = serializeIndices(uniqueIndices.get(), primitiveContext[1]); primitiveObject->setValue("indices", serializedIndices); return primitiveObject; }