react-babylonjs icon indicating copy to clipboard operation
react-babylonjs copied to clipboard

Why is Mesh.showBoundingBox not available as a prop?

Open nene opened this issue 1 year ago • 2 comments

I was hoping to write the following:

function MyComp() {
  return (<box name="myBox" showBoundingBox={true} />);
}

But no such prop is available. So instead I need to do the following:

function MyComp() {
  const ref = useRef(null);
  useEffect(() => {
    if (ref.current) {
      ref.current.showBoundingBox = true;
    }
  }, []);
  return (<box name="myBox" ref={ref} />);
}

Interestingly showSubMeshesBoundingBox prop is available. But no showBoundingBox.

Using version 3.2.2 of react-babylonjs.

nene avatar Jan 14 '25 10:01 nene

Well, agree it should be there. The reason it's not showing is because it's declared here: https://github.com/BabylonJS/Babylon.js/blob/84580a00705d4513393988e3eb2cab0f2d9053b3/packages/dev/core/src/Rendering/boundingBoxRenderer.ts#L75

I'm using ts-morph to generate the props. Let me look into it. The prop you did find is declared on AbstractMesh: https://github.com/BabylonJS/Babylon.js/blob/84580a00705d4513393988e3eb2cab0f2d9053b3/packages/dev/core/src/Meshes/abstractMesh.ts#L602

brianzinn avatar Jan 14 '25 21:01 brianzinn

it's a bit hideous, but can be added following same way instancedBuffers were added, since it's declared in a different area of the code base of babylon.js and dynamically applied: https://github.com/brianzinn/react-babylonjs/blob/master/packages/react-babylonjs/tools/generate-code.ts#L509

brianzinn avatar Jan 14 '25 23:01 brianzinn