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];
正确的你是我的朋友,我已经添加了法线并且工作。谢谢 –