private static void AddMetadataToDatasmithActor(FDatasmithFacadeActor InDatasmithActor, RhinoSceneHierarchyNode InNode, FDatasmithFacadeScene InDatasmithScene)
        {
            if (!InNode.Info.bHasRhinoObject)
            {
                return;
            }

            RhinoObject         NodeObject  = InNode.Info.RhinoModelComponent as RhinoObject;
            NameValueCollection UserStrings = NodeObject.Attributes.GetUserStrings();

            if (UserStrings != null && UserStrings.Count > 0)
            {
                string[] Keys = UserStrings.AllKeys;
                FDatasmithFacadeMetaData DatasmithMetaData = new FDatasmithFacadeMetaData(InDatasmithActor.GetName() + "_DATA");
                DatasmithMetaData.SetLabel(InDatasmithActor.GetLabel());
                DatasmithMetaData.SetAssociatedElement(InDatasmithActor);

                for (int KeyIndex = 0; KeyIndex < Keys.Length; ++KeyIndex)
                {
                    string CurrentKey     = Keys[KeyIndex];
                    string EvaluatedValue = FDatasmithRhinoUtilities.EvaluateAttributeUserText(InNode, UserStrings.Get(CurrentKey));

                    DatasmithMetaData.AddPropertyString(CurrentKey, EvaluatedValue);
                }

                InDatasmithScene.AddMetaData(DatasmithMetaData);
            }
        }
Esempio n. 2
0
        public RhinoSceneHierarchyNodeInfo(ModelComponent InModelComponent, string InName, string InLabel, List <string> InTags, int InMaterialIndex, bool bInOverrideMaterial, Transform InTransform)
        {
            RhinoModelComponent = InModelComponent;
            Name              = InName;
            Label             = InLabel;
            Tags              = InTags;
            MaterialIndex     = InMaterialIndex;
            bOverrideMaterial = bInOverrideMaterial;

            Transform ModelComponentTransform = FDatasmithRhinoUtilities.GetModelComponentTransform(RhinoModelComponent);

            WorldTransform = Transform.Multiply(InTransform, ModelComponentTransform);
        }
Esempio n. 3
0
        private void AddMaterialIndexMapping(int MaterialIndex)
        {
            if (!MaterialIndexToMaterialHashDictionary.ContainsKey(MaterialIndex))
            {
                Material IndexedMaterial = MaterialIndex == -1
                                        ? IndexedMaterial = Material.DefaultMaterial
                                        : RhinoDocument.Materials.FindIndex(MaterialIndex);

                string MaterialHash = FDatasmithRhinoUtilities.GetMaterialHash(IndexedMaterial);
                MaterialIndexToMaterialHashDictionary.Add(MaterialIndex, MaterialHash);

                AddMaterialHashMapping(MaterialHash, IndexedMaterial);
            }
        }
Esempio n. 4
0
        private void AddTextureHashMapping(string TextureHash, Texture RhinoTexture)
        {
            if (!TextureIdToTextureHash.ContainsKey(RhinoTexture.Id))
            {
                TextureIdToTextureHash.Add(RhinoTexture.Id, TextureHash);

                if (!TextureHashToTextureInfo.ContainsKey(TextureHash))
                {
                    if (FDatasmithRhinoUtilities.GetRhinoTextureNameAndPath(RhinoTexture, out string TextureName, out string TexturePath))
                    {
                        TextureName = TextureLabelGenerator.GenerateUniqueNameFromBaseName(TextureName);
                        TextureHashToTextureInfo.Add(TextureHash, new RhinoTextureInfo(RhinoTexture, TextureName, TexturePath));
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns the UV Parameters for the given Texture.
        /// This function uses the same operations as in FOpenNurbsTranslatorImpl::TranslateMaterialTable(), improvements should be applied to both functions.
        /// </summary>
        /// <param name="RhinoTexture"></param>
        /// <returns></returns>
        private static FDatasmithFacadeMaterialsUtils.FUVEditParameters GetUVParameter(Texture RhinoTexture)
        {
            // Extract texture mapping info
            FDatasmithFacadeMaterialsUtils.FUVEditParameters UVParameters = new FDatasmithFacadeMaterialsUtils.FUVEditParameters();

            // Use cached texture coordinates(channel 0)
            UVParameters.SetChannelIndex(0);

            //// Extract the UV tiling, offset and rotation angle from the UV transform matrix
            Transform RotationTransform, OrthogonalTransform;
            Vector3d  Translation, Scale;

            RhinoTexture.UvwTransform.DecomposeAffine(out Translation, out RotationTransform, out OrthogonalTransform, out Scale);

            double RotX, RotY, RotZ;

            if (!RotationTransform.GetYawPitchRoll(out RotX, out RotY, out RotZ))
            {
                //This is not a valid rotation make sure the angles are at 0;
                RotX = RotY = RotZ = 0;
            }
            else
            {
                RotX = FDatasmithRhinoUtilities.RadianToDegree(RotX);
                RotY = FDatasmithRhinoUtilities.RadianToDegree(RotY);
                RotZ = FDatasmithRhinoUtilities.RadianToDegree(RotZ);
            }

            UVParameters.SetUVTiling((float)Scale.X, (float)Scale.Y);

            //If the tiling vector is not zero.
            if (Math.Abs(Scale.X) > float.Epsilon && Math.Abs(Scale.Y) > float.Epsilon)
            {
                float UVOffsetX = (float)(Translation.X / Scale.X);
                float UVOffsetY = (float)-(Translation.Y / Scale.Y + 0.5f - 0.5f / Scale.Y);

                UVParameters.SetUVOffset(UVOffsetX, UVOffsetY);                 // V-coordinate is inverted in Unreal
            }

            // Rotation angle is reversed because V-axis points down in Unreal while it points up in OpenNurbs
            UVParameters.SetRotationAngle((float)-RotX);

            return(UVParameters);
        }
Esempio n. 6
0
        private void AddMaterialHashMapping(string MaterialHash, Material RhinoMaterial)
        {
            if (!MaterialHashToMaterialInfo.ContainsKey(MaterialHash))
            {
                string MaterialLabel = MaterialLabelGenerator.GenerateUniqueName(RhinoMaterial);
                string MaterialName  = FDatasmithFacadeElement.GetStringHash(MaterialLabel);

                MaterialHashToMaterialInfo.Add(MaterialHash, new RhinoMaterialInfo(RhinoMaterial, MaterialName, MaterialLabel));

                Texture[] MaterialTextures = RhinoMaterial.GetTextures();
                for (int TextureIndex = 0; TextureIndex < MaterialTextures.Length; ++TextureIndex)
                {
                    Texture RhinoTexture = MaterialTextures[TextureIndex];
                    if (RhinoTexture != null)
                    {
                        string TextureHash = FDatasmithRhinoUtilities.GetTextureHash(RhinoTexture);
                        AddTextureHashMapping(TextureHash, RhinoTexture);
                    }
                }
            }
        }
        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);
        }