InteractiveScene3D – a new Scene for Papervision3D

[kml_flashembed movie=”http://www.rockonflash.com/demos/pv3d/InteractiveScene3D/Main.swf” width=”550″ height=”300″/]

There’s been alot of questions about how to get mouse events from 3D objects in Papervision3D, and thanks to JLM (Justin Lawerance Mills) on the PV3D list, I flushed out his idea with using the existing Face3D 2D coordinates for drawing the triangles.

[ update ]
InteractiveScene3D has been integrated with Papervision3D 1.5 now. All you have to do is use InteractiveScene3D and assign one of the Interactive materials to your DisplayObject3D’s that you want to receive mouse events from. So, you now can have a 3D scene where only the objects you designate have mouse events.
[ /update ]

The new InteractiveScene3DEvent passes along the sprite container references as well as a reference to the corresponding DisplayObject3D. In the sample in the repository, and in the code below, I show how I’m able to use both by applying filters as well as changing the position of the 3D object that’s clicked.

So, this now allows me to create a complex scene in 3D Studio Max, create groups etc, and it’s automatically taken care of for me – all objects have mouse events!

Now, this sample might seem like the process is slow, but it’s not – I just put 4 spheres in with a total poly count over 5k and then added filters to the mouse events as well as actually set a visible alpha to the sprite containers – that’s why it seems a bit slow responding to the click event – its switching out one glow filter, for a new one. In normal conditions, the events are fast/responsive.

At this time, it’s doing an object level sort, and I’d like to add face level later on for those of you who want complex object interaction. Right now, this should work for over 90% of the use cases out there.

What I’m also hoping to get help on is creating something that anaylizes a MovieMaterial, and creates planes for UI elements for easy form UI setups on 3D objects.


To try it out, I’ve merged it with the 1.5 trunk version out there now:
http://papervision3d.googlecode.com/svn/trunk/src

[as]
// create your new InteractiveScene3D:
scene3d = new InteractiveScene3D(canvas);

// use one of the new Interactive materials – this enables mouse events:
var bam:BitmapFileMaterial = new InteractiveBitmapFileMaterial(“images/sphereMaterial.png”);

// add listeners
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_PRESS, handleMousePress);
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_RELEASE, handleMouseRelease);
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_CLICK, handleMouseClick);
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_OVER, handleMouseOver);
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_OUT, handleMouseOut);
scene.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_MOVE, handleMouseMove);
scene3d.interactiveSceneManager.addEventListener(
InteractiveScene3DEvent.OBJECT_RELEASE_OUTSIDE, handleReleaseOutside);

// define method handlers
private function handleMousePress(e:InteractiveScene3DEvent):void
{
log.debug(“press”, e.displayObject3D.name);
e.sprite.filters = [new GlowFilter(0xFFFFFF, 1, 20,20,3,1)];
e.displayObject3D.moveUp(30);
}

private function handleMouseRelease(e:InteractiveScene3DEvent):void
{
log.debug(“release”, e.displayObject3D.name);
e.sprite.filters = [];
e.displayObject3D.moveDown(30);
}

private function handleReleaseOutside(e:InteractiveScene3DEvent):void
{
log.debug(“releaseOutside”);
if( currentSphere != null ) currentSphere.moveDown(30);
}

private function handleMouseClick(e:InteractiveScene3DEvent):void
{
log.debug(“click”, e.displayObject3D.name);
e.sprite.filters = [];
}

private function handleMouseOver(e:InteractiveScene3DEvent):void
{
log.debug(“over”, e.displayObject3D.name);
e.sprite.filters = [new GlowFilter(0x20ADCD, .75, 20,20,2,1)];
}

private function handleMouseOut(e:InteractiveScene3DEvent):void
{
log.debug(“out”, e.displayObject3D.name);
e.sprite.filters = [];
}

private function handleMouseMove(e:InteractiveScene3DEvent):void
{
log.debug(“move”, e.displayObject3D.name);
}
[/as]

About these ads
  1. Not slow at all on mine. VERY handy!!

    • Psilos
    • July 18th, 2007

    Yeah.It’s good to see PV3D getting better and better
    And that many more give great ideas!!!

    Keep up the good work!

    By the way, it is not slowly for me.

  2. nice!
    i like the sound if it.
    i will have a demo for ya by this weekend

  3. well done!

    • Brian!
    • July 19th, 2007

    Nice work.

    The e.displayObject3D.moveDown(30); call is not tied to an onReleaseOutside event, so if you click-drag out then release, you can get the balls to move up by 30 each time.

    Maybe not the effect you were intending. That is one of the things about Flash that I often see missed actually. The missing onReleaseOutside…

    PV3D, if only I could justify it in a client production.

    • Brian!
    • July 19th, 2007

    Hah, I also just realized that if you click outside of any circle, then drag into one, then release the object gets the handleMouseRelease called.

    Seems that further event handling checks need to be put in place to avoid unwanted behavior.

  4. :) yeah, I actually DID look for onReleaseOutside, which I guess is called something else in AS3. But basically, since I knew I’d be merging with Ralph’s stuff etc, I left it as is and thought it was kinda fun that way

    I’ll be sure to get all events in there and dispatched for the final rev however, Thanks Brian!

  5. just as I thought – onReleaseOutside is removed, we use MouseEvent.MOUSE_UP and register that with the stage to basically capture a release outside type event.

    That’s now in there, and will now broadcast OBJECT_RELEASE_OUTSIDE

    Thanks Brian!

    • JLM
    • July 19th, 2007

    John

    Cool – found a solution to my initall limited problem of getting 2d corners of a 3D plane see

    http://www.nabble.com/solved-plane3D-%3E2D-%28as2%29-tf4111615.html

    Not sure if it is more usefull but it is what I need.

    let me know if you can optimise it or think it would be good in PV

    Laters

    JLM

    • D
    • July 30th, 2007

    Are the example files in the svn, cause I was unable to find?

  6. Is there a way to add button usability like:
    “*.buttonMode = true”

    Thank you

    Olli

  7. we’re working on it ;)

  8. are there other concepts in papervision3d to create button without interactiveSceneManager?

  9. not without modifying the code yourself. the ISM should do the work very well for what people will need.

    We’re working on the “button” issue in a movieclip as we speak!
    :)

  10. I just realized how cool InteractiveScene3D is! John, great work! Can’t wait to see updates!

    • Bruce Fullwood
    • October 24th, 2007

    John, your example does exactly what Im’ trying to do. It’s really slick.

    However, I’m having some trouble with it. My touble is your very first line. My equivalent is this:

    scene = new InteractiveScene3D(pnl3d);

    pnl3d is a mx.containers.Canvas an I assume your variable canvas is the same. I’m getting this:

    Type Coercion failed: cannot convert org.papervision3d.utils::InteractiveSprite@5d2b161 to mx.core.IUIComponent.

    Thoughts?

    BTW – It really is a cool example.

    • richard
    • April 3rd, 2008

    ive got an object that is inheriting from a papervision plane, when I click on it i would like for one of the member variables of the object to change. is there a way to get a reference to the object back from the InteractiveScene3DEvent?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 794 other followers