Notifications
Clear all

[Closed] Updating morphs

Hi guys,

I developed a script to update morphs. This was neeeded since many a times in the workflow of our projects, the expressions did not look right and this was realised during animation time. This script just provides an interface to update morphs in the scene. I need your feedback on this.

Regards,
Vikram


(
  global mstrobj = #()
 global obj_names = #() 
  if obj_names == undefined do obj_names = #() 
 global flname 
 global sel_obj
 global sel_obj_arr = #()
 global switch = false
 global flag=0
 global active_targets = #()
 global target_names = #()
 global changed = 0
 global active_slot = 0
 global doesExist = 0
 global alreadyExist = 0
 
 rollout updateMorphmain "Update Morpher" 
  (
   pickbutton pcbtn1 "Pick Master Object (object with morphs)" width:210
  button btn_selmax "Select Max file with correct morph(s)" width:210
   listbox lbx_objects "Objects:" items:obj_names 
   button btn_merge "Merge Selected node and update" width:210
  button btn_add "Add Selected New Morph" width:210
	
   on pcbtn1 picked obj do
  (
   clearselection()
   if obj != undefined do
   (
	pcbtn1.text = obj.name
	select obj
   )
   mstrobj = (getCurrentSelection())[1]
   if (mstrobj.modifiers[#morpher] == undefined)
   then
   (
	messagebox "Error! Object does not have a morpher modifier" beep:true
	 mstrobj = #()
	pcbtn1.text = "Pick Master Object"
   )
   
  ) 
  
  on btn_selmax pressed do
   (
	flname = getopenFileName caption:"Load Morph File"
	if flname != undefined do 
	(
	 obj_names = getmaxfileobjectnames flname 
	 lbx_objects.items = obj_names  
	
	 )
   )
  
  on btn_merge pressed do
  (
   sel_obj = lbx_objects.selected
   append sel_obj_arr sel_obj
   if sel_obj_arr.count > 1
   then deleteItem sel_obj_arr 1
   mergeMAXFile flname sel_obj_arr
   --execute  ("select $" + sel_obj_arr[1])
   
   for i =1 to 100 do
   (
	switch = WM3_MC_HasTarget mstrobj.morpher i 
	if switch == true 
	then 
	(
	 append active_targets (WM3_MC_GetName mstrobj.morpher i)
	)
   ) 
 
   for i = 1 to active_targets.count do
   (
	if sel_obj_arr[1] == active_targets[i]
	then 
	(
	 messagebox "Morph to be replaced already exists in scene"
	 flag = flag+1
	)
   )
   
   if (flag == 0) then
   (
	for i=1 to 100 do
	(
	 append target_names (WM3_MC_GetName mstrobj.morpher i)
	)
	
	for i=1 to 100 do
	(
	 if ((sel_obj_arr[1] == target_names[i]) and ((execute ("$" + sel_obj_arr[1])).vertices.count != mstrobj.vertices.count))
	 then
	 (
	  messagebox "The morph you want to replace does not have the same no. of vertices as the Master object"
	  doesExist = doesExist + 1
	 )
	 else if ((sel_obj_arr[1] == target_names[i]) and ((execute ("$" + sel_obj_arr[1])).vertices.count != mstrobj.vertices.count))
	 then
	 (
	  WM3_MC_BuildFromNode mstrobj.morpher i (execute ("$" + sel_obj_arr[1]))
	  doesExist = doesExist + 1
	 )
	)
	
	if (doesExist == 0) then
	(
	 messagebox "Morph to be replaced does not exist in Master object"
	)  
   )
   
   delete (execute ("$" + sel_obj_arr[1]))
   sel_obj_arr = #()
   switch = false
   flag=0
   active_targets = #()
   doesExist = 0
   target_names = #()

  )
  on btn_add pressed do
  (
   sel_obj = lbx_objects.selected
   append sel_obj_arr sel_obj
   if sel_obj_arr.count > 1
   then deleteItem sel_obj_arr 1
   mergeMAXFile flname sel_obj_arr
   
   for i = 1 to 100 do
   (
	switch = WM3_MC_HasData mstrobj.morpher i 
	if switch == true 
	then
	(
	 append active_targets (WM3_MC_GetName mstrobj.morpher i)
	)
   ) 
 
   for i = 1 to active_targets.count do
   (
	if sel_obj_arr[1] == active_targets[i]
	then 
	(
	 messagebox "Morph to be added already exists in scene"
	 flag = flag+1
	)
   )
   
   for i=1 to 100 do
   (
	if (sel_obj_arr[1] == target_names[i])
	then
	(
	 alreadyExist = alreadyExist + 1
	)
   )
   if (alreadyExist > 0) then
   (
	messagebox "Morph to be added already exists in Master object"
	flag = flag+1
   )  
   
   if (flag == 0) then
   (
	
	if ((execute ("$" + sel_obj_arr[1])).vertices.count != (mstrobj.vertices.count))
	then
	(
	 messagebox "The morph you want to add does not have the same no. of vertices as the Master object"
	)
	else
	(
	 active_slot = 1
	 while (WM3_MC_HasData mstrobj.morpher active_slot) == true do
	 (
	  active_slot += 1
	 )
	 WM3_MC_BuildFromNode mstrobj.morpher active_slot (execute ("$" + sel_obj_arr[1]))
	) 
   )
   delete (execute ("$" + sel_obj_arr[1]))
   sel_obj_arr = #()
   switch = false
   flag=0
   active_slot=0
   active_targets = #()
   alreadyExist = 0
   target_names = #()
  ) 
 
  )
  
 rollout abt "About" rolledUp:true
 (
  label ablb1 "Developed by Vikram Shingrani" 
  hyperLink gmail "email : [email="http://forums.cgsociety.org/vshingrani@gmail.com"]vshingrani@gmail.com[/email]" color:(color 0 0 255) address:"[email="http://forums.cgsociety.org/vshingrani@gmail.com"]vshingrani@gmail.com[/email]" align:#center
 )
 myfloater = (newRolloutFloater "Update Morphs" 360 320)
 addRollout updateMorphmain myfloater
 addRollout abt myfloater
)