Currently tackling a project involving the creation of a 3D Widget for rotating, scaling, and translating a mesh. Facing challenges with positioning the cone used for scaling the parent mesh. Here is the code snippet in question:
function generateScaleWidget(parentMesh, constantScale){
var boundingBox = new THREE.Box3().setFromObject(parentMesh);
var material = new THREE.MeshBasicMaterial({
color: 0x0000ff
});
var coneGeometry = new THREE.CylinderGeometry(0, constantScale, 10, 50, 20, false);
var coneMesh = new THREE.Mesh(coneGeometry, material);
coneMesh.position.y = boundingBox.max.y/2; //assuming all the objects are placed on the ground
coneMesh.position.z = boundingBox.max.z+10;
coneMesh.position.x = boundingBox.max.x+10;
parentMesh.add(coneMesh);
}
parentMesh is the mesh for which the widget is being created, coneMesh is the widget. The goal is to position the cone at the center of the mesh (in terms of y-axis) and at an angle relative to the bounding box (ideal placement would be on the right side of the face bounding box facing the camera). Issues may arise due to the fact that coneMesh is a child of parentMesh, making the final position dependent on both the bounding box and the position of the parentMesh itself.