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];
正確的你是我的朋友,我已經添加了法線並且工作。謝謝 –