Ejemplo n.º 1
0
bool Sprite3D::loadFromFile(const std::string& path, NodeDatas* nodedatas, MeshDatas* meshdatas,  MaterialDatas* materialdatas)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
    
    std::string ext = path.substr(path.length() - 4, 4);
    std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
    if (ext == ".obj")
    {
        return Bundle3D::loadObj(*meshdatas, *materialdatas, *nodedatas, fullPath);
    }
    else if (ext == ".c3b" || ext == ".c3t")
    {
        //load from .c3b or .c3t
        auto bundle = Bundle3D::createBundle();
        if (!bundle->load(fullPath))
        {
            Bundle3D::destroyBundle(bundle);
            return false;
        }
        
        auto ret = bundle->loadMeshDatas(*meshdatas)
            && bundle->loadMaterials(*materialdatas) && bundle->loadNodes(*nodedatas);
        Bundle3D::destroyBundle(bundle);
        
        return ret;
    }
    return false;
}
Ejemplo n.º 2
0
bool Sprite3D::loadFromC3x(const std::string& path)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);

    //load from .c3b or .c3t
    auto bundle = Bundle3D::getInstance();
    if (!bundle->load(fullPath))
        return false;
    
    MeshDatas meshdatas;
    MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas();
    NodeDatas*   nodeDatas = new (std::nothrow) NodeDatas();
    if (bundle->loadMeshDatas(meshdatas)
        && bundle->loadMaterials(*materialdatas)
        && bundle->loadNodes(*nodeDatas)
        && initFrom(*nodeDatas, meshdatas, *materialdatas))
    {
        //add to cache
        auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
        data->materialdatas = materialdatas;
        data->nodedatas = nodeDatas;
        data->meshVertexDatas = _meshVertexDatas;
        for (const auto mesh : _meshes) {
            data->glProgramStates.pushBack(mesh->getGLProgramState());
        }
        Sprite3DCache::getInstance()->addSprite3DData(path, data);
        return true;
    }
    
    delete materialdatas;
    delete nodeDatas;
    
    return false;
}