[Papervision3D] InteractiveScene3DEvent EventListener's only working sometimes!?!
Albinal
elyeball at gmail.com
Thu Sep 25 08:44:50 PDT 2008
Ok, brace yourself... I'm going to post the entire thing! The code is in the
top layer of my Flash Movie... traditional style AS coding I think!?!? I
haven't really got to grips with putting it all in separate AS files... I'm
mainly design-brained and coding is difficult for me to grasp... but I know
3D and see the potential, if only I could master it! :-)
I basically have my SWF along with a directory called images. In the images
folder are all the DAEs and textures. I just tried changing the DAEs to all
use a very small 1pixel jpg so that it would be very quick to load but even
with this my event listeners don't always work.
Here it is then, don't be laughing at me if it totally sucks! ;-)
import org.papervision3d.view.Viewport3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.FreeCamera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.objects.parsers.*;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.core.utils.InteractiveSceneManager;
// ##### VARIABLES #####
var viewport:Viewport3D = new Viewport3D( stage.stageWidth,
stage.stageHeight, true, true );;
var scene:Scene3D = new Scene3D();
var camera:FreeCamera3D = new FreeCamera3D();
var renderer:BasicRenderEngine = new BasicRenderEngine();;
var go3DRender:Boolean = false; // Should 3D renderer be running
var modelsTotal:int = 4; // Total number of 3D models to load
var modelsLoaded:int = 0; // Total number of 3D models loaded
// ##### SET-UP #####
//trace("STAGE WIDTH: " + stage.stageWidth);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//Set initial values that are later dealt with on RESIZE
transparent_mc.width = stage.stageWidth;
transparent_mc.height = stage.stageHeight;
overlay_mc.visible = false;
overlay_mc.x = stage.stageWidth/2;
overlay_mc.y = stage.stageHeight/2;
addChildAt(viewport,1); // Add Child and LEVEL!
camera.x = 0;
camera.y = 0;
camera.z = -1000;
camera.zoom = 11;
//##### FUNCTIONS #####
function modelLoadComplete():void{
modelsLoaded++;
}
function jumpToLink(sLink){
var sTargetURL:String = sLink;
var sRequest:URLRequest = new URLRequest(sTargetURL);
navigateToURL(sRequest, "_self");
}
//Trace the name of anything interactive Clicked!
viewport.interactiveSceneManager.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,
AnythingInteractiveClicked);
function AnythingInteractiveClicked(event:InteractiveScene3DEvent):void
{
trace("clicked: " + event.displayObject3D.name);
}
//##### MATERIALS #####
//Colour your own!
var CYOTexture:MovieMaterial = new MovieMaterial(colour_your_own_mc, false,
true); // (MC Name, Transparent, Animated)
CYOTexture.interactive = true ;
CYOTexture.oneSide = true;
CYOTexture.smooth = true;
//BUY!
var BuyTexture:MovieMaterial = new MovieMaterial(buy_mc, false, true); //
(MC Name, Transparent, Animated)
BuyTexture.interactive = true ;
BuyTexture.oneSide = true;
BuyTexture.smooth = true;
//Cloud 1
var Cloud1Texture:MovieMaterial = new MovieMaterial(cloud1_mc, false,
true); // (MC Name, Transparent, Animated)
Cloud1Texture.interactive = true ;
Cloud1Texture.oneSide = true;
Cloud1Texture.smooth = true;
//Plain Red (for testing)
var Red:ColorMaterial = new ColorMaterial(0xFF0000, 1);
Red.oneSide = false;
Red.interactive = true;
// #####################
// ##### 3D MODELS #####
// #####################
var AllModelsScale:Number = 800;
// ----- Main BG -----
var Main_BG_DAE:DAE = new DAE();
Main_BG_DAE.load("images/main_bg.dae");
scene.addChild(Main_BG_DAE, "Main_BG_DAE");
Main_BG_DAE.scaleX = AllModelsScale;
Main_BG_DAE.scaleY = AllModelsScale;
Main_BG_DAE.scaleZ = AllModelsScale;
//Main_BG_DAE.rotationX = 270;
Main_BG_DAE.addEventListener(FileLoadEvent.LOAD_COMPLETE,
Main_BG_LoadComplete);
function Main_BG_LoadComplete(event:Event):void
{
trace("Main_BG LOADED! :-)");
modelLoadComplete();
Main_BG_DAE.getMaterialByName("Main_BG_png").smooth = true;
}
// ----- CONTACT CLOUD -----
var Cloud1_DAE:DAE = new DAE();
Cloud1_DAE.load("images/cloud1.dae");
scene.addChild(Cloud1_DAE, "Cloud1_DAE");
Cloud1_DAE.scaleX = AllModelsScale;
Cloud1_DAE.scaleY = AllModelsScale;
Cloud1_DAE.scaleZ = AllModelsScale;
Cloud1_DAE.addEventListener(FileLoadEvent.LOAD_COMPLETE,
Cloud1_DAE_LoadComplete);
function Cloud1_DAE_LoadComplete(event:Event):void
{
trace("Cloud1 LOADED! :-)");
modelLoadComplete();
Cloud1_DAE.getMaterialByName("Cloud1_png").smooth = true;
//Cloud1_DAE.getMaterialByName("Cloud1_png").oneSide = false;
//Cloud1_DAE.getMaterialByName("Cloud1_png").interactive = true;
Cloud1_DAE.replaceMaterialByName(Cloud1Texture,"Cloud1_png");
Cloud1_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_002").getChildByName("11").addEventListener(
InteractiveScene3DEvent.OBJECT_OVER, onCloud1Over );
Cloud1_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_002").getChildByName("11").addEventListener(
InteractiveScene3DEvent.OBJECT_OUT, onCloud1Out );
Cloud1_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_002").getChildByName("11").addEventListener(
InteractiveScene3DEvent.OBJECT_CLICK, onCloud1Click );
function onCloud1Click( event:InteractiveScene3DEvent ):void
{
trace("CLOUD CLICK");
jumpToLink("/art/contact/");
}
function onCloud1Over( event:InteractiveScene3DEvent ):void
{
trace("CLOUD OVER");
viewport.buttonMode = true;
cloud1_mc.gotoAndPlay(2);
}
function onCloud1Out( event:InteractiveScene3DEvent ):void
{
trace("CLOUD OUT");
viewport.buttonMode = false;
cloud1_mc.gotoAndPlay(6);
}
}
// ----- BUY -----
var Buy_DAE:DAE = new DAE();
Buy_DAE.load("images/buy.dae");
scene.addChild(Buy_DAE, "Buy_DAE");
Buy_DAE.scaleX = AllModelsScale;
Buy_DAE.scaleY = AllModelsScale;
Buy_DAE.scaleZ = AllModelsScale;
Buy_DAE.addEventListener(FileLoadEvent.LOAD_COMPLETE,
Buy_DAE_LoadComplete);
function Buy_DAE_LoadComplete(event:Event):void
{
trace("Buy_DAE LOADED! :-)");
modelLoadComplete();
Buy_DAE.getMaterialByName("Buy_png").smooth = true;
Buy_DAE.getMaterialByName("Buy_png").interactive = true;
Buy_DAE.replaceMaterialByName(BuyTexture,"Buy_png");
Buy_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths").getChildByName("14").addEventListener(
InteractiveScene3DEvent.OBJECT_OVER, onBUYOver );
Buy_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths").getChildByName("14").addEventListener(
InteractiveScene3DEvent.OBJECT_OUT, onBUYOut );
Buy_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths").getChildByName("14").addEventListener(
InteractiveScene3DEvent.OBJECT_CLICK, onBUYClick );
function onBUYClick( event:InteractiveScene3DEvent ):void
{
trace("BUY CLICK");
jumpToLink("/art/artwork/");
}
function onBUYOver( event:InteractiveScene3DEvent ):void
{
trace("BUY OVER");
viewport.buttonMode = true;
buy_mc.gotoAndPlay(2);
}
function onBUYOut( event:InteractiveScene3DEvent ):void
{
trace("BUY OUT");
viewport.buttonMode = false;
buy_mc.gotoAndPlay(6);
}
}
// ----- ColourYourOwn -----
var ColourYourOwn_DAE:DAE = new DAE();
ColourYourOwn_DAE.load("images/colouryourown.dae");
scene.addChild(ColourYourOwn_DAE, "ColourYourOwn_DAE");
ColourYourOwn_DAE.scaleX = AllModelsScale;
ColourYourOwn_DAE.scaleY = AllModelsScale;
ColourYourOwn_DAE.scaleZ = AllModelsScale;
ColourYourOwn_DAE.addEventListener(FileLoadEvent.LOAD_COMPLETE,
ColourYourOwn_DAE_LoadComplete);
function ColourYourOwn_DAE_LoadComplete(event:Event):void
{
trace("ColourYourOwn LOADED! :-)");
modelLoadComplete();
ColourYourOwn_DAE.getMaterialByName("ColourYourOwn_png").smooth = true;
ColourYourOwn_DAE.getMaterialByName("ColourYourOwn_png").interactive =
true;
ColourYourOwn_DAE.replaceMaterialByName(CYOTexture,"ColourYourOwn_png");
ColourYourOwn_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_004").getChildByName("17").addEventListener(
InteractiveScene3DEvent.OBJECT_OVER, onCYOOver );
ColourYourOwn_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_004").getChildByName("17").addEventListener(
InteractiveScene3DEvent.OBJECT_OUT, onCYOOut );
ColourYourOwn_DAE.getChildByName("COLLADA_root").getChildByName("PurePaths_004").getChildByName("17").addEventListener(
InteractiveScene3DEvent.OBJECT_CLICK, onCYOClick );
function onCYOClick( event:InteractiveScene3DEvent ):void
{
trace("CYO CLICK");
jumpToLink("/art/ColourYourOwn/");
}
function onCYOOver( event:InteractiveScene3DEvent ):void
{
trace("CYO OVER");
viewport.buttonMode = true;
colour_your_own_mc.gotoAndPlay(2);
}
function onCYOOut( event:InteractiveScene3DEvent ):void
{
trace("CYO OUT");
viewport.buttonMode = false;
colour_your_own_mc.gotoAndPlay(6);
}
}
stage.addEventListener( Event.RESIZE, onStageResize );
function onStageResize( event:Event ):void
{
//Transparent MC. Necessary for a SWF with a transparent background to keep
focus when in an HTML page
transparent_mc.width = stage.stageWidth;
transparent_mc.height = stage.stageHeight;
overlay_mc.x = stage.stageWidth/2;
overlay_mc.y = stage.stageHeight/2;
}
function Loader3D():void
{
// Have all the models loaded AND 3D rendered is off?
if ( modelsTotal == modelsLoaded)
{
//trace("ALL LOADED");
ModelLoader_mc.visible = false;
go3DRender = true;
}
else
{
//trace("LOADING" + modelsLoaded);
ModelLoader_mc.visible = true;
var PercentageOfModelsLoaded = modelsLoaded * 25;
ModelLoader_mc.bar_mc.scaleX = PercentageOfModelsLoaded/100;
ModelLoader_mc.loading_info_txt.text = "LOADING 3D Models " +
PercentageOfModelsLoaded + "% - Please wait...";
}
}
stage.addEventListener( Event.ENTER_FRAME, onEnterFrameEvent );
function onEnterFrameEvent( event:Event ):void
{
ModelLoader_mc.x = mouseX;
ModelLoader_mc.y = mouseY;
// 3D Loader - wait for models to load
Loader3D();
// 3D rendering
if ( go3DRender )
renderer.renderScene( scene, camera, viewport );
var mouseXPos = Math.floor((mouseX - stage.stageWidth/2)/20);
var mouseYPos = Math.floor((mouseY - stage.stageHeight/2)/20);
//Rotate models
Main_BG_DAE.rotationY = -mouseXPos;
Main_BG_DAE.rotationX = mouseYPos;
Cloud1_DAE.rotationY = -mouseXPos;
Cloud1_DAE.rotationX = mouseYPos;
Buy_DAE.rotationY = -mouseXPos;
Buy_DAE.rotationX = mouseYPos;
ColourYourOwn_DAE.rotationY = -mouseXPos;
ColourYourOwn_DAE.rotationX = mouseYPos;
}
tmyers wrote:
>
> Abinal,
>
> Its hard to figure out the sequence of events...can you outline your
> implementation, or better still paste in the whole class. What way is your
> .dae file setup. Are the textures located in from a relative directory. Do
> they load automatically with the dae.
>
>
--
View this message in context: http://www.nabble.com/InteractiveScene3DEvent-EventListener%27s-only-working-sometimes%21-%21-tp19651124p19672403.html
Sent from the Papervision3D mailing list archive at Nabble.com.
More information about the Papervision3D
mailing list