I think the problem is you need to supply vertex normals for your mesh. Normals are required for the lighting calculations to operate correctly. The routines to automatically populate a sphere, etc. are generating and storing vertex normals in the mesh. Desktop OpenGL will generate normals for a mesh without them when you use glEnable(GL_AUTO_NORMAL), but this functionality doesn't exist in mobile, at least not in OpenGL ES 2.0.
CC3MeshNode is not affected by light in cocos3d
-
31-05-2022 - |
Domanda
I have drawn a complex 3d shape using CC3MeshNode in cocos3d, but this shape is not affected (shadow and bright places depending on positioning) by the light source (lamp) that i set in the world, where if i use one of the populateAs methods to draw something like a sphere it will get affected by the light source. What should i do while manually drawing a CC3MeshNode so that it will get affected by light.
Here is a sample code of drawing a rectangle manually in 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];
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow