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 <JSONExport::JSONObject> serializeIndices(JSONIndices* indices, void *context)
 {
     shared_ptr <JSONExport::JSONObject> indicesObject(new JSONExport::JSONObject());
     
     JSONBuffer* buffer = context ? (JSONBuffer*)context : indices->getBuffer().get();
     
     indicesObject->setString("type", JSONUtils::getStringForTypedArray(JSONExport::UNSIGNED_SHORT));
     indicesObject->setString("buffer", buffer->getID());
     indicesObject->setUnsignedInt32("byteOffset", (unsigned int)indices->getByteOffset());
     indicesObject->setUnsignedInt32("length", (unsigned int)indices->getCount());
     
     return indicesObject;
 }
示例#3
0
 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;
 }
示例#4
0
文件: GLTFWriter.cpp 项目: nil84/glTF
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;
}