Posted: Sun Jun 08, 2008 8:30 pm
Thanks for the input Genete. As long as our scripters are discussing things, I'm optimistic. 

Code: Select all
--Embed this script into all the vector layers that want to copy poses from frames 1,2,3,4, ..., maxposes
--it must be under a bone type layer and the following ROOT named bones MUST exists:
-- posek (with k form 1 to maxposes)
-- bonelesector
-- Copyright 2008 Genete
-- Released for free.
-- Thanks to Selgin for that great idea.
-- It can be extended for other animated values (curvatures, widths, shape fill colors, shape outline color, etc.)
-- Also weights w[k] can be overweigthed by the pose bone legth. It would allow some sort of variable action weights...
-- Under development...
-- Modififed June 5th, 2008:
-- Tim Fischer: Added local variables to speed up looping (interpreted languages recalculate every iteration so a variable can be much faster)
-- Added garbage collection routine to free memory (Auto GC doesn't appear to work). This fixes hanging, etc
poses = {}
maxposes = 2
bone = {}
boneselector = nil
function LayerScript(moho)
local w = {}
local distance
local posk
local pos_selector
local r
local length
local k
local layer = moho.layer
local frame = moho.frame
local skel = moho:ParentSkeleton()
if (skel == nil) then
print ("No parent skeleton found in layer:".. layer:Name())
return
end
local mesh = moho:Mesh()
if (mesh==nil) then
print ("No mesh found in layer:".. layer:Name())
return
end
if (frame <=maxposes) then
-----------------------------------look for the bones
for k=1, maxposes do
bone[k] = nil
local fc1 = skel:CountBones()-1 -- added to speed up loops
for i=0, fc1 do
local bonei = skel:Bone(i)
local bonek = "pose" .. tostring(k)
if (bonei:Name() == bonek) then
bone[k]=bonei
elseif (bonei:Name() == "boneselector") then
boneselector=bonei
end
end
if (bone[k] == nil) then
print("bone "..k.." is missing")
return
end
end
if boneselector == nil then
print("boneselector is missing")
return
end
collectgarbage(maxposes)
---------------------------------
--------------------------------- creates a new array for the layer
poses[layer]={}
poses[layer]["points"]={}
for k=1, maxposes do
poses[layer]["points"][k]={}
local fc2 = mesh:CountPoints()-1 -- added to speed up loops
for i=0, fc2 do
poses[layer]["points"][k][i]=mesh:Point(i).fAnimPos:GetValue(k) --store all the points/pose/positions
end
collectgarbage(fc2)
end
return
end
pos_selector = boneselector.fPos --position of the selector bone.
length = boneselector.fLength*boneselector.fAnimScale:GetValue(moho.frame) --current length of the boneselector
for k=1, maxposes do
w[k]=0
posk = bone[k].fPos
distance = posk - pos_selector
r = distance:Mag()
w[k]=weight(r, length)
end
local wtot=0.0 --total weight
for k=1, maxposes do
wtot =wtot +w[k]
end
if (wtot == 0.0) then return end
local fc3=mesh:CountPoints()-1 -- added to speed up loops
for i=0, fc3 do --- move the points.
local pimoved =LM.Vector2:new_local()
pimoved:Set(0,0)
for k=1, maxposes do
pimoved = pimoved + poses[layer]["points"][k][i]*w[k]/wtot
end
local pi=mesh:Point(i).fPos:Set(pimoved)
end
collectgarbage (fc3)
end
function weight (r, l)
if (r <= l) then
local w =r/l-1
--print(w)
return w
else
return 0.0
end
end
The reason for calcualting the variables *before* the for loop is that in an interpreted language, including VB/VB6, javascript, etc each iteration of the loop *MUST* re-calculate the variable - which can totally kill performance
I played around with this for just a few minutes. I don't know how it would work exactly. I think you might have to copy frame 0 to an "extra" pose frame. Or grab the point positions from frame 0 and calculate the difference in motion to the other frames with out the pose blending.I wonder if there's any way to make it so that, if need be, point animation can operate within the script...
There is no influence from other bones. Only the pose motion controls the points. All other influence is ignored.Also, I wonder about the affect of bones from parent layers on the points of the vector layers that are under control of this script. You either might get a odd warping or no warping at all, which could also be odd. -I've never tried it, but it seems like plausible issues.
What if you made a parse then open file menu script? You'd have to have AS already open, but then you should be able to search the text file for action names and key data, shouldn't you?The perfect solution would be if actions and the keys could be accessed as easily as the main time line keys. then instead of inserting keys in the first frames of the time line you would just use keys from the action.
In fact this script is very simple.slice11217 wrote:Hi guys,
This is a great script and a great idea and all, but there's a couple of areas where I feel a little hmm.... limited by it. I'm not a scripter or anything but I wonder if there's any way to make it so that, if need be, point animation can operate within the script. I mean, I often have points during an animation where I realize that I simply need to move a point manually because what I'm getting from the bones is warping the design in such a way that the image and the animation doesn't look right. This script doesn't allow point movement while the script is in play.
Also, I wonder about the affect of bones from parent layers on the points of the vector layers that are under control of this script. You either might get a odd warping or no warping at all, which could also be odd. -I've never tried it, but it seems like plausible issues.
Is there any way to address this in the script?
Thanks,
S
Code: Select all
local pi=mesh:Point(i).fPos:Set(pimoved)
Code: Select all
mesh:Point(i).fPos:Set(pimoved)
Well see, this is partly what I'm addressing: if I'm animating and I run into a problem (which happens far more frequently than I'd like for it to), and I need a pose that I didn't anticipate then I'm screwed. The script as it stands right now requires that you anticipate everything you're going to need up front. I don't know about anyone else but this is very difficult to do.Genete wrote: First you store a fixed (but can be modified) number of poses in the first frames (they can be stored in the negative frames after fantastic heyvern discovery.
Child vector layer as also fixed, but less so. While a child vector is selected I can set point motion animation but while it is interpolating from one child to another, I cannot.Genete wrote: They are like the child vector layers of a switch layer but they are fixed. They have not option to have a animation by the time as far as it hasn't its own time line.
I've never been able to combine more than two switch child vector layers at any time. Moreover, the only visual control of an interpolated pose that's available is the timing of it, and I'd personally prefer to be able to manipulate the ease the in/out of that manually.Genete wrote: There are two benefits from the usage of switch layers:
1) Visual control of the interpolated pose
2) You can stop at any intermediate pose and / or can combine several poses at the same time.
Why? I'm not sure I understand when you say you are "locked in" and can't make changes? The poses are based on named bones, need more poses just increase the "maxpose" variable and add in new poses and bones. If you need to tweak the poses later then, tweak the points on the frame of the pose with onion skin turned on. The only thing that might be a problem is how far ahead do you start the animation so there is rooom to add more poses?The disadvantage of this script is that once you've set up those poses, that's it! -You can't go in and modify things as you go, you're hardwired in. You have to anticipate what you're going to need up front or suffer the consequences.
This is the case even if the script had everything you wanted and was perfect. This script doesn't "cause" the extra work. It makes the extra work more usable.Also, for head turns it seems you'd need to create a rather vast library of mouth phenomes and eye positions, eyebrow expressions, etc. in every pose -Lots of work!