Ejemplo n.º 1
0
 public void TransformSceneInPlace(Func <IMesh, IMesh> meshTransform = null, Func <VimSceneNode, VimSceneNode> nodeTransform = null)
 {
     if (meshTransform != null)
     {
         Geometries = Geometries.Select(meshTransform).EvaluateInParallel();
     }
     if (nodeTransform != null)
     {
         VimNodes = VimNodes.Select(nodeTransform).EvaluateInParallel();
     }
 }
Ejemplo n.º 2
0
 public IEnumerable <VimSceneNode> VimNodesWithGeometry()
 => VimNodes.ToEnumerable().Where(n => n.GetGeometry() != null);
Ejemplo n.º 3
0
        public VimScene(SerializableDocument doc, ICancelableProgressLogger progress = null, bool inParallel = false)
        {
            progress?.LogProgress($"Creating scene from {doc.FileName}", 0.0);
            _SerializableDocument = doc;

            var createPropertyLookupActions = new Action[]
            {
                () => ElementIndexFromElementId           = CreateEntityIdToIndexLookup(Model.ElementEntityTable),
                () => MaterialIndexFromMaterialId         = CreateEntityIdToIndexLookup(Model.MaterialEntityTable),
                () => FamilyInstanceIndexFromElementIndex = CreateEntityIndexToIndexLookup(Model.FamilyInstanceEntityTable),
                () => FamilyTypeIndexFromElementIndex     = CreateEntityIndexToIndexLookup(Model.FamilyTypeEntityTable),
                () => FamilyIndexFromElementIndex         = CreateEntityIndexToIndexLookup(Model.FamilyEntityTable),
                () => ViewIndexFromElementIndex           = CreateEntityIndexToIndexLookup(Model.ViewEntityTable),
                () => AssemblyIndexFromElementIndex       = CreateEntityIndexToIndexLookup(Model.AssemblyInstanceEntityTable),
                () => DesignOptionIndexFromElementIndex   = CreateEntityIndexToIndexLookup(Model.DesignOptionEntityTable),
                () => LevelIndexFromElementIndex          = CreateEntityIndexToIndexLookup(Model.LevelEntityTable),
                () => PhaseIndexFromElementIndex          = CreateEntityIndexToIndexLookup(Model.PhaseEntityTable),
                () => RoomIndexFromElementIndex           = CreateEntityIndexToIndexLookup(Model.RoomEntityTable),
                // TODO: I think there are more entity tables missing
            };

            if (inParallel)
            {
                Parallel.Invoke(
                    () =>
                {
                    progress?.LogProgress("Creating Document", 0.1);
                    Document = _SerializableDocument.ToDocument();

                    progress?.LogProgress("Creating Model", 0.3);
                    Model = new DocumentModel(Document);

                    progress?.LogProgress("Creating lookups", 0.7);
                    Parallel.Invoke(createPropertyLookupActions);
                },
                    () =>
                {
                    progress?.LogProgress("Unpacking geometries", 0.1);
                    var srcGeo = _SerializableDocument.Geometry;
                    Geometries = srcGeo?.SubGeometries.Select(ToIMesh).Evaluate() ?? ((IMesh)null).Repeat(0);

                    progress?.LogProgress("Creating scene", 0.8);
                    VimNodes = GetExpandedVimSceneNodes(this, _SerializableDocument.Nodes, _SerializableDocument.GetExpansionMode()).ToIArray();
                    Nodes    = VimNodes.Select(n => n as ISceneNode);
                });
            }
            else
            {
                progress?.LogProgress("Creating IDocument", 0);
                Document = _SerializableDocument.ToDocument();

                progress?.LogProgress("Creating Model", 0.1);
                Model = new DocumentModel(Document);

                progress?.LogProgress("Unpacking geometries", 0.2);
                var srcGeo = _SerializableDocument.Geometry;
                Geometries = srcGeo?.SubGeometries.Select(ToIMesh).Evaluate() ?? ((IMesh)null).Repeat(0);

                progress?.LogProgress("Creating scene", 0.3);
                VimNodes = GetExpandedVimSceneNodes(this, _SerializableDocument.Nodes, _SerializableDocument.GetExpansionMode()).ToIArray();
                Nodes    = VimNodes.Select(n => n as ISceneNode);

                progress?.LogProgress("Creating element lookup", 0.5);
                ElementIndexFromElementId = CreateEntityIdToIndexLookup(Model.ElementEntityTable);

                progress?.LogProgress("Creating property lookup", 0.6);
                foreach (var action in createPropertyLookupActions)
                {
                    action.Invoke();
                }
            }

            progress?.LogProgress("Completed creating scene", 1.0);
        }