pinpisut / away3d

Automatically exported from code.google.com/p/away3d
0 stars 0 forks source link

sprite3D interactivity bug #136

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When I create a bitmapmaterial based on bitmapdata with transparency 
true and transparency color different from default and then use it as 
Sprite3D's material, all interactivity dissapears. 
Here is the code to reproduce the bug. 
package 
{ 
        import away3d.cameras.Camera3D; 
        import away3d.containers.ObjectContainer3D; 
        import away3d.containers.Scene3D; 
        import away3d.containers.View3D; 
        import away3d.events.MouseEvent3D; 
        import away3d.materials.BitmapMaterial; 
        import away3d.materials.WireColorMaterial; 
        import away3d.primitives.Cube; 
        import away3d.sprites.Sprite3D; 
        import flash.display.BitmapData; 
        import flash.display.Shape; 
        import flash.display.Sprite; 
        import flash.events.Event; 
        import flash.events.MouseEvent; 
        public class ShowSpriteBug extends Sprite 
        { 
                private var view:View3D; 
                private var scene:Scene3D; 
                private var camera:Camera3D; 
                private var testCube:Cube; 
                private var container:ObjectContainer3D; 
                private var sprite:Sprite3D; 
                //bitmapdata to be used in sprite3d's bitmapmaterial 
                private var bmd:BitmapData; 
                private var shape:Shape; 
                //bitmapmaterial to be used as sprite3d material 
                private var material:BitmapMaterial; 
                private var cubeMat:WireColorMaterial; 
                public function ShowSpriteBug() 
                { 
                        this.init(); 
                } 
                private function init():void 
                { 
                        this.initEngine(); 
                        this.initMaterials(); 
                        this.initObjects(); 
                        this.initListeners(); 
                } 
                private function initEngine():void 
                { 
                        this.view = new View3D(); 
                        this.scene = new Scene3D(); 
                        this.view.scene = this.scene; 
                        this.view.x = this.stage.stageWidth/2; 
                        this.view.y = this.stage.stageHeight/2; 
                        this.addChild(this.view); 
                        this.camera = this.view.camera; 
                        this.camera.moveBackward(1000); 
                        this.view.render(); 
                } 
                   //Here I initialise materials for cube and sprite3D 
                private function initMaterials():void 
                { 
                        //this.bmd = new BitmapData(200,200,true); //this works fine! 
                        this.bmd = new BitmapData(200,200,true,0x000000); //in this case 
all sprite3D interactivity disappears! 
                        this.shape = new Shape(); 
                        this.shape.graphics.beginFill(0xFF0000); 
                        this.shape.graphics.drawCircle(100,100,100); 
                        this.shape.graphics.endFill(); 
                        this.bmd.draw(this.shape); 
                        this.material = new BitmapMaterial(this.bmd); 
                        this.material.smooth = true; 
                        this.cubeMat = new  WireColorMaterial(0x00FF00); 
                } 
                private function initObjects():void 
                { 
                        this.container = new ObjectContainer3D(); 
                        this.container.useHandCursor = true; 
                        this.container.mouseEnabled = true; 
                        this.testCube = new Cube(); 
                        this.testCube.material = this.cubeMat; 
                        this.testCube.moveForward(100); 
                        this.container.addChild(this.testCube); 
                        this.sprite = new Sprite3D(this.material); 
                        this.sprite.y = 180; 
                        this.container.addSprite(this.sprite); 
                        this.scene.addChild(this.container); 
                        this.camera.lookAt(this.container.position); 
                } 
                private function initListeners():void 
                { 
                        this.addEventListener(Event.ENTER_FRAME,this.onEnterFrame); 
/*Testing sprite3d interactivity, if mouse is down, out or over 
container containing sprite3D, cube changes its color*/ 
this.container.addOnMouseOver(this.onOver); 
                        this.container.addOnMouseOut(this.onOut); 
                        this.container.addOnMouseDown(this.onDown); 
                } 
                private function onOver(event:MouseEvent3D):void 
                { 
                        this.cubeMat.color = 0xFF00FF; 
                } 
                private function onOut(event:MouseEvent3D):void 
                { 
                        this.cubeMat.color = 0x00FF00; 
                } 
                private function onDown(event:MouseEvent3D):void 
                { 
                        this.cubeMat.color = 0xFF0000; 
                } 
                private function onEnterFrame(event:Event):void 
                { 
                        this.view.render(); 
                } 
        } 

Original issue reported on code.google.com by antonkul...@gmail.com on 22 Oct 2010 at 10:45

GoogleCodeExporter commented 9 years ago
I found a dirty quick fix for that issue:

var bmd:BitmapData = new BitmapData(10,10,true); //this works fine! 

for (var xp:int = 0; xp < 10; xp++) 
{
    for (var yp:int = 0; yp < 10; yp++) 
    {
        bmd.setPixel(xp, yp, 0x00000000);
    }
}

var shape :Shape = new Shape();
shape.graphics.beginFill(0xFF0000);
shape.graphics.drawCircle(5,5,5);
shape.graphics.endFill();

bmd.draw(shape);

Original comment by roger...@gmail.com on 25 Mar 2011 at 3:33