xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
497 stars 173 forks source link

IFC2x3 to Wexbim Conversion Problem with XBIM #464

Open ogz opened 1 year ago

ogz commented 1 year ago

Hi, I am trying to integrate XBIM Web UI in to our application. We have IFC files in the local file system. We convert these IFC files to WexBIM format to display them in the browser (via XBIM Web UI). As far as I see XBIMv4 supports IFC versions 2x3 and 4.

But in my case, conversion works correctly with IFC4 files but not with IFC2x3 files. There is no exception or error message during the process and one WexBIM file created after the conversion. But the result wexBIM file is only 1KB. And nothing is displayed on the browser if we load that wexBIM file to the browser.

Assemblies and versions affected:

.net 6 and XBIM.Geometry v5.1.437

Steps (or code) to reproduce the issue:

I just run the following code to perform the conversion

using (var model = GetModel(originalIFCFilePhysicalPath, wexbimDestFolderPath, ref ifcFileName))
{
    if (model == null)
    {
        Logger.Error("No ifc model to process");
        return GenericRequestResultCode.NotFound;
    }
    var context = new Xbim3DModelContext(model);

    context.CreateContext();
    using (var wexBiMfile = new FileStream(wexbimFilePhysicalPath, FileMode.Create, FileAccess.Write))
    {
        using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
        {
            model.SaveAsWexBim(wexBimBinaryWriter);
            wexBimBinaryWriter.Close();
        }
        wexBiMfile.Close();
    }
}

Minimal file to reproduce the issue:

IFC files need to be zipped to be uploaded. Then just drag & drop here

Expected behavior:

A valid WexBIM File

Actual behavior or exception details:

A WecBIM file with size of 1KB

willoftw commented 1 year ago

Hello there,

Could you provide the IFC2x3 file in question? I will see if I can replicate the issue on my end.

Thanks, Will

ogz commented 1 year ago

Hi Will, thank you. Here is the original file and the result wexBIM file

test.ifc.zip test.wexbim.zip

And also Test2_IFC 2x Editon3.zip Test2_WexBIM 2x Editon3.zip

willoftw commented 1 year ago

Hi Ogz, You say it is working for IFC4, but for the examples you provided, both of the wexbim are 1kb?

Regards, Will

ogz commented 1 year ago

Hi Will, The example IFC files are in IFC2x3 format and WexBIM files are the results of the conversion. They are the problematic files.

I didn't uploaded any IFC4 example files because they were converted correctly.

Regards, Reha

willoftw commented 1 year ago

Hi Ogz,

The issue is that the file provided does not adhere to CV-2x3

Here is the simple resolution: image

The reason I ask about the IFC4 example is that this shouldn't change with schema. Maybe it was exported with a different program?

Hope this helps, Will

ogz commented 1 year ago

Hi Will,

Sorry for the late response. Do you mean I should change the content of the file? Unfortunately, the file belongs to the customer and we are providing a CMS for the customer. Therefore I cannot modify the file. In addition, I don't know which program(s) they are using. The sample file has just been uploaded to the CMS server. But at least I will test your solution to see if it solves the problem.

Is there anything that I can do with a code change at the backend? Regards,

Reha

andyward commented 1 year ago

What you could do is validate & patch the models all in code - before you generate the geometry (with Xbim3DModelContext.CreateContext()).

If you look at the code in the Geometry engine we validate the IfcGeometricRepresentationContext are correct and log warnings where there are issues. e.g.

https://github.com/xBimTeam/XbimGeometry/blob/a2c02d249a05ba4797dc844ba76d64b155acbfdd/Xbim.ModelGeometry.Scene/Xbim3DModelContext.cs#L589

It would be possible to copy this validation into a pre-processing step, and then, instead of logging, go ahead and patch (transiently) the invalid IfcGeometricRepresentationContexts before calling CreateContext. Once you've done that and get no warnings you should be good.

The key thing is that according to the specification IfcGeometricRepresentation[Sub]Context.ContextType Attribute MUST be 'Model'

In your models the values are 'Mesh' and 'Solid' which is invalid and violates the implementors agreements.

Equally the ContextIdentifier attribute needs to be match a ShapeRepresentation's RepresentationIdentifier. See Figure 405 on the spec on the standards page

Hope that helps

ogz commented 1 year ago

Hi Will, Thank you for your response. I have tested your solution and it works if I change the content (IFCGEOMETRICREPRESENTATIONSUBCONTEXT) of the IFC file. But I furthermore have tested another file and there the following lines are missing:

IFCGEOMETRICREPRESENTATIONCONTEXT($, 'Plan'.............
IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Body', 'Model', .............
IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Box', 'Model',.............

I tried to manually add the lines, but there was no success. It ended with the following exception during the conversion.

Exception during ifc to wexbim conversion: System.NullReferenceException: Object reference not set to an instance of an object.
   at Xbim.ModelGeometry.Scene.Xbim3DModelContext.<>c__DisplayClass18_0.<.ctor>b__1(IIfcGeometricRepresentationContext c)
   at System.Linq.Enumerable.WhereListIterator`1.ToList()
   at Xbim.ModelGeometry.Scene.Xbim3DModelContext..ctor(IModel model, String contextType, String requiredContextIdentifier, ILogger logger)
   at PPMRoom.Services.XBimService.CreateTempWexbimFile(String originalIFCFilePhysicalPath, String wexbimFilePhysicalPath, String wexbimDestFolderPath) in E:\GitLab-Runner\builds\NnDCcrQP\0\ppm-raum\ppm-raum-backend\src\PPMRoom.Services\Services\XBimService.cs:line 155
[2022-12-14 14:27:26.7300 ERROR PPMRoom.Services.XBimService]

I have attached the file, do you have any idea about that matter? sample2.zip

Regards,

Reha

martin1cerny commented 1 year ago

In this case, geometry representations don't refer to any context at all. This is an invalid IFC file, because all subtypes of IfcRepresentation have to define their context.