Exporting Models From Blender to Flash Sandy 3D, Experiments in 3D

Last week, reader rafbaf asked how to use Blender models in Sandy 3D. There are a few options, for instance Sandy 3D can import the Collada format that Blender exports. But there is also an easier way. A Python script for Blender allows you to export models straight to ActionScript code. However, as you will see in this post, it’s not as straightforward as it seems.

downloadExample FlashDevelop project.

There’s a reason this post is titled “experiments”. It is actually an unfinished work, but I wanted to give you a look at what I’ve already been able to create. This is how far I got for now:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

  1. First, I got an A-Wing from the blendermodels archive. Before I got the first render result shown in the picture above, I had to fix the normals of most of the meshes in there (in Blender: go into edit mode, select vertices and ctrl-n)
  2. Next, get the export script from Dennis’s page and install it. Take care to get the correct directory, it’s not that easy to find. If you have one of the latest versions of Blender, you should look in your user folder. For Windows that’s “C:Documents and Settings<username>Application DataBlender FoundationBlender.blenderscripts”.
  3. If you haven’t already done so, you also need to have Python installed. Python is necessary to execute the script.
  4. Once you got this out of the way, you will need to restart Blender. Check the file > export menu and verify that the ActionScript option is available. If it’s not, you probably placed the AS3Export.py file in the wrong directory.
  5. Select the object you want to export and click the export to ActionScript menu item. It’s probably a good idea to enter a package name, as this will keep your code cleaner.

Now you should have one or more .as files: one for every mesh and texture in your model. This model doesn’t come with textures, so there are none.

Next we are going to use those files in a FlashDevelop project. The first step is to create a new project in FlashDevelop and put the Sandy 3D library inside the src folder. Like described in previous blog posts.

Now inside the src directory, you should create a directory with the same name as the package you specified in step 5 above. If you forgot the package name or are not sure, you can open one of the files that was created and check the first line.

That’s pretty much it: add the meshes as Shape3D objects to your scene, just like you would add a cube or other shape:

1
scene.root.addChild( new Mesh() );

(you might want to add an appearance too)

You’ll notice I’m skipping a few steps here, but they are all very basic. If you download the example project and read through my previous blog posts, everything should be clear (feel free to comment if it isn’t).

You’ll notice a few issues/problems (correct me if I’m wrong):

  • The 3D object I choose, consists of several meshes. Each with their own texture (material in Sandy3D terminology). The export plugin doesn’t really help you on this point. You need to create every mesh and add them individually to the scene.
  • There seems to be an issue with the normal calculations. I did correct them in Blender as you can see in the small rendering at the top of my post, but still there seem to be missing triangles in the Sandy 3D version.
  • It looks like there is an issue with a bounding box or face culling. I still need to investigate this thoroughly.

To be continued…

downloadExample FlashDevelop project.

This entry was posted in Flash and ActionScript. Bookmark the permalink. Both comments and trackbacks are currently closed.

3 Comments

  1. Anon
    Posted July 30, 2010 at 10:34 pm | Permalink

    It seems that simply using the collada format importing might've been easier after all. Looking forward to some experiments in regards to that.

  2. Posted August 9, 2010 at 12:00 pm | Permalink

    Well yes, probably it would have been. I'm not sure, but I think at the time I did have some incompatibility problems between Blender's and Sandy's Collada code.
    In the meantime I do have some additional experiments ready, it just that I'm currently focused on different projects. But I will return to this sooner rather than later. I love experimenting with 3D.

  3. Posted October 16, 2010 at 2:00 pm | Permalink

    Very informative to learn more tricks about Blender and Flash. Thanks

  • Feedback or questions? Contact me right away.

    Comments have been disabled on my posts. Not because I don't want to hear from you, but because they were adding very little to the conversation (most of them were spam anyway). I do listen to you and try to keep as much posts as possible up-to-date and error free. So if you have a question, if something isn't working the way you hoped or you have general feedback, please use the contact form below. I guarantee an answer to every honest question or remark.
  • Get in touch
    1. (required)
    2. (valid email required)
     

    cforms contact form by delicious:days