Скрипт взят http://www.plemasson.fr/tools.html
Скрипт запускается, но Не понятно как он работает
Скрипт запускается, но Не понятно как он работает
Код:
num_iteration = 4
max_iteration = 100
num_bourgeon = 4
current_iteration = 0
num_objetSize = 100.00
num_currentSize
ratio = 1.0/2.2
kovalenceList=#()
chaos_scale = 0
chaos_angle = 0
offset_angle = #(0,0,0)
lockedID = false
lockedVColor = false
lockedOffsetRatio = false
colorIteration = 0
colorBranching = 0
fn VertexColorOverride obj = --function that change all vertex color of an object
(
nVerts = obj.GetNumVertices()--number of vertex in the Epoly
vertexSet = #{1..(nVerts)}--vertex list of the Epoly
obj.EditablePoly.setSelection #Vertex vertexSet --selection of all vertex
vertexList = obj.EditablePoly.GetSelection(2)
obj.SetVertexColor obj.wireColor 0 --set the vertex color on channel 0
)
fn PolygonIDOverride obj = --function that change all ID of an object
(
nPoly = obj.getNumFaces()--number of polygone in the poly
polySet = #{1..(nPoly)} --polyList of the Epoly
polyop.setFaceMatID obj polySet ((current_iteration + 1) as Integer) -- change the polyID
)
fn ScaleMoveRotateTint obj parentObj numName numNode = --apply the scale, the offset, the random rotation, the tint, and maybe the ID overriding
(
--create the random and offset rotation
obj.parent = parentObj
rotation_angle = eulerangles ((random -chaos_angle chaos_angle) + offset_angle[1]) ((random -chaos_angle chaos_angle) +offset_angle[2]) ((random -chaos_angle chaos_angle) + offset_angle[3])
rand_ratio = random -chaos_scale chaos_scale
mf = num_objetSize * (1+ ratio) --offset value for the new node
if lockedOffsetRatio do
(
mf = num_objetSize * (1+ ratio + rand_ratio) --offset value for nodes
)
in coordsys local rotate obj rotation_angle --random rotation
in coordsys local move obj [0, 0, mf] --moving
greenValue = (numName * colorBranching)
rg = current_iteration / num_iteration as Float
--print ("rg : " + (rg as String))
greenValue = (parentObj.wireColor.g * rg) + (greenValue *(1.0- rg))
in coordsys local scale obj [ratio + rand_ratio, ratio + rand_ratio, ratio + rand_ratio] --scale
obj.wireColor = color (colorIteration * (current_iteration + 1)) greenValue 128 --tint
obj.name = ("fractObj_"+(current_iteration as String)+"_"+(numNode as String)+"_"+(numName as String)) --rename
--changing object ID ?
if lockedID do
(
PolygonIDOverride obj
)
--changing VertexColor
if lockedVColor do
(
VertexColorOverride obj
)
)
fn KochIterate localObjetList = --recurcive function to clone objects
(
newObjectList=#() --temporary list of nodes
for j = 1 to localObjetList.count do
(
clonedObject = localObjetList[j] --take the current node
name_increment = 0 -- reset of name numeration
if num_bourgeon == 3 or num_bourgeon == 4 or num_bourgeon == 5 or num_bourgeon == 1 do
(
d = copy clonedObject
ScaleMoveRotateTint d clonedObject name_increment j
join newObjectList #(d)
name_increment += 1
)
if num_bourgeon == 2 do
(
d1 = copy clonedObject
rotation_angle = eulerangles 90 0 0
in coordsys local rotate d1 rotation_angle
ScaleMoveRotateTint d1 clonedObject name_increment j
join newObjectList #(d1)
name_increment += 1
d2 = copy clonedObject
rotation_angle = eulerangles 270 0 0
in coordsys local rotate d2 rotation_angle
ScaleMoveRotateTint d2 clonedObject name_increment j
join newObjectList #(d2)
name_increment += 1
)
if num_bourgeon == 3 do --creation of left and right oriented nodes
(
d1 = copy clonedObject
rotation_angle = eulerangles 0 120 0
in coordsys local rotate d1 rotation_angle
ScaleMoveRotateTint d1 clonedObject name_increment j
join newObjectList #(d1)
name_increment += 1
d2 = copy clonedObject
rotation_angle = eulerangles 0 240 0
in coordsys local rotate d2 rotation_angle
ScaleMoveRotateTint d2 clonedObject name_increment j
join newObjectList #(d2)
name_increment += 1
)
if num_bourgeon == 4 do --creation of tripode oriented nodes
(
for i = 1 to 3 do
(
d = copy clonedObject
rotation_angle = eulerangles 0 0 (120 * i)
in coordsys local rotate d rotation_angle
rotation_angle = eulerangles 0 120 0
in coordsys local rotate d rotation_angle
ScaleMoveRotateTint d clonedObject name_increment j
join newObjectList #(d)
name_increment += 1
)
)
if num_bourgeon == 5 do --creation of quadripode oriented nodes
(
for i = 1 to 4 do
(
d = copy clonedObject
rotation_angle = eulerangles 0 0 (90 * i)
in coordsys local rotate d rotation_angle
rotation_angle = eulerangles 0 90 0
in coordsys local rotate d rotation_angle
ScaleMoveRotateTint d clonedObject name_increment j
join newObjectList #(d)
name_increment += 1
)
)
if num_bourgeon == 6 do --creation of 6 oriented nodes
(
for i = 1 to 3 do
(
for h = 1 to 2 do
(
d = copy clonedObject
rotation_angle = eulerangles 0 0 (120 * i + h*60)
in coordsys local rotate d rotation_angle
rotation_angle = eulerangles 0 (90 * (h-1) + 30) 0
in coordsys local rotate d rotation_angle
ScaleMoveRotateTint d clonedObject name_increment j
join newObjectList #(d)
name_increment += 1
)
)
)
)
current_iteration += 1
num_currentSize *= ratio
--print ("taille courante : " + (num_currentSize as String))
--print ("iteration numero : " + (current_iteration as String))
if current_iteration < num_iteration do -- if there is still iteration level, relaunch the fractalize function on the new array
(
tempArray = deepCopy newObjectList
KochIterate tempArray
)
)
fn ScanObject = --keep the first editable poly of the selection
(
for obj in selection do
(
if classof obj.baseObject == Editable_Poly do --if the selected obj is an editable poly
(
--print "loop de scan objet"
kovalenceList[1] = obj
obj.wireColor = color 0 0 128
num_currentSize = num_objetSize
current_iteration = 0
colorIteration = 255.0 / num_iteration as Float
colorBranching = 255.0 / num_bourgeon as Float
if lockedID do
(
maxOps.CollapseNode obj on
--set the ID
PolygonIDOverride obj
)
if lockedVColor do --init vertexColorModifier (R : iteration age, G : Node id)
(
maxOps.CollapseNode obj on
--set the vertex Color
VertexColorOverride obj
)
KochIterate kovalenceList --launch iteration on the first object
exit
)
)
)
rollout Koch "Koch Object V 1.1 -- by Pierre Lemasson"
(
group "basics parameters"
(
spinner Iteration "fractal iteration" range:[0,max_iteration,num_iteration] type:#integer
spinner Bourgeon "number of nodes" range:[1, 6, num_bourgeon] type:#integer
spinner tailleObjet "basic object size" range:[-1000,1000,num_objetSize] type:#float
)
group "growing parameters"
(
spinner ratioDeDivision "scale divider" range:[0.1, 8, 2.2] type:#float
spinner chaosScale "chaos scale" range:[0,1,chaos_scale] type:#float
spinner chaosRotation "chaos angle" range:[0,360,chaos_angle] type:#float
checkbox constrainOffset "constrain offset with chaos ratio"
)
group "offset rotation"
(
spinner offsetRotationX "offset angle X" range:[-180,180,offset_angle[1]] type:#float
spinner offsetRotationY "offset angle Y" range:[-180,180,offset_angle[2]] type:#float
spinner offsetRotationZ "offset angle Z" range:[-180,180,offset_angle[3]] type:#float
)
group "dynamic overriding of IDs and UV"
(
edittext IDText fieldWidth:275 height:36 bold:false labelOnTop:false readOnly:true
text:"This option override polygon IDand branching ID\r\n(WARNING, collapse all modifiers)"
checkbox overrideID "overriding IDs"
edittext VColorText fieldWidth:275 height:62 bold:false labelOnTop:false readOnly:true
text:"This option set vertex color from the current iteration\r\nand branching ID (WARNING, collapse all modifiers and\r\nnot avialable before 3DSmax 2010) - Red is iteration\n\rlevel and Green is branching ID"
checkbox overrideVColor "overriding vertexColor"
)
button Koch "Clonage fractal" width:180
on Iteration changed val do num_iteration = val
on Bourgeon changed val do num_bourgeon = val
on tailleObjet changed val do num_objetSize = val
on chaosScale changed val do chaos_scale = val
on chaosRotation changed val do chaos_angle = val
on offsetRotationX changed val do offset_angle[1] = val
on offsetRotationY changed val do offset_angle[2] = val
on offsetRotationZ changed val do offset_angle[3] = val
on ratioDeDivision changed val do ratio = (1.0 / val)
on overrideID changed theState do lockedID = theState
on overrideVColor changed theState do lockedVColor = theState
on constrainOffset changed theState do lockedOffsetRatio = theState
on Koch pressed do ScanObject()
)
createDialog Koch 310 510