combined cursor and main scenes

This commit is contained in:
Tubix
2024-12-18 17:12:33 +00:00
parent dc89c4a634
commit 6e29d305d5
3 changed files with 363 additions and 407 deletions

View File

@@ -4,7 +4,6 @@ package alternativa.editor
import alternativa.editor.eventjournal.EventJournalItem; import alternativa.editor.eventjournal.EventJournalItem;
import alternativa.editor.prop.MeshProp; import alternativa.editor.prop.MeshProp;
import alternativa.editor.prop.Prop; import alternativa.editor.prop.Prop;
import alternativa.editor.scene.CursorScene;
import alternativa.editor.scene.EditorScene; import alternativa.editor.scene.EditorScene;
import alternativa.editor.scene.MainScene; import alternativa.editor.scene.MainScene;
import alternativa.editor.scene.OccupyMap; import alternativa.editor.scene.OccupyMap;
@@ -38,7 +37,7 @@ package alternativa.editor
private static const cameraOffset:Point3D = new Point3D(); private static const cameraOffset:Point3D = new Point3D();
public var cursorScene:CursorScene; //public var cursorScene:CursorScene;
public var mainScene:MainScene; public var mainScene:MainScene;
@@ -201,11 +200,11 @@ package alternativa.editor
{ {
removeEventListener(Event.ADDED_TO_STAGE,this.onAddedToStage); removeEventListener(Event.ADDED_TO_STAGE,this.onAddedToStage);
this.keyMapper.startListening(stage); this.keyMapper.startListening(stage);
this.cursorScene = new CursorScene(stage,this); //this.mainScene = new CursorScene(stage,this);
this.mainScene = new MainScene(); this.mainScene = new MainScene(stage,this);
this.cursorScene.occupyMap = this.mainScene.occupyMap; //this.mainScene.occupyMap = this.mainScene.occupyMap;
addChild(this.mainScene.view); addChild(this.mainScene.view);
addChild(this.cursorScene.view); //addChild(this.mainScene.view);
this.boundBoxesOverlay = new Shape(); this.boundBoxesOverlay = new Shape();
addChild(this.boundBoxesOverlay); addChild(this.boundBoxesOverlay);
this.dominationOverlay = new Shape(); this.dominationOverlay = new Shape();
@@ -214,7 +213,7 @@ package alternativa.editor
addChild(this.selectionRectOverlay); addChild(this.selectionRectOverlay);
this.initListeners(); this.initListeners();
this.eventJournal = new EventJournal(); this.eventJournal = new EventJournal();
var loc2:Object3D = this.cursorScene.camera; var loc2:Object3D = this.mainScene.camera;
this.cameraDistance = Math.sqrt(loc2.x * loc2.x + loc2.y * loc2.y + loc2.z * loc2.z); this.cameraDistance = Math.sqrt(loc2.x * loc2.x + loc2.y * loc2.y + loc2.z * loc2.z);
} }
@@ -246,7 +245,7 @@ package alternativa.editor
if(this.mainScene.selectedProp != null) if(this.mainScene.selectedProp != null)
{ {
this.startSelectionCoords = new Point3D().copyFromObject3D(this.mainScene.selectedProp); this.startSelectionCoords = new Point3D().copyFromObject3D(this.mainScene.selectedProp);
this.cursorScene.visible = false; this.mainScene.objectVisible = false;
} }
} }
this.mouseDown = true; this.mouseDown = true;
@@ -298,17 +297,17 @@ package alternativa.editor
{ {
if(this.propDown) if(this.propDown)
{ {
if(this.cursorScene.object) if(this.mainScene.object)
{ {
this.cursorScene.object.z = this.clickZ; this.mainScene.object.z = this.clickZ;
} }
this.propDown = false; this.propDown = false;
} }
this.cursorScene.moveCursorByMouse(); this.mainScene.moveCursorByMouse();
if(!this.cursorScene.visible) if(!this.mainScene.objectVisible)
{ {
this.mainScene.deselectProps(); this.mainScene.deselectProps();
this.cursorScene.visible = true; this.mainScene.objectVisible = true;
} }
} }
else if(param1.shiftKey) else if(param1.shiftKey)
@@ -416,7 +415,7 @@ package alternativa.editor
} }
else if(this.middleDown) else if(this.middleDown)
{ {
loc9 = this.cursorScene.camera.transformation; loc9 = this.mainScene.camera.transformation;
loc10 = new Point3D(loc9.a,loc9.e,loc9.i); loc10 = new Point3D(loc9.a,loc9.e,loc9.i);
loc11 = new Point3D(loc9.b,loc9.f,loc9.j); loc11 = new Point3D(loc9.b,loc9.f,loc9.j);
loc10.multiply(10 * (this.prevMoveX - param1.stageX)); loc10.multiply(10 * (this.prevMoveX - param1.stageX));
@@ -424,7 +423,7 @@ package alternativa.editor
loc12 = new Point3D(loc9.d,loc9.h,loc9.l); loc12 = new Point3D(loc9.d,loc9.h,loc9.l);
loc12.add(loc10); loc12.add(loc10);
loc12.add(loc11); loc12.add(loc11);
this.cursorScene.cameraController.setObjectPos(this.cursorScene.container.globalToLocal(loc12.toVector3D())); this.mainScene.cameraController.setObjectPos(this.mainScene.container.globalToLocal(loc12.toVector3D()));
} }
else if(this.mouseDown) else if(this.mouseDown)
{ {
@@ -475,7 +474,7 @@ package alternativa.editor
{ {
this.mainScene.selectProps(this.mainScene.getPropsUnderRect(loc15,loc13,loc14,true)); this.mainScene.selectProps(this.mainScene.getPropsUnderRect(loc15,loc13,loc14,true));
} }
this.cursorScene.visible = false; this.mainScene.objectVisible = false;
} }
} }
} }
@@ -500,18 +499,18 @@ package alternativa.editor
if(this.mainScene.selectedProp) if(this.mainScene.selectedProp)
loc2.copyFromObject3D(this.mainScene.selectedProp) loc2.copyFromObject3D(this.mainScene.selectedProp)
else else
loc2.copyFromVector3D(this.cursorScene.camera.localToGlobal(cameraPointV3)); loc2.copyFromVector3D(this.mainScene.camera.localToGlobal(cameraPointV3));
var loc3:Point3D = new Point3D().copyFromVector3D(this.cursorScene.container.localToGlobal(this.cursorScene.cameraController.coords3D)); var loc3:Point3D = new Point3D().copyFromVector3D(this.mainScene.container.localToGlobal(this.mainScene.cameraController.coords3D));
var loc4:Point3D = loc3.clone(); var loc4:Point3D = loc3.clone();
var loc5:Point3D = Point3D.difference(loc2,loc3); var loc5:Point3D = Point3D.difference(loc2,loc3);
if(loc5.length < 500) if(loc5.length < 500)
{ {
loc5 = Point3D.difference(new Point3D().copyFromVector3D(this.cursorScene.camera.localToGlobal(cameraPointV3)),loc3); loc5 = Point3D.difference(new Point3D().copyFromVector3D(this.mainScene.camera.localToGlobal(cameraPointV3)),loc3);
} }
loc5.normalize(); loc5.normalize();
loc5.multiply(param1 * 100); loc5.multiply(param1 * 100);
loc3.add(loc5); loc3.add(loc5);
this.cursorScene.cameraController.setObjectPos(this.cursorScene.container.globalToLocal(loc3.toVector3D())); this.mainScene.cameraController.setObjectPos(this.mainScene.container.globalToLocal(loc3.toVector3D()));
} }
private function onMouseOut(param1:MouseEvent) : void private function onMouseOut(param1:MouseEvent) : void
@@ -519,7 +518,7 @@ package alternativa.editor
if(param1.buttonDown) if(param1.buttonDown)
{ {
parent.addEventListener(MouseEvent.ROLL_OVER,this.onMouseOver); parent.addEventListener(MouseEvent.ROLL_OVER,this.onMouseOver);
this.cursorScene.containerController.setMouseLook(false); this.mainScene.containerController.setMouseLook(false);
} }
} }
@@ -553,15 +552,15 @@ package alternativa.editor
} }
else else
{ {
loc2 = new Point3D().copyFromVector3D(this.cursorScene.camera.localToGlobal(new Vector3D(0,0,this.cameraDistance))); loc2 = new Point3D().copyFromVector3D(this.mainScene.camera.localToGlobal(new Vector3D(0,0,this.cameraDistance)));
} }
loc4 = this.cursorScene.containerController.coords.clone(); loc4 = this.mainScene.containerController.coords.clone();
loc4.subtract(loc2); loc4.subtract(loc2);
loc5 = new Point3D().copyFromVector3D(this.cursorScene.container.localToGlobal(this.cursorScene.cameraController.coords3D)); loc5 = new Point3D().copyFromVector3D(this.mainScene.container.localToGlobal(this.mainScene.cameraController.coords3D));
loc5.add(loc4); loc5.add(loc4);
this.cursorScene.cameraController.setObjectPos(this.cursorScene.container.globalToLocal(loc5.toVector3D())); this.mainScene.cameraController.setObjectPos(this.mainScene.container.globalToLocal(loc5.toVector3D()));
this.cursorScene.containerController.coords = loc2; this.mainScene.containerController.coords = loc2;
this.cursorScene.containerController.setMouseLook(true); this.mainScene.containerController.setMouseLook(true);
} }
else else
{ {
@@ -572,28 +571,28 @@ package alternativa.editor
private function onMiddleMouseUp(param1:MouseEvent) : void private function onMiddleMouseUp(param1:MouseEvent) : void
{ {
this.middleDown = false; this.middleDown = false;
this.cursorScene.containerController.setMouseLook(false); this.mainScene.containerController.setMouseLook(false);
} }
private function onEnterFrame(param1:Event) : void private function onEnterFrame(param1:Event) : void
{ {
this.cursorScene.containerController.yawLeft(this.keyMapper.keyPressed(0)); this.mainScene.containerController.yawLeft(this.keyMapper.keyPressed(0));
this.cursorScene.containerController.yawRight(this.keyMapper.keyPressed(1)); this.mainScene.containerController.yawRight(this.keyMapper.keyPressed(1));
this.cursorScene.containerController.pitchDown(this.keyMapper.keyPressed(6)); this.mainScene.containerController.pitchDown(this.keyMapper.keyPressed(6));
this.cursorScene.containerController.pitchUp(this.keyMapper.keyPressed(7)); this.mainScene.containerController.pitchUp(this.keyMapper.keyPressed(7));
this.cursorScene.containerController.speed = 2000; this.mainScene.containerController.speed = 2000;
this.cursorScene.containerController.moveLeft(this.keyMapper.keyPressed(2)); this.mainScene.containerController.moveLeft(this.keyMapper.keyPressed(2));
this.cursorScene.containerController.moveRight(this.keyMapper.keyPressed(3)); this.mainScene.containerController.moveRight(this.keyMapper.keyPressed(3));
this.cursorScene.containerController.moveForward(this.keyMapper.keyPressed(4)); this.mainScene.containerController.moveForward(this.keyMapper.keyPressed(4));
this.cursorScene.containerController.moveBack(this.keyMapper.keyPressed(5)); this.mainScene.containerController.moveBack(this.keyMapper.keyPressed(5));
this.cursorScene.cameraController.processInput(); this.mainScene.cameraController.processInput();
this.cursorScene.containerController.processInput(); this.mainScene.containerController.processInput();
this.cursorScene.calculate(); //this.mainScene.calculate();
this.cameraTransformation = this.cursorScene.camera.transformation; this.cameraTransformation = this.mainScene.camera.transformation;
cameraOffset.x = this.cameraTransformation.d; cameraOffset.x = this.cameraTransformation.d;
cameraOffset.y = this.cameraTransformation.h; cameraOffset.y = this.cameraTransformation.h;
cameraOffset.z = this.cameraTransformation.l; cameraOffset.z = this.cameraTransformation.l;
this.cursorScene.drawAxis(this.cameraTransformation); this.mainScene.drawAxis(this.cameraTransformation);
var loc2:Point3D = this.cameraTransformation.getRotations(); var loc2:Point3D = this.cameraTransformation.getRotations();
this.mainScene.setCameraPosition(cameraOffset,loc2.x,loc2.y,loc2.z); this.mainScene.setCameraPosition(cameraOffset,loc2.x,loc2.y,loc2.z);
this.mainScene.calculate(); this.mainScene.calculate();
@@ -631,9 +630,9 @@ package alternativa.editor
} }
getMeshBounds(loc2,this.min,this.max); getMeshBounds(loc2,this.min,this.max);
fillBBPoints(this.min,this.max,this.bbPoints); fillBBPoints(this.min,this.max,this.bbPoints);
var loc3:Number = this.cursorScene.camera.focalLength; var loc3:Number = this.mainScene.camera.focalLength;
var loc6:Number = 0.5 * this.cursorScene.view.width; var loc6:Number = 0.5 * this.mainScene.view.width;
var loc7:Number = 0.5 * this.cursorScene.view.height; var loc7:Number = 0.5 * this.mainScene.view.height;
loc5 = 0; loc5 = 0;
while(loc5 < 8) while(loc5 < 8)
{ {
@@ -686,7 +685,7 @@ package alternativa.editor
private function onResize(param1:Event = null) : void private function onResize(param1:Event = null) : void
{ {
this.cursorScene.viewResize(parent.width - 20,parent.height - 40); this.mainScene.viewResize(parent.width - 20,parent.height - 40);
this.mainScene.viewResize(parent.width - 20,parent.height - 40); this.mainScene.viewResize(parent.width - 20,parent.height - 40);
} }
@@ -703,9 +702,9 @@ package alternativa.editor
case Keyboard.NUMBER_0: case Keyboard.NUMBER_0:
if(param1.ctrlKey) if(param1.ctrlKey)
{ {
this.cursorScene.camera.rotationX = this.cursorScene.camera.rotationX = this.cursorScene.camera.rotationX = -2.0943951023931953; this.mainScene.camera.rotationX = this.mainScene.camera.rotationX = this.mainScene.camera.rotationX = -2.0943951023931953;
this.cursorScene.cameraController.coords = new Point3D(250,-7800,4670); this.mainScene.cameraController.coords = new Point3D(250,-7800,4670);
loc5 = this.cursorScene.camera; loc5 = this.mainScene.camera;
this.cameraDistance = Math.sqrt(loc5.x * loc5.x + loc5.y * loc5.y + loc5.z * loc5.z); this.cameraDistance = Math.sqrt(loc5.x * loc5.x + loc5.y * loc5.y + loc5.z * loc5.z);
} }
break; break;
@@ -713,9 +712,9 @@ package alternativa.editor
case KeyboardUtils.DOWN: case KeyboardUtils.DOWN:
case KeyboardUtils.LEFT: case KeyboardUtils.LEFT:
case KeyboardUtils.RIGHT: case KeyboardUtils.RIGHT:
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.moveByArrows(param1.keyCode); this.mainScene.moveByArrows(param1.keyCode);
break; break;
} }
loc2 = this.mainScene.selectedProp; loc2 = this.mainScene.selectedProp;
@@ -729,10 +728,10 @@ package alternativa.editor
this.verticalMoving = true; this.verticalMoving = true;
break; break;
case KeyboardUtils.W: case KeyboardUtils.W:
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.object.z += EditorScene.snapByHalf ? EditorScene.VERTICAL_GRID_RESOLUTION_2 : EditorScene.VERTICAL_GRID_RESOLUTION_1; this.mainScene.object.z += EditorScene.snapByHalf ? EditorScene.VERTICAL_GRID_RESOLUTION_2 : EditorScene.VERTICAL_GRID_RESOLUTION_1;
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
break; break;
} }
loc2 = this.mainScene.selectedProp; loc2 = this.mainScene.selectedProp;
@@ -748,10 +747,10 @@ package alternativa.editor
case KeyboardUtils.S: case KeyboardUtils.S:
if(!param1.ctrlKey) if(!param1.ctrlKey)
{ {
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.object.z -= EditorScene.snapByHalf ? EditorScene.VERTICAL_GRID_RESOLUTION_2 : EditorScene.VERTICAL_GRID_RESOLUTION_1; this.mainScene.object.z -= EditorScene.snapByHalf ? EditorScene.VERTICAL_GRID_RESOLUTION_2 : EditorScene.VERTICAL_GRID_RESOLUTION_1;
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
break; break;
} }
loc2 = this.mainScene.selectedProp; loc2 = this.mainScene.selectedProp;
@@ -770,7 +769,7 @@ package alternativa.editor
loc2 = this.mainScene.selectedProp; loc2 = this.mainScene.selectedProp;
if(loc2) if(loc2)
{ {
loc6 = this.cursorScene.object; loc6 = this.mainScene.object;
if(loc6) if(loc6)
{ {
loc6.setPositionXYZ(loc2.x,loc2.y,loc2.z); loc6.setPositionXYZ(loc2.x,loc2.y,loc2.z);
@@ -781,24 +780,24 @@ package alternativa.editor
} }
loc7 = this.mainScene.deleteProps(); loc7 = this.mainScene.deleteProps();
this.eventJournal.addEvent(EventJournal.DELETE,loc7); this.eventJournal.addEvent(EventJournal.DELETE,loc7);
this.cursorScene.visible = true; this.mainScene.objectVisible = true;
} }
break; break;
case KeyboardUtils.Z: case KeyboardUtils.Z:
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.rotateCursorCounterClockwise(); this.mainScene.rotateCursorCounterClockwise();
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
break; break;
} }
this.eventJournal.addEvent(EventJournal.ROTATE,this.mainScene.selectedProps.clone(),false); this.eventJournal.addEvent(EventJournal.ROTATE,this.mainScene.selectedProps.clone(),false);
this.mainScene.rotateCounterClockwise(); this.mainScene.rotateCounterClockwise();
break; break;
case KeyboardUtils.X: case KeyboardUtils.X:
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.rotateCursorClockwise(); this.mainScene.rotateCursorClockwise();
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
break; break;
} }
this.eventJournal.addEvent(EventJournal.ROTATE,this.mainScene.selectedProps.clone(),true); this.eventJournal.addEvent(EventJournal.ROTATE,this.mainScene.selectedProps.clone(),true);
@@ -808,13 +807,13 @@ package alternativa.editor
loc2 = this.mainScene.selectedProp; loc2 = this.mainScene.selectedProp;
if(loc2) if(loc2)
{ {
if(this.cursorScene.object) if(this.mainScene.object)
{ {
this.cursorScene.object.setPositionXYZ(loc2.x,loc2.y,loc2.z); this.mainScene.object.setPositionXYZ(loc2.x,loc2.y,loc2.z);
this.cursorScene.object.snapToGrid(); this.mainScene.object.snapToGrid();
} }
this.mainScene.deselectProps(); this.mainScene.deselectProps();
this.cursorScene.visible = true; this.mainScene.objectVisible = true;
} }
break; break;
case Keyboard.NUMPAD_ADD: case Keyboard.NUMPAD_ADD:
@@ -866,14 +865,14 @@ package alternativa.editor
public function clear() : void public function clear() : void
{ {
this.mainScene.clear(); this.mainScene.clear();
this.cursorScene.clear(); this.mainScene.clear();
} }
public function set snapMode(param1:Boolean) : void public function set snapMode(param1:Boolean) : void
{ {
this._snapMode = param1; this._snapMode = param1;
this.mainScene.snapMode = param1; this.mainScene.snapMode = param1;
this.cursorScene.snapMode = param1; this.mainScene.snapMode = param1;
} }
public function get snapMode() : Boolean public function get snapMode() : Boolean
@@ -883,13 +882,13 @@ package alternativa.editor
public function addProp(param1:Prop) : void public function addProp(param1:Prop) : void
{ {
var loc2:Prop = this.mainScene.addProp(param1,new Point3D().copyFromObject3D(this.cursorScene.object),this.cursorScene.object.rotationZ); var loc2:Prop = this.mainScene.addProp(param1,new Point3D().copyFromObject3D(this.mainScene.object),this.mainScene.object.rotationZ);
var loc3:Set = new Set(); var loc3:Set = new Set();
loc3.add(loc2); loc3.add(loc2);
this.eventJournal.addEvent(EventJournal.ADD,loc3); this.eventJournal.addEvent(EventJournal.ADD,loc3);
setTimeout(this.cursorScene.updateMaterial,200); setTimeout(this.mainScene.updateMaterial,200);
loc2.addEventListener(MouseEvent3D.MOUSE_DOWN,this.onPropMouseDown); loc2.addEventListener(MouseEvent3D.MOUSE_DOWN,this.onPropMouseDown);
if(this._snapMode && !this.cursorScene.freeState && (this.multiplePropMode == MultiPropMode.NONE && this.cursorScene.occupyMap.isConflict(loc2) || this.multiplePropMode == MultiPropMode.GROUP && this.cursorScene.occupyMap.isConflictGroup(loc2))) if(this._snapMode && !this.mainScene.freeState && (this.multiplePropMode == MultiPropMode.NONE && this.mainScene.occupyMap.isConflict(loc2) || this.multiplePropMode == MultiPropMode.GROUP && this.mainScene.occupyMap.isConflictGroup(loc2)))
{ {
Alert.show("This location is occupied. Continue?","",Alert.YES | Alert.NO,this,this.alertConflict,null,Alert.YES); Alert.show("This location is occupied. Continue?","",Alert.YES | Alert.NO,this,this.alertConflict,null,Alert.YES);
} }
@@ -907,9 +906,9 @@ package alternativa.editor
if(loc1) if(loc1)
{ {
this.mainScene.undo(loc1); this.mainScene.undo(loc1);
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
} }
} }
} }
@@ -920,9 +919,9 @@ package alternativa.editor
if(loc1) if(loc1)
{ {
this.mainScene.redo(loc1); this.mainScene.redo(loc1);
if(this.cursorScene.visible) if(this.mainScene.objectVisible)
{ {
this.cursorScene.updateMaterial(); this.mainScene.updateMaterial();
} }
} }
} }

View File

@@ -1,324 +0,0 @@
package alternativa.editor.scene
{
import alternativa.editor.prop.CustomFillMaterial;
import alternativa.editor.prop.MeshProp;
import alternativa.editor.prop.Prop;
import alternativa.editor.prop.Sprite3DProp;
import alternativa.editor.engine3d.controllers.WalkController;
import alternativa.engine3d.core.Camera3D;
import alternativa.engine3d.core.Object3D;
import alternativa.engine3d.core.View;
import alternativa.engine3d.materials.Material;
import alternativa.types.Matrix4;
import alternativa.types.Point3D;
import alternativa.types.Set;
import alternativa.types.Texture;
import alternativa.utils.MathUtils;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.geom.Point;
import alternativa.engine3d.core.Object3DContainer;
import flash.geom.Vector3D;
import alternativa.engine3d.materials.TextureMaterial;
import flash.display.Sprite;
public class CursorScene extends EditorScene
{
private static var redClass:Class = CursorScene_redClass;
private static const redBmp:BitmapData = new redClass().bitmapData;
private static var greenClass:Class = CursorScene_greenClass;
private static const greenBmp:BitmapData = new greenClass().bitmapData;
protected var _object:Prop;
private var redMaterial:Material;
private var greenMaterial:Material;
private var material:Material;
private var _freeState:Boolean = true;
public var cameraController:WalkController;
public var containerController:WalkController;
public var container:Object3DContainer;
private var eventSourceObject:DisplayObject;
protected var _snapMode:Boolean = true;
private var axisIndicatorOverlay:Shape;
private var axisIndicatorSize:Number = 30;
private var _visible:Boolean = false;
public function CursorScene(param1:DisplayObject, container:Sprite)
{
super();
this.eventSourceObject = param1;
this.initControllers();
container.addChild(this.axisIndicatorOverlay = new Shape());
}
private function initControllers() : void
{
this.cameraController = new WalkController(this.eventSourceObject);
this.cameraController.object = camera;
this.cameraController.speedMultiplier = 4;
this.cameraController.speedThreshold = 1;
this.cameraController.mouseEnabled = false;
this.cameraController.coords = new Point3D(250,-7800,4670);
this.container = new Object3DContainer();
root.addChild(this.container);
this.containerController = new WalkController(this.eventSourceObject);
this.containerController.object = this.container;
this.containerController.mouseEnabled = false;
this.container.addChild(camera);
}
public function set object(param1:Prop) : void
{
var loc2:Vector3D = null;
if(this._object)
{
loc2 = new Vector3D(this._object.x,this._object.y,this._object.z);
if(this._visible)
{
root.removeChild(this._object);
}
}
this._object = param1;
this.material = this._object.material.clone();
//this.material.alpha = 0.5;
this._object.alpha = 0.5;
if(loc2)
{
this._object.setPositionFromVector3(loc2);
}
if(this._visible)
{
root.addChild(this._object);
}
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this.snapObject();
}
this.updateMaterial();
}
public function get object() : Prop
{
return this._object;
}
public function set snapMode(param1:Boolean) : void
{
if(this._snapMode != param1 && Boolean(this._object))
{
this._snapMode = param1;
if(param1)
{
this.snapObject();
}
else
{
this._object.setMaterial(this.material);
}
}
}
private function snapObject() : void
{
this.createMaterials();
this._object.snapToGrid();
}
private function createMaterials() : void
{
var loc1:BitmapData = this._object.bitmapData.clone();
var loc2:BitmapData = loc1.clone();
var loc3:Matrix = new Matrix();
loc3.a = loc1.width / redBmp.width;
loc3.d = loc3.a;
loc1.draw(redBmp,loc3,null,BlendMode.HARDLIGHT);
loc2.draw(greenBmp,loc3,null,BlendMode.HARDLIGHT);
if(this._object is Sprite3DProp)
{
this.greenMaterial = new TextureMaterial(loc2);
this.redMaterial = new TextureMaterial(loc1);
}
else
{
this.greenMaterial = new CustomFillMaterial(new Point3D(-10000000000,-7000000000,4000000000),65280);
this.redMaterial = new CustomFillMaterial(new Point3D(-10000000000,-7000000000,4000000000),16711680);
}
//this.greenMaterial.alpha = 0.8;
//this.redMaterial.alpha = 0.8;
this._object.alpha = 0.8;
}
public function moveCursorByMouse() : void
{
var loc1:Vector3D = null;
if(this._object)
{
loc1 = camera.projectGlobal(new Vector3D(view.mouseX,view.mouseY,this._object.z));
this._object.x = loc1.x;
this._object.y = loc1.y;
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this._object.snapToGrid();
}
this.updateMaterial();
}
}
public function get freeState() : Boolean
{
return this._freeState;
}
override protected function initScene() : void
{
root = new Object3DContainer();
camera = new Camera3D();
camera.rotationX = -MathUtils.DEG90 - MathUtils.DEG30;
view = new View(100,100);
camera.view = view;
//view.interactive = false;
view.mouseEnabled = false;
view.mouseChildren = false;
view.graphics.beginFill(16777215);
view.graphics.drawRect(0,0,1,1);
view.graphics.endFill();
}
public function updateMaterial() : void
{
if(this._object)
{
if(this._snapMode)
{
if(occupyMap.isConflict(this._object))
{
this._freeState = false;
this._object.setMaterial(this.redMaterial);
}
else
{
this._freeState = true;
this._object.setMaterial(this.greenMaterial);
}
}
else
{
this._object.setMaterial(this.material);
}
}
}
public function clear() : void
{
if(this._object)
{
if(root.getChildByName(this._object.name))
{
root.removeChild(this._object);
}
this._object = null;
this._visible = false;
}
}
public function drawAxis(param1:Matrix4) : void
{
var loc2:Graphics = this.axisIndicatorOverlay.graphics;
var loc3:Number = this.axisIndicatorSize;
loc2.clear();
loc2.lineStyle(2,16711680);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.a * this.axisIndicatorSize + loc3,param1.b * this.axisIndicatorSize + 0);
loc2.lineStyle(2,65280);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.e * this.axisIndicatorSize + loc3,param1.f * this.axisIndicatorSize + 0);
loc2.lineStyle(2,255);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.i * this.axisIndicatorSize + loc3,param1.j * this.axisIndicatorSize + 0);
}
public function set visible(param1:Boolean) : void
{
if(param1 != this._visible)
{
this._visible = param1;
if(this._object)
{
if(this._visible)
{
root.addChild(this._object);
this.updateMaterial();
}
else
{
root.removeChild(this._object);
}
}
}
}
public function get visible() : Boolean
{
return this._visible;
}
public function moveByArrows(param1:uint) : void
{
move(this._object,param1);
this.updateMaterial();
}
override public function viewResize(param1:Number, param2:Number) : void
{
super.viewResize(param1,param2);
this.axisIndicatorOverlay.y = view.height - this.axisIndicatorSize;
}
public function rotateCursorCounterClockwise() : void
{
rotatePropsCounterClockwise(this.getCursorObjectSet());
this.snapCursorToGrid();
}
public function rotateCursorClockwise() : void
{
rotatePropsClockwise(this.getCursorObjectSet());
this.snapCursorToGrid();
}
private function getCursorObjectSet() : Set
{
var loc1:Set = new Set();
loc1.add(this._object);
return loc1;
}
private function snapCursorToGrid() : void
{
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this._object.snapToGrid();
}
}
}
}

View File

@@ -43,6 +43,16 @@ package alternativa.editor.scene
import alternativa.engine3d.core.EllipsoidCollider; import alternativa.engine3d.core.EllipsoidCollider;
import flash.geom.Vector3D; import flash.geom.Vector3D;
import alternativa.engine3d.core.Object3DContainer; import alternativa.engine3d.core.Object3DContainer;
import flash.display.BitmapData;
import alternativa.engine3d.materials.Material;
import alternativa.editor.engine3d.controllers.WalkController;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.display.BlendMode;
import alternativa.engine3d.materials.TextureMaterial;
import alternativa.editor.prop.CustomFillMaterial;
import alternativa.types.Matrix4;
public class MainScene extends EditorScene public class MainScene extends EditorScene
{ {
@@ -55,8 +65,6 @@ package alternativa.editor.scene
public var propMouseDown:Boolean = false; public var propMouseDown:Boolean = false;
public var snapMode:Boolean = true;
private var _changed:Boolean = false; private var _changed:Boolean = false;
private var hiddenProps:Array; private var hiddenProps:Array;
@@ -84,8 +92,43 @@ package alternativa.editor.scene
private var domSpawnPoint:SpawnPoint; private var domSpawnPoint:SpawnPoint;
private var controlPointNameField:ControlPointNameField; private var controlPointNameField:ControlPointNameField;
private static var redClass:Class = CursorScene_redClass;
public function MainScene() private static const redBmp:BitmapData = new redClass().bitmapData;
private static var greenClass:Class = CursorScene_greenClass;
private static const greenBmp:BitmapData = new greenClass().bitmapData;
protected var _object:Prop;
private var redMaterial:Material;
private var greenMaterial:Material;
private var material:Material;
private var _freeState:Boolean = true;
public var cameraController:WalkController;
public var containerController:WalkController;
public var container:Object3DContainer;
private var eventSourceObject:DisplayObject;
protected var _snapMode:Boolean = true;
private var axisIndicatorOverlay:Shape;
private var axisIndicatorSize:Number = 30;
private var _visible:Boolean = false;
public function MainScene(eventSource:DisplayObject, container:Sprite)
{ {
this.hiddenProps = []; this.hiddenProps = [];
this.bonusTypesPanel = new BonusRegionPropertiesPanel(); this.bonusTypesPanel = new BonusRegionPropertiesPanel();
@@ -95,12 +138,16 @@ package alternativa.editor.scene
this.layers = new Layers(); this.layers = new Layers();
this.dominationPoints = new Dictionary(); this.dominationPoints = new Dictionary();
super(); super();
this.eventSourceObject = eventSource;
this.initControllers();
container.addChild(this.axisIndicatorOverlay = new Shape());
occupyMap = new OccupyMap(); occupyMap = new OccupyMap();
this.selectedProps = new Set(); this.selectedProps = new Set();
this.selectablePropTypes = AlternativaEditor.DEFAULT_SELECTABLE_TYPES; this.selectablePropTypes = AlternativaEditor.DEFAULT_SELECTABLE_TYPES;
var loc2:Number = 15 * hBase2; var loc2:Number = 15 * hBase2;
this.grid = new Plane(loc2,loc2,15,15); this.grid = new Plane(loc2,loc2,15,15);
this.grid.setMaterialToAllFaces(new WireMaterial(1,loc2,loc2,15,9474192)); this.grid.setMaterialToAllFaces(new WireMaterial(10,loc2,loc2,15,9474192));
root.addChild(this.grid); root.addChild(this.grid);
this.grid.x = hBase; this.grid.x = hBase;
this.grid.y = hBase; this.grid.y = hBase;
@@ -116,6 +163,227 @@ package alternativa.editor.scene
GlobalEventDispatcher.addListener(DominationSpawnLinkStartEvent.DOMINATION_SPAWN_LINK_START,this.onDominationLinkStart); GlobalEventDispatcher.addListener(DominationSpawnLinkStartEvent.DOMINATION_SPAWN_LINK_START,this.onDominationLinkStart);
GlobalEventDispatcher.addListener(DominationSpawnLinkEndEvent.DOMINATION_SPAWN_LINK_END,this.onDominationLinkEnd); GlobalEventDispatcher.addListener(DominationSpawnLinkEndEvent.DOMINATION_SPAWN_LINK_END,this.onDominationLinkEnd);
} }
private function initControllers() : void
{
this.cameraController = new WalkController(this.eventSourceObject);
this.cameraController.object = camera;
this.cameraController.speedMultiplier = 4;
this.cameraController.speedThreshold = 1;
this.cameraController.mouseEnabled = false;
this.cameraController.coords = new Point3D(250,-7800,4670);
this.container = new Object3DContainer();
root.addChild(this.container);
this.containerController = new WalkController(this.eventSourceObject);
this.containerController.object = this.container;
this.containerController.mouseEnabled = false;
this.container.addChild(camera);
}
public function set object(param1:Prop) : void
{
var loc2:Vector3D = null;
if(this._object)
{
loc2 = new Vector3D(this._object.x,this._object.y,this._object.z);
if(this._visible)
{
root.removeChild(this._object);
}
}
this._object = param1;
this.material = this._object.material.clone();
//this.material.alpha = 0.5;
this._object.alpha = 0.5;
if(loc2)
{
this._object.setPositionFromVector3(loc2);
}
if(this._visible)
{
root.addChild(this._object);
}
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this.snapObject();
}
this.updateMaterial();
}
public function get object() : Prop
{
return this._object;
}
public function set snapMode(param1:Boolean) : void
{
if(this._snapMode != param1 && Boolean(this._object))
{
this._snapMode = param1;
if(param1)
{
this.snapObject();
}
else
{
this._object.setMaterial(this.material);
}
}
}
public function get snapMode() : Boolean
{
return this._snapMode;
}
public function updateMaterial() : void
{
if(this._object)
{
if(this._snapMode)
{
if(occupyMap.isConflict(this._object))
{
this._freeState = false;
this._object.setMaterial(this.redMaterial);
}
else
{
this._freeState = true;
this._object.setMaterial(this.greenMaterial);
}
}
else
{
this._object.setMaterial(this.material);
}
}
}
private function snapObject() : void
{
this.createMaterials();
this._object.snapToGrid();
}
private function createMaterials() : void
{
var loc1:BitmapData = this._object.bitmapData.clone();
var loc2:BitmapData = loc1.clone();
var loc3:Matrix = new Matrix();
loc3.a = loc1.width / redBmp.width;
loc3.d = loc3.a;
loc1.draw(redBmp,loc3,null,BlendMode.HARDLIGHT);
loc2.draw(greenBmp,loc3,null,BlendMode.HARDLIGHT);
if(this._object is Sprite3DProp)
{
this.greenMaterial = new TextureMaterial(loc2);
this.redMaterial = new TextureMaterial(loc1);
}
else
{
this.greenMaterial = new CustomFillMaterial(new Point3D(-10000000000,-7000000000,4000000000),65280);
this.redMaterial = new CustomFillMaterial(new Point3D(-10000000000,-7000000000,4000000000),16711680);
}
//this.greenMaterial.alpha = 0.8;
//this.redMaterial.alpha = 0.8;
this._object.alpha = 0.8;
}
public function moveCursorByMouse() : void
{
var loc1:Vector3D = null;
if(this._object)
{
loc1 = camera.projectGlobal(new Vector3D(view.mouseX,view.mouseY,this._object.z));
this._object.x = loc1.x;
this._object.y = loc1.y;
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this._object.snapToGrid();
}
this.updateMaterial();
}
}
public function get freeState() : Boolean
{
return this._freeState;
}
public function drawAxis(param1:Matrix4) : void
{
var loc2:Graphics = this.axisIndicatorOverlay.graphics;
var loc3:Number = this.axisIndicatorSize;
loc2.clear();
loc2.lineStyle(2,16711680);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.a * this.axisIndicatorSize + loc3,param1.b * this.axisIndicatorSize + 0);
loc2.lineStyle(2,65280);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.e * this.axisIndicatorSize + loc3,param1.f * this.axisIndicatorSize + 0);
loc2.lineStyle(2,255);
loc2.moveTo(loc3,0);
loc2.lineTo(param1.i * this.axisIndicatorSize + loc3,param1.j * this.axisIndicatorSize + 0);
}
public function set objectVisible(param1:Boolean) : void
{
if(param1 != this._visible)
{
this._visible = param1;
if(this._object)
{
if(this._visible)
{
root.addChild(this._object);
this.updateMaterial();
}
else
{
root.removeChild(this._object);
}
}
}
}
public function get objectVisible() : Boolean
{
return this._visible;
}
override public function viewResize(param1:Number, param2:Number) : void
{
super.viewResize(param1,param2);
this.axisIndicatorOverlay.y = view.height - this.axisIndicatorSize;
}
public function rotateCursorCounterClockwise() : void
{
rotatePropsCounterClockwise(this.getCursorObjectSet());
this.snapCursorToGrid();
}
public function rotateCursorClockwise() : void
{
rotatePropsClockwise(this.getCursorObjectSet());
this.snapCursorToGrid();
}
private function getCursorObjectSet() : Set
{
var loc1:Set = new Set();
loc1.add(this._object);
return loc1;
}
private function snapCursorToGrid() : void
{
if(this._snapMode || this._object is MeshProp && !(this._object is Sprite3DProp))
{
this._object.snapToGrid();
}
}
public static function getProjectedPoint(param1:Vector3D) : Vector3D public static function getProjectedPoint(param1:Vector3D) : Vector3D
{ {
@@ -192,7 +460,7 @@ package alternativa.editor.scene
loc4.x -= param2.x; loc4.x -= param2.x;
loc4.y -= param2.y; loc4.y -= param2.y;
loc4.z -= param2.z; loc4.z -= param2.z;
if(this.snapMode) if(this._snapMode)
{ {
loc4.snapToGrid(); loc4.snapToGrid();
occupyMap.occupy(loc4); occupyMap.occupy(loc4);
@@ -483,6 +751,9 @@ package alternativa.editor.scene
occupyMap.occupy(loc3); occupyMap.occupy(loc3);
} }
} }
move(this._object,param1);
this.updateMaterial();
} }
public function verticalMove(param1:Boolean) : void public function verticalMove(param1:Boolean) : void
@@ -823,6 +1094,16 @@ package alternativa.editor.scene
public function clear() : void public function clear() : void
{ {
if(this._object)
{
if(root.getChildByName(this._object.name))
{
root.removeChild(this._object);
}
this._object = null;
this._visible = false;
}
var loc1:Object3D; var loc1:Object3D;
var loc2:Prop = null; var loc2:Prop = null;
for each(loc1 in root.children) for each(loc1 in root.children)