cesium icon indicating copy to clipboard operation
cesium copied to clipboard

[Suggestion] `OrientedBoundingBox.fromTransformation`

Open bbbbx opened this issue 2 years ago • 0 comments

https://github.com/CesiumGS/cesium/pull/10130 introduces some new functions, but OrientedBoundingBox.fromTransformation confuses me, I think without half scale is better.

image

The smaller box is computed with OrientedBoundingBox.fromTransformation, and bigger box computed without half scale.

code:


function CreateOBBPrimitiveHalfScale(matrix) {
  const obb = Cesium.OrientedBoundingBox.fromTransformation(matrix)
  const center = obb.center;
  const halfAxes = obb.halfAxes;

  const tileOBB = new Cesium.TileOrientedBoundingBox(center, halfAxes);
  return tileOBB.createDebugVolume(Cesium.Color.YELLOW);
}

function CreateOBBPrimitive(matrix) {
  const halfAxes = Cesium.Matrix4.getMatrix3(matrix, new Cesium.Matrix3());
  const center = Cesium.Matrix4.getTranslation(matrix, new Cesium.Cartesian3());

  const tileOBB = new Cesium.TileOrientedBoundingBox(center, halfAxes);
  return tileOBB.createDebugVolume(Cesium.Color.YELLOW);
}

function CreateMatrixPrimitive(matrix) {
  const matrixPrimitive = new Cesium.DebugModelMatrixPrimitive({
    modelMatrix : matrix,
    length : 1.0,
    width : 3.0
  });
  const obbPrimitive = CreateOBBPrimitive(matrix);
  const collection = new Cesium.PrimitiveCollection();
  collection.add(matrixPrimitive);
  collection.add(obbPrimitive);
  return collection;
}

viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(114, 23, 500), new Cesium.Cartesian3(0.1, 0, 0));
                     
                     
const M = viewer.camera.inverseViewMatrix.clone();

const p1 = CreateMatrixPrimitive(M);
viewer.scene.primitives.add(p1);

const p2 = CreateOBBPrimitiveHalfScale(M);
viewer.scene.primitives.add(p2);

viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(114, 23, 500), new Cesium.Cartesian3(20, 20, 0));

sandcastle

bbbbx avatar Jul 04 '22 02:07 bbbbx