the new pv3d 2.0 release features an entirely new way of dispatching and handling events. earlier versions of the engine utilized two different flavors of materials, regular and interactive. with this new release, you just have materials with a boolean interactive property.
with this simple demo, im trying to learn more about the new interactive scene events. first, you create a 3D scene, and set it's interactive flag to true:
view = new Viewport3D(width, height, scaleToStage, interactive);
then create a material and set it's interactive property to true:
skin = new CompositeMaterial(); skin.interactive = true;
this can also be done through the object as opposed to the material:
terrain = new Plane(...); terrain.material.interactive = true;
after that you attach listeners to your object. in this case, we're going to use the interactiveScene3DEvent.
here's a list of the available interactive scene3d events:
OBJECT_CLICK OBJECT_OVER OBJECT_OUT OBJECT_MOVE OBJECT_PRESS OBJECT_RELEASE OBJECT_RELEASE_OUTSIDE OBJECT_ADDED
from these events its possible to receive a multitude of information. the 4 main ones are the instance properties available to you, which are:displyObject3D, face3D, renderHitData, and sprite. in this demo i use face3D to return the current triangle3D that the user is interacting with.
when the user moves the mouse over the plane, a highlight function is fired. i look at the current face3D and the last face3D and change their materials. this gives the effect that the triangle you are hovering over is illuminated.
but the code gets a bit hacky in the extrude function. this gets fired when the user actually clicks the plane. i receive an event from the interactive scene manager and once again get the current face3D instance. beyond that, i look that the v0 property and increment (or decrement, depending on the user's on click settings) the current face's z amount. notice that the current face is not the only one affected. it's surrounding triangles also rise up and form pyramids on their own. this is a sign is a well programmed engine!
as usual, sources are available...
view the interactive terrain generator
view its source code here