newbie basic cube cuestion.

Software: Away3D 4.x

charlito, Jr. Member
Posted: 22 March 2012 01:16 AM   Total Posts: 36

Hi, im still trying to create a cube, with each face with diferent, color.
i tryed some crazy stuff.. like this: (6 cubes next to each other with diferents colors)

public class away3DBasico_v003 extends Sprite
 {
  
public var view:View3D = new View3D();
  
  private var 
cube1:CubeGeometry= new CubeGeometry(100);
  private var 
cube2:CubeGeometry= new CubeGeometry(100);
  private var 
cube3:CubeGeometry= new CubeGeometry(100);
  private var 
cube4:CubeGeometry= new CubeGeometry(100);
  private var 
cube5:CubeGeometry= new CubeGeometry(100);
  private var 
cube6:CubeGeometry= new CubeGeometry(100);
  
  private var 
cubeM1:ColorMaterial;
  private var 
cubeM2:ColorMaterial;
  private var 
cubeM3:ColorMaterial;
  private var 
cubeM4:ColorMaterial;
  private var 
cubeM5:ColorMaterial;
  private var 
cubeM6:ColorMaterial;
  
  public var 
malla1:Mesh;
  public var 
malla2:Mesh;
  public var 
malla3:Mesh;
  public var 
malla4:Mesh;
  public var 
malla5:Mesh;
  public var 
malla6:Mesh;
 
  public function 
away3DBasico_v003()
  
{

   cubeM1
= new ColorMaterial(0xfff000);
   
cubeM2= new ColorMaterial(0x000fff);
   
cubeM3= new ColorMaterial(0xff4500);
   
cubeM4= new ColorMaterial(0xB0C4D0);
   
cubeM5= new ColorMaterial(0xff0000);
   
cubeM6= new ColorMaterial(0xffffff);
   
   
malla1 = new Mesh(cube1,cubeM1);
   
malla2 = new Mesh(cube2,cubeM2);
   
malla3 = new Mesh(cube3,cubeM3);
   
malla4 = new Mesh(cube4,cubeM4);
   
malla5 = new Mesh(cube5,cubeM5);
   
malla6 = new Mesh(cube6,cubeM6);
   
   
addChild(view);
   
   
view.scene.addChild(malla1);
   
view.scene.addChild(malla2);
   
view.scene.addChild(malla3);
   
view.scene.addChild(malla4);
   
view.scene.addChild(malla5);
   
view.scene.addChild(malla6);
   
   
malla1.x+=5;
   
malla2.x-=5;
   
malla3.y+=5;
   
malla4.y-=5;
   
malla5.z+=5;
   
malla6.z-=5;
    
   
view.camera.z+=500;
   
             
this.addEventListener(Event.ENTER_FRAMEloop);
   
  
}
  
  
public function loop(e:Event):void
  {
     
   malla1
.rotationY+=1;
   
malla2.rotationY+=1;
   
malla3.rotationY+=1;
   
malla4.rotationY+=1;
   
malla5.rotationY+=1;
   
malla6.rotationY+=1;
   
   
view.render();
  
}
 } 

but even this.. doesnt work if i rotate the cube..
tryed move all the cubes to the center, but still not working

i know.. there gotta be a better way.. but i just cant find it..

should i export a cube from 3d soft, with each face with a jpg texture??

appreciate all ur help.

thx a lot in advance.

 

   

happy3d, Newbie
Posted: 22 March 2012 03:39 AM   Total Posts: 6   [ # 1 ]

You should draw 6 planes with different color,set their positions ,angels and group them.If it’s possible,add in a container object as chlidren.

or extend’s Cube.override the methoud about UV.i don’t know…

   

Vice, Member
Posted: 22 March 2012 10:20 AM   Total Posts: 58   [ # 2 ]

use e. g.:

malla1.rotate(new Vector3D(0,1,0), 1);

but you should always use to put your mesh in an Object3D and than do all the rotation stuff and things like that

   

charlito, Jr. Member
Posted: 22 March 2012 09:48 PM   Total Posts: 36   [ # 3 ]

thx a lot guys..
u were really helpfull, i did just what u said and it work..

i’m posting the result.. just in case.. someone wants to do something like this in the future..

im pretty sure this code can optimized a lot.. but in the meantime
here is what i did so i can have a cube with diferents color faces..

public class away3DBasico_v003 extends Sprite
{


  public var view:View3D = new View3D();
 
 
  public var plano1:PlaneGeometry = new PlaneGeometry(100,100,1,1,true);//false indica si el plano esta acostado o parado
  public var plano2:PlaneGeometry = new PlaneGeometry(100,100,1,1,true);//estos dos estaran de huevones acostados
  public var plano3:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
  public var plano4:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
  public var plano5:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
  public var plano6:PlaneGeometry = new PlaneGeometry(100,100,1,1,false);
 
  private var plano_m1:ColorMaterial;
  private var plano_m2:ColorMaterial;
  private var plano_m3:ColorMaterial;
  private var plano_m4:ColorMaterial;
  private var plano_m5:ColorMaterial;
  private var plano_m6:ColorMaterial;
 
  public var malla1:Mesh;
  public var malla2:Mesh;
  public var malla3:Mesh;
  public var malla4:Mesh;
  public var malla5:Mesh;
  public var malla6:Mesh;
 
  //public var vector3d:Vector3D = new Vector3D(5,5,0,1);
  public var contenedor:ObjectContainer3D =new ObjectContainer3D();
 
 
  public function away3DBasico_v003()
  {
 
  view.backgroundColor= 0xB0C4DE;

  plano_m1= new ColorMaterial(0x000fff);
  plano_m2= new ColorMaterial(0xfff000);
  plano_m3= new ColorMaterial(0xffcc00);
  plano_m4= new ColorMaterial(0x909090);
  plano_m5= new ColorMaterial(0x008000);
  plano_m6= new ColorMaterial(0xff0000);
 
 
  malla1 = new Mesh(plano1,plano_m1);
  malla2 = new Mesh(plano2,plano_m2);
  malla3 = new Mesh(plano3,plano_m3);
  malla4 = new Mesh(plano4,plano_m4);
  malla5 = new Mesh(plano5,plano_m5);
  malla6 = new Mesh(plano6,plano_m6);
 
  addChild(view);
 
 
  malla1.y+=50;//cara superior
  malla2.rotationZ=180;malla2.y-=50;//cara inferior
  malla3.z-=50;//cara frontal
  malla4.rotationY=180;malla4.z+=50//cara atras
      malla5.rotationY=90;malla5.x=-50; //cara derecha
  malla6.rotationY=270;malla6.x=50; //cara izquierda
 
  view.camera.y+=100;
  view.camera.z+=300;
 
  contenedor.addChild(malla1);
  contenedor.addChild(malla2);
  contenedor.addChild(malla3);
  contenedor.addChild(malla4);
  contenedor.addChild(malla5);
  contenedor.addChild(malla6);
 
  view.scene.addChild(contenedor);
   
  contenedor.pivotPoint = new Vector3D(0,1,0);
 
  this.addEventListener(Event.ENTER_FRAME, loop);
 
   
  }
 
  public function loop(e:Event):void
  {
 
  contenedor.rotationY+=1;
 
  view.camera.y = 3 * (stage.mouseY - stage.stageHeight/2);
  view.camera.x = -3 * (stage.mouseX - stage.stageHeight/2);
  view.render();
  }
 
 
}

thx a lot again..

can someone tell me how can i mark this post as finished or resolved??
thx smile

 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X