3D Cube script questions

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
User avatar
Peteroid
Posts: 162
Joined: Thu Aug 12, 2010 3:57 am
Location: las vegas, NV
Contact:

3D Cube script questions

Post by Peteroid » 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? :)
[==Peter==]
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete » Sun Oct 03, 2010 6:12 pm

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'?
local layer = moho:CreateNewLayer(MOHO.LT_3D)

The local layer variable is just to store the result of the moho:CreateNewLayer(MOHO.LT_3D)
when you can that moho member you effectively add a new layer in the document on top of the current selected layer in the layer stack. So yes, layer is never used but there is not need too. Mesh is added in the current selected layer that is the just created one.
-G
Post Reply