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
699 stars 281 forks source link

After rotating a model, I get the wrong aabb values #1316

Open hamza-hajji opened 6 months ago

hamza-hajji commented 6 months ago

Describe the bug Rotating a model makes its aabb wrong

To Reproduce Steps to reproduce the behavior:

  1. Open the https://xeokit.github.io/xeokit-sdk/examples/buildings/#xkt_vbo_Duplex example
  2. Rotate the model by 40° in Y axis viewer.scene.models.myModel.rotation = [0, 40, 0]
  3. check its abb, you get the wrong values

Expected behavior The aabb is still right after rotation

Screenshots

I made a script that draws a transparent cube given an aabb for testing:

const makeBox = (aabb) => {
  new Mesh(viewer.scene, {
    geometry: new ReadableGeometry(
      viewer.scene,
      buildBoxGeometry({
        center: [
          (aabb[3] + aabb[0]) / 2,
          (aabb[4] + aabb[1]) / 2,
          (aabb[5] + aabb[2]) / 2,
        ],
        xSize: (aabb[3] - aabb[0]) / 2, // Half-size on each axis
        ySize: (aabb[4] - aabb[1]) / 2,
        zSize: (aabb[5] - aabb[2]) / 2,
      })
    ),
    material: new PhongMaterial(viewer.scene, {
      // diffuseMap: new Texture(viewer.scene, {
      //   src: "textures/diffuse/uvGrid2.jpg",
      // }),
      backfaces: true,
      alpha: 0.2,
    }),
  });
};

It is correct initially before rotation

image

But after rotating:

image

Desktop (please complete the following information):

paireks commented 5 months ago

My observation after looking at it for a while, is that after the rotation (e.g. changing position doesn't seem to have a problem) the size of aabb seems probably fine, but its the position of aabb which is wrong. I can't find out however why wrong aabb is actually calculated. SceneModelEntity during get aabb() do this += this.origin of the aabb, so maybe there is something with this origin. But it's difficult to spot how this origin is being calculated and when.

paireks commented 5 months ago

I tried to dig a little further, found out that for some reason in web-ifc example there is no such problem after rotation

image

paireks commented 5 months ago

Few additional observations:

intrida-dev commented 2 months ago

Has this been fixed? #1379 seems to be closed.

xeolabs commented 2 months ago

@intrida-dev It has not been fixed. For distantly-placed models, I have not been able to make individual object rotations on objects work within xeokit's RTC tiles coordinate system. I'm not sure of a solution for that at this stage. Only translations currently work for all models.

intrida-dev commented 2 months ago

@xeolabs Ok. We will try applying translations until this gets fixed. Thanks