Does anyone have experience with this method? I am experiencing what I think is either a bug or documentation error and would like someone to confirm and/or explain what’s going on.
When I use PolygonMesh.GetApproximatedMeshAndAttributes(), half of the returned data is as expected, but the 2nd half doesn’t match what is described in the the SDK documentation (http://tinyurl.com/kfggmfu). To better illustrate the problem, create a polygon mesh cube, apply a texture projection, press “+” on number pad to subdivide once, then run included code from script editor (script appended to bottom of this message). Consult output in script log. According to the SDK documentation (http://tinyurl.com/kfggmfu), the approximated mesh data is returned as an array of arrays. Each index corresponding to different type of mesh data: 0 = vertex positions 1 = vertex connection order per polygon 2 = polygon node normals 3 = polygon node indices per polygon 4 = Texture UVW coordinates 5 = Vertex Color values 6 = Materials 7 = weight data (weight map?) 8 = Envelope Data NOTE: 7 and 8 not implemented. In my experience, the returned data for indices 0, 1, 2, and 3 is as expected, but index 4 is the monkey wrench as it returns a 1-dimensional array of what appears to be polygon indices of the hull, not Texture UVW coordinates as described in the SDK documentation. The texture UVW data is actually in index 5 and vertex color data in index 6 (NOTE: do not confuse array index with numbering shown in the SDK documentation as they do not align). The documentation states Materials should be accessible in the index following vertex color data, but in my experience none of the array indices are accessible beyond vertex colors meaning I cannot get access to materials. Could somebody confirm what data this method is actually returning and in the format it’s returned so I may use it? thanks, Matt ----------------------------------- // JScript main(); //=========================================================================== // main() //=========================================================================== function main() { var oObject = Selection(0); var oProperty = oObject.Properties( "Geometry Approximation" ); var SubDivisionLevel = oProperty.Parameters( "gapproxmosl" ).value; var DiscontinuityActive = oProperty.Parameters( "gapproxmoad" ).value; var DiscontinuityAngle = oProperty.Parameters( "gapproxmoan" ).value; var oData = oObject.ActivePrimitive.Geometry.GetApproximatedMeshAndAttributes( siCatmullClark, SubDivisionLevel, DiscontinuityActive, DiscontinuityAngle ); Dump( oData ); } //=========================================================================== // Dump() //=========================================================================== function Dump( oData ) { LogMessage( "--- Dump() ---", siComment ); var aData = oData.toArray(); var aVertexPositions = ( oData.getItem(0) ).toArray(); var aVertexConnections = ( oData.getItem(1) ).toArray(); var aNodeNormals = ( oData.getItem(2) ).toArray(); var aNodeConnections = ( oData.getItem(3) ).toArray(); var aPolygonNodeMap = ( oData.getItem(4) ).toArray(); var aTextureData = ( oData.getItem(5) ).toArray(); var aVertexColorData = ( oData.getItem(6) ).toArray(); // var aMaterialData = ( oData.getItem(7) ).toArray(); // var aWeightData = ( oData.getItem(7) ).toArray(); // var aEnvelopeData = ( oData.getItem(8) ).toArray(); //------------------------- // Vertex positions //------------------------- LogMessage( "NbPositions: " + ( aVertexPositions.length / 3 ), siComment ); for ( var i = 0, n = 0; i < aVertexPositions.length; i += 3 ) { LogMessage( "Position[" + (n++) + "]: " + aVertexPositions[i ] + ", " + aVertexPositions[i+1] + ", " + aVertexPositions[i+2], siComment ); } //------------------------- // Vertex Connections //------------------------- LogMessage( "NbFaces: " + ( aVertexConnections.length / 5 ), siComment ); var j = 0; var n = 0; do { var NbVertices = aVertexConnections[n++]; var aVertexIndices = new Array(); for ( var i = 0; i < NbVertices; i++ ) { aVertexIndices[i] = aVertexConnections[n++]; } LogMessage( "PolygonNodeIndices[" + (j++) + "]: " + aVertexIndices.join(", "), siComment ); } while( n < aVertexConnections.length ); //------------------------- // Node Normals //------------------------- LogMessage( "NbNormals: " + ( aNodeNormals.length / 3 ), siComment ); for ( var i = 0, n = 0; i < aNodeNormals.length; i += 3 ) { LogMessage( "PolygonNodeNormal[" + (n++) + "]: " + aNodeNormals[i ] + ", " + aNodeNormals[i+1] + ", " + aNodeNormals[i+2], siComment ); } //------------------------- // Node Connections //------------------------- LogMessage( "NbNodes: " + ( aNodeConnections.length / 5 ), siComment ); var j = 0; var n = 0; do { var NbVertices = aNodeConnections[n++]; var aNodeIndices = new Array(); for ( var i = 0; i < NbVertices; i++ ) { aNodeIndices[i] = aNodeConnections[n++]; } LogMessage( "PolygonNodeMap[" + (j++) + "]: " + aNodeIndices.join(", "), siComment ); } while( n < aNodeConnections.length ); //------------------------- // Polygon-Node Map(???) //------------------------- LogMessage( "PolygonNodeMap size: " + aPolygonNodeMap.length, siComment ); for ( var i = 0; i < aPolygonNodeMap.length; i++ ) { LogMessage( "Node-Polygon[" + i + "]: " + aPolygonNodeMap[i], siComment ); } //------------------------- // UVW Coordinates //------------------------- LogMessage( "TextureData size: " + aTextureData.length, siComment ); for ( var j = 0; j < aTextureData.length; j += 2 ) { var oTextureProjection = aTextureData[j]; var aUVWCoordinates = aTextureData[j+1].toArray(); // var UnknownData = aTextureData[j+2]; LogMessage( "Texture Projection: " + oTextureProjection.FullName, siComment ); for ( var i = 0, n = 0; i < aUVWCoordinates.length; i += 3 ) { LogMessage( "UVW[" + (n++) + "]: " + aUVWCoordinates[i ] + ", " + aUVWCoordinates[i+1] + ", " + aUVWCoordinates[i+2], siComment ); } } //------------------------- // Vertex Colors //------------------------- LogMessage( "NbColors: " + aVertexColorData.length, siComment ); var oVertexColorProperty = aVertexColorData[0]; var aVertexColors = aVertexColorData[1].toArray(); for ( var i = 0, n = 0; i < aVertexColors.length; i += 4 ) { LogMessage( "Color[" + (n++) + "]: " + aVertexColors[i ] + ", " + aVertexColors[i+1] + ", " + aVertexColors[i+2] + ", " + aVertexColors[i+3], siComment ); } //------------------------- // Materials //------------------------- LogMessage( "MaterialData size: " + aMaterialData.length, siComment ); // for ( var i = 0, n = 0; i < aMaterials.length; i++ ) { // LogMessage( "Material[" + (n++) + "]: " + aMaterials[i], siComment ); // } return; }

