English 中文(简体)
• 尽快向开放式GL-ES装载各种vert和面对指数?
原标题:Fastest way to load arrays of vertices and face indices into OpenGL-ES?

I m试图装上我编成以下文件:

vertexX vertexY vertexZ normalX normalY normalZ

并且

index1 index2 index3

病媒和病媒阵列的形式,然后由我直接以开放式-ES的形式提供。 我的问题是,当我试图将模型装入阵列时,大约需要40秒钟才能装上。 我不敢肯定,为什么它如此缓慢,我看到其他法典只用几秒钟就装上同样的模式。 任何建议? 我的档案装载法如下:

-(void)loadModel:(NSString*)filePath
{
    try {

    ifstream objFile([filePath UTF8String]);
    objFile >> numVertices;
    objFile.ignore(128,  
 );
    vertices.resize(numVertices*6);
    VertexNormal* vertex = (VertexNormal*) &vertices[0];
    svec3* faceDef;

    while (objFile) {
        char c = objFile.get();

        switch (c) {
            case  v :
            {
                objFile >> vertex->vertices.x >> vertex->vertices.y >> vertex->vertices.z
                >> vertex->normals.x >> vertex->normals.y >> vertex->normals.z;
                vertex++;
                break;
            }
            case  f :
            {
                objFile >> faceDef->x >> faceDef->y >> faceDef->z;
                faceDef++;
                break;
            }
            case  # :
            {
                part newPart;
                partList.push_back(newPart);
                numObjects++;
                objFile.ignore(128,  
 );
                int numFaces;
                objFile >> numFaces;
                partList[partList.size()-1].faces.resize(numFaces*3);
                partList[partList.size()-1].numFaces = numFaces;
                faceDef = (svec3*) &partList[partList.size()-1].faces[0];
                break;
            }
            default:
                break;
        }
        objFile.ignore(128,  
 );
    }
    objFile.close();
    free(objFile);
    } catch (NSException *ex) {
        NSLog(@"%@", [ex reason]);
    }
}

我的思路之一是将阵列编成双手文件,然后将其简单化为我的节目。 虽然如此,但也许可以按照这些思路找到解决办法。

最佳回答

游戏行业的最佳做法是用双向格式保存所有模型数据,这样,你就可以很快装上可以作为vert、正常或任何其他东西代表的全非环外记忆。 你们都需要这样做——使小指挥线工具把文字文件(obj)翻译成你自己的双手档案。

此外:

  • Did you try to do text loading with stdio library, not stl ifstream?
  • Maybe try to read all the text data once and fill arrays from memory, not from filesystem?
  • how much parts in file do you have? Each resize of std::vector leads to new allocation and copying. Try to reserve space in std::vector, if you know desired volume before.
问题回答

I don t know if you ve considered this, but if your .obj files won t change in your application, you can format them as objective-C arrays and compile them directly with your code.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签