Messing With Papervision3D and Material/Plane Interactivity

Update: I've hacked PV3D to get it to work with YouTube. Right, after much browsing through the Papervision3D code, I've found out something very interesting: Papervision3D renders hit test, on every frame, on objects that request the mouse, that means those with event listeners. So, going back to my original issue of getting the YouTube player to function with Papervision3D, I created some tests to see exactly what Papervision3D was doing, and how I could maybe adjust the code so it can work for me. The first test was to simply add a button (using my "ButtonSimple()" class) to a material and add the material to a plane and test for interactivity: package { import com.firestartermedia.lib.as3.display.component.interaction.ButtonSimple; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.text.Font; import org.papervision3d.cameras.CameraType; import org.papervision3d.materials.MovieMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF( width='580', height='400', frameRate='30', backgroundColor='#000000' )] public class App extends BasicView { [Embed( systemFont='Arial', fontName='Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E', mimeType='application/x-font' )] private var _Arial:Class; private var plane:Plane; public function App() { super( 580, 400, true, true, CameraType.TARGET ); Font.registerFont( _Arial ); init(); } private function init():void { var mat:MovieMaterial; var test:Sprite = new Sprite(); var button:ButtonSimple = new ButtonSimple(); button.buttonText = 'asddaskadskadskasdkasdkasdkasdkaskaskadskasd'; button.x = 100; button.y = 100; button.draw(); test.addChild( button ); mat = new MovieMaterial( test, true, true, true, new Rectangle( 0, 0, 400, 300 ) ); mat.interactive = true; mat.smooth = true; plane = new Plane( mat, 400, 300, 3, 3 ); plane.x = 0; plane.y = 0; plane.z = -700; scene.addChild( plane ); startRendering(); } } } And this gave me:

[kml_flashembed publishmethod="static" fversion="9.0.0" movie="/_/dev/ytpv3d/1.swf" width="580" height="300" targetclass="flashmovie"/]

So, as you can see, you can't click on the button, but then as soon as I add an event listener like so: package { import com.firestartermedia.lib.as3.display.component.interaction.ButtonSimple; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.text.Font; import org.papervision3d.cameras.CameraType; import org.papervision3d.materials.MovieMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF( width='580', height='400', frameRate='30', backgroundColor='#000000' )] public class App extends BasicView { [Embed( systemFont='Arial', fontName='Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E', mimeType='application/x-font' )] private var _Arial:Class; private var plane:Plane; public function App() { super( 580, 400, true, true, CameraType.TARGET ); Font.registerFont( _Arial ); init(); } private function init():void { var mat:MovieMaterial; var test:Sprite = new Sprite(); var button:ButtonSimple = new ButtonSimple(); button.addEventListener( MouseEvent.CLICK, handleClick ); button.buttonText = 'asddaskadskadskasdkasdkasdkasdkaskaskadskasd'; button.x = 100; button.y = 100; button.draw(); test.addChild( button ); mat = new MovieMaterial( test, true, true, true, new Rectangle( 0, 0, 400, 300 ) ); mat.interactive = true; mat.smooth = true; plane = new Plane( mat, 400, 300, 3, 3 ); plane.x = 0; plane.y = 0; plane.z = -700; scene.addChild( plane ); startRendering(); } private function handleClick(e:MouseEvent):void { var button:ButtonSimple = e.target as ButtonSimple; button.buttonText = 'You clicked on me'; button.draw(); } } } Which gives me:

[kml_flashembed publishmethod="static" fversion="9.0.0" movie="/_/dev/ytpv3d/2.swf" width="580" height="300" targetclass="flashmovie"/]

So, they are on the right path, and that's some good scripting there, but the main issue still remains: you can't* convert the YouTube player into the bitmap style material needed by Papervision3D, so kind of back to square one. * The reason I say can't is that if you run the script locally through say Flex Builder, it works fine, but as soon as you load it from a server, the security settings hook up and you'll soon find out you don't have permission to change the YouTube player, thus converting it to a bitmap.

© Ahmed Nuaman, all of my code and stuff is available under a 'Attribution-ShareAlike 3.0 Unported' license, however my clients own their respective copyrights.

Contact me

07811 184 436
London & Kent, UK