Exemplo n.º 1
0
        private void RecursivelyParseLayerHierarchy(Layer CurrentLayer, RhinoSceneHierarchyNode ParentNode)
        {
            if (!CurrentLayer.IsVisible || CurrentLayer.IsDeleted)
            {
                return;
            }

            int       MaterialIndex                 = CurrentLayer.RenderMaterialIndex;
            Transform ParentTransform               = ParentNode.bIsRoot ? ExportOptions.Xform : ParentNode.Info.WorldTransform;
            RhinoSceneHierarchyNodeInfo NodeInfo    = GenerateNodeInfo(CurrentLayer, ParentNode.bIsInstanceDefinition, MaterialIndex, ParentTransform);
            RhinoSceneHierarchyNode     CurrentNode = ParentNode.AddChild(NodeInfo, CurrentLayer.Index);

            GuidToHierarchyNodeDictionary.Add(CurrentLayer.Id, CurrentNode);
            LayerIndexToLayerString.Add(CurrentLayer.Index, BuildLayerString(CurrentLayer, ParentNode));
            AddMaterialIndexMapping(CurrentLayer.RenderMaterialIndex);

            RhinoObject[] ObjectsInLayer = RhinoDocument.Objects.FindByLayer(CurrentLayer);
            RecursivelyParseObjectInstance(ObjectsInLayer, CurrentNode);

            Layer[] ChildrenLayer = CurrentLayer.GetChildren();
            if (ChildrenLayer != null)
            {
                foreach (var ChildLayer in ChildrenLayer)
                {
                    RecursivelyParseLayerHierarchy(ChildLayer, CurrentNode);
                }
            }

            if (CurrentNode.GetChildrenCount() == 0)
            {
                // This layer is empty, remove it.
                ParentNode.RemoveChild(CurrentNode);
            }
        }
Exemplo n.º 2
0
        private void ParseRhinoHierarchy()
        {
            RhinoSceneHierarchyNode DummyDocumentNode = SceneRoot;

            if (bIsInWorksession)
            {
                // Rhino worksession adds dummy layers (with non consistent IDs) to all of the linked documents except the active one.
                // This can cause reimport inconsistencies when the active document changes, as dummies are shuffled and some may be created while others destroyed.
                // To address this issue we add our own "Current Document Layer" dummy layer, and use the file path as ActorElement name,
                // that way there are no actors deleted and the Datasmith IDs stay consistent.
                string    DummyLayerName       = RhinoDocument.Path;
                string    DummyLayerLabel      = RhinoDocument.Name;
                const int DefaultMaterialIndex = -1;
                const int DummyLayerIndex      = -1;

                DummyDocumentNode = SceneRoot.AddChild(GenerateDummyNodeInfo(DummyLayerName, DummyLayerLabel, DefaultMaterialIndex, ExportOptions.Xform), DummyLayerIndex);
                LayerIndexToLayerString.Add(DummyLayerIndex, BuildLayerString(DummyDocumentNode.Info.Label, SceneRoot));
            }

            foreach (var CurrentLayer in RhinoDocument.Layers)
            {
                //Only add Layers directly under root, the recursion will do the rest.
                if (CurrentLayer.ParentLayerId == Guid.Empty)
                {
                    RhinoSceneHierarchyNode ParentNode = bIsInWorksession && !CurrentLayer.IsReference
                                                ? DummyDocumentNode
                                                : SceneRoot;

                    RecursivelyParseLayerHierarchy(CurrentLayer, ParentNode);
                }
            }
        }
Exemplo n.º 3
0
        private void RecursivelyParseObjectInstance(RhinoObject[] InObjects, RhinoSceneHierarchyNode ParentNode)
        {
            foreach (RhinoObject CurrentObject in InObjects)
            {
                if (CurrentObject == null ||
                    IsObjectIgnoredBySelection(CurrentObject, ParentNode) ||
                    IsUnsupportedObject(CurrentObject))
                {
                    // Skip the object.
                    continue;
                }

                RhinoSceneHierarchyNode DefinitionRootNode = null;
                if (CurrentObject.ObjectType == ObjectType.InstanceReference)
                {
                    InstanceObject CurrentInstance = CurrentObject as InstanceObject;
                    DefinitionRootNode = GetOrCreateDefinitionRootNode(CurrentInstance.InstanceDefinition);

                    if (DefinitionRootNode.GetChildrenCount() == 0)
                    {
                        // Don't instantiate empty definitions.
                        continue;
                    }
                }

                int MaterialIndex = GetObjectMaterialIndex(CurrentObject, ParentNode.Info);
                RhinoSceneHierarchyNodeInfo ObjectNodeInfo = GenerateNodeInfo(CurrentObject, ParentNode.bIsInstanceDefinition, MaterialIndex, ParentNode.Info.WorldTransform);
                RhinoSceneHierarchyNode     ObjectNode;
                if (ParentNode.bIsRoot && ParentNode.bIsInstanceDefinition)
                {
                    // The objects inside a Block definitions may be defined in a different layer than the one we are currently in.
                    ObjectNode = ParentNode.AddChild(ObjectNodeInfo, GetOrCreateLayerIndexHierarchy(CurrentObject.Attributes.LayerIndex));
                }
                else
                {
                    ObjectNode = ParentNode.AddChild(ObjectNodeInfo);
                }
                GuidToHierarchyNodeDictionary.Add(CurrentObject.Id, ObjectNode);
                AddObjectMaterialReference(CurrentObject, MaterialIndex);

                if (DefinitionRootNode != null)
                {
                    InstanciateDefinition(ObjectNode, DefinitionRootNode);
                }
            }
        }
Exemplo n.º 4
0
        private void InstanciateDefinition(RhinoSceneHierarchyNode ParentNode, RhinoSceneHierarchyNode DefinitionNode)
        {
            ParentNode.LinkToNode(DefinitionNode);

            for (int ChildIndex = 0; ChildIndex < DefinitionNode.GetChildrenCount(); ++ChildIndex)
            {
                RhinoSceneHierarchyNode DefinitionChildNode = DefinitionNode.GetChild(ChildIndex);
                int MaterialIndex = GetObjectMaterialIndex(DefinitionChildNode.Info.RhinoModelComponent as RhinoObject, ParentNode.Info);
                RhinoSceneHierarchyNodeInfo ChildNodeInfo     = GenerateInstanceNodeInfo(ParentNode.Info, DefinitionChildNode.Info, MaterialIndex);
                RhinoSceneHierarchyNode     InstanceChildNode = ParentNode.AddChild(ChildNodeInfo);

                InstanciateDefinition(InstanceChildNode, DefinitionChildNode);
            }
        }