Loading Collada files (.dae) into Papervision3d 2.0 GreatWhite

December 7, 2007 – 1:57 pm Tags: , , , , , , , , ,

For anyone interested in learning how to load .dae (collada) files into Papervision3D 2.0, this is your lucky day!

A collada file is an open source version of your regular 3d file, whether it be created in 3dStudio Max, Maya, Blender, SketchUp, etc. It is essentially an XML file that describes all the assets, lighting, and textures of a 3 dimensional object.

Papervision3D 2.0 comes packaged with ASCollada, which was made by Tim Knip, and is quite a feat. Tim’s classes go through a collada file, parse all the information, and make it happen in Papervision. If you ever want to feel like a noob, just have a look inside the ASCollada/core directory and the files contained within, they’re quite extensive.

Anyways, once you have a collada file which ends with a .dae extension, you can import it into papervision with a simple command:

import org.papervision3d.objects.parsers.DAE;

var daeFile = new DAE(”yourFile.dae”);

universe.addChild(daeFile);

And that’s pretty much it in terms of getting the .dae file into flash!

[you can get the full source here]

But wait, there’s more!

A few things should be noted about doing all of this. Because of the time it takes for ASCollada to parse a .dae file, the script will often run more than the default 15 seconds and throw an error.

You can get around this by changing your script time limit in File/Publish Settings, and put it up to 30 or even 60 seconds. This will give Flash enough time to parse the XML before it throws an error.

Some other issues:

3d editors let you animate 3d scenes and objects, and, lo and behold, ASCollada supports these animations! Trouble is, Papervision3D 2.0 is still in Alpha testing, and the animations will sometimes throw an error if they are not in the proper format.

If you have an animation that isn’t working, please let Tim know about it. He’s busy trying to figure out everything right now, and the more files he has to test the better he can build ASCollada.

If you do not have access to a 3d application (kind of like me) you can do some googling to find some sample collada files.  I got a few at Collada.org.  These ones were kind of old, and perhaps that was the reason why their animations were not working.

If you do use any of these, or any other model that you find, make sure the texture images are NOT in the .targa format (which isn’t supported in flash).  Also, make sure to go through the collada file, find where it is referencing the texture, and verify that the path to the image is correct.

And with that, its time relax and stop obsessing over Papervision3d 2.0 for the weekend.

  1. 41 Responses to “Loading Collada files (.dae) into Papervision3d 2.0 GreatWhite”

  2. I just want to add another note:

    Loading textures belonging to the collada-file *can* be troublesome sometimes due to the fact that some exporters export absolute texture paths.

    If you are experiencing texture loading problems then you need to manually change the DAE:
    Open the DAE in a text editor and find the “” node.

    Then make the paths relative.

    By Tim K on Dec 7, 2007

  3. Sorry, comments doesn’t take lt en gt :-)
    That should say: “Find the ‘library_images’ node”…

    By Tim K on Dec 7, 2007

  4. Thanks for this! I had been missing a few lines of code while trying to parse a collada file, and your source was very helpful. Cheers.

    By Brad on Dec 18, 2007

  5. This works great for my blender files.

    After importing I’m trying to change one of the materials using replaceMaterialByName but I keep getting this error:
    Call to a possibly undefined method replaceMaterialByName[…]

    Any ideas?

    By helder on Jan 24, 2008

  6. Hi Helder. Do you know which version and revision of PV3D you are using? Let me know-

    By Thomas on Jan 25, 2008

  7. Thanks a lot!
    But i still don’t understand how to export from Blender with textures. I read this (http://collada.org/public_forum/viewtopic.php?p=2057) that all texture should be UV and Export Settings “-Select Triangles, Disable Physics, Use Relative Paths (Do not select Use UV Image)”, but still dae not have node, and assigning my object’s material’s from AS(getMaterialByName(”Skin”)) not working. When i compiled app, i always see wireframe material on my object! ((

    By Exey on Jan 27, 2008

  8. *not have node “library_images”

    By Exey on Jan 27, 2008

  9. Hi - wonder if you can help. Error 1009 always pops up when I try to import a .dae model exported from 3d studio max 9 or Strata. I have tried Papervision on mac and pc to no avail. Any ideas?

    By Jim on Feb 16, 2008

  10. hi, i’m trying to load an animation with dae file.

    problem is it doesn’t work and i’m having a hard time.

    i dont know if it’s a problem on my mesh or it’s my coding.

    please have a look on my files and 3d mesh file.

    http://freelance.zerodevice.net/twopets/

    thanks.

    By zerodevice on Mar 1, 2008

  11. Do your models have to be textured and lit before exporting?

    I’ve made a simple blocked-out game environment in Maya 8.5, exported all as a Collada .dae, but when I open this in Papervision (just changing the filename called from a working 3D example) I get a parsing error and then a white screen. I haven’t textured anything or added any lights and baked shadows, etc., so would I need to do this first?

    By Naeblis on Mar 13, 2008

  12. Hey all,

    I’d just like to leave a note that I am by no means an expert in Blender, 3ds Max, or any 3d package for that matter. I don’t have any of them on my computer.

    So I can’t give much help for how to properly export a collada from your 3d application.

    There’s tons of resources out there on how to do this for each of these applications, I suggest looking for those.

    Once your 3d model is properly exported, I can help you get it into papervision, but until then … sorry! :(

    By Thomas on Mar 13, 2008

  13. Thank You! Thank You! Thank You!

    I was killing myself all day trying to get this to work with the Collada object! We need to get the DAE into the documentation;)

    Also, I’ve been having a tough time getting a clean working collada out of the Google sketchup kmz, I’m trying Blender next.

    By HEBCHOP on Apr 16, 2008

  14. Works great with well formed DAE. I noticed a new Sketchup Parser, Do you know anything about it? I’m having a hard time getting it to work for me like in this example; http://rubyurl.com/7Be2

    By HEBCHOP on Apr 17, 2008

  15. Fixed the issues I was having before and I now have a working and textured environment, sky box, and 3D character.

    Next step is trying to get animations exported and working (currently it makes my character go invisible ;-) )

    By Nae'blis on Apr 23, 2008

  16. a great tool… but i have a problem with how configure it!!….
    I’ve downloaded the complete library of papervision at
    http://papervision3d.googlecode.com/svn/trunk/
    and in the directory branches I’ve founded two directories Effects and GreatWhite… I’ve being trying to import a collada file into flash cs3 but i need the shadows and the lights of it!!…. how can i do that???…. when i tried to run in flash once i’ve imported the directories:
    - as3/trunk/scr of papervision , and
    - branches/GreatWhite/src of GreatWhite

    a message like “TriangleMaterial.as, Line 24 1220:Method marked override must override another method ” appears in the compiler errors window….

    Help me please!!!

    By david on Apr 25, 2008

  17. hi, I1m trying to load a .dae file, into papervision 3d, but is throws an error:
    Error: Don’t know how to create face for a DaePrimitive with type = polylist
    at org.papervision3d.objects.parsers::DAE/buildFaces()
    at org.papervision3d.objects.parsers::DAE/buildGeometries()
    at org.papervision3d.objects.parsers::DAE/buildScene()
    at org.papervision3d.objects.parsers::DAE/loadNextMaterial()
    at org.papervision3d.objects.parsers::DAE/onMaterialError()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at org.papervision3d.materials::BitmapFileMaterial/loadBitmapErrorHandler()

    the model is exported from XSI. What’s that polylist?
    Could anyone help me?
    Ador

    By Ador on Apr 28, 2008

  18. if run the source you give, it doesen’t apply shade materials. It only displays a wireframe material, or a full black model. What shall i do, to get shaded objects, to make papervision to apply a shade material, and lights and stuff like that from the .dae file?
    please help me!
    thanks
    Ador

    By Ador on Apr 28, 2008

  19. hey ador,

    I can’t tell what you’re problem is without looking at your source. I would assume that the paths to your materials are incorrect in your .dae file.

    If you send me your file I could take a look.

    By Thomas on Apr 28, 2008

  20. Thank you for your answer. If you give me an email address, i will send you the sources.
    My question is, that how can i import a model - exported in a .dae file - with shaded materials.
    How can i achieve that, the models i’ve imported, are rendered with shading. Shall i replace the materials of the model with shadematerials? I’m a bit new in papervision, and the fact, that papervision 2.0 doesen’t have a documentation, doesent’t help me:D But I’m very interested in this field.
    Thank you for your answer.
    Ador

    By Ador on Apr 29, 2008

  21. Here is my source.

    package {

    // _______________________________________________________________________
    // classes to import
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.text.TextField;

    //import main papervision assets
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.render.*;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.materials.*
    import org.papervision3d.materials.shaders.*

    //import objects
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.parsers.*;
    import org.papervision3d.core.proto.MaterialObject3D
    import org.papervision3d.materials.utils.BumpmapGenerator

    //import event listener
    import org.papervision3d.events.FileLoadEvent;

    public class Main extends Sprite
    {

    // _______________________________________________________________________
    // vars

    //papervision main assets
    private var scene:Scene3D;
    private var viewport:Viewport3D;
    private var camera:Camera3D;
    private var light:PointLight3D;
    private var renderer:BasicRenderEngine;

    //other things needed for dae
    private var universe:DisplayObject3D;
    private var daeFile:DAE
    private var bumpMapGen:BumpmapGenerator

    private var bl:Number;
    private var bt:Number;
    private var per:Number;

    // _______________________________________________________________________
    // main constructor
    public function Main()
    {
    init();
    }

    // _______________________________________________________________________
    // initialize
    private function init():void
    {
    //Setup stage.
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.quality = “BEST”;

    //Setup viewport, add to stage
    viewport = new Viewport3D(0,0,true);
    addChild(viewport);

    //Setup renderer
    renderer = new BasicRenderEngine();

    //Setup camera
    camera = new Camera3D();
    camera.z = - 200;
    camera.zoom = 12;

    //Setup light
    light = new PointLight3D(true);
    light.x = 50
    light.y = 50
    light.z = 50
    //Setup scene
    scene = new Scene3D();

    //add dae object
    daeFile = new DAE()
    daeFile.load(”Object.dae”);

    daeFile.scaleX = daeFile.scaleY = 80
    daeFile.scaleZ = 80
    daeFile.x = 0
    daeFile.y = 0
    daeFile.z = 0

    //add loading listeners to your dae
    daeFile.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
    daeFile.addEventListener(FileLoadEvent.LOAD_ERROR, handleLoadError);
    daeFile.addEventListener(FileLoadEvent.LOAD_PROGRESS, handleProgress);
    daeFile.addEventListener(FileLoadEvent.SECURITY_LOAD_ERROR, handleSecurity);
    daeFile.addEventListener(FileLoadEvent.COLLADA_MATERIALS_DONE, handleMaterialsDone);

    //Setup container, add dae to container, add container to scene.
    universe = new DisplayObject3D();
    universe.addChild(daeFile);
    scene.addChild(universe);
    //

    bumpMapGen = new BumpmapGenerator()
    //Listen to enter frame
    addEventListener(Event.ENTER_FRAME, handleRender);
    }

    // _______________________________________________________________________
    // collada load event listeners

    private function handleLoadComplete(e:Event):void
    {
    trace(”IN EVENT LISTENER, LOAD COMPLETE”);

    messageText.text = “COLLADA LOAD COMPLETE”;

    };

    private function handleLoadError(e:Event):void
    {
    messageText.text = “THERE HAS BEEN A LOADING ERROR”;
    };

    private function handleProgress(e:Event):void
    {
    bl = e.target.bytesLoaded;
    bt = e.target.bytesTotal;
    per = Math.round(bl/bt*100);
    messageText.text = “COLLADA “+per+”% LOADED, PLEASE WAIT”;
    };

    private function handleSecurity(e:Event):void
    {
    messageText.text = “THERE HAS BEEN A SECURITY ERROR”;
    };

    private function handleMaterialsDone(e:Event):void
    {

    messageText.text = “COLLADA MATERIALS LOAD COMPLETE”;
    };

    // _______________________________________________________________________
    // render on enterframe

    private function handleRender(e:Event):void
    {
    //rotate and render!
    /*universe.yaw(1);
    universe.pitch(1);
    universe.roll(1)*/
    renderer.renderScene(scene,camera,viewport);

    //DAE IN PV3D GREATWHITE COMPLETE!
    }
    }
    }

    I load here a model created in swift3d, or in other 3D modeling software. A would like to make the model to have a similiar look as in the modeling software. Because I only get flat colors.

    thanks
    Ador

    By Ador on Apr 29, 2008

  22. Another question.
    Can i get teh width and height of a collada obeject in papervision. A have to detect collision between obejcts, and i plan to use the wow engine, and link wow objects with the collada objects. But, to make wowBox with the same dimensions of the collada boject i have to know the dimensions of the collada object.
    Can i get the boundingbox of the collada object?
    Please, if you know any way to do this, tell me!
    It’s wery important to me!
    Thanks

    By Ador on Apr 29, 2008

  23. hi,

    total noob here. how does flash know where your dae file is if it is sitting on a folder in your desktop - are you supposed to import it into flash somehow before using the code above?

    A

    By amir on May 1, 2008

  24. continued from above: … or is it as simple as saving your flash file to the same directory as the DAE?

    By amir on May 1, 2008

  25. Anyone an idea how to put a video texture on a dae-cylinder ? please help…

    By panoman on May 4, 2008

  26. Hi, i’m playng around with collada too, does anybody ever had a dae object with tiled texture on it ? i can’t get it working anyway…

    thank u for interest :)

    By hierro on May 8, 2008

  27. thanks a lot for this important code, but i have a problem when a i run the .fla this is the error i have

    location
    triangleMaterial.as line 24

    description
    1020: Method marked override must override another method.

    source
    override public fuction drawTriangle(Face3d:Triangle3d,graphics:Graphics
    please somebody help with this

    By Pedro consuegra on May 10, 2008

  28. Having trouble getting the DAE to be visible in the browser once the files are uploaded to the web. Any thoughts?

    By csmithcg on May 20, 2008

  29. I just downloaded a couple of the basic models from the Collada Test Bank http://www.collada.org/owl/

    I copied the .dae file into the same directory as your Main.as code and changed line 128 in Main.as to reflect the new .dae file name.

    error:1119 “Access of possibly undefined property renderRect through a reference with static type org.papervision3d.core.geom.renderables:Particle.

    Location: RectangleParticleCuller.as, Line 35

    Any ideas? Are the dae files not formatted right or something?

    By brianemsu on May 30, 2008

  30. I made an object in Blender, with a basic texture and a spotlight and it looks alright in Blender. But when I bring it into Flash CS3 with DAE in Papervision3D, the object only shows the color of the texture…no reflections or shadows. How can I get light to “play” on an object loaded with DAE? If I export with the “Use UV Image Mats” option selected I just get a wire frame.

    Is it something on the Blender side or the Papervision side?

    By the way, here’s a good tutorial on using textures with Blender and Papervision:

    http://www.alteredegg.com/cms/index.php?option=com_content&task=view&id=42&Itemid=18

    By Joey on Jun 30, 2008

  31. I made a little city from 3D max and exported it into .dae, use it in papervision. All works well, material and models are all loaded.

    The problem is, some of the mesh in the models are missing, i tried to fix it by adding some more mesh in the models but the result is still the same? Could anyone help me?

    By Joshua on Sep 10, 2008

  32. Hi there, my models were loaded but at some angles it shows weird. Can you tank a look please?

    http://duplodesign.com/v3/dd2008.html

    http://duplodesign.com/v3/models/ if you want to see the models.

    Regards

    By Vortek on Oct 2, 2008

  33. Hi Vortek,

    From what I can see, it doesn’t look like your problem has anything to do with the models, but rather a problem with your camera focus/zoom settings. Try adjusting those and let me know if you find that helpful-

    cheers!

    By Thomas on Oct 2, 2008

  34. Hi again thomas,

    I’ve updated the code to be able to change the camera focus too but i can’t see any difference between focus and zoom.

    Any help would be great. Thanks again.
    Regards!

    By Vortek on Oct 3, 2008

  35. I am not getting any errors when loading the collada or anything but when I upload everything to the server…the dae file is not found…the pathing is correct…the browser simply indicates that the file doesn’t exist…any ideas why this would be happening?

    By Adam on Oct 20, 2008

  36. I have the exact same problem as Adam. Everything works locally, but when I upload them to a ftp server, it told me can’t find the .dae file. “the browser simply indicates that the file doesn’t exist”….. Any idea?

    By Xiaolin on Dec 4, 2008

  37. Hey, Adam

    I have solved my problem by asking my colleague to add .dae file to the server that is reading it. Apparently, the server has to be configured to read .dae file I think. I have asked my colleague exactly how he did it. When I got the answer, I will let you know :)

    Best
    xiaolin

    By Xiaolin on Dec 4, 2008

  38. remarks regarding local / remote issues :
    check your compiler use-network variable is set :
    false for local file access
    true for net access

    By sancelot on Mar 13, 2009

  39. hi, i’m new from papervision3d…and i have this free tutorial of a flartoolkit, http://saqoosha.net/en/flartoolkit/start-up-guide/
    is very intresting but i need to know how i can change an object…i try to export .dae on max but i need an hand to change the scrips and where to but the file….coul anyone help me?:) thanks

    By dino roselli on Mar 17, 2009

  40. hi! I’m new with papervision3D, i’m using flash CS3 and maya 2009, with the respective plugins installed (the pavervision and collada).
    For a start i’ve exported a cube, with the following options enabled: relative paths and triangulate, till now everything seems to work fine. The problem is when i try to import it to flash, it throws this error:

    DisplayObject3D: null
    Papervision3D Beta 1.5 (23.07.07)

    DisplayObject3D: null
    COLLADA file load error Error #2032: Stream Error. URL: /Volumes/Mac HD/Users/Desktop/Teste_flash_papervision/ppv_teste/scenescube_test05.dae

    I have all files contained in the same folder, including the .dae and the maya scene file.
    Can anyone tell me what am i doing wrong?

    Thank you

    By Kawaii on Mar 30, 2009

  41. For example, with IIS, you must add .dae to the allowed MIME extensions on the server or you will get a 404 exception when trying to access.

    IIS Manager, (Run as admin), select site, features view, Mime Types, Add, .dae, application/octet-stream works.

    With Apache, you’d use ‘AddType’ directive.

    By Frediano on May 30, 2010

  42. Hey ador did you find out why there were flat colours to your object and how did you overcome it

    By lisa on Nov 27, 2011

Post a Comment