There are multiple ways of accomplishing any task. With papervision that statement holds true. When you want to interact with 3D objects one way we have found works very well is to apply the MouseEvent's to the textureFile and bypass the InteractiveScene3DEvent all together.
Here are a few things to remember when working with anything interactive in Papervision
1) Always set your ViewPort to interactive
2) Always set your Material to interactive
3) Set your Material animation to "true" if you want to see the material update
4) Be sure that your render is running so you can see your material update
Here is some sample code that shows the basic building blocks of an animated / interactive papervision object:
-
//Viewport set to interactive
-
viewport.interactive = true;
-
-
//Create your symbol - can be a class or MovieClip exported in your library
-
var textureMC:TextureSymbol = new TextureSymbol();
-
textureMC.id = i;
-
textureMC.clickButton.addEventListener(MouseEvent.CLICK, onMovieMatClicked);
-
-
//Create your movie Material - animated / interactive set to true
-
var movieMat:MovieMaterial = new MovieMaterial(textureMC, true, true);
-
movieMat.doubleSided = true;
-
movieMat.interactive = true;
-
movieMat.smooth = true;
This approach is nice because you can deal with native Flash events.
Here is the full class:
-
package
-
{
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import gs.easing.Quint;
-
import gs.TweenLite;
-
import org.papervision3d.materials.MovieMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
-
import org.papervision3d.view.BasicView;
-
import TextureSymbol;
-
-
/**
-
* ...
-
* @author Charlie Schulze, charlie[at]woveninteractive[dot]com
-
*/
-
-
public class Main extends BasicView
-
{
-
protected var cube:Cube;
-
protected var interactiveMats:Array;
-
protected var materialsList:MaterialsList;
-
-
public function Main():void
-
{
-
super();
-
init();
-
}
-
protected function init():void
-
{
-
createChildren();
-
commitProperties();
-
startRendering();
-
}
-
protected function createChildren():void
-
{
-
//Set the viewport to interactive
-
viewport.interactive = true;
-
-
//Create Materials:
-
materialsList = new MaterialsList();
-
interactiveMats = ["front", "back", "top", "bottom", "left", "right"];
-
-
for (var i:int = 0; i <interactiveMats.length; i++)
-
{
-
//Create the texture symbol from the library
-
var textureMC:TextureSymbol = new TextureSymbol();
-
textureMC.id = i;
-
textureMC.clickButton.addEventListener(MouseEvent.CLICK, onMovieMatClicked);
-
-
//Create the MovieMat
-
var movieMat:MovieMaterial = new MovieMaterial(textureMC, true, true);
-
movieMat.doubleSided = true;
-
movieMat.interactive = true;
-
movieMat.smooth = true;
-
-
materialsList.addMaterial(movieMat, interactiveMats[i]);
-
}
-
-
//Create Cube
-
cube = new Cube(materialsList, 100, 100, 100);
-
-
//Add cube to the scene
-
scene.addChild(cube);
-
}
-
-
protected function onMovieMatClicked(evt:MouseEvent):void
-
{
-
var randomX:Number = Math.random() * 600 - 300;
-
var randomY:Number = Math.random() * 200 - 100;
-
TweenLite.to(cube, 1, { x:randomX, y:randomY, ease:Quint.easeInOut});
-
}
-
-
protected function commitProperties():void
-
{
-
//Set the properties of our camera
-
camera.zoom = 200;
-
camera.y = 1000;
-
}
-
override protected function onRenderTick(event:Event = null):void
-
{
-
super.onRenderTick(event);
-
cube.yaw(2);
-
}
-
}
-
}







