Hi, i want to assign diferents materials to child meshes, i can
rotate them but assigning material is not working. any help is
appreciated.
in the _onSuccess function, i am trying to assign one material to all
meshes with name "vidrio", and the others a default material, in 3ds i
export with the names assigned, and after loading, using the
basic_loadmodel as reference, i can rotate the childs whos names are
"vidrio", but can't assign materials.
the code is:
package
{
import away3d.cameras.*;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.core.render.*;
import away3d.core.utils.*;
import away3d.debug.AwayStats;
import away3d.events.*;
import away3d.exporters.*;
import away3d.lights.*;
import away3d.loaders.*;
import away3d.materials.*;
import away3d.primitives.*;
import flash.display.*;
import flash.events.*;
import flash.geom.Vector3D;
import flash.system.*;
public class Porfa extends Sprite
{
protected var _camera : HoverCamera3D;
protected var _view : View3D;
private var _loader : LoaderCube;
private var _cube:Cube;
private var _plane:Plane;
public var sphere:Sphere;
private var material:ShadingColorMaterial;
private var material2:ShadingColorMaterial;
private var aw:AwayStats;
private var model:ObjectContainer3D;
public var _luces:ObjectContainer3D;
private var _dirLight:DirectionalLight3D;
public function Porfa() {
super();
_createView();
initMaterials();
_createScene();
}
private function initMaterials():void
{
material = new ShadingColorMaterial(0xFF0000,
{diffuse:0xFFFFFF,
specular:0xFFFFFF, alpha:1});
material2 = new ShadingColorMaterial(0xcccccc,
{diffuse:0xcccccc,
specular:0xFFFFFF, alpha:0.2});
}
protected function _createView() : void {
_camera = new HoverCamera3D();
//_camera.distance = 12000;
_camera.distance = 7000;
_camera.tiltAngle = 10;
_camera.panAngle = 180;
_view = new View3D();
_view.x = 400;
_view.y = 300;
_view.camera = _camera;
addChild(_view);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
protected function _createScene() : void {
_plane = new Plane ;
_plane.yUp = true;
_plane.material = material;
_plane.segmentsW = 10;
_plane.segmentsH = 10;
_plane.width = 7000;
_plane.height = 3000;
_plane.bothsides = false;
_plane.segmentsW = 10;
_plane.segmentsH = 5;
_view.scene.addChild(_plane);
_view.renderer = Renderer.INTERSECTING_OBJECTS;
var aw:AwayStats=new AwayStats();
aw.registerView(_view);
addChild(aw);
Debug.active = true;
_loader = new LoaderCube();
var url : String = '../models/boxes.3DS';
_loader.addEventListener(Loader3DEvent.LOAD_SUCCESS,
_onSuccess);
_loader.loadGeometry(url, new Max3DS());
_loader.scale(10);
_loader.material= material;
_view.scene.addChild(_loader);
_luces=new ObjectContainer3D();
_view.scene.addChild(_luces);
_dirLight = new DirectionalLight3D ;
_dirLight.direction = new Vector3D(3000,-10000,3000);
_dirLight.specular = .1;
_dirLight.diffuse = 0.5;
_dirLight.ambient = 0.5;
_dirLight.brightness = 1;
_luces.addLight(_dirLight);
}
protected function _onEnterFrame(ev : Event) : void {
if (model) {
for each (var object:Object3D in
model.children) {
if (object.name.indexOf("vidrio") != -1)
object.rotationZ += 10;
}
}
_camera.panAngle += (stage.mouseX - stage.stageWidth/2)
/ 100;
_camera.hover();
_view.render();
}
protected function _onSuccess(ev : Loader3DEvent) : void
{
var mat1:PhongColorMaterial = new
PhongColorMaterial(0xFF0000,
{shininess : 1,specular : 1, alpha:1});
var mat2:PhongColorMaterial = new
PhongColorMaterial(0xcccccc,
{shininess : 1,specular : 1, alpha:1});
model = _loader.handle as ObjectContainer3D;
for each (var object:Object3D in model.children) {
if (object.name.indexOf("vidrio") != -1){
object.material = mat1;
}else{
object.material = mat2;
}
}
}
}
}