/// <summary> /// Returns the preview-meshes of the RhinoObject. /// TODO: Extend to handle sub-assigned materials returning a list of KV-pairs of meshes, materials. /// </summary> /// <param name="rhinoObject"></param> /// <returns></returns> public static Rhino.Geometry.Mesh[] GetMeshes(RhinoObject rhinoObject) { if (rhinoObject.ObjectType == ObjectType.Mesh) { MeshObject meshObj = rhinoObject as MeshObject; return(new Rhino.Geometry.Mesh[] { meshObj.MeshGeometry }); } // Need to get a Mesh from the None-mesh object. Using the FastRenderMesh here. Could be made configurable. // First make sure the internal rhino mesh has been created rhinoObject.CreateMeshes(MeshType.Preview, MeshingParameters.FastRenderMesh, true); // Then get the internal rhino meshes Rhino.Geometry.Mesh[] meshes = rhinoObject.GetMeshes(MeshType.Preview); List <Rhino.Geometry.Mesh> validMeshes = new List <Mesh>(); foreach (Rhino.Geometry.Mesh mesh in meshes) { if (MeshIsValidForExport(mesh)) { mesh.EnsurePrivateCopy(); validMeshes.Add(mesh); } } return(validMeshes.Count == 0 ? new Rhino.Geometry.Mesh[] { } : validMeshes.ToArray()); }
public Rhino.Geometry.Mesh[] GetMeshes(RhinoObject rhinoObject) { if (rhinoObject.ObjectType == ObjectType.Mesh) { MeshObject meshObj = rhinoObject as MeshObject; return(new Rhino.Geometry.Mesh[] { meshObj.MeshGeometry }); } else if (rhinoObject.ObjectType == ObjectType.SubD) { SubDObject subdObject = rhinoObject as SubDObject; Rhino.Geometry.SubD subd = subdObject.Geometry as Rhino.Geometry.SubD; Rhino.Geometry.Mesh mesh = null; if (options.SubDExportMode == SubDMode.ControlNet) { mesh = Rhino.Geometry.Mesh.CreateFromSubDControlNet(subd); } else { int level = options.SubDLevel; mesh = Rhino.Geometry.Mesh.CreateFromSubD(subd, level); } return(new Rhino.Geometry.Mesh[] { mesh }); } // Need to get a Mesh from the None-mesh object. Using the FastRenderMesh here. Could be made configurable. // First make sure the internal rhino mesh has been created rhinoObject.CreateMeshes(Rhino.Geometry.MeshType.Preview, Rhino.Geometry.MeshingParameters.FastRenderMesh, true); // Then get the internal rhino meshes Rhino.Geometry.Mesh[] meshes = rhinoObject.GetMeshes(Rhino.Geometry.MeshType.Preview); List <Rhino.Geometry.Mesh> validMeshes = new List <Rhino.Geometry.Mesh>(); foreach (Rhino.Geometry.Mesh mesh in meshes) { if (MeshIsValidForExport(mesh)) { mesh.EnsurePrivateCopy(); validMeshes.Add(mesh); } } return(validMeshes.ToArray()); }
public override void RenderScene(DB.View dBView, Autodesk.Revit.DB.DisplayStyle displayStyle) { try { if (primitives == null) { if (rhinoObject is PointObject pointObject) { primitives = new Primitive[] { new ObjectPrimitive(pointObject, pointObject.PointGeometry) }; } else if (rhinoObject is PointCloudObject pointCloudObject) { AddPointCloudPreviews(pointCloudObject.PointCloudGeometry); } else if (rhinoObject is CurveObject curveObject) { primitives = new Primitive[] { new ObjectPrimitive(curveObject, curveObject.CurveGeometry) }; } else if (rhinoObject is MeshObject meshObject) { AddMeshPreviews(meshObject.MeshGeometry); } else if (rhinoObject.IsMeshable(MeshType.Render)) { var meshingParameters = rhinoObject.GetRenderMeshParameters(); if (rhinoObject.MeshCount(MeshType.Render, meshingParameters) == 0) { rhinoObject.CreateMeshes(MeshType.Render, meshingParameters, false); } var renderMeshes = rhinoObject.GetMeshes(MeshType.Render); if (renderMeshes?.Length > 0) { int vertexCount = renderMeshes.Select((x) => x.Vertices.Count).Sum(); if (vertexCount > VertexThreshold) { foreach (var m in renderMeshes) { AddMeshPreviews(m); } } else { var previewMesh = renderMeshes.Length == 1 ? renderMeshes[0] : null; if (previewMesh == null) { previewMesh = new Mesh(); previewMesh.Append(renderMeshes); } AddMeshPreviews(previewMesh); } } } } if (primitives != null) { DB3D.DrawContext.SetWorldTransform(Autodesk.Revit.DB.Transform.Identity.ScaleBasis(1.0 / Revit.ModelUnits)); foreach (var primitive in primitives) { if (DB3D.DrawContext.IsInterrupted()) { return; } primitive.Draw(displayStyle); } } } catch (Exception e) { Debug.Fail(e.Source, e.Message); } }