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?
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?
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:
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.