示例#1
0
        private DatasmithMeshInfo GenerateMeshInfo(Guid ObjectID, List <Mesh> Meshes, List <ObjectAttributes> Attributes)
        {
            DatasmithMeshInfo MeshInfo = null;

            if (GuidToHierarchyNodeDictionary.TryGetValue(ObjectID, out RhinoSceneHierarchyNode HierarchyNode))
            {
                Vector3d   PivotOffset     = FDatasmithRhinoMeshExporter.CenterMeshesOnPivot(Meshes);
                List <int> MaterialIndices = new List <int>(Attributes.Count);
                for (int AttributeIndex = 0; AttributeIndex < Attributes.Count; ++AttributeIndex)
                {
                    int MaterialIndex = GetMaterialIndexFromAttributes(HierarchyNode, Attributes[AttributeIndex]);
                    MaterialIndices.Add(MaterialIndex);
                }

                string Name  = FDatasmithFacadeElement.GetStringHash("M:" + HierarchyNode.Info.Name);
                string Label = HierarchyNode.Info.Label;

                MeshInfo = new DatasmithMeshInfo(Meshes, PivotOffset, MaterialIndices, Name, Label);
            }
            else
            {
                RhinoApp.WriteLine("Could not find the corresponding hierarchy node for the object ID: {0}", ObjectID);
            }

            return(MeshInfo);
        }
示例#2
0
 public RhinoTextureInfo(Texture InRhinoTexture, string InName, string InFilePath)
 {
     RhinoTexture = InRhinoTexture;
     Name         = FDatasmithFacadeElement.GetStringHash(InName);
     Label        = InName;
     FilePath     = InFilePath;
 }
        private static FDatasmithFacadeActor ParseEmptyActor(RhinoSceneHierarchyNode InNode)
        {
            string HashedName = FDatasmithFacadeElement.GetStringHash(InNode.Info.Name);
            FDatasmithFacadeActor DatasmithActor = new FDatasmithFacadeActor(HashedName);

            DatasmithActor.SetLabel(InNode.Info.Label);

            float[] MatrixArray = InNode.Info.WorldTransform.ToFloatArray(false);
            DatasmithActor.SetWorldTransform(MatrixArray);

            return(DatasmithActor);
        }
示例#4
0
        public static void ExportMeshes(FDatasmithFacadeScene DatasmithScene, DatasmithRhinoSceneParser SceneParser)
        {
            int MeshIndex = 0;
            int MeshCount = SceneParser.ObjectIdToMeshInfoDictionary.Count;

            foreach (DatasmithMeshInfo CurrentMeshInfo in SceneParser.ObjectIdToMeshInfoDictionary.Values)
            {
                FDatasmithRhinoProgressManager.Instance.UpdateCurrentTaskProgress((float)(MeshIndex++) / MeshCount);

                string HashedName = FDatasmithFacadeElement.GetStringHash(CurrentMeshInfo.Name);
                FDatasmithFacadeMesh DatasmithMesh = new FDatasmithFacadeMesh(HashedName);
                DatasmithMesh.SetLabel(CurrentMeshInfo.Label);

                List <RhinoMaterialInfo> MaterialInfos = new List <RhinoMaterialInfo>(CurrentMeshInfo.MaterialIndices.Count);
                CurrentMeshInfo.MaterialIndices.ForEach((MaterialIndex) => MaterialInfos.Add(SceneParser.GetMaterialInfoFromMaterialIndex(MaterialIndex)));
                ParseMesh(DatasmithMesh, CurrentMeshInfo.RhinoMeshes, MaterialInfos);

                DatasmithScene.AddMesh(DatasmithMesh);
            }
        }
示例#5
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 FDatasmithFacadeActor ParseMeshActor(RhinoSceneHierarchyNode InNode, DatasmithRhinoSceneParser InSceneParser, DatasmithMeshInfo InMeshInfo)
        {
            string HashedActorName = FDatasmithFacadeActor.GetStringHash("A:" + InNode.Info.Name);
            FDatasmithFacadeActorMesh DatasmithActorMesh = new FDatasmithFacadeActorMesh(HashedActorName);

            DatasmithActorMesh.SetLabel(InNode.Info.Label);

            Transform OffsetTransform = Transform.Translation(InMeshInfo.PivotOffset);
            Transform WorldTransform  = Transform.Multiply(InNode.Info.WorldTransform, OffsetTransform);

            DatasmithActorMesh.SetWorldTransform(WorldTransform.ToFloatArray(false));

            string MeshName = FDatasmithFacadeElement.GetStringHash(InMeshInfo.Name);

            DatasmithActorMesh.SetMesh(MeshName);

            if (InNode.Info.bOverrideMaterial)
            {
                RhinoMaterialInfo MaterialInfo = InSceneParser.GetMaterialInfoFromMaterialIndex(InNode.Info.MaterialIndex);
                DatasmithActorMesh.AddMaterialOverride(MaterialInfo.Name, 0);
            }

            return(DatasmithActorMesh);
        }
        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);
        }
示例#8
0
        private void AddCameraActor(
            View3D InView3D,
            CameraInfo InViewCamera
            )
        {
            // Create a new Datasmith camera actor.
            // Hash the Datasmith camera actor name to shorten it.
            string HashedName = FDatasmithFacadeElement.GetStringHash(InView3D.UniqueId);
            FDatasmithFacadeActorCamera CameraActor = new FDatasmithFacadeActorCamera(HashedName);

            CameraActor.SetLabel(InView3D.Name);

            if (InView3D.Category != null)
            {
                // Set the Datasmith camera actor layer to be the 3D view category name.
                CameraActor.SetLayer(InView3D.Category.Name);
            }

            // Gets the current non-saved orientation of the 3D view.
            ViewOrientation3D ViewOrientation = InView3D.GetOrientation();

            // Set the world position (in right-handed Z-up coordinates) of the Datasmith camera actor.
            XYZ CameraPosition = ViewOrientation.EyePosition;

            CameraActor.SetCameraPosition((float)CameraPosition.X, (float)CameraPosition.Y, (float)CameraPosition.Z);

            // Set the world rotation of the Datasmith camera actor with
            // the camera world forward and up vectors (in right-handed Z-up coordinates).
            XYZ CameraForward = ViewOrientation.ForwardDirection;
            XYZ CameraUp      = ViewOrientation.UpDirection;

            CameraActor.SetCameraRotation((float)CameraForward.X, (float)CameraForward.Y, (float)CameraForward.Z, (float)CameraUp.X, (float)CameraUp.Y, (float)CameraUp.Z);

            // When the 3D view camera is not available, an orthographic view should be assumed.
            if (InViewCamera != null)
            {
                // Compute the aspect ratio (width/height) of the Revit 3D view camera, where
                // HorizontalExtent is the distance between left and right planes on the target plane,
                // VerticalExtent is the distance between top and bottom planes on the target plane.
                float AspectRatio = (float)(InViewCamera.HorizontalExtent / InViewCamera.VerticalExtent);

                // Set the aspect ratio of the Datasmith camera.
                CameraActor.SetAspectRatio(AspectRatio);

                if (InView3D.IsPerspective)
                {
                    // Set the sensor width of the Datasmith camera.
                    CameraActor.SetSensorWidth((float)(InViewCamera.HorizontalExtent * /* millimeters per foot */ 304.8));

                    // Get the distance from eye point along view direction to target plane.
                    // This value is appropriate for perspective views only.
                    float TargetDistance = (float)InViewCamera.TargetDistance;

                    // Set the Datasmith camera focus distance.
                    CameraActor.SetFocusDistance(TargetDistance);

                    // Set the Datasmith camera focal length.
                    CameraActor.SetFocalLength(TargetDistance * /* millimeters per foot */ 304.8F);
                }
            }

            // Add the camera actor to the Datasmith scene.
            DatasmithScene.AddActor(CameraActor);

            DirectLink?.MarkForExport(InView3D);
            DirectLink?.CacheElement(RevitDocument, InView3D, new FDocumentData.FBaseElementData(CameraActor, null, DocumentDataStack.Peek()));
        }