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;
 }
示例#2
0
 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;
 }
示例#3
0
文件: GLTFWriter.cpp 项目: nil84/glTF
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];

    void** serializationContext = (void**)primitiveContext[1];

    GLTFConverterContext *converterContext = (GLTFConverterContext*)serializationContext[3];

    primitiveObject->setUnsignedInt32("primitive", converterContext->profile->getGLenumForString(primitive->getType()));

    primitiveObject->setString("material", primitive->getMaterialID());

    shared_ptr <GLTF::JSONObject> attributes(new GLTF::JSONObject());
    primitiveObject->setValue("attributes", attributes);

    size_t count = primitive->getVertexAttributesCount();
    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::TEXCOORD) {
            indexOfSet = primitive->getIndexOfSetAtIndex(j);
            semanticAndSet += "_" + GLTFUtils::toString(indexOfSet);
        }
        attributes->setString(semanticAndSet, mesh->getMeshAttributesForSemantic(semantic)[indexOfSet]->getID());
    }
    shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices();
    primitiveObject->setString("indices", uniqueIndices->getID());

    return primitiveObject;
}