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); }
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); }
//======================================================================================================================== // Implement IPhotoRenderContext interface methods called at times of drawing geometry as if executing the Render command. // Only actual geometry suitable to appear in a rendered view will be processed and output. // Start is called at the very start of the export process, still before the first entity of the model was send out. public bool Start() { // Retrieve the list of extra search paths for Revit texture files. RetrieveExtraTexturePaths(); // Set the coordinate system type of the world geometries and transforms. // Revit uses a right-handed Z-up coordinate system. FDatasmithFacadeElement.SetCoordinateSystemType(FDatasmithFacadeElement.ECoordinateSystemType.RightHandedZup); // Set the scale factor from Revit world units to Datasmith centimeters. // Revit uses foot as internal system unit for all 3D coordinates. FDatasmithFacadeElement.SetWorldUnitScale(CENTIMETERS_PER_FOOT); // We are ready to proceed with the export. return(true); }
public static Rhino.PlugIns.WriteFileResult Export(string Filename, RhinoDoc RhinoDocument, Rhino.FileIO.FileWriteOptions Options) { string RhinoAppName = Rhino.RhinoApp.Name; string RhinoVersion = Rhino.RhinoApp.ExeVersion.ToString(); FDatasmithFacadeElement.SetCoordinateSystemType(FDatasmithFacadeElement.ECoordinateSystemType.RightHandedZup); FDatasmithFacadeElement.SetWorldUnitScale((float)Rhino.RhinoMath.UnitScale(RhinoDocument.ModelUnitSystem, UnitSystem.Centimeters)); FDatasmithFacadeScene DatasmithScene = new FDatasmithFacadeScene("Rhino", "Robert McNeel & Associates", "Rhino3D", RhinoVersion); DatasmithScene.PreExport(); try { RhinoApp.WriteLine(string.Format("Exporting to {0}.", System.IO.Path.GetFileName(Filename))); RhinoApp.WriteLine("Press Esc key to cancel..."); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Parsing Document", 0.1f); DatasmithRhinoSceneParser SceneParser = new DatasmithRhinoSceneParser(RhinoDocument, Options); SceneParser.ParseDocument(); if (ExportScene(SceneParser, DatasmithScene) == Rhino.Commands.Result.Success) { string SceneName = System.IO.Path.GetFileName(Filename); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Writing to files..", 1); DatasmithScene.ExportScene(Filename); } } catch (DatasmithExportCancelledException) { return(Rhino.PlugIns.WriteFileResult.Cancel); } catch (Exception e) { RhinoApp.WriteLine("An unexpected error has occured:"); RhinoApp.WriteLine(e.ToString()); return(Rhino.PlugIns.WriteFileResult.Failure); } finally { FDatasmithRhinoProgressManager.Instance.StopProgress(); } return(Rhino.PlugIns.WriteFileResult.Success); }
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); } }
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); }
// Abandon ownership of the returned FDatasmithFacadeElement C++ pointer. internal static global::System.Runtime.InteropServices.HandleRef getCPtrAndDisown(FDatasmithFacadeElement obj) { if (obj != null) { obj.swigCMemOwn = false; } return(getCPtr(obj)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FDatasmithFacadeElement obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public void SetAssociatedElement(FDatasmithFacadeElement Element) { DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeMetaData_SetAssociatedElement(swigCPtr, FDatasmithFacadeElement.getCPtr(Element)); }
public void AddElement(FDatasmithFacadeElement InElementPtr) { DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeScene_AddElement(swigCPtr, FDatasmithFacadeElement.getCPtrAndDisown(InElementPtr)); }
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); }
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())); }