The Cornerstone for Creative Christians
AlteredEgg.com
Home
Blender Collada models for Papervision3D - revisited
Article Index
Blender Collada models for Papervision3D - revisited
Page 2
Page 3

 Using Plain Code

 Again, for those of you who just want something to build upon, use this code. Big thanks to Mr. Doob for the base code which I modified for this.

Create a new AS3 document and save it in the same directory as your .dae (Collada) model. 

Create a nice looking movieclip to use for a material and then select it in your Library. Right-click it and select Properties. Check the "export for Actionscript" box, and enter "MyMCMaterial" into the class field.

Create a bitmap material by placing an image in your library. Right-click it and select Properties. Check the "export for Actionscript" box, and enter "MyBitmapMaterial" into the class field.

Then just copy>paste the code below into frame 1 of your timeline. Just view the comments to understand what's going on.

Applying Materials to Collada Models
  1. import flash.display.*;
  2. import flash.display.stage.*;
  3. import flash.events.*;
  4. import flash.geom.ColorTransform;
  5. import flash.utils.Dictionary;
  6.  
  7.  
  8. // Import Papervision3D
  9. import org.papervision3d.core.proto.*;
  10. import org.papervision3d.scenes.*;
  11. import org.papervision3d.cameras.*;
  12. import org.papervision3d.objects.*;
  13. import org.papervision3d.materials.*;
  14.  
  15. // ___________________________________________________________________ 3D vars
  16.  
  17. var container :Sprite;
  18. var scene     :MovieScene3D;
  19. var camera    :Camera3D;
  20. var i:Number;
  21.  
  22. var item:DisplayObject3D;
  23. var city:Collada;
  24.  
  25. var material1:ColorMaterial;
  26. var material2:MovieMaterial;
  27. var material3:BitmapMaterial;
  28.  
  29. stage.quality = StageQuality.HIGH;
  30. stage.scaleMode = StageScaleMode.NO_SCALE;
  31. init3D();
  32. createScene();
  33.  
  34. // ___________________________________________________________________ Init3D
  35.  
  36. function init3D():void {
  37.   // Create container sprite and center it in the stage
  38.   container = new Sprite();
  39.   addChild( container );
  40.   container.x = 320;
  41.   container.y = 240;
  42.  
  43.   // Create scene
  44.   scene = new MovieScene3D( container );
  45.  
  46.   // Create camera
  47.   camera = new Camera3D();
  48.   camera.zoom = 15;
  49.   camera.focus = 40;
  50.   camera.y = 1000;
  51.   camera.x = 0;
  52.   camera.z = -3000;
  53.  
  54. }
  55.  
  56. // ___________________________________________________________________ Create scene
  57.  
  58. function createScene() {
  59.   // create flat red material
  60.   material1 = new ColorMaterial();
  61.   material1.doubleSided = true;
  62.   material1.fillColor = 0xFF0000;
  63.   material1.fillAlpha = 1.0;
  64.  
  65.   //create movieclip material
  66.   material2 = new MovieMaterial(new MyMCMaterial(),true);//transparency
  67.   material2.animated = true;
  68.   material2.smooth = true;
  69.   material2.doubleSided = true;// you'll notice this if transparency is enabled
  70.  
  71.   // create Bitmap material
  72.   material3 = new BitmapMaterial(new MyBitmapMaterial(2,2));//pass required parameters which are meaningless (the dimensions will come from the library bitmap)
  73.   material3.doubleSided = true;
  74.  
  75.  
  76.   var matList=new MaterialsList();
  77.   matList.addMaterial(material1,"mat0");//second parameter is the name you gave the material in Blender
  78.   matList.addMaterial(material3,"mat1");
  79.   matList.addMaterial(material2,"mat2");
  80.   matList.addMaterial(material3,"mat3");
  81.   matList.addMaterial(material1,"mat4");
  82.  
  83.  
  84.   city = new Collada("testcityUV.dae", matList );//path to your Collada file
  85.   scene.addChild( city, "city" );
  86.   this.addEventListener( Event.ENTER_FRAME, loop );//runs the loop function every frame for live updating. You could change this to only render on demand if desired.
  87.  
  88. }
  89.  
  90. // ___________________________________________________________________ Loop
  91.  
  92. function loop(event:Event):void {
  93.   update3D();
  94. }
  95.  
  96. function update3D():void {
  97.   //camera.x +=((container.mouseX*10) - camera.x) * 0.005;
  98.   city.rotationY+=container.mouseX/50;
  99.   //camera.y +=((container.mouseY*10) - camera.y) * 0.005;
  100.   item=city.getChildByName("building1"); //the name you gave the object in Blender
  101.   item.rotationZ++;
  102.   scene.renderCamera( camera );
  103. }

  There you go! Just comment below if I happen to have missed something and I'll be glad to help.

 





Digg!Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
Comments
Add New Search
ignore
Thomas 2009-11-11 12:01:24

Hi just solved it, ignore last post. I m ight post a link to your great tutorial if u dont mind with an updated zip for getting this to work in flashdevelop with papervision 2.0 and send it to you over email if you want,
my blog is www.thumbleaf.com, cheers

thomas
None
Thomas 2009-11-11 11:55:18

What is the name of the material ?
Using the latest Blender is it mat1, mat2 by default. You dont mention in your Blender tutorial anything about naming:

matList.addMaterial(material1,"mat1& #34;);//second
parameter is the name you gave the material in Blender

I get a model but no texture loading. Is This related to name ? I have modified this to run with papervision 3 (Scene3D) and using Flashdevelop so rewritten to
a straight class...

Cube but only frame outline of it. I'm speaking of your tutorial for exporting from Blender, DAE models. That works fine. But im confused as you in this followupcode for how to import the .dae
suddenly mention something about naming and that is not mentioned in your initial tutorial. So to be clear> what is "mat1" for the cube tutorial. How can I check that I have the right named sides. Are you sure it
is always mat1 ?

I saw something in blender webiste aobut default names being Material.001 etc...?Both tutorials great but please explain the name comment as it snot explained anywhere by you in the blender tutorial and
Im sitting wondering wether im actually targetting something with the right name... Email me please

Thomas
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."



 
< Prev   Next >
[ Back ]

We want your stuff!
Follow us on Twitter:

@confidant_ca (business)
@alteredegg (fun)

Main Menu
Home
What is This Website?
Bookmarks
Send Us Your Stuff!
Why is Jesus So Important?
News, Commentary & Weird
Famous Christian Creatives
Contact Us
Site Map
Interesting Stuff For:
Actors
Animators & Filmmakers
Architects
Artists
Cartoonists
Clothing Designers
Dancers
Graphic Designers
Illustrators
Multimediacs
Musicians
Photographers
Poets
Preachers
Writers
Login Form





Lost Password?