Softimage Forum (Read Only)
Welcome to Autodesk’s Softimage Forums. Share your knowledge, ask questions, and explore popular Softimage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating XSICollection from list of floats in Python

2 REPLIES 2
Reply
Message 1 of 3
Scam249
461 Views, 2 Replies

Creating XSICollection from list of floats in Python

I am trying to create a script in Python which loops through selection of points, creates user normal values for each point and then writes them to the object.

 

Everything works fine if I loop all the selected points and set user normals for each point individually with the Application.PasteUserNormals() command. However, this is quite slow, especially when you are looping through hundreds or thousands of points.

 

I would like to put x,y,z values of normals to a list and then use the method Application.SetUserNormalValues() to set them with one API call. The method accepts point indices and x,y,z values in a XSICollection object.

 

My question is: How can I convert Python list with float values to XSICollection object in order to call the SetUserNormalValues() method successfully?

Tags (2)
2 REPLIES 2
Message 2 of 3
Scam249
in reply to: Scam249

I came across this problem again last week and decided to solve it.

 

The issue was not in the Python list. It is an acceptable XSICollection. So if you are scripting in Python, you can safely pass lists whenever a XSICollection is needed.

 

My actual problem, using SetUserNormalValues() succesfully was a bit trickier. My problem were the wrong indices. Point.Index is an index of a point, which contains one vertex to each adjacent polygon. What makes this even trickier is that even PolygonFace.Vertices.IndexArray returns the point indices.

 

The indices of each individual polygon vertices can be found from PolygonFace.Nodes.IndexArray. These are the indices that SetUserNormalValues() expects.

Message 3 of 3
MattLind3768
in reply to: Scam249

to make it easy on yourself, take a different approach.  Instead of copying and pasting the normal value while traversing each vertex, build a list of normal vectors and apply them in a single bulk edit.  Will be significantly faster

// JScript

var oObject = Selection(0);

 

var oPolygonNodes = oObject.ActivePrimitive.Geometry.Nodes;

 

// create a gridData object to store the normal vectors you want to apply

var oNormalData = XSIFactory.CreateGridData();

oNormalData.RowCount      = oPolygonNodes.Count;

oNormalData.ColumnCount = 3; // xyz

 

for ( var i = 0; i < oPolygonNodes.Count; i++ ) {

 

   var oPolygonNode = oPolygonNodes(i);

   var oPolygonNodeNormal = oPolygonNode.Normal;

 

   // do something to the normal

   oPolygonNodeNormal.x *= 2.0;

   oPolygonNodeNormal.NormalizeInPlace();

 

   // record modified normal

   var aPolygonNodeNormalData = new Array(

       oPolygonNodeNormal.x,

       oPolygonNodeNormal.y,

       oPolygonNodeNormal.z

   );

 

   aNormalData.SetRowValues( oPolygonNode.Index, aPolygonNodeNormalData );

}

 

// Assign results to UserNormal property

var oCluster = oObject.ActivePrimitive.Geometry.AddCluster( siSampledPointCluster, "MyNormals" );

var oUserNormalsProperty = oCluster.AddProperty( "User Normal Property", false );

oUserNormalsProperty.Elements.Array = aNormalData.Data;

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report