Papervision: Cubos Rusos

Hace unos años vi en www.uncontrol.com una demo en la que había varios cubos metidos unos dentro de otros, y reaccionaban a los movimientos de ratón con diferentes easings. Este es un "homenaje" a esa demo, hecha con PPV.

//////////////////////////////////////////////////////////
//Clases
 
import flash.display.Sprite;
import flash.events.Event;
 
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.Cube;
import org.papervision3d.scenes.MovieScene3D;
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.materials.MaterialsList;
 
//////////////////////////////////////////////////////////
//Variables
 
var container: Sprite;
var scene: MovieScene3D;
var camera: Camera3D;
var cube2:Cube;
var cube3:Cube;
var cube4:Cube;
var cube5:Cube;
var cube6:Cube;
var cube7:Cube;
var materiallist:MaterialsList;
var material1:MovieAssetMaterial;
 
//////////////////////////////////////////////////////////
//Funciones
function Empezar() {
	Crear3D();
	CrearMateriales();
	CrearCubo();
	addEventListener(Event.ENTER_FRAME,Renderizar);
}
 
 
function Crear3D() {
	//Creo el contenedor de la escena
	container = new Sprite;
	container.x = 300;
	container.y = 200;
	addChild( container );
 
	//Creo la escena 3D
	scene = new MovieScene3D( container );
 
	//Creo la camara
	camera = new Camera3D();
	camera.z = -500;
	camera.y = 200;
	camera.zoom = 5;
 
}
 
function CrearMateriales(){
		//Creo los materiales
	material1 = new MovieAssetMaterial("Lado1",true);
	//material1.smooth = true;
	// create the material list for the cube
	materiallist = new MaterialsList();
	materiallist.addMaterial(material1,"top");
	materiallist.addMaterial(material1,"bottom");
	materiallist.addMaterial(material1,"front");
	materiallist.addMaterial(material1,"back");
	materiallist.addMaterial(material1,"left");
	materiallist.addMaterial(material1,"right");
 
}
 
function CrearCubo(){
	// create cube
	cube2 = new Cube( materiallist, 250, 250, 250, 2, 2, 2);
	cube3 = new Cube( materiallist, 200, 200, 200, 2, 2, 2);
	cube4 = new Cube( materiallist, 150, 150, 150, 2, 2, 2);
	cube5 = new Cube( materiallist, 100, 100, 100, 2, 2, 2);
	cube6 = new Cube( materiallist, 50, 50, 50, 2, 2, 2);
	cube7 = new Cube( materiallist, 25, 25, 25, 2, 2, 2);
	//scene.addChild(cube1);
	scene.addChild(cube2);
	scene.addChild(cube3);
	scene.addChild(cube4);
	scene.addChild(cube5);
	scene.addChild(cube6);
	scene.addChild(cube7);
 
}
function Renderizar(e:Event){
	cube2.rotationY += ((mouseX - 300) - cube2.rotationY)/9;
	cube2.rotationX += ((mouseY - 300) - cube2.rotationX)/9;
	cube3.rotationY += ((mouseX - 300) - cube3.rotationY)/8;
	cube3.rotationX += ((mouseY - 300) - cube3.rotationX)/8;
	cube4.rotationY += ((mouseX - 300) - cube4.rotationY)/7;
	cube4.rotationX += ((mouseY - 300) - cube4.rotationX)/7;
	cube5.rotationY += ((mouseX - 300) - cube5.rotationY)/6;
	cube5.rotationX += ((mouseY - 300) - cube5.rotationX)/6;
	cube6.rotationY += ((mouseX - 300) - cube6.rotationY)/5;
	cube6.rotationX += ((mouseY - 300) - cube6.rotationX)/5;
	cube7.rotationY += ((mouseX - 300) - cube7.rotationY)/4;
	cube7.rotationX += ((mouseY - 300) - cube7.rotationX)/4;
	scene.renderCamera( camera );
 
}
//////////////////////////////////////////////////////////////////////////////
//Empezamos
 
Empezar();

Comentarios:
Sergio dijo:
Hola que tal, ya trate de generar los cubos pero cuando lo veo en ejecucion las caras de los cubos aparecen desfasadas y tambien no puedo darle ese efecto de transparancia.
SErgio dijo:
Ya me funciono, gracias de todos modos, solo tengo una duda, como se crea la textura que se le pone a los cubos porque dependiendo del color que pongas de fondo se dibuja la textura.
Dejar un comentario:
Tu nombre (obligatorio):

E-mail (obligatorio, no se mostrará):

Web: