If you work long enough in Papervision you will eventually have to deal with loading complex models into Papervision. This is one of the more difficult things to do but not because of the actionscript or Papervision coding. Whenever we have had problems with models in the past; it has always been an issue model's source.
Hopefully you are one of the few blessed enough to have an resource available to modify and create Papervision ready models for you. If not, just know you're not alone.
Issues with 3D models aside, the code for loading a 3D model into Papervision is extremely easy. It is as simple as loading a plane, cube, or cone.
-
package
-
{
-
import flash.events.Event;
-
import org.papervision3d.materials.BitmapFileMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.parsers.Collada;
-
import org.papervision3d.view.BasicView;
-
-
public class Main extends BasicView
-
{
-
protected var cow:DisplayObject3D;
-
protected var materialList:MaterialsList;
-
protected var bitmapFileMaterial:BitmapFileMaterial;
-
public function Main()
-
{
-
super();
-
createChildren();
-
startRendering();
-
}
-
public function createChildren():void
-
{
-
//Setup the materials manually (sometimes the dae handles this without issue)
-
materialList = new MaterialsList();
-
bitmapFileMaterial = new BitmapFileMaterial("daeModel/Cow.png");
-
materialList.addMaterial(bitmapFileMaterial,"all");
-
-
//Create the new Collada Object with materialList
-
cow = new Collada("daeModel/cow.dae",materialList);
-
-
//Set some properties
-
cow.moveDown(150);
-
cow.scale = 3;
-
cow.pitch( -10);
-
-
//Add to scene
-
scene.addChild(cow);
-
}
-
-
override protected function onRenderTick(event:Event = null):void
-
{
-
super.onRenderTick(event);
-
-
//Rotate
-
cow.yaw(1);
-
}
-
}
-
}
Once you have a good model, in papervision all you need for this to work properly is to:
1) Create the model new Collada()
2) Create the model's texture new BitmapFileMaterial()
3) Create and add the bitmap material to a materials list new MaterialsList()
4) Add the model to the scene scene.addChild(cow)
5) Render startRendering()
It's too much to cover all the issues you may run into here but if you're up for it open up the cow.dae file. You'll find it is just a lot of XML. Go through it, see if you can find the texture file.


