ThatOpen / engine_components

MIT License
350 stars 134 forks source link

IfcFragmentLoader creates transformations with shear, causing problems down the line #369

Closed wlinna closed 5 months ago

wlinna commented 7 months ago

Describe the bug 📝

When I import certain models with IfcFragmentLoader, the loading process introduces shearing to the matrices. Shearing is not supported well by some engines. See this issue for example.

There's no clear way to detect shearing in matrices, which means that the only way to make geometries generated by IfcFragmentLoader to work outside is to duplicate them and apply the corresponding instance matrices to them. This wastes memory and / or increases file sizes (if for example I decide to export the model in glTF format). And figuring out the problem can be very difficult in the first place.

EverythingMisplaced

Reproduction ▶️

https://shear-problem.netlify.app/

Steps to reproduce 🔢

  1. Open reproduction
  2. Wait until it has loaded the pre-configured IFC file
  3. Save the exported GLB file wherever you want
  4. Open the GLB in Blender or any other glTF-capable viewer
  5. Observe how every component has been misplaced.

The problem is that the matrix cannot be decomposed cleanly into position, rotation and scale as has been established in this issue this issue.

The code is unoptimized so it can be read. And it's based on IfcFragmentLoader example with some extras removed (and IfcSite is added to the excluded categories).

System Info 💻

System:
    OS: Linux 6.8 Pop!_OS 22.04 LTS
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 18.33 GB / 31.19 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.12.2 - /usr/bin/node
    npm: 10.5.0 - /usr/bin/npm
  Browsers:
    Chromium: 123.0.6312.105
  npmPackages:
    openbim-components: 1.5.0 => 1.5.0

Used Package Manager 📦

npm

Error Trace/Logs 📃

No response

Validations ✅

HoyosJuan commented 7 months ago

Hi @wlinna!

Have you tried to apply the FragmentsGroup.coordinationMatrix to the elements right before exporting the model to GLB?

wlinna commented 7 months ago

EDIT: Hi there, thanks for the response!

When I apply coordinationMatrix to the model, I do it on the root of the model. However, whether I apply it or not, this problem remains the same. I have indeed tried.

agviegas commented 5 months ago

Hi @wlinna this might happen due to 2 reasons:

1 - You are probably using the web-ifc option OPTIMIZE_PROFILES: true. This is something that we set as true by default because it helped with performance, but now that we have streaming we are removing that option for simplicity's sake. Basically, this deduplicates all circular and rectangular extrusions. This shouldn't be an issue in future versions, and if you are using a past version, you can already disable that by setting that option to false when reading an IFC.

2 - Because the shear comes from the IFC itself.

If the cause is 1, is solved. If the cause is 2, there's nothing we can do, because we are just reading the transformations present in the IFC and using them to create the geometry. Either way, this issue is either solved, or has no solution. Let us know!

wlinna commented 2 months ago

Thank you, OPTIMIZE_PROFILES was the cause. The problem disappears once I disable it