CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.71k stars 307 forks source link

is that the georeference information lost when convert into gltf/glb ? #142

Closed fzlavr closed 6 years ago

fzlavr commented 6 years ago

Hi.. i want to kindly ask this question.. i have a 3D model, it has obj file format generated by Photoscan. Then, i want to put it inside cesium. first i need to convert it into gltf/glb. i have successfully converted it. but when i put it inside Cesium the object (gltf/glb) position is not correct. it is tilt. before i genereate the obj file i have change the georeference into WGS84 which is same like Cesium. but why after the conversion into gltf/glb the position is not correct ? is the georeference information has lost after it converted ?

here is the image of tilted model https://imgur.com/6ox0pAP

it always like that after conversion..

lilleyse commented 6 years ago

Hi @fzlavr - if the vertex data of the obj is in WGS84 coordinates then it should be preserved and drawn correctly in Cesium. Would you mind uploading the obj model and paste the Cesium code you used?

fzlavr commented 6 years ago

Hi @lilleyse thanks for your reply.. here is my obj model http://www.mediafire.com/file/xw978cg2y7c24ba/photoscan.zip and i use this cesium code

var viewer = new Cesium.Viewer('cesiumContainer', { infoBox : false, selectionIndicator : false, shadows : false, shouldAnimate : true });

function createModel(url, height) {

viewer.entities.removeAll();

var position = Cesium.Cartesian3.fromDegrees(121.607209, 23.988376, height);

var heading = Cesium.Math.toRadians(135);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

var entity = viewer.entities.add({
    name : url,
    position : position,
    orientation : orientation,
    model : {
        uri : url
        //minimumPixelSize : 128,
        //maximumScale : 20000
    }
});
viewer.trackedEntity = entity;

} createModel('../Apps/SampleData/wgs84.gltf', 10.0);

i have seen the sandcastle example model. it is very good that has planar position with the ground.. i wonder how it can be like that, because i always had a wrong result position after it convert into gltf/glb

fzlavr commented 6 years ago

Hi @lilleyse i have solved my problem with Meshlab. i dont know why but every obj that i created even it has georeferenced all of them are seem to be like my previous screenshot. So, i open it in Meshlab and it reveals all the orientation positions perfectly same as Cesium. then, i just set the X rotation to be planar with the ground and i save it. after that the position is perfectly great and just put it into Cesium without any manual set of heading, pitch, and roll.

lilleyse commented 6 years ago

Ok I'm glad you solved it. I didn't have any luck placing the model correctly myself so that additional X rotation must be the fix.

hubert-thieriot commented 5 years ago

Hi @fzlavr ,

I'm facing similar issues and have a related question...

Issue Using your very obj file: on meshlab it looks fine, well aligned with xy plan. Yet when I load it on Cesium, it indeed looks in the wrong angle. How exactly did you tilt it back in meshlab? See screenshot below:

Screenshot 2019-06-17 at 5 23 43 PM

Related question About the georeferencing of the obj / glb file: do we have to set the position everytime we load a glb file? Can this information be stored in the glb file during the conversion? Or is there another pipeline that keeps exact georeferencing from photogrammetry software to Cesium rendering? Apologies if this is a beginner question, I'm a beginner with these file formats..