Papervision: Cubos Rusos

Papervision: Cubos Rusos

Imagen en reemplazo de flash
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.

  1. //////////////////////////////////////////////////////////
  2. //Clases
  3.  
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6.  
  7. import org.papervision3d.cameras.Camera3D;
  8. import org.papervision3d.objects.Cube;
  9. import org.papervision3d.scenes.MovieScene3D;
  10. import org.papervision3d.materials.MovieAssetMaterial;
  11. import org.papervision3d.materials.MaterialsList;
  12.  
  13. //////////////////////////////////////////////////////////
  14. //Variables
  15.  
  16. var container: Sprite;
  17. var scene: MovieScene3D;
  18. var camera: Camera3D;
  19. var cube2:Cube;
  20. var cube3:Cube;
  21. var cube4:Cube;
  22. var cube5:Cube;
  23. var cube6:Cube;
  24. var cube7:Cube;
  25. var materiallist:MaterialsList;
  26. var material1:MovieAssetMaterial;
  27.  
  28. //////////////////////////////////////////////////////////
  29. //Funciones
  30. function Empezar() {
  31. 	Crear3D();
  32. 	CrearMateriales();
  33. 	CrearCubo();
  34. 	addEventListener(Event.ENTER_FRAME,Renderizar);
  35. }
  36.  
  37.  
  38. function Crear3D() {
  39. 	//Creo el contenedor de la escena
  40. 	container = new Sprite;
  41. 	container.x = 300;
  42. 	container.y = 200;
  43. 	addChild( container );
  44.  
  45. 	//Creo la escena 3D
  46. 	scene = new MovieScene3D( container );
  47.  
  48. 	//Creo la camara
  49. 	camera = new Camera3D();
  50. 	camera.z = -500;
  51. 	camera.y = 200;
  52. 	camera.zoom = 5;
  53.  
  54. }
  55.  
  56. function CrearMateriales(){
  57. 		//Creo los materiales
  58. 	material1 = new MovieAssetMaterial("Lado1",true);
  59. 	//material1.smooth = true;
  60. 	// create the material list for the cube
  61. 	materiallist = new MaterialsList();
  62. 	materiallist.addMaterial(material1,"top");
  63. 	materiallist.addMaterial(material1,"bottom");
  64. 	materiallist.addMaterial(material1,"front");
  65. 	materiallist.addMaterial(material1,"back");
  66. 	materiallist.addMaterial(material1,"left");
  67. 	materiallist.addMaterial(material1,"right");
  68.  
  69. }
  70.  
  71. function CrearCubo(){
  72. 	// create cube
  73. 	cube2 = new Cube( materiallist, 250, 250, 250, 2, 2, 2);
  74. 	cube3 = new Cube( materiallist, 200, 200, 200, 2, 2, 2);
  75. 	cube4 = new Cube( materiallist, 150, 150, 150, 2, 2, 2);
  76. 	cube5 = new Cube( materiallist, 100, 100, 100, 2, 2, 2);
  77. 	cube6 = new Cube( materiallist, 50, 50, 50, 2, 2, 2);
  78. 	cube7 = new Cube( materiallist, 25, 25, 25, 2, 2, 2);
  79. 	//scene.addChild(cube1);
  80. 	scene.addChild(cube2);
  81. 	scene.addChild(cube3);
  82. 	scene.addChild(cube4);
  83. 	scene.addChild(cube5);
  84. 	scene.addChild(cube6);
  85. 	scene.addChild(cube7);
  86.  
  87. }
  88. function Renderizar(e:Event){
  89. 	cube2.rotationY += ((mouseX - 300) - cube2.rotationY)/9;
  90. 	cube2.rotationX += ((mouseY - 300) - cube2.rotationX)/9;
  91. 	cube3.rotationY += ((mouseX - 300) - cube3.rotationY)/8;
  92. 	cube3.rotationX += ((mouseY - 300) - cube3.rotationX)/8;
  93. 	cube4.rotationY += ((mouseX - 300) - cube4.rotationY)/7;
  94. 	cube4.rotationX += ((mouseY - 300) - cube4.rotationX)/7;
  95. 	cube5.rotationY += ((mouseX - 300) - cube5.rotationY)/6;
  96. 	cube5.rotationX += ((mouseY - 300) - cube5.rotationX)/6;
  97. 	cube6.rotationY += ((mouseX - 300) - cube6.rotationY)/5;
  98. 	cube6.rotationX += ((mouseY - 300) - cube6.rotationX)/5;
  99. 	cube7.rotationY += ((mouseX - 300) - cube7.rotationY)/4;
  100. 	cube7.rotationX += ((mouseY - 300) - cube7.rotationX)/4;
  101. 	scene.renderCamera( camera );
  102.  
  103. }
  104. //////////////////////////////////////////////////////////////////////////////
  105. //Empezamos
  106.  
  107. Empezar();

Descargar archivos

Comentarios
    • Autor
    • Sergio
    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.
    • Autor
    • SErgio
    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:

Comentario: