PolygonMesh.GetApproximatedMeshAndAttributes

導入

v5.0

詳細

指定されたサブディビジョンルールで細分割されたメッシュのジオメトリ描写、サブディビジョンのレベルおよび使用されている場合は不連続角を指定します。ジオメトリ データは 1D 配列で戻され、次の値で構成されます。

1)頂点: x、y、z 値のポリゴン頂点 2D 配列(Nx3)。

2)ポリゴンデータ:順序付けられた、ポリゴン定義の配列。各ポリゴンはエレメントのリストによって定義され、ポリゴン定義の最初のエレメントにはポリゴンのインデックスの数を設定する必要があります。頂点の順序付けは、外側を向く法線を基準として反時計回りの順序付け(右手の法則)に従う必要があります。たとえば、それぞれ 4 つのインデックスを持つポリゴンの配列: {4,0,1,4,3,4,1,2,5,4... }

3)ポリゴン ノード標準配列: 各ポリゴン ノードに標準 X、Y、Z 値を含む·2D 配列。

4)各ポリゴンフェイスに対するポリゴンノード:各ポリゴンフェイスにおけるポリゴンノードの数の後に、対応するポリゴンノードのインデックスが続く 1D 配列。

5)UVW 配列:連続するUVクラスタプロパティであるClusterPropertyオブジェクトを含む 1D 配列で、オブジェクトそれぞれには対応する 1D 配列が続きます。この配列は UVW クラスタプロパティの各ポリゴンノードに対する UVW 値からなります。

6)カラー配列:連続する頂点カラークラスタプロパティであるClusterPropertyオブジェクトを含む 1D 配列で、オブジェクトそれぞれには対応する 1D 配列が続きます。この配列は頂点カラープロパティの各ポリゴンノードに対する RGBA 値からなります。

7)マテリアル配列:連続するポリゴンクラスタであるMaterialオブジェクトを含む 1D 配列で、オブジェクトそれぞれには対応する 1D 配列が続きます。この配列は各ポリゴンクラスタの補間されたポリゴン値からなります。

8)ウェイト配列:現時点ではサポートされていません。

9)エンベロープウェイト配列:現時点ではサポートされていません。

注:C++ API 相当のPolygonMesh::GetGeometryAccessor関数は、必要なデータのみを取得できる(ゆえにこのデータへのアクセス効率を格段に向上させる)CGeometryAccessorオブジェクトを戻します。

スクリプト 構文

oArray = PolygonMesh.GetApproximatedMeshAndAttributes( SubdivisionRule, SubdivisionLevel, UseDiscontinuity, DiscontinuityAngle );

戻り値

1DArray

パラメータ

パラメータ タイプ 詳細
SubdivisionRule siSubdivisionRuleType このパラメータには、アプロクシメーションに使用するサブディビジョンルールが含まれます。
SubdivisionLevel Long このパラメータには、アプロクシメーションに使用するサブディビジョンルールが含まれます。
UseDiscontinuity Boolean 不連続角を使用するかどうかを指定します。
DiscontinuityAngle Double 不連続角を指定します。

VBScript の例

'
' This example illustrates how to create a nem PolygonMesh from an ApproximatedMesh
' and how to carry over the attributes.
'
set oCube = ActiveSceneRoot.AddGeometry("Cube","MeshSurface")
set oMaterial = oCube.AddMaterial("Blinn")
'Add Polygon Material and texture
set oPolygonCluster = oCube.ActivePrimitive.Geometry.AddCluster(siPolygonCluster, ,Array(4))
set oMaterial    = oPolygonCluster.AddMaterial("Phong")
set oImage = AddImageSource( "$SI_HOME\Data\XSI_SAMPLES\Pictures\jio.jpg" )
set oImageClip = AddImageClip( oImage )
set oPhong = oMaterial.Shaders("Phong")
set oColor8Mix1 = oPhong.ambient.connectfromprogid("Softimage.sib_color_8mix.1")
set oColor8Mix2 = oPhong.diffuse.connectfromprogid("Softimage.sib_color_8mix.1")
set oTex2D = oColor8Mix1.color1.connectfromprogid("Softimage.txt2d-image-explicit.1")
call oColor8Mix2.color1.connect(oTex2D)
set oTex2D.tex.source = oImageClip
'Add Polygon Material
set oPolygonCluster = oCube.ActivePrimitive.Geometry.AddCluster(siPolygonCluster,,Array(0,1))
set oMaterial = oPolygonCluster.AddMaterial("Lambert")
'Add UV and VertexColor Properties
set oSamplePointCluster = oCube.ActivePrimitive.Geometry.AddCluster(siSampledPointCluster)
set oUVProp = oSamplePointCluster.AddProperty("Texture Projection")
set oRGBAProp = oSamplePointCluster.AddProperty("Vertex Color")
set oGApprox = oCube.Properties.Find("geomapprox")
oGApprox.Parameters("gapproxmosl").value = 1
MakeLocal oGApprox
ApproxVersion( oCube)
'This function will duplicate the approximated version of the
if selection.count > 0 then
        ApproxVersion( selection(0))
else
        Application.LogMessage "You must select a PolygonMesh"
end if          
'This function will duplicate the approximated version of the
Sub ApproxVersion(in_obj)
        Dim l_NewMesh
        Dim l_Parent
        Dim l_AllInputUVTxtAndCAV
        Dim l_AllOutputUVTxtAndCAV
        Dim l_GeometryApproximation
        Dim l_NewLocalGeometryApproximation
        Dim l_aVertices
        Dim l_aPolygonData
        Dim l_aPolygonNodeNormalArray
        Dim l_aUVArray
        Dim l_aColorArray
        Dim l_aMaterialArray
        Dim l_LocalProperties
        Dim l_attribs
        set l_AllInputUVTxtAndCAV = CreateObject( "XSI.Collection")
        set l_AllOutputUVTxtAndCAV = CreateObject( "XSI.Collection")
        'Check that in_obj is an object
        if not(IsObject(in_obj)) then
                Application.LogMessage "The inputed parameter must be a 3D Object."
                Exit Sub
        end if
        if not(in_obj.BelongsTo("3D Object")) then
                Application.LogMessage "The inputed object must be a 3D Object."
                Exit Sub
        end if
        'If the object is not a PolygonMesh than exit the function
        if in_obj.activeprimitive.geometry.type <> "PolygonMesh" then
                Application.LogMessage in_obj & " has to be a polymesh object"
                Exit Sub
        end if
        set l_GeometryApproximation = in_Obj.Properties.Find("geomapprox")
        l_attribs = in_obj.ActivePrimitive.Geometry.GetApproximatedMeshAndAttributes( _
                l_GeometryApproximation.Parameters("gapproxmosr").value,_
                l_GeometryApproximation.Parameters("gapproxmosl").value,_
                l_GeometryApproximation.Parameters("gapproxmoad").value,_
                l_GeometryApproximation.Parameters("gapproxmoan").value )
        l_aVertices = l_attribs(0)
        l_aPolygonData = l_attribs(1)
        l_aPolygonNodeNormalArray = l_attribs(2)
        l_aPolygonNodePolygonFaceIndexArray = l_attribs(3)
        l_aPolygonFaceParentPolygonFaceIndexArray = l_attribs(4)
        l_aUVArray = l_attribs(5)
        l_aColorArray = l_attribs(6)
        l_aMaterialArray = l_attribs(7)
        set l_Parent  =         in_obj.Parent
        set l_NewMesh = l_Parent.AddPolygonMesh(l_aVertices,l_aPolygonData)     
        'Copy local properties
        set l_LocalProperties = in_obj.LocalProperties
        for each iLocProp in l_LocalProperties
                        CopyPaste iLocProp,,l_NewMesh,2
        next
        'If the geometry approximation is a local property we set the subdivision level to
        '0 as it is the most likely thing users want to do.
        set l_NewLocalGeometryApproximation = l_NewMesh.LocalProperties.Find("geomapprox")
        if IsObject(l_NewLocalGeometryApproximation) and TypeName(l_NewLocalGeometryApproximation) <> "Nothing" then
                l_NewLocalGeometryApproximation.Parameters("gapproxmosl").value = 0
        end if
        'Add a sample cluster if there's some VertexColors or UVProp
        if IsArray(l_aUVArray) then
                i = 0
                do while i < ubound(l_aUVArray)
                        set l_Cluster = l_NewMesh.ActivePrimitive.Geometry.AddCluster(siSampledPointCluster)
                        set l_UVProp = l_Cluster.AddProperty("Texture Projection", ,l_aUVArray(i).Name & "_" & l_Cluster.Name)
                        ReDim l_UVPropArray(2,(l_Cluster.Elements.Count - 1))
                        for j = 0 to l_Cluster.Elements.Count-1
                                l_UVPropArray(0,j) = l_aUVArray(i+1)(j*3)
                                l_UVPropArray(1,j) = l_aUVArray(i+1)(j*3 + 1)
                                l_UVPropArray(2,j) = l_aUVArray(i+1)(j*3 + 2)
                        next
                        l_UVProp.Elements.Array  = l_UVPropArray
                        l_AllInputUVTxtAndCAV.Add l_aUVArray(i)
                        l_AllOutputUVTxtAndCAV.Add l_UVProp
                        i = i+2
                Loop
        end if
        if IsArray(l_aColorArray) then
                i = 0
                do while i < ubound(l_aColorArray)
                        set l_Cluster = l_NewMesh.ActivePrimitive.Geometry.AddCluster(siSampledPointCluster)
                        set l_ColorProp = l_Cluster.AddProperty("Vertex Color", ,l_aColorArray(i).Name & "_" & l_Cluster.Name)
                        ReDim l_ColorPropArray(3,l_Cluster.Elements.Count - 1)
                        for j = 0 to l_Cluster.Elements.Count-1
                                l_ColorPropArray(0,j) = l_aColorArray(i+1)(j*4)
                                l_ColorPropArray(1,j) = l_aColorArray(i+1)(j*4 + 1)
                                l_ColorPropArray(2,j) = l_aColorArray(i+1)(j*4 + 2)
                                l_ColorPropArray(3,j) = l_aColorArray(i+1)(j*4 + 3)
                        next
                        l_ColorProp.Elements.Array  = l_ColorPropArray
                        l_AllInputUVTxtAndCAV.Add l_aColorArray(i)
                        l_AllOutputUVTxtAndCAV.Add l_ColorProp
                        i = i+2
                Loop
        end if
        if IsArray(l_aMaterialArray) then
                Dim l_bEmptyMaterialIndexArray
                Dim l_CurrentMaterial
                Dim l_NewMaterial
                Dim l_NewCluster
                Dim l_MaxIndex
                Dim l_MaterialIndexArray
                Dim l_Material
                i = 0
                do while i < ubound(l_aMaterialArray)
                        set l_NewCluster = l_NewMesh.ActivePrimitive.Geometry.AddCluster(siPolygonCluster, , l_aMaterialArray(i+1))
                        MakeLocal l_NewCluster.Material
                        CopyPaste l_aMaterialArray(i),,l_NewCluster,2
                        SIRebindByNameUserData l_NewCluster.Material, l_AllInputUVTxtAndCAV, l_AllOutputUVTxtAndCAV
                        i = i+2
                Loop
        end if
        'Rebind the material that may be a local property at object level
        SIRebindByNameUserData l_NewMesh.Material, l_AllInputUVTxtAndCAV, l_AllOutputUVTxtAndCAV
        SelectObj l_NewMesh
End Sub