Bookmark and Share

You can export collada from 3dsmax 2010 but it won’t load properly in Papervision3D and throw an error. You will need a plugin called “Collada Max NextGen” from SourceForge.

To load a collada file “box.dae”, write the code like below:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
 
	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.parsers.Collada;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;
 
	[SWF(width="640", height="480", frameRate="30", backgroundColor="#000000")]
	public class ColladaExample extends BasicView {
		private var collada:Collada;
 
		public function ColladaExample ()	{
			super(0, 0, true, true, CameraType.FREE);
			init();
		}
 
		private function init():void {
			camera.z = -1500;
			camera.focus = 200;
			camera.zoom = 2;
			addCollada();
		}	
 
		private function addCollada():void {
			collada = new Collada();
			collada.load("box.dae");
			collada.addEventListener(FileLoadEvent.LOAD_COMPLETE, onColladaLoaded);
			scene.addChild(collada);
		}	
 
		private function onColladaLoaded(e:FileLoadEvent):void {
			collada.removeEventListener(FileLoadEvent.LOAD_COMPLETE, onColladaLoaded);
			startRendering();
		}
 
		override protected function onRenderTick(event:Event=null):void {
			collada.rotationY += 2;
			super.onRenderTick(event);
		}
	}
}

If you have created a box named “box1″ and you want to interact with it, you will need to delete a node tag id called “node-Scene_Root” in collada file so collada.getChildByName(“Box1″) won’t throw an error. So you get like:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
 
	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.parsers.Collada;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;
 
	[SWF(width="640", height="480", frameRate="30", backgroundColor="#000000")]
	public class ColladaExample extends BasicView {
		private var collada:Collada;
		private var myObj3d:DisplayObject3D ;
		private var myMaterial:MaterialObject3D;
 
		public function ColladaExample ()	{
			super(0, 0, true, true, CameraType.FREE);
			init();
		}
 
		private function init():void {
			camera.z = -1500;
			camera.focus = 200;
			camera.zoom = 2;
			addCollada();
		}	
 
		private function addCollada():void {
			collada = new Collada();
			collada.load("box.dae");
			collada.addEventListener(FileLoadEvent.LOAD_COMPLETE, onColladaLoaded);
			scene.addChild(collada);
		}	
 
		private function onColladaLoaded(e:FileLoadEvent):void {
			collada.removeEventListener(FileLoadEvent.LOAD_COMPLETE, onColladaLoaded);
 
			myObj3d = collada.getChildByName("box1", true)
			myObj3d.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, on3dOver);
			myObj3d.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, on3dOut);
			myObj3d.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, on3dClick);
 
			// You can find out your material name by collada.materialsList()
			myMaterial = myObj3d.materials.getMaterialByName("m1");
			myMaterial.interactive = true;
			myMaterial.smooth = true;
 
			startRendering();
		}
 
		override protected function onRenderTick(event:Event=null):void {
			collada.rotationY += 2;
			super.onRenderTick(event);
		}
 
		private function on3dOver(e:InteractiveScene3DEvent):void {
			viewport.buttonMode = true;
			trace("OVER");
		}
 
		private function on3dOut(e:InteractiveScene3DEvent):void {
			viewport.buttonMode = false;
			trace("OUT");
		}
 
		private function on3dClick(e:InteractiveScene3DEvent):void {
			trace("CLICK");
		}
	}
}