Model won't move when position is changed

Hello,

I'm trying to move an object on a Cesium 3D map. My code works fine when I use your sample Cesium_Man.glft that I pulled from one of your demos. But when I use a .gltf that was created from one of my own COLLADA via your converter it doesn't move. https://cesiumjs.org/convertmodel.html

This is the code I'm using:

    function createModel(command) {
        var center = Cesium.Cartesian3.fromDegrees(command.lon, command.lat, command.elev);
        viewer.entities.add({
            id: command.modelId,
            position: center,
            model: {
                uri: '../img/models/myColladaModel.gltf',
                scale: 10
                
            }
        });

    }

    function moveModel(command) {
        var modelEntity = viewer.entities.getById(command.modelId);
        if (modelEntity) {
            var center = Cesium.Cartesian3.fromDegrees(command.lon, command.lat, command.elev)
            playerEntity.position = center;
        } else {
            createModel(command)
        }
    }

Both Cesium_Man.glft and myColladaModel.gltf show on the map after createModel(). But moveModel() only works when I use the model Cesium_Man.gltf. What am I missing in my model?

Thanks
Brendan

Hi Brendan,

I’m not sure why this would be the case. I’m not sure if this is the problem, but you do have a typo in the code sample you pasted:

if (modelEntity) {
var center = Cesium.Cartesian3.fromDegrees(command.lon, command.lat, command.elev)
playerEntity.position = center; <------- Should this be modelEntity?
} else {

``

If you’re still seeing the problem, could you attach the model you are using? Are there any errors in the console?

Best,

Hannah

Sorry... no that was just a copy/paste error (facepalm)... not the cause of my issue.

Here are the models: https://drive.google.com/open?id=0B7j19VJiLbfrNVdPc3BvVnctS1E

I'm using Stormtrooper.gltf. I've also included the COLLADA model I used to convert.

So your model was failing because it couldn’t load the image file you are using for your texture. You need to save your Stormtrooper_D.tga file as a .png or .jpg. Then you can change the path to new image by opening the glTF file in a text editor
Line 147:

"images": {
    "Image": {
        "name": "Image",
        "uri": "./Stormtrooper_D.png"
    }
},

``

After that, everything should work.

By the way, that’s a great model! I’m very curious, what kind of app are you working on?

Best,

Hannah

Awesome thanks for the quick response. Got it working now :smiley:

If you use the online converter (http://cesiumjs.org/ConvertModel.html) and upload the collada along with the tga image we will convert the image and embed it in a binary gltf file for you. It'll be converted to a jpeg if there isn't any transparency or a png otherwise.