In this sample <doulbe-click> handler is added to deal with additional file loads:
public function mouseDblClick(event: MouseEvent): void { if ( this.loader || loadcount == 0 || loadcount > 2) return; if ( loadcount == 1) { this.loader = new Xc3Loader("/demos/models/walkload/pawn.zc3"); this.loader.resourcePath = "/demos/models/walkload"; this.loaded = false; } else if ( loadcount == 2) { this.loader = new Xc3Loader("/demos/models/walkload/bunny.zc3"); this.loader.resourcePath = "/demos/models/walkload"; this.loaded = false; } this.loader.useCurrentScene = true; statusText.visible = true; statusText.text = "loading file: " + loader.sourceURL; statusTimer = new Timer(1000, 0.2); // designates listeners for the interval and completion events statusTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); statusTimer.start(); this.loader.addEventListener(LoadEvent.LOAD_COMPLETE, this.cast3dLoadComplete); this.loader.addEventListener(LoadEvent.LOAD_ERROR, this.cast3dLoadError); this.loader.addEventListener(LoadEvent.LOAD_PROGRESS, this.cast3dLoadProgress); this.loader.load(this.animator.source); }
An important thing to remember after you created loader with
this.loader = new Xc3Loader("/demos/models/walkload/pawn.zc3");
is to set 'current Scene' flag
this.loader.useCurrentScene = true;
such that loader will not create a new scene but load into current.
Other things to consider:
After you loaded a model you may want to position it in scene in a certain place and angle, which can be done with Positioner class as shown below:
private function cast3dLoadComplete(event: LoadEvent): void { if ( this.loader.sourceURL == "/demos/models/walkload/pawn.zc3" ) { positionNode("Circle", {x: 0, y:4, z:17}, null); } } /** * sets node position / orientation in 3D scene */ public function positionNode(nodeId:String, position:Object, rotation:Object): Boolean { var nodename:String = nodeId; var node:Node3d = this.animator.source.find(nodeId) as Node3d; if (!node) return false; var p:Positioner = new Positioner(node); if (position) p.updatePosition(position.x, position.y,position.z); if (rotation) p.upadetRotation(rotation.x, rotation.y ,rotation.z , rotation.w); return true; }
Complete source code for this sample
You can also look at Subload sample in distribution package.