PolygonMesh.GetApproximatedMeshAndAttributes

Introduced

v5.0

Description

Gives the geometry description of the subdivided mesh given the subdivision rule, the level of subdivision and the discontinuity angle if used. The geometry data is returned in a one dimension array and contains the following values:

1) vertices: polygon vertex 2D array (Nx3) of x,y,z values.

2) polygon data: ordered array of polygon definitions, each polygon is defined by a list of elements, the first element of a polygon definition must be set with the number of indices for that polygon. The ordering of vertices must respect a ccw ordering to get out going normals (right-hand rule). For exampl, an array of polygons with 4 indices each : {4,0,1,4,3,4,1,2,5,4... }

3) polygon node normal array: 2D array containing the normal x,y,z values for every polygon node.

4) polygon node for each polygon face: 1D array containing the number of polygon nodes on each polygon face followed by the corresponding polygon node index.

5) UVW array: 1D array containing the successive UV cluster property ClusterProperty objects, each followed by the corresponding 1D array of UVW values for each polygon node for that UVW cluster property.

6) color array: 1D array containing the successive vertex color cluster prop ClusterProperty objects, each followed by the corresponding 1D array of RGBA values for each polygon node for that vertex color property.

7) material array: 1D array containing the successive polygon cluster Material objects, each followed by the corresponding 1D array of interpolated polygon values of each polygon cluster.

8) weight array: not supported yet.

9) envelope weight array: not supported yet.

Note: The C++ API equivalent function, PolygonMesh::GetGeometryAccessor, returns the CGeometryAccessor object which allows you to get only the data you need, and is therefore a much more efficient way to access this data.

Scripting Syntax

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

Return Value

1-dimensional Array

Parameters

Parameter Type Description
SubdivisionRule siSubdivisionRuleType This parameter contains the subdivision rule to use for the approximation.
SubdivisionLevel Long This parameter contains the subdivision rule to use for the approximation.
UseDiscontinuity Boolean Specified if we want to use the discontinuity angle or not.
DiscontinuityAngle Double Specifies the angle of discontinuity.

Examples

VBScript Example

'
' 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