//============================================================================= // // le_file_io.mel - handles all file io for the level editor // //============================================================================= //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Load the native Maya formatted file in that contains the level data global proc le_load_file (string $file, string $type) { global int $le_file_lock_status; global string $le_current_file; global string $le_dialog_name; string $a, $ret; if ($file == "") { string $path = `workspace -q -dir` + "*.led"; $file = `fileDialog -dm $path`; if ($file == "") return; } $a = `match "\\.led" $file`; if (`strcmp $a ".led"`) $file += ".led"; // release a prior lock // le_unlock_current_file(); string $f_lock = `substitute "\\.led" $file ".lock"`; string $user_id1[] = `GetUserID(0)`; string $user_id2[] = `GetUserID(1)`; int $file_id; $le_current_file = $f_lock; file -f -new; /* // does it exist? if (`filetest -f $f_lock` == 0) { // no, create it and save current user's data int $file_id = `fopen $f_lock "w"`; fwrite $file_id ($user_id1[0] + "\r\n" + $user_id2[0] + "\r\n" + $user_id1[1] + "\r\n" + $user_id1[2] + "\r\n"); fclose $file_id; } file -f -new; $file_id = `fopen $f_lock "r"`; if ($file_id == 0) { // error, set to read only $le_file_lock_status = 0; $ret = `confirmDialog -message ("Error locking file\n" + "Do you want to load file\n" + "for reading only?") -button "Read only" -button "Cancel" -dismissString "Close"`; if ($ret == "Cancel" || $ret == "Close") return; } else { string $fdata, $fstrings[]; $fdata = `fread $file_id $fdata`; fclose $file_id; tokenize $fdata "\r\n" $fstrings; if ($fstrings[0] == $user_id1[0]) $le_file_lock_status = 1; else { $le_file_lock_status = 0; $ret = `confirmDialog -message ("File is locked by '" + $fstrings[0] + "'\n" + "AKA '" + $fstrings[1] + "'\n" + "time: " + $fstrings[2] + "\n" + "date: " + $fstrings[3] + "\n\n" + "Do you want to load file\n" + "for reading only?") -button "Read only" -button "Cancel" -dismissString "Close"`; if ($ret == "Cancel" || $ret == "Close") return; } } */ le_delete_all_layers(); file -i -type mayaAscii $file; // load all object icons le_load_all_objects(); string $name = le_get_name ($le_current_file); $name = `substitute "\\.lock" $name ""`; string $title = "Level Editor: " + $name; window -edit -title $title $le_dialog_name; string $path = `le_get_path ($file)`; // set proper path in project source "setProject.mel"; sp_setLocalWorkspaceCallback ($path, "directory"); workspace -dir $path; le_fix_workspace(); select -cl; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // global proc le_fix_workspace() { workspace -rt "sourceImages" "textures;../../Art/textures/LED_textures;../../Art/textures;"; setAttr "perspShape.farClipPlane" 100000; setAttr "topShape.farClipPlane" 100000; setAttr "sideShape.farClipPlane" 100000; setAttr "frontShape.farClipPlane" 100000; setAttr "perspShape.nearClipPlane" 1; setAttr "topShape.nearClipPlane" 1; setAttr "sideShape.nearClipPlane" 1; setAttr "frontShape.nearClipPlane" 1; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Unlock selected file global proc le_unlock_file (string $file, string $type) { global int $le_file_lock_status; global string $le_current_file; string $a; if ($file == "") { string $path = `workspace -q -dir` + "*.led"; $file = `fileDialog -dm $path`; if ($file == "") return; } $a = `match "\\.led" $file`; if (`strcmp $a ".led"`) $file += ".led"; string $f_lock = `substitute "\\.led" $file ".lock"`; string $user_id1[] = `GetUserID(0)`; string $user_id2[] = `GetUserID(1)`; int $file_id; // does it exist? if (`filetest -f $f_lock` == 0) confirmDialog -message "File wasn't locked\nso no action was taken." -button "OK"; else { // yes is it ours? $file_id = `fopen $f_lock "r"`; if ($file_id != 0) { string $fdata, $fstrings[]; $fdata = `fread $file_id $fdata`; fclose $file_id; tokenize $fdata "\r\n" $fstrings; if ($fstrings[0] == $user_id1[0]) { sysFile -del $f_lock; if ($f_lock == $le_current_file) $le_file_lock_status = 0; } else confirmDialog -message ("'" + $fstrings[0] + "' has it locked,\n'" + $user_id1[0] + "' (you) don't.\n\nSo no action taken!\n") -button "OK"; } } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& global proc le_unlock_current_file() { global int $le_file_lock_status; global string $le_current_file; // check a prior lock if ($le_file_lock_status == 1) { // release lock sysFile -del $le_current_file; $le_file_lock_status = 0; } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Save the level data as a Maya formatted file global proc le_save_file (string $file, string $type) { global int $le_file_lock_status; global string $le_current_file; le_create_layers(); string $a, $ret; if ($file == "") { string $path = `workspace -q -dir` + "*.led"; $file = `fileDialog -dm $path`; if ($file == "") fileBrowser ( "le_save_file", "Save", "led", 1); if ($file == "") return; } $a = `match "\\.led" $file`; if (`strcmp $a ".led"`) $file += ".led"; /* if (`filetest -f $file` != 0 && $le_file_lock_status == 0) { confirmDialog -message ("No can do!!!\n" + "This file was originally\n" + "loaded as read-only or\n" + "you've already released the lock.\n\n" + "So no action taken!\n") -button "OK"; return; } else { string $f_lock = `substitute "\\.led" $file ".lock"`; // is it different than the loaded file and does a lock exist for that? if ($f_lock != $le_current_file && `filetest -f $f_lock` != 0) { confirmDialog -message "No can do!!!\nThat's a different filename\nand someone has a lock on it.\n\nSo no action taken!\n" -button "OK"; return; } // here if it didn't exist before if (`filetest -f $f_lock` == 0) { string $user_id1[] = `GetUserID(0)`; string $user_id2[] = `GetUserID(1)`; // no, create it and save current user's data int $file_id = `fopen $f_lock "w"`; fwrite $file_id ($user_id1[0] + "\r\n" + $user_id2[0] + "\r\n" + $user_id1[1] + "\r\n" + $user_id1[2] + "\r\n"); fclose $file_id; if ($le_file_lock_status == 0) { $le_current_file = $f_lock; $le_file_lock_status = 1; } } } */ if (`filetest -f $file` != 0) { // here if it exists if (`filetest -w $file` == 0) { // here if it's not writable confirmDialog -message ("No can do!!!\n\n" + "You must check out the file first and then save.\n" + "Then check it back in when you're done.\n\n" + "No action taken!\n") -button "OK"; return; } } // copy current selection $le_current_selection = `ls -selection`; // move the nasty reference objects away from their parent nodes le_unparent_all_ref_namespaces(); select -clear; select -add `editDisplayLayerMembers -fn -q Zones`; select -add `editDisplayLayerMembers -fn -q Objects`; select -add `editDisplayLayerMembers -fn -q Cameras`; select -add `editDisplayLayerMembers -fn -q AI`; // and from that list, get only the good stuff le_deselect_unwanted_objects(); file -exportSelected -type mayaAscii -constructionHistory true -channels true -expressions false -constraints false -shader false -defaultExtensions false -uiConfiguration false $file; // restore ref_ objects le_reparent_all_ref_groups(); // restore selection select $le_current_selection; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Writes out text form of level data (on its way to the parser) global proc le_export (string $file, string $type) { int $fn, $flag, $object_index, $sound_index, $fauna_dna; string $ext, $sect_type; string $cr = "\r\n"; // DOS carriage return string $attr, $pairs[], $values[]; string $type, $out, $path, $zone, $tzone, $bare_file, $level_file, $dat_file; float $pos[], $quat[], $scale[], $mat[]; string $object, $all[], $zones[]; global string $le_icon_dir; if ($file == "") { $path = `workspace -q -dir` + "*.level"; $file = `fileDialog -dm $path`; if ($file == "") fileBrowser ( "le_export", "Save", "level", 1); if ($file == "") return; } $ext = `match "\\.level" $file`; if (`strcmp $ext ".level"`) $file += ".level"; string $filepath = `le_get_path ($file)`; int $size1, $size2; $size1 = size ($filepath) + 1; $size2 = size ($file); // strips out the path string $bare_file = `substring $file $size1 $size2`; $size1 = size ($bare_file) - 6; // bare file $bare_file = `substring $bare_file 1 $size1`; $dat_file = $bare_file + ".dat"; $level_file = $bare_file + ".level"; // copy current selection $le_current_selection = `ls -sl`; $fn = `file -q -ex $file`; // if it doesn't exist then all is well if ($fn == 0) $fn = 1; else $fn = `filetest -w $file`; if ($fn == 0) { // check it out system ("spawn_it.bat save_level.bat " + $level_file); $fn = `filetest -w $file`; } if ($fn) { $fn = fopen ($file, "w"); fprint ($fn, ".include ../../Art/LED_icons/led_defs.cmd\r\n"); fprint ($fn, ".include ../../Art/LED_icons/uberbits.cmd\r\n"); fprint ($fn, $cr); fprint ($fn, "// level header\r\n"); if (`objExists header_object`) { $attr = le_get_attributes ("header_object"); $pairs = le_pairs_from_attr ($attr); $values = le_values_from_pairs ($pairs, "level_name"); fprint ($fn, "LEVEL_NAME \"" + $values[0] + "\"" + $cr); $values = le_values_from_pairs ($pairs, "map_name"); fprint ($fn, "MAP_NAME \"" + $values[0] + "\"" + $cr); $values = le_values_from_pairs ($pairs, "minimap_name"); fprint ($fn, "MINIMAP_NAME \"" + $values[0] + "\"" + $cr); $values = le_values_from_pairs ($pairs, "skydome1"); fprint ($fn, "SKYDOME1 \"" + $values[0] + "\"" + $cr); $values = le_values_from_pairs ($pairs, "skydome2"); fprint ($fn, "SKYDOME2 \"" + $values[0] + "\"" + $cr); // world modifying values $values = le_values_from_pairs ($pairs, "far_clip"); fprint ($fn, "FAR_CLIP_PLANE " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "near_clip"); fprint ($fn, "NEAR_CLIP_PLANE " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "fog_near"); fprint ($fn, "FOG_NEAR_PLANE " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "fog_red"); fprint ($fn, "FOG_COLOR_RED " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "fog_green"); fprint ($fn, "FOG_COLOR_GREEN " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "fog_blue"); fprint ($fn, "FOG_COLOR_BLUE " + $values[0] + $cr); $values = le_values_from_pairs ($pairs, "level_bank"); fprint ($fn, "SOUND_BANK \"" + $values[0] + "\"" + $cr); $values = le_values_from_pairs ($pairs, "music"); fprint ($fn, "MUSIC_DEFAULT \"" + $values[0] + "\"" + $cr); fprint ($fn, $cr); } else { fprint ($fn, "FAR_CLIP_PLANE 400.0\r\n"); fprint ($fn, "FOG_NEAR_PLANE 300.0\r\n"); fprint ($fn, "FOG_COLOR_RED 0\r\n"); fprint ($fn, "FOG_COLOR_GREEN 0\r\n"); fprint ($fn, "FOG_COLOR_BLUE 0\r\n"); fprint ($fn, $cr); fprint ($fn, "SOUND_BANK \"levelbank\"\r\n"); fprint ($fn, "MUSIC_DEFAULT \r\n"); fprint ($fn, "MUSIC_2 \r\n"); fprint ($fn, "MUSIC_3 \r\n"); fprint ($fn, $cr); } if (`objExists "start_camera"`) { $pos = le_fix_pos (`getAttr ("start_camera.translate")`); fprint ($fn, "CAMERA_START_POSITION " + $pos[0] + " " + $pos[1] + " " + $pos[2] + $cr); fprint ($fn, $cr); } if (`objExists "start_target"`) { $pos = le_fix_pos (`getAttr ("start_target.translate")`); fprint ($fn, "CAMERA_START_TARGET " + $pos[0] + " " + $pos[1] + " " + $pos[2] + $cr); fprint ($fn, $cr); } $all = `ls -sn -transforms`; $object_index = 0; $sound_index = 0; float $progress = 0; float $num_items = `size ($all)`; window -widthHeight 280 10 -tb 0 -s 0 statusWindow; frameLayout -bs out -lv 0 ffLay; floatScrollBar -m 1 -width 280 -height 10 -min 0 -max ($num_items*1.2) -value 0 -step 1 statusScroll2; showWindow statusWindow; for ($object in $all) { $progress += 1; floatScrollBar -e -max ($num_items*1.1/$progress) statusScroll2; $attr = le_get_attributes ($object); if ($attr != "") { global string $le_event_data[]; $pairs = le_pairs_from_attr ($attr); $out = ""; switch ($pairs[0]) { case "object": case "camera": { $type = le_find_param_in_pairs ($pairs, "type"); $pos = le_fix_pos (`getAttr ($object + ".translate")`); $scale = le_fix_values (`getAttr ($object + ".scale")`); $mat = le_fix_mat (`getAttr ($object + ".worldMatrix")`); if ((`strcmp $type "insta_fixed_cam"` == 0) || (`strcmp $type "parented_fixed_cam"` == 0) || (`strcmp $type "fixed_cam"` == 0) || (`strcmp $type "al_cam"` == 0) || (`strcmp $type "al_insta_fixed"` == 0) || (`strcmp $type "directional_cam"` == 0) || (`strcmp $type "directional_climb_cam"` == 0) || (`strcmp $type "2dscroll_cam"` == 0)) { $mat[0] = -$mat[0]; $mat[1] = -$mat[1]; $mat[2] = -$mat[2]; $mat[8] = -$mat[8]; $mat[9] = -$mat[9]; $mat[10] = -$mat[10]; } $quat = le_fix_values (ExtractMatQuat ($mat, $scale)); // output entity type and name $out += "// #" + $object_index + " " + $pairs[0] + " " + le_short_name ($object) + $cr; $object_index++; // print ($out); if ($type == "") $out += "OBJECT_BLOCK \"\" $(obj_normal_object)" + $cr; else $out += "OBJECT_BLOCK \"" + $type + "\" $(obj_normal_object)" + $cr; $out += "OBJ_NAME " + $object + $cr; $out += "OBJ_POS " + $pos[0] + " " + $pos[1] + " " + $pos[2] + $cr; $out += "OBJ_QUAT " + $quat[0] + " " + $quat[1] + " " + $quat[2] + " " + $quat[3] + $cr; // tack on the event data if ($pairs[0] == "object") { $le_event_data = le_values_from_pairs ($pairs, "events"); $out += le_build_event_export_data(); } $zone = le_find_param_in_pairs ($pairs, "zone"); // see if zone still exists if ($zone != "" && `objExists $zone`) { $flag = 0; for ($tzone in $zones) { if (`strcmp $zone $tzone` == 0) { $flag = 1; break; } } if ($flag == 0) { $out += le_build_collision_data ($object, $zone); $zones[size($zones)] = $zone; } else { $out += "// zone " + le_short_name ($zone) + $cr; $out += "COLL_REF " + le_short_name ($zone) + $cr; } } break; } case "world_object": { string $world_obj = le_find_param_in_pairs ($pairs, "world_obj"); $type = le_find_param_in_pairs ($pairs, "type"); // not really needed but send anyway $pos = le_fix_pos (`getAttr ($object + ".translate")`); // output entity type and name $out += "// #" + $object_index + " " + $pairs[0] + " " + le_short_name ($object)+ $cr; $object_index++; // print ($out); $out += "WORLD_OBJ_BLOCK \"" + $world_obj + "\" $(obj_world_object)" + $cr; $out += "OBJ_NAME " + $object + $cr; $out += "OBJ_POS " + $pos[0] + " " + $pos[1] + " " + $pos[2] + $cr; break; } case "sound_object": { // output entity type and name $out += "// #" + $sound_index + " " + $pairs[0] + " " + le_short_name ($object) + $cr; $sound_index++; $values = le_values_from_pairs ($pairs, "type"); string $old_parent[] = `listRelatives -p $object`; // make sure we have real world data if ($old_parent[0] != "") parent -w $object; $pos = le_fix_pos (`getAttr ($object + ".translate")`); if ($old_parent[0] != "") parent -a $object $old_parent[0]; $values = le_values_from_pairs ($pairs, "snd_name"); $out += "SOUND_EFFECT " + $values[0] + $cr; $values = le_values_from_pairs ($pairs, "snd_type"); $out += "SND_TYPE $(" + $values[0] + ")" + $cr; $out += "SND_POS " + $pos[0] + " " + $pos[1] + " " + $pos[2] + $cr; $values = le_values_from_pairs ($pairs, "inner_vol"); $out += "SND_FULLVOL " + $values[0] + $cr; $values = le_values_from_pairs ($pairs, "outer_vol"); $out += "SND_FALLOFF " + $values[0] + $cr; $out += "SND_NAME " + le_short_name ($object) + $cr; break; } case "path": { $out += le_export_path ($object); break; } } if ($out != "") { $out += $cr; fprint ($fn, $out); } } } // now do all of the leftover zones for ($zone in $all) { $attr = le_get_attributes ($zone); if ($attr != "") { $pairs = le_pairs_from_attr ($attr); $out = ""; switch ($pairs[0]) { case "zone": { // see if zone still exists if ($zone != "" && `objExists $zone`) { $flag = 0; // see if this one needs to be exported for ($object in $zones) { if (`strcmp $object $zone` == 0) { $flag = 1; break; } } if ($flag == 0) $out = le_build_collision_data ("", $zone); } } } if ($out != "") { $out += $cr; fprint ($fn, $out); } } } floatScrollBar -e -max 1.1 statusScroll2; // now see if there's a merge file string $merge_file = le_get_path ($file); $merge_file += "/merge.me"; if (`file -q -exists $merge_file`) { int $fn2 = `fopen $merge_file "r"`; if ($fn2) { $out = `fgetline $fn2`; int $len; while (size ($out) > 0) { $len = size ($out) - 1; if ($len == 0) $out = ""; else $out = `substring $out 1 $len`; $out += $cr; fprint ($fn, $out); $out = `fgetline $fn2`; } fclose ($fn2); } } fclose ($fn); floatScrollBar -e -max 1.0 statusScroll2; deleteUI statusWindow; // now crunch system ("spawn_it.bat build_level.bat " + $level_file + " " + $dat_file + " exit pause"); } // restore selection select $le_current_selection; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Convert pos to left hand coords global proc float[] le_fix_pos (float $values[]) { if (size ($values) == 3) $values[0] = -$values[0]; return le_fix_values ($values); } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Convert matrix to left hand coords global proc float[] le_fix_mat (float $values[]) { /* if (size ($values) == 16) { $values[0] = -$values[0]; $values[4] = -$values[4]; $values[8] = -$values[8]; } */ return le_fix_values ($values); } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Fix values global proc float[] le_fix_values (float $values[]) { int $val, $idx = 0; float $value; for ($value in $values) { $values[$idx] = le_fix_value ($value); $idx++; } return $values; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Fix value global proc float le_fix_value (float $value) { return trunc ($value * 10000) / 10000; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Build collision data global proc string le_build_collision_data (string $object, string $zone) { string $cr = "\r\n"; // DOS carriage return string $attr, $pairs[], $values[]; string $type, $out, $path, $col_type; float $pos[], $quat[], $scale[], $mat[]; if ($object != "") { $attr = le_get_attributes ($object); $pairs = le_pairs_from_attr ($attr); $type = le_find_param_in_pairs ($pairs, "type"); $pos = le_fix_pos (`getAttr ($object + ".translate")`); $scale = le_fix_values (`getAttr ($object + ".scale")`); $mat = le_fix_mat (`getAttr ($object + ".worldMatrix")`); $quat = le_fix_values (ExtractMatQuat ($mat, $scale)); $col_type = "OBJ_COLLISION"; } else $col_type = "COLLISION"; string $zattr, $zpairs[], $ztype; string $local_or_world = "WORLD"; float $zpos[], $zquat[], $zscale[], $zmat[]; int $i; $zattr = le_get_attributes ($zone); $zpairs = le_pairs_from_attr ($zattr); // output entity type and name $out = "// " + $zpairs[0] + " " + le_short_name ($zone) + $cr; string $old_parent[] = `listRelatives -p $zone`; // make sure we have real world data if ($old_parent[0] != "") { // see if object one of the parents string $sel[] = `ls -long $zone`; string $tokens[]; // make it into a hierarchy tokenize $sel[0] "|" $tokens; // find object in list for ($i=(size($tokens)-1); $i>=0; $i--) { if (`strcmp $tokens[$i] $object` == 0) break; } if ($i != -1) { if ($object != $old_parent[0]) parent -a $zone $object; $local_or_world = "LOCAL"; } else parent -w $zone; } $zpos = le_fix_pos (`getAttr ($zone + ".translate")`); $zscale = le_fix_values (`getAttr ($zone + ".scale")`); $zmat = le_fix_mat (`getAttr ($zone + ".xformMatrix")`); $zquat = le_fix_values (ExtractMatQuat ($zmat, $zscale)); if ($old_parent[0] != "") { if ($object != $old_parent[0]) parent -a $zone $old_parent[0]; } int $pos_flag, $rot_flag; if ($local_or_world == "LOCAL" && abs ($zpos[0]) < .001 && abs ($zpos[1]) < .001 && abs ($zpos[2]) < .001) $pos_flag = 0; else $pos_flag = 1; if ($zquat[0] == 0 && $zquat[1] == 0 && $zquat[2] == 0 && $zquat[3] == 1) $rot_flag = 0; else $rot_flag = 1; $ztype = le_find_param_in_pairs ($zpairs, "type"); switch ($ztype) { // COL_RADIUS case "sphere": if ($pos_flag) { $out += $col_type + " COL_RADIUS_POS " + $local_or_world + $cr; $out += "COLL_POS " + $zpos[0] + " " + $zpos[1] + " " + $zpos[2] + $cr; } else { $out += $col_type + " COL_RADIUS " + $local_or_world + $cr; } $out += "COLL_RADIUS " + le_fix_value (getAttr ($zone + ".scaleX")) + $cr; break; // COL_CYLINDER case "cylinder": if ($pos_flag == 0 && $rot_flag == 0) { $out += $col_type + " COL_CYLINDER " + $local_or_world + $cr; } else if ($pos_flag == 1 && $rot_flag == 0) { $out += $col_type + " COL_CYLINDER_POS " + $local_or_world + $cr; $out += "COLL_POS " + $zpos[0] + " " + $zpos[1] + " " + $zpos[2] + $cr; } else if ($pos_flag == 0 && $rot_flag == 1) { $out += $col_type + " COL_CYLINDER_ROT " + $local_or_world + $cr; $out += "COLL_QUAT " + $zquat[0] + " " + $zquat[1] + " " + $zquat[2] + " " + $zquat[3] + $cr; } else { $out += $col_type + " COL_CYLINDER_ROT_POS " + $local_or_world + $cr; $out += "COLL_POS " + $zpos[0] + " " + $zpos[1] + " " + $zpos[2] + $cr; $out += "COLL_QUAT " + $zquat[0] + " " + $zquat[1] + " " + $zquat[2] + " " + $zquat[3] + $cr; } $out += "COLL_RADIUS " + $zscale[0] + $cr; $out += "COLL_HEIGHT " + abs ($zscale[1] * 0.5) + $cr; break; // COL_BOX case "box": if ($pos_flag == 0 && $rot_flag == 0) { $out += $col_type + " COL_BOX " + $local_or_world + $cr; } else if ($pos_flag == 1 && $rot_flag == 0) { $out += $col_type + " COL_BOX_POS " + $local_or_world + $cr; $out += "COLL_POS " + $zpos[0] + " " + $zpos[1] + " " + $zpos[2] + $cr; } else if ($pos_flag == 0 && $rot_flag == 1) { $out += $col_type + " COL_BOX_ROT " + $local_or_world + $cr; $out += "COLL_QUAT " + $zquat[0] + " " + $zquat[1] + " " + $zquat[2] + " " + $zquat[3] + $cr; } else { $out += $col_type + " COL_BOX_ROT_POS " + $local_or_world + $cr; $out += "COLL_POS " + $zpos[0] + " " + $zpos[1] + " " + $zpos[2] + $cr; $out += "COLL_QUAT " + $zquat[0] + " " + $zquat[1] + " " + $zquat[2] + " " + $zquat[3] + $cr; } $out += "COLL_SCALE " + abs ($zscale[0] * .5) + " " + abs ($zscale[1] * .5) + " " + abs ($zscale[2] * .5) + $cr; break; } $out += "COLL_NAME " + le_short_name ($zone) + $cr; return $out; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Remove path data from all textures in currently loaded file proc le_fix_textures (string $file) { string $obj, $path, $new_path, $obj_attr; string $tex[] = `ls -tex`; string $attrs[]; for ($obj in $tex) { $attrs = `listAttr $obj`; string $attr_type; int $flag = false; for ($attr_type in $attrs) { if ($attr_type == ".fileTextureName") { $flag = true; break; } } if ($flag == false) continue; $obj_attr = $obj + ".fileTextureName"; $path = `getAttr ($obj_attr)`; int $len = size ($path); int $i; for ($i=$len; $i>=1; $i--) { string $c = `substring $path $i $i`; if (`match $c "\\/:"` == $c) break; } $i++; $new_path = `substring $path $i $len`; // set texture path to just the texture name itself setAttr ($obj_attr) -type "string" $new_path; } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Return path portion of a file global proc string le_get_path (string $file) { int $len = size ($file); int $i; for ($i=$len; $i>=1; $i--) { string $c = `substring $file $i $i`; if (`match $c "\\/:"` == $c) break; } string $path = `substring $file 1 $i`; return $path; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Return file name portion of a file global proc string le_get_name (string $file) { int $len = size ($file); int $i; for ($i=$len; $i>=1; $i--) { string $c = `substring $file $i $i`; if (`match $c "\\/:"` == $c) break; } string $name = `substring $file ($i+1) ($i+100)`; return $name; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Clear then import a Maya world and set proper project directories global proc le_load_world (string $file, string $type) { if ($file == "") { string $path = `workspace -en ..`; int $len = `size $path`; $path = `substring $path 1 ($len-3)` + "/*.mb"; $file = `fileDialog -dm $path`; if ($file == "") return; } file -import -groupReference -type mayaBinary $file; // select -cl; // $path = `le_get_path ($file)`; // set proper path in project // source "setProject.mel"; // sp_setLocalWorkspaceCallback ($path, "directory"); // workspace -dir $path; // workspace -rt "sourceImages" "textures;../textures;../../textures;"; // fix all textures // le_fix_textures ($file); // setAttr "perspShape.farClipPlane" 100000; // setAttr "topShape.farClipPlane" 100000; // setAttr "sideShape.farClipPlane" 100000; // setAttr "frontShape.farClipPlane" 100000; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Import (load) a reference object global proc le_load_ref_object (string $parent_obj, string $ref_namespace, string $path) { global string $le_icon_dir; // string $load_path = ($le_icon_dir + $path); string $load_path = ($path); if ($load_path == "" || `file -q -exists $load_path` == false) return; string $attr, $pairs[]; int $zone_flag = true; // if is exists, get a new one if (le_check_namespace ($ref_namespace)) { $ref_namespace = le_get_unique_namespace(); string $ref_path = $ref_namespace + "," + $path; $attr = le_get_attributes ($parent_obj); if ($attr != "") le_set_attr_from_param ($parent_obj, "path", $ref_path); } //------------------------------------------------------------------------- string $parent_attr = le_get_attributes ($parent_obj); string $parent_pairs[] = le_pairs_from_attr ($parent_attr); // mark if we need to load a zone here if ($parent_attr != "") { string $old_zone[] = le_values_from_pairs ($parent_pairs, "zone"); string $values[], $ref_zone; $values = le_values_from_pairs ($parent_pairs, "path"); $ref_zone = $values[0] + ":zone"; if (`match ":zone" $old_zone[0]` == ":zone" && $old_zone[0] != $ref_zone) { le_set_attr_from_param ($parent_obj, "zone", $ref_zone); $old_zone[0] = $ref_zone; } if (`objExists $old_zone[0]`) $zone_flag = false; } // search through database and look for an existing one string $ref_copy = le_find_ref_instance ($path); string $temp_group[]; if ($ref_copy != "") { namespace -add $ref_namespace; namespace -set $ref_namespace; $temp_group = `duplicate -rr $ref_copy`; namespace -set ":"; // now just get a name and use that for the ref group's name string $get_a_name = `group -empty`; delete $get_a_name; rename $temp_group[0] $get_a_name; $temp_group[0] = $get_a_name; // get another group so that we can make the group relative to origin again string $rel_group = `group -empty`; parent -r $temp_group[0] $rel_group; parent -w $temp_group[0]; delete $rel_group; } else { print ("\n" + $load_path + "\n"); file -import -type "mayaBinary" -groupReference -renameAll true -namespace $ref_namespace $load_path; $temp_group[0] = `le_get_group_node ($ref_namespace)`; } string $object[] = `listRelatives -children $temp_group[0]`; string $sub_obj; // make a new group in the desired namespace namespace -set (":"+$ref_namespace); string $ref_group = `group -empty -name $ref_namespace`; // attach it to le_object parent -r $ref_group $parent_obj; // back to normal namespace namespace -set ":"; // go through all children of node created at load time for ($sub_obj in $object) { string $attr = le_get_attributes ($sub_obj); if ($attr != "") // we found an le object, see what it is { string $pairs[] = le_pairs_from_attr ($attr); if ($pairs[0] == "zone") // we found a zone, rename it and put it in zone layer { if ($parent_attr != "") { if ($zone_flag == false) continue; le_set_attr_from_param ($parent_obj, "zone", $sub_obj); } // assign to zone layer select -r $sub_obj; // set zone's target object string $p_name[] = `ls -sn $parent_obj`; le_set_attr_from_param ($sub_obj, "object", $p_name[0]); layerEditorAddObjects Zones; } } parent -r $sub_obj $ref_group; } // delete temporary parent delete $temp_group; } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Load all objects global proc le_load_all_objects() { // add layers if necessary le_create_layers(); if (`layerButton -exists Objects` ) { select -cl; select -add `editDisplayLayerMembers -fn -q Objects`; string $obj; for ($obj in `selectedNodes`) { string $attr = le_get_attributes ($obj); if ($attr != "") { string $pairs[] = le_pairs_from_attr ($attr); string $ref_path[] = le_values_from_pairs ($pairs, "path"); le_load_ref_object ($obj, $ref_path[0], $ref_path[1]); } } } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Reparent all ref_ objects global proc le_reparent_all_ref_groups() { // add layers if necessary le_create_layers(); if (`layerButton -exists Objects` ) { select -cl; select -add `editDisplayLayerMembers -fn -q Objects`; string $sel[]; int $sel_size; // what is selected $sel = `ls -sl`; if (`size ($sel)` != 0) { string $obj; for ($obj in `selectedNodes`) { string $attr = le_get_attributes ($obj); if ($attr != "") { string $pairs[] = le_pairs_from_attr ($attr); string $ref_path[] = le_values_from_pairs ($pairs, "path"); string $ref_group = ($ref_path[0] + ":" + $ref_path[0]); if (`objExists $ref_group`) parent $ref_group $obj; } } } } } //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // // Load and build the uberbit selection menu global proc le_load_uber_bits() { global string $le_uber_bits[]; global string $le_icon_dir; int $i, $file, $index; string $line, $tokens[], $chr, $data, $fname; $fname = $le_icon_dir + "/uberbits.cmd"; $file = `fopen $fname "r"`; clear $le_uber_bits; if ($file) { $index = 0; $line = `fgetline $file`; while (size ($line) > 0) { $data = ""; if (`substring $line 1 2` == "//") $line = ""; // first look for 'folder' or 'end' tokenize $line "# \r\n\t" $tokens; if (size ($tokens) > 0 && $tokens[0] == "folder") { // found a folder start $le_uber_bits[$index++] = "folder_start"; if (size ($tokens) == 1) $le_uber_bits[$index++] = "no folder name"; else { for ($i=1; $i 0 && $tokens[0] == "end") { // found a folder end $le_uber_bits[$index++] = "folder_end"; } for ($i=1; $i 1 && $tokens[0] != "#") $le_uber_bits[$index++] = $tokens[0]; $line = `fgetline $file`; } fclose $file; } }