Using three.js library I have assembled a design(plant). That design is contains of so many smaller models which have the reference of position in (x,y,z) from origin (0,0,0). Attached the sample screenshot in the below link
Now I wanted to load the individual model with its own position into Cesium. When I try to load the directly converting the position (x,y,z) to (north, east, up) the result is not as expected. All the models are scattered.
The functionality which I am trying to achieve is, based on some origin (lon, lat, alt) point, I should position the model into cesium with reference of (x,y,z) relative to cesium coordinates (lon, lat, alt)
E.g.
origin geo-coordinates (ori_lon, ori_lat, ori_alt) => (-106.690647, 36.806761, 0)
Model coordinates (m_x, m_y, m_z) => (-150.9, 126.26, 217.7)
Expecting Coordinates for Cesium : (ori_lon + m_x, ori_lat + m_y, ori_alt + m_z)
or some algorithm to achieve this.I have tried with the below article to convert the (x,y,z) to the (long, lat, alt) with some origin (long, lat, alt), but no luck :(
(x, y, z) coordinates >> geo-coordinates
Advice/help to fix the issue.
--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Matthew,
Thank you so much for the explanation. I'm working on to implement the solution. I've a bit challenge to understanding some of the concepts.
· Reference frame the XYZ offset are in EarthFixed or NorthEastDown or EastNorthUp. How to find this? I've created these models with the reference of 0,0,0 in 3D plane. I'm not sure what exactly I need to convert or find out. Can you please send me some reference article on this?
· Screenshot :
Above screenshot will give the reference of model designed in three.js and the reference point on cesiumjs. The model which I’ve build is based in (0,0,0) axis point of 3D plane. And I want to build the same model in Cesium in the selected geo-coordinate point (32.0621175298, -28.3045768893, 0) as origin.
So, from the explanation, “convert origin to earth-fixed Cartesian” will refer to convert geo-coordinate point (32.0621175298, -28.3045768893, 0) to origin to earth-fixed Cartesian
i.e. var position = Cesium.Cartesian3.fromDegrees (oLon, oLat, oAlt) => (32.0621175298, -28.3045768893, 0); ??
Also, required little explanation on this “Then for each offset you just add the values.”
It will be very much helpful, If I get some reference on this.
Note: If required, I shall share the source code.
Thanks,Premkumar
var viewer = new Cesium.Viewer('cesiumContainer');
var ellipsoid = viewer.scene.globe.ellipsoid;
var ENU = new Cesium.Matrix4();
var position = Cesium.Cartesian3.fromDegrees(0,0,0);
Cesium.Transforms.eastNorthUpToFixedFrame(position,ellipsoid,ENU);
console.log(ENU);//Transform a point
var viewer = new Cesium.Viewer('cesiumContainer');
var ellipsoid = viewer.scene.globe.ellipsoid;
var ENU = new Cesium.Matrix4();
var position = Cesium.Cartesian3.fromDegrees(0,0,0);
Cesium.Transforms.eastNorthUpToFixedFrame(position,ellipsoid,ENU);
var offset=new Cesium.Cartesian3(2,0,0);
console.log(position);
var finalPos = Cesium.Matrix4.multiplyByPoint(ENU, offset, new Cesium.Cartesian3());
console.log(finalPos);//Transform a vector
var viewer = new Cesium.Viewer('cesiumContainer');
var ellipsoid = viewer.scene.globe.ellipsoid;
var ENU = new Cesium.Matrix4();
var position = Cesium.Cartesian3.fromDegrees(0,0,0);
Cesium.Transforms.eastNorthUpToFixedFrame(position,ellipsoid,ENU);
var localDir=new Cesium.Cartesian3(0,0,2);
console.log(localDir);
var EarthDir = Cesium.Matrix4.multiplyByPointAsVector(ENU, localDir, new Cesium.Cartesian3());
console.log(EarthDir);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) { 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); } }});
offsetEast= 0;
offsetNorth = 0;
offsetUp = 0;
var ENU = new Cesium.Matrix4();
var position = Cesium.Cartesian3.fromDegrees(oLon, oLat, oAlt);
Cesium.Transforms.eastNorthUpToFixedFrame(position, ellipsoid, ENU);//return result via parameter
var offset = new Cesium.Cartesian3(offsetEast, offsetNorth, offsetUp);
var finalPos = Cesium.Matrix4.multiplyByPoint(ENU, offset, new Cesium.Cartesian3());
//swap y and z
var temp = modelPosition.z;
modelPosition.z=modelPosition.y;
modelPosition.y=temp;While testing the swap be sure to comment this out/* altitude adjustment */
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); }
Also I think you've inadvertently commented this out
//to get model position
viewer.scene.primitives._primitives[i].modelMatrix[12] //position x of primitive 0
viewer.scene.primitives._primitives[i].modelMatrix[13] //position y of primitive 1
viewer.scene.primitives._primitives[i].modelMatrix[14] //position z of primitive 2//to get model EAST NORTH UP orientation
var myMatrix4 = new Cesium.Matrix4();
var myMatrix3 = new Cesium.Matrix3();
var EAST = new Cesium.Cartesian3();
var NORTH = new Cesium.Cartesian3();
var UP = new Cesium.Cartesian3();
myMatrix4 = viewer.scene.primitives._primitives[i].modelMatrix.clone();
Cesium.Matrix4.getRotation(myMatrix4,myMatrix3);
Cesium.Matrix3.getColumn(myMatrix3,0,EAST);
Cesium.Matrix3.getColumn(myMatrix3,0,NORTH);
Cesium.Matrix3.getColumn(myMatrix3,0,UP);Cesium.Matrix3.getColumn(myMatrix3,0,EAST);
Cesium.Matrix3.getColumn(myMatrix3,1,NORTH);
Cesium.Matrix3.getColumn(myMatrix3,2,UP); offsetNorth = modelPosition.x + adjustment value; // trying with different operators (+, -, * , /)
offsetEast = modelPosition.y + adjustment value;
offsetUp = modelPosition.z / adjustment value;
if (model1Flag) { mesh.position.set(position.x, position.y, position.z); } else { mesh.position.set(position.x - 350, position.y + 100, position.z + 300); }
x varies between 325 to 401 from the origin; so I adjusted -350 from x;y varies between -27 to -91 from the origin, so I adjusted +100 from y;z varies between -301 to -348 from the origin, so I adjusted +300 from z;
if(0) //make as entity
{
var entity = viewer.entities.add({
name: "gltf/" + fileName,
position: finalPos,
orientation: orientation,
model: {
uri: "gltf/" + fileName,
minimumPixelSize: 0
}
});
viewer.trackedEntity = entity;
}
else //make as primitive
{
var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
url : "gltf/"+fileName,
modelMatrix : ENU
}));
}var j=0;while(j<11)
{
if( (j!=3) && (j!=7) ){pick.primitive.modelMatrix[j]*=10;}
j+=1;
}var entity = viewer.entities.add({ name: "gltf/" + fileName, position: finalPos, orientation: orientation, model: { uri: "gltf/" + fileName, minimumPixelSize: 0, scale: 10 } }); viewer.trackedEntity = entity;