3D Cube script questions
Posted: Sun Oct 03, 2010 3:48 pm
Here is the main routine for the 3D Cube menu script:
function LM_Cube:Run(moho)
local layer = moho:CreateNewLayer(MOHO.LT_3D)
local mesh = moho:Mesh3D()
if (mesh == nil) then
return
end
moho.document:PrepUndo(nil)
moho.document:SetDirty()
local startPt = mesh:CountPoints()
local vec = LM.Vector3:new_local()
-- top points
vec:Set(-0.5, 0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(0.5, 0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(0.5, 0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(-0.5, 0.5, -0.5)
mesh:AddPoint(vec)
-- bottom points
vec:Set(-0.5, -0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(0.5, -0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(0.5, -0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(-0.5, -0.5, 0.5)
mesh:AddPoint(vec)
local mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 1.25)
mesh:AddFace(startPt + 0, startPt + 1, startPt + 2, startPt + 3) -- top
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.5)
mesh:AddFace(startPt + 4, startPt + 5, startPt + 6, startPt + 7) -- bottom
mat = mesh:CreateNewMaterial()
mesh:AddFace(startPt + 0, startPt + 7, startPt + 6, startPt + 1) -- front
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.65)
mesh:AddFace(startPt + 2, startPt + 5, startPt + 4, startPt + 3) -- back
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.75)
mesh:AddFace(startPt + 3, startPt + 4, startPt + 7, startPt + 0) -- left
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.75)
mesh:AddFace(startPt + 1, startPt + 6, startPt + 5, startPt + 2) -- right
mesh:RebuildEdgeList()
end
Questions:
- The call 'CreateNewLayer' is nowhere in the documentation I have. I also need to be able to destroy a layer... but I'm I suppose to now guess function names and call sequences for a function I don't even know exists? Is there any COMPLETE documentation that includes this call and others along the same lines? I have ALL the documentation available in the Sticky posts, so no need to point me there, that is the documentation that is incomplete and has tons of typos (of course...lol).
- Look at the definition of 'layer' in the above code. It is created, and NEVER USED! Yet, when this code is called, a new 3D layer is created and the points created seem to be part of this layer. How did these points get associated with 'layer'?
- try creating a cube. It seems to be completely un-editable! You can't add points or access existing points. All you can do is re-size, move, and rotate it. The 'Draw', 'Fill', and 'Bones' tools are not available, and the fill color, line color, and line thickness are fixed at creation time. So this shows how to create a 3D object with a script, but the end result is not very manipulative!
Is there a way of creating a 3D layer that one CAN edit? Or is this a feature for AS8PRO?
function LM_Cube:Run(moho)
local layer = moho:CreateNewLayer(MOHO.LT_3D)
local mesh = moho:Mesh3D()
if (mesh == nil) then
return
end
moho.document:PrepUndo(nil)
moho.document:SetDirty()
local startPt = mesh:CountPoints()
local vec = LM.Vector3:new_local()
-- top points
vec:Set(-0.5, 0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(0.5, 0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(0.5, 0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(-0.5, 0.5, -0.5)
mesh:AddPoint(vec)
-- bottom points
vec:Set(-0.5, -0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(0.5, -0.5, -0.5)
mesh:AddPoint(vec)
vec:Set(0.5, -0.5, 0.5)
mesh:AddPoint(vec)
vec:Set(-0.5, -0.5, 0.5)
mesh:AddPoint(vec)
local mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 1.25)
mesh:AddFace(startPt + 0, startPt + 1, startPt + 2, startPt + 3) -- top
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.5)
mesh:AddFace(startPt + 4, startPt + 5, startPt + 6, startPt + 7) -- bottom
mat = mesh:CreateNewMaterial()
mesh:AddFace(startPt + 0, startPt + 7, startPt + 6, startPt + 1) -- front
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.65)
mesh:AddFace(startPt + 2, startPt + 5, startPt + 4, startPt + 3) -- back
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.75)
mesh:AddFace(startPt + 3, startPt + 4, startPt + 7, startPt + 0) -- left
mat = mesh:CreateNewMaterial()
MOHO.MultiplyColor(mat.color, 0.75)
mesh:AddFace(startPt + 1, startPt + 6, startPt + 5, startPt + 2) -- right
mesh:RebuildEdgeList()
end
Questions:
- The call 'CreateNewLayer' is nowhere in the documentation I have. I also need to be able to destroy a layer... but I'm I suppose to now guess function names and call sequences for a function I don't even know exists? Is there any COMPLETE documentation that includes this call and others along the same lines? I have ALL the documentation available in the Sticky posts, so no need to point me there, that is the documentation that is incomplete and has tons of typos (of course...lol).
- Look at the definition of 'layer' in the above code. It is created, and NEVER USED! Yet, when this code is called, a new 3D layer is created and the points created seem to be part of this layer. How did these points get associated with 'layer'?
- try creating a cube. It seems to be completely un-editable! You can't add points or access existing points. All you can do is re-size, move, and rotate it. The 'Draw', 'Fill', and 'Bones' tools are not available, and the fill color, line color, and line thickness are fixed at creation time. So this shows how to create a 3D object with a script, but the end result is not very manipulative!
Is there a way of creating a 3D layer that one CAN edit? Or is this a feature for AS8PRO?
