In an effort to keep the information on this site up to date over the next few weeks we will be re-writing the majority of the tutorials on this site.
All new tutorials will include:
1) More up to date PV3D code.
2) A version that can be compiled with the Flash IDE
3) A version that can be compiled with FlashDevelop, Flex etc.
4) Full source code.
Having two versions of the code, as well as full source (including pv3d code) will hopefully cut down on the confusion when getting started.
Please feel free to leave comments here for other requests. If we get several requests for features other than what has been mentioned we will do my best to incorporate them.
**UPDATE
This tutorial has been updated:
Updates:
1) Removed InteractiveScene3DEvent and replaced it with standard MouseEvents
2) Updated to use papervision's BasicView.as class
Today we're going to learn how to handle more advanced interactivity. We'll be making something like this:
Click on a face of the cube to zoom into it. Click it again to make the cube spin again.
So, in this tutorial I'm going to show you exactly how to work out which material has been clicked on the cube and act accordingly.
If you haven't read it already, I strongly suggest that you read the Basic Interactivity tutorial first or you'll probably miss something.
Ok, so on to the code.
Firstly we'll want six materials to apply to each face of the cube. Here are mine, although you can create whatever materials you like:
Now we need to set up the 3d initiation code. In this code we will firstly set all of our materials as interactive, and then give each of our materials a name. This is VERY important to be able to easily find out which material has been clicked. If we didn't give each material a name then we wouldn't be able to easily work out which face has been clicked.
So, add the following code to your init3d() function:
So, In this code, we've set each material as interactive, given each one a sensible name, and initialised our cube with the materials assigned to the correct faces.
We then add an event listener to trigger the "onPress" event when the cube is clicked, then finally we add the cube to the scene.
We've now got a cube with six materials on it listening for a click event.
Now, the code which will let us work out which face has been clicked:
// This code will be run when the front face is clicked
break;
case"back":
// This code will be run when the back face is clicked
break;
case"left":
// This code will be run when the left face is clicked
break;
case"right":
// This code will be run when the right face is clicked
break;
case"top":
// This code will be run when the top face is clicked
break;
case"bottom":
// This code will be run when the bottom face is clicked
break;
}
}
Pretty self explanitary. The "e" variable in this code holds lots of data about the click event, including which material has been clicked, so, because we know which material is on each face, we can tell by the materials name which face has been clicked!
With a little bit of code, you can make a nice spinning cube gallery like the example above: