-- **************************************************
-- 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?
-- **************************************************
-- 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
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.
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.
-- **************************************************
-- 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
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.
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
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.
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.
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
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.
Last edited by Ricardo on Sat Jul 21, 2007 4:19 am, edited 1 time in total.