Almost a year later.... I've used this script a few times now, I've always
gotten the same error message when trying to copy over weights


62     WeightsArray.push(NewWeights);
"// ERROR : Object doesn't support this property or method - [line 62]"

In the past the curves have always stuck fairly well to the geo so I
assumed it was working properly.  This latest time it seems to be ignoring
the geo's weights and is applying a new envelope as if I'd just set a new
envelope - lots of stretching between the curves.  Has anybody else run
into this?  Does anybody know of a workaround for copying weights from a
mesh to a curve?


Thanks,

Dave





On Mon, Mar 28, 2011 at 9:16 AM, Jeremie Passerin <[email protected]>wrote:

> Eric, maybe we should just log the request :)
>
> cheers, Cyril !
> I'll try it next time.
> hope you're doing fine, long time no see ;-)
>
>
> On 28 March 2011 15:10, Cyril Gibaud <[email protected]> wrote:
>
>>  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 ---
>>
>>  *From:* Jeremie Passerin <[email protected]>
>> *Sent:* Monday, March 28, 2011 10:01 AM
>> *To:* [email protected]
>> *Subject:* Gator and Curves
>>
>> Hey list,
>>
>> Anyone knows the reason why we can not use gator with curves ? I mean to
>> transfer envelope and shapes ?
>>
>> cheers,
>>
>> Jeremie
>>
>
>


-- 
Dave Thomlison

Reply via email to