Getting Blender 2.58 into Away3D

Software: Away3D 3.x

FlashGuy, Newbie
Posted: 06 August 2011 08:03 PM   Total Posts: 3

Hello everyone, I’m new to Away3D and 3d in flash in general, so I apologize in advance for noob mistakes.  However, I am trying to get a blender file into away3d and it is not working.

I’ve tried exporting from blender (and 3ds Max) in collada, and obj, and I can view the files in prefab3D, but they are completely white instead of using the materials assigned to the model in blender.  When I try to import these files into away3d, I get an error at Loader3d/loadTextures().  The model doesn’t use any external images, just the materials, and it doesn’t use any textures either; there is no <library_images> in the collada, just a <library_materials>.  Any help would be appreciated.

   

Avatar
Choons, Sr. Member
Posted: 06 August 2011 10:21 PM   Total Posts: 281   [ # 1 ]

one thing you will find with obj files is the 3.6 parser imports Blender exported obj files reversed. I prefer to export 3ds files from blender for use in Away3D. In general you will also find it better to apply materials to models from within Away3D. I generally make an ObjectContainer3D to hold the mesh(es) of the model and parse it in like this:

myObjContainer3D = Max3DS.parse(Cast.bytearray(myModel), { autoLoadTextures:false } );

then to apply materials I do

for each (var child:Mesh in myObjContainer3D.children) {
    child.material = myMaterial
}

That autoLoadTextures:false value can save you a lot of headaches. It also allows you to use any materials you want, not just what you put on the model in Blender. You do of course have to load in the images in Away3D and put them in your materials first. If you have multiple mesh objects in your model, make sure to name them in Blender and you can also do a if(child.name = “soandso”) child.material = materialForSoandSo. A quirk I found with Blender 3ds models is even if you don’t use them in Away3D, the model needs a material assigned, and an image texture before you export or you just get a black model that won’t recognize any materials you assign to it.

I highly recommend these books:

The Essential Guide to 3D in Flash
Away3D 3.6 Essentials
Away3D 3.6 CookBook

I would have never figured out how to get started without them. Now I’m getting paid to create Flash 3D content. Good luck- the learnng curve is a bit steep, but once you get it it’s amazing.

 

   

FlashGuy, Newbie
Posted: 07 August 2011 01:36 AM   Total Posts: 3   [ # 2 ]

Hey, thank you very much for you’re reply, you’ve definitely set me on the right track.  I’m getting those books, so hopefully in the future they will answer most of my questions.  smile

I switched to the .3DS format and embedded the model, then parsed it as you demonstrated.  I don’t get the texture errors anymore, instead I get output like this (the model is very large, so this is only a portion of the output):

+ Material Type : shadingMaterial
+ Build Material : Material_007_mat
+ Material Type : shadingMaterial
+ Build Material : Material_004_mat
+ Material Type : shadingMaterial
+ Build Mesh : Governors_
+ Build Mesh : Governors0
+ Build Mesh : Governors1

So it sounds like it’s working, but I still don’t see anything on the screen.  Just wondering if it is loading and parsing the file correctly so I can try and find the problem. 

Also, does embedding the model require the Flex SDK?  Flash initially threw an error for this code (public static const MAXFILE:Class;) saying it needed Flex, but it quit saying that after I let it use it’s default directory.  I’m working in Flash professional.  If that isn’t it, I probably just messed something up with the view, scene, or camera, something like that.  Here is the code if you feel like checking it for me, any help is really appreciated.  I’ve spent days trying to get the collada and obj files to load correctly, there doesn’t seem to be much documentation.  I would attach the files, but the 3ds is too big.  Here is the class:

public class test extends Sprite
{
      Embed (source=“house.3DS”, mimeType=“application/octet-stream”)]
  public static const MAXFILE:Class;
  private var loader:Loader3D;
  private var view:View3D;
  private var mesh:Object3D;
  //private var scene:Scene3D;
  private var camera:Camera3D;
  private var model:ObjectContainer3D;
 
  public function test():void
  {
  Debug.active = true;
  var mat:ColorMaterial = new ColorMaterial(0xff0000);
  camera = new Camera3D();
  model = Max3DS.parse(MAXFILE,{  texturePath:”“, material:mat, autoLoadTextures:false, scaling:1, y:0, x:0, z:0 });
  view = new View3D({x:1280, y:800, renderer:Renderer.BASIC});
  addChild(view);
  view.scene.addChild(model);
  view.camera.position = new Vector3D(0, 0, 1000);
  view.camera.lookAt(model.position);
  view.render();
  }
}

 

   

Avatar
Choons, Sr. Member
Posted: 07 August 2011 02:03 AM   Total Posts: 281   [ # 3 ]

I think you are very close to getting it. One thing that you need to realize is that materials need a bitmap object. When you use preFab, hit that Windows button in the top menu after you load a model and have a look at the Process log. It gives good info on what Away3D is looking for materials-wise from your model. Since you have the embedding part down, do the same for your materials in jpg or png format and create materials from them. Declare a material variable

var my_mat:BitmapMaterial;

and say you embedded an image to use as a material with a class name MyImage then you would

my_mat = new BitmapMaterial(Cast.bitmap(MyImage));

and use that like I said above.

By the way, your view.render call needs to be in an onEnterFrame function that gets updated every frame. So your typical code flow is going to be load the model, assign materials to it, and then add an

addEventListener(Event.ENTER_FRAME, onEnterFrame);

where you put your view.render call

   

Avatar
Choons, Sr. Member
Posted: 07 August 2011 02:07 AM   Total Posts: 281   [ # 4 ]

also before I got the books, I made great headway by studying the examples code and cherry-picking what I needed out of it so check that out too

   

Avatar
Choons, Sr. Member
Posted: 07 August 2011 02:31 AM   Total Posts: 281   [ # 5 ]

as for your question about FLEX, Flash uses flex in the background, they just don’t tell you that since they want people to think Flash works somehow differently and keep buying it wink

   

FlashGuy, Newbie
Posted: 07 August 2011 11:49 AM   Total Posts: 3   [ # 6 ]

Yea, everything seems right except the materials…  The problem there is that the model doesn’t use a bitmap or png that I can include, all the materials are defined inside blender.  For example, in the generated .mtl file that goes with the .obj the materials look like this:

# Blender MTL File: ‘house.blend’
# Material Count: 6
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.226197 0.230632 0.130231
Ks 0.159266 0.147491 0.077682
Ni 1.000000
d 1.000000
illum 2

There are no references to external bitmaps or pngs.  It’s the same in the collada, the materials are defined like this:

<material id=“Material_006-material” name=“Material.006”>
    <instance_effect url=”#Material_006-effect”>
  </material>

:/  Any suggestions?  I’ve been searching for a way to export the blender materials as bitmaps or pngs, but no luck there.  I guess that’s why prefab always shows the models as being white.  I will post the prefab process log later.

   

skitley, Newbie
Posted: 07 August 2011 04:24 PM   Total Posts: 6   [ # 7 ]

I havent been able to get Away3D to work yet, but I think this is more of a Blender question now…

My planned approach to a workflow will involve unwrapping my objects and saving out the image from the UV/Image editor in blender. You can save out images as a .png (or whatever) and use that as an asset in your Flash/Actionscript project. If you go to http://www.blendercookie.com/ they ,have plenty of tutorials you can view to learn how to create and export textures (tutorials > textures).

The only thing I dont know about this process is what type of maps are supported by Away3D and how you would apply those UV transformations. Basically, I’m guessing here and assuming Away3D works like other 3D engines going from models/textures to the code. That’s the part I haven’t been able to get working yet in order to experiment/test.

(EDIT)
Looking over the Away3D tutorials briefly it looks like the above workflow should be good to go… Otherwise, here’s the basic UV/unwrapping intro video linky:
http://www.blendercookie.com/2011/01/21/intro_uvmapping/

   

Avatar
Choons, Sr. Member
Posted: 07 August 2011 04:56 PM   Total Posts: 281   [ # 8 ]

yeah gotta use bitmap materials. here’s a thread from a while back that may help.

http://away3d.com/forum/viewthread/94/

   

Avatar
Choons, Sr. Member
Posted: 07 August 2011 05:01 PM   Total Posts: 281   [ # 9 ]

also another quirk if using 3ds is that format only supports 8 character material names so keep that in mind. That log in preFab hipped me to that one when I could see it was truncating the material file name. redbricks.jpg
became redbricks.jp

   

FlashGuy, Newbie
Posted: 08 August 2011 03:21 PM   Total Posts: 3   [ # 10 ]

Alright, thanks guys.  I will ask the artist to UV unwrap everything and ship over the jpg or pngs.  It should be easy then to apply them to the mesh.  Do you know if Away3D will load materials from .mtl .dae or .3ds files in the future without needing the bitmaps?

I’ll keep in mind that 3ds truncates the names, could have been a nasty issue.  smile  Thanks again for the help, I’m pretty confident I’ll be able to get it to work once I get the bitmap materials.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X