gpt4 book ai didi

ios - CC3MeshNode在cocos3d中不受光照影响

转载 作者:行者123 更新时间:2023-11-29 13:11:51 31 4
gpt4 key购买 nike

我在 cocos3d 中使用 CC3MeshNode 绘制了一个复杂的 3d 形状,但是这个形状不受我在世界中设置的光源(灯)的影响(阴影​​和明亮的地方取决于定位),如果我使用其中一个populateAs 方法来绘制类似球体的东西,它会受到光源的影响。手动绘制 CC3MeshNode 时应该怎么做才能使其受到光线的影响。

下面是在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];

最佳答案

我认为问题在于您需要为网格提供顶点法线。光照计算需要法线才能正确运行。自动填充球体等的例程正在生成顶点法线并将其存储在网格中。当您使用 glEnable(GL_AUTO_NORMAL) 时,桌面 OpenGL 将为没有法线的网格生成法线,但此功能在移动设备中不存在,至少在 OpenGL ES 2.0 中不存在。

关于ios - CC3MeshNode在cocos3d中不受光照影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17084380/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com