Changeset 965 for AE/packages/31000GlassBreakingMoves/patches/common/level0_Final/TRAM-slide-.oni-patch
- Timestamp:
- Mar 2, 2014, 2:50:25 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/packages/31000GlassBreakingMoves/patches/common/level0_Final/TRAM-slide-.oni-patch
r950 r965 3 3 @CUSTOM_CODE 4 4 <code> 5 function contains(fullStringOrArray, subString){ 6 return fullStringOrArray.indexOf(subString)!=-1; 7 } 5 // |———————————————————————————————————Code best viewed at this width————————————————————————————————————————| 6 7 // Load XML data 8 var myBuilder = new JSXMLBuilder(); 9 myBuilder.load($xmlData); 10 var elements = myBuilder.elements[0]; 8 11 9 function removeFromArray(_array, _value){ 10 _array.splice(_array.indexOf(_value), 1); 12 // If there are no attacks in this TRAM, ignore it 13 if (!elements.childElement("Animation").childElement("Attacks")) 14 return; 15 16 // Gather all the necessary info 17 var particles = elements.childElement("Animation").childElement("Particles"); 18 var attack = elements.childElement("Animation").childElement("Attacks").childElement("Attack"); 19 var hit_start = attack.childElement("Start").text; 20 var hit_end = attack.childElement("End").text; 21 var array_bones = attack.childElement("Bones").text.split(" "); 22 23 // Remove glass_break if it is already assigned to any bones, because it's probably not been assigned the 24 // way we want it to be 25 for (var i = 0; (particles.childElement(i)); i++) 26 { 27 var particle = particles.childElement(i); 28 if (particle.childElement("Name").text == "glass_break") 29 myBuilder.removeElement(particle.index); 11 30 } 12 31 13 var myBuilder = new JSXMLBuilder(); 14 myBuilder.load($xmlData); 15 16 var elements = myBuilder.elements[0]; 17 18 var particles = elements.childElement("Animation").childElement("Particles"); 19 20 21 if(!elements.childElement("Animation").childElement("Attacks")){ // if no attacks found ignore file 22 return; 23 } 24 25 var attackElement = elements.childElement("Animation").childElement("Attacks").childElement("Attack"); 26 27 var int_start,int_end,array_bones; 28 29 // gather all the necessary info 30 int_start=attackElement.childElement("Start").text; 31 int_end=attackElement.childElement("End").text; 32 array_bones=attackElement.childElement("Bones").text.split(" "); 33 34 // Check if any of the existing particles correspond to the same bone and glass_break 35 for (var i=0; (particles.childElement(i)); i++){ // the condition is to check if the child element exists (!= undefined) 36 var currElement=particles.childElement(i); 37 38 if(contains(array_bones,currElement.childElement("Bone").text) && currElement.childElement("Name").text=="glass_break"){ 39 removeFromArray(array_bones,currElement.childElement("Bone").text); // not necessary to add 32 // Find the outermost bone of each type 33 // The "type" in bone_type[] refers to the extremity of the body to which a bone belongs ("mid" counts as 34 // as an extremity because the head is part of "mid"); this is a "parallel array" with array_bones[] 35 var bone_type = new Array(19); 36 // The "ext" in bone_ext[] refers to the "outermostness" of the bone, that is, how far out on the extremity 37 // this bone is; this is a parallel array with array_bones[] 38 var bone_ext = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; 39 // The extremity_ arrays are parallel arrays which store the highest "outermostness" value found for each 40 // extremity, among all the bones in that extremity that are listed in the attack 41 var extremity_name = ["mid", "left_arm", "right_arm", "left_leg", "right_leg"]; 42 var extremity_max = [0, 0, 0, 0, 0]; 43 for (var i = 0; i < array_bones.length; i++) 44 { 45 var bone = array_bones[i]; 46 if (bone == "Head" || bone == "Neck" || bone == "Chest" || bone == "Mid" || bone == "Pelvis") 47 { 48 bone_type[i] = "mid"; 49 if (bone == "Neck") 50 bone_ext[i] = 1; 51 else if (bone == "Head") 52 bone_ext[i] = 2; 53 // The rest of these bones are extremity '0' 54 } 55 else if (bone == "LeftShoulder" || bone == "LeftArm" || bone == "LeftWrist" || bone == "LeftFist") 56 { 57 bone_type[i] = "left_arm"; 58 if (bone == "LeftShoulder") 59 bone_ext[i] = 1; 60 else if (bone == "LeftArm") 61 bone_ext[i] = 2; 62 else if (bone == "LeftWrist") 63 bone_ext[i] = 3; 64 else if (bone == "LeftFist") 65 bone_ext[i] = 4; 66 } 67 else if (bone == "RightShoulder" || bone == "RightArm" || bone == "RightWrist" || bone == "RightFist") 68 { 69 bone_type[i] = "right_arm"; 70 if (bone == "RightShoulder") 71 bone_ext[i] = 1; 72 else if (bone == "RightArm") 73 bone_ext[i] = 2; 74 else if (bone == "RightWrist") 75 bone_ext[i] = 3; 76 else if (bone == "RightFist") 77 bone_ext[i] = 4; 78 } 79 else if (bone == "LeftThigh" || bone == "LeftCalf" || bone == "LeftFoot") 80 { 81 bone_type[i] = "left_leg"; 82 if (bone == "LeftThigh") 83 bone_ext[i] = 1; 84 else if (bone == "LeftCalf") 85 bone_ext[i] = 2; 86 else if (bone == "LeftFoot") 87 bone_ext[i] = 3; 88 } 89 else if (bone == "RightThigh" || bone == "RightCalf" || bone == "RightFoot") 90 { 91 bone_type[i] = "right_leg"; 92 if (bone == "RightThigh") 93 bone_ext[i] = 1; 94 else if (bone == "RightCalf") 95 bone_ext[i] = 2; 96 else if (bone == "RightFoot") 97 bone_ext[i] = 3; 40 98 } 41 99 } 42 43 // Insert the new glass particles 44 for (var i = 0; i < array_bones.length; i++) { 45 if(array_bones[i]=="RightFoot" || array_bones[i]=="LeftFoot" || array_bones[i]=="RightFist" || array_bones[i]=="LeftFist"){ 46 myBuilder.addElementAt("Particle","", 47 "<Start>"+int_start+"</Start>\ 48 <End>"+int_end+"</End>\ 49 <Bone>"+array_bones[i]+"</Bone>\ 50 <Name>glass_break</Name>",particles.index+1,particles.level+1); 100 101 // Find outermost bone for each extremity, among the bones listed in the Attack 102 for (var a = 0; a < array_bones.length; a++) 103 { 104 for (var b = 0; b < extremity_name.length; b++) 105 { 106 if (extremity_name[b] == bone_type[a]) 107 { 108 if (bone_ext[a] > extremity_max[b]) 109 extremity_max[b] = bone_ext[a]; 110 } 51 111 } 52 112 } 113 114 // Add a glass_break particle for every outermost bone in the attack 115 for (var a = 0; a < array_bones.length; a++) 116 { 117 // Move to next bone if this is not the outermost attacking bone on this extremity 118 var add_this_bone = false; 119 for (var b = 0; b < extremity_name.length; b++) 120 { 121 if (bone_type[a] == extremity_name[b]) 122 { 123 if (bone_ext[a] == extremity_max[b]) 124 add_this_bone = true; 125 } 126 } 127 if (!add_this_bone) 128 continue; 129 130 // Exit if we are past Oni's limit on TRAM particles 131 if (particles.length >= 16) 132 { 133 echo("Reached maximum of 16 particles for this TRAM, exiting…"); 134 return; 135 } 136 137 echo("Adding glass_break to " + array_bones[a]); 138 var par_string = "<Start>" + hit_start + "</Start><End>" + hit_end + "</End><Bone>" + array_bones[a] + "</Bone><Name>glass_break</Name>"; 139 140 // Add glass_break to bone for time period that bone has collision status 141 myBuilder.addElementAt("Particle", 142 "", 143 par_string, 144 particles.index + 1, 145 particles.level + 1); 146 } 53 147 54 $xmlData=myBuilder.generateXML(); // update the global variable with the new XML 148 // Update the global variable with the new XML 149 $xmlData = myBuilder.generateXML(); 55 150 </code>
Note:
See TracChangeset
for help on using the changeset viewer.