[Closed] [BETA] Scripted SimpleObject: COLUMNS
from: http://forums.cgsociety.org/showthread.php?p=4865468#post4865468
First of all: Thanks Bobo
Second: tested in MAX 8
The columns have different elements to apply different materials.
The Radiosity parameter increase the number of poligons in the column only, because softwares which calcutate radiosity like square poligons.
The rectangular planes at the start and the end are for creating the floor and ceiling meshes (from boolean operations on other objects) so, they have to be detached manualy at the end. Another time, this is only important for radiosity solutions.
plugin simpleObject Column
name:"Column"
classID:#(63446,55333)
category:"3DEmpire" (
local groundMesh, wallBaseMesh, columnMesh, ceilMesh, varTemp,
tempMesh0, tempMesh1, tempMesh2, tempMesh3, offAux, offsetX, offsetY
parameters sec rollout:params1 (
creationMethod type:#integer ui:creationMethod default:2
on creationMethod set val do (
if creationMethod == 1 then (
if this.length > this.width then this.length = this.width else this.width = this.length
)
)
)
parameters main rollout:params2 (
width type:#worldUnits ui:width default:0.3
length type:#worldUnits ui:length default:0.3
height type:#worldUnits ui:height default:2.4
corRadius type:#worldUnits ui:corRadius default:0.0
wbsHeight type:#float ui:wbsHeight default: 0.1
wbsWidth type:#float ui:wbsWidth default: 0.2
radiosity type:#boolean ui:radiosity
on width set val do (
if this.creationMethod == 1 do length = width
corRadius = if corRadius > width / 2.0 then width / 2.0 else corRadius
)
on length set val do (
if this.creationMethod == 1 do width = length
corRadius = if corRadius > length / 2.0 then length / 2.0 else corRadius
)
on wbsHeight set val do (
wbsHeight = if val > height then height else val
)
on corRadius set val do (
varTemp = (if width < length then width else length) / 2.0
corRadius = if val > varTemp then varTemp else val
)
)
fn offsetHalfMesh theTriMesh = ( -- offset all the vertices from the center to both sides
for v = 1 to theTriMesh.numverts do (
if (in coordsys grid getVert theTriMesh v).x > 0 then (
setVert theTriMesh v ((getVert theTriMesh v) * (matrix3 [1,0,0] [0,1,0] [0,0,1] [offsetX,0,0]))
)
else setVert theTriMesh v ((getVert theTriMesh v) * (matrix3 [1,0,0] [0,1,0] [0,0,1] [-offsetX,0,0]))
if (in coordsys grid getVert theTriMesh v).y > 0 then (
setVert theTriMesh v ((getVert theTriMesh v) * (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,offsetY,0]))
)
else setVert theTriMesh v ((getVert theTriMesh v) * (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,-offsetY,0]))
)
)
fn assignMatID theMesh IDnum = ( -- assign Material ID to each part of the mesh
for f = 1 to theMesh.numfaces do setFaceMatID theMesh f IDnum
)
fn transformMesh theTriMesh theMatrix = ( -- offset all vertex of each mesh to put it on top of the other
for v = 1 to theTriMesh.numverts do
setVert theTriMesh v ((getVert theTriMesh v)*theMatrix)
theTriMesh
)
fn deleteFacesLookingUpDown theTriMesh lookVect = ( -- delete duplicated and not needed faces
for vect in lookVect do (
for f = theTriMesh.numfaces to 1 by -1 do (
theNormal = getFaceNormal theTriMesh f
-- delete faces looking up/down
if acos(dot theNormal vect) == 0 do deleteFace theTriMesh f
)
)
)
rollout params1 "Creation Method" (
Radiobuttons creationMethod labels:#("Square","Rectangle") columns:2
)
rollout params2 "Column" (
group "Dimensions" (
spinner width "width" type:#worldUnits range:[0.0,1E9,1E-3]
spinner length "length" type:#worldUnits range:[0.0,1E9,1E-3]
spinner height "height" type:#worldUnits range:[0.0,1E9,1E-3]
spinner corRadius "corner Radius" type:#worldUnits range:[0.0,1E9,1E-3]
)
group "Wall base" (
spinner wbsHeight "height" type:#float range:[0.0,1E9,1E-3]
spinner wbsWidth "width" type:#float range:[0.0,1E9,1E-3]
)
group "Parameters" (
checkbutton radiosity "Radiosity" checked:false tooltip:"Increase number of polygons in column mesh"
)
)
rollout ak_ab "About" (
label lbl3 "(c) 2008" align:#left
label lbl4 "Fernando Ferro" align:#left
label lbl5 "[www.3dempire.com.ar]( http://www.3dempire.com.ar/ )" align:#left
label lbl6 "info@reconstruccionvirtual.com" align:#left
)
on buildMesh do (
if corRadius != 0.0 then ( -- has corner radius, so create cylinders
wallBaseMesh = createInstance cylinder heightsegs: 1 sides: 20 smooth:true realWorldMapSize: on
columnMesh = createInstance cylinder heightsegs: 1 sides: 20 smooth:true realWorldMapSize: on
)
else ( -- no corner radius, so just boxes
wallBaseMesh = createInstance box heightsegs: 1 widthsegs: 1 realWorldMapSize: on
columnMesh = createInstance box heightsegs: 1 widthsegs: 1 realWorldMapSize: on
)
-- create the cap an end meshes
groundMesh = createInstance box lengthsegs: 1 widthsegs: 1 height: 0.0 realWorldMapSize: on
ceilMesh = createInstance box lengthsegs: 1 widthsegs: 1 height: 0.0 realWorldMapSize: on
-- divide the column mesh to get a better radiosity solution
if radiosity == on then columnMesh.heightsegs = 5 else columnMesh.heightsegs = 1
wallBaseMesh.height = wbsHeight ; columnMesh.height = height - wbsHeight
if corRadius != 0.0 then ( -- define the radius of a circular shape
wallBaseMesh.radius = corRadius + wbsWidth / 2.0
columnMesh.radius = corRadius
)
else ( -- define the width an lenght of a rectangular shape
wallBaseMesh.width = (width + wbsWidth)
wallBaseMesh.length = (length + wbsWidth)
columnMesh.width = width
columnMesh.length = length
)
groundMesh.width = ceilMesh.width = (width + wbsWidth) * 1.1
groundMesh.length = ceilMesh.length = (length + wbsWidth) * 1.1
-- create temporal meshes to operate with its vertexs
tempMesh0 = groundMesh.mesh
tempMesh1 = wallBaseMesh.mesh
tempMesh2 = columnMesh.mesh
tempMesh3 = ceilMesh.mesh
assignMatID tempMesh0 3
assignMatID tempMesh1 4
assignMatID tempMesh2 5
assignMatID tempMesh3 6
deleteFacesLookingUpDown tempMesh0 #([0,0,-1])
deleteFacesLookingUpDown tempMesh1 #([0,0,-1])
deleteFacesLookingUpDown tempMesh2 #([0,0,1],[0,0,-1])
deleteFacesLookingUpDown tempMesh3 #([0,0,1])
tempMesh2 = transformMesh tempMesh2 (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,this.wbsHeight])
tempMesh3 = transformMesh tempMesh3 (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,this.height])
if corRadius != 0.0 do ( -- when it has corner radius, defines the offset in X and Y local axis
offsetX = width / 2.0 - corRadius
offsetY = length / 2.0 - corRadius
offsetHalfMesh tempMesh1 -- then move some vertexs
offsetHalfMesh tempMesh2
)
mesh = tempMesh0.mesh + tempMesh2.mesh + tempMesh1.mesh + tempMesh3.mesh
delete tempMesh0 -- delete temporal meshes
delete tempMesh1
delete tempMesh2
delete tempMesh3
)
tool create (
on mousePoint click do
case click of (
1: nodeTM.translation = gridPoint
6: #stop
)
on mouseMove click do
case click of (
2: (width = abs gridDist.x; length = abs gridDist.y)
3: height = abs gridDist.z
4: corRadius = abs gridDist.x
5: wbsHeight = abs gridDist.z
6: wbsWidth = abs gridDist.x
)
)
)
Thank you focomoso, but too much for me. In my language: “mucha arena para mi camioncito”
I’m involved in some arquitectural projects now but all modern style, so not needed …
But next step will be the creation of ceiling and floor meshes.
These would have the hole of each column, the outside delimited by a polyline, and with square faces only. Uhmm… not too easy.