The attached swf and source code illustrates a problem that I have with a Mesh object that is mouse enabled. It seems that the entire rectangular area around this polygon Mesh triggers the MouseEvent3D and not just the actual area of the polygon. The cursor should not change when over the whitespace but it does change in the white corner areas of this cross object.
Am I just doing something screwy here or is this a bug?
thanks,
...bob klein…
p.s. I am using the downloaded swc file for 4.0.7 gold (8/1/12)
Here is the complete source code:
package
{
import away3d.containers.View3D;
import away3d.materials.ColorMaterial;
import away3d.entities.Mesh;
import away3d.core.base.Geometry;
import away3d.core.base.SubGeometry;
import away3d.tools.helpers.FaceHelper;
import away3d.core.base.data.UV;
import away3d.core.base.data.Vertex;
import away3d.events.MouseEvent3D;
import flash.events.Event;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
import flash.display.Sprite;
[SWF(width="500", height="400", backgroundColor="#FFFF00")]
public class bug extends Sprite
{
private var view:View3D;
public function bug()
{
var mesh:Mesh;
var triangles_array:Array = new Array(
0,0,100,0,100,100,
0,0,100,100,0,100,
100,-100,200,-100,200,200,
100,-100,200,200,100,200,
200,0,300,0,300,100,
200,0,300,100,200,100
);
view = new View3D();
view.width = 400;
view.height = 300;
view.x = 50;
view.y = 50;
view.backgroundColor = 0xffffff;
addChild(view);
mesh = polygon_mesh(
new ColorMaterial(0xff0000,1.0),
triangles_array,0);
mesh.x = -150;
mesh.y = 25;
mesh.mouseEnabled = true;
mesh.addEventListener(MouseEvent3D.MOUSE_OVER,
mouse_over);
mesh.addEventListener(MouseEvent3D.MOUSE_OUT,
mouse_out);
view.scene.addChild(mesh);
addEventListener(Event.ENTER_FRAME,render);
}
private function render ( e:Event ):void
{
view.render();
}
private function polygon_mesh ( mat: ColorMaterial,
triangles:Array,
z:int ):Mesh
{
var rval:Mesh;
var i:int;
var g:Geometry;
var sg:SubGeometry;
var uv:UV = new UV(); // don't care about UVs here...
sg = new SubGeometry();
sg.autoDeriveVertexTangents = true;
sg.autoDeriveVertexNormals = true;
sg.autoGenerateDummyUVs = true;
g = new Geometry();
g.addSubGeometry(sg);
rval = new Mesh(g,mat);
i = 0;
while (i < triangles.length) {
var v0:Vertex;
var v1:Vertex;
var v2:Vertex;
v0 = new Vertex(triangles[i],triangles[i+1],z);
v1 = new Vertex(triangles[i+2],triangles[i+3],z);
v2 = new Vertex(triangles[i+4],triangles[i+5],z);
FaceHelper.addFace(rval,v0,v1,v2,uv,uv,uv,0);
FaceHelper.addFace(rval,v0,v2,v1,uv,uv,uv,0);
i += 6;
};
return rval;
}
private function mouse_over ( e:MouseEvent3D ):void
{
Mouse.cursor = MouseCursor.BUTTON;
}
private function mouse_out ( e:MouseEvent3D ):void
{
Mouse.cursor = MouseCursor.ARROW;
}
}
}