2012-09-06 61 views
1

我已經安裝Blender,編譯Jeff LaMarche’s Blender Objective-C Export Plugin併成功導出「MyImage.obj」作爲Objective-C頭文件(GraphicsTypes.h)。從Blender導出的3D形狀導出使用iPhone中的OpenGL頭文件

現在我試圖從Blender中使用OpenGL在iPhone中導出頭文件來繪製3D形狀。

這是Blender中的picture representation of MyImage.obj。下面我粘貼了我的Blender導出的Objective-C頭文件。

如何使用下面的代碼在Objective-C中繪製相同的3D圖片。

我跟着this鏈接來做這個過程。但是我無法將模型加入到我的應用程序中。

我沒有找到任何教程來渲染圖像使用下面的代碼(Blender導出Objective-C頭)。我的代碼 HelloGLKit OpenGL sample application。但它沒有吸引任何東西。

對此問題的任何幫助表示讚賞。

GraphicsTypes.h [攪拌機出口Objective-C的報頭]

//If not using MC3D, change 1 to 0 to add needed types 
#if 1 
    #import "MC3DTypes.h" 
#else 
    struct texCoord 
    { 
     GLfloat  u; 
     GLfloat  v; 
    }; 
    typedef struct texCoord texCoord; 
    typedef texCoord* texCoordPtr; 

    typedef struct vec2 vec2; 
    typedef vec2* vec2Ptr; 

    struct vec3 
    { 
     GLfloat x; 
     GLfloat y; 
     GLfloat z; 
    }; 

    typedef struct vec3 vec3; 
    typedef vec3* vec3Ptr; 

    struct vec4 
    { 
     GLfloat x; 
     GLfloat y; 
     GLfloat z; 
     GLfloat w; 
     }; 

    typedef struct vec4 vec4; 
    typedef vec4* vec4Ptr; 

#endif 

struct vertexData 
{ 
    vec3  vertex; 
    vec3  normal; 
} 
typedef struct vertexData vertexData; 
typedef vertexData* vertexDataPtr; 


static const vertexData MeshVertexData[] = { 
    {/*v:*/{1.000000, -1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{1.000000, -1.000000, 1.000000}, /*n:*/{0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{1.000000, 1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{0.999999, 1.000000, 1.000001}, /*n:*/{0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{1.000000, -1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{1.000000, 1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{1.000000, -1.000000, 1.000000}, /*n:*/{0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{1.000000, -1.000000, 1.000000}, /*n:*/{0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{0.999999, 1.000000, 1.000001}, /*n:*/{0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{1.000000, 1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{1.000000, -1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{1.000000, -1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{0.999999, 1.000000, 1.000001}, /*n:*/{0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{1.000000, 1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{0.999999, 1.000000, 1.000001}, /*n:*/{0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{1.000000, -1.000000, 1.000000}, /*n:*/{0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{0.999999, 1.000000, 1.000001}, /*n:*/{0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, 1.000000}, /*n:*/{-0.577349, -0.577349, -0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, 1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{1.000000, 1.000000, -1.000000}, /*n:*/{0.577349, 0.577349, 0.577349} }, 
    {/*v:*/{-1.000000, -1.000000, -1.000000}, /*n:*/{-0.577349, 0.577349, -0.577349} }, 
}; 

// Example OpenGL ES 1.1 Drawing Code: 
// glEnableClientState(GL_VERTEX_ARRAY); 
// glEnableClientState(GL_NORMAL_ARRAY); 
// glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), &MeshVertexData[0].vertex); 
// glNormalPointer(GL_FLOAT, sizeof(VertexData3D), &MeshVertexData[0].normal); 
// glDrawArrays(GL_TRIANGLES, 0, kMeshNumberOfVertices); 
// glDisableClientState(GL_VERTEX_ARRAY); 
// glDisableClientState(GL_NORMAL_ARRAY); 
+0

導出的文件看起來有點不對我。它只包含35個左右的頂點,它們的值都是-1.0或1.0或0.0。這很奇怪。你確定你正在使用正確的導出腳本版本嗎?另外,你是否使用他的示例項目,並試圖用它替換你的文件? –

+0

@VladimirMitrovic:我暫時還沒有獲得任何示例應用程序。如果有,請分享有關它的鏈接/信息。 –

+0

在2009年的[this](http://iphonedevelopment.blogspot.com/2009/07/fixed-improved-blender-export-script.html)博客中,該出口商的作者發佈了一個包含您需要。但是,這個鏈接似乎已經死了。你應該聯繫他(他最近很活躍),也許他可以給你想要的東西。但是如果你熟悉OpenGL(你可以在屏幕上繪製東西,設置法線,紋理等等),你最好自己寫出口和格式。或者我可以爲你做(我喜歡爲Blender寫出口商:)) –

回答

0

我已經使用了NinevehGL代替攪拌機。

NinevehGL是純粹的OBJ-C

NinevehGL結下了3D引擎現在是BETA版本0.9.3

您可以查看NinevehGL細節here

你可以看到NinevehGL論壇here

相關問題