Everyday 3D

Creative use of technology // A blog about 3D Flash and Actionscript by Bartek Drozdz

From Blender to Papervision3D

Here is a simple wheel I created using Blender. The wheel is exported from Blender as as COLLADA object (*.dae file).

Use Cursor Keys to rotate the model, and Space to roll.

Along my way of creating this stunning artwork :) I came on to some difficulties with Blender and the Collada plugin. Such problems are always frustrating, so here are some notes that may help:

  1. Do not install the latest Blender release (2.45 at the time I write this). Use 2.43 instead, as the Collada 1.4.1 script is not working properly in the newest one.
  2. You need also to install the Python programming language because the Collada script needs some libraries that are not part of the Blender distribution. You need to set some environment variables in order make it work, but the Blender documentation mentions only one, PYTHON, which does not seem enough. After some research I found out that you need tow of them:

    PYTHON=[path to python.exe in the python instaloation folder]
    PYTHONPATH=[path to python instalation folder and some other folders]

    On my computer it looks like this:

    PYTHON=”C:\Program Files\Python\python.exe”

    PYTHONPATH=C:\Program Files\Python;C:\Program Files\Python\DLLS;C:\Program Files\Python\LIB;C:\Program Files\Python\LIB\LIB-TK

  3. If you do not know anything about Blender (like me) check out this tutorial. I helped me alot.

UPDATE May 17th 2008. Source code. I decided to publish the source for this example. Grab it here.

Categories: 3D, Blender, Papervision3D

comments RSS

13 Comments

  1. That’s great – I’ve just managed to load up my first dae from Blender into papervision, but I can’t work out how to access the object for position, rotation etc…

    Here’s my .as file –

    package {

    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.Event;

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.Collada;
    import org.papervision3d.scenes.MovieScene3D;

    public class collCube extends Sprite
    {

    public var scene:MovieScene3D;
    public var camera:Camera3D;
    public var dae:Collada;
    public var myobject:DisplayObject3D;

    public function collCube() {
    init();
    }

    private function init() {
    //basic scene stuff
    var container:Sprite = new Sprite();
    container.x = 200;
    container.y = 200;
    addChild( container );

    scene = new MovieScene3D(container);

    camera = new Camera3D();
    camera.z = -500;
    camera.zoom = 5;

    var dae = new Collada(“cube.dae”);
    var myobject = new DisplayObject3D();

    myobject.addChild(dae);
    scene.addChild(myobject);

    stage.addEventListener(Event.ENTER_FRAME, runtime);

    }

    private function runtime(e:Event):void {
    //WHAT CODE DO I USE HERE?
    //dae.Cube.rotationX += 5;
    scene.renderCamera(camera);

    }
    }
    }

    Would love it if you could help me out – or even better – post the code from your example.

    Cheers

    Karl

  2. In my code it goes something like this:

    cola = new Collada(“model.dae”);
    colaHolder = new DisplayObject3D();
    colaHolder.addChild(cola);
    scene.addChild(colaHolder);

    and then I modify the colaHolder properties such as rotation, postion etc… Anyway, I updated the post with the source files (see above), so grab them and check them out!

  3. Thanks Bartek, that’s a great help! I’d managed to do it using the PV3D components, but this way seems to have more flexibility – eg for combining collada objects and PV primitives. Have you had any success exporting meshes with armature animations as colladas from Blender? Can’t get those to work either…
    Can’t wait for Blender 2.46 by the way.

    Cheers

    Karl
    http://www.twodotsinacircle.com
    check it out

  4. [...] Este tutorial nos explica ¿cómo pasar un modelo de Blender*? a una aplicación de PaperVision3D. :-) [...]

  5. vitaLee

    hi Bartek.
    where are suppose to set these python paths you were talking about?

  6. @vitaLee These are the windows system environment variables.

    On an XP machine you set them by right-clikcking the ‘My Computer’ icon, choosing the ‘Advanced’ tab and then ‘Environment variables’ at the bottom.

    You will see 2 panels, one for user variables on the top, other for system variables on the bottom. I added the Python related variables to the system ones so that they are available for every user.

  7. MikeTheVike

    Have you tried using the newest version of Blender? I think they might have fixed it. I successfully exported a dae file and loaded it into Papervision.

  8. @MikeTheVike No, I haven’t. But I intend to go back to the Blender/PV3D topic later this month, so I will check that and maybe update this post. Thanks!

  9. [...] be bugged as well, as I wrote the last time, with faulty animation. And while there’s tons of options for exporting Blender models into PV3D, none seems to include [...]

  10. scheggia

    hi, i am projecting a game with at maximum 36 cones and 5*36 circles. if i use PV3D to buil the objects are about 36*5+5*6*36=1360 triangles and the game appears slow, too much slow! do you think that importing the 3d object with blender could be faster?

  11. @scheggia it’s the polygon count that’s important, not where the models come from, so making them in Blender would not help. On the other hand 1360 tris is not very many…

    Suggestions:
    - try setting Stage.quality to LOW
    - if you can, switch from pv3d to away3d or away3dlite – this engine, in the fp10 version, is significantly faster

  12. [...] be bugged as well, as I wrote the last time, with faulty animation. And while there’s tons of options for exporting Blender models into PV3D, none seems to include [...]

  13. Nabil

    Hello, im trying to put a Loader im my Flash builder augmented reality. Someone can help me, where can I insert the loader im my code.

    following my code:

    package
    {
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.filters.GlowFilter;

    import org.papervision3d.core.proto.MaterialObject3D;
    import org.papervision3d.events.FileLoadEvent;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.BitmapMaterial;
    import org.papervision3d.materials.shadematerials.EnvMapMaterial;
    import org.papervision3d.objects.parsers.DAE;
    import org.papervision3d.objects.primitives.Plane;

    [SWF (width="640", height="480", backgroundColor="0x000000",frameRate="30")]

    public class GRINGO extends AR_AlchemyBase
    {
    public var dae : DAE;
    public var shadowPlane : Plane;

    [Embed (source="/../assets/envmap-livingroom.jpg")]
    private var EnvMap : Class;

    [Embed (source="/../assets/torusshadow.jpg")]
    private var ShadowBitmap : Class;

    override public function addSceneObjects():void
    {
    dae = new DAE();
    dae.load(“assets/toro.dae”);
    dae.z -=0;
    dae.rotationX = 270;
    dae.scale=0.7;

    dae.addEventListener(FileLoadEvent.LOAD_COMPLETE, daeLoadComplete);

    shadowPlane = new Plane(new BitmapMaterial(new ShadowBitmap().bitmapData),100,100,4,4);
    //shadowPlane.rotationZ= 45;

    onImageFound = fadeIn;
    onImageLost = fadeOut;

    }

    override public function enterFrame(e:Event):void
    {
    dae.yaw(0);
    //shadowPlane.roll(3);
    super.enterFrame(e);
    }

    public function daeLoadComplete(e:FileLoadEvent) : void
    {
    trace(“DAE LOADED!”);
    trace(dae.materials);

    var newmaterial : MaterialObject3D;

    var envmap : BitmapData = new EnvMap().bitmapData;
    var light : PointLight3D = new PointLight3D();
    newmaterial = new EnvMapMaterial(light, envmap, envmap,0);
    dae.replaceMaterialByName(newmaterial, “torus_texture”);
    dae.useOwnContainer = true;
    dae.filters = [new BlurFilter(1.2,1.2,4)];

    container.addChild(dae);

    shadowPlane.useOwnContainer = true;
    shadowPlane.blendMode = BlendMode.MULTIPLY;
    shadowPlane.alpha = 0.4;
    shadowPlane.scale = 1.5;
    container.addChild(shadowPlane);

    }

    public function fadeIn() : void
    {
    if(dae.alpha0) dae.alpha-=0.1;
    shadowPlane.alpha = dae.alpha * 0.4;
    }

    }
    }



  • FATC2011


  • FITC2011


  • FITC2010


  • FITC2010