public static void ExportMaterials(FDatasmithFacadeScene DatasmithScene, DatasmithRhinoSceneParser SceneParser) { int TextureAndMaterialCount = SceneParser.TextureHashToTextureInfo.Count + SceneParser.MaterialHashToMaterialInfo.Count; int TextureAndMaterialProgress = 0; foreach (RhinoTextureInfo CurrentTextureInfo in SceneParser.TextureHashToTextureInfo.Values) { FDatasmithRhinoProgressManager.Instance.UpdateCurrentTaskProgress((float)(++TextureAndMaterialProgress) / TextureAndMaterialCount); FDatasmithFacadeTexture TextureElement = ParseTexture(CurrentTextureInfo); if (TextureElement != null) { DatasmithScene.AddTexture(TextureElement); } } foreach (RhinoMaterialInfo CurrentMaterialInfo in SceneParser.MaterialHashToMaterialInfo.Values) { FDatasmithRhinoProgressManager.Instance.UpdateCurrentTaskProgress((float)(++TextureAndMaterialProgress) / TextureAndMaterialCount); FDatasmithFacadeUEPbrMaterial DSMaterial = new FDatasmithFacadeUEPbrMaterial(CurrentMaterialInfo.Name); DSMaterial.SetLabel(CurrentMaterialInfo.Label); ParseMaterial(DSMaterial, CurrentMaterialInfo.RhinoMaterial, SceneParser); DatasmithScene.AddMaterial(DSMaterial); } }
// Intersect elements exported in this sync with cached elements. // Those out of the intersection set are either deleted or hidden // and need to be removed from cache. public void Purge(FDatasmithFacadeScene DatasmithScene, bool bInRecursive) { if (bInRecursive) { // Call purge on linked docs first. foreach (var Link in LinkedDocumentsCache.Values) { Link.Purge(DatasmithScene, true); } } List <ElementId> ElementsToRemove = new List <ElementId>(); foreach (var ElemId in CachedElements.Keys) { if (!ExportedElements.Contains(ElemId)) { ElementsToRemove.Add(ElemId); } } // Apply deletions according to the accumulated sets of elements. foreach (var ElemId in ElementsToRemove) { if (!CachedElements.ContainsKey(ElemId)) { continue; } FDocumentData.FBaseElementData ElementData = CachedElements[ElemId]; CachedElements.Remove(ElemId); ElementData.Parent?.ChildElements.Remove(ElementData); DatasmithScene.RemoveActor(ElementData.ElementActor); } }
private static void ExportActors(FDatasmithFacadeScene DatasmithScene, DatasmithRhinoSceneParser SceneParser) { foreach (RhinoSceneHierarchyNode Node in SceneParser.SceneRoot) { if (Node.bIsRoot) { continue; } ExportHierarchyNode(DatasmithScene, Node, SceneParser); } }
private static void ExportHierarchyNode(FDatasmithFacadeScene DatasmithScene, RhinoSceneHierarchyNode Node, DatasmithRhinoSceneParser SceneParser) { FDatasmithFacadeActor ExportedActor = null; if (Node.Info.bHasRhinoObject) { RhinoObject CurrentObject = Node.Info.RhinoModelComponent as RhinoObject; if (CurrentObject.ObjectType == ObjectType.InstanceReference || CurrentObject.ObjectType == ObjectType.Point) { // The Instance Reference node is exported as an empty actor under which we create the instanced block. // Export points as empty actors as well. ExportedActor = ParseEmptyActor(Node); } else if (CurrentObject.ObjectType == ObjectType.Light) { ExportedActor = ParseLightActor(Node); } else if (SceneParser.ObjectIdToMeshInfoDictionary.TryGetValue(CurrentObject.Id, out DatasmithMeshInfo MeshInfo)) { // If the node's object has a mesh associated to it, export it as a MeshActor. ExportedActor = ParseMeshActor(Node, SceneParser, MeshInfo); } else { //#ueent_todo Log non-exported object in DatasmithExport UI (Writing to Rhino Console is extremely slow). } } else { // This node has no RhinoObject (likely a layer), export an empty Actor. ExportedActor = ParseEmptyActor(Node); } if (ExportedActor != null) { // Add common additional data to the actor, and add it to the hierarchy. Node.SetDatasmithActor(ExportedActor); AddTagsToDatasmithActor(ExportedActor, Node); AddMetadataToDatasmithActor(ExportedActor, Node, DatasmithScene); ExportedActor.SetLayer(GetDatasmithActorLayers(Node, SceneParser)); AddActorToParent(ExportedActor, Node, DatasmithScene); } }
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); }
private FDirectLink(Document InDocument) { RootCache = new FCachedDocumentData(InDocument); CurrentCache = RootCache; DatasmithScene = new FDatasmithFacadeScene( FDatasmithRevitExportContext.HOST_NAME, FDatasmithRevitExportContext.VENDOR_NAME, FDatasmithRevitExportContext.PRODUCT_NAME, InDocument.Application.VersionNumber); SceneName = Path.GetFileNameWithoutExtension(RootCache.SourceDocument.PathName); string SceneLabel = Path.GetFileNameWithoutExtension(InDocument.PathName); DatasmithScene.SetLabel(SceneLabel); DocumentChangedHandler = new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); InDocument.Application.DocumentChanged += DocumentChangedHandler; }
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); } }
// OnViewBegin marks the beginning of a 3D view to be exported. public RenderNodeAction OnViewBegin( ViewNode InViewNode // render node associated with the 3D view ) { // Set the level of detail when tessellating faces (between -1 and 15). InViewNode.LevelOfDetail = LevelOfTessellation; // Initialize the world transform for the 3D view being processed. WorldTransformStack.Push(Transform.Identity); // Create an empty Datasmith scene. if (DirectLink != null) { DirectLink.OnBeginExport(); DatasmithScene = DirectLink.DatasmithScene; } else { DatasmithScene = new FDatasmithFacadeScene(HOST_NAME, VENDOR_NAME, PRODUCT_NAME, ProductVersion); } DatasmithScene.PreExport(); View3D ViewToExport = RevitDocument.GetElement(InViewNode.ViewId) as View3D; if (DatasmithFilePaths != null && !DatasmithFilePaths.TryGetValue(ViewToExport.Id, out CurrentDatasmithFilePath)) { return(RenderNodeAction.Skip); // TODO log error? } // Keep track of the active Revit document being exported. PushDocument(RevitDocument); // Add a new camera actor to the Datasmith scene for the 3D view camera. AddCameraActor(ViewToExport, InViewNode.GetCameraInfo()); // We want to export the 3D view. return(RenderNodeAction.Proceed); }
// OnViewEnd marks the end of a 3D view being exported. // This method is invoked even for 3D views that were skipped. public void OnViewEnd( ElementId InElementId // exported 3D view ID ) { // Forget the active Revit document being exported. PopDocument(); // Check if this is regular file export. if (DirectLink == null) { // Build and export the Datasmith scene instance and its scene element assets. DatasmithScene.ExportScene(CurrentDatasmithFilePath); // Dispose of the Datasmith scene. DatasmithScene = null; } else { DirectLink.OnEndExport(); } // Forget the 3D view world transform. WorldTransformStack.Pop(); }
public void OnProcessExit(object sender, EventArgs e) { AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; FDatasmithFacadeScene.Shutdown(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FDatasmithFacadeScene obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public static Rhino.Commands.Result ExportScene(DatasmithRhinoSceneParser SceneParser, FDatasmithFacadeScene DatasmithScene) { FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Exporting Materials", 0.2f); FDatasmithRhinoMaterialExporter.ExportMaterials(DatasmithScene, SceneParser); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Exporting Meshes", 0.7f); FDatasmithRhinoMeshExporter.ExportMeshes(DatasmithScene, SceneParser); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Exporting Actors", 0.8f); ExportActors(DatasmithScene, SceneParser); return(Rhino.Commands.Result.Success); }
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); } }
private static void AddActorToParent(FDatasmithFacadeActor InDatasmithActor, RhinoSceneHierarchyNode InNode, FDatasmithFacadeScene InDatasmithScene) { if (InNode.Parent.bIsRoot) { InDatasmithScene.AddActor(InDatasmithActor); } else { InNode.Parent.DatasmithActor.AddChild(InDatasmithActor); } }
public bool UpdateScene(FDatasmithFacadeScene FacadeScene) { bool ret = DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeDirectLink_UpdateScene(swigCPtr, FDatasmithFacadeScene.getCPtr(FacadeScene)); return(ret); }
public bool InitializeForScene(FDatasmithFacadeScene FacadeScene) { bool ret = DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeDirectLink_InitializeForScene(swigCPtr, FDatasmithFacadeScene.getCPtr(FacadeScene)); return(ret); }