Page 1 of 1

Get position of a point?

Posted: Fri Jun 18, 2010 5:04 am
by ponysmasher
I'm probably missing something really obvious here but I've managed to get for example the x translation on frame 5 of a layer like this:

Code: Select all

local layerVector = LM.Vector3:new_local()
layerVector=textGroup.fTranslation:GetValue(5)
print(layerVector.x)
But how would I get the position of a point?

I know for sure that this doesn't work:

Code: Select all

numPoints=mesh:CountPoints()
	print(numPoints)
local vt = LM.Vector2:new_local()
	for i = 0, numPoints-1 do
	vt = mesh:Point(i).fPos:GetValue(0)
	print(vt.x)
	end
I get the first print and then an error. I'm guessing the problem is this syntax:

Code: Select all

mesh:Point(i).fPos:GetValue(0)

Re: Get position of a point?

Posted: Fri Jun 18, 2010 8:20 pm
by Rudiger
ponysmasher wrote:I'm probably missing something really obvious here but I've managed to get for example the x translation on frame 5 of a layer like this:

Code: Select all

local layerVector = LM.Vector3:new_local()
layerVector=textGroup.fTranslation:GetValue(5)
print(layerVector.x)
But how would I get the position of a point?

I know for sure that this doesn't work:

Code: Select all

numPoints=mesh:CountPoints()
	print(numPoints)
local vt = LM.Vector2:new_local()
	for i = 0, numPoints-1 do
	vt = mesh:Point(i).fPos:GetValue(0)
	print(vt.x)
	end
I get the first print and then an error. I'm guessing the problem is this syntax:

Code: Select all

mesh:Point(i).fPos:GetValue(0)
This section of the forum appears to be getting more active lately, which is awesome! There is still so much untapped potential in AS just waiting to be realized!

Anyway, try using fAnimPos instead of fPos. fPos is just the current poisition of the point, so doesn't have a GetValue method, whereas fAnimPos is the animantion channel you're probably looking for.

Posted: Fri Jun 18, 2010 10:07 pm
by heyvern

Code: Select all

    mesh = moho:Mesh()
    for i = 0, mesh:CountPoints() - 1 do
        local v = LM.Vector2:new_local()
        v = mesh:Point(i).fPos
        print(v.x)
        print(v.y)
    end
or...

Code: Select all

    mesh = moho:Mesh()
    for i = 0, mesh:CountPoints() - 1 do
        local v = LM.Vector2:new_local()
        v = mesh:Point(i).fAnimPos:GetValue(0)
        print(v.x)
        print(v.y)
    end

Rudiger is correct. fPos is direct access to the points position. fAnimPos you can get the value from a specific frame regardless of what frame you are on.

Generally I use fPos more because the code is simpler and you can CHANGE it and READ it much easier. fAnimPos must use..

Code: Select all

fAnimPos:SetValue(frame, value)
to set the value and...

Code: Select all

fAnimPos:GetValue(frame)
to get the value

fPos is easy, just "fPos = newPos" to change it. Of course that won't work if you want to change a position on a different frame.

I believe that fAnimPos is also needed to set a key frame... don't quote me... working from memory. :)

p.s. fAnimPos and fAnimAngle are very cool. I created a bone tool that would move and rotate bones only on frame 0 no matter what frame you were on. It was done ages ago for version 6 because of the sequencer. If a bone layer was slid BEHIND frame 0 of the document you couldn't reach frame 0 of that layer to move bones around.

-vern

Posted: Sat Jun 19, 2010 5:40 am
by ponysmasher
Yep, now it's working.

Thanks for the help! :D