Esempio n. 1
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;
 }
Esempio n. 2
0
 //copy that retains elements
 GLTFMesh::GLTFMesh(const GLTFMesh &mesh) : JSONObject(), _subMeshes(nullptr) {
     this->_remapTableForPositions = nullptr;
     GLTFMesh *meshPtr = const_cast <GLTFMesh*>(&mesh);
     this->setPrimitives(meshPtr->getPrimitives());
     this->_semanticToMeshAttributes = mesh._semanticToMeshAttributes;
     this->_ID = mesh._ID;
     this->setName(meshPtr->getName());
 }
Esempio n. 3
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];

    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;
}