Trunk Generator
MaxscriptJO00
plain_text
6 months ago
7.3 kB
6
Indexable
rollout bob_ross "Tree Maker" width:330 height:375
(
global tree_location=[0,0,0]
global arr_spline_for_del=#()
fn thisshape =
(
local sp = splineShape()
addnewSpline sp
addKnot sp 1 #corner #line [20,10,0]
addKnot sp 1 #corner #line [-20,11,0]
addKnot sp 1 #corner #line [-20,-11,0]
addKnot sp 1 #corner #line [20,-10,0]
close sp 1
updateShape sp
select sp
subobjectlevel = 1
setKnotSelection sp 1 #(1,4) keep:false
weldSpline sp 21.0
local knotCount = numknots sp
if (knotCount != 3) do
throw ("Spline should have 3 knots, found "+ (knotCount as string))
)
label 'lbl_bob_quote' "There are no mistakes, only happy accidents. bob ross" pos:[104,334] width:216 height:56 align:#left
pickButton 'btn_curve_tree_trunk' "Pick Curve here!" pos:[8,24] width:100 height:22 align:#left
pickButton 'btn_created_tree' "Slot_created_Tree_here" pos:[8,24] width:100 height:22 align:#left
spinner spin_tree_thickness "Thickness of Tree" align:#left pos:[64,100] range:[0,20,3]
button 'btn2' "make me that tree" pos:[64,136] width:192 height:26 align:#left
button 'btn3_del' "delete selected" pos:[64,166] width:192 height:26 align:#left
slider 'sld_wiggle' "Tree_Trunk_Wiggle" pos:[74,218] width:165 height:44 range:[0,1,1] align:#left ticks:3 type:#float
slider 'sld_height' "Tree_Trunk_Height" pos:[74,278] width:165 height:44 range:[0.1,1,1] align:#left ticks:3 type:#float
fn making_tr length_spline =
(
--local spline_make = splineShape()
spline_make=line transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] tree_location) isSelected:on
print"appended"
append arr_spline_for_del spline_make
--spline_make.pos=tree_location
spline_make.name="Tree Trunk"
--select spline_make
--actionMan.executeAction 0 "50001"
--select spline_make
addnewSpline spline_make
spline_make.render_renderable=true
spline_make.render_displayRenderMesh =true
spline_make.render_thickness=1.2*spin_tree_thickness.value
spline_make.render_sides=15
--spline_make.pos.x=
pos_trunk_point_1=spline_make.pos
--print sld_height.value as string
pos_trunk_point_2=[spline_make.pos.x+20*sld_wiggle.value,spline_make.pos.y,spline_make.pos.z+86*sld_height.value]
pos_trunk_point_3=[spline_make.pos.x+90*sld_wiggle.value,spline_make.pos.y,spline_make.pos.z+160*sld_height.value]
pos_trunk_point_4=[spline_make.pos.x+80*sld_wiggle.value,spline_make.pos.y-22,spline_make.pos.z+225*sld_height.value]
--print spline_make.pos as string
--print pos_trunk_point_2 as string
addKnot spline_make 1 #smooth #curve pos_trunk_point_1
addKnot spline_make 1 #smooth #curve pos_trunk_point_2
addKnot spline_make 1 #smooth #curve pos_trunk_point_3
addKnot spline_make 1 #corner #line pos_trunk_point_4
updateshape spline_make
weldSpline spline_make 6.0
print"made spline"
max modify mode
convertTo spline_make PolyMeshObject
subobjectLevel = 0
---making the trunk more and less thick depending on its scale
int_verts_total=polyop.getNumVerts spline_make
ring_count=int_verts_total/12
float_half_selection=ring_count/3*12 as integer
arr_vertext_to_select=#()
for i=1 to float_half_selection do
(
append arr_vertext_to_select i
)
print "done the append vertex select i"
subobjectLevel = 1
polyop.setVertSelection spline_make arr_vertext_to_select
spline_make.useSoftSel = on
spline_make.falloff=spline_make.max.z-spline_make.min.z
--print spline_make.falloff as string
spline_make.pinch=0.4
print"subobjected"
--subobjectLevel = 1
try
(
print"pushing mesh"
modPanel.addModToSelection (Push ()) ui:off
)
catch
(
print"failed to push"
)
--print spin_tree_thickness.value as string
spline_make.modifiers[#Push].Push_Value = spin_tree_thickness.value
print"modifier done"
convertTo spline_make PolyMeshObject
print"converted and alll"
--maxOps.CollapseNode spline_make ui:off
--spline_make.EditablePoly.SetSelection #Vertex #{arr_vertext_to_select}
--now selecting the very bottom and pushing it a bit more plus it again
print"selecting the very bottom and pushing it a bit more plus it again"
arr_vertext_to_select=#()
for i=1 to 12 do
(
append arr_vertext_to_select i
)
polyop.setVertSelection spline_make arr_vertext_to_select
spline_make.useSoftSel = on
spline_make.falloff=(spline_make.max.z-spline_make.min.z)*1.5
--spline_make.pinch=0.4
subobjectLevel = 1
modPanel.addModToSelection (Push ()) ui:off
spline_make.modifiers[#Push].Push_Value = spin_tree_thickness.value*2.5
convertTo spline_make PolyMeshObject
--maxOps.CollapseNode spline_make ui:off
print"selecting bottom"
polyop.setVertSelection spline_make arr_vertext_to_select
--spline_make.useSoftSel = on
--spline_make.falloff=(spline_make.max.z-spline_make.min.z)/4
--spline_make.pinch=0.4
subobjectLevel = 1
modPanel.addModToSelection (Push ()) ui:off
spline_make.modifiers[#Push].Push_Value = spin_tree_thickness.value*3
subobjectLevel = 0
convertTo spline_make Editable_Poly
--convertToMesh spline_make
--maxOps.CollapseNode spline_make ui:off
print "complete all"
)
fn making_trunk splineinput =
(
print"starting"
tree_location=getKnotPoint splineinput 1 1
splineinput.render_renderable=true
splineinput.render_displayRenderMesh =true
--print splineinput.render_length as string
float_length=splineinput.render_length
print"doing float length"
if float_length<10 then
(
float_length=12
print float_length as string
--print"spline too short lengthing"
)
--print Tree_Trunk.render_useViewportSettings as string
making_tr(float_length)
print"deciding length"
--Tree_Trunk.pos=[20,0,0]
)
on btn_curve_tree_trunk picked picked_item do
(
try
(
if classof picked_item == Line then
(
--print" its a line"
btn_curve_tree_trunk.text="Picked "+picked_item.name as string
)
else
(
btn_curve_tree_trunk.object=undefined
)
)
catch
(
print"did nottt work oops"
)
)
on btn_curve_tree_trunk rightclick do
(
btn_curve_tree_trunk.text="Pick Curve here!"
btn_curve_tree_trunk.object=undefined
)
on btn2 pressed do
(
try
(
spline_picked=btn_curve_tree_trunk.object
--print spline_picked as string
if spline_picked!=undefined do
(
print spline_picked as string
making_trunk(spline_picked)
)
--thisshape()
)
catch
(
print "Nothing is selected! Trying again"
delete arr_spline_for_del[1]
arr_spline_for_del=#()
try
(
spline_picked=btn_curve_tree_trunk.object
--print spline_picked as string
if spline_picked!=undefined do
(
print spline_picked as string
making_trunk(spline_picked)
)
)
catch
(
print"Failure again"
delete arr_spline_for_del[1]
arr_spline_for_del=#()
)
)
)
on btn3_del pressed do
(
try
(
for obj in getCurrentSelection() do
(
delete obj
)
)
catch
(
print "couldnt delete for some reason"
)
)
)
CreateDialog bob_rossEditor is loading...
Leave a Comment