===== First Cast3D Application ===== ==== Objectives of this sample are to demonstrate ==== - import of .3ds file into Cast3D .Xc3 xml file. - setting up rendering scene - loading and displaying 3D model ==== 1. Importing 3D model ==== * Using Cast3D .3ds file format to Cast3D XML file import command-line utility [[http://cast3d.googlecode.com/files/3ds2Xml.zip| 3ds2XML (Windows, Win32)]] convert this [[http://cast3d.com/demos/tutorials/intro/stealth.zip|stealth.3ds]] model into 'stealth.xc3' file with following command. C:\work> 3ds2XML stealth.3ds stealth.xc3 A new file stealth.xc3 should appear in current directory. ==== 2. Setting up 3D scene ==== Setting up scene consists of following steps: * initial setup of rendering engine. In this tutorial we will be using Sandy3D rendering engine. /** * initial setup for Sandy3D. */ public function setupSandy(): void { // We create the camera this.camera = new Camera3D( 600, 400 ); this.camera.near = 1; // We create the "group" that is the tree of all the visible objects var root:Group = new Group(); // We create a Scene and we add the camera and the objects tree this.scene = new Scene3D( "scene", this, camera, root ); this.scene.light = new Light3D(new Vector(0,0,1),100); } * initial setup of Cast3D animation framework. /** * initial setup for Cast3D. */ public function setupCast3D(): void { // init loading status this.loaded = false; // new Cast3D instance with created earlier 3D scene and camera this.animator = new Cast3d(this.scene, this.camera); // set animation type this.animator.animationType = Cast3d.ANIMATION_TYPE_BYFRAME; // ANIMATION_TYPE_REAL; // // set desired animation frame rate this.animator.fps = 22; // run it once this.animator.autoRewind = false; } ==== 3. Loading model ==== /** * Function performs 3D data load from a X3c file. */ private function loadData(): void { /** stealth - simple model, no animation */ this.loader = new Xc3Loader("stealth.x3c"); this.loader.resourcePath = "/data"; // optimize animation this.loader.preCalcMotion = true; // register notification of load completion this.loader.addEventListener(LoadEvent.LOAD_COMPLETE, this.cast3dLoadComplete); // register notification of load error this.loader.addEventListener(LoadEvent.LOAD_ERROR, this.cast3dLoadError); // proceed with load this.loader.load(this.animator.source); } If you noticed the line this.loader.resourcePath = "/data"; indicated the place where you want to put texture images and other media materials like sound, movie and video. ==== results ==== So, if done it right you should see something like these: ---- Complete source code of this [[samplesource|sample]].