Get position of a point?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
ponysmasher
Posts: 370
Joined: Wed Aug 04, 2004 6:23 pm
Location: Los Angeles
Contact:

Get position of a point?

Post 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)
Rudiger
Posts: 786
Joined: Sat Dec 17, 2005 5:25 pm

Re: Get position of a point?

Post 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.
User avatar
heyvern
Posts: 7043
Joined: Thu Sep 01, 2005 8:49 pm

Post 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
ponysmasher
Posts: 370
Joined: Wed Aug 04, 2004 6:23 pm
Location: Los Angeles
Contact:

Post by ponysmasher »

Yep, now it's working.

Thanks for the help! :D
Post Reply