Hi
No idea of the actual reason...except that
poymeshes/Surfaces geometries are not defined as Curves geometries, so I guess
the exact same algorithm cannot be used.
I don't know if you need something like that but I
had to gator curves to polymeshes recently so I wrote a very simple
function that acts pretty much like a gator curve...Maybe could be helpfull for
others anyway ^^.
The script is not commented...for a simple usage
select your curve then your polymesh, or just the curve and you will be asked to
pick a polymsh. Don't hesistate to contact me if it doesn't work
anymore.
cheers
Cyril
// --- JAVASCRIPT ---
var oSel = GetValue("SelectionList");
if(oSel.Count > 0)
{
if(oSel.Count
> 1)
{
GatorCurve(oSel(0),
selection(1));
}
else
{
var rtn =
PickElement(siPolyMeshFilter, "Select polymesh", "Select
polymesh");
var element = rtn.Value(
"PickedElement");
logmessage(element.Type);
if(element.Type
==
"polymsh")
{
GatorCurve(GetValue("SelectionList")(0),
element);
}
}
}
else
{
logmessage("Please
select the curve, and eventually the mesh to be \"gatorized\" !",
siError);
}
function GatorCurve(inCurve,
inMesh)
{
var NurbsCurve =
inCurve.ActivePrimitive.Geometry.Curves(0);
var oGeo =
inMesh.ActivePrimitive.Geometry;
var oEnvelope =
inMesh.ActivePrimitive.ConstructionHistory.Find( "envelopop" );
var
oDefs = oEnvelope.Deformers;
var oEnvelopeWeights =
oEnvelope.Weights.Array.toArray();
ApplyFlexEnv(inCurve + ";" +
oDefs.GetAsText(), null, 2);
var CurveEnvelope =
inCurve.ActivePrimitive.ConstructionHistory.Find( "envelopop"
);
var WeightsArray = new Array();
var
DeformWeightsArray = new Array(oDefs.Count);
for(var i = 0; i <
NurbsCurve.ControlPoints.Count ; i++)
{
//Get closest
from the point
var ClosestPointLocator =
oGeo.GetClosestLocations(new Array(NurbsCurve.ControlPoints(i).Position.X,
NurbsCurve.ControlPoints(i).Position.Y,
NurbsCurve.ControlPoints(i).Position.Z))
var TriangleVertices =
oGeo.GetTriangleVertexIndexArray(ClosestPointLocator).toArray();
var
TriangleWeights =
oGeo.GetTriangleWeightArray(ClosestPointLocator).toArray();
//GetWeights for each
vertex
var NewWeights1 =
GetSubArray(oEnvelopeWeights, oDefs.Count,
TriangleVertices[0]);
var NewWeights2 =
GetSubArray(oEnvelopeWeights, oDefs.Count,
TriangleVertices[1]);
var NewWeights3 =
GetSubArray(oEnvelopeWeights, oDefs.Count, TriangleVertices[2]);
//Blend Arrays
var
NewWeights = BlendArrays(NewWeights1, TriangleWeights[0], NewWeights2,
TriangleWeights[1], NewWeights3,
TriangleWeights[2]);
WeightsArray.push(NewWeights);
}
for(var
k = 0; k < oDefs.Count ; k++)
{
DeformWeightsArray[k]
= new Array(WeightsArray.length);
for(var j = 0;
j < WeightsArray.length ;
j++)
{
DeformWeightsArray[k][j] =
WeightsArray[j][k];
}
}
for(var j =
0; j < oDefs.Count ;
j++)
{
CurveEnvelope.SetDeformerWeights(oDefs(j),
JS2VBArray(DeformWeightsArray[j]));
}
}
function GetSubArray(inEnvelopeWeights,
inDefsCount, inIndex)
{
var NewArray = new
Array(inDefsCount);
for(var i = 0 ; i < inDefsCount;
i++)
{
NewArray[i] = inEnvelopeWeights[i + ( inIndex *
inDefsCount)];
}
return NewArray;
}
function BlendArrays(inNewWeights1,
inWeights1, inNewWeights2, inWeights2, inNewWeights3,
inWeights3)
{
var NewArray = new
Array(inNewWeights1.length);
for(var i = 0 ; i <
NewArray.length; i++)
{
NewArray[i] = inNewWeights1[i] *
inWeights1 + inNewWeights2[i] * inWeights2 + inNewWeights3[i] *
inWeights3;
}
return NewArray;
}
function JS2VBArray( objJSArray )
{
var
dictionary = new ActiveXObject( "Scripting.Dictionary" );
for ( var i = 0; i < objJSArray.length; i++ )
{
dictionary.add( i, objJSArray[ i
] );
}
return dictionary.Items();
}
// --- END OF SCRIPT ---