Get ShapeKey cluster elment by index
Posted: 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:
The output:
Any ideas?
Thanks
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]);
}
}
}
}
}
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