Get 3D cube from an Obb3

79 views Asked by At

given an Obb3 (Center, HalfVector and axis[3]),
how can I create a cube that has the same bounds as this Obb3 ? I'll then use this cube to display my obb3 bounds.

I use vector_math and three.dart libraries
So far, my code is :

Matrix3 rot_mat = new Matrix3(node.box.axis0[0], node.box.axis1[0], node.box.axis2[0],  
                              node.box.axis0[1], node.box.axis1[1], node.box.axis2[1],  
                              node.box.axis0[2], node.box.axis1[2], node.box.axis2[2]);
Vector3 diag = rot_mat.absoluteRotate(node.box.halfExtents.clone());
var geometry = new CubeGeometry(diag[0] * 2.0, diag[1] * 2.0, diag[2] * 2.0);
var material = new MeshBasicMaterial(color: 0x00ff00,
 wireframe: true,
 blending: NormalBlending,
 side: DoubleSide,
 shading: FlatShading);

var obj = new Mesh(geometry, material);
obj.position = node.box.center;
obj.matrix.setRotation(rot_mat);
obj.updateMatrix();
scene.add(obj);

Thanks a lot for your help :]

0

There are 0 answers