3Ds Max 가지 만드는 코드
3D max code를 활용하여 가지를 만드는 코드를 제작하였다. 이는 책의 내용을 참고하였으며 코드는 다음과 같다.
Code to Create 3Ds Max Branches
Using 3D max code, we made a code to make branches. It refers to the contents of the book and the code is as follows.
result
utility Branching "Branching"
(
global rootTree
global branchesArray=#
()
--Parameters
--Branch Shape
global trunkHeight=200
global trunkRadius=2
global trunkSides=12
global taperingFactorMin=0.4
global taperingFactorMax=0.6
--Branching
global branchingDepth=5
global branchingNumberMin=4
global branchingNumberMax=8
--Offset/Translation
global offsetFactorMin=0.0
global offsetFactorMax=0.5
--Unfolding/Rotation
global branchingXAngleMin=10
global branchingXAngleMax=15
global branchingZAngleMin=2
global branchingZAngleMax=6
--Height/Scale
global heightFactorMin=0.2
global heightFactorMax=0.8
group "Branch Shape"
(
spinner trunkHeight_spinner "Height: "type
:#worldunits range
:[0.0001,100000
,trunkHeight]toolTip:"Initial Trunk Height"
spinner trunkRadius_spinner "Radius: "type
:#worldunits range
:[0.0001,100000
,trunkRadius]toolTip:"Initial Trunk Radius (at base)"
spinner trunkSides_spinner "Sides: "type
:#integer range
:[3,36
,trunkSides]toolTip:"Number of Sides"
spinner taperingFactorMin_spinner "Taper Min: "type
:#float range
:[0.0,1.0
,taperingFactorMin]
toolTip:"Minimum Tapering Factor"
spinner taperingFactorMax_spinner"Taper Max: "type
:#float range
:[0.0,1.0
,taperingFactorMax]
toolTip:"Maximum Tapering Factor"
)
group "Branching"
(
spinner branchingDepth_spinner "Depth: "type
:#integer range
:[1,100000
,branchingDepth]
toolTip:"total recursion steps"
spinner branchingNumberMin_spinner "Min: "type
:#integer
ramge:[0,100000
,branchingNumberMin]
toolTip: "Minimum number to branch out at each step"
spinner branchingNumberMax_spinner "Max:"type
:#integer range
:[0,100000
,branchingNumberMax]
toolTip: "Maximum number to branch out at each step"
)
group"Offset/Translation"
(
spinner offsetFactorMin_spinner"Min:"
tpye:#float range
:[0.0,100000
,heightFactorMin]toolTip:"Minimum distance offset factor to slide child along parent"
spinner offsetFactorMax_spinner "Max: "type
:#float range
:[0.0,100000
,heightFactorMax]
toolTip:"Maximum distance offset factor to slide child along parent"
)
group "Unfolding/Rotation"
(
spinner branchingXAngleMin_spinner "X Min: "type
:#float range
:[0,360
,branchingXAngleMin]
toolTip: "Minimum X rotation angle of each branch"
spinner branchingXAngleMax_spinner "X Max: "type: #float range
:[0,360
,branchingXAngleMax]
toolTip: "Maximum X rotation angle of each branch"
spinner branchingZAngleMin_spinner "Z Min: "type: #float range
:[0,360
,branchingZAngleMin]
toolTip: "Minimum Z additional Z rotation angle offset"
spinner branchingZAngleMax_spinner "Z Max: "type: #float range
:[0,360
,branchingZAngleMax]
toolTip: "Maximum additional Z rotation angle offset"
)
group "Height/Scale"
(
spinner heightFactorMin_spinner "Scale Min: "type: #float range
:[0.0,100000
,heightFactorMin]
toolTip: "Minimum scale factor of child to parent"
spinner heightFactorMax_spinner "Scale Max: "type: #float range: [0.0,100000
,heightFactorMax]
toolTip:"Maximum scale factor of child to parent"
)
button generate_button "Generate" enabled
:true
fn branch parent depth =
(
if(depth<
branchingDepth)then
(
numberOfBranches=
(random
branchingNumberMin branchingNumberMax)
for i = 1 to
numberofBranches do
(
myBranch = copy parent
myBranch.parent = parent
myBranch.height=
(parent
.height
)*
(random
heightFactorMin heightFactorMax)
myBranch.radius1 = parent
.radius2
myBranch.radius2 = myBranch.radius1*(random taperingFactorMin taperingFactorMax)
in coordsys parent move
myBranch [0,0
,parent
.height]
myRot =
eulerAngles (random
branchingXAngleMin branchingXAngleMax) 0 0
in coordsys parent rotate
myBranch myRot
myRot = eulerAngles 0 0 (((360/numberOfBranches)*i)+(random branchingZAngleMin branchingZAngleMax))
in coordsys parent rotate
myBranch myRot
in coordsys parent move
myBranch [0,0
,((random
offSetFactorMin offSetFactorMax)*-parent
.height)]
myBranch.wirecolor= (color
(255-(255/branchingDepth*depth)) 0 0)
append branchesArray myBranch
branch myBranch (depth + 2)
)
)
)
fn deleteTree anArry=
(
for i = 1 to
branchesArray.count by 1 do
(
if(isDeleted branchesArray[i] == false) then
(
delete branchesArray[i]
)
)
branchesArray.count=0
)
on generate_button pressed do
(
deleteTree branchingArray
rootTree = cone
()
rootTree.height =
trunkHeight
rootTree.radius1=
trunkRadius
rootTree.radius2 = rootTree.radius1*(random taperingFactorMin taperingFactorMax)
rootTree.sides =
trunkSides
rootTree.heightsegs = 1
rootTree.wirecolor = (color 0 255 0)
append branchesArray rootTree
branch rootTree 1
)
on trunkHeight_spinner changed
amt do
(
trunkHeight =
amt
)
on trunkRadius_spinner changed
amt do
(
trunkRadius =
amt
)
on trunkSides_spinner changed
amt do
(
trunkSides =
amt
)
on taperingFactorMin_spinner changed
amt do
(
taperingFactorMin =
amt
)
on taperingFactorMax_spinner changed
amt do
(
taperingFactorMax =
amt
)
on branchingDepth_spinner changed
amt do
(
branchingDepth =
amt
)
on branchingNumberMin_spinner changed
amt do
(
branchingNumberMin =
amt
)
on branchingNumberMax_spinner changed
amt do
(
branchigNumberMax=
amt
)
on offsetFactorMin_spinner changed
amt do
(
offsetFactorMin =
amt
)
on offsetFactorMax_spinner
changedd amt do
(
offsetFactorMax =
amt
)
on branchingXAngleMin_spinner changed
amt do
(
branchingXAngleMin =
amt
)
on branchingXAngleMax_spinner changed
amt do
(
branchingXAngleMax =
amt
)
on branchingZAngleMin_spinner changed
amt do
(
branchingZAngleMin =
amt
)
on branchingZAngleMax_spinner changed
amt do
(
branchingZAngleMax =
amt
)
on heightFactorMin_spinner changed
amt do
(
heightFactorMin =
amt
)
on heightFactorMax_spinner changed
amt do
(
heightFactorMax =
amt
)
)