Get ShapeKey cluster elment by index

Discussions concerning programming of SOFTIMAGE©
Post Reply
MikeM
Posts: 17
Joined: 23 Jun 2013, 23:11

Get ShapeKey cluster elment by index

Post by MikeM » 25 Sep 2015, 19:20

Hi, I am writing a script trying to get the ShapeKeys(clskey) vertex data and so far I can get the Shapekey vertex position changes, the ShapeKey only lists the vertices that have changed of position compared to the original mesh and I would like to get the index of those vertices relative to the original full mesh vertices list.

The ShapeKey vertex data is accessed through the ClusterElementCollection and I think I could get the vertex index with ItemsByIndex but I am not sure how to use it in Jscript and the only examples are in VBS.

Here's my current code to get to the mesh cluster shapes and the ShapeKey vertices position , I am just using a cube with a few vertices moved and 3 shapes for testing:

Code: Select all

SelectObj("cube_shapes_test", null, null);

//get mesh shape cluster
var oCls = selection(0).ActivePrimitive.Geometry.Clusters;
for ( var c = 0 ; c < oCls.count ; c++ )
{
//find a cluster of point type  and named "Shape"
if((oCls(c).Type == "pnt") && (oCls(c).Name == "Shape"))
{
//get cluster properties
var oProps = oCls(c).Properties;
	for ( var p = 0 ; p < oProps.count ; p++ )
	{
		if(oProps(p).Type == "clskey") 
		{
			var pts =  (new VBArray(oProps(p).Elements.Array)).toArray();

			// get vertices
			for ( var v = 0; v < pts.length; v+=3 )
			{
				logmessage ("cluster_" + p + "  " + pts[v] + " " + pts[v+1] + " " + pts[v+2]);
			}
		}
	}
}

}
The output:

Code: Select all

// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_0  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_1  0 0 0
// INFO : cluster_2  0 0 0
// INFO : cluster_2  0 0 0
// INFO : cluster_2  0 12.000000000000003 0
// INFO : cluster_2  0 12.000000000000003 0
// INFO : cluster_2  0 0 0
// INFO : cluster_2  0 0 0
// INFO : cluster_2  0 12.000000000000003 0
// INFO : cluster_2  0 12.000000000000003 0
// INFO : cluster_3  0 0 0
// INFO : cluster_3  0 0 0
// INFO : cluster_3  -11 -3 0
// INFO : cluster_3  -11 -3 0
// INFO : cluster_3  0 0 0
// INFO : cluster_3  0 0 0
// INFO : cluster_3  -11 -3 0
// INFO : cluster_3  -11 -3 0

Any ideas?
Thanks

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Get ShapeKey cluster elment by index

Post by csaez » 26 Sep 2015, 02:17

I dont have access to softimage on this computer, but afaik clusterProperty.Elements.Array gives you an array of deltas (vector3) indexed by the point id on the cluster, so you should map pointID/clusterID and there you go.

I also recommend you to get the entire dataset in one call and play around on your own instead of calling softimage methods per point, it's way faster! :)

MikeM
Posts: 17
Joined: 23 Jun 2013, 23:11

Re: Get ShapeKey cluster elment by index

Post by MikeM » 26 Sep 2015, 09:48

Oh I got that wrong and was confused thinking the shape wasn't giving me the same number or vertices as I am writing a mesh exporter, I export the triangles and not the facets (which gives a different number of points), it is indeed mapped like the points in the mesh so I don't need to look for the index, they are ordered in the same as the mesh points, thanks!

Although I am not sure how to read the multi-dimensional array as Vector3 in Jscript as I convert the Elements.Array safe array to a flat array, is there anyother way? I tried the data Grid but I am not too familiar with these, having to convert the SafeArrays for Jscript in softimage confuses me.

By getting the entire data set in one call I am guessing you mean storing the mesh points array into a var of my own (var oPoints= oGeometry.Points) instead of calling oGeometry.Points for every point?

Thanks

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 15:31
Skype: csaezmargotta
Location: Sydney, Australia
Contact:

Re: Get ShapeKey cluster elment by index

Post by csaez » 27 Sep 2015, 07:25

Hi Mike,

Be aware that ID mapping is 1:1 on entire clusters (probably the shapes you're testing), but you can also create partial clusters to hold shapekeys in which case indices will not match the mesh, shapekeys/weightmaps are indexed by its cluster ID :)

I haven't done much with shapekeys lately, but I think Softimage DataArrays follow this scheme ((x1, x2, x3... xn), (y1, y2, y3... yn), (z1, z2, z3... zn)).
The reason has to do with performance, here's a nice explanation showing the difference at a lower level: http://www.youtube.com/watch?v=ScvpoiTbMKc

And yes, try to minimize Softimage types/calls as it go through a tricky pipeline (win32com) and it takes time, specially if you're dealing with a lot of data (i.e. points, pixels and so on).

Cheers!

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests