0

RhinoPython を RhinoCommon と共に使用して、既存のメッシュに面を追加しようとしています。すべてが機能しているように見えますが、作成された面は、選択したポイントと同じ場所にありません。選択したポイントのインデックス番号が正しいものではないように見える理由を誰かが説明できますか?

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import rhinoscript.utility as rhutil

def AddVertices(me):
    """Add face to a mesh"""
    mesh=rhutil.coercemesh(me)

    #select the vertices
    go=Rhino.Input.Custom.GetObject()
    go.GeometryFilter=Rhino.DocObjects.ObjectType.MeshVertex
    go.SetCommandPrompt("Get mesh vertex")
    go.GetMultiple(3,4)
    objrefs = go.Objects()
    point=[item.GeometryComponentIndex.Index for item in objrefs]
    go.Dispose()

    if len(point)==4:
        mesh.Faces.AddFace(point[0], point[1], point[2], point[3])
    else:
        mesh.Faces.AddFace(point[0], point[1], point[2])
    #replace mesh delete point
    scriptcontext.doc.Objects.Replace(me,mesh)
    mesh.Dispose()
    scriptcontext.doc.Views.Redraw()

if( __name__ == "__main__" ):
    me=rs.GetObject("Select a mesh to add face")
    AddVertices(me)
4

1 に答える 1

3

これは、「get」操作から返されたものが MeshTopologyVertex であり、MeshVertex ではないためです。MeshTopologyVertex は、空間内の同じ位置をたまたま共有する 1 つまたは複数のメッシュ頂点を表します。これは、すべての頂点に関連付けられた頂点法線があるためです。メッシュ ボックスの角を考えてみてください。そのコーナーには頂点法線が異なる 3 つの面があるため、そのコーナーには 3 つのメッシュ頂点がありますが、MeshTopologyVertex は 1 つだけです。代わりに頂点インデックスを使用するようにスクリプトを調整しました。

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import rhinoscript.utility as rhutil

def AddVertices(me):
    """Add face to a mesh"""
    mesh=rhutil.coercemesh(me)

    #select the vertices
    go=Rhino.Input.Custom.GetObject()
    go.GeometryFilter=Rhino.DocObjects.ObjectType.MeshVertex
    go.SetCommandPrompt("Get mesh vertex")
    go.GetMultiple(3,4)
    objrefs = go.Objects()
    topology_indices=[item.GeometryComponentIndex.Index for item in objrefs]
    go.Dispose()

    point = []
    for index in topology_indices:
        # in many cases there are multiple vertices in the mesh
        # for a single topology vertex. Just pick the first one
        # in this sample, you will probably have to make a better
        # decision that this for your specific case
        vertex_indices = mesh.TopologyVertices.MeshVertexIndices(index)
        point.append(vertex_indices[0])

    if len(point)==4:
        mesh.Faces.AddFace(point[0], point[1], point[2], point[3])
    else:
        mesh.Faces.AddFace(point[0], point[1], point[2])
    #replace mesh delete point
    scriptcontext.doc.Objects.Replace(me,mesh)
    mesh.Dispose()
    scriptcontext.doc.Views.Redraw()

if( __name__ == "__main__" ):
    me=rs.GetObject("Select a mesh to add face")
    AddVertices(me)
于 2013-04-18T20:16:49.277 に答える