ThatOpen / web-ifc-viewer

Graphics engine and toolkit for client applications.
MIT License
947 stars 235 forks source link

Origin of IFC Models looks shifted #124

Closed ostwalprasad closed 2 years ago

ostwalprasad commented 2 years ago

Hello!👋

Thank you for the support on the discord channel, I'm opening this issue for the continuing discussion.

A lot of IFC files seem to be shifted from their origin as seen in the screenshots below. These example files are taken from https://github.com/IFCjs/test-ifc-files

image image image

The model itself looks alright, but when the coordinates are to be used/communicated with different systems like IfcOpenShell it becomes a bit difficult because the coordinates do not match.

The COORDINATE_TO_ORIGIN argument to applyWebIfcConfig also doesn't seem to have any effect.

Links for the above files in screenshot: https://github.com/IFCjs/test-ifc-files/blob/main/Others/haus.ifc https://github.com/IFCjs/test-ifc-files/blob/main/Others/479l7.ifc https://github.com/IFCjs/test-ifc-files/blob/main/Revit/rst_advanced_sample_project.ifc

Moult commented 2 years ago

I ran into this today - the origin is meant to be at the centroid of the cube, but instead is at a corner.

test.ifc.txt

2022-09-07-175602_1024x478_scrot

agviegas commented 2 years ago

Hi! IFC.js has an option called COORDINATE_TO_ORIGIN, which moves the geometry of the file to the origin (ignoring the data within the IFC file) to prevent numerical stability issues if the file is very far away from the origin. At first we were using the IFC data to do this, but we found that the data was not correct in many cases. We decided to go for the solution that succeded in most use cases and pick a random triangle of the geometry as origin of transformation.

Of course, all data is available using IFC.js API, so that any dev can provide options to the user to federate multiple models. We store the transformation matrix used in each model, so that multiple models can be coordinated using it, and the real coordinates of any point in space can be infered. By disabling this option, the IFC will be located in its real position.

I'm closing this for now. If you have a specific problem with a file that you can't locate where you want, feel free to open another issue.

Moult commented 2 years ago

At first we were using the IFC data to do this, but we found that the data was not correct in many cases

Can you elaborate on this? I feel there is a better solution than universally moving the origin for every model. In Blender, we only create a false origin when the model is using map coordinates.

agviegas commented 2 years ago

Using the data of the properties of IFC that describe the position of a model in space resulted in numerical stability issues in many cases. We found that optionally allowing users to just bring the geometry to the origin work in 100% of the use cases. This is not the only way to work with IFC.js: you can also query the data of the IFC to get its actual position. The library users often have little control of the IFCs they have to work with, so giving them an optional approach that always works (and even allows them to federate multiple models), regardless of the quality of the model, makes them happy. Users that want to use the IFC-defined origin also have the power to do so already.

But hey, if you'd like to propose an optional alternative approach, PRs are open! 🙂