我正在尝试通过gltf显示多个框(具有不同的大小和位置)。
我使用https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF/Box.gltf示例作为模板,只需用新节点替换节点。
当我将节点创建为
gltf["scenes"][0]["nodes"]=[]
gltf["nodes"]=[]
nodeId=0
for x, y, z, w, h, d in boxes:
gltf["nodes"]+=[{ "mesh": 0, "translation": [x, y, z], "scale":[w, h, d]}]
gltf["scenes"][0]["nodes"]+=[nodeId]
nodeId+=1 长方体(彼此相邻)发生碰撞(不仅在边上)。所以3d是错误的。
当我在没有缩放的情况下创建我的长方体时(从许多小长方体),它可以工作:
gltf["scenes"][0]["nodes"]=[]
gltf["nodes"]=[]
nodeId=0
for x, y, z, w, h, d in boxes:
for x1 in range(x, w+w):
for y1 in range(y, y+w):
for z1 in range(z, z+d):
gltf["nodes"]+=[{"mesh": 0, "translation": [x1, y1, z1]}]
gltf["scences"][0]["nodes"]+=[nodeId]
nodeId+=1 但这当然是一个更大更复杂的gltf。
方框中的坐标是左下角( x、y和z值中的最小值)
发布于 2019-12-12 22:14:33
链接到的glTF示例框沿每个轴具有从-0.5到0.5的顶点位置。因此,要定位长方体,应将节点平移到长方体中心所在的位置。
我还没有尝试运行这段代码,但是对于表示框的角的x, y, z值,下面这样的代码应该会将它更改为框的中心。我所做的唯一改变是添加了一半的宽度、一半的高度和一半的深度。
gltf["scenes"][0]["nodes"]=[]
gltf["nodes"]=[]
nodeId=0
for x, y, z, w, h, d in boxes:
gltf["nodes"]+=[{ "mesh": 0, "translation": [
x + w/2,
y + h/2,
z + d/2
], "scale":[w, h, d]}]
gltf["scenes"][0]["nodes"]+=[nodeId]
nodeId+=1 https://stackoverflow.com/questions/59300570
复制相似问题