I needed to read coordinates of vertices of the geo-referenced gltf file(which have CESIUM_RTC extension) in ECEF so made some code but my result looks not correct.
I have attached the glb file. This glb file was extracted from the b3dm file of some 3d tileset.
This is the screenshot where I load the original 3d tileset in Cesium.
This is the screenshot where I load the attached, extracted glb file in the Cesium.
This is the code snippet which I tried to get coordinates in ECEF.
function test(parsedGltf) {
console.log(parsedGltf);
const firstMesh = parsedGltf.meshes[0];
const firstMeshFirstPrimitive = firstMesh.primitives[0];
const accessorIndexOfBatchId = firstMeshFirstPrimitive.attributes['_BATCHID'];
const accessorIndexOfPosition = firstMeshFirstPrimitive.attributes['POSITION'];
const batchIdAccessor = parsedGltf.accessors[accessorIndexOfBatchId];
const positionAccessor = parsedGltf.accessors[accessorIndexOfPosition];
const batchIdArray = readAccessorPacked(parsedGltf, batchIdAccessor);
const positionArray = readAccessorPacked(parsedGltf, positionAccessor);
const RTCCenter = parsedGltf.extensions.CESIUM_RTC.center;
console.log('CESIUM_RTC position', RTCCenter);
const RTCCenterPosition = new Cesium.Cartesian3(RTCCenter[0], RTCCenter[1], RTCCenter[2]);
let RTCCenterCartographic = Cesium.Cartographic.fromCartesian(RTCCenterPosition);
console.log('CESIUM_RTC geographic', Cesium.Math.toDegrees(RTCCenterCartographic.longitude), Cesium.Math.toDegrees(RTCCenterCartographic.latitude), RTCCenterCartographic.height);
let j = 0;
let maxTestBallCount = 10;
for(let i = 0; i < batchIdAccessor.count; i++) {
const batchId = batchIdArray[i];
if(batchId === window.pickedFeatureBatchId) {
let start = i * 3;
let x = positionArray[start];
let y = positionArray[start + 1];
let z = positionArray[start + 2];
console.log(j, 'gltf local position', x, y, z);
x += RTCCenter[0];
y += RTCCenter[1];
z += RTCCenter[2];
console.log(j, 'cartesian', x, y, z);
let cartographic = Cesium.Cartographic.fromCartesian(new Cesium.Cartesian3(x , y, z));
console.log(j, 'geographic', Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), RTCCenterCartographic.height);
viewer.entities.add({
position: new Cesium.Cartesian3(x, y, z),
ellipsoid: {
radii: new Cesium.Cartesian3(1, 1, 1),
material: Cesium.Color.RED.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
}
});
j++;
if(j > maxTestBallCount) {
return;
}
}
}
}
Any help would be thankful.data0.zip (1.6 MB)