コード例 #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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #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);
                }
            }
        }