2013-06-13 32 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

正确的你是我的朋友,我已经添加了法线并且工作。谢谢 –