Erain 3D
-->

Author: Max Pellizzaro
Date: November 1st 2007
version: 3.0

Importing 3DS MAX Part I

Objective of the tutorial

It's time to learn more advanced features of Sandy, so we will face now the possibility to import models coming from other softwares. Sandy can import 3DS MAX format files Collada format files (an incoming format standard). Basically there are two ways you can import a model 3D coming from another software:

The two approaches are quite different, and this is why I have decided to dedicate two different tutorials: Part I and Part II. The first part, this one, will show how to use a model that has been exported in an AS format. It will take a little more effort to export the model, but the Sandy code will result so easy to write. The second approach (Part II) will import the 3DS file and you will see it will take a little more code to write (just a little).

How to

Set up 3DS MAX

In the Set up section we have put the 3DS MAX set up since with these tutorial we will use a plug in order to generate an AS file. The plug in can be find in the shirotokoro blog, but I will attach here the plug in just in case (for other export tools, check this page).

script3ds.rar

Basically you need to do three things:

  1. Install the plug in inside 3DS MAX
  2. Create a 3D model
  3. Export the model in Sandy AS format

A little tutorial with snap shot can be found here.
At the end of your work you should have a .as file representing the model. For our example I have build a tea pot (I cheat a little bit since it is a predefined solid in 3DS), and exported as Teiera.as file. You will find this file inside the downloadable code in the next section.

Set up

The Document class must be changed to Example006.as The name of the class in the .as file and the name of the constructor now is: Example006. In this archive you will find also the class Teiera.as that we have produced with the previuos step.

example006.rar

The AS Code

package {
  import flash.display.Sprite; 
  import flash.events.*;
  import sandy.core.Scene3D;
  import sandy.core.data.*;
  import sandy.core.scenegraph.*;
  import sandy.materials.*;
  import sandy.materials.attributes.*;
  import sandy.primitive.*;
  import sandy.parser.*;
 
  public class Example006 extends Sprite {
    private var scene:Scene3D;
    private var camera:Camera3D;
    private var pot:Teiera;
 
    public function Example006() { 
      camera = new Camera3D( 300, 300 );
      camera.y = 30;
      camera.z = -200;
 
      var root:Group = createScene();
 
      scene = new Scene3D( "scene", this, camera, root );
 
      addEventListener( Event.ENTER_FRAME, enterFrameHandler );
    }
 
    private function createScene():Group {
      var g:Group = new Group("myGroup");
 
      var materialAttr:MaterialAttributes = new MaterialAttributes(new LightAttributes( true, 0.2 ) );
      var material:Material = new ColorMaterial( 0xE0F87E, 0.9, materialAttr);
      material.lightingEnable = true;
      var app:Appearance = new Appearance( material);
 
      pot = new Teiera("pot");
      pot.appearance = app;
      pot.enableBackFaceCulling = false;
      g.addChild( pot );
 
      return g;
    }
 
    private function enterFrameHandler( event : Event ) : void {
      pot.pan +=5;
      scene.render();
    }
  }
}

Examining the code

private var scene:Scene3D;
private var camera:Camera3D;
private var pot:Teiera;
pot = new Teiera("pot");

Actually before that creation of the class I have defined a skin to apply to our tea pot. We haven’t study yet how to import *.jpg material, so for now I will only use “hard coded” material, but I still like the result.

var materialAttr:MaterialAttributes = new MaterialAttributes(new LightAttributes( true, 0.2 ) );
var material:Material = new ColorMaterial( 0xE0F87E, 0.9, materialAttr);
material.lightingEnable = true;
var app:Appearance = new Appearance( material);

The use of the lightingEnable tells the rendering engine to use light effect on the 3D model.

pot.appearance = app;
pot.enableBackFaceCulling = false;
g.addChild( pot );

And new let's see the result.

The output

This time I did not add any keyboard interaction, but you know how to do it…