示例#1
0
        public static GltfRef TryCreatingGltfRef(string ifcObjectGuid, B5dProjectNode project, B5dObject b5dObject)
        {
            var existingRef = DbLinq.Objects <GltfRef>().FirstOrDefault(o => o.BelongsTo == b5dObject);

            if (existingRef != null)
            {
                return(existingRef);
            }

            string documentsDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            string conversionPath     = $"{documentsDirectory}\\Conversions";

            var projectName   = project.Name;
            var b5dObjectType = b5dObject.TypeSpecifier.ToLower();

            b5dObjectType = b5dObjectType.Replace("ifc", "");
            // The ifcTo3DTiles conversion renames WallStandardCase to Wall
            b5dObjectType = b5dObjectType.Replace("wallstandardcase", "wall");

            var ifcDirectory = $"{conversionPath}\\Conversion_{projectName}\\IFCs";
            var files        = Directory.GetFiles(ifcDirectory);
            var ifcFiles     = files.Where(f => f.ToLower().Contains(b5dObjectType));

            if (ifcFiles.Count() == 0)
            {
                return(null);
            }

            foreach (string ifcFilePath in ifcFiles)
            {
                var ifcModel  = IfcStore.Open(ifcFilePath);
                var ifcObject = ifcModel.Instances.FirstOrDefault() as IIfcObject;
                if (ifcObject.GlobalId == ifcObjectGuid)
                {
                    var        gltfFilepath = ifcFilePath.Replace("IFCs", "GLTFs").Replace(".ifc", ".gltf");
                    FileStream gltfFile     = File.Open(gltfFilepath, FileMode.Open);
                    var        filename     = Path.GetFileName(gltfFilepath);

                    if (ifcObject != null && gltfFile != null)
                    {
                        var fileRef = new GltfRef()
                        {
                            BelongsTo = b5dObject,
                            Extension = "gltf",
                            FileId    = ifcObjectGuid,
                            FileName  = filename,
                            MimeType  = "model/gltf+json",
                            FileSize  = gltfFilepath.Length,
                        };
                        return(fileRef);
                    }
                    break;
                }
            }

            return(null);
        }
示例#2
0
        public B5dProjectNode BuildTree(B5dObject b5dParent, IIfcObjectDefinition ifcParent, IIfcObjectDefinition ifcChild)
        {
            B5dProjectNode b5dChild = IfcObjectConverter.Convert(ifcChild);

            if (ifcChild is IIfcProject)
            {
                currentProject = b5dChild;
            }
            else
            {
                GltfRef.TryCreatingGltfRef(ifcChild.GlobalId.ToString(), currentProject, b5dChild);
            }


            if (b5dParent != null)
            {
                B5dProjectNodeChild ChildRelationship = B5dProjectNodeChild.CreateNodeChildRelation(b5dParent, b5dChild);
            }

            if (ifcChild is IIfcObject ifcObject)
            {
                // Use containsElements to recursively create nodes for Window, Door, Slab, Wall etc
                foreach (var ifcSpatialElement in RelContainedInSpatialStructure.GetElementsIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialElement);
                }

                // Use isDecomposedy to recursively create nodes for Project, Site, Building, Story and Space
                foreach (var ifcSpatialStructure in RelAggregates.GetSpatialStructuresIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialStructure);
                }

                // Use isDefinedBy to convert all of the ifcProperties
                PropertyConverter.ConvertProperties(ifcObject, b5dChild);
            }

            return(b5dChild);
        }