Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:createmeshfrombrep [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Create Meshes from Brep =====
 +
 +===== C# =====
 +<code c#>
 +[System.Runtime.InteropServices.Guid("​BF92CA69-3628-4167-96C1-3FA90E460333"​)]
 +public class CreateMeshFromBrepCommand : Command
 +{
 +  public override string EnglishName { get { return "​csCreateMeshesFromBrep";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    ObjRef objRef;
 +    var rc = RhinoGet.GetOneObject("​Select surface or polysurface to mesh", true, ObjectType.Surface | ObjectType.PolysrfFilter,​ out objRef);
 +    if (rc != Result.Success)
 +      return rc;
 +    var brep = objRef.Brep();​
 +    if (null == brep)
 +      return Result.Failure;​
 +
 +    // you could choose anyone of these for example
 +    var jaggedAndFaster = MeshingParameters.Coarse;​
 +    var smoothAndSlower = MeshingParameters.Smooth;​
 +    var defaultMeshParams = MeshingParameters.Default;​
 +    var minimal = MeshingParameters.Minimal;​
 +
 +    var meshes = Mesh.CreateFromBrep(brep,​ smoothAndSlower);​
 +    if (meshes == null || meshes.Length == 0)
 +      return Result.Failure;​
 +
 +    var brepMesh = new Mesh();
 +    foreach (var mesh in meshes)
 +      brepMesh.Append(mesh);​
 +    doc.Objects.AddMesh(brepMesh);​
 +    doc.Views.Redraw();​
 +
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +<​System.Runtime.InteropServices.Guid("​97FED029-61EC-458B-9229-46DDFEC8DB76"​)>​ _
 +Public Class CreateMeshFromBrepCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbCreateMeshesFromBrep"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim objRef As ObjRef
 +    Dim rc = Rhino.Input.RhinoGet.GetOneObject("​Select surface or polysurface to mesh", True, ObjectType.Surface Or ObjectType.PolysrfFilter,​ objRef)
 +    If rc <> Result.Success Then
 +      Return rc
 +    End If
 +    Dim brep = objRef.Brep()
 +    If brep Is Nothing Then
 +      Return Result.Failure
 +    End If
 +
 +    ' you could choose anyone of these for example
 +    Dim jaggedAndFaster = MeshingParameters.Coarse
 +    Dim smoothAndSlower = MeshingParameters.Smooth
 +    Dim defaultMeshParams = MeshingParameters.[Default]
 +    Dim minimal = MeshingParameters.Minimal
 +
 +    Dim meshes = Mesh.CreateFromBrep(brep,​ smoothAndSlower)
 +    If meshes Is Nothing OrElse meshes.Length = 0 Then
 +      Return Result.Failure
 +    End If
 +
 +    Dim brepMesh = New Mesh()
 +    For Each mesh__1 As Mesh In meshes
 +      brepMesh.Append(mesh__1)
 +    Next
 +    doc.Objects.AddMesh(brepMesh)
 +    doc.Views.Redraw()
 +
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +from Rhino.Geometry import *
 +from Rhino.Input import RhinoGet
 +from Rhino.Commands import Result
 +from Rhino.DocObjects import ObjectType
 +import rhinoscriptsyntax as rs
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  rc, objRef = RhinoGet.GetOneObject("​Select surface or polysurface to mesh", True, 
 +                                     ​ObjectType.Surface | ObjectType.PolysrfFilter)
 +  if rc <> Result.Success:​
 +    return rc
 +  brep = objRef.Brep()
 +  if None == brep:
 +    return Result.Failure
 +
 +  jaggedAndFaster = MeshingParameters.Coarse
 +  smoothAndSlower = MeshingParameters.Smooth
 +  defaultMeshParams = MeshingParameters.Default
 +  minimal = MeshingParameters.Minimal
 +
 +  meshes = Mesh.CreateFromBrep(brep,​ smoothAndSlower)
 +  if meshes == None or meshes.Length == 0:
 +    return Result.Failure
 +
 +  brepMesh = Mesh()
 +  for mesh in meshes:
 +    brepMesh.Append(mesh)
 +  doc.Objects.AddMesh(brepMesh)
 +  doc.Views.Redraw()
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/createmeshfrombrep.txt ยท Last modified: 2015/09/14 (external edit)