Hi,
Thank you so much for the guidance.
I’ve tried your solution. I’m half way through to meet my goal. I’m facing some challenges, when perform transform (point or vector). The place of the models is going wrong.
Here is the code and demo site.
var viewer = new Cesium.Viewer(“globe-Container”, {
infoBox: false,
selectionIndicator: false
});
var globeScene = viewer.scene;
var ellipsoid = viewer.scene.globe.ellipsoid;
function addMesh(fileName, modelPosition, modelRotation) {
var oLat = -28.3045985862,
oLon = 32.0621455464,
oAlt = 0,
lat = oLat + (modelPosition.x / 1000000),
long = oLon + (modelPosition.z / 1000000),
alt = 0 + ((modelPosition.y) / 10),
heading = Cesium.Math.toRadians(modelRotation.y),
pitch = Cesium.Math.toRadians(modelRotation.z),
roll = Cesium.Math.toRadians(modelRotation.x),
offsetLat = (modelPosition.x / 1000000), // Adjusting the position to geo position.
offsetLong = (modelPosition.z / 1000000),
offsetAlt = (modelPosition.y / 10);
if (model1Flag) {
alt = 0 + ((modelPosition.y) / 10);
} else {
/* The models are loading below the ground level, So added +100 to the altitude */
alt = 0 + ((modelPosition.y + 100) / 10);
}
/* var ENU = new Cesium.Matrix4();
var position = Cesium.Cartesian3.fromDegrees(oLon, oLat, oAlt);
Cesium.Transforms.eastNorthUpToFixedFrame(position, ellipsoid, ENU);
var offset = new Cesium.Cartesian3(offsetLat, offsetLong, offsetAlt);
console.log(position);
var finalPos = Cesium.Matrix4.multiplyByPointAsVector(ENU, offset, new Cesium.Cartesian3());
console.log(finalPos);*/
var finalPos = Cesium.Cartesian3.fromDegrees(long, lat, alt);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(finalPos, heading, pitch, roll);
var entity = viewer.entities.add({
name: "gltf/" + fileName,
position: finalPos,
orientation: orientation,
model: {
uri: "gltf/" + fileName,
minimumPixelSize: 0
}
});
viewer.trackedEntity = entity;
}
function removeGlobeMesh() {
viewer.entities.removeAll();
}
var models = [
{gltffilename:“productsizingcrusher.gltf”,position:{x:0,y:34.6866455477384,z:0},rotation:{x:0,y:1.5707963267948966,z:0}},
{gltffilename:“smallpiller.gltf”,position:{x:0,y:0,z:0},rotation:{x:0,y:1.5707963267948966,z:0}},
{gltffilename:“basicironbeam.gltf”,position:{x:1.8474245779789382,y:56.978831129127812,z:.436160116231305},rotation:{x:0,y:1.5707963267948966,z:0}},
{gltffilename:“roof05.gltf”,position:{x:0,y:32.993313735315141,z:10.52622915735363},rotation:{x:0,y:0,z:0}}]
/* On click */
$("#loadModel").click(function () {
/* remove the models */
removeGlobeMesh();
/* To load the model into cesiumjs */
for (var j = 0; j < models.length; j++) {
if (models[j].gltffilename !== “”) {
addMesh(models[j].gltffilename, models[j].position, models[j].rotation);
}
}
});
``
The complete source code can be downloaded from **here. **
I’m totally struck with this problem. Please advice to fix it.
Thank you!