try (destroydialog igorznag_path_lookat) catch()
rollout igorznag_path_lookat "Chain. Path. LookAt."
(
--gui
radiobuttons rb_cs "" labels:#("Count:", "Spacing:") pos:[5,5] columns:1
spinner sp_count "" range:[2,1e9,10] fieldWidth:60 type:#integer pos:[65,5]
spinner sp_spacing "" range:[0,1e9,0] fieldWidth:60 type:#worldunits pos:[65,22]
checkbox chb_taf "Flip. Object LookAt Axis = X" pos:[5,42]
radiobuttons rb_stoa "Object Upnode Axis" labels:#("Y", "Z") pos:[5,60]
checkbox chb_stoaf "Flip" pos:[80,77]
label lbl_info "Spline Upnode Axis = Z" pos:[5,95]
button btn_apply "Apply" pos:[140,60] width:60 height:50
button btn_update "Update" pos:[145,10]
--functions
fn update_cs =
(
if(selection.count==2)then
(
spline_path=undefined; obj=undefined;
spline_types=#(SplineShape,line);cl1=classof selection[1];cl2=classof selection[2]
if(finditem spline_types cl1!=0 and finditem spline_types cl2==0)then
(spline_path=selection[1];obj=selection[2])
if(finditem spline_types cl2!=0 and finditem spline_types cl1==0)then
(spline_path=selection[2];obj=selection[1])
if(spline_path!=undefined)then
(
if numSplines spline_path==1 then
(
spline_length=0; sl_a=getSegLengths spline_path 1
if(sl_a.count>0)then spline_length=sl_a[sl_a.count]
if rb_cs.state==1 then sp_spacing.value=1.0*spline_length/sp_count.value
if rb_cs.state==2 then
(
if(sp_spacing.value>0)then
(
v=int(1.0*spline_length/sp_spacing.value)
if v<2 then v=2; sp_count.value=v
)--if(sp_spacing.value>0)then
else sp_count.value=2
)--if rb_cs.state==2 then
)--if numSplines spline_path==1 then
)--if(spline_path!=undefined)then
)--if(selection.count==2)then
)--fn update_cs =
--events
on btn_apply pressed do
(
if(selection.count==2)then
(
spline_path=undefined; obj=undefined;
spline_types=#(SplineShape,line);cl1=classof selection[1];cl2=classof selection[2]
if(finditem spline_types cl1!=0 and finditem spline_types cl2==0)then
(spline_path=selection[1];obj=selection[2])
if(finditem spline_types cl2!=0 and finditem spline_types cl1==0)then
(spline_path=selection[2];obj=selection[1])
if(spline_path!=undefined)then
(
if numSplines spline_path==1 then
(
undo on
(
with animate off
(
objs_temp_a=#(); objs_count=sp_count.value
script_continue=true
if objs_count>1000 then script_continue=queryBox "Continue?" title:"Count is a big number!"
if(script_continue==true)then
(
for i=1 to objs_count do
(
maxOps.cloneNodes obj cloneType:#instance newNodes:&n
append objs_temp_a n[1];
)--for i=1 to objs_count do
d=undefined
for i=1 to objs_temp_a.count do
(
if i==1 then
(
objs_temp_a[i].pos.controller = Path_Constraint()
c=objs_temp_a[i].pos.controller; c.path=spline_path
c.percent.controller=bezier_float();
setBeforeORT c.percent.controller #cycle
setAfterORT c.percent.controller #cycle
--
d=dummy();d.pos.controller=Path_Constraint()
c=d.pos.controller;c.path=spline_path
setBeforeORT c.percent.controller #cycle
setAfterORT c.percent.controller #cycle
c.percent.controller = float_script()
c.percent.controller.AddObject "obj1_percent" objs_temp_a[1].pos.controller.percent.controller
c.percent.controller.script="obj1_percent.value"
)--if(i==1)then
if i>1 then
(
objs_temp_a[i].pos.controller=Path_Constraint()
c=objs_temp_a[i].pos.controller;c.path=spline_path
setBeforeORT c.percent.controller #cycle
setAfterORT c.percent.controller #cycle
c.percent.controller = float_script()
c.percent.controller.AddObject "obj1_percent" objs_temp_a[1].pos.controller.percent.controller
c.percent.controller.script="obj1_percent.value+"+(((1.0/objs_count)*(i-1)) as string)
)--if i>1 then
objs_temp_a[i].rotation.controller = LookAt_Constraint();
c=objs_temp_a[i].rotation.controller
c.target_axis=0;c.lookat_vector_length=0;c.target_axisFlip=chb_taf.checked
objs_temp_a[i].rotation.controller.upnode_world = off
objs_temp_a[i].rotation.controller.pickUpNode=spline_path
c.upnode_ctrl=1;c.StoUP_axis=rb_stoa.state;c.StoUP_axisFlip=chb_stoaf.checked;
c.upnode_axis=2
if(i<objs_temp_a.count)then c.appendTarget objs_temp_a[i+1] 100
if(i==objs_temp_a.count)then c.appendTarget d 100
)--for i=1 to objs_temp_a.count do
select objs_temp_a; selectMore d
redrawViews()
)--if(script_continue==true)then
)--with animate off
)--undo off
)--if numSplines spline_path==1then
)--if(spline_path!=undefined)then
)--if(selection.count==2)then
)--on btn_apply pressed do
--
on igorznag_path_lookat open do
(
sp_spacing.enabled=false
update_cs()
)--on igorznag_path_lookat open do
--
on rb_cs changed arg do
(
sp_count.enabled=true;sp_spacing.enabled=true
if(arg==1)then sp_spacing.enabled=false
if(arg==2)then sp_count.enabled=false
update_cs()
)--on rb_cs changed arg do
--
on sp_count entered do update_cs()
on sp_spacing entered do update_cs()
on btn_update pressed do update_cs()
); createdialog igorznag_path_lookat 210 115