【问题标题】:Q: cesium load gltf model from storage问:cesium 从存储中加载 gltf 模型
【发布时间】:2018-04-23 09:26:10
【问题描述】:

我正在尝试将我的 .gltf 模型放入数据库。我构建了一个 RESTful API 来从数据库中获取它。但是当我把 URL 放入 Cesium 的框架中时,出现了错误。错误如下所示。

      Sandcastle.addToolbarButton('models', function () {
    // eslint-disable-next-line
    var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
      id: 'house',
      url: 'http://127.0.0.1:8000/test',
      // url: gltf_data,
      modelMatrix: modelMatrix,
      scale: 0.1
    }))
  }, 'singleModel')

前端javascript代码

class Test(flask_restful.Resource):
def get(self):
    client = MongoClient()

    db = client['test']
    fs = gridfs.GridFS(db)
    for x in fs.find():
        data = x.read()
        break
    data = data.decode('utf-8')
    # file = fs.find_one()
    return jsonify(data)

服务器端python代码

【问题讨论】:

  • 你能分享将这个模型加载到Cesium中的代码吗?看来您可能需要调用 JSON.parse() 才能将字符串转换为对象。
  • 就是上面的服务器端和前端代码。 @emackey

标签: javascript cesium gltf


【解决方案1】:

我自己解决了,我忘记将字符串转换为 json 对象,我在服务器端的代码中添加了 json.loads(data)。它运行。谢谢@emackey 你给我一个建议

【讨论】:

    猜你喜欢
    • 2016-05-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2021-08-24
    • 1970-01-01
    • 2021-08-14
    • 2019-07-31
    相关资源
    最近更新 更多