2013-06-13 33 views
1

我使用cocos3d中的CC3MeshNode繪製了一個複雜的3d形狀,但是這個形狀不受光源(燈)影響(陰影​​和明亮的位置取決於定位),我在世界,如果我使用其中一個populateAs方法繪製像球體一樣的東西,它將受到光源的影響。 手動繪製CC3MeshNode時應該怎麼做才能使其受到光線的影響。CC3MeshNode不受cocos3d中的燈光影響

這裏是手工繪製一個矩形中cocos3d

CC3MeshNode *pMeshNode = [[CC3MeshNode alloc] init]; 
    [pMeshNode setIsTouchEnabled:YES]; 

    CC3Mesh* theArrayMesh = [pMeshNode prepareParametricMesh]; 
    // Prepare the vertex content and allocate space for vertices and indices. 
    [theArrayMesh ensureVertexContent]; 
    theArrayMesh.allocatedVertexCapacity = totalVertexCount; 
    theArrayMesh.allocatedVertexIndexCapacity = (triangleCount * 3); 
    GLushort* indices = theArrayMesh.vertexIndices.vertices; 

    /* 
    * 1-------0 
    * |  /| -z 
    * | /| ⥣ 
    * | /|  =>+x 
    * | / | 
    * |/ | 
    * |/ | 
    * |/  | 
    * 2-------3 
    */ 
    { 
     [theArrayMesh setVertexLocation: cc3v(3, -3,0) at: 3]; 
     [theArrayMesh setVertexLocation: cc3v(-3, -3,0) at: 2]; 
     [theArrayMesh setVertexLocation: cc3v(-3, 3, 0) at: 1]; 
     [theArrayMesh setVertexLocation: cc3v(3, 3, 0) at: 0]; 

    } 
    GLubyte indxIndx = 0; 
    GLubyte vtxIndx = 0; 
    for (int side = 0; side < 1; side++) { 
     // First trangle of side - CCW from bottom left 
     indices[indxIndx++] = vtxIndx++;  // vertex 0 
     indices[indxIndx++] = vtxIndx++;  // vertex 1 
     indices[indxIndx++] = vtxIndx;   // vertex 2 

     // Second triangle of side - CCW from bottom left 
     indices[indxIndx++] = vtxIndx++;  // vertex 2 
     indices[indxIndx++] = vtxIndx++;  // vertex 3 
     indices[indxIndx++] = (vtxIndx - 4); // vertex 0 
    } 

    [self addChild:pMeshNode]; 

回答

1

我認爲這個問題是您需要爲您提供網格頂點法的示例代碼。法線是照明計算正確運行所必需的。自動填充球體的例程等在網格中生成並存儲頂點法線。當你使用glEnable(GL_AUTO_NORMAL)時,桌面OpenGL將爲它們生成法線,但是這個功能在移動中不存在,至少在OpenGL ES 2.0中不存在。

+0

正確的你是我的朋友,我已經添加了法線並且工作。謝謝 –