In Lightwave’s lScript language, I cannot seem to get “Align Pitch” working. It should work the same in lScript as in Layout, but I have had no success.

My general process is:

  • load an object with skelegons
  • convert skelegons to bones
  • select a bone
  • record pivot rotation
  • align pitch

I can script everything correctly (I think) up to aligning the pitch. I can’t seem to get this right in scripting.

In lscript,

  • I grab the mesh’s overall rotation
  • Then, for each bone, I set the rest rotation with RecordPivotRotation()
  • I then apply the mesh’s rotation to each bone, but it doesn’t seem to have an effect – the object ends up twisted beyond recognition.

Below is the code I tried. Please note that there are a lot of different attempts, so you can’t assume that just because I commented/uncommented something that it is needed/unneeded. I basically do not know how to get this to work.

generic
{
	// set frame to edit in
	currTime = 0;

	// Create Mesh Object Agent from first object.
	mesh = Mesh();
	EnableIK;
	ParentInPlace(true);
	
	// if no bones, then create from skelegons
	if(mesh.bone() == nil)
	{
		SkelegonsToBones();
		
		// if no bones now, then exit
		if(mesh.bone() == nil)
		{
			info("No skelegons or bones in this object: " + mesh.name);
			return;
		}		
	}

	// enter bone edit mode
	// EditBones();

	// Create Bone Object Agent from first bone in
	// from mesh Object Agent.

	// select the first bone
	bone = mesh.bone();
	// tempParent = bone.parent;
	
	// get mesh's default rotation
	meshRot = mesh.getRotation(currTime);
	info(meshRot);

	// Cycle through all bones until a bone value == 'nil'.while(bone)
	while(bone != nil)
	{
		// Display some of the current bone’s
		// values on frame 0, by accessing bone Object Agent.
		// info("Bone Name: ", bone);
		
		// set next's parent to the mesh to keep from deforming.
		// boneNext = bone.next();
		// SelectByName(boneNext.name);
		// ParentItem(tempParent);
		
		// select the current bone
		SelectByName(bone.name);
		//BoneActive();
		
		// reset the bone's rest position to the current position
		RecordPivotRotation();
		
		// realign rotation to the mesh's rotation.
		//Generic_BT_AlignPitch();
		BoneRestRotation(meshRot.h, meshRot.p, meshRot.b);
		// (Heading, Pitch, Bank)
		//info(bone.getRotation(currTime).h, mesh.getRotation(currTime).p, bone.getRotation(currTime).b);
		// BoneRestRotation(bone.getRotation(currTime).h, mesh.getRotation(currTime).p, bone.getRotation(currTime).b);
		//Generic_BT_BonesOFF;
		// SelectByName(boneNext.name);
		// ParentItem(bone);
		
		// NextFrame;
		// PreviousFrame;
		// RedrawNow;
		// RefreshNow;
		
		// pause
		//info("Bone Name: ", bone);
		
		// Cycle to next bone. If no bone is available, bone will equal ‘nil’.
		bone = bone.next();
		
		// bone = bone.SelectChild();
		// if(bone = nil)
		// {
			// bone = bone.NextSibling();
			// if(bone = nil)
			// {
				// bone = parBone.NextSibling();
			// }				
		// }		
	}
	
	//ModCommand_BoneWeights;
}

Can anyone help?

– 30 –

Advertisements