Dear Cesium Team,
I am trying to load tileset.json file in cesium viewer but i am not able to set the exact location location of that particular tileset file and the orientation of that modal is also wrong. I tried to find all the solutions but i am not able to get it. kindly i request you to please help me as soon as possible.
Here is the code
const viewer = new Cesium.Viewer(‘cesiumContainer’, {
terrainProvider: Cesium.createWorldTerrain()
});
const latitude = 28.6496374696;
const longitude = 77.2120535173;
const elevation = 16.4954383582;
var heading = 0; //Cesium.Math.toRadians(0);
var pitch = -0.3; //Cesium.Math.toRadians(10);
var roll = -120.6882219912; //Cesium.Math.toRadians(0);
var modelMatrix = new Cesium.Matrix4();
var headingPitchRoll = new Cesium.HeadingPitchRoll(heading,pitch,roll);
var tileset = undefined;
var cartographic = Cesium.Cartographic.fromDegrees(longitude, latitude, elevation);
var cartesian = Cesium.Cartographic.toCartesian(cartographic);
var transform = Cesium.Transforms.headingPitchRollToFixedFrame(cartesian, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, modelMatrix);
//var transform = Cesium.Transforms.headingPitchRollToFixedFrame(tileset.boundingSphere.center, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, modelMatrix);
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : './SampleData/Cesium3DTiles/Tilesets/Tileset-ankit/tileset.json',
}));
// tileset.modelMatrix = modelMatrix;
tileset.readyPromise.then(function(loaded_tileset) {
viewer.scene.primitives.add(tileset);
loaded_tileset._root.transform = transform;
viewer.zoomTo(loaded_tileset);
});
When i upload same Mesh into ION i am able to setup the location and orientation and can use it easily. but i want to achieve this from tileset.json.
Thanks in advance. Waiting for your response.
Hi there. I struggled on the same problem for a long time and just managed to find a solution. The problem when importing an asset from a tileset.json is the origin of your asset will be in the center of the earth. So it’s easy to perform a translation, but not a rotation. The trick is to apply the rotation after your tileset is loaded by defining the origin of headingPitchRollToFixedFrame
as the center of the tileset’s boundingsphere. I see that you did that but before your tileset was loaded. Try to do it after.
So first thing to do in so un-comment your transform
variable (and comment the previous one) that takes into account the center of the tileset’s bounding sphere. At the end of your code
tileset.readyPromise.then(function(loaded_tileset) {
viewer.scene.primitives.add(tileset);
loaded_tileset._root.transform = transform;
viewer.zoomTo(loaded_tileset);
});
add a tileset.root.transform = modelMatrix
. It should do the trick to rotate your tileset correctly
@theogerritsen
Respected Sir,
Thaks for your response, but i am not able to access the tileset.boundingSphere.center because it is not present in my tileset.json file. I am also trying to get this value from object of tileset by this > tileset._root._boundingSphere.center but it is redirect on somewhere else which is not my correct position. I am totally confused how to plot the correct orientation with position. Right now i am adding the manual heading, pitch and roll which is actully wrong approch. i need to make it automatically grab the heading, pitch roll and position so that whatever modal of tileset i can load, it will loaded without any code level setting.
I am pasting my all code. Please see once and give your valueable word and guidence.
here is the code:
// Your access token can be found at: Cesium ion.
// This is the default access token from your ion account
// Grant CesiumJS access to your ion assets
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZTI5OGE3ZS00YjQ4LTRjNWYtYmEyNS0zNzU5NDdmMDNjZmMiLCJpZCI6NzQ4OSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0OTUyMTU0N30.-xQTfe4Lp6ro_rlFzgo-UtxeoU7W1LoGlc213hXbRqI";
// Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
const viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain()
});
const latitude = 28.652433447919023;
const longitude = 77.21181285944374;
const elevation = 16.4954383582;
var heading = 0; //Cesium.Math.toRadians(0);
var pitch = -0.3; //Cesium.Math.toRadians(10);
var roll = -120.6882219912; //Cesium.Math.toRadians(0);
var modelMatrix = new Cesium.Matrix4();
var headingPitchRoll = new Cesium.HeadingPitchRoll(heading,pitch,roll);
var tileset = undefined;
var cartographic = Cesium.Cartographic.fromDegrees(longitude, latitude, elevation);
var cartesian = Cesium.Cartographic.toCartesian(cartographic);
var transform = Cesium.Transforms.headingPitchRollToFixedFrame(cartesian, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, modelMatrix);
//var transform = Cesium.Transforms.headingPitchRollToFixedFrame(tileset.boundingSphere.center, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, modelMatrix);
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : './SampleData/Cesium3DTiles/Tilesets/Tileset-ankit/tileset.json',
}));
// tileset.modelMatrix = modelMatrix;
tileset.readyPromise.then(function(loaded_tileset) {
viewer.scene.primitives.add(tileset);
loaded_tileset._root.transform = transform;
viewer.zoomTo(loaded_tileset);
});
here is the screenshot of wrong orientation
Thanks waiting for your response sir