Search code examples
javascriptcesiumjsgltf

Q: cesium load gltf model from storage


I am trying to put my .gltf model into a database. I built a restful API to get it from the database. But when I put the URL into Cesium's framework, an error occurs. The error is shown below.

enter image description here

      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')

front end javascript code

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)

server end python code


Solution

  • I fix out by myself, i forget to translate the string to json object, i added a json.loads(data) at server end's code. it runs. Thanks @emackey you give me an advise