away3d / away3d-core-fp11

Away3D engine for Flash Player 11
http://www.away3d.com
Other
639 stars 274 forks source link

RaycastPicker bug #700

Open matrix3d opened 10 years ago

matrix3d commented 10 years ago

why can not pick?

the center of point is x=8 z=8

package mytest 
{
    import away3d.containers.View3D;
    import away3d.core.base.Geometry;
    import away3d.core.base.SubGeometry;
    import away3d.core.pick.PickingColliderType;
    import away3d.core.pick.PickingCollisionVO;
    import away3d.core.pick.RaycastPicker;
    import away3d.entities.Mesh;
    import away3d.events.MouseEvent3D;
    import away3d.materials.ColorMaterial;
    import away3d.materials.MaterialBase;
    import flash.events.Event;
    import flash.geom.Vector3D;
    /**
     * ...
     * @author lizhi
     */
    public class TestMouse extends View3D
    {

        public function TestMouse() 
        {
            addMesh(Vector.([8, -13.898313811479861 , 7, 8, -13.176487753206212, 8, 7, -13.679803966417216, 8]));
            addMesh(Vector.([8, -13.176487753206212, 8, 8, -11.964657473672023, 9, 7, -12.450258983111945, 9]));
            addMesh(Vector.([7 ,-12.450258983111945 ,9 ,7, -13.679803966417216 ,8 ,8, -13.176487753206212 ,8]));
            addMesh(Vector.([9 ,-12.955115272308943, 7, 9, -11.638058724648703 ,8, 8, -13.176487753206212, 8]));
            addMesh(Vector.([8, -13.176487753206212 ,8 ,8 ,-13.898313811479861, 7 ,9 ,-12.955115272308943, 7]));
            addMesh(Vector.([8, -11.964657473672023, 9, 8, -13.176487753206212 ,8, 9 ,-11.638058724648703, 8]));

            var raycastPicker:RaycastPicker = new RaycastPicker(true);
            var vo:PickingCollisionVO=raycastPicker.getSceneCollision(new Vector3D(8,1000 , 8),new Vector3D(0,-1,0), scene)
            trace(vo?vo.localPosition:null);
            camera.x = 0;
            camera.z = 0;
            camera.y = 10;
            camera.lookAt(new Vector3D);
        }
        private function addMesh(vs:Vector.):void {
            var g:Geometry = new Geometry();
            var subg:SubGeometry = new SubGeometry();
            subg.updateIndexData(Vector.([0,1,2]));
            subg.updateVertexData(vs);
            g.addSubGeometry(subg);

            var t:MaterialBase = new ColorMaterial(0xffffff * Math.random());
            t.bothSides = true;

            var m:Mesh = new Mesh(g, t);
            m.mouseEnabled = true;
            m.pickingCollider = PickingColliderType.AS3_BEST_HIT;
            scene.addChild(m);
            m.addEventListener(MouseEvent3D.MOUSE_OVER, m_mouseOver);
            m.addEventListener(MouseEvent3D.MOUSE_OUT, m_mouseOut);
            addEventListener(Event.ENTER_FRAME, enterFrame);
        }

        private function m_mouseOut(e:MouseEvent3D):void 
        {
            var m:Mesh = e.currentTarget as Mesh;
            m.showBounds = false;
        }

        private function m_mouseOver(e:MouseEvent3D):void 
        {
            var m:Mesh = e.currentTarget as Mesh;
            m.showBounds = true;
        }

        private function enterFrame(e:Event):void 
        {
            render();
        }

    }

}
gonchar commented 10 years ago

thank you for the issue, I will check it soon

matrix3d commented 10 years ago

@gonchar thanks there have 5 mesh,if you marge it to one mesh.the vo also null. var vo:PickingCollisionVO=raycastPicker.getSceneCollision(new Vector3D(8,1000 , 8),new Vector3D(0,-1,0), scene)

but if set vector3d (8.0001,1000,8.0001) the vo not null.