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);
-
}
-
}
-
}



when i click on the ‘click me’
nothing happened,
why?
It works well, I’ve tried. :)
Hi, im new to papervision and want to learn a few things about it. Could you tell me the purpose of a few things. If you have time of course.
1: what is super, and why do people always access it when using papervision
2:what is the purpose of the get and set functions in the texture AS file
3:What is protected function, and how come the overide protected function works as an onEnterFrame would.
Thanks
Hi, im new in papervision too.
charlie i want to thank god at first and then thank you for the things you have done here for every single article and tutorials.
Dex:
1.super() mean that to call the base function
2.get and set functions give you ability to do things that you are not able in a simple variable.imagine that you want to call another function when this happen : (scale = 2) see DisplayObject3D.as
3.and protected attribute: Specifies that a variable, constant, method, or namespace is available only to the class that defines it and to any subclasses of that class. so the papervision decided to get us ability to override them and if we want to have those method coexists with our method functionality we use this as i mentioned : super.onRenderTick(event);
First of all, thank you for these introductory tutorials on Papervision. They have been a huge help in getting started. I have some specific questions about interactivity of dynamically loaded materials, such as you have in this tutorial. I noticed you are loading a MovieClip symbol from the Library. I assume that it is within the MovieClip’s code that you will find the functionality for the rollovers, and whatever other interactivity one might want. I have been setting up something very similar to this and have found that I can’t ever seem to get the mouse to change to the hand cursor when rolled over buttons or other elements that have Events attached to them. I’ve tried setting the buttonMode, mouseChildren, and useHandCursor properties in just about every combination possible (to the viewport, scene, materials, and actual elements inside the loaded MovieClip), but no luck so far. Is this a known issue? Is there a workaround for it? Or am I just doing something wrong? Any feedback would be greatly appreciated, thanks!
Sorry, have to add some things.
super refers to the parent object. So when you have a class Bla extends Sprite and you want to refer to a function or property of the Sprite class, you use super.function() or super.property
get and set are the two main things that hide behind the term encapsulation. Instead of making all your variables public to access them troughout your coding, you access them through getter and setter functions. This seems a little unnecessary but helps to prevent yourself from doing mistakes like accidentally overriding a variable which you didnt want to in the first place. there are more advantages but I forgot, computer classes are already dead past for me
a protected function is a function that is meant to be overwritten with the keyword override. this is so you dont accidentally override the function by defining a function which coincidentially has the same name as a function which is already definied in the super class of your actual class. with that in mind, coders define functions they want to be overwritten troughout your coding and do this intentially with the keywords protected function… because you know that those functions are protected, you override them