GLTF 中的平移和缩放

Translation and scaling in GLTF

我正在尝试通过 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值中的最小值)

您链接到的 glTF 示例框的顶点位置沿每个轴的范围从 -0.50.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