How to convert x,y,z to longitude, latitude, altitude in Cesium?

Hi,

There are no units in three.js. Just have to be consistent with what the units mean.

Regarding the model 2 inputs.

In the actual design, the models will load below the ground level. Also, the model is build in negative z axis. That is the reason, You can see the below code in addModel function from “WebGL.three.js” file. It is just to position the models in the center.

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 you comment out the else condition from the above code. the model will get load in the same position. you should zoom out and see the model. But the models will still in the same structure. only the position will be differs.

I believe, CesiumJS is not supporting JSON format. I may be wrong!

The 3D models are designed in Blender and exported as Collada (for Cesium and converted into gltf) and JSON (for Three.JS).

Three.JS is having separate plugin for Blender to convert to model into JSON (https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender).

If CesiumJS supports same JSON format, then we can use it directly. But I didn’t see a single example with JSON loader in CesiumJS.

Regarding geoposition, I try to convert the XY to LAT & LONG from this link (http://www.whoi.edu/marine/ndsf/cgi-bin/NDSFutility.cgi?form=0&from=XY&to=LatLon). But it’s of no use!

If CesiumJS can’t load JSON models, maybe try loading GLTF models into ThreeJS and see what happens.

https://github.com/KhronosGroup/glTF/tree/master/loaders/threejs

an example

http://threejs.org/examples/webgl_loader_gltf.html

Are these JSON models uncompressed GLTF models?

http://threejs.org/examples/models/gltf/monster/monster.json

http://threejs.org/examples/models/gltf/duck/duck.json

Is this the only other resource to the duck model?

http://threejs.org/examples/models/gltf/duck/duckCM.png

I made some changes just to the addMesh function, and it affected the model in ThreeJS, is that supposed to happen?

JavaScript is pass by value for primitives, but not for objects. I changed to
addMesh(models[j].gltffilename, {x:models[j].position.x,y:models[j].position.y,z:models[j].position.z}, models[j].rotation);

So when modelPosition is changed in addMesh it no longer affects the models in ThreeJS.

Just in case I also did

addModel(models[i].filename, {x:models[i].position.x,y:models[i].position.y,z:models[i].position.z}, models[i].scale, models[i].rotation);

Primitives give you full control over the modelMatrix. I’ve been scaling the primitives, I don’t know how to scale entity models.

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
}));
}

``

Place this within the double click code so each time you double click a part it increases in size 10 fold, for example

var j=0;while(j<11)
{
if( (j!=3) && (j!=7) ){pick.primitive.modelMatrix[j]*=10;}
j+=1;
}

``

Hi,

I don’t have any problem with ThreeJS. I can load gltf or JSON or OBJ formats. In CesiumJS we have only GLTF file support. That’s fine. we were able to load the 3D models.

The below code will help to load the models with the scaling. I’ve tried using the same scaling from ThreeJS to CesiumJS. But still not resolving the position problem.

var entity = viewer.entities.add({

name: “gltf/” + fileName,

position: finalPos,

orientation: orientation,

model: {

uri: “gltf/” + fileName,

minimumPixelSize: 0,

        scale: 10

}

});

viewer.trackedEntity = entity;

``

I believe, I’m missing some minor thing.

Let me know, if you got any clue.

Thank you!

The reason I was suggesting loading GLTF models in ThreeJS was to see how the pieces come together there using the provided model positions as the model origin might be different between the GLTF and JSON models. For example, let’s say verticie B is +2 x units from verticie A. Well there are an infinite amount of ways to achieve by the sliding the model around relative to the origin
-A could be (-1,0,0) and B would be (1,0,0)

-A could be (3,2,4) and B would be (5,2,4)

-And so on.

Model origin is placed at the translation point specified by modelMatrix, in terms of Earth coordinates.

East component of ENU Matrix determines what direction +x points towards, in terms of Earth coordinates.

To make things more complicated is the model scale. Even if you had the models in the correct positions it wouldn’t be obvious if they were at the wrong scale.

OK so you might be able to initialize the modelMatrix of a model in a entity, but can you change it after that? That’s what’s nice about primitives, you have full control over the modelMatrix at all times. I think I’ll work on a full-blown modelMatrix editor for the selected primitive in Cesium to figure out how to put these sub-models together, though it wouldn’t be nearly as as fancy as the one in ThreeJS.

Hi,

Thank you for your support.

I’m working on to update my code to support GLTF format. It seems there is a bug in the plugin. I’m trying to fix it. I shall send you the link shortly.

Meantime, if you find something positive. Please update.

Thank you!

Hi Hyper Sonic,

I really appreciate your support on this.

I’ve spend time on experimenting the Three.JS gltf loader. It is not compatible with the version of gltf convertor. So, I’m not in a position to update the site with gltf loader. I’m still following with the issue to be fix.

So, have you get some time to spend on this (modelMatrix editor for the selected primitive in Cesium to figure out how to put these sub-models together.). any findings?

Thank you!

I plan to work on it this weekend. I’m thinking of making a modelMatrix manipulator module for a selected model in my Space Navigator plugin https://groups.google.com/d/msg/cesium-dev/PHEkXPyLKQw/-FQuJswORjwJ
This way I can easily add Space Navigator control over the modelMatrix for very fine precision manipulation. The plugin can easily be plugged into any app.

Excellent feature! Thank you so much Hyper!

Hi Hyper,

Greetings to you!

Have you get some time to spend on “Adding Space Navigator control over the selected model”…?

Thank you!

I’ve got it started, I’ve added a test model that can be selected and unselected to test with. When selected I’m having it put it through the same paces as I do the camera, so you’re be able to move the model in 5DOF or 6DOF, with keyboard or with a Space Navigator, maybe even with a 2D Mouse. I have to make my own functions for the models, can’t use the camera functions to manipulate those. I should have it done soon!

Thank you for the update!

Once the navigator for the selected model is implemented, I can go for reverse engineering to find the offset value between the XYZ and Geo-location to load the model at the exact place.

Thank you!

Hi Hyper,

Have you get some time to spend to implement space navigator for the selected model? Any luck?

Thank you!

Sorry, I haven’t checked the forum lately, though that gives me more time to work on my projects!

All of model1’s sub-models have the model origin near the center of the mesh (as can be observed by rotating around their own axis), same with most of model2’s sub-models, all except for the first 2 as indicated in the video.

Model manipulation (rotations and translations) is all done with the plugin, all the app has to do it just include it. You can use keyboard or 3DMouse. I plan to add add a few different rotation modes that use different reference frames (self,ENU,cam.) Once all models are placed, the position/orientation information can be saved, world relative or relative to any other reference. Perhaps a measuring grid model could be placed in Cesium and the models could be scaled to the proper size as well all on the fly.

hi,I am working on cesium flight simulator and I just wanted to run my final code without going into sandcastle.for example if user have to see the model then he should just double click on a html or any file that contains cesium code. can you help me with this?