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();
}
}
}