Papervision Collada Interactivity

On my most recent project, I had the opportunity to write my first full blown Flash application that uses Papervision. Although Papervision has definitely presented some unique challenges, I think it is a fantastic library that opens the door to some really interesting flash applications. One of the challenges that I ran into recently had to do with Collada model interactivity.

In my application, I needed to be able to click on a Collada object to "select" it and then move it around the stage. My first instinct was to simply add an event listener to my Collada class and handle the MouseEvent. Unfortunately, things aren't quite that simple in Papervision.

I discovered that Papervision interactivity is handled by the InteractiveSceneManager class. I'm not going to begin to claim a complete understanding of the magic that occurs in this class, but my understanding of it is this: InteractiveSceneManager translates 3D objects to 2D faces and throws events based on mouse position and clicks on the resulting sprites. In order for a 3D object to react to mouse events, the Materials applied need to have their "interactive" property set to true. If you have an object with multiple materials applied (a cube with 6 different materials), you can have different faces that are and are not interactive. For primative object types, once you have the interactive property set on the material you can simply add a listener to the object for InteractiveScene3DEvent.

Collada object interactivity is basically the same except you have to get a handle to a child object of the Collada class and then set its materials as interactive. The listener then goes on the child object instead of the parent Collada class.

myCollada.getChildByName("cow").addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onObjectClick);

More to come...

Example coming soon...

Comments

mogwai said…
also, you need to add a listener for when the collada is done loading before doing this.
collada.addEventListener( FileLoadEvent.LOAD_COMPLETE, handleColladaLoad);

then add the listener.

Also i found for collada saved with Softimage|XSI, lines 248 and 252 of Collada.as need node.@name changed to node.@id
Unknown said…
This comment has been removed by the author.

Popular Posts