Hello Experts,
I’ve loaded two different gltf object on the scene and I need to get actual width of theese 3D objects. I’m using the following code be able to add an 3D object the scene. When I use the THREE.Box3().setFromObject(object).getSize(new THREE.Vector3()).x one of the 3D object’s width value is accurate. But the other 3D object’s with value is too long. I’ve tried many things be able to solve this. But I couldn’t do that. What should I do at this point ? How can I get the accurate width value of the 3D Gltf objects ?
Here is my code:
setupVehicle: function () {
//Setup Vehicle
var oVehicleGroup = new THREE.Group();
var [oFlag, oSphere] = base.setVehicleCountryFlag();
oLoader.load("./resources/models/turkuaz/scene.gltf", function (oGltf) {
if (oGltf.scene.children[0].isObject3D) {
var oObject3D = oGltf.scene.children[0];
// oObject3D.scale.set(0.004, 0.004, 0.004);
oObject3D.scale.multiplyScalar(5);
oVehicleGroup.type = "Midibus";
oVehicleGroup.name = "Midibus Turkuaz";
oVehicleGroup.userData.id = "midibus-" + jQuery.sap.uid();
oVehicleGroup.userData.name = "Midibus Turkuaz";
oVehicleGroup.userData.flag = oFlag;
oVehicleGroup.userData.sphere = oSphere;
oVehicleGroup.add(oObject3D);
oVehicleGroup.add(oFlag);
oVehicleGroup.add(oSphere);
oScene.add(oVehicleGroup);
oVehicleGroup.position.y = new THREE.Box3().setFromObject(oLayout).min.y;
oVehicleGroup.position.z = 27;
oVehicleGroup.rotation.y = Math.PI;
if (!allMidibusVehicles.length) {
oVehicleGroup.position.x = -620;
} else {
oVehicleGroup.position.x = (allMidibusVehicles[allMidibusVehicles.length - 1].position.x - new THREE.Box3().setFromObject(allMidibusVehicles[allMidibusVehicles.length - 1]).getSize(new THREE.Vector3()).x) - (turkuazVehicleCount * 50);
}
oFlag.rotation.y = -Math.PI;
oFlag.geometry.center();
oFlag.position.y = new THREE.Box3().setFromObject(oVehicleGroup).max.y + 30;
oSphere.geometry.center();
oSphere.position.y = new THREE.Box3().setFromObject(oVehicleGroup).max.y + 30;
allMidibusVehicles.push(oVehicleGroup);
}
});
},
Here is the image:
Thanks a lot for your help.