示例#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
        public RhinoSceneHierarchyNode AddChild(RhinoSceneHierarchyNodeInfo InNodeInfo, IEnumerable <int> LayerIndices)
        {
            RhinoSceneHierarchyNode ChildNode = AddChild(InNodeInfo);

            ChildNode.LayerIndices.UnionWith(LayerIndices);

            return(ChildNode);
        }
示例#3
0
        public RhinoSceneHierarchyNode AddChild(RhinoSceneHierarchyNodeInfo InNodeInfo, int LayerIndex)
        {
            RhinoSceneHierarchyNode ChildNode = AddChild(InNodeInfo);

            ChildNode.LayerIndices.Add(LayerIndex);

            return(ChildNode);
        }
示例#4
0
        /// <summary>
        /// Creates a new hierarchy node info by using the DefinitionNodeInfo as a base, and using InstanceParentNodeInfo for creating a unique name. Used when instancing block definitions.
        /// </summary>
        /// <param name="InstanceParentNodeInfo"></param>
        /// <param name="DefinitionNodeInfo"></param>
        /// <param name="MaterialIndex"></param>
        /// <returns></returns>
        private RhinoSceneHierarchyNodeInfo GenerateInstanceNodeInfo(RhinoSceneHierarchyNodeInfo InstanceParentNodeInfo, RhinoSceneHierarchyNodeInfo DefinitionNodeInfo, int MaterialIndex)
        {
            string        Name              = string.Format("{0}_{1}", InstanceParentNodeInfo.Name, DefinitionNodeInfo.Name);
            string        Label             = ActorLabelGenerator.GenerateUniqueNameFromBaseName(DefinitionNodeInfo.Label);
            List <string> Tags              = new List <string>(DefinitionNodeInfo.Tags);
            bool          bOverrideMaterial = DefinitionNodeInfo.MaterialIndex != MaterialIndex;

            return(new RhinoSceneHierarchyNodeInfo(DefinitionNodeInfo.RhinoModelComponent, Name, Label, Tags, MaterialIndex, bOverrideMaterial, InstanceParentNodeInfo.WorldTransform));
        }
示例#5
0
        public RhinoSceneHierarchyNode AddChild(RhinoSceneHierarchyNodeInfo InNodeInfo)
        {
            RhinoSceneHierarchyNode ChildNode = new RhinoSceneHierarchyNode(this, InNodeInfo);

            ChildNode.LayerIndices.UnionWith(LayerIndices);
            Children.Add(ChildNode);

            return(ChildNode);
        }
示例#6
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);
            }
        }
示例#7
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);
                }
            }
        }
示例#8
0
        private RhinoSceneHierarchyNode GetOrCreateDefinitionRootNode(InstanceDefinition InInstanceDefinition)
        {
            RhinoSceneHierarchyNode InstanceRootNode;

            //If a hierarchy node does not exist for this instance definition, create one.
            if (!InstanceDefinitionHierarchyNodeDictionary.TryGetValue(InInstanceDefinition, out InstanceRootNode))
            {
                const bool bIsInstanceDefinition = true;
                const int  MaterialIndex         = -1;

                RhinoSceneHierarchyNodeInfo DefinitionNodeInfo = GenerateNodeInfo(InInstanceDefinition, bIsInstanceDefinition, MaterialIndex, Transform.Identity);
                InstanceRootNode = new RhinoSceneHierarchyNode(/*bInIsInstanceDefinition=*/ true, DefinitionNodeInfo);
                InstanceDefinitionHierarchyNodeDictionary.Add(InInstanceDefinition, InstanceRootNode);

                RhinoObject[] InstanceObjects = InInstanceDefinition.GetObjects();
                RecursivelyParseObjectInstance(InstanceObjects, InstanceRootNode);
            }

            return(InstanceRootNode);
        }
示例#9
0
        private int GetObjectMaterialIndex(RhinoObject InRhinoObject, RhinoSceneHierarchyNodeInfo ParentNodeInfo)
        {
            ObjectMaterialSource MaterialSource = InRhinoObject.Attributes.MaterialSource;

            if (MaterialSource == ObjectMaterialSource.MaterialFromParent)
            {
                // Special use-case for block instances with the source material set to "Parent".
                // The material source in this case is actually the layer in which the definition objects are.
                if (InRhinoObject is InstanceObject)
                {
                    InstanceObject Instance          = InRhinoObject as InstanceObject;
                    RhinoObject[]  DefinitionObjects = Instance.InstanceDefinition.GetObjects();
                    if (DefinitionObjects != null && DefinitionObjects.Length > 0)
                    {
                        Layer ObjectLayer = RhinoDocument.Layers.FindIndex(InRhinoObject.Attributes.LayerIndex);
                        return(ObjectLayer.RenderMaterialIndex);
                    }
                }
                else if (ParentNodeInfo == null)
                {
                    MaterialSource = ObjectMaterialSource.MaterialFromLayer;
                }
            }

            switch (MaterialSource)
            {
            case ObjectMaterialSource.MaterialFromLayer:
                Layer ObjectLayer = RhinoDocument.Layers.FindIndex(InRhinoObject.Attributes.LayerIndex);
                return(ObjectLayer.RenderMaterialIndex);

            case ObjectMaterialSource.MaterialFromParent:
                return(ParentNodeInfo.MaterialIndex);

            case ObjectMaterialSource.MaterialFromObject:
            default:
                return(InRhinoObject.Attributes.MaterialIndex);
            }
        }
        private static FDatasmithFacadeActorLight SetupLightActor(RhinoSceneHierarchyNodeInfo HierarchyNodeInfo, Light RhinoLight)
        {
            LightObject RhinoLightObject = HierarchyNodeInfo.RhinoModelComponent as LightObject;
            string      HashedName       = FDatasmithFacadeElement.GetStringHash(HierarchyNodeInfo.Name);
            FDatasmithFacadeActorLight LightElement;

            switch (RhinoLight.LightStyle)
            {
            case LightStyle.CameraSpot:
            case LightStyle.WorldSpot:
                FDatasmithFacadeSpotLight SpotLightElement = new FDatasmithFacadeSpotLight(HashedName);
                LightElement = SpotLightElement;
                double OuterSpotAngle = FDatasmithRhinoUtilities.RadianToDegree(RhinoLight.SpotAngleRadians);
                double InnerSpotAngle = RhinoLight.HotSpot * OuterSpotAngle;

                SpotLightElement.SetOuterConeAngle((float)OuterSpotAngle);
                SpotLightElement.SetInnerConeAngle((float)InnerSpotAngle);
                break;

            case LightStyle.WorldLinear:
            case LightStyle.WorldRectangular:
                FDatasmithFacadeAreaLight AreaLightElement = new FDatasmithFacadeAreaLight(HashedName);
                LightElement = AreaLightElement;
                double Length = RhinoLight.Length.Length;
                AreaLightElement.SetLength((float)Length);

                if (RhinoLight.IsRectangularLight)
                {
                    double Width = RhinoLight.Width.Length;

                    AreaLightElement.SetWidth((float)Width);
                    AreaLightElement.SetLightShape(FDatasmithFacadeAreaLight.EAreaLightShape.Rectangle);
                    AreaLightElement.SetLightType(FDatasmithFacadeAreaLight.EAreaLightType.Rect);
                }
                else
                {
                    AreaLightElement.SetWidth((float)(0.01f * Length));
                    AreaLightElement.SetLightShape(FDatasmithFacadeAreaLight.EAreaLightShape.Cylinder);
                    AreaLightElement.SetLightType(FDatasmithFacadeAreaLight.EAreaLightType.Point);
                    // The light in Rhino doesn't have attenuation, but the attenuation radius was found by testing in Unreal to obtain a visual similar to Rhino
                    float DocumentScale = (float)Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, UnitSystem.Centimeters);
                    AreaLightElement.SetAttenuationRadius(1800f / DocumentScale);
                }
                break;

            case LightStyle.CameraDirectional:
            case LightStyle.WorldDirectional:
                LightElement = new FDatasmithFacadeDirectionalLight(HashedName);

                break;

            case LightStyle.CameraPoint:
            case LightStyle.WorldPoint:
                LightElement = new FDatasmithFacadePointLight(HashedName);
                break;

            case LightStyle.Ambient:                     // not supported as light
            default:
                LightElement = null;
                break;
            }

            if (LightElement != null)
            {
                System.Drawing.Color DiffuseColor = RhinoLight.Diffuse;
                LightElement.SetColor(DiffuseColor.R, DiffuseColor.G, DiffuseColor.B, DiffuseColor.A);
                LightElement.SetIntensity(RhinoLight.Intensity * 100f);
                LightElement.SetEnabled(RhinoLight.IsEnabled);
                LightElement.SetLabel(HierarchyNodeInfo.Label);

                FDatasmithFacadePointLight PointLightElement = LightElement as FDatasmithFacadePointLight;
                if (PointLightElement != null)
                {
                    PointLightElement.SetIntensityUnits(FDatasmithFacadePointLight.EPointLightIntensityUnit.Candelas);
                }
            }

            return(LightElement);
        }
示例#11
0
 private RhinoSceneHierarchyNode(RhinoSceneHierarchyNode InParent, RhinoSceneHierarchyNodeInfo InNodeInfo) : this(InParent.bIsInstanceDefinition)
 {
     bIsRoot = false;
     Parent  = InParent;
     Info    = InNodeInfo;
 }
示例#12
0
 //No Parent, this is a root node.
 public RhinoSceneHierarchyNode(bool bInIsInstanceDefinition, RhinoSceneHierarchyNodeInfo InNodeInfo = null)
 {
     Children = new List <RhinoSceneHierarchyNode>();
     bIsInstanceDefinition = bInIsInstanceDefinition;
     Info = InNodeInfo;
 }