Changing ColorMaterial for meshes from asd files.

Software: Away3D 4.x

Shaedo, Newbie
Posted: 25 December 2013 11:26 AM   Total Posts: 9

Hi, For any advice or direction on this I would be supremely grateful:

I’m trying to modify the ColorMaterial for a mesh extracted from loading the asd class generated (essentially) from Prefab3D as below.

var myClass:MyClass=new MyClass();
var 
v:Vector.<Mesh>=myClass.meshes;
var 
m:Mesh=v[0];
m.material=new ColorMaterial(0x00FF00,.5);
view.scene.addChild(m); 

Why isn’t the myClass now green?
This works fine on meshes from awd2 files that I load.
I’m also trying to change the lightpicker and specular of the materials with no result.

This also (unsurprisingly) has no effect:

for each (subMesh in m)
{
 subMesh
.material=new ColorMaterial(0x00FF00,.5);
 
subMesh.material.lightPicker=staticLightPicker;
 
ColorMaterial(subMesh.material).specular=.1;

Should I simply go back to to using awd2 files?

Incidentally I’ve been generating my awd2 files using AwayBuilder rather than Prefab because the AwayBuilder awd2 files are about half the size (I assume because of their compression?), and I only need the meshes as I apply ColorMaterials on the fly. Being able to create asd style classes with only the mesh data would be fantastic and any advice on how to go about this would be extremely welcome.

Thank you for your consideration!

   

Avatar
Fabrice Closier, Administrator
Posted: 25 December 2013 01:37 PM   Total Posts: 1260   [ # 1 ]

Depending on your export settings, your code might be overwritted.
For instance, if your export has the some material set and you run your code.
What possibly is happening is that you get : init, set the custom material, the class has loaded something and assigns the material overwritting in the process what you just did. So if you plan to define all materials by code, make sure you export only the geometry.

awd vs as3. The idea behind the as3/asd is to give you a greater freedom than using awd’s. They do not require loaders and init much faster on mobiles. That doesn’t say one is better than the other. Its all about what your project requirements are, where you publish and personal preferences. (note: Prefab’s next version will bring you an update of asd’s with even greater init times and lower sizes, both version will load back in Prefab for eventual edits)

As about the awd exports being smaller. This is something that next update will fix as well. The diff is indeed caused by compression option lzma that wasn’t offered at the time Prefab awd exporter was written. There were not enough 11.3+ users yet.

   

Shaedo, Newbie
Posted: 25 December 2013 02:45 PM   Total Posts: 9   [ # 2 ]

Thanks Fabrice! I read in some of your other posts that asd was faster, thought I’d give it a try, and I was genuinely blown away with my brief tests. Massive respect to you.

I’m still searching for how to ‘export only the geometry’ any pointers on where to select this in Prefab3D?  [Exports] -> [Prefab Files] -> [Prefab3D ASD] ?

I created a bare-bones class that tries to set the material every frame but it seems that the mesh (or reference to the mesh?) is somehow lost each frame:

package 
{
 import flash
.events.*;
 
import flash.display.*;

 
import away3d.entities.Mesh;
 
import away3d.core.base.SubMesh;
 
import away3d.core.partition.MeshNode;
 
import away3d.containers.View3D;
 
import away3d.lights.*; //Pointlight
 
import away3d.materials.lightpickers.StaticLightPicker//
 
import away3d.library.AssetLibrary;
 
import away3d.materials.*; // ColorMaterial, TextureMaterial

 
import MyClass;

final public class 
MainMenu extends MovieClip
{
 
private var view:View3D;
 private var 
staticLightPicker:StaticLightPicker;
 private var 
directionalLight:DirectionalLight;

 var 
myClass:MyClass
 var 
myMesh:Mesh;

 public function 
MainMenu()
 
/*CONSTRUCTOR*/
 

  
/*setup stage, camera, lights*/
  
directionalLight=new DirectionalLight();
  
directionalLight.ambient=0.1;
  
staticLightPicker=new StaticLightPicker([directionalLight]);
  
view=new View3D();
  
view.camera.z=-1000;
  
view.scene.addChild(directionalLight);
  
addChild(view);
  
  
/*Instantiate asd-class 'myClass'*/
  
myClass=new MyClass(); //create instance of asd class
  
var v:Vector.<Mesh>=myClass.meshes// use get meshs 
  
var myMesh:Mesh=v[0]//
  
myMesh.material=new ColorMaterial(0x00FF00,.5);
  
ColorMaterial(myMesh.material).lightPicker=staticLightPicker;
  
ColorMaterial(myMesh.material).specular=.1;
  
view.scene.addChild(myMesh);
  
trace(myMesh);
  
  
addEventListener(Event.ENTER_FRAME,render,false,0,true);
  
stage.addEventListener(MouseEvent.CLICK,clickHandler,false,0,true);
 
}
 
private function render(e:Event):void
 {
  view
.render();

  
trace('!!'+myMesh);//null
  
var v:Vector.<Mesh>=myClass.meshes;
  var 
myMesh:Mesh=v[0];
  
myMesh.material=new ColorMaterial(0x00FF00,.5);
  
ColorMaterial(myMesh.material).lightPicker=staticLightPicker;
  
ColorMaterial(myMesh.material).specular=.1;
  
view.scene.addChild(myMesh);
  
trace('??'+myMesh);//[object Mesh]
 
}
 
private function clickHandler(e:MouseEvent):void
 {
  
while(view.scene.numChildren)view.scene.removeChildAt(0); // removes mesh until render() is called and mesh is restored - no visible change
 

I’m using version 2.143 of Prefab and Away3D 4.1.4

   

Avatar
Fabrice Closier, Administrator
Posted: 26 December 2013 02:38 PM   Total Posts: 1260   [ # 3 ]

myMesh is declare as class var “var myMesh:Mesh;”. In your constructor code, you define it as: var myMesh:Mesh=v[0];...  change it by myMesh = v[0]; and it will not be null in your render function.

To export geometry only just unselect the export dependencies option.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X