Page 1 of 2
Rotate LayerY from a script?
Posted: Fri Jul 20, 2007 12:22 am
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?
Posted: Fri Jul 20, 2007 3:00 am
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?
Posted: Fri Jul 20, 2007 6:09 am
by Genete
Angle must be in radians.

-G
Posted: Fri Jul 20, 2007 6:24 am
by Ricardo
Genete wrote:Angle must be in radians.

-G
How is this?
Posted: Fri Jul 20, 2007 6:38 am
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.
Posted: Fri Jul 20, 2007 8:42 am
by Genete
What says your debug prints?
(I cannot test your script now)
360 degrees = 2*PI radians
PI = 3.14159 ....
-G
Posted: Fri Jul 20, 2007 6:48 pm
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.
Posted: Fri Jul 20, 2007 8:22 pm
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
Posted: Fri Jul 20, 2007 8:25 pm
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?
Posted: Fri Jul 20, 2007 10:09 pm
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
Posted: Fri Jul 20, 2007 10:57 pm
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.
Posted: Sat Jul 21, 2007 12:58 am
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
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
Posted: Sat Jul 21, 2007 3:57 am
by Ricardo
Posted: Sat Jul 21, 2007 4:12 am
by Ricardo
What i had in mind was that user make some shape in a layer.
The the script make some identicall geometric figure in another layer and give it some Z
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
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.
Posted: Sat Jul 21, 2007 4:13 am
by Ricardo