/** * Sets up Navigation Controller for Character node */ private function setupNavigator():void { // First lets find the root node of a character // we know by looking at source file, its Id is 'Cube' var nodename:String = "Cube"; var node:Node3d = this.animator.source.find(nodename) as Node3d; if (!node) { statusText.visible = true; statusText.text = "Failed to set Navigation control for node: " + nodename; return; } // create smooth navigation conrloller fo this node. var nc:NavigationBlenderController = new NavigationBlenderController(node,"navigator"); _navigations.push(nc); // We know that "Cube" node actually represents Skinned geometry, which means // the motion is controlled by another skeleton node(s), in this case "lowerBack" node is // root skeleton node( see source file) nodename = "lowerBack"; node = this.animator.source.find(nodename) as Node3d; if (!node) { statusText.visible = true; statusText.text = "Failed to set Navigation control for node: " + nodename; return; } var track_id:String; var motionAlias:String; var track:Track3d; var i:int = 0; // Lets make an instance of motion blender var mixer:MotionBlender = new MotionBlender( "lowerBack_motion_blend"); // We are going to blend two motion groups // now we add a 'walking' motion which is represented by MotionGroup class instance with id == "lowerBack_motion" // again, we know that by looking at source file. // Notice that 'motion' is produced by different node that we created nvigation controlled, which in that case "cube" // First motion group to blend with is "lowerBack_motion"; track_id = "lowerBack_motion"; motionAlias = "walk"; // we need to fine "lowerBack_motion" track first, which is 'walking' motion for each ( track in node.tracks) { if (track.id == track_id) break; track = null; i++; } // then remove it from node's track list to prevent it from being animated if (track) { node.tracks.splice(i,1); track.enabled = true; } // next, we add to blender, with weight = 0.5, // which meams 50% infulence from this motion will be applied to node mixer.addTrack(track,.5); // same thing with anpther motion group "lowerBack_motion539", which is 'waving' motion track_id = "lowerBack_motion539"; i=0; for each ( track in node.tracks) { if (track.id == track_id) break; track = null; i++;} if (track) { node.tracks.splice(i,1); track.enabled = true; } mixer.addTrack(track,.5); // we need to enable mixed, by default all tracks are disabled mixer.enabled = true; // now we jast add it navigation controller if (!nc.addMotion2(node, motionAlias, mixer )) { statusText.visible = true; statusText.text = "Failed to add Motion " + motionAlias + " for track: " + track_id; return; } // just another motion ( non mixed) motionAlias = "jump"; track_id = "lowerBack_motionjump"; for each ( track in node.tracks) { if (track.id == track_id) break; track = null; } if (!nc.addMotion2(node, motionAlias, track)) { statusText.visible = true; statusText.text = "Failed to add Motion " + motionAlias + " for track: " + track_id; return; } motionAlias = "wave"; track_id = "lowerBack_motion539"; for each ( track in node.tracks) { if (track.id == track_id) break; track = null;} // since we removed "lowerBack_motion539" track from node.tracks list, // track should be 'null' if (!nc.addMotion2(node, motionAlias, track )) { statusText.visible = true; statusText.text = "Failed to add Motion " + motionAlias + " for track: " + track_id; return; } nc.position.x -= 5.0; nc.rotation.x = 0; nc.rotation.y = 0; nc.rotation.z = 1; nc.rotation.w = 30 * Math.PI/180.0 ; this.stage.addEventListener(KeyboardEvent.KEY_DOWN, this.keyDownHandler); }