【问题标题】:Translation and scaling in GLTFGLTF 中的平移和缩放
【发布时间】:2020-04-05 14:35:15
【问题描述】:

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

【问题讨论】:

    标签: python gltf


    【解决方案1】:

    您链接到的 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 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 2012-03-19
      • 2015-08-08
      • 2013-12-12
      • 2016-03-10
      • 2014-09-30
      • 1970-01-01
      相关资源
      最近更新 更多