it seems all of u guys know what maxscript is all about!
wish i could be like one of u someday…Amen
iam an undergraduate student and i have my project involving maxscript
i tried fulfilling some tasks in maxscript ,some were made well and many were only to waste my time…my project needs simulation of “people walking in street randomly”
i tried watching some tutorials to handle this simulation using “crowd-bipes”
however…i didnt get many tips besides not finding what i want exactly
i have tried to handle crowd of delegates before, and i thought that “crowd of delegates” script may only need some changes to fit crowd of bipes ,but i couldn’t figure out these changes!
i only started learning maxscript since 2 months…so do u think u can help me?
this is the script of “delegates following some leader”…hope u can turn it to “bipes walking randomly”.
animationRange = interval animationRange.start 150f
(
local switcher = off
local theRolloutFloater
local Test
local Custom_Leader
local TheFrame
local TheSurface
local Arr_Obstacles
local Arr_Delegates
local TheTarget
local C
local Leader
local Sur
local Distribution_Object
local Del
local Obstacles
local Simulation
local Leader_Proxy
local Environment_Setup
local assin_01
local assin_02
local assin_03
local team_01
----Functions -----
Fn TicksToFrames TheFrame =
(
–This Function Changes Ticks to frames NO matter what Frame rate is Pal , NTSC , Film …etc
(TheFrame as integer/TicksPerFrame)
)
/*
this function creates the Crowd helper , the behaviors and the teams
/
Fn MakeTheCrowd Num_Of_Delegates Frames =
(
Try( Delete $Delegate ; Delete $First_Crowd* ; )Catch()
delegate width:6 depth:9 height:6 xyconstraint:false WireColor:Red
– Constructing the Crowd Helper !
C = crowd name:“First_Crowd” pos:[320,150,0] IconSize:50 SolveEnd:Frames
C.scatter.positionspace = 3
C.scatter.positionobject = $TheSphere
C.scatter.cloneobject = $delegate01
C.scatter.numclones = Num_Of_Delegates - 1
C.scatter.clonetype=0
crowds.genclones C
crowds.genlocations C
Arr_Delegates = $Delegate* as array
C.deleteKeys = true
–surface follow behavior
TheSurfaceFollow_Behavior = Surface_Follow_Behavior name:“SurfaceFollow”
Append TheSurfaceFollow_Behavior.Surfaces TheSurface
append C.Behaviors TheSurfaceFollow_Behavior
–seek behavior
TheSeekTarget_Behavior = Seek_Behavior name:“Seek_Target”
Append TheSeekTarget_Behavior.targets TheTarget
append C.Behaviors TheSeekTarget_Behavior
–avoid behavior
TheAvoid_Behavior = Avoid_Behavior name:“Avoid_Delegates&Obstacles”
for i in Arr_Delegates do (Append TheAvoid_Behavior.Obstacles i)
if Arr_Obstacles != undefined do for i in Arr_Obstacles do (Append TheAvoid_Behavior.Obstacles i)
TheAvoid_Behavior.HardRadius = 0.4
TheAvoid_Behavior.LookAhead = 40
append C.behaviors TheAvoid_Behavior
team_01 =CrowdTeam()
team_01.name = “All_Delegate”
team_01.members = Arr_Delegates
append C.teams team_01
assin_01 = crowdassignment team:team_01 behavior:TheSeekTarget_Behavior active:true
append C.assignments assin_01
assin_02 = crowdassignment team:team_01 behavior:TheSurfaceFollow_Behavior active:true
append C.assignments assin_02
assin_03 = crowdassignment team:team_01 behavior:TheAvoid_Behavior active:true
append C.assignments assin_03
)
/*
–this function creates a plane adds a noise and bend modifier and collapse the stack
–then it selects an edge and extract a path
–a leader is generated and assigned the path as path constraint
–then it generates and aligns obstacles according to the number of obstacles
–if an obstacle is not aligned properly by intersectray it gets deleted
*/
fn autoEnvironment numobstacles theColor switcher = (
try(
SuspendEditing()
resetMaxFile #noPrompt – due to scope limitation a max reset was decided !
ResumeEditing()
)catch()
P = converttopoly(Plane width:250 length:500 lengthsegs:40 widthsegs:40)
N = NoiseModifier()
N.Fractal = true
addModifier P N
N.Strength.z = 50
B = Bend()
addmodifier P B
B.angle = -180 ; B.BendAxis = 0
B2 = Bend Angle: -90 BendAxis:1 ; addmodifier P B2
collapsestack p
polyop.setEdgeSelection P 160
P.EditablePoly.SelectEdgeLoop ()
P.EditablePoly.createShape “thePath” on P
if switcher == off then S = sphere radius:10 wirecolor:theColor else s = Box length:10 width:10 height:10 wirecolor:theColor
pc = path_constraint()
S.pos.Controller = pc
pc.path = $thePath
for i = 1 to numobstacles do (
theBox = box length:(random 5 10) width:(random 5 10) height:(random 5 10) Name:(uniquename “Obstacle_01”); CenterPivot theBox
theBox.wirecolor = (random white gray)
theBox.pos = [(random P.min.x P.max.x) , (random P.min.y P.max.y) , (random P.min.z P.max.z)]
in coordsys local (theBox.rotation.x = random 1 180 ; theBox.rotation.y = random 1 180; theBox.rotation.z = random 1 180)
theRay = ray theBox.pivot [theBox.pos.X,theBox.pos.Y,-50000]
theintersection = intersectray P theRay ; print theintersection
if theintersection != undefined then theBox.pos = theintersection.pos else delete theBox
redrawviews()
)
)
– UI Configurateion
–these are set of rollouts and their event handlers made separatly and then added to a rollout floater
–if the user chooses to AutoEnvironment an additional rollout is created to give the options
–simple rollout to choose auto or manual creation of the environment
rollout Mode “Environment Mode”
(
Group “Mode”
(
radioButtons rdo1 “” labels:#(“Manual”,"Auto_Environment ") default:1 columns:1 Align:#Center
)
on rdo1 changed item do
(
if item == 1 then
(
for i in theRolloutFloater.Rollouts do if i != Mode do removerollout i theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater
)
else
(
for i in theRolloutFloater.Rollouts do if i != Mode do removerollout i theRolloutFloater
–addrollout Leader_Proxy theRolloutFloater
addrollout Environment_Setup theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater
)
)
)
–environment options
rollout Environment_Setup “Environment_Setup”
(
Group “Obstacles”
(
Spinner No_Obstacles “Up To” type:#integer range:[1,1000000,40] Align:#Center
)
Group “Leader”
(
dropDownList ddl1 width:100 height:40 items:#(“Sphere”, “Box”) align:#left across:2
colorPicker cp1 “” width:20 height:20 color:(color 255 0 0) align:#right across:2
)
Button Btn_Env “Generate Envoronment” ali:#center
on ddl1 selected item do
(
if item == 2 then switcher = on else switcher = off
)
on Btn_Env pressed do autoEnvironment NO_Obstacles.value cp1.color switcher
)
– the leader rollout … this rollout provides a button to choose the leader
rollout Leader “Leader”
(
Group “Leader”
(
PickButton PB_Leader “Pick The Leader !” Align:#Center AutoDisplay:true
)
on PB_Leader Picked obj do
(
if obj != undefined do TheTarget = obj
)
)
–the surface rollout … this rollout provides a button to choose the Surface
rollout Sur “Surface”
(
Group “Surface”
(
Pickbutton PB_Surface “Pick The Surface !” Align:#Center AutoDisplay:true
)
on PB_Surface Picked obj do
(
if obj != undefined do TheSurface = obj
)
)
–distribution rollout … proper values for autoEnvironment is x = - 130 and y = -240
rollout Distribution_Object “Distribution Object”
(
Group “Distribution Object”
(
Button Btn_Help “?” Across:2 align:#left
Button Btn_SphereDistribution “Create The Object” Across:2 align:#Right
Spinner Spin_Radius “Radius” type:#Float range:[0.001,1000000,40] Align:#Center enabled:false
Spinner Spin_Xpos “Position X” type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
Spinner Spin_Ypos “Position Y” type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
Spinner Spin_Zpos “Position Z” type:#Float range:[-1000000,1000000,0] Align:#Center enabled:false
)
on Btn_Help pressed do
(
MessageBox "This is a Distribution Sphere meant to Distribute the Delegates initially
ControlThe Radius and Position for best Sim Environment "
)
on Btn_SphereDistribution pressed do
(
Try(Delete $TheSphere*)Catch()
Sphere name:“TheSphere” pos:[0,0,0] segments:40 radius:40
Spin_Radius.enabled = true
Spin_Xpos.enabled = true
Spin_Ypos.enabled = true
Spin_Zpos.enabled = true
)
on Spin_Radius changed val do ($TheSphere.Radius = Spin_Radius.Value)
on Spin_Xpos Changed val do ($TheSphere.Position.X = Spin_Xpos.Value)
on Spin_Ypos Changed val do ($TheSphere.Position.Y = Spin_Ypos.Value)
on Spin_Zpos Changed val do ($TheSphere.Position.Z = Spin_Zpos.Value)
)
–number of delegates to follow the leader
rollout Del “Delegates”
(
Group “Delegates”
(
Spinner Spin_NumDelegates “No. Delegates” type:#integer range:[1,50000000,10] align:#center
)
)
–this rollout provides a method to choose the obstacles
rollout Obstacles “Obstacles”
(
Group “Obstacles”
(
Button Btn_PickObstacles “>> Select Obstacles <<” width:(Obstacles.width - 20) Align:#Center
Label lab_01 “No. Obstacles = 0”
)
on Btn_PickObstacles Pressed do
(
max tool hlist
if (Selection.Count == 0 ) then (lab_01.text = "No Obstacles Assigned ")
else (
Arr_Obstacles = Selection as array
lab_01.text = "No. Obstacles = " + Selection.count as string
)
)
on Btn_Help pressed do
(
MessageBox "This is a Distribution Sphere meant to Distribute the Delegates initially
ControlThe Radius and Position for best Sim Environment "
)
)
–Simulation rollout … self explanatory
rollout Simulation “Simulation”
(
Group “Simulation”
(
Spinner Spin_Frames “Frames” type:#integer range:[1,TicksToFrames AnimationRange.End,TicksToFrames AnimationRange.End] align:#center
Button Btn_Solve “Solve” Width:(Simulation.width - 40) Height:30
)
on Btn_Solve pressed do
(
if (TheSurface !=undefined and TheTarget !=undefined and $TheSphere != undefinde) Then
(
MakeTheCrowd Del.Spin_NumDelegates.Value Spin_Frames.Value
Crowds.Solve C
)
else (MessageBox "Please Fill The Parameters First ")
)
)
theRolloutFloater= newrolloutfloater “Crowd_Solver” 180 200
addrollout Mode theRolloutFloater
addrollout Leader theRolloutFloater
addrollout Sur theRolloutFloater
addrollout Distribution_Object theRolloutFloater
addrollout Del theRolloutFloater
addrollout Obstacles theRolloutFloater
addrollout Simulation theRolloutFloater
)