package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import org.papervision3d.cameras.FreeCamera3D; import org.papervision3d.scenes.MovieScene3D; import org.papervision3d.objects.Plane; import org.papervision3d.materials.BitmapFileMaterial; import org.papervision3d.materials.ColorMaterial; import flash.display.DisplayObject; import org.papervision3d.objects.DisplayObject3D; import flash.text.TextField; [SWF(width='800',height='512',backgroundColor='0x000000',frameRate='30')] public class VisionneuseCubeHotspots extends Sprite { private static const CHEMIN_IMAGES:String = "../assets/"; private static var MAX_X_ROTATION:int = 50; private static var taille:Number = 5000; private var container :Sprite; private var scene :MovieScene3D; private var camera :FreeCamera3D; private var nullObject:DisplayObject3D = new DisplayObject3D(); private var plan:Plane; private var materials :Array; private var label:TextField; private var labelText:String = "Clic sur un objet"; public function VisionneuseCubeHotspots() { configChampTexte(); container = new Sprite(); container.x = stage.stageWidth/2; container.y = stage.stageHeight/2; addChild( container ); scene = new MovieScene3D( container ); camera = new FreeCamera3D(); camera.zoom = 1; camera.focus = 400; camera.z = 0; var centre:Number = taille/2; materials = new Array(); var boxGroup:DisplayObject3D = new DisplayObject3D(); var worldEnd:DisplayObject3D = new DisplayObject3D(); //Face Avant var texture:BitmapFileMaterial = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_FR.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.z = centre; boxGroup.addChild( plan ); //Face Droite texture = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_RT.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.x = -centre; plan.rotationY = -90; boxGroup.addChild( plan ); //Face Gauche texture = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_LF.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.x = centre; plan.rotationY = 90; boxGroup.addChild( plan ); //Face Bas texture = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_DN.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.y = -centre; plan.rotationX = -90; boxGroup.addChild( plan ); //Face Haut texture = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_UP.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.y = centre; plan.rotationX = 90; boxGroup.addChild( plan ); //Face Arriere texture = new BitmapFileMaterial(VisionneuseCubeHotspots.CHEMIN_IMAGES+"rendu_cubique_BK.jpg"); materials.push( texture ); plan = new Plane( texture , taille, taille, 8, 8); plan.z = -centre; plan.rotationY = -180; boxGroup.addChild( plan ); worldEnd.addChild( boxGroup ); worldEnd.addChild( nullObject ); scene.addChild(worldEnd); /******** Création des hotspots ****************/ //radiateur var textureCouleur:ColorMaterial = new ColorMaterial(); textureCouleur.doubleSided = true; materials.push(textureCouleur); plan = new Plane( textureCouleur, 2158, 1210, 4, 4 ); plan.y = -450; plan.z = -1000; plan.x = -centre + 100; plan.rotationY = -90; scene.addChild( plan ); //Ajout des évenements souris var planDynamique:Sprite = scene.getSprite( plan ); planDynamique.alpha = 0; planDynamique.addEventListener( MouseEvent.MOUSE_DOWN, _onMouseDown ); planDynamique.addEventListener( MouseEvent.MOUSE_UP, _onMouseUp ); //armoire textureCouleur = new ColorMaterial(); textureCouleur.doubleSided = true; materials.push(textureCouleur); plan = new Plane( textureCouleur, 3242, 3212, 4, 4 ); plan.y = 0; plan.z = -600; plan.x = centre - 100; plan.rotationY = 90; scene.addChild( plan ); //Ajout des évenements souris planDynamique = scene.getSprite( plan ); planDynamique.alpha = 0; planDynamique.addEventListener( MouseEvent.MOUSE_DOWN, _onMouseDown ); planDynamique.addEventListener( MouseEvent.MOUSE_UP, _onMouseUp ); /*****************************************************/ stage.addEventListener( Event.ENTER_FRAME, onEnterFrame ); } private function onEnterFrame( event: Event ): void { camera.rotationY += (container.mouseX)/60; camera.rotationX -= (container.mouseY)/60; //on limite la rotation vertivale if(camera.rotationX > VisionneuseCubeHotspots.MAX_X_ROTATION) { camera.rotationX = VisionneuseCubeHotspots.MAX_X_ROTATION; } if(camera.rotationX < -VisionneuseCubeHotspots.MAX_X_ROTATION) { camera.rotationX = -VisionneuseCubeHotspots.MAX_X_ROTATION; } scene.renderCamera( camera ); } private function _onMouseDown(event:Event):void { addChild(label); } private function _onMouseUp(event:Event):void { removeChild(label); } private function configChampTexte():void { label = new TextField(); label.autoSize = TextFieldAutoSize.LEFT; label.background = true; label.border = true; var format:TextFormat = new TextFormat(); format.font = "Verdana"; format.color = 0xFF0000; format.size = 10; format.underline = true; label.defaultTextFormat = format; label.text = labelText; } } }