I was trying to make a DraggableMeshContainer class, but I ran into some trouble. The meshes where disappearing when I started to drag with Drag3D.
So I broke it down to the simplest example possible, and it was still happening.
This is my example class:
public class Example002 extends Sprite
{
//plane texture
[Embed(source="floor_diffuse.jpg")]
public static var FloorDiffuse:Class;
//engine variables
private var _view:View3D;
//scene objects
private var _sphere:Mesh;
// drag
private var _drag :Drag3D;
private var _isDragging :Boolean = false;
public function Example002()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//setup the view
_view = new View3D();
addChild(_view);
//setup the camera
_view.camera.z = -600;
_view.camera.y = 500;
_view.camera.lookAt(new Vector3D());
//setup the scene
_sphere = new Mesh(new SphereGeometry(100, 100), new TextureMaterial(Cast.bitmapTexture(FloorDiffuse)));
_sphere.mouseEnabled = true;
_view.scene.addChild(_sphere);
_sphere.addEventListener(MouseEvent3D.MOUSE_DOWN, startDragging);
_sphere.addEventListener(MouseEvent3D.MOUSE_UP, stopDragging);
//setup the render loop
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
private function startDragging(event : MouseEvent3D) : void
{
trace('start');
_drag = new Drag3D(_view, _sphere, Drag3D.PLANE_ZY);
_isDragging = true;
}
private function stopDragging(event : MouseEvent3D) : void
{
trace('stop');
_isDragging = false;
}
/**
* render loop
*/
private function _onEnterFrame(e:Event):void
{
if (_isDragging)
{
_drag.updateDrag();
trace('_sphere.x: ' + (_sphere.x));
trace('_sphere.y: ' + (_sphere.y));
trace('_sphere.z: ' + (_sphere.z));
}
else
{
_sphere.rotationY += 1;
}
_view.render();
}
private function onResize(event:Event = null):void
{
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
}
}
What happens is that when _isDragging is set to true, after the _drag.updateDrag(), the coordinates of _sphere return NaN… I tried all the draggable planes… I am now a bit confused… it should be simple right?
I traced inside the Drag3D.updateDrag():
localIntersect = _object3d.parent.inverseSceneTransform.transformVector(_intersect);
trace('localIntersect: ' + (localIntersect));
That traces like this: localIntersect: Vector3D(NaN, NaN, NaN)
Any ideas?
Am I using a wrong version? Last git update is last year for the Drag3D class.