Rotate LayerY from a script?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Rotate LayerY from a script?

Post by Ricardo »

I modify triangle script (from the menu ones) to draw a rectangle.

It works fine.

Code: Select all

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

ScriptName = "RA_Square"

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

RA_Square = {}

RA_Square.BASE_STR = 2580

function RA_Square:Name()
	return "Square"
end

function RA_Square:Version()
	return "5.0"
end

function RA_Square:Description()
	return MOHO.Localize(self.BASE_STR, "Creates a new square shape in the current layer.")
end

function RA_Square:Creator()
	return "Ricardo"
end

function RA_Square:UILabel()
	return(MOHO.Localize(self.BASE_STR + 1, "Square"))
end

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

function RA_Square:IsEnabled(moho)
	if (moho.layer:LayerType() ~= MOHO.LT_VECTOR) then
		return false
	end
	if (moho.layer:CurrentAction() ~= "") then
		return false -- creating new objects in the middle of an action can lead to unexpected results
	end
	return true
end

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

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

	local n = mesh:CountPoints()
	local v = LM.Vector2:new_local()
	local r = 0.75

	mesh:SelectNone()

	v.x = -0.667
	v.y = 0.667
	mesh:AddLonePoint(v, 0)

	v.x = 0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)

	v.x = 0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)

	

	mesh:WeldPoints(n, n + 4, 0)

	mesh:Point(n):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 1):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 2):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 3):SetCurvature(MOHO.PEAKED, 0)

	mesh:SelectConnected()
	moho:CreateShape(true)
end
But now i want to from the same script dom the "Rotate LayerY" but dont know how.
Its possible?
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

This other dont work

Code: Select all

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

ScriptName = "RA_Cube"

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

RA_Cube = {}

RA_Cube.BASE_STR = 2490

function RA_Cube:Name()
	return "Square"
end

function RA_Cube:Version()
	return "5.0"
end

function RA_Cube:Description()
	return MOHO.Localize(self.BASE_STR, "Creates a new cube shape in the current layer.")
end

function RA_Cube:Creator()
	return "Ricardo"
end

function RA_Cube:UILabel()
	return(MOHO.Localize(self.BASE_STR + 1, "Cube"))
end

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

function RA_Cube:IsEnabled(moho)
	if (moho.layer:LayerType() ~= MOHO.LT_VECTOR) then
		return false
	end
	if (moho.layer:CurrentAction() ~= "") then
		return false -- creating new objects in the middle of an action can lead to unexpected results
	end
	return true
end

function RA_Cube:Run(moho)
	local layer = moho:CreateNewLayer(MOHO.LT_VECTOR)
	layer:SetName("Front") 


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

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

	local n = mesh:CountPoints()
	local v = LM.Vector2:new_local()
	local r = 0.75

	mesh:SelectNone()

	v.x = -0.667
	v.y = 0.667
	mesh:AddLonePoint(v, 0)

	v.x = 0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)

	v.x = 0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)

	

	mesh:WeldPoints(n, n + 4, 0)

	mesh:Point(n):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 1):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 2):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 3):SetCurvature(MOHO.PEAKED, 0)

	mesh:SelectConnected()
	moho:CreateShape(true)
	moho.layer.fRotationY.value = 45  --<<<<<<<<<
	moho.layer.fRotationX.value = 45  --<<<<<<<<<
	print (moho.layer.fRotationY.value) 
	print (moho.layer.fRotationX.value)
	print (layer:Name())
end
Why?
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Angle must be in radians. 8)
-G
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

Genete wrote:Angle must be in radians. 8)
-G
:shock:

How is this?
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

Radian/Dehree converter http://wolf.galekus.com/viewpage.php?page_id=10

Ok, i go there and i get that 0.5 radians are more or less like 90 degrees.

I change that in the script and still nothing.
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

What says your debug prints?
(I cannot test your script now)

360 degrees = 2*PI radians

PI = 3.14159 ....
-G
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

If you are having trouble with this you could try this:

Code: Select all

math.rad (60) --> 1.0471975511966
math.deg (1.0471975511966)  --> 60
Then at least you could test what you are doing to see if the values are correct.

math.rad and math.deg converts to each type of value for a rotation. I think it was Genete who told me you should always work in radians as much as possible.
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

heyvern wrote:If you are having trouble with this you could try this:

Code: Select all

math.rad (60) --> 1.0471975511966
math.deg (1.0471975511966)  --> 60
Then at least you could test what you are doing to see if the values are correct.

math.rad and math.deg converts to each type of value for a rotation. I think it was Genete who told me you should always work in radians as much as possible.
Thanks for you advice.

I added that to the script but cant see any difference, no matter that if i print the fRotationY value it shows fine.

Here is the script

Code: Select all

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

ScriptName = "RA_Cube"

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

RA_Cube = {}

RA_Cube.BASE_STR = 2490

function RA_Cube:Name()
	return "Square"
end

function RA_Cube:Version()
	return "5.0"
end

function RA_Cube:Description()
	return MOHO.Localize(self.BASE_STR, "Creates a new cube shape in the current layer.")
end

function RA_Cube:Creator()
	return "Ricardo"
end

function RA_Cube:UILabel()
	return(MOHO.Localize(self.BASE_STR + 1, "Cube"))
end

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

function RA_Cube:IsEnabled(moho)
	if (moho.layer:LayerType() ~= MOHO.LT_VECTOR) then
		return false
	end
	if (moho.layer:CurrentAction() ~= "") then
		return false -- creating new objects in the middle of an action can lead to unexpected results
	end
	return true
end

function RA_Cube:Run(moho)
	local layer = moho:CreateNewLayer(MOHO.LT_VECTOR)
	layer:SetName("Front") 


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

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

	local n = mesh:CountPoints()
	local v = LM.Vector2:new_local()
	local r = 0.75

	mesh:SelectNone()

	v.x = -0.667
	v.y = 0.667
	mesh:AddLonePoint(v, 0)

	v.x = 0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)

	v.x = 0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = -0.667
	mesh:AppendPoint(v, 0)

	v.x = -0.667
	v.y = 0.667
	mesh:AppendPoint(v, 0)


	mesh:WeldPoints(n, n + 4, 0)

	mesh:Point(n):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 1):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 2):SetCurvature(MOHO.PEAKED, 0)
	mesh:Point(n + 3):SetCurvature(MOHO.PEAKED, 0)

	mesh:SelectConnected()
	moho:CreateShape(true)
	moho.layer.fRotationY.value = math.rad (90)  --<<<
	print (moho.layer.fRotationY.value) 
	print (layer:Name())
end
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

I realise that to be able to build a fake 3D structure using layers, i need to use RotateY, RotateX and give a Z value from my script.

Can anybody point some some script that uses this functions or can give me some advice how to acomplish it please?
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

If you want to create "3D" structures out of layers try doing it by hand first with the rotate layer tools. You don't need a script to rotate layers...

Unless of course.. you only have the standard version of AS which can't rotate layers on the Y and X... Is that what this is about? You want to create your own rotate layer tools because you have the standard version of AS?

It could be that the standard version won't even allow rotation on those axes, that might be why the script isn't working.

-vern
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

Yes, i know i can doit by hand and i know how ro do it.
Now im looking for doing it by script to add some features i want to be able to do it automatically.
I have some nice ideas about it, but cant find a way to do a simple 3D fake cube (like the one on the tutorial) by script.

Ince i get able to do that, i think i have a way to develope a tool that let me do some houses and so in a easier way :)

*BTW, im using PRO version.
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Genete and I have been working on that "fake" 3D you speak of.

It was NOT easy to get there... but the results are great and... fairly simple to set up. Our solution is based on a vector layer and using bones for each point. The bones are translated based on 3D math to create the 3D rotation.

http://www.lowrestv.com/moho_stuff/chair_props.mov
Image

I was just thinking that the 3D system Genete and I have come up with could create a "3D house" and you could put a character inside it. You might have to split the 3D layer into multiple layers and insert the character between them but it could be done.

I may try a simple demo using this technique to see how it would work.

You can find the discussion of this in the Tips and Techniques forum section.

-vern
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

Its possible to do fake 3D houses and put characters inside.
Porlbme is that doing it manually is hard, but yes, we can find some tricks to get help from some scripts to do the maths

Image

Image

Image

Image
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

What i had in mind was that user make some shape in a layer.

Image



The the script make some identicall geometric figure in another layer and give it some Z

Image




Next, same script build and give the Xroration and Yrotation (plus Y values) to the needed shapes (each one in a different layer) to build the fake 3D house

Image

Exactly as the cube in the tutorial 2.8 that comes with AS, but with a little more complicated user designed shapes (not only cubes).

Maybe no bones needed for this.

Note: An yes, allow other script to put inside characters, because doing it by hand is very complicated and time consuming.
Last edited by Ricardo on Sat Jul 21, 2007 4:19 am, edited 1 time in total.
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Ricardo
Posts: 66
Joined: Thu Jun 28, 2007 4:50 am
Location: Argentina

Post by Ricardo »

heyvern wrote: Image
This is VERY good stuff!!! :shock: :D
----------------------------------
Im a software developer, my apps:
Mp3Doctor
SuperMp3Normalizer
Post Reply