**Update
This tutorial has been updated:
![]()
Hi, Today we're going to modify the "Creating Objects" project again, this time to load a Collada Model file.
Loading Collada files is the fastest and easiest way in Papervision 3d to get a complex model into your scene. By changing a few lines in your code, we can quickly load a model of a cow and make it spin! The result will be this:
All that, in just a few lines of code!
Let's show you how to spin cows..
We'll need to use the org.papervision3d.objects.DisplayObject3D package to store our model in. This will store the geometry, materials and everything like the position and rotation. We'll also need the Collada file parser.. Change your import lines so they look like this:
import PaperBase; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.parsers.Collada;
They're the only three imports needed!
Now, instead of making a cone, this time we're making a cow, so we change the "public var cone" line to this:
public var cow:DisplayObject3D;
So, that line tells our program that we want to store a DisplayObject3D in a variable called cow.
Now, in the init3d() function code we'll load the Collada file. I have the file stored on my server. You can download it if you want but this example will refer to the model on my server so it will work wherever. Change all of the code in "init3d" to this:
cow = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
cow.moveDown(100);
cow.scale = 3;
cow.pitch(-30);
default_scene.addChild(cow);
Most of that code is just positioning the cow in the scene!
The first line of that code makes the cow variable load the Collada model file from my server. All of the parsing, getting the material and everything like that is done by the Collada package which is pretty neat!
We then move the cow down a bit, tilt her towards the camera, and add her to the scene.
All that's needed now is to rotate the cow each time the frame is processed. Simple! Change the code under "processFrame" so that it reads:
cow.yaw(5);
and you're all done!
My final code is here:
-
package {
-
-
import PaperBase;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.parsers.Collada;
-
-
public class Main extends PaperBase {
-
-
public var cow:DisplayObject3D;
-
-
public function Main() {
-
init();
-
}
-
-
override protected function init3d():void {
-
cow = new Collada("http://papervision2.com/wp-content/downloads/dae/cow.dae");
-
cow.moveDown(100);
-
cow.scale = 3;
-
cow.pitch( -30);
-
default_scene.addChild(cow);
-
}
-
-
override protected function processFrame():void {
-
cow.yaw(5);
-
}
-
-
}
-
-
}


EDIT: sorry the right thing is:
mycollada.materials = mysecondmateriallist;
But it doesn’t work anyway…
Thanks, but now what if you want to remove this model from the scene, load another one with its texture?
And imagine we want to be able to browse a list of models… so after 20 loading, what will happen? It will probably be slow because of memory leaks in Papervision.
Do you have a solution for that?
Hello,
Excellent tutorial,
I’m trying to load now a model that is animated via bones in Maya 2008.
I read in Nabble that for animations, org.papervision3d.objects.parsers.DAE
should be used:
————-START CODE——————-
character = new DAE(true);
character.load(“character.dae”);
default_scene.addChild(character);
————-END CODE———————
This results in the following Output:
INFO: Papervision3D Public Beta 2.0 – Great White (September 9th, 2008)
INFO: BitmapFileMaterial: Loading bitmap from Art/Textures/character1_color.jpg?nc=0.16253294749185443
ERROR: BitmapFileMaterial: Unable to load file Art/Textures/character1_color.jpg?nc=0.16253294749185443
INFO: DisplayObject3D: COLLADA_Scene
INFO: DisplayObject3D: pCube1
INFO: DisplayObject3D: transform2
INFO: DisplayObject3D: pCylinder1
INFO: DisplayObject3D: transform1
INFO: DisplayObject3D: polySurface1
Nothing happens… Is here any other way to load and play animations ?
Excellent tutorials Luke!
I tried the code for this tutorial in Flash CS3… worked fine, but in the Output window I get these messages:
INFO: Papervision3D Public Beta 2.0 – Great White (September 9th, 2008)
INFO: DisplayObject3D: vsn-mats
INFO: BitmapFileMaterial: Loading bitmap from http://papervision2.com/wp-content/downloads/dae/Cow.png
ERROR: MaterialObject3D: transformUV() material.bitmap not found!
ERROR: MaterialObject3D: transformUV() material.bitmap not found!
ERROR: MaterialObject3D: transformUV() material.bitmap not found!
ERROR: MaterialObject3D: transformUV() material.bitmap not found!
…
ERROR: MaterialObject3D: transformUV() material.bitmap not found!
…
Any idea what might have gone wrong?
I am sorry to bother you, but everytime i launch flashplayer to start the animation, i get several times this output:
MaterialObject3D: transformUV() material.bitmap not found!
Can you please indicate me what am i supposed to do? This is driving me crazy.
It’s not a problem of this tutorial only, i got tha same output also in other tutorials where i used bitmap references.
Thanks a lot!
I’m a newbie on this subject. I’m suing swift 3d to export some 3d designs, but I can’t get them to load using the sample above. Is there something that I have to do dae files?
And thanks for the tutorials they’re nice
Hi everyone A big thank you for this wonderful site, it has helped me immensely
when i coped those codes into my FlashDevelp , the Output displayed : ERROR: MaterialObject3D: transformUV() material.bitmap not found! ,what’s wrong with it ?
To void getting the error: “ERROR: MaterialObject3D: transformUV() material.bitmap not found!” …don’t add the Collada to the scene until the material bitmap(s) have loaded.
The error is caused by the fact that the cow material bitmap is still loading. (You might have noticed that the error stops firing once the bitmap loads).
The most efficient way to wait for the bitmap to load, is to wait for the Collada object to dispatch the FileLoadEvent.COLLADA_MATERIALS_DONE, like so:
cow.addEventListener(FileLoadEvent.COLLADA_MATERIALS_DONE, cowOnLoadCompleteHandler);
…then do the addChild(cow) in the cowOnLoadCompleteHandler.
(Note that FileLoadEvent.LOAD_COMPLETE fires too soon, before the bitmap loads, so DO NOT use it for this purpose.)
(While discovering this, I found that polling the cow to wait for (cow.loaded && cow.materialsToLoad == 0) did the trick – but using the event is 100 times cleaner!)
Cheers
Toby
After following along it simply does not work. No error outputs, but nothing on the stage either. Any ideas?
Mant thanks for your great help in learning papervision
I have the same problem others have mentioned but I have not seen a solution. The cow model loads fine but it is a mesh with no texture. This is the same even if I download the 2 files and use them locally.
Please help!
Hello,
The cow shows up in wireframe, but no texture. The output I’m receiving is:
Papervision3D Public Alpha 3.0 – PapervisionX (18.09.08)
DisplayObject3D: vsn-mats
Collada material mat0 not found.
Oh , thank you !!!!haha
I tried this tutorial and I can see the cow, but no textures. The error is:
WARNING: Collada material mat0 not found.
Also, I see the model from the top down – NOT from the side view as you have it.
I get the same mat0 error not found, anyone solved this yet?
never mind.. solved it myself
var mat:BitmapFileMaterial= new BitmapFileMaterial(“Cow.png”);
var mp:MaterialsList = new MaterialsList();
mp.addMaterial(mat, “mat0″);
after adding the material to mp, you should change your code to
cow = new Collada(“http://papervision2.com/wp-content/downloads/dae/cow.dae”, mp);
provide more source code
package {
import PaperBase;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Collada;
public class Main extends PaperBase {
public var cow:DisplayObject3D;
public function Main() {
init();
}
override protected function init3d():void {
cow = new Collada(“http://papervision2.com/wp-content/downloads/dae/cow.dae”);
cow.moveDown(100);
cow.scale = 3;
cow.pitch( -30);
default_scene.addChild(cow);
}
override protected function processFrame():void {
cow.yaw(5);
}
}
}
Here’s my entire code, extending BasicView instead of PaperBase. It works as the example swf:
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 ColladaTest extends BasicView {
private var do3d:DisplayObject3D;
private var mList:MaterialsList;
public function ColladaTest() {
init();
}
private function init():void {
init3d();
render();
}
private function init3d():void {
mList = new MaterialsList();
var mtl:BitmapFileMaterial = new BitmapFileMaterial(“http://papervision2.com/wp-content/downloads/dae/Cow.png”);
mList.addMaterial(mtl, “mat0″);
do3d = new Collada(“http://papervision2.com/wp-content/downloads/dae/cow.dae”, mList);
do3d.moveDown(100);
do3d.pitch(90);
do3d.scale = 3;
scene.addChild(do3d);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function render():void {
startRendering();
}
private function enterFrameHandler(evt:Event):void {
do3d.yaw(1);
}
}
awesome thanks for the code.. I got an xwing model to show up and rotate in my space map thingy :)
How it is possible to embed .swf which uses external collada files with code that validates? Seems that collada files load not the first, but the second time the page loads with swfobject. The embed used on this site doesn’t validate.
For those of you who have downloaded
http://papervision2.com/wp-content/downloads/dae/Cow.dae
you should also download texture image:
http://papervision2.com/wp-content/downloads/dae/Cow.png
Could you please publish short tutorial about creating collada object, such as this beauty cow?
Many thanks for your work.
May I ask how would you use a collada file that is not hosted on the internet but on your own computer?
hi,
thank you fpr this tutorial.
But I have another question.
I need to turn around the camera targeted on the object and not the object spinning around itself.
How can i do this ?
Hey Karol,
I was actually going to setup a tutorial on this very subject but the short answer to your solution would look as follows:
protected var _camAng :Number = 90;
static private var CAM_SPEED :Number = 120;
static private var CAM_RADIUS :Number = 2000;
protected function render(evt:Event):void
{
camera.lookAt(sphere);
_camAng += Math.PI / CAM_SPEED;
if (_camAng > Math.PI * 2)
{
_camAng = 0;
}
camera.x = Math.sin(_camAng) * CAM_RADIUS;
camera.z = Math.cos(_camAng) * CAM_RADIUS;
renderer.renderScene(scene, camera, viewport);
}
If anyone has a more elegant solution I would love to see. :)
Charlie
OH THANK YOU…that was fast ! :)
i have another little problem (very noob like)
flashdevelop says “the path to flash.exe is not configured properly” than i go to settings, but i don’t know the path to it. It is not inside of the “Flex2SDK” dir, or?
my windowssearch says there is n “flash.exe” but I installed everything needed I think.
My path is set to:
C:\Program Files (x86)\Adobe\Adobe Flash CS3
For Flex builder compiling it is set to:
C:\Program Files (x86)\Adobe\Flex Builder 3\sdks\3.1.0
Charlie
okay thank you, it works with:
C:\Program Files (x86)\Adobe\Flex Builder 3\sdks\3.2.0
but i get a plane white app.
I’m very very new to actionscript, so can you please explain what to do with this code?
1. Do I need the code version from the tutorial or one from the comments?
2. what do I need to make this camera spin, I got your code:
– you override an exsisting function “render()” ?
– where do I have to declare the variables (in the main class or directly above the
function?)
– “cow.yaw(5);” this function I do not need, because I only want to move the camera not
the object?
Is this right ?
I work with the new flashdevelop, have installed papaervision3D and Adobe Flex, and I have a .DAE Object from Lightwave 3D.
Sorry that code was not specific to this project but a general overview of how you would accomplish the task of rotation around a papervision object. A full tutorial is soon to come.
Charlie
I’ll be the second to ask this: what program do you use to make the Collada files AND the png texture, and could you perhaps explain the process if it’s less than clear?
Otherwise I’ve got this up and working with files on my computer now. You rock, Charlie ^.^
package
{
import PaperBase;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Collada;
/**
* …
* @author admiraL_b
*/
public class Main extends PaperBase
{
protected var sceneWidth:Number;
protected var sceneHeight:Number;
public var house:DisplayObject3D;
public function Main()
{
sceneWidth = stage.stageWidth
sceneHeight = stage.stageHeight;
init(sceneWidth,sceneHeight);
}
override protected function init3d():void
{
house = new Collada(“bla.dae”);
house.moveDown(100);
house.scale = 1;
house.pitch( -30);
default_scene.addChild(house);
}
override protected function processFrame():void
{
house.yaw(5);
}
}
}
okay i got this code but i see nothing. Can someone tell me why? the DAE file is in the same directory. i tried also with an absolut path. Same problem. ??????????????????
@Justin Redfield: The Collada files are from an exporter from a 3D Tool like Lightwave, 3DS Max or blender or sketchup. But to explain how o create complex models in thes tools would take very long. but there are many totorials on the web when you search for or there are also many complet DAE files on the web to use. PNG Textures you can also get from the internet when you search for, or you can create them by yourself with adobe photoshop or paint or whatever you like.
I need help, please :( !!!!!
Have you tried using a different model? If you can see a different model perhaps the issue is not with your code but with your model. Let me know,
Charlie
hi
i tried with the cow. that works, but 2 different models (both from lightwave 9.6; one a simple box and one a complex house) from the local directory it doesn’t work. I don’t know why
how should the path to the .dae file should be written ?
Download this:
http://papervision2.com/wp-content/downloads/dae/cow.dae
Save it locally to your computer as cow.dae
Test this file locally. Once you get that working place YOUR model in the same directory.
If locally the cow works and your model doesn’t then it is the model and not the code.
If you need support on creating 3D Models unfortunately I won’t be able to offer any assistance.
Charlie
hi I tried this, but if the cow DAE is in the same local directory, i see a white plane too.
3D Models are no problem, i worked with lightwave a long time, i have problems with actionscipt/papervision
this is the code, and it won’t work
cow = new Collada(“cow.dae”, null, 2, false);
so i tried also uploading the cow on my server, but it is the same problem
okay when i upload the cow to my server it works (without textures, but this is because th .png is not on my server) so i think there has to be wsomething wrong with my DAE files
you can find 2 of my DAE files on
http://karol.bplaced.net/media/bla.dae
http://karol.bplaced.net/media/test.dae
(doesn’t work)
and the cow (works):
http://karol.bplaced.net/media/cow.dae
But e.g. the Swirl X3D Viewer shows me test.dae and cow.dae but not bla.dae
Perhaps it is too complex, too much polygons (about 100, shouldn’t be too much)
Odd. I will look into the paperbase and if it is conflicting with the updated papervision code.
Try this:
package
{
import flash.events.Event;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.view.BasicView;
public class MainView extends BasicView
{
protected var model:DAE;
public function MainView():void
{
model = new DAE(true, “mycam”, true);
model.load(“bla.dae”);
model.texturePath = “”;
model.scale = 1
model.moveDown(100);
model.pitch( -30);;
scene.addChild(model);
camera.zoom = 100;
startRendering();
}
override protected function onRenderTick(event:Event = null):void
{
super.onRenderTick(event);
model.yaw(2);
}
}
}
Charlie
thank you very much for this code…but it is the same problem.
I tried several DAE files, from my lightwave and free DAE files from the internet. Doesn’t work. Only the cow (no matter where on the internet it is, but locally the cow also doesn’t work)
i tried also:
package
{
import flash.media.Camera;
import PaperBase;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.view.BasicView;
/**
* date: 15/04/09
* @author admiraL_b
*/
public class Main extends PaperBase
{
protected var sceneWidth:Number;
protected var sceneHeight:Number;
public var house:DisplayObject3D;
public function Main()
{
sceneWidth = stage.stageWidth
sceneHeight = stage.stageHeight;
init(sceneWidth,sceneHeight);
}
override protected function init3d():void
{
house = new DAE(true, “http://papervision2.com/wp-content/downloads/dae/cow.dae”, false);
default_scene.addChild(house);
}
override protected function processFrame():void
{
house.yaw(5);
}
}
}
//but same problem, i get a blank window
does anyone know the solution or where to search for the problem…its important !!! thank you very much
Hello, I’ve been trying to load a collada made from Blender… I have four objects, each with a different material… The compiler tells me this:
INFO: DisplayObject3D: Sphere
WARNING: Collada material logo_Sphere_png not found.
INFO: DisplayObject3D: CurveCircle
WARNING: Collada material logo_CurveCircle1_png not found.
INFO: DisplayObject3D: Curve_002
WARNING: Collada material logo_Curve3_png not found.
INFO: DisplayObject3D: Curve_001
WARNING: Collada material logo_Curve_png not found.
Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
at org.papervision3d.objects.parsers::Collada/parseGeometry()
at org.papervision3d.objects.parsers::Collada/parseNode()
at org.papervision3d.objects.parsers::Collada/parseScene()
at org.papervision3d.objects.parsers::Collada/buildCollada()
at org.papervision3d.objects.parsers::Collada/onComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
So basically, it’s not finding my materials AND it’s taking to long to load…
I havent been able to implement the material list into the code and make it work…
SOMEONE PLEASE HELP!!! I’M GOING NUTS!!!!
thanks, and awesome tut…
@Karol It’s quite possible that the Collada file is the wrong version. It should be v1.4 to work properly. Also, I’m not sure about Lightwave but I’ve read that in 3DS Max the default Collada exporter doesn’t produce files that will work with AS3. You could do what I did, which is port them into Blender (not a bad choice considering it’s free, but you’ll need to download Python for the scripts to work properly) and then export them as Collada 1.4, and there is a nice add-on for Blender that will actually make AS3 files out of your shape (great for making prims, but no animation yet), or there is a fix for the 3DS problem if you use that.
And thanks for the answer on the ripping PNGs; I found out how to properly do it in Blender (though it’s about 10 steps more than I find reasonable)
it’s not so easy to import lightwave files to blender and export them to DAE.
And it is not possible to create a model in blender for me inside of 1-2 days.
now i tried this once again:
package
{
import flash.events.Event;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.view.BasicView;
public class Main extends BasicView
{
protected var model:DAE;
public function Main():void
{
model = new DAE(true, “ding”, false);
model.load(“http://karol.bplaced.net/media/bla.dae”);
model.texturePath = “”;
model.scale = 1
model.moveDown(100);
model.pitch( -30);;
scene.addChild(model);
camera.zoom = 100;
startRendering();
}
override protected function onRenderTick(event:Event = null):void
{
super.onRenderTick(event);
model.yaw(2);
}
}
}
// but i got the error:
C:\Users\Leo\Desktop\flash\flashy\cone\main.as: Error: A file found in a source-path ‘main’ must have the same name as the class definition inside the file ‘Main’.
sorry for spamming so much :)
YES IT WORKS !!!! with the last sourcecode i posted !!!
thanks for the help guys!!!
now i have to find out how to spin the camera around the objekt