xBimTeam / XbimWindowsUI

The home of XbimXplorer and WPF components for your desktop BIM applications.
Other
255 stars 150 forks source link

How can I load&render wexBIM file in XbimWindowsUI #54

Closed metorm closed 7 years ago

metorm commented 7 years ago

I am working on a viewer system, which is aimed at loading structures as fast as possible.

Then I found that XbimWebUI uses a light-weight .wexBIM file, which can be loaded faster than standard ifc files and keeps the same GUID with origin ifc files. Is this possible to load .wexBIM file into XbimWindowsUI ? How can I do it ?

theebow commented 7 years ago

Hi, you have to notice that the elapsed time is due to load the Model (IfcStore) and not to render it (that is doing faster) Even if you success in viewing a wexbim file into WindowsUI, you 'll have to convert ifc file into wexbim one, then you 'll have to load an IfcStore and reduce performance as same as ifc file

This is my opinion, now if you want to do it, perhaps take look at the IfcStore::SaveAsxbim and the SurfaceLayer::BuildScene (that renderer the geometry in UI) : you will see that finally both seem to be a story of triangulation

regards

metorm commented 7 years ago

@theebow

It is OK for me to convert an .ifc file to a .wexBIM and store it in the disk. Next time I can load the *.wexBIM file directly.

So, currently we do not have an off-the-shelf API to load *.wexBIM files into WPF windows? If I custom SurfaceLayer::BuildScene to render the file, will other parts of the system (e.g. interactive selecting) still work?

BR

theebow commented 7 years ago

no i don't think there is actualy a way to load wexbim file in UI, and i don't know, if parts of the system still work : it was just a suggestion because i had to understand how work those methods and noticed similar features....but i didn't study them Exactly. i made a try one day to load multiple Ifc file in UI, i did it in the BuildScene method and i remember loosing the selection entity, but it was a little try ( a short dev) perhaps you will have to spend most time on this dev...but let the xBim Team answer for this 😉 And what about adding WebBrowser contol into your WPF windows ?

metorm commented 7 years ago

@theebow

I also need to load multi *.ifc files in one scene... You mean xBIM doesn't have this API too? When was it you tried to do this?

By "adding WebBrowser contol into your WPF windows", you mean I should try to embed WebUI into our local WPF program?

theebow commented 7 years ago

@metorm "you mean I should try to embed WebUI into our local WPF program?" Yes it may be a choice, i do it with a Windows Form capture

For loading multiple ifc file, i did a try, but as it was just a try, it was a bad Dev (jut a two hours whereas it would take weeks ...)

you can try this : in the SurfaceLayer::BuildScene just before : foreach (var wpfMeshGeometry3D in meshesByStyleId.Values) { wpfMeshGeometry3D.EndUpdate(); } //} insert this code DO NOT FORGET TO REPLACE FILE PATH !! :


                      using (IfcStore modelTmp = IfcStore.Open(E:\\Tests\\toto.ifc))
                        {
                            if (modelTmp.GeometryStore.IsEmpty)
                            {
                                var context = new Xbim3DModelContext(modelTmp);
                                context.CreateContext(progDelegate: null);
                            }

                            var geomStoreTmp = modelTmp.GeometryStore;
                            using (var geomReaderTmp = geomStoreTmp.BeginRead())
                            {
                                //get a list of all the unique style ids then build their style and mesh
                                var sstyleIdsTmp = geomReaderTmp.StyleIds;
                                foreach (var styleId in sstyleIdsTmp)
                                {
                                    var wpfMaterial = GetWpfMaterial(modelTmp, styleId);
                                    materialsByStyleId.Add(styleId, wpfMaterial);

                                    var mg = GetNewStyleMesh(wpfMaterial, tmpTransparentsGroup, tmpOpaquesGroup);
                                    meshesByStyleId.Add(styleId, mg);
                                }

                                List<Type> myListe = new List<Type>();
                                myListe.Add(typeof(IfcVirtualElement));
                                var excludedTypesTmp = model.DefaultExclusions(myListe);

                                foreach (var shapeInstance in geomReaderTmp.ShapeInstances.Where(s=>s.IfcTypeId==excludedTypesTmp.First()))
                                {
                                    // work out style
                                    var styleId = shapeInstance.StyleLabel > 0
                                        ? shapeInstance.StyleLabel
                                        : shapeInstance.IfcTypeId * -1;

                                    if (!materialsByStyleId.ContainsKey(styleId))
                                    {
                                        // if the style is not available we build one by ExpressType
                                        var material2 = GetWpfMaterialByType(modelTmp, shapeInstance.IfcTypeId);
                                        materialsByStyleId.Add(styleId, material2);

                                        var mg = GetNewStyleMesh(material2, tmpTransparentsGroup, tmpOpaquesGroup);
                                        meshesByStyleId.Add(styleId, mg);
                                    }

                                    {
                                        IXbimShapeGeometryData shapeGeom = geomReaderTmp.ShapeGeometry(shapeInstance.ShapeGeometryLabel);
                                        WpfMeshGeometry3D targetMergeMeshByStyle = null;

                                        // if is a forcing color entity
                                        targetMergeMeshByStyle = meshesByStyleId[styleId];

                                        if (shapeGeom.Format != (byte)XbimGeometryType.PolyhedronBinary)
                                            continue;

                                        var transform = XbimMatrix3D.Multiply(shapeInstance.Transformation, modelTransform);
                                        targetMergeMeshByStyle.Add(
                                            shapeGeom.ShapeData,
                                            shapeInstance.IfcTypeId,
                                            shapeInstance.IfcProductLabel,
                                            shapeInstance.InstanceLabel, transform,
                                            (short)modelTmp.UserDefinedId);
                                    }
                                }
                            }
                        }
metorm commented 7 years ago

Unfortunately, my boss insists on using native xBIM code instead of a web browser control... Thanks anyway.

Your code about loading multiple ifc is useful. I will try to compile/improve it later. I will post it here once I fix all the issue in loading multiple ifc files. Thanks very much @theebow

CBenghi commented 7 years ago

Hello and apologies... I had missed this thread over the holiday period, @metorm, have you sorted this? It's not clear to me if you have noticed that saving the file as xbim stores the cache fully, so that loading time are much faster after that. Can you confirm? Claudio

metorm commented 7 years ago

@CBenghi Well, I am working on another (totally irrelevant) project in recent month ... The xBIM project is abandoned by my boss because it seems to require too much development. The web/js version is being used now by them, but I do not belong to that group...

CBenghi commented 7 years ago

Thanks,

I'm sorry to hear that, please let your boss know that other people have found our solution easy to embed just by asking us to develop the most complex components and working together on the architecture.

Anyway, I'll close this issue then. Best, Claudio