mirror of
https://github.com/MapMakersAndProgrammers/alternativa-editor-mod.git
synced 2025-10-26 01:49:05 -07:00
props selection & placement fixed
This commit is contained in:
@@ -902,7 +902,7 @@ package alternativa.editor
|
|||||||
|
|
||||||
private function onPropMouseDown(param1:MouseEvent3D) : void
|
private function onPropMouseDown(param1:MouseEvent3D) : void
|
||||||
{
|
{
|
||||||
this.clickZ = param1.relatedObject.z;
|
this.clickZ = param1.target.z;
|
||||||
this.propDown = true;
|
this.propDown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ package alternativa.editor.prop
|
|||||||
|
|
||||||
private function onMouseDown(param1:MouseEvent3D) : void
|
private function onMouseDown(param1:MouseEvent3D) : void
|
||||||
{
|
{
|
||||||
param1.relatedObject = this;
|
param1._target = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initBitmapData() : void
|
protected function initBitmapData() : void
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package alternativa.editor.scene
|
|||||||
import alternativa.engine3d.materials.TextureMaterial;
|
import alternativa.engine3d.materials.TextureMaterial;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import mx.controls.Alert;
|
import mx.controls.Alert;
|
||||||
|
import flash.geom.Point;
|
||||||
|
|
||||||
public class CursorScene
|
public class CursorScene
|
||||||
{
|
{
|
||||||
@@ -31,6 +32,9 @@ package alternativa.editor.scene
|
|||||||
|
|
||||||
private static const greenBmp:BitmapData = new greenClass().bitmapData;
|
private static const greenBmp:BitmapData = new greenClass().bitmapData;
|
||||||
|
|
||||||
|
private static const znormal:Vector3D = new Vector3D(0,0,1);
|
||||||
|
|
||||||
|
|
||||||
protected var _object:Prop;
|
protected var _object:Prop;
|
||||||
|
|
||||||
private var redMaterial:Material;
|
private var redMaterial:Material;
|
||||||
@@ -176,9 +180,10 @@ package alternativa.editor.scene
|
|||||||
var loc1:Vector3D = null;
|
var loc1:Vector3D = null;
|
||||||
if(this._object)
|
if(this._object)
|
||||||
{
|
{
|
||||||
loc1 = this.mainScene.camera.projectGlobal(new Vector3D(this.mainScene.view.mouseX,this.mainScene.view.mouseY,this._object.z));
|
loc1 = this.mainScene.camera.projectViewPointToPlane(new Point(this.mainScene.view.mouseX,this.mainScene.view.mouseY),znormal,this._object.z);
|
||||||
this._object.x = loc1.x;
|
this._object.x = loc1.x;
|
||||||
this._object.y = loc1.y;
|
this._object.y = loc1.y;
|
||||||
|
|
||||||
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
|
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
|
||||||
{
|
{
|
||||||
this._object.snapToGrid();
|
this._object.snapToGrid();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ package alternativa.editor.scene
|
|||||||
import alternativa.utils.MathUtils;
|
import alternativa.utils.MathUtils;
|
||||||
import flash.geom.Point;
|
import flash.geom.Point;
|
||||||
import alternativa.engine3d.core.Object3DContainer;
|
import alternativa.engine3d.core.Object3DContainer;
|
||||||
|
import flash.geom.Vector3D;
|
||||||
|
|
||||||
public class EditorScene extends Scene3D
|
public class EditorScene extends Scene3D
|
||||||
{
|
{
|
||||||
@@ -35,17 +36,17 @@ package alternativa.editor.scene
|
|||||||
|
|
||||||
public var occupyMap:OccupyMap;
|
public var occupyMap:OccupyMap;
|
||||||
|
|
||||||
protected var znormal:Point3D;
|
protected var znormal:Vector3D;
|
||||||
|
|
||||||
protected var ynormal:Point3D;
|
protected var ynormal:Vector3D;
|
||||||
|
|
||||||
protected var xnormal:Point3D;
|
protected var xnormal:Vector3D;
|
||||||
|
|
||||||
public function EditorScene()
|
public function EditorScene()
|
||||||
{
|
{
|
||||||
this.znormal = new Point3D(0,0,1);
|
this.znormal = new Vector3D(0,0,1);
|
||||||
this.ynormal = new Point3D(0,1,0);
|
this.ynormal = new Vector3D(0,1,0);
|
||||||
this.xnormal = new Point3D(1,0,0);
|
this.xnormal = new Vector3D(1,0,0);
|
||||||
super();
|
super();
|
||||||
this.initScene();
|
this.initScene();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,13 +430,13 @@ package alternativa.editor.scene
|
|||||||
loc8 = getCameraFacing();
|
loc8 = getCameraFacing();
|
||||||
if(loc8 == CameraFacing.Y || loc8 == CameraFacing.NEGATIVE_Y)
|
if(loc8 == CameraFacing.Y || loc8 == CameraFacing.NEGATIVE_Y)
|
||||||
{
|
{
|
||||||
loc3 = camera.projectGlobal(new Vector3D(loc2.x,loc2.y,this.selectedProp.y));
|
loc3 = camera.projectViewPointToPlane(loc2,ynormal,this.selectedProp.y);
|
||||||
loc5 = loc3.x - this.selectedProp.x;
|
loc5 = loc3.x - this.selectedProp.x;
|
||||||
this.selectedProp.x = loc3.x;
|
this.selectedProp.x = loc3.x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
loc3 = camera.projectGlobal(new Vector3D(loc2.x,loc2.y,this.selectedProp.x));
|
loc3 = camera.projectViewPointToPlane(loc2,xnormal,this.selectedProp.x);
|
||||||
loc6 = loc3.y - this.selectedProp.y;
|
loc6 = loc3.y - this.selectedProp.y;
|
||||||
this.selectedProp.y = loc3.y;
|
this.selectedProp.y = loc3.y;
|
||||||
}
|
}
|
||||||
@@ -445,7 +445,7 @@ package alternativa.editor.scene
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
loc3 = camera.projectGlobal(new Vector3D(loc2.x,loc2.y,this.selectedProp.z));
|
loc3 = camera.projectViewPointToPlane(loc2,znormal,this.selectedProp.z);
|
||||||
loc5 = loc3.x - this.selectedProp.x;
|
loc5 = loc3.x - this.selectedProp.x;
|
||||||
loc6 = loc3.y - this.selectedProp.y;
|
loc6 = loc3.y - this.selectedProp.y;
|
||||||
this.selectedProp.x = loc3.x;
|
this.selectedProp.x = loc3.x;
|
||||||
@@ -512,7 +512,7 @@ package alternativa.editor.scene
|
|||||||
var loc3:Boolean = false;
|
var loc3:Boolean = false;
|
||||||
if(!param1.ctrlKey)
|
if(!param1.ctrlKey)
|
||||||
{
|
{
|
||||||
loc2 = param1.relatedObject as Prop;
|
loc2 = param1.target as Prop;
|
||||||
if(this.isSelectableProp(loc2))
|
if(this.isSelectableProp(loc2))
|
||||||
{
|
{
|
||||||
loc3 = loc2.selected;
|
loc3 = loc2.selected;
|
||||||
|
|||||||
@@ -38,11 +38,14 @@ package alternativa.engine3d.core
|
|||||||
import flash.display.StageAlign;
|
import flash.display.StageAlign;
|
||||||
import __AS3__.vec.*;
|
import __AS3__.vec.*;
|
||||||
import alternativa.engine3d.alternativa3d;
|
import alternativa.engine3d.alternativa3d;
|
||||||
|
import alternativa.types.Matrix4;
|
||||||
|
|
||||||
use namespace alternativa3d;
|
use namespace alternativa3d;
|
||||||
|
|
||||||
public class Camera3D extends Object3D
|
public class Camera3D extends Object3D
|
||||||
{
|
{
|
||||||
|
private static const tmpOrigin:Vector3D = new Vector3D();
|
||||||
|
private static const tmpDir:Vector3D = new Vector3D();
|
||||||
|
|
||||||
alternativa3d static var renderId:int = 0;
|
alternativa3d static var renderId:int = 0;
|
||||||
private static const constantsAttributesCount:int = 8;
|
private static const constantsAttributesCount:int = 8;
|
||||||
@@ -1054,6 +1057,68 @@ package alternativa.engine3d.core
|
|||||||
_arg_2.z = (_arg_2.z * _local_12);
|
_arg_2.z = (_arg_2.z * _local_12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function projectViewPointToPlane(param1:Point, param2:Vector3D, param3:Number, param4:Vector3D = null) : Vector3D
|
||||||
|
{
|
||||||
|
if(param4 == null)
|
||||||
|
{
|
||||||
|
param4 = new Vector3D();
|
||||||
|
}
|
||||||
|
this.calculateRayOriginAndVector(param1.x - (this.view._width >> 1),param1.y - (this.view._height >> 1),tmpOrigin,tmpDir,true);
|
||||||
|
if(!this.calculateLineAndPlaneIntersection(tmpOrigin,tmpDir,param2,param3,param4))
|
||||||
|
{
|
||||||
|
param4.setTo(NaN,NaN,NaN);
|
||||||
|
}
|
||||||
|
return param4;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateRayOriginAndVector(param1:Number, param2:Number, param3:Vector3D, param4:Vector3D, param5:Boolean = false) : void
|
||||||
|
{
|
||||||
|
var loc6:Number = NaN;
|
||||||
|
var loc7:Number = NaN;
|
||||||
|
var loc8:Number = NaN;
|
||||||
|
var loc9:Matrix4 = null;
|
||||||
|
if(param5)
|
||||||
|
{
|
||||||
|
loc9 = Object3D.tmpMatrix4;
|
||||||
|
this.getTransformation(loc9);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loc9 = this.transformation;
|
||||||
|
}
|
||||||
|
param3.x = loc9.d;
|
||||||
|
param3.y = loc9.h;
|
||||||
|
param3.z = loc9.l;
|
||||||
|
loc6 = param1;
|
||||||
|
loc7 = param2;
|
||||||
|
if(param5)
|
||||||
|
{
|
||||||
|
loc8 = this.focalLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loc8 = this.focalLength;
|
||||||
|
}
|
||||||
|
param4.x = loc6 * loc9.a + loc7 * loc9.b + loc8 * loc9.c;
|
||||||
|
param4.y = loc6 * loc9.e + loc7 * loc9.f + loc8 * loc9.g;
|
||||||
|
param4.z = loc6 * loc9.i + loc7 * loc9.j + loc8 * loc9.k;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateLineAndPlaneIntersection(param1:Vector3D, param2:Vector3D, param3:Vector3D, param4:Number, param5:Vector3D) : Boolean
|
||||||
|
{
|
||||||
|
var loc6:Number = param3.x * param2.x + param3.y * param2.y + param3.z * param2.z;
|
||||||
|
if(loc6 < 1e-8 && loc6 > -1e-8)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var loc7:Number = (param4 - param1.x * param3.x - param1.y * param3.y - param1.z * param3.z) / loc6;
|
||||||
|
param5.x = param1.x + loc7 * param2.x;
|
||||||
|
param5.y = param1.y + loc7 * param2.y;
|
||||||
|
param5.z = param1.z + loc7 * param2.z;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
override public function clone():Object3D
|
override public function clone():Object3D
|
||||||
{
|
{
|
||||||
var _local_1:Camera3D = new Camera3D();
|
var _local_1:Camera3D = new Camera3D();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ package alternativa.engine3d.core
|
|||||||
public var relatedObject:Object3D;
|
public var relatedObject:Object3D;
|
||||||
public var localOrigin:Vector3D = new Vector3D();
|
public var localOrigin:Vector3D = new Vector3D();
|
||||||
public var localDirection:Vector3D = new Vector3D();
|
public var localDirection:Vector3D = new Vector3D();
|
||||||
alternativa3d var _target:Object3D;
|
public var _target:Object3D;
|
||||||
alternativa3d var _currentTarget:Object3D;
|
alternativa3d var _currentTarget:Object3D;
|
||||||
alternativa3d var _bubbles:Boolean;
|
alternativa3d var _bubbles:Boolean;
|
||||||
alternativa3d var _eventPhase:uint = 3;
|
alternativa3d var _eventPhase:uint = 3;
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ package alternativa.engine3d.core
|
|||||||
alternativa3d static const tB:Object3D = new (Object3D)();
|
alternativa3d static const tB:Object3D = new (Object3D)();
|
||||||
private static const staticSphere:Vector3D = new Vector3D();
|
private static const staticSphere:Vector3D = new Vector3D();
|
||||||
|
|
||||||
|
public static const tmpMatrix4:Matrix4 = new Matrix4();
|
||||||
|
|
||||||
private var _x:Number = 0;
|
private var _x:Number = 0;
|
||||||
private var _y:Number = 0;
|
private var _y:Number = 0;
|
||||||
private var _z:Number = 0;
|
private var _z:Number = 0;
|
||||||
@@ -226,6 +228,12 @@ package alternativa.engine3d.core
|
|||||||
return (new Matrix3D(Vector.<Number>([tA.ma, tA.me, tA.mi, 0, tA.mb, tA.mf, tA.mj, 0, tA.mc, tA.mg, tA.mk, 0, tA.md, tA.mh, tA.ml, 1])));
|
return (new Matrix3D(Vector.<Number>([tA.ma, tA.me, tA.mi, 0, tA.mb, tA.mf, tA.mj, 0, tA.mc, tA.mg, tA.mk, 0, tA.md, tA.mh, tA.ml, 1])));
|
||||||
}
|
}
|
||||||
public function get transformation() : Matrix4
|
public function get transformation() : Matrix4
|
||||||
|
{
|
||||||
|
var matrix:Matrix4 = new Matrix4();
|
||||||
|
getTransformation(matrix);
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
public function getTransformation(newMatrix:Matrix4) : void
|
||||||
{
|
{
|
||||||
tA.composeMatrixFromSource(this);
|
tA.composeMatrixFromSource(this);
|
||||||
var _local_1:Object3D = this;
|
var _local_1:Object3D = this;
|
||||||
@@ -235,7 +243,7 @@ package alternativa.engine3d.core
|
|||||||
tB.composeMatrixFromSource(_local_1);
|
tB.composeMatrixFromSource(_local_1);
|
||||||
tA.appendMatrix(tB);
|
tA.appendMatrix(tB);
|
||||||
};
|
};
|
||||||
return new Matrix4(tA.ma, tA.mb, tA.mc, tA.md, tA.me, tA.mf, tA.mg, tA.mh, tA.mi, tA.mj, tA.mk, tA.ml);
|
newMatrix.init(tA.ma, tA.mb, tA.mc, tA.md, tA.me, tA.mf, tA.mg, tA.mh, tA.mi, tA.mj, tA.mk, tA.ml);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set matrix(_arg_1:Matrix3D):void
|
public function set matrix(_arg_1:Matrix3D):void
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ package alternativa.engine3d.core{
|
|||||||
private static var configured:Boolean = false;
|
private static var configured:Boolean = false;
|
||||||
private static var cleared:Boolean = true;
|
private static var cleared:Boolean = true;
|
||||||
|
|
||||||
private static const tmpVec1:Vector3D = new Vector3D();
|
private static const v1:Vector3D = new Vector3D();
|
||||||
|
private static const v2:Vector3D = new Vector3D();
|
||||||
private static const tmpMatrix3:Matrix3 = new Matrix3();
|
private static const tmpMatrix3:Matrix3 = new Matrix3();
|
||||||
|
|
||||||
private var presented:Boolean = false;
|
private var presented:Boolean = false;
|
||||||
@@ -300,7 +301,7 @@ package alternativa.engine3d.core{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onMouseMove(_arg_1:MouseEvent):void{
|
private function onMouseMove(_arg_1:MouseEvent):void{
|
||||||
return;
|
return; //disable for optimization because it is not used
|
||||||
this.onMouse(_arg_1);
|
this.onMouse(_arg_1);
|
||||||
this.defineTarget(_arg_1);
|
this.defineTarget(_arg_1);
|
||||||
if (this.target != null)
|
if (this.target != null)
|
||||||
@@ -620,8 +621,6 @@ package alternativa.engine3d.core{
|
|||||||
mouse.x = _arg_1.localX;
|
mouse.x = _arg_1.localX;
|
||||||
mouse.y = _arg_1.localY;
|
mouse.y = _arg_1.localY;
|
||||||
|
|
||||||
//idk how to make this to work, pls help
|
|
||||||
|
|
||||||
this.target = null;
|
this.target = null;
|
||||||
|
|
||||||
var root:Object3DContainer = this.camera.parent;
|
var root:Object3DContainer = this.camera.parent;
|
||||||
@@ -638,43 +637,17 @@ package alternativa.engine3d.core{
|
|||||||
if(!root.mouseChildren)
|
if(!root.mouseChildren)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//ErrorHandler.clearMessages();
|
var origin:Vector3D = v1;
|
||||||
|
var direction:Vector3D = v2;
|
||||||
|
|
||||||
tmpVec1.setTo(mouse.x,mouse.y,0);
|
this.camera.calculateRay(origin, direction, mouse.x, mouse.y);
|
||||||
var origin:Vector3D = this.camera.projectGlobal(tmpVec1);
|
|
||||||
|
|
||||||
tmpVec1.setTo(0,0,1);
|
var rayHit:RayIntersectionData = root.intersectRay(origin, direction, null, this.camera);
|
||||||
|
|
||||||
//ErrorHandler.addText("local dir: " + tmpVec1);
|
|
||||||
|
|
||||||
var dir:Vector3D = camera.localToGlobal(tmpVec1,true);
|
|
||||||
|
|
||||||
//debugging:
|
|
||||||
/*ErrorHandler.addText("ray: origin="+origin + " ; dir=" + dir);
|
|
||||||
|
|
||||||
var box:Box = new Box(10,10,30);
|
|
||||||
box.setMaterialToAllFaces(new FillMaterial(0xff0000));
|
|
||||||
root.addChild(box);
|
|
||||||
|
|
||||||
tmpMatrix3.setDirectionVector(dir);
|
|
||||||
var rotation:Vector3D = new Vector3D();
|
|
||||||
tmpMatrix3.getEulerAngles(rotation);
|
|
||||||
|
|
||||||
box.setPositionXYZ(origin.x,origin.y,origin.z);
|
|
||||||
box.setRotationXYZ(rotation.x,rotation.y,rotation.z);*/
|
|
||||||
|
|
||||||
var rayHit:RayIntersectionData = root.intersectRay(origin, dir, null, this.camera);
|
|
||||||
|
|
||||||
/*setTimeout(function():void{
|
|
||||||
ErrorHandler.showWindow();
|
|
||||||
},10);*/
|
|
||||||
|
|
||||||
if(rayHit == null)
|
if(rayHit == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.target = rayHit.object;
|
this.target = rayHit.object;
|
||||||
|
|
||||||
//ErrorHandler.addText("hit: " + rayHit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function getObjectsUnderPoint(_arg_1:Point):Array{
|
override public function getObjectsUnderPoint(_arg_1:Point):Array{
|
||||||
|
|||||||
@@ -43,6 +43,22 @@ package alternativa.types
|
|||||||
this.l = param12;
|
this.l = param12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function init(param1:Number = 1, param2:Number = 0, param3:Number = 0, param4:Number = 0, param5:Number = 0, param6:Number = 1, param7:Number = 0, param8:Number = 0, param9:Number = 0, param10:Number = 0, param11:Number = 1, param12:Number = 0) : void
|
||||||
|
{
|
||||||
|
this.a = param1;
|
||||||
|
this.b = param2;
|
||||||
|
this.c = param3;
|
||||||
|
this.d = param4;
|
||||||
|
this.e = param5;
|
||||||
|
this.f = param6;
|
||||||
|
this.g = param7;
|
||||||
|
this.h = param8;
|
||||||
|
this.i = param9;
|
||||||
|
this.j = param10;
|
||||||
|
this.k = param11;
|
||||||
|
this.l = param12;
|
||||||
|
}
|
||||||
|
|
||||||
public static function inverseTranslationMatrix(param1:Number = 0, param2:Number = 0, param3:Number = 0) : Matrix4
|
public static function inverseTranslationMatrix(param1:Number = 0, param2:Number = 0, param3:Number = 0) : Matrix4
|
||||||
{
|
{
|
||||||
return new Matrix4(1,0,0,-param1,0,1,0,-param2,0,0,1,-param3);
|
return new Matrix4(1,0,0,-param1,0,1,0,-param2,0,0,1,-param3);
|
||||||
|
|||||||
Reference in New Issue
Block a user