Page 1 of 2

Not really Flip Points but Simulate it...

Posted: Thu Aug 10, 2006 7:23 pm
by Rai López
...HI! I always have thought if don't could have a way to resolve basic morphings in a more easy and quick way with something like a little intelligent "Flip Horizontal/Vertical" tool. Well, the case is that If I have a simetric (in number of points) shape, let's say a head, and I want to simulate a 3/4 head turn flipping horizontally the points, the animation/morphing results, as you know, in something like a dissaster cause the ID of the points is flipped too and, in example, the points that form the right eye of the head go to the other side to become in the left eye and viceversa... And well, the question is if don't could be a tool (or an option) to can simulate the same flip effect but leaving the points in the same part of the head avoiding that unwanted results during point morph... Hmmm, well I hope have got more or less explain it and someone be interested in something like this... CIAO! :)

Posted: Fri Aug 11, 2006 1:50 am
by jeff
Ramón, I don't think what you are proposing is possible, if I understand you correctly. Any "flipping" must mean that points have to cross from left to right and vice versa and so something horrible must happen between the two extremes.

For minor head turns, I use the "rotate Y" layer and it works well for me, but then I am not looking for realism.

Jeff

Posted: Fri Aug 11, 2006 10:29 am
by heyvern
I think it might be possible as long as the mesh is perfectly symetrical... not in shape but in number of points.. and the mesh is centered on the the layers x axis origin point.

So... you could apply a "reversed" point translation to the opposite points of the symetrical mesh. Like he says... you wouldn't actually be flipping the points.. you would make the points on opposite sides the "reversed" position of the other side... basically copying the points location and applying a negative number or... whatever... to the x axis location of the point.

This would be a god send for doing "complete" head turns.

I end up having an "extra" layer in the switch (the "middle" position.. like facing forward) and "jump" to one that is flipped... not a pretty solution but it sort of works.

Lately I have been "tracing" the flipped layer. I modify the mesh in the switch to line up with a flipped mesh... uh... yeah... like that. ;)

-vern

Posted: Sat Aug 12, 2006 7:02 am
by jeff
Not sure I really understand, Vern, but then I'm no techie. I'd be interested to see what you describe in action. Since Moho is purely 2D, I rather suspect the end result would be......odd. Certainly wouldn't have anything in common with the same very simple action in a true 3D program since there would be no information concerning perspective.

Jeff

Posted: Sat Aug 12, 2006 7:36 am
by Rai López
EY! Thank you for your interest guys :) ...Now I have no time to write enough but I must say that Vern has understood exactly what I mean, and about jeff I'd say that you souldn't expect miracles usin this technique, only it could make more easy and quick some "little" morphings and some "little" head turns, there is nothing new on it and you can do it now manualy in Moho to observe the results so, in principle, it would be compatible with te 2D possibilities and philosophy, SO LONG!

Posted: Sat Aug 12, 2006 8:51 am
by Víctor Paredes
oh, was hard to understand it. but it's a really good idea!!
i hope someone of our loved scripters could make it true.

i have technical questions, but i don't know if would be pertinent ask now.

Posted: Sat Aug 12, 2006 4:01 pm
by heyvern
Jeff,

Actually, Animation:Master has a similar feature... called "Paste Mirrored". It allows you to do something similar to what is being described... and it has nothing to do with perspective. This is all about point locations... no perspective. 3d need not be involved.

I can't think of a better way to explain it... but I will try

You have a 2d circle with 25 points on one side... and 25 on the other. It is a perfect circle made of 50 points and is symmetrical.

You move those points to creat the shape of a face.. a profile of a face.

Let's imagine this profile is a layer in a head turn switch. The other layer is the forward version.

You want to create a turn going the other direction so you need to flip it... but you can't really flip.

Now you run the "magic script"...

It takes the XY locations of each of the points on the left side and "reverses" the coordinates with a "matching" point on the right side.

The points STAY on the same side so there is no... twisting and flipping during the switch interopolation... but move to a "mirrored" point location simulating a "flip". They just move to the exact opposite position that mirrors a matching point on the other side.

If it still isn't clear... I give up... I can't think of any other way to explain it. It seems pretty simple in my head... basically because I wish I had it!

;)

-vern

Posted: Sun Aug 13, 2006 3:46 am
by jeff
Thanks for that Vern.

Jeff

Posted: Wed Aug 16, 2006 7:21 am
by Fazek
Below you can find a "button" tool (don't forget to enter its name into the _tool_list.txt as a button) It reverses the order of the selected points on curves. It also mirrors the points with a mirroring axis, defined by the first and the middle point of the curve.

My polygon tool is a good one to make Heyvern's circle.
Maybe I'll make a complete tool from this later. It looks really useful.

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "FA_ReversePoints"

-- **************************************************
-- General information about this script
-- **************************************************

FA_ReversePoints = {}

function FA_ReversePoints:Name()
	return "Reverse Points"
end

function FA_ReversePoints:Version()
	return "5.0"
end

function FA_ReversePoints:Description()
	return "Reverse the order of selected points (by curves)"
end

function FA_ReversePoints:Creator()
	return "Fazek"
end

function FA_ReversePoints:UILabel()
	return("Reverse Points")
end

-- **************************************************
-- The guts of this script
-- **************************************************

function FA_ReversePoints:IsEnabled(moho)
	if (moho:CountSelectedPoints() > 1) then
		return true
	end
	return false
end

function FA_ReversePoints:Run(moho)
	local mesh = moho:Mesh()
	if (mesh == nil) then
		return
	end

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()
	mesh:PrepMovePoints()

	for i = 0, mesh:CountCurves() - 1 do
		local cve= mesh:Curve(i)
		local tab= {}
		local even= true

		for j = 0, cve:CountPoints() - 1 do
			local pt= cve:Point(j)

			if (pt.fSelected) then
				table.insert(tab,pt)
				even= not even
			end
		end
		local n= table.getn(tab)

		if (n > 1) then

			if (cve.fClosed) then
				table.insert(tab,tab[1])
				even= not even
				n= n + 1
			end
			local mx,my
			local mirrorX= tab[1].fTempPos.x
			local mirrorY= tab[1].fTempPos.y

			if (even) then
				mx= (tab[n / 2].fTempPos.x + tab[(n + 2) / 2].fTempPos.x) / 2 - mirrorX
				my= (tab[n / 2].fTempPos.y + tab[(n + 2) / 2].fTempPos.y) / 2 - mirrorY
			else
				mx= tab[(n + 1) / 2].fTempPos.x - mirrorX
				my= tab[(n + 1) / 2].fTempPos.y - mirrorY
			end
			local q= (mx * mx) + (my * my)

			for j = 0, cve:CountPoints() - 1 do
				local pt= cve:Point(j)

				if (pt.fSelected) then
					local pt2= tab[n]
					local ax= pt2.fTempPos.x - mirrorX
					local ay= pt2.fTempPos.y - mirrorY

					if (q > 0) then
						local x= ((ay * mx) - (ax * my)) / q
						local y= ((ax * mx) + (ay * my)) / q
						ax= (mx * y) + (my * x)
						ay= (my * y) - (mx * x)
					end
					pt.fPos.x= mirrorX + ax
					pt.fPos.y= mirrorY + ay
					n= n - 1
				end
			end
		end
	end
	moho:AddPointKeyframe(moho.frame)
	moho:NewKeyframe(CHANNEL_POINT)
end

Posted: Wed Aug 16, 2006 9:02 am
by Víctor Paredes
thank you!!!!
i'm now playing with this new tool and it's great.

Posted: Wed Aug 16, 2006 2:30 pm
by heyvern
Yeehaaa!


..Uh... I have a question though...


Supposing... you used the old regular "flip points" tool... this flips on the axis of the view... which is good.

Now... you can't use this for doing a switch turn thingy because now all the points are in a different order...

... but if you just did that... reverse order thingy... right?

Do we even need the mirror points part of it? Just use the regular flipper?

For instance I created a switch layer and reversed it using the new tool... then I just rotated it around so it matched up with the other layer since I didn't have the middle point in the center.

Just thinking out loud...

-vern

Posted: Wed Aug 16, 2006 2:42 pm
by bupaje
Cool! I hope I get some time to use Moho soon, lots of useful scripts. I actually suggested this recently as I thought it would be useful with macton's 'copy curve' thing to define a head turn with a curve but on anything but squares all the points flipped as already mentioned.

Image

Posted: Wed Aug 16, 2006 11:28 pm
by Fazek
Hello Vern,

First I made this without the flipping part. With this algorythm, where a point gets exactly the coordinates of one another point, and the addressing begins from the first point of the curve, the mirroring axis cannot be anywhere. As I wrote, I am thinking on a more complete tool where the mirroring axis can be set by the user, but it requires a new point addressing technique and sometimes interpolation between the points. You can use the regular flip points tool only in special cases.

Posted: Wed Aug 16, 2006 11:51 pm
by heyvern
Thanks Fazek.

I played around with this and it could really really be useful.

Even as it is it could save a ton of work on complex head turns that... uh... need to go the other way.

I have found lately I don't need more than two layers for a head turn. This is great. It is always that... other side of the turn... that causes the trouble.

It doesn't work with multiple closed shapes selected (eye holes)... but there is always more than one way to skin a cat! ;)

p.s. No cats were harmed during testing.

-vern

Posted: Mon Sep 11, 2006 5:21 am
by Rai López
...EY, Fazek! I've finally had some time to play & experiment with your code and definitely it can save a lot of time! I think Moho needs some specific 2D tools to make it more easier and effective and fortunately we have you here :) ...Well, as you guys have still said, the tool would need some implementations (for several objects at a time, i.e.) and improvements during flipping, yes, but I think that it's a very good start point to get it and this is the more important thing... plus Fazek's lines of code always open lots of possiblities and maybe inspire another incredible scripting features for our happyness, who knows :) ...Well, for this and for so many things (I never will be able to forget that INSTANCING VECTOR LAYERS script) I must say you THANK YOU!!! one more time, BYE! :D