xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
715 stars 286 forks source link

Creating a ReadableGeometry with buildBoxGeometry gives the wrong aabb #1388

Closed hamza-hajji closed 6 months ago

hamza-hajji commented 6 months ago

Describe the bug In version 2.5.2-beta-23, creating a box with buildBoxGeometry yields the wrong aabb values

To Reproduce Steps to reproduce the behavior:

  1. Go to https://xeokit.github.io/xeokit-sdk/examples/buildings/#xkt_vbo_Duplex
  2. Create a cube with 1.5x1.5x1.5 meters
  3. Check the node's aabb
    const dimensions = [1.5, 1.5, 1.5];
    const cubeGeometry = new ReadableGeometry(
    viewer.scene,
    buildBoxGeometry({
    center: [0, 0, 0],
    id: "Cube_Geometry",
        xSize: dimensions[0] / 2,
        ySize: dimensions[1] / 2,
        zSize: dimensions[2] / 2,
    })
    );
    const cubeMaterial = new PhongMaterial(viewer.scene, {
    // Blue by convention
    diffuse: [0.3, 0.3, 0.3],
    ambient: [0.0, 0.0, 0.0],
    specular: [0.6, 0.6, 0.3],
    shininess: 80,
    lineWidth: 2,
    });
    const node = new Node(viewer.scene, {
    id: "CubeNode",
    isModel: true,
    rotation: [0, 0, 0],
    position: [0, 0, 0],
    scale: [1, 1, 1],
    children: [
        new Mesh(viewer.scene, {
            // Shaft
            geometry: cubeGeometry,
            material: cubeMaterial,
            pickable: false,
            collidable: false,
            visible: true,
            position: [0, 0, 0],
            rotation: [0, 0, 0],
        }),
    ],
    });

Additionally, if I use scene.getAAB, I get different values. But Xmax-Xmin doesn't give 1.5, the width of the cube (Screenshot 3)

Expected behavior The values of aabb are right

Screenshots image

image

image

hamza-hajji commented 6 months ago

This issue was solved by making the Mesh collidable

new Mesh(viewer.scene, {
            // Shaft
            geometry: cubeGeometry,
            material: cubeMaterial,
            pickable: false,
            collidable: true,
            visible: true,
            position: [0, 0, 0],
            rotation: [0, 0, 0],
        }),