Section 1
//FPS (com.alternativagame.admin.FPS)
package com.alternativagame.admin {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import flash.text.*;
import flash.system.*;
public final class FPS extends Sprite {
private var currentY:int;
private var diagramTimer:int;
private var tfTimer:int;
private var downloadedBytes:uint;// = 0
private var socketOutBytes:uint;// = 0
private var socketOutLast:uint;// = 0
private var socketInBytes:uint;// = 0
private var mem:TextField;
private var skn:TextField;
private var diagram:BitmapData;
private var socketOut:TextField;
private var skins:int;// = -1
private var fps:TextField;
private var socketInLast:uint;// = 0
private var tfDelay:int;// = 0
private var socketIn:TextField;
private var dwl:TextField;
private var skinsChanged:int;// = 0
private static const maxMemory:uint = 41943040;
private static const diagramWidth:uint = 60;
private static const tfDelayMax:int = 10;
private static const maxSocket:uint = 4200;
private static const diagramHeight:uint = 40;
private static var instance:FPS;
public function FPS(_arg1:DisplayObjectContainer){
var _local2:Bitmap;
fps = new TextField();
mem = new TextField();
skn = new TextField();
dwl = new TextField();
socketIn = new TextField();
socketOut = new TextField();
super();
if (instance == null){
mouseEnabled = false;
mouseChildren = false;
_arg1.addChild(this);
fps.defaultTextFormat = new TextFormat("Tahoma", 10, 0xCCCCCC);
fps.autoSize = TextFieldAutoSize.LEFT;
fps.text = ("FPS: " + Number(stage.frameRate).toFixed(2));
fps.selectable = false;
fps.x = (-(diagramWidth) - 2);
addChild(fps);
mem.defaultTextFormat = new TextFormat("Tahoma", 10, 0xCCCC00);
mem.autoSize = TextFieldAutoSize.LEFT;
mem.text = ("MEM: " + bytesToString(System.totalMemory));
mem.selectable = false;
mem.x = (-(diagramWidth) - 2);
mem.y = 10;
addChild(mem);
currentY = 20;
skn.defaultTextFormat = new TextFormat("Tahoma", 10, 0xFF6600);
skn.autoSize = TextFieldAutoSize.LEFT;
skn.text = ("MEM: " + bytesToString(System.totalMemory));
skn.selectable = false;
skn.x = (-(diagramWidth) - 2);
dwl.defaultTextFormat = new TextFormat("Tahoma", 10, 0xCC00CC);
dwl.autoSize = TextFieldAutoSize.LEFT;
dwl.selectable = false;
dwl.x = (-(diagramWidth) - 2);
socketIn.defaultTextFormat = new TextFormat("Tahoma", 10, 0xFF00);
socketIn.autoSize = TextFieldAutoSize.LEFT;
socketIn.selectable = false;
socketIn.x = (-(diagramWidth) - 2);
socketOut.defaultTextFormat = new TextFormat("Tahoma", 10, 26367);
socketOut.autoSize = TextFieldAutoSize.LEFT;
socketOut.selectable = false;
socketOut.x = (-(diagramWidth) - 2);
diagram = new BitmapData(diagramWidth, diagramHeight, true, 553648127);
_local2 = new Bitmap(diagram);
_local2.y = (currentY + 4);
_local2.x = -(diagramWidth);
addChildAt(_local2, 0);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
diagramTimer = getTimer();
tfTimer = getTimer();
} else {
throw (new Error("FPS is a Singleton. Use FPS.init to create FPS instance"));
};
}
private function bytesToString(_arg1:uint):String{
var _local2:String;
if (_arg1 < 0x0400){
_local2 = (String(_arg1) + "b");
} else {
if (_arg1 < 0x2800){
_local2 = (Number((_arg1 / 0x0400)).toFixed(2) + "kb");
} else {
if (_arg1 < 102400){
_local2 = (Number((_arg1 / 0x0400)).toFixed(1) + "kb");
} else {
if (_arg1 < 0x100000){
_local2 = (Math.round((_arg1 / 0x0400)) + "kb");
} else {
if (_arg1 < 0xA00000){
_local2 = (Number((_arg1 / 0x100000)).toFixed(2) + "mb");
} else {
if (_arg1 < 104857600){
_local2 = (Number((_arg1 / 0x100000)).toFixed(1) + "mb");
} else {
_local2 = (Math.round((_arg1 / 0x100000)) + "mb");
};
};
};
};
};
};
return (_local2);
}
private function onEnterFrame(_arg1:Event):void{
tfDelay++;
if (tfDelay >= tfDelayMax){
tfDelay = 0;
fps.text = ("FPS: " + Number(((1000 * tfDelayMax) / (getTimer() - tfTimer))).toFixed(2));
tfTimer = getTimer();
};
var _local2:Number = (1000 / (getTimer() - diagramTimer));
var _local3:Number = ((_local2)>stage.frameRate) ? 1 : (_local2 / stage.frameRate);
diagramTimer = getTimer();
diagram.scroll(1, 0);
diagram.fillRect(new Rectangle(0, 0, 1, diagram.height), 553648127);
diagram.setPixel32(0, (diagramHeight * (1 - _local3)), 4291611852);
mem.text = ("MEM: " + bytesToString(System.totalMemory));
var _local4:Number = ((skins)==0) ? 0 : (skinsChanged / skins);
diagram.setPixel32(0, (diagramHeight * (1 - _local4)), 4294927872);
var _local5:Number = (System.totalMemory / maxMemory);
diagram.setPixel32(0, (diagramHeight * (1 - _local5)), 4291611648);
var _local6:Number = ((socketInBytes - socketInLast) / maxSocket);
socketInLast = socketInBytes;
diagram.setPixel32(0, (diagramHeight * (1 - _local6)), 4278255360);
var _local7:Number = ((socketOutBytes - socketOutLast) / maxSocket);
socketOutLast = socketOutBytes;
diagram.setPixel32(0, (diagramHeight * (1 - _local7)), 4278216447);
}
private function onResize(_arg1:Event=null):void{
var _local2:Point = parent.globalToLocal(new Point((stage.stageWidth - 2), -3));
x = _local2.x;
y = _local2.y;
}
public static function addDownloadBytes(_arg1:uint):void{
if (instance.downloadedBytes == 0){
instance.dwl.y = instance.currentY;
instance.currentY = (instance.currentY + 10);
instance.addChild(instance.dwl);
instance.getChildAt(0).y = (instance.currentY + 4);
};
instance.downloadedBytes = (instance.downloadedBytes + _arg1);
instance.dwl.text = ("DWL: " + instance.bytesToString(instance.downloadedBytes));
}
public static function init(_arg1:DisplayObjectContainer):void{
instance = new FPS(_arg1);
}
public static function addSocketInBytes(_arg1:uint):void{
if (instance.socketInBytes == 0){
instance.socketIn.y = instance.currentY;
instance.currentY = (instance.currentY + 10);
instance.addChild(instance.socketIn);
instance.getChildAt(0).y = (instance.currentY + 4);
};
instance.socketInBytes = (instance.socketInBytes + _arg1);
instance.socketIn.text = ("IN: " + instance.bytesToString(instance.socketInBytes));
}
public static function addSocketOutBytes(_arg1:uint):void{
if (instance.socketOutBytes == 0){
instance.socketOut.y = instance.currentY;
instance.currentY = (instance.currentY + 10);
instance.addChild(instance.socketOut);
instance.getChildAt(0).y = (instance.currentY + 4);
};
instance.socketOutBytes = (instance.socketOutBytes + _arg1);
instance.socketOut.text = ("OUT: " + instance.bytesToString(instance.socketOutBytes));
}
public static function addSkins(_arg1:uint, _arg2:uint):void{
if (instance.skins < 0){
instance.skn.y = instance.currentY;
instance.currentY = (instance.currentY + 10);
instance.addChild(instance.skn);
instance.getChildAt(0).y = (instance.currentY + 4);
};
instance.skins = _arg1;
instance.skinsChanged = _arg2;
instance.skn.text = ("SKN: " + ((_arg2)>0) ? ((_arg1.toString() + "-") + _arg2.toString()) : _arg1.toString());
}
}
}//package com.alternativagame.admin
Section 2
//Box (com.alternativagame.engine3d.primitive.Box)
package com.alternativagame.engine3d.primitive {
import com.alternativagame.engine3d.*;
public class Box extends Mesh {
public static const BACK:String = "back";
public static const FRONT:String = "front";
public static const BOTTOM:String = "bottom";
public static const TOP:String = "top";
public static const LEFT:String = "left";
public static const RIGHT:String = "right";
public function Box(_arg1:Number=100, _arg2:Number=100, _arg3:Number=100, _arg4:IRenderer=null, _arg5:uint=1, _arg6:uint=1, _arg7:uint=1, _arg8:Boolean=false){
var _local16:uint;
var _local17:uint;
var _local18:uint;
var _local22:Face;
var _local23:ISurfaceRenderer;
var _local24:ISurfaceRenderer;
var _local25:ISurfaceRenderer;
var _local26:ISurfaceRenderer;
var _local27:ISurfaceRenderer;
var _local28:ISurfaceRenderer;
super();
if (_arg4 != null){
if ((_arg4 is ISurfaceRenderer)){
_local23 = ISurfaceRenderer(_arg4);
_local24 = ISurfaceRenderer(_arg4.clone());
_local25 = ISurfaceRenderer(_arg4.clone());
_local26 = ISurfaceRenderer(_arg4.clone());
_local27 = ISurfaceRenderer(_arg4.clone());
_local28 = ISurfaceRenderer(_arg4.clone());
_local23.name = FRONT;
_local24.name = BACK;
_local25.name = LEFT;
_local26.name = RIGHT;
_local27.name = TOP;
_local28.name = BOTTOM;
addRenderer(_local23);
addRenderer(_local24);
addRenderer(_local25);
addRenderer(_local26);
addRenderer(_local27);
addRenderer(_local28);
} else {
addRenderer(_arg4);
};
};
var _local9:Array = new Array();
var _local10:Number = (_arg1 / 2);
var _local11:Number = (_arg2 / 2);
var _local12:Number = (_arg3 / 2);
var _local13:Number = (_arg1 / _arg5);
var _local14:Number = (_arg2 / _arg6);
var _local15:Number = (_arg3 / _arg7);
_local16 = 0;
while (_local16 <= _arg7) {
_local9[_local16] = new Array();
_local17 = 0;
while (_local17 <= _arg6) {
_local9[_local16][_local17] = new Array();
_local18 = 0;
while (_local18 <= _arg5) {
if ((((((((((((_local16 == 0)) || ((_local16 == _arg7)))) || ((_local17 == 0)))) || ((_local17 == _arg6)))) || ((_local18 == 0)))) || ((_local18 == _arg5)))){
_local9[_local16][_local17][_local18] = new Vertex(((_local18 * _local13) - _local10), ((_local16 * _local15) - _local12), ((_local17 * _local14) - _local11));
addVertex(_local9[_local16][_local17][_local18]);
};
_local18++;
};
_local17++;
};
_local16++;
};
var _local19:Number = (1 / _arg5);
var _local20:Number = (1 / _arg6);
var _local21:Number = (1 / _arg7);
_local16 = 0;
while (_local16 < _arg7) {
_local18 = 0;
while (_local18 < _arg5) {
if (_arg8){
_local22 = new Face(_local9[_local16][_arg6][_local18], _local9[(_local16 + 1)][_arg6][_local18], _local9[(_local16 + 1)][_arg6][(_local18 + 1)], _local9[_local16][_arg6][(_local18 + 1)]);
} else {
_local22 = new Face(_local9[_local16][_arg6][_local18], _local9[_local16][_arg6][(_local18 + 1)], _local9[(_local16 + 1)][_arg6][(_local18 + 1)], _local9[(_local16 + 1)][_arg6][_local18]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local27.addFace(_local22);
};
_local18++;
};
_local16++;
};
_local16 = 0;
while (_local16 < _arg7) {
_local18 = 0;
while (_local18 < _arg5) {
if (_arg8){
_local22 = new Face(_local9[_local16][0][_local18], _local9[_local16][0][(_local18 + 1)], _local9[(_local16 + 1)][0][(_local18 + 1)], _local9[(_local16 + 1)][0][_local18]);
} else {
_local22 = new Face(_local9[_local16][0][_local18], _local9[(_local16 + 1)][0][_local18], _local9[(_local16 + 1)][0][(_local18 + 1)], _local9[_local16][0][(_local18 + 1)]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local28.addFace(_local22);
};
_local18++;
};
_local16++;
};
_local16 = 0;
while (_local16 < _arg7) {
_local17 = 0;
while (_local17 < _arg6) {
if (_arg8){
_local22 = new Face(_local9[_local16][_local17][0], _local9[(_local16 + 1)][_local17][0], _local9[(_local16 + 1)][(_local17 + 1)][0], _local9[_local16][(_local17 + 1)][0]);
} else {
_local22 = new Face(_local9[_local16][_local17][0], _local9[_local16][(_local17 + 1)][0], _local9[(_local16 + 1)][(_local17 + 1)][0], _local9[(_local16 + 1)][_local17][0]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local25.addFace(_local22);
};
_local17++;
};
_local16++;
};
_local16 = 0;
while (_local16 < _arg7) {
_local17 = 0;
while (_local17 < _arg6) {
if (_arg8){
_local22 = new Face(_local9[_local16][_local17][_arg5], _local9[_local16][(_local17 + 1)][_arg5], _local9[(_local16 + 1)][(_local17 + 1)][_arg5], _local9[(_local16 + 1)][_local17][_arg5]);
} else {
_local22 = new Face(_local9[_local16][_local17][_arg5], _local9[(_local16 + 1)][_local17][_arg5], _local9[(_local16 + 1)][(_local17 + 1)][_arg5], _local9[_local16][(_local17 + 1)][_arg5]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local26.addFace(_local22);
};
_local17++;
};
_local16++;
};
_local17 = 0;
while (_local17 < _arg6) {
_local18 = 0;
while (_local18 < _arg5) {
if (_arg8){
_local22 = new Face(_local9[0][_local17][_local18], _local9[0][(_local17 + 1)][_local18], _local9[0][(_local17 + 1)][(_local18 + 1)], _local9[0][_local17][(_local18 + 1)]);
} else {
_local22 = new Face(_local9[0][_local17][_local18], _local9[0][_local17][(_local18 + 1)], _local9[0][(_local17 + 1)][(_local18 + 1)], _local9[0][(_local17 + 1)][_local18]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local23.addFace(_local22);
};
_local18++;
};
_local17++;
};
_local17 = 0;
while (_local17 < _arg6) {
_local18 = 0;
while (_local18 < _arg5) {
if (_arg8){
_local22 = new Face(_local9[_arg7][_local17][_local18], _local9[_arg7][_local17][(_local18 + 1)], _local9[_arg7][(_local17 + 1)][(_local18 + 1)], _local9[_arg7][(_local17 + 1)][_local18]);
} else {
_local22 = new Face(_local9[_arg7][_local17][_local18], _local9[_arg7][(_local17 + 1)][_local18], _local9[_arg7][(_local17 + 1)][(_local18 + 1)], _local9[_arg7][_local17][(_local18 + 1)]);
};
addFace(_local22);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local24.addFace(_local22);
};
_local18++;
};
_local17++;
};
}
}
}//package com.alternativagame.engine3d.primitive
Section 3
//Cone (com.alternativagame.engine3d.primitive.Cone)
package com.alternativagame.engine3d.primitive {
import com.alternativagame.engine3d.*;
import com.alternativagame.utility.*;
public class Cone extends Mesh {
public static const TOP:String = "top";
public static const SIDE:String = "side";
public static const BOTTOM:String = "bottom";
public function Cone(_arg1:Number=100, _arg2:Number=100, _arg3:Number=0, _arg4:IRenderer=null, _arg5:int=1, _arg6:int=12, _arg7:Boolean=false){
var _local8:Number;
var _local9:Number;
var _local10:Number;
var _local11:Number;
var _local12:Face;
var _local13:Number;
var _local14:Number;
var _local15:uint;
var _local16:uint;
var _local17:Array;
var _local18:Array;
var _local19:ISurfaceRenderer;
var _local20:ISurfaceRenderer;
var _local21:ISurfaceRenderer;
super();
if ((((_arg2 > 0)) || ((_arg3 > 0)))){
if (_arg4 != null){
if ((_arg4 is ISurfaceRenderer)){
_local19 = ISurfaceRenderer(_arg4);
_local19.name = SIDE;
addRenderer(_local19);
if (_arg3 > 0){
_local20 = ISurfaceRenderer(_arg4.clone());
_local20.name = TOP;
addRenderer(_local20);
};
if (_arg2 > 0){
_local21 = ISurfaceRenderer(_arg4.clone());
_local21.name = BOTTOM;
addRenderer(_local21);
};
} else {
addRenderer(_arg4);
};
};
_local8 = (_arg1 / 2);
_local9 = (_arg1 / _arg5);
_local10 = ((_arg3 - _arg2) / _arg5);
_local11 = (MathUtility.degree360 / _arg6);
_local13 = -(_local8);
_local14 = _arg2;
if (_arg2 > 0){
_local17 = new Array();
_local16 = 0;
while (_local16 < _arg6) {
_local17[_local16] = new Vertex((Math.sin((_local16 * _local11)) * _local14), (Math.cos((_local16 * _local11)) * _local14), _local13);
addVertex(_local17[_local16]);
_local16++;
};
if (_arg7){
_local17.reverse();
};
_local12 = new Face(_local17);
addFace(_local12);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local21.addFace(_local12);
};
} else {
_local17 = new Array();
_local17[0] = new Vertex(0, 0, _local13);
addVertex(_local17[0]);
};
_local15 = 0;
while (_local15 < _arg5) {
_local13 = (_local13 + _local9);
_local14 = (_local14 + _local10);
if ((((_local15 == (_arg5 - 1))) && ((_arg3 <= 0)))){
_local18 = new Array();
_local18[0] = new Vertex(0, 0, _local13);
addVertex(_local18[0]);
_local16 = 0;
while (_local16 < _arg6) {
_local12 = new Face(_local17[_local16], _local18[0], _local17[((_local16)==(_arg6 - 1)) ? 0 : (_local16 + 1)]);
addFace(_local12);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local19.addFace(_local12);
};
_local16++;
};
} else {
_local18 = new Array();
_local16 = 0;
while (_local16 < _arg6) {
_local18[_local16] = new Vertex((Math.sin((_local16 * _local11)) * _local14), (Math.cos((_local16 * _local11)) * _local14), _local13);
addVertex(_local18[_local16]);
_local16++;
};
if (_arg7){
_local18.reverse();
};
if ((((_local15 == 0)) && ((_arg2 <= 0)))){
_local16 = 0;
while (_local16 < _arg6) {
_local12 = new Face(_local18[_local16], _local18[((_local16)==(_arg6 - 1)) ? 0 : (_local16 + 1)], _local17[0]);
addFace(_local12);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local19.addFace(_local12);
};
_local16++;
};
} else {
_local16 = 0;
while (_local16 < _arg6) {
_local12 = new Face(_local17[_local16], _local18[_local16], _local18[((_local16)==(_arg6 - 1)) ? 0 : (_local16 + 1)], _local17[((_local16)==(_arg6 - 1)) ? 0 : (_local16 + 1)]);
addFace(_local12);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local19.addFace(_local12);
};
_local16++;
};
};
_local17 = _local18;
};
_local15++;
};
if (_arg3 > 0){
_local17.reverse();
_local12 = new Face(_local17);
addFace(_local12);
if (((!((_arg4 == null))) && ((_arg4 is ISurfaceRenderer)))){
_local20.addFace(_local12);
};
};
};
}
}
}//package com.alternativagame.engine3d.primitive
Section 4
//GeoSphere (com.alternativagame.engine3d.primitive.GeoSphere)
package com.alternativagame.engine3d.primitive {
import com.alternativagame.engine3d.*;
public class GeoSphere extends Mesh {
public function GeoSphere(_arg1:Number=100, _arg2:IRenderer=null, _arg3:int=2, _arg4:Boolean=false){
var _local6:Number;
var _local7:Number;
var _local8:Number;
var _local9:Number;
var _local10:Number;
var _local11:uint;
var _local12:uint;
var _local19:uint;
var _local20:uint;
var _local21:Number;
var _local22:Number;
var _local23:Number;
var _local24:Number;
super();
if (_arg2 != null){
addRenderer(_arg2);
};
var _local5:uint = 20;
var _local13:uint = ((_local5 * _arg3) * _arg3);
var _local14:Number = ((_local13 / 2) + 2);
var _local15:Array = new Array();
var _local16:Array = new Array();
_local15[0] = new Vertex(0, 0, _arg1);
_local7 = (0.4472136 * _arg1);
_local6 = (2 * _local7);
_local11 = 0;
while (_local11 < 5) {
_local8 = (((2 * Math.PI) * _local11) / 5);
_local9 = Math.sin(_local8);
_local10 = Math.cos(_local8);
_local15.push(new Vertex((_local6 * _local10), (_local6 * _local9), _local7));
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
_local8 = ((Math.PI * ((2 * _local11) + 1)) / 5);
_local9 = Math.sin(_local8);
_local10 = Math.cos(_local8);
_local15.push(new Vertex((_local6 * _local10), (_local6 * _local9), -(_local7)));
_local11++;
};
_local15.push(new Vertex(0, 0, -(_arg1)));
_local11 = 0;
while (_local11 < 12) {
_local11++;
};
var _local17:uint = 11;
_local11 = 0;
while (_local11 < 5) {
interpolate(0, (_local11 + 1), _arg3, _local15);
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
interpolate((_local11 + 1), (((_local11 + 1) % 5) + 1), _arg3, _local15);
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
interpolate((_local11 + 1), (_local11 + 6), _arg3, _local15);
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
interpolate((_local11 + 1), (((_local11 + 4) % 5) + 6), _arg3, _local15);
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
interpolate((_local11 + 6), (((_local11 + 1) % 5) + 6), _arg3, _local15);
_local11++;
};
_local11 = 0;
while (_local11 < 5) {
interpolate(11, (_local11 + 6), _arg3, _local15);
_local11++;
};
_local12 = 0;
while (_local12 < 5) {
_local11 = 1;
while (_local11 <= (_arg3 - 2)) {
interpolate(((12 + (_local12 * (_arg3 - 1))) + _local11), ((12 + (((_local12 + 1) % 5) * (_arg3 - 1))) + _local11), (_local11 + 1), _local15);
_local11++;
};
_local12++;
};
_local12 = 0;
while (_local12 < 5) {
_local11 = 1;
while (_local11 <= (_arg3 - 2)) {
interpolate(((12 + ((_local12 + 15) * (_arg3 - 1))) + _local11), ((12 + ((_local12 + 10) * (_arg3 - 1))) + _local11), (_local11 + 1), _local15);
_local11++;
};
_local12++;
};
_local12 = 0;
while (_local12 < 5) {
_local11 = 1;
while (_local11 <= (_arg3 - 2)) {
interpolate(((((12 + ((((_local12 + 1) % 5) + 15) * (_arg3 - 1))) + _arg3) - 2) - _local11), ((((12 + ((_local12 + 10) * (_arg3 - 1))) + _arg3) - 2) - _local11), (_local11 + 1), _local15);
_local11++;
};
_local12++;
};
_local12 = 0;
while (_local12 < 5) {
_local11 = 1;
while (_local11 <= (_arg3 - 2)) {
interpolate(((12 + ((((_local12 + 1) % 5) + 25) * (_arg3 - 1))) + _local11), ((12 + ((_local12 + 25) * (_arg3 - 1))) + _local11), (_local11 + 1), _local15);
_local11++;
};
_local12++;
};
var _local18:uint;
_local12 = 0;
while (_local12 <= (_local5 - 1)) {
_local19 = 0;
while (_local19 <= (_arg3 - 1)) {
_local20 = 0;
while (_local20 <= _local19) {
_local21 = findVertices(_arg3, _local12, _local19, _local20);
_local22 = findVertices(_arg3, _local12, (_local19 + 1), _local20);
_local23 = findVertices(_arg3, _local12, (_local19 + 1), (_local20 + 1));
if (_arg4){
var _temp1 = _local18;
_local18 = (_local18 + 1);
var _local25 = _temp1;
_local16[_local25] = new Face(_local15[_local21], _local15[_local23], _local15[_local22]);
} else {
var _temp2 = _local18;
_local18 = (_local18 + 1);
_local25 = _temp2;
_local16[_local25] = new Face(_local15[_local21], _local15[_local22], _local15[_local23]);
};
if (_local20 < _local19){
_local24 = findVertices(_arg3, _local12, _local19, (_local20 + 1));
if (_arg4){
var _temp3 = _local18;
_local18 = (_local18 + 1);
_local25 = _temp3;
_local16[_local25] = new Face(_local15[_local21], _local15[_local24], _local15[_local23]);
} else {
var _temp4 = _local18;
_local18 = (_local18 + 1);
_local25 = _temp4;
_local16[_local25] = new Face(_local15[_local21], _local15[_local23], _local15[_local24]);
};
};
_local20++;
};
_local19++;
};
_local12++;
};
_local11 = 0;
while (_local11 < _local15.length) {
addVertex(_local15[_local11]);
_local11++;
};
_local11 = 0;
while (_local11 < _local16.length) {
addFace(_local16[_local11]);
_local11++;
};
if (((!((_arg2 == null))) && ((_arg2 is ISurfaceRenderer)))){
ISurfaceRenderer(_arg2).faces = faces;
};
}
private function interpolate(_arg1:uint, _arg2:uint, _arg3:uint, _arg4:Array):void{
var _local12:Vertex;
var _local13:Number;
var _local14:Number;
var _local15:Number;
var _local16:Number;
if (_arg3 < 2){
return;
};
var _local5:Vertex = _arg4[_arg1];
var _local6:Vertex = _arg4[_arg2];
var _local7:Number = dot(_local5, _local5);
var _local8:Number = (dot(_local5, _local6) / _local7);
_local8 = ((_local8 < -1)) ? -1 : ((_local8 > 1)) ? 1 : _local8;
var _local9:Number = Math.acos(_local8);
var _local10:Number = Math.sin(_local9);
var _local11:uint = 1;
while (_local11 <= (_arg3 - 1)) {
_local12 = new Vertex();
_local13 = ((_local9 * _local11) / _arg3);
_local14 = ((_local9 * (_arg3 - _local11)) / _arg3);
_local15 = Math.sin(_local13);
_local16 = Math.sin(_local14);
_local12.x = (((_local5.x * _local16) + (_local6.x * _local15)) / _local10);
_local12.y = (((_local5.y * _local16) + (_local6.y * _local15)) / _local10);
_local12.z = (((_local5.z * _local16) + (_local6.z * _local15)) / _local10);
_arg4[_arg4.length] = _local12;
_local11++;
};
}
private function dot(_arg1:Vertex, _arg2:Vertex):Number{
return ((((_arg1.x * _arg2.x) + (_arg1.y * _arg2.y)) + (_arg1.z * _arg2.z)));
}
private function findVertices(_arg1:uint, _arg2:uint, _arg3:uint, _arg4:uint):uint{
if (_arg3 == 0){
if (_arg2 < 5){
return (0);
};
if (_arg2 > 14){
return (11);
};
return ((_arg2 - 4));
};
if ((((_arg3 == _arg1)) && ((_arg4 == 0)))){
if (_arg2 < 5){
return ((_arg2 + 1));
};
if (_arg2 < 10){
return ((((_arg2 + 4) % 5) + 6));
};
if (_arg2 < 15){
return ((((_arg2 + 1) % 5) + 1));
};
return ((((_arg2 + 1) % 5) + 6));
};
if ((((_arg3 == _arg1)) && ((_arg4 == _arg1)))){
if (_arg2 < 5){
return ((((_arg2 + 1) % 5) + 1));
};
if (_arg2 < 10){
return ((_arg2 + 1));
};
if (_arg2 < 15){
return ((_arg2 - 9));
};
return ((_arg2 - 9));
};
if (_arg3 == _arg1){
if (_arg2 < 5){
return ((((12 + ((5 + _arg2) * (_arg1 - 1))) + _arg4) - 1));
};
if (_arg2 < 10){
return ((((12 + ((20 + ((_arg2 + 4) % 5)) * (_arg1 - 1))) + _arg4) - 1));
};
if (_arg2 < 15){
return (((((12 + ((_arg2 - 5) * (_arg1 - 1))) + _arg1) - 1) - _arg4));
};
return (((((12 + ((5 + _arg2) * (_arg1 - 1))) + _arg1) - 1) - _arg4));
};
if (_arg4 == 0){
if (_arg2 < 5){
return ((((12 + (_arg2 * (_arg1 - 1))) + _arg3) - 1));
};
if (_arg2 < 10){
return ((((12 + (((_arg2 % 5) + 15) * (_arg1 - 1))) + _arg3) - 1));
};
if (_arg2 < 15){
return (((((12 + ((((_arg2 + 1) % 5) + 15) * (_arg1 - 1))) + _arg1) - 1) - _arg3));
};
return ((((12 + ((((_arg2 + 1) % 5) + 25) * (_arg1 - 1))) + _arg3) - 1));
};
if (_arg4 == _arg3){
if (_arg2 < 5){
return ((((12 + (((_arg2 + 1) % 5) * (_arg1 - 1))) + _arg3) - 1));
};
if (_arg2 < 10){
return ((((12 + (((_arg2 % 5) + 10) * (_arg1 - 1))) + _arg3) - 1));
};
if (_arg2 < 15){
return (((((12 + (((_arg2 % 5) + 10) * (_arg1 - 1))) + _arg1) - 1) - _arg3));
};
return ((((12 + (((_arg2 % 5) + 25) * (_arg1 - 1))) + _arg3) - 1));
};
return ((((((12 + (30 * (_arg1 - 1))) + (((_arg2 * (_arg1 - 1)) * (_arg1 - 2)) / 2)) + (((_arg3 - 1) * (_arg3 - 2)) / 2)) + _arg4) - 1));
}
}
}//package com.alternativagame.engine3d.primitive
Section 5
//FillSkin (com.alternativagame.engine3d.skin.FillSkin)
package com.alternativagame.engine3d.skin {
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
public class FillSkin extends Shape {
public function draw(_arg1:Array, _arg2:uint, _arg3:Number):void{
var length:*;
var i:*;
var points = _arg1;
var color = _arg2;
var alpha = _arg3;
var _local5 = graphics;
with (_local5) {
clear();
beginFill(color, alpha);
moveTo(points[0].x, points[0].y);
length = points.length;
i = 1;
while (i < length) {
lineTo(points[i].x, points[i].y);
i++;
};
endFill();
};
}
public function light(_arg1:RGB):void{
transform.colorTransform = new ColorTransform(1, 1, 1, 1, ((_arg1.red - 127) << 1), ((_arg1.green - 127) << 1), ((_arg1.blue - 127) << 1));
}
}
}//package com.alternativagame.engine3d.skin
Section 6
//HelperSkin (com.alternativagame.engine3d.skin.HelperSkin)
package com.alternativagame.engine3d.skin {
import com.alternativagame.type.*;
import flash.display.*;
import flash.text.*;
public class HelperSkin extends Sprite {
private var link:Shape;
private var body:Shape;
private var tf:TextField;// = null
private var gizmo:Shape;
public function HelperSkin(){
super();
var _local2 = graphics;
with (_local2) {
clear();
beginFill(0, 0);
drawCircle(0, 0, 10);
};
body = new Shape();
link = new Shape();
gizmo = new Shape();
addChild(gizmo);
addChild(body);
addChild(link);
}
public function drawOmniRange(_arg1:uint, _arg2:Number, _arg3:Number):void{
var color = _arg1;
var near = _arg2;
var far = _arg3;
var _local5 = gizmo.graphics;
with (_local5) {
clear();
lineStyle(1, color, 0.5);
drawCircle(0, 0, far);
lineStyle(1, color, 0.75);
drawCircle(0, 0, near);
};
}
public function drawBody(_arg1:uint, _arg2:Boolean):void{
var color = _arg1;
var solid = _arg2;
var _local4 = body.graphics;
with (_local4) {
clear();
beginFill(color);
drawCircle(0, 0, 3);
endFill();
if (solid){
lineStyle(1, color);
drawCircle(0, 0, 6);
};
};
}
public function clearLink():void{
link.graphics.clear();
}
public function drawAxes(_arg1:Matrix3D):void{
var transformMatrix = _arg1;
var xlen:Number = Math.sqrt((((transformMatrix.a * transformMatrix.a) + (transformMatrix.e * transformMatrix.e)) + (transformMatrix.i * transformMatrix.i)));
var ylen:Number = Math.sqrt((((transformMatrix.b * transformMatrix.b) + (transformMatrix.f * transformMatrix.f)) + (transformMatrix.j * transformMatrix.j)));
var zlen:Number = Math.sqrt((((transformMatrix.c * transformMatrix.c) + (transformMatrix.g * transformMatrix.g)) + (transformMatrix.k * transformMatrix.k)));
var _local3 = gizmo.graphics;
with (_local3) {
clear();
moveTo(0, 0);
lineStyle(1, 0xFF0000);
lineTo(((transformMatrix.a / xlen) * 40), ((transformMatrix.e / xlen) * 40));
moveTo(0, 0);
lineStyle(1, 0xFF00);
lineTo(((transformMatrix.b / ylen) * 40), ((transformMatrix.f / ylen) * 40));
moveTo(0, 0);
lineStyle(1, 0xFF);
lineTo(((transformMatrix.c / zlen) * 40), ((transformMatrix.g / zlen) * 40));
};
}
public function drawDirection(_arg1:uint, _arg2:Matrix3D, _arg3:Boolean):void{
var x0:*;
var y0:*;
var ang:*;
var x1:*;
var y1:*;
var x2:*;
var y2:*;
var color = _arg1;
var transformMatrix = _arg2;
var enabled = _arg3;
var ylen:Number = Math.sqrt((((transformMatrix.b * transformMatrix.b) + (transformMatrix.f * transformMatrix.f)) + (transformMatrix.j * transformMatrix.j)));
var _local5 = gizmo.graphics;
with (_local5) {
clear();
lineStyle(1, (enabled) ? color : 0x333333);
moveTo(0, 0);
x0 = ((transformMatrix.b / ylen) * 30);
y0 = ((transformMatrix.f / ylen) * 30);
lineTo(x0, y0);
ang = Math.atan2(y0, x0);
x1 = ((Math.cos((ang + 2.5)) * 5) + x0);
y1 = ((Math.sin((ang + 2.5)) * 5) + y0);
x2 = ((Math.cos((ang - 2.5)) * 5) + x0);
y2 = ((Math.sin((ang - 2.5)) * 5) + y0);
moveTo(x1, y1);
lineTo(x0, y0);
lineTo(x2, y2);
if (!enabled){
drawCircle(0, 0, 6);
};
};
}
public function clearGizmo():void{
gizmo.graphics.clear();
}
public function clearBody():void{
body.graphics.clear();
}
public function drawText(_arg1:String, _arg2:uint):void{
var _local3:TextFormat;
if (tf == null){
tf = new TextField();
_local3 = new TextFormat("Courier", 11);
_local3.align = "center";
tf.defaultTextFormat = _local3;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.selectable = false;
tf.mouseEnabled = false;
addChild(tf);
};
tf.text = _arg1;
tf.textColor = _arg2;
tf.x = (-(tf.width) / 2);
}
public function drawLight(_arg1:uint, _arg2:Boolean):void{
var color = _arg1;
var enabled = _arg2;
var _local4 = body.graphics;
with (_local4) {
clear();
lineStyle(1, (enabled) ? color : 0x333333);
moveTo(-8, 0);
lineTo(0, -8);
lineTo(8, 0);
lineTo(0, 8);
lineTo(-8, 0);
if (!enabled){
drawCircle(0, 0, 8);
};
};
}
public function clearText():void{
if (tf != null){
removeChild(tf);
tf = null;
};
}
public function drawOmni(_arg1:uint, _arg2:Boolean):void{
var color = _arg1;
var enabled = _arg2;
var _local4 = body.graphics;
with (_local4) {
clear();
lineStyle(1, (enabled) ? color : 0x333333);
moveTo(-8, 0);
lineTo(8, 0);
moveTo(0, -8);
lineTo(0, 8);
moveTo(-6, -6);
lineTo(6, 6);
moveTo(6, -6);
lineTo(-6, 6);
if (!enabled){
drawCircle(0, 0, 8);
};
};
}
public function drawLink(_arg1:Point3D):void{
var canvasCoords = _arg1;
var _local3 = link.graphics;
with (_local3) {
clear();
moveTo(0, 0);
lineStyle(1, 0xFFFFFF, 0.3);
lineTo((canvasCoords.x - x), (canvasCoords.y - y));
};
}
}
}//package com.alternativagame.engine3d.skin
Section 7
//TextureSkin (com.alternativagame.engine3d.skin.TextureSkin)
package com.alternativagame.engine3d.skin {
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
public class TextureSkin extends Shape {
private var textureMatrix:Matrix;
public function draw(_arg1:Array, _arg2:BitmapData, _arg3:Boolean):void{
var length:*;
var i:*;
var points = _arg1;
var texture = _arg2;
var smoothing = _arg3;
var drawMatrix:Matrix = textureMatrix.clone();
drawMatrix.concat(new Matrix((points[1].x - points[0].x), (points[1].y - points[0].y), (points[2].x - points[0].x), (points[2].y - points[0].y), points[0].x, points[0].y));
var _local5 = graphics;
with (_local5) {
clear();
beginBitmapFill(texture, drawMatrix, true, smoothing);
moveTo(points[0].x, points[0].y);
length = points.length;
i = 1;
while (i < length) {
lineTo(points[i].x, points[i].y);
i++;
};
endFill();
};
}
public function calculateMatrix(_arg1:Array, _arg2:uint):void{
var _local3:Point3D = _arg1[0];
var _local4:Point3D = _arg1[1];
var _local5:Point3D = _arg1[2];
textureMatrix = new Matrix();
textureMatrix.tx = ((_local3.x / _arg2) + 1);
textureMatrix.ty = ((_local3.y / _arg2) + 1);
textureMatrix.a = ((_local4.x - _local3.x) / _arg2);
textureMatrix.b = ((_local4.y - _local3.y) / _arg2);
textureMatrix.c = ((_local5.x - _local3.x) / _arg2);
textureMatrix.d = ((_local5.y - _local3.y) / _arg2);
textureMatrix.invert();
}
}
}//package com.alternativagame.engine3d.skin
Section 8
//UVSkin (com.alternativagame.engine3d.skin.UVSkin)
package com.alternativagame.engine3d.skin {
import flash.display.*;
public class UVSkin extends Shape {
public function drawFaceUV(_arg1:Array, _arg2:Number, _arg3:uint, _arg4:Number):void{
var length:*;
var i:*;
var points = _arg1;
var thickness = _arg2;
var color = _arg3;
var alpha = _arg4;
var _local6 = graphics;
with (_local6) {
lineStyle(thickness, color, alpha);
moveTo(points[0].x, points[0].y);
length = points.length;
i = 1;
while (i < length) {
lineTo(points[i].x, points[i].y);
i++;
};
lineTo(points[0].x, points[0].y);
lineStyle();
};
}
public function clear():void{
graphics.clear();
}
public function drawGizmo(_arg1:Array, _arg2:Number, _arg3:uint, _arg4:uint, _arg5:Number, _arg6:uint):void{
var length:*;
var i:*;
var points = _arg1;
var thickness = _arg2;
var lineColor = _arg3;
var fillColor = _arg4;
var fillAlpha = _arg5;
var beginColor = _arg6;
var _local8 = graphics;
with (_local8) {
beginFill(fillColor, fillAlpha);
lineStyle(thickness, lineColor);
moveTo(points[0].x, points[0].y);
length = points.length;
i = 1;
while (i < length) {
lineTo(points[i].x, points[i].y);
i++;
};
lineStyle(thickness, beginColor);
endFill();
lineStyle();
};
}
}
}//package com.alternativagame.engine3d.skin
Section 9
//Ambient (com.alternativagame.engine3d.Ambient)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public class Ambient extends Light {
private static var num:uint = 0;
public function Ambient(_arg1:RGB=null){
super(_arg1);
}
override protected function defaultName():String{
num++;
return (("ambient" + num));
}
}
}//package com.alternativagame.engine3d
Section 10
//Directional (com.alternativagame.engine3d.Directional)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public class Directional extends Light {
var canvasDirection:Point3D;
private static var num:uint = 0;
public function Directional(_arg1:RGB=null){
super(_arg1);
canvasDirection = new Point3D();
}
override function calculate():void{
super.calculate();
if (((((transformChanged) || (viewChanged))) || (parentChanged))){
canvasDirection.x = transformMatrix.b;
canvasDirection.y = transformMatrix.f;
canvasDirection.z = transformMatrix.j;
canvasDirection.normalize();
};
}
override function getStrength(_arg1:Point3D, _arg2:Point3D):Number{
return ((_enabled) ? calculateStrength(_arg2, canvasDirection) : NaN);
}
override protected function cloneParams(_arg1):void{
var _local2:Directional = Directional(_arg1);
super.cloneParams(_local2);
}
override protected function defaultName():String{
num++;
return (("directional" + num));
}
override public function clone():Object3D{
var _local1:Directional = new Directional();
cloneParams(_local1);
cloneRenderers(_local1);
return (_local1);
}
}
}//package com.alternativagame.engine3d
Section 11
//Face (com.alternativagame.engine3d.Face)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.utils.*;
public class Face {
var normalCalculated:Boolean;// = false
var meshChanged:Boolean;// = false
private var lightColorCalculated:Boolean;// = false
var lightColorChanged:Boolean;// = false
var transformChanged:Boolean;// = true
var coordsChanged:Boolean;// = true
var lightChanged:Boolean;// = false
var canvasCenter:Point3D;
var visibleCalculated:Boolean;// = false
public var center:Point3D;
var _vertices:Array;
var canvasNormal:Point3D;
var visibleChanged:Boolean;// = false
var length:uint;
public var normal:Point3D;
var canvasCenterCalculated:Boolean;// = false
var lightColor:RGB;
var visible:Boolean;// = false
var centerCalculated:Boolean;// = false
var mesh:Mesh;
var lightStrength:Dictionary;
var canvasNormalCalculated:Boolean;// = false
public function Face(... _args){
if ((((_args.length == 1)) && ((_args[0] is Array)))){
this._vertices = _args[0];
} else {
this._vertices = _args;
};
length = this._vertices.length;
lightStrength = new Dictionary(true);
lightColor = new RGB();
}
public function get vertices():Array{
return (new Array().concat(_vertices));
}
function calculateLightColor():void{
var _local1:RGB;
var _local2:RGB;
var _local3:Number;
var _local4:*;
if (!lightColorCalculated){
_local1 = new RGB();
for (_local4 in lightStrength) {
_local3 = lightStrength[_local4];
_local2 = Light(_local4)._color;
_local1.red = (_local1.red + (_local2.red * _local3));
_local1.green = (_local1.green + (_local2.green * _local3));
_local1.blue = (_local1.blue + (_local2.blue * _local3));
};
if (((((!(_local1.equals(lightColor))) || (meshChanged))) || (mesh.viewChanged))){
lightColor = _local1;
lightColorChanged = true;
};
lightColorCalculated = true;
};
}
function calculateNormal():void{
var _local1:Point3D;
var _local2:Point3D;
var _local3:Point3D;
var _local4:Point3D;
var _local5:Point3D;
if (!normalCalculated){
_local1 = Vertex(_vertices[0]).coords;
_local2 = Vertex(_vertices[1]).coords;
_local3 = Vertex(_vertices[2]).coords;
_local4 = new Point3D((_local3.x - _local1.x), (_local3.y - _local1.y), (_local3.z - _local1.z));
_local5 = new Point3D((_local2.x - _local1.x), (_local2.y - _local1.y), (_local2.z - _local1.z));
normal = Point3D.cross(_local5, _local4);
normal.normalize();
normalCalculated = true;
};
}
function dropLightColorCalculated():void{
lightColorCalculated = false;
}
public function get vertexJoinedFaces():Set{
var _local2:Vertex;
var _local1:Set = new Set(true);
for each (_local2 in _vertices) {
_local1.concat(_local2.faces);
};
_local1.remove(this);
return (_local1);
}
function calculateVisible():void{
var _local1:Point3D;
var _local2:Point3D;
var _local3:Point3D;
var _local4:Boolean;
if (!visibleCalculated){
_local1 = _vertices[0].canvasCoords;
_local2 = _vertices[1].canvasCoords;
_local3 = _vertices[2].canvasCoords;
_local4 = ((((_local2.x - _local1.x) * (_local3.y - _local1.y)) - ((_local2.y - _local1.y) * (_local3.x - _local1.x))) < 0);
if (_local4 != visible){
visible = _local4;
visibleChanged = true;
};
visibleCalculated = true;
};
}
function calculateLightStrength(_arg1:Light, _arg2:Function=null):void{
var _local3:Number = _arg1.getStrength(canvasCenter, canvasNormal);
if (((isNaN(_local3)) || ((_local3 < 0)))){
removeLight(_arg1);
} else {
if (((!((_arg1 is Ambient))) && (!((_arg2 == null))))){
_local3 = _arg2.call(null, _local3);
};
if ((((((((lightStrength[_arg1] == undefined)) || (!((_local3 == lightStrength[_arg1]))))) || (meshChanged))) || (mesh.viewChanged))){
lightStrength[_arg1] = _local3;
lightChanged = true;
lightColorCalculated = false;
};
};
}
function calculateCanvasCenter():void{
var _local1:uint;
if (!canvasCenterCalculated){
canvasCenter = new Point3D();
_local1 = 0;
while (_local1 < length) {
canvasCenter.add(Vertex(_vertices[_local1]).canvasCoords);
_local1++;
};
canvasCenter.multiply((1 / length));
canvasCenterCalculated = true;
};
}
function calculateCenter():void{
var _local1:uint;
if (!centerCalculated){
center = new Point3D();
_local1 = 0;
while (_local1 < length) {
center.add(Vertex(_vertices[_local1]).coords);
_local1++;
};
center.multiply((1 / length));
centerCalculated = true;
};
}
public function hasVertex(_arg1:Vertex):Boolean{
return ((_vertices.indexOf(_arg1) >= 0));
}
function calculateCanvasNormal():void{
var _local1:Point3D;
var _local2:Point3D;
var _local3:Point3D;
var _local4:Point3D;
var _local5:Point3D;
if (!canvasNormalCalculated){
_local1 = Vertex(_vertices[0]).canvasCoords;
_local2 = Vertex(_vertices[1]).canvasCoords;
_local3 = Vertex(_vertices[2]).canvasCoords;
_local4 = new Point3D((_local3.x - _local1.x), (_local3.y - _local1.y), (_local3.z - _local1.z));
_local5 = new Point3D((_local2.x - _local1.x), (_local2.y - _local1.y), (_local2.z - _local1.z));
canvasNormal = Point3D.cross(_local4, _local5);
canvasNormal.normalize();
canvasNormalCalculated = true;
};
}
function drop():void{
coordsChanged = false;
transformChanged = false;
visibleChanged = false;
meshChanged = false;
lightColorChanged = false;
lightChanged = false;
}
public function get edgeJoinedFaces():Set{
var _local3:Face;
var _local1:Set = new Set(true);
var _local2:uint;
while (_local2 < length) {
for each (_local3 in Vertex(_vertices[_local2]).faces) {
if (((!((_local3 == this))) && ((_local3._vertices.indexOf(_vertices[((_local2)<(length - 1)) ? (_local2 + 1) : 0]) >= 0)))){
_local1.add(_local3);
};
};
_local2++;
};
return (_local1);
}
function setMesh(_arg1:Mesh):void{
mesh = _arg1;
meshChanged = true;
visibleCalculated = false;
centerCalculated = false;
canvasCenterCalculated = false;
normalCalculated = false;
canvasNormalCalculated = false;
}
function removeLight(_arg1:Light):void{
delete lightStrength[_arg1];
lightChanged = true;
lightColorCalculated = false;
}
}
}//package com.alternativagame.engine3d
Section 12
//FillRenderer (com.alternativagame.engine3d.FillRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import com.alternativagame.engine3d.skin.*;
public class FillRenderer extends InteractiveSurfaceRenderer {
private var specularPrecalc1:Number;// = -0.5
private var _alpha:Number;
private var _specular:Number;// = 1
private var _color:uint;
var drawParamsChanged:Boolean;// = true
var specularChanged:Boolean;// = true
private var lights:Set;
private var specularOffset:Number;
var lightChanged:Boolean;// = false
private var specularPrecalc2:Number;
private static var num:uint = 0;
public function FillRenderer(_arg1:RGB=null, _arg2:Number=1, _arg3:Number=3, _arg4:Boolean=false){
specularPrecalc2 = (1 / Math.sqrt((2 * Math.PI)));
specularOffset = (Math.exp(specularPrecalc1) * specularPrecalc2);
super();
_color = ((_arg1)==null) ? 0x7F7F7F : _arg1.toInt();
_alpha = _arg2;
this.specular = _arg3;
this.interactive = _arg4;
}
private function calculateFaceLight(_arg1:Face, _arg2:Function=null):void{
var _local3:Light;
var _local4:Boolean;
if (((((((_arg1.coordsChanged) || (_arg1.transformChanged))) || (_arg1.meshChanged))) || (_object.viewChanged))){
_arg1.calculateCanvasCenter();
if (((((_arg1.transformChanged) || (_arg1.meshChanged))) || (_object.viewChanged))){
_arg1.calculateCanvasNormal();
};
};
for each (_local3 in lights) {
_local4 = ((((((((((((((((_arg1.meshChanged) || (_arg1.visibleChanged))) || (_object.viewChanged))) || (_object.solidParentChanged))) || (_local3.enabledChanged))) || (_local3.solidParentChanged))) || (_local3.viewChanged))) || (_local3.parentChanged))) || (specularChanged));
if ((_local3 is Omni)){
_local4 = ((_local4) || (((((((_arg1.coordsChanged) || (_arg1.transformChanged))) || (_local3.coordsChanged))) || (Omni(_local3).rangeChanged))));
} else {
if ((_local3 is Directional)){
_local4 = ((_local4) || (((_arg1.transformChanged) || (_local3.transformChanged))));
};
};
if (_local4){
_arg1.calculateLightStrength(_local3, _arg2);
};
if (_local3.colorChanged){
_arg1.dropLightColorCalculated();
};
};
_arg1.calculateLightColor();
lightChanged = ((lightChanged) || (_arg1.lightColorChanged));
}
public function get specular():Number{
return (_specular);
}
private function updateLights():void{
var _local1:Set;
var _local2:Light;
var _local3:Face;
if (((((((_object.viewChanged) || (_object.solidParentChanged))) || (_object.solidParent.solidObjectsChanged))) || (objectChanged))){
_local1 = _object.getSolidObjects(Light);
for each (_local2 in lights) {
if (!_local1.has(_local2)){
for each (_local3 in _faces) {
_local3.removeLight(_local2);
};
};
};
lights = _local1;
};
}
override public function drop():void{
super.drop();
drawParamsChanged = false;
specularChanged = false;
lightChanged = false;
}
override public function clone():IRenderer{
var _local1:FillRenderer = new FillRenderer(new RGB(_color), _alpha, specular, _interactive);
return (_local1);
}
public function set alpha(_arg1:Number):void{
_alpha = _arg1;
drawParamsChanged = true;
}
override public function clear():void{
super.clear();
lights = null;
}
public function set specular(_arg1:Number):void{
_specular = _arg1;
var _local2:Number = (1 / _specular);
specularPrecalc1 = (-1 / ((2 * _local2) * _local2));
specularPrecalc2 = (1 / (_local2 * Math.sqrt((2 * Math.PI))));
specularOffset = (Math.exp(specularPrecalc1) * specularPrecalc2);
specularChanged = true;
}
override public function render():void{
var _local1:Face;
var _local2:SkinData;
updateSkinDatas();
updateLights();
for each (_local1 in _faces) {
_local2 = datas[_local1];
updateFaceVisible(_local1);
if (_local1.visible){
calculateFaceLight(_local1, gaussianShading);
if (((((_local1.lightColorChanged) || (_local1.visibleChanged))) || (objectChanged))){
FillSkin(_local2.skin).light(_local1.lightColor);
};
if (((((((((((((_local1.coordsChanged) || (_local1.transformChanged))) || (_local1.meshChanged))) || (_local1.visibleChanged))) || (_object.viewChanged))) || (drawParamsChanged))) || (objectChanged))){
_object._view.changeSkin(_local2);
FillSkin(_local2.skin).draw(_local2.points, _color, _alpha);
};
};
};
}
public function set color(_arg1:RGB):void{
_color = _arg1.toInt();
drawParamsChanged = true;
}
override protected function createSkinData(_arg1:Face):SkinData{
var _local2:Array = _arg1._vertices;
var _local3:uint = _local2.length;
var _local4:SkinData = new SkinData(this, _local3);
var _local5:uint;
while (_local5 < _local3) {
_local4.points[_local5] = _local2[_local5].canvasCoords;
_local5++;
};
_local4.skin = new FillSkin();
return (_local4);
}
public function get alpha():Number{
return (_alpha);
}
function gaussianShading(_arg1:Number):Number{
return (((Math.exp((((1 - _arg1) * (1 - _arg1)) * specularPrecalc1)) * specularPrecalc2) - specularOffset));
}
public function get color():RGB{
return (new RGB(_color));
}
override protected function defaultName():String{
num++;
return (("fillRenderer" + num));
}
}
}//package com.alternativagame.engine3d
Section 13
//HelperRenderer (com.alternativagame.engine3d.HelperRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import com.alternativagame.engine3d.skin.*;
public class HelperRenderer extends ObjectRenderer {
private const skinSize:Number = 20;
private var _body:Boolean;
var textChanged:Boolean;// = true
private var _gizmo:Boolean;
private var _text:Boolean;
var colorChanged:Boolean;// = true
private var _link:Boolean;
var gizmoChanged:Boolean;// = true
var linkChanged:Boolean;// = true
private var _color:uint;
var bodyChanged:Boolean;// = true
private static var num:uint = 0;
public function HelperRenderer(_arg1:Boolean=true, _arg2:Boolean=true, _arg3:Boolean=true, _arg4:Boolean=true, _arg5:RGB=null){
_color = ((_arg5)==null) ? 0xCCCCCC : _arg5.toInt();
_text = _arg1;
_link = _arg2;
_gizmo = _arg3;
_body = _arg4;
}
public function set gizmo(_arg1:Boolean):void{
_gizmo = _arg1;
gizmoChanged = true;
}
public function set body(_arg1:Boolean):void{
_body = _arg1;
bodyChanged = true;
}
public function get text():Boolean{
return (_text);
}
public function set color(_arg1:RGB):void{
_color = _arg1.toInt();
colorChanged = true;
}
public function get link():Boolean{
return (_link);
}
public function set text(_arg1:Boolean):void{
_text = _arg1;
textChanged = true;
}
override public function render():void{
var _local1:Point3D = _object.canvasCoords;
if (data == null){
data = new SkinData(this, 4);
data.skin = new HelperSkin();
_object._view.addSkin(data);
};
var _local2:HelperSkin = HelperSkin(data.skin);
if (((((((_object.coordsChanged) || (_object.viewChanged))) || (_object.parentChanged))) || (objectChanged))){
data.points[0] = new Point3D((_local1.x - (skinSize / 2)), (_local1.y - (skinSize / 2)), _local1.z);
data.points[1] = new Point3D((_local1.x - (skinSize / 2)), (_local1.y + (skinSize / 2)), _local1.z);
data.points[2] = new Point3D((_local1.x + (skinSize / 2)), (_local1.y + (skinSize / 2)), _local1.z);
data.points[3] = new Point3D((_local1.x + (skinSize / 2)), (_local1.y - (skinSize / 2)), _local1.z);
_object._view.changeSkin(data);
_local2.x = _local1.x;
_local2.y = _local1.y;
};
if (((((((((_object.coordsChanged) || (_object.viewChanged))) || (_object.parentChanged))) || (linkChanged))) || (objectChanged))){
if (((_link) && (!((_object.parent == null))))){
_local2.drawLink(_object.parent.canvasCoords);
} else {
_local2.clearLink();
};
};
if (_gizmo){
if ((_object is Light)){
if ((((_object is Omni)) && (((((((((((((((Omni(_object).colorChanged) || (Omni(_object).enabledChanged))) || (Omni(_object).rangeChanged))) || (_object._view.zoomChanged))) || (_object.viewChanged))) || (_object.parentChanged))) || (gizmoChanged))) || (objectChanged))))){
if (Omni(_object)._enabled){
_local2.drawOmniRange(Omni(_object)._color.toInt(), Omni(_object).canvasNear, Omni(_object).canvasFar);
} else {
_local2.clearGizmo();
};
} else {
if ((((_object is Directional)) && (((((((((((((Directional(_object).colorChanged) || (Directional(_object).enabledChanged))) || (_object.transformChanged))) || (_object.viewChanged))) || (_object.parentChanged))) || (gizmoChanged))) || (objectChanged))))){
_local2.drawDirection(Directional(_object)._color.toInt(), _object.transformMatrix, Directional(_object)._enabled);
};
};
} else {
if (((((((((_object.transformChanged) || (_object.viewChanged))) || (_object.parentChanged))) || (gizmoChanged))) || (objectChanged))){
_local2.drawAxes(_object.transformMatrix);
};
};
} else {
_local2.clearGizmo();
};
if (_body){
if ((_object is Light)){
if (((((((((((Light(_object).colorChanged) || (Light(_object).enabledChanged))) || (_object.viewChanged))) || (_object.parentChanged))) || (bodyChanged))) || (objectChanged))){
if ((_object is Omni)){
_local2.drawOmni(Light(_object)._color.toInt(), Light(_object)._enabled);
} else {
_local2.drawLight(Light(_object)._color.toInt(), Light(_object)._enabled);
};
};
} else {
if (((((((((((_object.solidChanged) || (_object.viewChanged))) || (_object.parentChanged))) || (bodyChanged))) || (colorChanged))) || (objectChanged))){
_local2.drawBody(_color, _object.solid);
};
};
} else {
_local2.clearBody();
};
if (((((((((((_object.nameChanged) || (_object.viewChanged))) || (_object.parentChanged))) || (textChanged))) || (colorChanged))) || (objectChanged))){
if (_text){
_local2.drawText(_object.name, _color);
} else {
_local2.clearText();
};
};
}
public function get color():RGB{
return (new RGB(_color));
}
public function get body():Boolean{
return (_body);
}
override protected function defaultName():String{
num++;
return (("helperRenderer" + num));
}
public function set link(_arg1:Boolean):void{
_link = _arg1;
linkChanged = true;
}
override public function drop():void{
super.drop();
textChanged = false;
linkChanged = false;
gizmoChanged = false;
bodyChanged = false;
colorChanged = false;
}
override public function clone():IRenderer{
var _local1:HelperRenderer = new HelperRenderer(_text, _link, _gizmo, _body, new RGB(_color));
return (_local1);
}
public function get gizmo():Boolean{
return (_gizmo);
}
}
}//package com.alternativagame.engine3d
Section 14
//Interaction (com.alternativagame.engine3d.Interaction)
package com.alternativagame.engine3d {
public class Interaction {
public static const SKIN_CLICK:uint = 5;
public static const SKIN_OUT:uint = 4;
public static const OBJECT_CLICK:uint = 11;
public static const RENDERER_OVER:uint = 6;
public static const MOVE:uint = 0;
public static const RENDERER_OUT:uint = 7;
public static const OBJECT_OVER:uint = 9;
public static const OBJECT_OUT:uint = 10;
public static const RENDERER_CLICK:uint = 8;
public static const DOWN:uint = 1;
public static const UP:uint = 2;
public static const SKIN_OVER:uint = 3;
}
}//package com.alternativagame.engine3d
Section 15
//InteractiveSurfaceRenderer (com.alternativagame.engine3d.InteractiveSurfaceRenderer)
package com.alternativagame.engine3d {
public class InteractiveSurfaceRenderer extends SurfaceRenderer {
protected var _interactive:Boolean;// = false
var interactiveChanged:Boolean;// = true
private static var num:uint = 0;
public function get interactive():Boolean{
return (_interactive);
}
public function set interactive(_arg1:Boolean):void{
_interactive = _arg1;
interactiveChanged = true;
}
override protected function defaultName():String{
num++;
return (("interactiveSurfaceRenderer" + num));
}
override public function clone():IRenderer{
var _local1:InteractiveSurfaceRenderer = new InteractiveSurfaceRenderer();
_local1.interactive = _interactive;
return (_local1);
}
override public function drop():void{
super.drop();
interactiveChanged = false;
}
}
}//package com.alternativagame.engine3d
Section 16
//IRenderer (com.alternativagame.engine3d.IRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public interface IRenderer {
function setObject(_arg1:Object3D):void;
function interaction(_arg1:uint, _arg2:SkinData, _arg3:Point3D, _arg4:Boolean, _arg5:Boolean, _arg6:Boolean, _arg7:Boolean):void;
function clear():void;
function set name(_arg1:String):void;
function render():void;
function checkInteraction(_arg1:SkinData, _arg2:Point3D):Boolean;
function get name():String;
function clone():IRenderer;
function get object():Object3D;
function drop():void;
}
}//package com.alternativagame.engine3d
Section 17
//ISurfaceRenderer (com.alternativagame.engine3d.ISurfaceRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public interface ISurfaceRenderer extends IRenderer {
function removeFace(_arg1:Face):void;
function set faces(_arg1:Set):void;
function get faces():Set;
function addFace(_arg1:Face):void;
}
}//package com.alternativagame.engine3d
Section 18
//Light (com.alternativagame.engine3d.Light)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public class Light extends Object3D {
var _enabled:Boolean;
var _color:RGB;
var colorChanged:Boolean;// = true
var enabledChanged:Boolean;// = true
private static var num:uint = 0;
public function Light(_arg1:RGB=null):void{
_color = ((_arg1)==null) ? new RGB() : _arg1;
_enabled = true;
}
public function get enabled():Boolean{
return (_enabled);
}
public function get color():RGB{
return (_color);
}
protected function calculateStrength(_arg1:Point3D, _arg2:Point3D):Number{
if (_enabled){
return (-(Point3D.dot(_arg2, _arg1)));
};
return (NaN);
}
override protected function cloneParams(_arg1):void{
var _local2:Light = Light(_arg1);
_local2.color = _color;
_local2.enabled = _enabled;
super.cloneParams(_local2);
}
override protected function defaultName():String{
num++;
return (("light" + num));
}
public function set color(_arg1:RGB):void{
_color = _arg1;
colorChanged = true;
}
override function drop():void{
super.drop();
colorChanged = false;
enabledChanged = false;
}
function getStrength(_arg1:Point3D, _arg2:Point3D):Number{
return ((_enabled) ? 1 : NaN);
}
public function set enabled(_arg1:Boolean):void{
_enabled = _arg1;
enabledChanged = true;
}
override public function clone():Object3D{
var _local1:Light = new Light();
cloneParams(_local1);
cloneRenderers(_local1);
return (_local1);
}
}
}//package com.alternativagame.engine3d
Section 19
//Mesh (com.alternativagame.engine3d.Mesh)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.utils.*;
public class Mesh extends Object3D {
private var _vertices:Set;
var geometryChanged:Boolean;// = false
var facesChanged:Boolean;// = false
private var _faces:Set;
var verticesChanged:Boolean;// = false
private static var num:uint = 0;
public function Mesh(){
_vertices = new Set(true);
_faces = new Set(true);
}
public function removeFace(_arg1:Face):void{
var _local2:Vertex;
var _local3:uint;
if (_faces.has(_arg1)){
_faces.remove(_arg1);
_local3 = 0;
while (_local3 < _arg1._vertices.length) {
_local2 = Vertex(_arg1._vertices[_local3]);
_local2.faces.remove(_arg1);
_local2.facesChanged = true;
_local3++;
};
_arg1.setMesh(null);
facesChanged = true;
};
}
override protected function cloneParams(_arg1):void{
var _local2:Mesh = Mesh(_arg1);
super.cloneParams(_local2);
}
public function removeVertex(_arg1:Vertex):void{
var _local2:Face;
if (_vertices.has(_arg1)){
for each (_local2 in _arg1.faces) {
removeFace(_local2);
};
_vertices.remove(_arg1);
_arg1.setMesh(null);
verticesChanged = true;
};
}
override public function addRenderer(_arg1:IRenderer):void{
super.addRenderer(_arg1);
if ((((((_arg1 is ISurfaceRenderer)) && (_renderers.has(_arg1)))) && ((ISurfaceRenderer(_arg1).faces.length == 0)))){
ISurfaceRenderer(_arg1).faces = _faces;
};
}
public function addRendererAuto(_arg1:ISurfaceRenderer, _arg2:Number):void{
var _local4:Face;
var _local5:ISurfaceRenderer;
var _local3:Set = new Set(true);
for each (_local4 in _faces) {
_local4.calculateNormal();
_local3.add(_local4);
};
if (_local3.length > 0){
addFacesToRendererByAngle(_local3, _local3.first(), _arg1, _arg2);
addRenderer(_arg1);
while (_local3.length > 0) {
_local5 = ISurfaceRenderer(_arg1.clone());
addFacesToRendererByAngle(_local3, _local3.first(), _local5, _arg2);
addRenderer(_local5);
};
};
}
protected function cloneLinkedParams(_arg1:Mesh):void{
var _local3:Vertex;
var _local4:Face;
var _local5:Dictionary;
var _local6:uint;
var _local7:Array;
var _local8:IRenderer;
var _local9:IRenderer;
var _local10:uint;
var _local11:Set;
var _local2:Dictionary = new Dictionary(true);
for each (_local3 in vertices) {
_local2[_local3] = _local3.clone();
_arg1.addVertex(_local2[_local3]);
};
_local5 = new Dictionary(true);
for each (_local4 in faces) {
_local6 = _local4._vertices.length;
_local7 = new Array();
_local10 = 0;
while (_local10 < _local6) {
_local7.push(_local2[_local4._vertices[_local10]]);
_local10++;
};
_local5[_local4] = new Face(_local7);
_arg1.addFace(_local5[_local4]);
};
for each (_local9 in _renderers) {
_local8 = _local9.clone();
_arg1.addRenderer(_local8);
if ((_local9 is ISurfaceRenderer)){
_local11 = new Set(true);
for each (_local4 in ISurfaceRenderer(_local9).faces) {
_local11.add(_local5[_local4]);
};
ISurfaceRenderer(_local8).faces = _local11;
};
};
}
public function removeGeometry():void{
var _local1:Face;
var _local2:Vertex;
if (_vertices.length > 0){
for each (_local1 in _faces) {
_local1.setMesh(null);
};
_faces.clear();
for each (_local2 in _vertices) {
_local2.faces.clear();
_local2.setMesh(null);
};
_vertices.clear();
verticesChanged = true;
facesChanged = true;
};
}
override public function replaceRenderer(_arg1:IRenderer, _arg2:IRenderer):void{
if (!(_arg2 is ISurfaceRenderer)){
super.replaceRenderer(_arg1, _arg2);
} else {
if (_renderers.has(_arg1)){
removeRenderer(_arg1);
addRenderer(_arg2);
if ((_arg1 is ISurfaceRenderer)){
ISurfaceRenderer(_arg2).faces = ISurfaceRenderer(_arg1).faces;
};
};
};
}
override public function clone():Object3D{
var _local1:Mesh = new Mesh();
cloneParams(_local1);
cloneLinkedParams(_local1);
return (_local1);
}
public function addFace(_arg1:Face):void{
var _local2:Vertex;
if (_arg1.mesh != null){
_arg1.mesh.removeFace(_arg1);
};
_faces.add(_arg1);
var _local3:uint;
while (_local3 < _arg1._vertices.length) {
_local2 = Vertex(_arg1._vertices[_local3]);
if (_local2.mesh == this){
_local2.faces.add(_arg1);
_local2.facesChanged = true;
} else {
throw (new Error("Face use vertex from another mesh"));
};
_local3++;
};
_arg1.setMesh(this);
facesChanged = true;
}
public function addVertex(_arg1:Vertex):void{
if (_arg1.mesh != null){
_arg1.mesh.removeVertex(_arg1);
};
_vertices.add(_arg1);
_arg1.setMesh(this);
verticesChanged = true;
}
override function calculate():void{
var _local1:Vertex;
super.calculate();
if (((((((((((transformChanged) || (coordsChanged))) || (geometryChanged))) || (verticesChanged))) || (viewChanged))) || (parentChanged))){
for each (_local1 in _vertices) {
_local1.calculate(transformMatrix);
};
};
}
override function setView(_arg1:View):void{
var _local2:Face;
if (_view != _arg1){
for each (_local2 in _faces) {
_local2.visibleCalculated = false;
_local2.canvasCenterCalculated = false;
_local2.canvasNormalCalculated = false;
};
};
super.setView(_arg1);
}
private function addFacesToRendererByAngle(_arg1:Set, _arg2:Face, _arg3:ISurfaceRenderer, _arg4:Number):void{
var _local6:Face;
_arg3.addFace(_arg2);
_arg1.remove(_arg2);
var _local5:Set = _arg2.edgeJoinedFaces;
for each (_local6 in _local5) {
if (((_arg1.has(_local6)) && ((Point3D.angleFast(_arg2.normal, _local6.normal) < _arg4)))){
addFacesToRendererByAngle(_arg1, _local6, _arg3, _arg4);
};
};
}
override function setTransformChanged():void{
var _local1:Vertex;
var _local2:Face;
if (!transformChanged){
for each (_local1 in _vertices) {
_local1.coordsChanged = true;
};
for each (_local2 in _faces) {
_local2.coordsChanged = true;
_local2.transformChanged = true;
_local2.visibleCalculated = false;
_local2.canvasCenterCalculated = false;
_local2.canvasNormalCalculated = false;
};
};
super.setTransformChanged();
}
override protected function defaultName():String{
num++;
return (("mesh" + num));
}
override function drop():void{
var _local1:Vertex;
var _local2:Face;
super.drop();
geometryChanged = false;
verticesChanged = false;
facesChanged = false;
for each (_local1 in _vertices) {
_local1.drop();
};
for each (_local2 in _faces) {
_local2.drop();
};
}
override function setCoordsChanged():void{
var _local1:Vertex;
var _local2:Face;
if (!coordsChanged){
for each (_local1 in _vertices) {
_local1.coordsChanged = true;
};
for each (_local2 in _faces) {
_local2.coordsChanged = true;
_local2.canvasCenterCalculated = false;
};
};
super.setCoordsChanged();
}
public function get vertices():Set{
return (_vertices);
}
public function get faces():Set{
return (_faces);
}
}
}//package com.alternativagame.engine3d
Section 20
//Object3D (com.alternativagame.engine3d.Object3D)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.utils.*;
import com.alternativagame.utility.*;
public class Object3D {
var objectsChanged:Boolean;// = false
public var solidParent:Object3D;
private var _coords:Point3D;
private var _rotX:Number;// = 0
private var _rotY:Number;// = 0
private var _rotZ:Number;// = 0
private var directionTransformCalculated:Boolean;// = false
var transformMatrix:Matrix3D;
var viewChanged:Boolean;// = false
private var _scaleX:Number;// = 1
private var _scaleY:Number;// = 1
private var _scaleZ:Number;// = 1
private var _name:String;
var _view:View;// = null
var solidChanged:Boolean;// = true
protected var _renderers:Set;
var solidObjectsChanged:Boolean;// = true
var renderersChanged:Boolean;// = false
var canvasCoords:Point3D;
var transformChanged:Boolean;// = true
var nameChanged:Boolean;// = true
private var _solid:Boolean;// = false
var parentChanged:Boolean;// = false
var mobileChanged:Boolean;// = true
var coordsChanged:Boolean;// = true
var parent:Object3D;// = null
var solidParentChanged:Boolean;// = true
private var _mobile:Boolean;// = false
var directionTransformMatrix:Matrix3D;
var _objects:Set;
private var solidObjects:Dictionary;
private var inverseTransformCalculated:Boolean;// = false
var inverseTransformMatrix:Matrix3D;
private static var num:uint = 0;
public function Object3D(){
_coords = new Point3D();
_objects = new Set(true);
solidParent = this;
solidObjects = new Dictionary(true);
addSolidObject(this);
_renderers = new Set(true);
_name = defaultName();
}
public function get renderers():Set{
return (_renderers);
}
public function get objects():Set{
return (_objects);
}
public function getObjectByName(_arg1:String):Object3D{
var _local3:Object3D;
var _local2:Object3D;
for each (_local3 in _objects) {
if (_local3.name == _arg1){
_local2 = _local3;
break;
};
};
return (_local2);
}
public function getRendererByName(_arg1:String):IRenderer{
var _local3:IRenderer;
var _local2:IRenderer;
for each (_local3 in _renderers) {
if (_local3.name == _arg1){
_local2 = _local3;
break;
};
};
return (_local2);
}
public function set name(_arg1:String):void{
_name = _arg1;
nameChanged = true;
}
public function get coords():Point3D{
return (_coords);
}
function setView(_arg1:View):void{
var _local2:Object3D;
var _local3:IRenderer;
if (_view != _arg1){
if (_arg1 == null){
canvasCoords = null;
transformMatrix = null;
for each (_local3 in _renderers) {
_local3.clear();
};
} else {
canvasCoords = new Point3D();
viewChanged = true;
};
_view = _arg1;
for each (_local2 in _objects) {
_local2.setView(_arg1);
};
};
}
function setTransformChanged():void{
var _local1:Object3D;
if (!transformChanged){
for each (_local1 in _objects) {
_local1.setCoordsChanged();
_local1.setTransformChanged();
};
transformChanged = true;
};
}
public function canvasToLocal(_arg1:Point3D):Point3D{
calculateInverseTransform();
var _local2:Point3D = _arg1.clone();
_local2.transform(inverseTransformMatrix);
return (_local2);
}
protected function cloneRenderers(_arg1):void{
var _local3:IRenderer;
var _local4:IRenderer;
var _local2:Object3D = Object3D(_arg1);
for each (_local3 in _renderers) {
_local4 = _local3.clone();
_local4.name = _local3.name;
_local2.addRenderer(_local4);
};
}
public function set coords(_arg1:Point3D):void{
_coords.copy(_arg1);
setCoordsChanged();
}
protected function cloneParams(_arg1):void{
var _local3:Object3D;
var _local2:Object3D = Object3D(_arg1);
_local2.coords = _coords;
_local2.rotX = _rotX;
_local2.rotY = _rotY;
_local2.rotZ = _rotZ;
_local2.scaleX = _scaleX;
_local2.scaleY = _scaleY;
_local2.scaleZ = _scaleZ;
_local2.solid = _solid;
_local2.name = _name;
_local2.mobile = _mobile;
for each (_local3 in _objects) {
_local2.attach(_local3.clone());
};
}
public function set mobile(_arg1:Boolean):void{
if (_mobile != _arg1){
_mobile = _arg1;
mobileChanged = true;
};
}
public function attach(_arg1:Object3D):void{
if (((!((_arg1 == null))) && (!((_arg1.parent == this))))){
if (_arg1.parent != null){
_arg1.parent._objects.remove(_arg1);
_arg1.parent.objectsChanged = true;
} else {
if (((!((_arg1._view == null))) && ((_arg1._view.object == _arg1)))){
_arg1._view.object = null;
};
};
if (getBranch().indexOf(_arg1) < 0){
_objects.add(_arg1);
_arg1.setParent(this);
_arg1.setView(_view);
objectsChanged = true;
} else {
throw (new Error("Can't attach parent object"));
};
};
}
public function get scaleX():Number{
return (_scaleX);
}
public function get scaleY():Number{
return (_scaleY);
}
public function get scaleZ():Number{
return (_scaleZ);
}
public function set solid(_arg1:Boolean):void{
var _local2:Object3D;
var _local3:Object3D;
_solid = _arg1;
if (_arg1){
_local2 = this;
} else {
_local2 = solidParent;
};
for each (_local3 in _objects) {
_local3.setSolidParent(_local2);
};
solidChanged = true;
}
public function getSolidObjects(_arg1:Class=null):Set{
if (((solid) || ((parent == null)))){
_arg1 = ((_arg1)==null) ? Object3D : _arg1;
if (solidObjects[_arg1] != undefined){
return (Set(solidObjects[_arg1]).clone());
};
return (new Set());
//unresolved jump
};
return (solidParent.getSolidObjects(_arg1));
}
public function get rotX():Number{
return (_rotX);
}
public function get rotY():Number{
return (_rotY);
}
public function get rotZ():Number{
return (_rotZ);
}
function calculate():void{
var _local1:Object3D;
var _local2:Matrix3D;
var _local3:Point3D;
if (((((((transformChanged) || (coordsChanged))) || (viewChanged))) || (parentChanged))){
_local2 = ((this)==_view.object) ? _view.transformMatrix : parent.transformMatrix;
if (((((transformChanged) || (viewChanged))) || (parentChanged))){
transformMatrix = Matrix3D.transformMatrix(x, y, z, rotX, rotY, rotZ, scaleX, scaleY, scaleZ);
transformMatrix.combine(_local2);
} else {
_local3 = coords.clone();
_local3.transform(_local2);
transformMatrix.d = _local3.x;
transformMatrix.h = _local3.y;
transformMatrix.l = _local3.z;
};
canvasCoords.x = transformMatrix.d;
canvasCoords.y = transformMatrix.h;
canvasCoords.z = transformMatrix.l;
inverseTransformCalculated = false;
directionTransformCalculated = false;
};
for each (_local1 in _objects) {
_local1.calculate();
};
}
public function removeRenderer(_arg1:IRenderer):void{
if (_renderers.has(_arg1)){
_renderers.remove(_arg1);
_arg1.setObject(null);
renderersChanged = true;
};
}
function addSolidObject(_arg1:Object3D):void{
var _local3:Class;
var _local2:Array = ObjectUtility.getClassTree(_arg1, Object3D);
var _local4:uint;
while (_local4 < _local2.length) {
_local3 = _local2[_local4];
if (solidObjects[_local3] == undefined){
solidObjects[_local3] = new Set();
};
solidObjects[_local3].add(_arg1);
_local4++;
};
solidObjectsChanged = true;
}
function setSolidParent(_arg1:Object3D):void{
var _local2:Object3D;
solidParent.removeSolidObject(this);
_arg1.addSolidObject(this);
if (!solid){
for each (_local2 in _objects) {
_local2.setSolidParent(_arg1);
};
};
solidParent = _arg1;
solidParentChanged = true;
}
function setCoordsChanged():void{
var _local1:Object3D;
if (!coordsChanged){
for each (_local1 in _objects) {
_local1.setCoordsChanged();
};
coordsChanged = true;
};
}
public function clone():Object3D{
var _local1:Object3D = new Object3D();
cloneParams(_local1);
cloneRenderers(_local1);
return (_local1);
}
public function get x():Number{
return (_coords.x);
}
public function get y():Number{
return (_coords.y);
}
protected function defaultName():String{
num++;
return (("object" + num));
}
public function get z():Number{
return (_coords.z);
}
public function toString():String{
return ((((("[" + ObjectUtility.getClassName(this)) + " ") + _name) + "]"));
}
public function set scale(_arg1:Number):void{
_scaleX = _arg1;
_scaleY = _arg1;
_scaleZ = _arg1;
setTransformChanged();
}
public function replaceRenderer(_arg1:IRenderer, _arg2:IRenderer):void{
if (_renderers.has(_arg1)){
removeRenderer(_arg1);
addRenderer(_arg2);
};
}
function getBranch():Array{
var _local1:Array = new Array();
var _local2:Object3D = this;
while (_local2 != null) {
_local1.push(_local2);
_local2 = _local2.parent;
};
return (_local1);
}
public function set scaleZ(_arg1:Number):void{
_scaleZ = _arg1;
setTransformChanged();
}
public function detach(_arg1:Object3D):void{
if (((!((_arg1 == null))) && (_objects.has(_arg1)))){
_objects.remove(_arg1);
_arg1.setParent(null);
_arg1.setView(null);
objectsChanged = true;
};
}
public function get name():String{
return (_name);
}
function render():void{
var _local1:IRenderer;
var _local2:Object3D;
for each (_local1 in _renderers) {
_local1.render();
};
for each (_local2 in _objects) {
_local2.render();
};
}
function removeSolidObject(_arg1:Object3D):void{
var _local3:Class;
var _local2:Array = ObjectUtility.getClassTree(_arg1, Object3D);
var _local4:uint;
while (_local4 < _local2.length) {
_local3 = _local2[_local4];
Set(solidObjects[_local3]).remove(_arg1);
if (Set(solidObjects[_local3]).length == 0){
delete solidObjects[_local3];
};
_local4++;
};
solidObjectsChanged = true;
}
public function set scaleX(_arg1:Number):void{
_scaleX = _arg1;
setTransformChanged();
}
public function set scaleY(_arg1:Number):void{
_scaleY = _arg1;
setTransformChanged();
}
public function canvasDirectionToLocal(_arg1:Point3D):Point3D{
calculateDirectionTransform();
var _local2:Point3D = _arg1.clone();
_local2.transform(directionTransformMatrix);
return (_local2);
}
function setParent(_arg1:Object3D):void{
if (_arg1 == null){
setSolidParent(this);
} else {
setSolidParent((_arg1.solid) ? _arg1 : _arg1.solidParent);
};
parent = _arg1;
parentChanged = true;
}
public function get view():View{
return (_view);
}
public function get solid():Boolean{
return (_solid);
}
public function addRenderer(_arg1:IRenderer):void{
if (!_renderers.has(_arg1)){
if (_arg1.object != null){
_arg1.object.removeRenderer(_arg1);
};
_renderers.add(_arg1);
_arg1.setObject(this);
renderersChanged = true;
};
}
public function set rotX(_arg1:Number):void{
_rotX = _arg1;
setTransformChanged();
}
public function set rotY(_arg1:Number):void{
_rotY = _arg1;
setTransformChanged();
}
public function set rotZ(_arg1:Number):void{
_rotZ = _arg1;
setTransformChanged();
}
public function removeRendererByName(_arg1:String):void{
var _local2:IRenderer = getRendererByName(_arg1);
if (_local2 != null){
removeRenderer(_local2);
};
}
function calculateDirectionTransform():void{
var _local1:Matrix3D;
if (!directionTransformCalculated){
_local1 = transformMatrix.clone();
_local1.d = 0;
_local1.h = 0;
_local1.l = 0;
directionTransformMatrix = Matrix3D.inverseMatrix(_local1);
directionTransformCalculated = true;
};
}
public function get mobile():Boolean{
return (_mobile);
}
function calculateInverseTransform():void{
if (!inverseTransformCalculated){
inverseTransformMatrix = Matrix3D.inverseMatrix(transformMatrix);
inverseTransformCalculated = true;
};
}
public function removeRenderers():void{
var _local1:IRenderer;
for each (_local1 in _renderers) {
_local1.setObject(null);
};
_renderers.clear();
renderersChanged = true;
}
function drop():void{
var _local1:IRenderer;
var _local2:Object3D;
coordsChanged = false;
transformChanged = false;
viewChanged = false;
parentChanged = false;
objectsChanged = false;
renderersChanged = false;
solidChanged = false;
solidParentChanged = false;
solidObjectsChanged = false;
nameChanged = false;
mobileChanged = false;
for each (_local1 in _renderers) {
_local1.drop();
};
for each (_local2 in _objects) {
_local2.drop();
};
}
public function set x(_arg1:Number):void{
_coords.x = _arg1;
setCoordsChanged();
}
public function set y(_arg1:Number):void{
_coords.y = _arg1;
setCoordsChanged();
}
public function replaceRendererByName(_arg1:String, _arg2:IRenderer):void{
var _local3:IRenderer = getRendererByName(_arg1);
if (_local3 != null){
replaceRenderer(_local3, _arg2);
};
}
public function set z(_arg1:Number):void{
_coords.z = _arg1;
setCoordsChanged();
}
}
}//package com.alternativagame.engine3d
Section 21
//ObjectRenderer (com.alternativagame.engine3d.ObjectRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import com.alternativagame.utility.*;
public class ObjectRenderer implements IRenderer {
protected var data:SkinData;
protected var _object:Object3D;
var nameChanged:Boolean;// = true
private var _name:String;
var objectChanged:Boolean;// = false
private static var num:uint = 0;
public function ObjectRenderer(){
_name = defaultName();
}
public function setObject(_arg1:Object3D):void{
if (_object != _arg1){
clear();
_object = _arg1;
objectChanged = true;
};
}
public function get name():String{
return (_name);
}
public function interaction(_arg1:uint, _arg2:SkinData, _arg3:Point3D, _arg4:Boolean, _arg5:Boolean, _arg6:Boolean, _arg7:Boolean):void{
}
public function clear():void{
if (((((!((_object == null))) && (!((_object._view == null))))) && (!((data == null))))){
_object._view.removeSkin(data);
data = null;
};
}
public function set name(_arg1:String):void{
_name = _arg1;
nameChanged = true;
}
public function render():void{
}
public function clone():IRenderer{
var _local1:ObjectRenderer = new ObjectRenderer();
return (_local1);
}
public function checkInteraction(_arg1:SkinData, _arg2:Point3D):Boolean{
return (false);
}
protected function defaultName():String{
num++;
return (("objectRenderer" + num));
}
public function drop():void{
nameChanged = false;
objectChanged = false;
}
public function toString():String{
return ((((("[" + ObjectUtility.getClassName(this)) + " ") + _name) + "]"));
}
public function get object():Object3D{
return (_object);
}
}
}//package com.alternativagame.engine3d
Section 22
//Omni (com.alternativagame.engine3d.Omni)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public class Omni extends Light {
private var _near:Number;
var nearSqr:Number;
var canvasNearSqr:Number;
private var _far:Number;
var canvasFar:Number;
var canvasNear:Number;
var canvasFarNearSqr:Number;
var farNearSqr:Number;
var rangeChanged:Boolean;// = true
var canvasFarSqr:Number;
var farSqr:Number;
private static var num:uint = 0;
public function Omni(_arg1:RGB=null, _arg2:Number=0, _arg3:Number=100){
super(_arg1);
_near = _arg2;
_far = _arg3;
setChangedRange();
}
override protected function cloneParams(_arg1):void{
var _local2:Omni = Omni(_arg1);
_local2.far = far;
_local2.near = near;
super.cloneParams(_local2);
}
override function getStrength(_arg1:Point3D, _arg2:Point3D):Number{
var _local3:Point3D;
var _local4:Number;
var _local5:Number;
if (_enabled){
_local3 = new Point3D((_arg1.x - canvasCoords.x), (_arg1.y - canvasCoords.y), (_arg1.z - canvasCoords.z));
_local4 = _local3.lengthSqr;
if (_local4 <= canvasFarSqr){
_local3.normalize();
_local5 = calculateStrength(_arg2, _local3);
if (_local4 > canvasNearSqr){
_local5 = (_local5 * (canvasFarNearSqr * (canvasFarSqr - _local4)));
};
return (_local5);
} else {
return (NaN);
};
//unresolved jump
};
return (NaN);
}
public function get near():Number{
return (_near);
}
public function set near(_arg1:Number):void{
_near = _arg1;
setChangedRange();
}
public function get far():Number{
return (_far);
}
public function set far(_arg1:Number):void{
_far = _arg1;
setChangedRange();
}
override public function clone():Object3D{
var _local1:Omni = new Omni();
cloneParams(_local1);
cloneRenderers(_local1);
return (_local1);
}
override function calculate():void{
super.calculate();
if (((((((_view.zoomChanged) || (rangeChanged))) || (viewChanged))) || (parentChanged))){
canvasNear = (_near * _view.zoom);
canvasFar = (_far * _view.zoom);
canvasNearSqr = (canvasNear * canvasNear);
canvasFarSqr = (canvasFar * canvasFar);
canvasFarNearSqr = (1 / (canvasFarSqr - canvasNearSqr));
};
}
private function setChangedRange():void{
nearSqr = (_near * _near);
farSqr = (_far * _far);
farNearSqr = (1 / (farSqr - nearSqr));
rangeChanged = true;
}
override protected function defaultName():String{
num++;
return (("omni" + num));
}
override function drop():void{
super.drop();
rangeChanged = false;
}
}
}//package com.alternativagame.engine3d
Section 23
//PolyTextureObject (com.alternativagame.engine3d.PolyTextureObject)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.geom.*;
public class PolyTextureObject extends TextureObject {
private var _points:Array;
private var _color:RGB;
private var _texture:TextureData;
public function PolyTextureObject(_arg1:RGB=null, _arg2:TextureData=null, ... _args){
_color = _arg1;
_texture = _arg2;
_points = _args;
}
public function get color():RGB{
return (_color);
}
public function set color(_arg1:RGB):void{
_color = _arg1;
setTextureChanged();
}
public function get points():Array{
return (new Array().concat(_points));
}
override public function clone():TextureObject{
var _local1:PolyTextureObject = new PolyTextureObject(_color, _texture);
_local1.alpha = alpha;
_local1.points = new Array().concat(_points);
return (_local1);
}
public function set points(_arg1:Array):void{
_points = _arg1;
setTextureChanged();
}
public function set texture(_arg1:TextureData):void{
_texture = _arg1;
setTextureChanged();
}
public function get texture():TextureData{
return (_texture);
}
override function render():void{
var uvCoords:Point3D;
var length:uint;
var i:*;
if (((((textureChanged) || (coordsChanged))) || (_renderer.uvChanged))){
uvCoords = _renderer.localToUV(Point3D.sum(coords, _points[0]));
length = _points.length;
var _local2 = graphics;
with (_local2) {
clear();
if (((!((_texture == null))) || (!((_color == null))))){
if (_texture != null){
beginBitmapFill(_texture.bitmapData, new Matrix(_texture.resolution, 0, 0, _texture.resolution), true, true);
} else {
beginFill(_color.toInt());
};
moveTo(uvCoords.x, uvCoords.y);
i = 1;
while (i < length) {
uvCoords = _renderer.localToUV(Point3D.sum(coords, _points[i]));
lineTo(uvCoords.x, uvCoords.y);
i++;
};
endFill();
};
};
};
}
}
}//package com.alternativagame.engine3d
Section 24
//ShadowTextureObject (com.alternativagame.engine3d.ShadowTextureObject)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
public class ShadowTextureObject extends TextureObject {
private var _mesh:Mesh;
private var meshUV:Dictionary;
var meshChanged:Boolean;// = true
public function ShadowTextureObject(_arg1:Mesh){
_mesh = _arg1;
blendMode = BlendMode.SUBTRACT;
}
public function set mesh(_arg1:Mesh):void{
if (_mesh != _arg1){
_mesh = _arg1;
meshChanged = true;
};
}
override function render():void{
var comulativeMeshChanged:Boolean;
var light:Directional;
var v:Vertex;
var direction:Point3D;
var f:Face;
var uv:*;
var p:*;
var i:*;
graphics.clear();
var lights:Set = _renderer.object.getSolidObjects(Directional);
var comulativeTextureChanged:Boolean = ((meshChanged) && ((_mesh == null)));
if (_mesh != null){
comulativeMeshChanged = ((((((((((_mesh.coordsChanged) || (_mesh.transformChanged))) || (_mesh.facesChanged))) || (_mesh.geometryChanged))) || (meshChanged))) || (_renderer.uvChanged));
if (comulativeMeshChanged){
meshUV = new Dictionary(true);
for each (v in _mesh.vertices) {
meshUV[v] = _renderer.localToUV(_renderer.object.canvasToLocal(v.canvasCoords));
};
};
for each (light in lights) {
if (((((comulativeMeshChanged) || (light.colorChanged))) || (light.transformChanged))){
direction = _renderer.localDirectionToUV(_renderer.object.canvasDirectionToLocal(light.canvasDirection));
direction.normalize();
if (direction.z < 0){
for each (f in _mesh.faces) {
var _local6 = graphics;
with (_local6) {
uv = meshUV[f._vertices[0]];
p = new Point((uv.x - ((uv.z * direction.x) / direction.z)), (uv.y - ((uv.z * direction.y) / direction.z)));
moveTo(p.x, p.y);
beginFill(light._color.toInt(), (-(direction.z) / 3));
i = 1;
while (i < f._vertices.length) {
uv = meshUV[f._vertices[i]];
p = new Point((uv.x - ((uv.z * direction.x) / direction.z)), (uv.y - ((uv.z * direction.y) / direction.z)));
lineTo(p.x, p.y);
i++;
};
endFill();
};
};
};
comulativeTextureChanged = true;
};
};
};
if (comulativeTextureChanged){
setTextureChanged();
};
}
public function get mesh():Mesh{
return (_mesh);
}
override function drop():void{
super.drop();
meshChanged = false;
}
}
}//package com.alternativagame.engine3d
Section 25
//SkinData (com.alternativagame.engine3d.SkinData)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
public class SkinData {
var skin:DisplayObject;
var boundBack:Number;
var num:uint;
var relations:Array;
var infront:Set;
var boundLeft:Number;
var boundMapLeft:int;
var behind:Set;
var boundMapRight:int;
var renderer:IRenderer;
var boundRight:Number;
var borders:Array;
var boundBottom:Number;
var boundFront:Number;
public var layer:int;// = -1
var boundMapBottom:int;
var points:Array;
var planeA:Number;
var length:uint;
var planeC:Number;
var planeD:Number;
var common:Array;
var planeB:Number;
var boundTop:Number;
var boundMapTop:int;
static const vertexHitRadius:Number = 5;
static const INFRONT:int = 1;
static const NOINTERSECTION:int = 0;
static const edgeHitHalfThickness:Number = 3;
static const BEHIND:int = -1;
static const vertexHitRadiusSquare:Number = 25;
public function SkinData(_arg1:IRenderer, _arg2:uint){
var _local3:uint;
super();
this.renderer = _arg1;
this.length = _arg2;
points = new Array();
common = new Array();
if (_arg2 > 1){
borders = new Array();
relations = new Array();
num = ((_arg2)>2) ? _arg2 : 1;
_local3 = 0;
while (_local3 < num) {
borders.push(new Border());
relations.push(new Array());
_local3++;
};
} else {
num = 0;
};
behind = new Set(true);
infront = new Set(true);
}
private function calculateBorders():void{
var _local1:Border;
var _local2:Point3D;
var _local3:Point3D;
var _local4:uint;
while (_local4 < num) {
_local1 = borders[_local4];
_local1.a = _local4;
_local1.b = (((_local4 + 1))==length) ? 0 : (_local4 + 1);
_local2 = points[_local1.a];
_local3 = points[_local1.b];
_local1.x = (_local3.x - _local2.x);
_local1.y = (_local3.y - _local2.y);
_local1.z = (_local3.z - _local2.z);
_local4++;
};
}
function calculate():void{
calculateBound();
if (length > 1){
calculateBorders();
calculatePlane();
};
}
function breakLinks():void{
var _local1:SkinData;
for each (_local1 in behind) {
_local1.infront.remove(this);
};
for each (_local1 in infront) {
_local1.behind.remove(this);
_local1.moveBack();
};
behind.clear();
infront.clear();
setLayer(0);
}
private function isBehind(_arg1:SkinData):Boolean{
var _local3:SkinData;
var _local2:Boolean;
for each (_local3 in behind) {
if ((((_local3 == _arg1)) || (_local3.isBehind(_arg1)))){
_local2 = true;
break;
};
};
return (_local2);
}
private function intersectionXY(_arg1:Point3D, _arg2:Point3D, _arg3:Point3D, _arg4:Point3D):Point{
var _local5:Number = (_arg2.x - _arg1.x);
var _local6:Number = (_arg3.x - _arg4.x);
var _local7:Number = (_arg3.x - _arg1.x);
var _local8:Number = (_arg2.y - _arg1.y);
var _local9:Number = (_arg3.y - _arg4.y);
var _local10:Number = (_arg3.y - _arg1.y);
var _local11:Number = ((_local5 * _local9) - (_local6 * _local8));
return (new Point((((_local7 * _local9) - (_local10 * _local6)) / _local11), (((_local5 * _local10) - (_local7 * _local8)) / _local11)));
}
function calculateInteractionCoords(_arg1:Point3D):void{
var _local2:Point3D;
var _local3:Border;
var _local4:uint;
var _local5:Number;
var _local6:Number;
if (length > 2){
if (boundContains(_arg1)){
_local4 = 0;
while (_local4 < num) {
_local2 = points[_local4];
_local3 = borders[_local4];
if (((_local3.x * (_arg1.y - _local2.y)) - (_local3.y * (_arg1.x - _local2.x))) > 0){
_arg1.z = NaN;
return;
};
_local4++;
};
_arg1.z = projectionZ(_arg1);
if (!renderer.checkInteraction(this, _arg1)){
_arg1.z = NaN;
};
} else {
_arg1.z = NaN;
};
} else {
if (length > 1){
if (!(((((((_arg1.x > (boundRight + edgeHitHalfThickness))) || ((_arg1.x < (boundLeft - edgeHitHalfThickness))))) || ((_arg1.y > (boundBottom + edgeHitHalfThickness))))) || ((_arg1.y < (boundTop - edgeHitHalfThickness))))){
_local2 = points[0];
_local3 = borders[0];
if ((Math.abs(((_local3.x * (_arg1.y - _local2.y)) - (_local3.y * (_arg1.x - _local2.x)))) / Math.sqrt(((_local3.x * _local3.x) + (_local3.y * _local3.y)))) <= edgeHitHalfThickness){
_arg1.z = projectionZ(_arg1);
if (!renderer.checkInteraction(this, _arg1)){
_arg1.z = NaN;
};
} else {
_arg1.z = NaN;
};
} else {
_arg1.z = NaN;
};
} else {
if (!(((((((_arg1.x > (boundRight + vertexHitRadius))) || ((_arg1.x < (boundLeft - vertexHitRadius))))) || ((_arg1.y > (boundBottom + vertexHitRadius))))) || ((_arg1.y < (boundTop - vertexHitRadius))))){
_local2 = points[0];
_local5 = (_arg1.x - _local2.x);
_local6 = (_arg1.y - _local2.y);
if (((_local5 * _local5) + (_local6 * _local6)) <= vertexHitRadiusSquare){
_arg1.z = _local2.z;
if (!renderer.checkInteraction(this, _arg1)){
_arg1.z = NaN;
};
} else {
_arg1.z = NaN;
};
} else {
_arg1.z = NaN;
};
};
};
}
private function isInfront(_arg1:SkinData):Boolean{
var _local3:SkinData;
var _local2:Boolean;
for each (_local3 in infront) {
if ((((_local3 == _arg1)) || (_local3.isInfront(_arg1)))){
_local2 = true;
break;
};
};
return (_local2);
}
private function calculatePlane():void{
var _local4:Border;
var _local5:Point3D;
var _local1:Border = borders[0];
var _local2:Point3D = points[0];
var _local3:Point3D = points[1];
if (length > 2){
_local4 = borders[1];
_local5 = points[2];
} else {
_local4 = new Border();
_local4.x = (_local3.y - _local2.y);
_local4.y = (_local2.x - _local3.x);
_local4.z = 0;
_local5 = new Point3D((_local3.x + _local4.x), (_local3.y + _local4.y), (_local3.z + _local4.z));
};
planeA = (((-(_local2.y) * _local4.z) + (_local3.y * (_local5.z - _local2.z))) - (_local5.y * _local1.z));
planeB = (((-(_local2.z) * _local4.x) + (_local3.z * (_local5.x - _local2.x))) - (_local5.z * _local1.x));
planeC = (((-(_local2.x) * _local4.y) + (_local3.x * (_local5.y - _local2.y))) - (_local5.x * _local1.y));
planeD = (((-(_local2.x) * ((_local3.y * _local5.z) - (_local5.y * _local3.z))) - (_local3.x * ((_local5.y * _local2.z) - (_local2.y * _local5.z)))) - (_local5.x * ((_local2.y * _local3.z) - (_local3.y * _local2.z))));
}
function linkInfront(_arg1:SkinData):void{
if (!isBehind(_arg1)){
infront.add(_arg1);
_arg1.behind.add(this);
_arg1.moveFront((layer + 1));
};
}
private function setLayer(_arg1:int):void{
renderer.object._view.updateArrangeMap(this, layer, _arg1);
layer = _arg1;
}
private function calculateBound():void{
var _local1:Point3D;
boundLeft = Number.MAX_VALUE;
boundRight = -(Number.MAX_VALUE);
boundTop = Number.MAX_VALUE;
boundBottom = -(Number.MAX_VALUE);
boundFront = -(Number.MAX_VALUE);
boundBack = Number.MAX_VALUE;
var _local2:uint;
while (_local2 < length) {
_local1 = points[_local2];
boundLeft = ((_local1.x)<boundLeft) ? _local1.x : boundLeft;
boundRight = ((_local1.x)>boundRight) ? _local1.x : boundRight;
boundTop = ((_local1.y)<boundTop) ? _local1.y : boundTop;
boundBottom = ((_local1.y)>boundBottom) ? _local1.y : boundBottom;
boundBack = ((_local1.z)<boundBack) ? _local1.z : boundBack;
boundFront = ((_local1.z)>boundFront) ? _local1.z : boundFront;
_local2++;
};
var _local3:Number = ((length)<3) ? ((length)==2) ? edgeHitHalfThickness : vertexHitRadius : 0;
boundMapLeft = Math.floor(((boundLeft - _local3) / View.boundMapSize));
boundMapRight = Math.floor(((boundRight + _local3) / View.boundMapSize));
boundMapTop = Math.floor(((boundTop - _local3) / View.boundMapSize));
boundMapBottom = Math.floor(((boundBottom + _local3) / View.boundMapSize));
}
function boundContains(_arg1:Point3D):Boolean{
return (!((((((((_arg1.x > boundRight)) || ((_arg1.x < boundLeft)))) || ((_arg1.y > boundBottom)))) || ((_arg1.y < boundTop)))));
}
function linkBehind(_arg1:SkinData):void{
if (!isInfront(_arg1)){
behind.add(_arg1);
_arg1.infront.add(this);
moveFront((_arg1.layer + 1));
};
}
private function moveFront(_arg1:int):void{
var _local2:SkinData;
if (_arg1 > layer){
setLayer(_arg1);
for each (_local2 in infront) {
_local2.moveFront((_arg1 + 1));
};
};
}
function compare(_arg1:SkinData):int{
var _local2:Number;
var _local3:Number;
var _local4:Boolean;
var _local5:uint;
var _local6:uint;
var _local7:Point3D;
var _local8:Point3D;
var _local9:Point3D;
var _local10:Point3D;
var _local11:Border;
var _local12:Number;
var _local13:Number;
var _local14:Number;
var _local15:Number;
var _local16:int;
var _local17:Point3D;
var _local18:Boolean;
var _local19:Boolean;
var _local20:Point;
var _local21:int;
var _local22:int;
var _local23:int;
var _local24:int;
var _local25:Boolean;
var _local26:Boolean;
var _local27:Boolean;
if (!(((((((_arg1.boundLeft > boundRight)) || ((_arg1.boundRight < boundLeft)))) || ((_arg1.boundTop > boundBottom)))) || ((_arg1.boundBottom < boundTop)))){
_local2 = 0;
_local3 = 0;
_local4 = false;
_local5 = 0;
while (_local5 < length) {
common[_local5] = false;
_local5++;
};
_local6 = 0;
while (_local6 < _arg1.length) {
_arg1.common[_local6] = false;
_local6++;
};
if (renderer.object == _arg1.renderer.object){
_local21 = -1;
_local22 = -1;
_local23 = -1;
_local24 = -1;
_local25 = false;
_local5 = 0;
while (_local5 < length) {
_local6 = 0;
while (_local6 < _arg1.length) {
if (points[_local5] == _arg1.points[_local6]){
if (_local21 < 0){
_local21 = _local5;
_local23 = _local6;
common[_local5] = true;
_arg1.common[_local6] = true;
break;
} else {
_local22 = _local5;
_local24 = _local6;
if ((((_local21 == 0)) && ((_local22 == (length - 1))))){
_local21 = (length - 1);
_local22 = 0;
};
if ((((_local23 == 0)) && ((_local24 == (_arg1.length - 1))))){
_local23 = (_arg1.length - 1);
_local24 = 0;
};
common[_local5] = true;
_arg1.common[_local6] = true;
_local25 = true;
break;
};
};
_local6++;
};
if (_local25){
break;
};
_local5++;
};
if (_local21 >= 0){
if (_local22 >= 0){
if ((((length == 2)) || ((_arg1.length == 2)))){
if (length == 2){
return (BEHIND);
};
return (INFRONT);
};
_local11 = borders[_local21];
_local7 = points[_local21];
_local9 = points[borders[_local22].b];
_local10 = _arg1.points[_arg1.borders[_local24].b];
_local14 = ((_local11.x * (_local9.y - _local7.y)) - (_local11.y * (_local9.x - _local7.x)));
_local15 = ((_local11.x * (_local10.y - _local7.y)) - (_local11.y * (_local10.x - _local7.x)));
if ((((((_local14 >= 0)) && ((_local15 <= 0)))) || ((((_local14 <= 0)) && ((_local15 >= 0)))))){
return (NOINTERSECTION);
};
} else {
if ((((length == 1)) || ((_arg1.length == 1)))){
if (length == 1){
return (BEHIND);
};
return (INFRONT);
};
if (length == 2){
if (_arg1.length == 2){
return (NOINTERSECTION);
};
_local7 = _arg1.points[_local23];
_local8 = ((_local23)>0) ? _arg1.points[(_local23 - 1)] : _arg1.points[(_arg1.length - 1)];
_local9 = ((_local23)<(_arg1.length - 1)) ? _arg1.points[(_local23 + 1)] : _arg1.points[0];
_local10 = ((_local21)==0) ? points[1] : points[0];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
return (NOINTERSECTION);
};
} else {
if (_arg1.length == 2){
_local7 = points[_local21];
_local8 = ((_local21)>0) ? points[(_local21 - 1)] : points[(length - 1)];
_local9 = ((_local21)<(length - 1)) ? points[(_local21 + 1)] : points[0];
_local10 = ((_local23)==0) ? _arg1.points[1] : _arg1.points[0];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
return (NOINTERSECTION);
};
} else {
_local26 = false;
_local27 = false;
_local7 = points[_local21];
_local8 = ((_local21)>0) ? points[(_local21 - 1)] : points[(length - 1)];
_local9 = ((_local21)<(length - 1)) ? points[(_local21 + 1)] : points[0];
_local10 = ((_local23)>0) ? _arg1.points[(_local23 - 1)] : _arg1.points[(_arg1.length - 1)];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
_local10 = ((_local23)<(_arg1.length - 1)) ? _arg1.points[(_local23 + 1)] : _arg1.points[0];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
_local26 = true;
};
};
_local7 = _arg1.points[_local23];
_local8 = ((_local23)>0) ? _arg1.points[(_local23 - 1)] : _arg1.points[(_arg1.length - 1)];
_local9 = ((_local23)<(_arg1.length - 1)) ? _arg1.points[(_local23 + 1)] : _arg1.points[0];
_local10 = ((_local21)>0) ? points[(_local21 - 1)] : points[(length - 1)];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
_local10 = ((_local21)<(length - 1)) ? points[(_local21 + 1)] : points[0];
_local13 = (((_local8.x - _local7.x) * (_local10.y - _local7.y)) - ((_local8.y - _local7.y) * (_local10.x - _local7.x)));
_local14 = (((_local9.x - _local7.x) * (_local10.y - _local7.y)) - ((_local9.y - _local7.y) * (_local10.x - _local7.x)));
if ((((_local13 <= 0)) || ((_local14 >= 0)))){
_local27 = true;
};
};
if (((_local26) && (_local27))){
return (NOINTERSECTION);
};
};
};
};
};
};
_local16 = NOINTERSECTION;
if (boundBack >= _arg1.boundFront){
_local16 = BEHIND;
} else {
if (_arg1.boundBack >= boundFront){
_local16 = INFRONT;
};
};
_local5 = 0;
while (_local5 < num) {
_local7 = points[_local5];
_local11 = borders[_local5];
_local6 = 0;
while (_local6 < _arg1.length) {
_local8 = _arg1.points[_local6];
relations[_local5][_local6] = ((_local11.x * (_local8.y - _local7.y)) - (_local11.y * (_local8.x - _local7.x)));
_local6++;
};
if (_arg1.length > 2){
relations[_local5][_arg1.length] = relations[_local5][0];
};
_local5++;
};
_local5 = 0;
while (_local5 < _arg1.num) {
_local7 = _arg1.points[_local5];
_local11 = _arg1.borders[_local5];
_local6 = 0;
while (_local6 < length) {
_local8 = points[_local6];
_arg1.relations[_local5][_local6] = ((_local11.x * (_local8.y - _local7.y)) - (_local11.y * (_local8.x - _local7.x)));
_local6++;
};
if (length > 2){
_arg1.relations[_local5][length] = _arg1.relations[_local5][0];
};
_local5++;
};
_local19 = true;
_local5 = 0;
while (_local5 < length) {
_local17 = points[_local5];
if (_arg1.boundContains(_local17)){
if (!common[_local5]){
_local18 = true;
_local6 = 0;
while (_local6 < _arg1.num) {
if (_arg1.relations[_local6][_local5] > 0){
_local18 = false;
_local19 = false;
break;
} else {
if ((((_arg1.length == 2)) && ((_arg1.relations[_local6][_local5] < 0)))){
_local18 = false;
_local19 = false;
break;
};
};
_local6++;
};
if (_local18){
if (_arg1.length > 1){
_local2 = (_local2 + _local17.z);
_local3 = (_local3 + _arg1.projectionZ(_local17));
_local4 = true;
if (_local16 != NOINTERSECTION){
return (_local16);
};
} else {
return (((_local17.z)>_arg1.points[0].z) ? BEHIND : INFRONT);
};
};
};
} else {
_local19 = false;
};
_local5++;
};
if (_local19){
return (((_local2)>_local3) ? BEHIND : INFRONT);
};
_local19 = true;
_local5 = 0;
while (_local5 < _arg1.length) {
_local17 = _arg1.points[_local5];
if (boundContains(_local17)){
if (!_arg1.common[_local5]){
_local18 = true;
_local6 = 0;
while (_local6 < num) {
if (relations[_local6][_local5] > 0){
_local18 = false;
_local19 = false;
break;
} else {
if ((((length == 2)) && ((relations[_local6][_local5] < 0)))){
_local18 = false;
_local19 = false;
break;
};
};
_local6++;
};
if (_local18){
if (length > 1){
_local2 = (_local2 + projectionZ(_local17));
_local3 = (_local3 + _local17.z);
_local4 = true;
if (_local16 != NOINTERSECTION){
return (_local16);
};
} else {
return (((_local17.z)<points[0].z) ? BEHIND : INFRONT);
};
};
};
} else {
_local19 = false;
};
_local5++;
};
if (_local19){
return (((_local2)>_local3) ? BEHIND : INFRONT);
};
_local5 = 0;
while (_local5 < num) {
_local6 = 0;
while (_local6 < _arg1.num) {
_local12 = relations[_local5][_local6];
_local13 = relations[_local5][(_local6 + 1)];
_local14 = _arg1.relations[_local6][_local5];
_local15 = _arg1.relations[_local6][(_local5 + 1)];
if ((((((((_local12 > 0)) && ((_local13 < 0)))) || ((((_local12 < 0)) && ((_local13 > 0)))))) && ((((((_local14 > 0)) && ((_local15 < 0)))) || ((((_local14 < 0)) && ((_local15 > 0)))))))){
_local7 = points[_local5];
_local8 = points[borders[_local5].b];
_local9 = _arg1.points[_local6];
_local10 = _arg1.points[_arg1.borders[_local6].b];
_local20 = intersectionXY(_local7, _local8, _local9, _local10);
_local2 = (_local2 + (_local7.z + ((_local8.z - _local7.z) * _local20.x)));
_local3 = (_local3 + (_local9.z + ((_local10.z - _local9.z) * _local20.y)));
_local4 = true;
if (_local16 != NOINTERSECTION){
return (_local16);
};
};
_local6++;
};
_local5++;
};
if (_local4){
return (((_local2)>_local3) ? BEHIND : INFRONT);
};
};
return (NOINTERSECTION);
}
private function moveBack():void{
var _local2:SkinData;
var _local1:int;
for each (_local2 in behind) {
if ((_local2.layer + 1) > _local1){
_local1 = (_local2.layer + 1);
};
};
if (_local1 < layer){
setLayer(_local1);
for each (_local2 in infront) {
_local2.moveBack();
};
};
}
private function projectionZ(_arg1:Point3D):Number{
return ((-((((planeA * _arg1.x) + (planeB * _arg1.y)) + planeD)) / planeC));
}
}
}//package com.alternativagame.engine3d
class Border {
public var a:uint;
public var x:Number;
public var b:uint;
public var y:Number;
public var z:Number;
private function Border(){
}
}
Section 26
//SurfaceRenderer (com.alternativagame.engine3d.SurfaceRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.utils.*;
import com.alternativagame.utility.*;
public class SurfaceRenderer implements ISurfaceRenderer {
protected var datas:Dictionary;
var nameChanged:Boolean;// = true
var facesChanged:Boolean;// = false
protected var _faces:Set;
protected var _object:Mesh;
var visibleChanged:Boolean;// = false
var objectChanged:Boolean;// = false
protected var _name:String;
private static var num:uint = 0;
public function SurfaceRenderer(){
_faces = new Set(true);
datas = new Dictionary(true);
_name = defaultName();
}
public function removeFace(_arg1:Face):void{
if (_faces.has(_arg1)){
_faces.remove(_arg1);
facesChanged = true;
};
}
public function checkInteraction(_arg1:SkinData, _arg2:Point3D):Boolean{
return (true);
}
public function toString():String{
return ((((("[" + ObjectUtility.getClassName(this)) + " ") + _name) + "]"));
}
public function interaction(_arg1:uint, _arg2:SkinData, _arg3:Point3D, _arg4:Boolean, _arg5:Boolean, _arg6:Boolean, _arg7:Boolean):void{
}
public function get name():String{
return (_name);
}
public function render():void{
}
public function addFace(_arg1:Face):void{
if (!_faces.has(_arg1)){
_faces.add(_arg1);
facesChanged = true;
};
}
public function set name(_arg1:String):void{
_name = _arg1;
nameChanged = true;
}
public function get faces():Set{
return (_faces);
}
public function setObject(_arg1:Object3D):void{
if (_object != _arg1){
clear();
if ((((_arg1 == null)) || ((_arg1 is Mesh)))){
_object = Mesh(_arg1);
objectChanged = true;
} else {
throw (new Error("Surface renderer must be added to Mesh object only"));
};
};
}
protected function updateSkinDatas():void{
var _local1:Dictionary;
var _local2:Face;
var _local3:SkinData;
if (((((((_object.facesChanged) || (_object.viewChanged))) || (facesChanged))) || (objectChanged))){
updateFaces();
_local1 = new Dictionary(true);
for each (_local2 in _faces) {
if (datas[_local2] == undefined){
_local1[_local2] = createSkinData(_local2);
} else {
_local1[_local2] = datas[_local2];
delete datas[_local2];
};
};
for each (_local3 in datas) {
_object._view.removeSkin(_local3);
};
datas = _local1;
};
}
public function get object():Object3D{
return (_object);
}
protected function updateFaceVisible(_arg1:Face):void{
if (((((((_arg1.transformChanged) || (_arg1.meshChanged))) || (_object.viewChanged))) || (objectChanged))){
_arg1.calculateVisible();
if (_arg1.visibleChanged){
if (_arg1.visible){
_object._view.addSkin(datas[_arg1]);
} else {
_object._view.removeSkin(datas[_arg1]);
};
visibleChanged = true;
};
};
}
public function clear():void{
var _local1:SkinData;
if (((!((_object == null))) && (!((_object._view == null))))){
for each (_local1 in datas) {
_object._view.removeSkin(_local1);
};
};
datas = new Dictionary(true);
}
protected function getFaceByData(_arg1:SkinData):Face{
var _local2:*;
for (_local2 in datas) {
if (datas[_local2] == _arg1){
return (_local2);
};
};
return (null);
}
protected function createSkinData(_arg1:Face):SkinData{
return (null);
}
public function clone():IRenderer{
var _local1:SurfaceRenderer = new SurfaceRenderer();
return (_local1);
}
protected function updateFaces():void{
var _local1:Face;
if (((!((_object == null))) && (((_object.facesChanged) || (objectChanged))))){
for each (_local1 in _faces.clone()) {
if (!_object.faces.has(_local1)){
removeFace(_local1);
};
};
};
}
public function drop():void{
nameChanged = false;
objectChanged = false;
facesChanged = false;
visibleChanged = false;
}
protected function defaultName():String{
num++;
return (("surfaceRenderer" + num));
}
public function set faces(_arg1:Set):void{
_faces = _arg1.clone();
facesChanged = true;
}
}
}//package com.alternativagame.engine3d
Section 27
//TextureData (com.alternativagame.engine3d.TextureData)
package com.alternativagame.engine3d {
import flash.display.*;
public class TextureData {
var bitmapData:BitmapData;
var resolution:Number;
public function TextureData(_arg1:BitmapData, _arg2:Number=1){
this.bitmapData = _arg1;
this.resolution = _arg2;
}
public function toString():String{
return ((((((("[TextureData " + bitmapData.width) + "x") + bitmapData.height) + " ") + resolution.toFixed(1)) + "cm/px]"));
}
}
}//package com.alternativagame.engine3d
Section 28
//TextureObject (com.alternativagame.engine3d.TextureObject)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.display.*;
public class TextureObject extends Shape {
var textureChanged:Boolean;// = true
protected var _renderer:TextureRenderer;
var coordsChanged:Boolean;// = true
private var _coords:Point3D;
public function TextureObject(){
_coords = new Point3D();
super();
}
public function get renderer():TextureRenderer{
return (_renderer);
}
function setRenderer(_arg1:TextureRenderer):void{
_renderer = _arg1;
}
override public function set alpha(_arg1:Number):void{
super.alpha = _arg1;
setRendererTextureChanged();
}
function render():void{
var _local1:Point3D;
if (((coordsChanged) || (_renderer.uvChanged))){
_local1 = _renderer.localToUV(_coords);
super.x = _local1.x;
super.y = _local1.y;
};
}
protected function setTextureChanged():void{
setRendererTextureChanged();
textureChanged = true;
}
public function clone():TextureObject{
var _local1:TextureObject = new TextureObject();
_local1.alpha = alpha;
_local1.coords = _coords.clone();
return (_local1);
}
public function get coords():Point3D{
return (_coords);
}
function drop():void{
textureChanged = false;
coordsChanged = false;
}
override public function set x(_arg1:Number):void{
_coords.x = _arg1;
setCoordsChanged();
}
override public function set y(_arg1:Number):void{
_coords.y = _arg1;
setCoordsChanged();
}
private function setCoordsChanged():void{
setRendererTextureChanged();
coordsChanged = true;
}
override public function get x():Number{
return (_coords.x);
}
override public function get y():Number{
return (_coords.y);
}
public function get z():Number{
return (_coords.z);
}
public function set z(_arg1:Number):void{
_coords.z = _arg1;
setCoordsChanged();
}
public function set coords(_arg1:Point3D):void{
_coords = _arg1;
setCoordsChanged();
}
private function setRendererTextureChanged():void{
if (_renderer != null){
_renderer.mergedTextureChanged = true;
};
}
}
}//package com.alternativagame.engine3d
Section 29
//TextureRenderer (com.alternativagame.engine3d.TextureRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import com.alternativagame.utility.*;
import com.alternativagame.engine3d.skin.*;
import flash.filters.*;
public class TextureRenderer extends UVRenderer {
private var lightEdgesContainer:Sprite;
private var mipmap:uint;// = 1
private var lightContainer:Sprite;
var mipmapChanged:Boolean;// = true
private var light:BitmapData;
var textureChanged:Boolean;// = false
private var texture:BitmapData;
private var specularPrecalc1:Number;// = -0.5
private var specularPrecalc2:Number;
var bumpChanged:Boolean;// = false
private var globalLights:Set;
private var lightFacesContainer:Sprite;
private var _specular:Number;// = 1
private var mipmapBumpResolution:int;// = 2
private var bump:BitmapData;
private var cacheTexture:BitmapData;
private var mipmapLightResolution:int;// = 6
private var bumpLayer:Sprite;
private var specularOffset:Number;
var lightChanged:Boolean;// = false
private var bumpMap:BitmapData;
private var pointLights:Set;
private var mergedTexture:BitmapData;
private var dynamicLayer:Sprite;
private var lightFaces:Dictionary;
private var lightLayer:Sprite;
private var lightEdges:Dictionary;
var mergedTextureChanged:Boolean;// = false
var specularChanged:Boolean;// = true
private var textureLayer:Sprite;
private var lightGI:Sprite;
private var mipmapTextureResolution:int;// = 1
public static const DYNAMIC_LAYER:uint = 3;
private static const lightGISize:uint = 50;
private static const lightBlur:uint = 50;
public static const LIGHT_LAYER:uint = 1;
public static const BUMP_LAYER:uint = 2;
public static const TEXTURE_LAYER:uint = 0;
private static const highestResolution:int = 1;
private static const lowestResolution:int = 50;
private static var num:uint = 0;
static var bumpEnabledChanged:Boolean = true;
static var textureResolutionChanged:Boolean = true;
private static var _bumpResolution:int = 2;
private static var _lightResolution:int = 6;
static var smoothChanged:Boolean = true;
private static var _textureResolution:int = 1;
private static var realBumpResolution:int = 2;
private static var _smooth:Boolean = true;
static var bumpResolutionChanged:Boolean = true;
private static var realLightResolution:int = 6;
private static var _bumpEnabled:Boolean = false;
static var lightResolutionChanged:Boolean = true;
public function TextureRenderer(_arg1:Number=3){
specularPrecalc2 = (1 / Math.sqrt((2 * Math.PI)));
specularOffset = (Math.exp(specularPrecalc1) * specularPrecalc2);
super();
this.specular = _arg1;
textureLayer = new Sprite();
bumpLayer = new Sprite();
lightContainer = new Sprite();
lightEdgesContainer = new Sprite();
lightFacesContainer = new Sprite();
lightGI = new Sprite();
lightGI.blendMode = BlendMode.MULTIPLY;
lightLayer = new Sprite();
lightContainer.addChild(lightEdgesContainer);
lightContainer.addChild(lightFacesContainer);
lightContainer.addChild(lightGI);
lightContainer.addChild(lightLayer);
lightEdges = new Dictionary(true);
lightFaces = new Dictionary(true);
dynamicLayer = new Sprite();
}
override protected function defaultName():String{
num++;
return (("textureRenderer" + num));
}
private function updateMergedTexture():void{
var _local1:Number;
if (((mergedTextureChanged) || (objectChanged))){
updateTexture();
updateLight();
if (((((textureChanged) || (lightChanged))) || (bumpChanged))){
cacheTexture.copyPixels(texture, texture.rect, new Point());
_local1 = (mipmapLightResolution / mipmapTextureResolution);
cacheTexture.draw(light, new Matrix(_local1, 0, 0, _local1, (1 - _local1), (1 - _local1)), null, BlendMode.HARDLIGHT, null, true);
if (_bumpEnabled){
_local1 = (mipmapBumpResolution / mipmapTextureResolution);
cacheTexture.draw(bump, new Matrix(_local1, 0, 0, _local1, (1 - _local1), (1 - _local1)), null, BlendMode.ADD, null, true);
};
};
mergedTexture.copyPixels(cacheTexture, cacheTexture.rect, new Point());
if (dynamicLayer.numChildren > 0){
mergedTexture.draw(dynamicLayer, new Matrix((1 / mipmapTextureResolution), 0, 0, (1 / mipmapTextureResolution), 1, 1), null, null, null, true);
};
};
}
public function getTextureObjects(_arg1:uint=0):Array{
var _local3:uint;
var _local4:Array;
var _local5:uint;
var _local2:Sprite = getLayer(_arg1);
if (_local2 != null){
_local3 = _local2.numChildren;
if (_local3 > 0){
_local4 = new Array();
_local5 = 0;
while (_local5 < _local3) {
_local4.push(_local2.getChildAt(_local5));
_local5++;
};
return (_local4);
};
};
return (null);
}
public function get specular():Number{
return (_specular);
}
public function set specular(_arg1:Number):void{
_specular = _arg1;
var _local2:Number = (1 / _specular);
specularPrecalc1 = (-1 / ((2 * _local2) * _local2));
specularPrecalc2 = (1 / (_local2 * Math.sqrt((2 * Math.PI))));
specularOffset = (Math.exp(specularPrecalc1) * specularPrecalc2);
specularChanged = true;
}
override public function drop():void{
var _local1:uint;
var _local2:TextureObject;
super.drop();
specularChanged = false;
smoothChanged = false;
textureResolutionChanged = false;
lightResolutionChanged = false;
bumpResolutionChanged = false;
bumpEnabledChanged = false;
mipmapChanged = false;
mergedTextureChanged = false;
textureChanged = false;
lightChanged = false;
bumpChanged = false;
var _local3:uint = textureLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
TextureObject(textureLayer.getChildAt(_local1)).drop();
_local1++;
};
_local3 = lightLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
TextureObject(lightLayer.getChildAt(_local1)).drop();
_local1++;
};
_local3 = bumpLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
TextureObject(bumpLayer.getChildAt(_local1)).drop();
_local1++;
};
_local3 = dynamicLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
TextureObject(dynamicLayer.getChildAt(_local1)).drop();
_local1++;
};
}
private function updateTexture():void{
if (textureChanged){
texture.fillRect(texture.rect, 0x7F7F7F);
texture.draw(textureLayer, new Matrix((1 / mipmapTextureResolution), 0, 0, (1 / mipmapTextureResolution), 1, 1), null, null, null, true);
};
}
private function updateBump():void{
var _local1:Matrix3D;
var _local2:Matrix3D;
var _local3:Point3D;
var _local4:Point3D;
var _local5:Point3D;
var _local6:Point3D;
var _local7:Number;
var _local8:Number;
var _local9:Number;
var _local10:Light;
if (((((lightChanged) || (bumpChanged))) || (objectChanged))){
if (_bumpEnabled){
_local1 = uvMatrix.clone();
_local1.translateLocal((uvWidth / 2), (uvHeight / 2), 0);
_local1.combine(_object.transformMatrix);
_local2 = Matrix3D.inverseMatrix(_local1);
_local2.d = 0;
_local2.h = 0;
_local2.l = 0;
_local3 = new Point3D(_local1.d, _local1.h, _local1.l);
_local4 = new Point3D(_local1.c, _local1.g, _local1.k);
_local5 = new Point3D(_local1.a, _local1.e, _local1.i);
bump.fillRect(bump.rect, 0);
if (bumpLayer.numChildren > 0){
for each (_local10 in globalLights) {
if ((_local10 is Directional)){
_local7 = _local10.getStrength(_local3, _local4);
if (_local7 > 0){
_local6 = new Point3D(-(_local10.transformMatrix.b), -(_local10.transformMatrix.f), -(_local10.transformMatrix.j));
_local6.transform(_local2);
_local8 = (gaussianShading(_local6.z) / 5);
_local9 = (180 + MathUtility.toDegree(Math.atan2(_local6.y, _local6.x)));
bump.applyFilter(bumpMap, bumpMap.rect, new Point(0, 0), new BevelFilter(1, _local9, _local10._color.toInt(), 1, 0, 0, 1, 1, (((1 - _local8) * _local7) * 5), 1));
};
};
};
};
};
};
}
public function getTextureObject(_arg1:uint, _arg2:uint=0):TextureObject{
var _local3:Sprite = getLayer(_arg2);
if (_local3 != null){
return (TextureObject(_local3.getChildAt(_arg1)));
};
return (null);
}
public function addTextureObject(_arg1:TextureObject, _arg2:int=-1, _arg3:uint=0):void{
if (((!((_arg1 == null))) && (((!((_arg1.renderer == this))) || (!(getLayer(_arg3).contains(_arg1))))))){
if (_arg1.renderer != null){
_arg1.renderer.removeTextureObject(_arg1);
};
switch (_arg3){
case TEXTURE_LAYER:
if (_arg2 < 0){
textureLayer.addChild(_arg1);
} else {
textureLayer.addChildAt(_arg1, _arg2);
};
textureChanged = true;
break;
case LIGHT_LAYER:
if (_arg2 < 0){
lightLayer.addChild(_arg1);
} else {
lightLayer.addChildAt(_arg1, _arg2);
};
lightChanged = true;
break;
case BUMP_LAYER:
if (_arg2 < 0){
bumpLayer.addChild(_arg1);
} else {
bumpLayer.addChildAt(_arg1, _arg2);
};
break;
case DYNAMIC_LAYER:
if (_arg2 < 0){
dynamicLayer.addChild(_arg1);
} else {
dynamicLayer.addChildAt(_arg1, _arg2);
};
break;
};
mergedTextureChanged = true;
_arg1.setRenderer(this);
};
}
private function updateTextureObjects():void{
var _local1:uint;
var _local2:TextureObject;
var _local3:uint = textureLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
_local2 = TextureObject(textureLayer.getChildAt(_local1));
_local2.render();
textureChanged = ((textureChanged) || (_local2.textureChanged));
_local1++;
};
_local3 = lightLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
_local2 = TextureObject(lightLayer.getChildAt(_local1));
_local2.render();
lightChanged = ((lightChanged) || (_local2.textureChanged));
_local1++;
};
_local3 = bumpLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
_local2 = TextureObject(bumpLayer.getChildAt(_local1));
_local2.render();
bumpChanged = ((bumpChanged) || (_local2.textureChanged));
_local1++;
};
_local3 = dynamicLayer.numChildren;
_local1 = 0;
while (_local1 < _local3) {
_local2 = TextureObject(dynamicLayer.getChildAt(_local1));
_local2.render();
_local1++;
};
}
public function getTextureObjectLayer(_arg1:TextureObject):int{
if (((!((_arg1 == null))) && ((_arg1.renderer == this)))){
if (textureLayer.contains(_arg1)){
return (TEXTURE_LAYER);
};
if (lightLayer.contains(_arg1)){
return (LIGHT_LAYER);
};
if (bumpLayer.contains(_arg1)){
return (BUMP_LAYER);
};
if (dynamicLayer.contains(_arg1)){
return (DYNAMIC_LAYER);
};
};
return (-1);
}
function gaussianShading(_arg1:Number):Number{
return (((Math.exp((((1 - _arg1) * (1 - _arg1)) * specularPrecalc1)) * specularPrecalc2) - specularOffset));
}
private function updateMipmap():void{
var _local1:int;
if (_object._view.zoomChanged){
_local1 = ((_object._view.zoom)>=1) ? 1 : Math.round((1 / _object._view.zoom));
if (mipmap != _local1){
mipmap = _local1;
mipmapChanged = true;
};
};
if (((((((mipmapChanged) || (textureResolutionChanged))) || (lightResolutionChanged))) || (bumpResolutionChanged))){
mipmapTextureResolution = (_textureResolution * mipmap);
mipmapLightResolution = (realLightResolution * mipmap);
mipmapBumpResolution = (realBumpResolution * mipmap);
};
}
public function getTextureObjectIndex(_arg1:TextureObject):int{
var _local2:int = getTextureObjectLayer(_arg1);
if (_local2 >= 0){
return (getLayer(_local2).getChildIndex(_arg1));
};
return (-1);
}
override public function render():void{
var face:Face;
var data:SkinData;
var skin:TextureSkin;
var textureMatrixChanged:Boolean;
var geometryChanged:Boolean;
var uvs:Array;
var length:uint;
var i:uint;
var v:*;
var i2:*;
var edge:*;
var joined:*;
var j:*;
var j2:*;
updateSkinDatas();
calculateUVCoords();
updateMipmap();
updateTextureSize();
updateTextureObjects();
updateLightSize();
updateLightElements();
updateBumpSize();
updateBumpMap();
updateLights();
for each (face in _faces) {
updateFaceVisible(face);
if (face.visible){
data = datas[face];
skin = TextureSkin(data.skin);
textureMatrixChanged = ((((((((((((face.visibleChanged) || (face.meshChanged))) || (_object.viewChanged))) || (uvChanged))) || (mipmapChanged))) || (textureResolutionChanged))) || (objectChanged));
geometryChanged = ((((((((((face.coordsChanged) || (face.transformChanged))) || (face.visibleChanged))) || (face.meshChanged))) || (_object.viewChanged))) || (objectChanged));
if (textureMatrixChanged){
skin.calculateMatrix(uv[face], mipmapTextureResolution);
};
if (geometryChanged){
_object._view.changeSkin(data);
};
if (((((geometryChanged) || (textureMatrixChanged))) || (smoothChanged))){
skin.draw(data.points, mergedTexture, _smooth);
};
};
calculateFaceGlobalLight(face, gaussianShading);
if (((((((((mipmapChanged) || (textureResolutionChanged))) || (lightResolutionChanged))) || (uvChanged))) || (objectChanged))){
uvs = uv[face];
length = face.length;
var _local4 = Shape(lightEdges[face]).graphics;
with (_local4) {
clear();
lineStyle((((2 * lightBlur) / mipmapLightResolution) + 2), 0, 1, false, LineScaleMode.NONE);
i = 0;
while (i < length) {
v = Vertex(face._vertices[i]);
i2 = ((i)<(length - 1)) ? (i + 1) : 0;
edge = true;
for each (joined in v.faces) {
if (((!((joined == face))) && (_faces.has(joined)))){
j = joined._vertices.indexOf(v);
j2 = ((j)>0) ? (j - 1) : (joined.length - 1);
if (face._vertices[i2] == joined._vertices[j2]){
edge = false;
break;
};
};
};
if (edge){
moveTo(uvs[i].x, uvs[i].y);
lineTo(uvs[i2].x, uvs[i2].y);
};
i++;
};
};
if (((uvChanged) || (objectChanged))){
_local4 = Shape(lightFaces[face]).graphics;
with (_local4) {
clear();
beginFill(0);
moveTo(uvs[0].x, uvs[0].y);
i = 1;
while (i < length) {
lineTo(uvs[i].x, uvs[i].y);
i++;
};
endFill();
};
};
lightChanged = true;
mergedTextureChanged = true;
};
if (((((face.lightColorChanged) || (uvChanged))) || (objectChanged))){
Shape(lightFaces[face]).transform.colorTransform = new ColorTransform(0, 0, 0, 1, face.lightColor.red, face.lightColor.green, face.lightColor.blue);
Shape(lightEdges[face]).transform.colorTransform = new ColorTransform(0, 0, 0, 1, face.lightColor.red, face.lightColor.green, face.lightColor.blue);
lightChanged = true;
mergedTextureChanged = true;
};
};
updateGI();
updateBump();
updateMergedTexture();
}
private function getLayer(_arg1:uint):Sprite{
switch (_arg1){
case TEXTURE_LAYER:
return (textureLayer);
case LIGHT_LAYER:
return (lightLayer);
case BUMP_LAYER:
return (bumpLayer);
case DYNAMIC_LAYER:
return (dynamicLayer);
default:
return (null);
};
}
public function setTextureObjectIndex(_arg1:TextureObject, _arg2:uint):void{
var _local3:Sprite = getLayer(getTextureObjectLayer(_arg1));
if (_local3 != null){
_local3.setChildIndex(_arg1, _arg2);
};
}
private function updateTextureSize():void{
var _local1:uint;
var _local2:uint;
if (((((uvChanged) || (mipmapChanged))) || (textureResolutionChanged))){
_local1 = (Math.ceil((uvWidth / mipmapTextureResolution)) + 2);
_local2 = (Math.ceil((uvHeight / mipmapTextureResolution)) + 2);
_local1 = (_local1 + (((_local1 % 2))==0) ? 1 : 0);
_local2 = (_local2 + (((_local2 % 2))==0) ? 1 : 0);
if (mergedTexture != null){
if (((!((mergedTexture.width == _local1))) || (!((mergedTexture.height == _local2))))){
if (mergedTexture != null){
mergedTexture.dispose();
mergedTexture = null;
};
if (cacheTexture != null){
cacheTexture.dispose();
cacheTexture = null;
};
if (texture != null){
texture.dispose();
texture = null;
};
mergedTexture = new BitmapData(_local1, _local2, false, 0);
cacheTexture = new BitmapData(_local1, _local2, false, 0);
texture = new BitmapData(_local1, _local2, false, 0);
mergedTextureChanged = true;
textureChanged = true;
};
} else {
mergedTexture = new BitmapData(_local1, _local2, false, 0);
cacheTexture = new BitmapData(_local1, _local2, false, 0);
texture = new BitmapData(_local1, _local2, false, 0);
mergedTextureChanged = true;
textureChanged = true;
};
};
}
private function updateBumpMap():void{
if (bumpChanged){
if (_bumpEnabled){
bumpMap.fillRect(bumpMap.rect, 0);
if (bumpLayer.numChildren > 0){
bumpMap.draw(bumpLayer, new Matrix((1 / mipmapBumpResolution), 0, 0, (1 / mipmapBumpResolution), 1, 1), null, null, null, true);
bumpMap.copyChannel(bumpMap, bumpMap.rect, new Point(), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
bumpMap.colorTransform(bumpMap.rect, new ColorTransform(0, 0, 0, 1));
};
};
};
}
private function calculateFaceGlobalLight(_arg1:Face, _arg2:Function=null):void{
var _local3:Light;
var _local4:Boolean;
if (((((((_arg1.coordsChanged) || (_arg1.transformChanged))) || (_arg1.meshChanged))) || (_object.viewChanged))){
_arg1.calculateCanvasCenter();
if (((((_arg1.transformChanged) || (_arg1.meshChanged))) || (_object.viewChanged))){
_arg1.calculateCanvasNormal();
};
};
for each (_local3 in globalLights) {
_local4 = ((((((((((((((((_arg1.meshChanged) || (_arg1.visibleChanged))) || (_object.viewChanged))) || (_object.solidParentChanged))) || (_local3.enabledChanged))) || (_local3.solidParentChanged))) || (_local3.viewChanged))) || (_local3.parentChanged))) || (specularChanged));
if ((_local3 is Directional)){
_local4 = ((_local4) || (((_arg1.transformChanged) || (_local3.transformChanged))));
};
if (_local4){
_arg1.calculateLightStrength(_local3, _arg2);
};
if (_local3.colorChanged){
_arg1.dropLightColorCalculated();
};
};
_arg1.calculateLightColor();
}
private function updateLights():void{
var _local1:Set;
var _local2:Set;
var _local3:Light;
var _local4:Face;
if (((((((_object.viewChanged) || (_object.solidParentChanged))) || (_object.solidParent.solidObjectsChanged))) || (objectChanged))){
_local1 = _object.getSolidObjects(Ambient);
_local1.concat(_object.getSolidObjects(Directional));
_local2 = _object.getSolidObjects(Omni);
for each (_local3 in globalLights) {
if (!_local1.has(_local3)){
for each (_local4 in _faces) {
_local4.removeLight(_local3);
};
};
};
globalLights = _local1;
pointLights = _local2;
};
}
override public function clone():IRenderer{
var _local1:TextureRenderer = new TextureRenderer(_specular);
return (_local1);
}
override protected function createSkinData(_arg1:Face):SkinData{
var _local2:Array = _arg1._vertices;
var _local3:uint = _local2.length;
var _local4:SkinData = new SkinData(this, _local3);
var _local5:uint;
while (_local5 < _local3) {
_local4.points[_local5] = _local2[_local5].canvasCoords;
_local5++;
};
_local4.skin = new TextureSkin();
return (_local4);
}
private function updateLightElements():void{
var _local1:Dictionary;
var _local2:Dictionary;
var _local3:Shape;
var _local4:Face;
if (((((((_object.facesChanged) || (_object.viewChanged))) || (facesChanged))) || (objectChanged))){
_local1 = new Dictionary(true);
_local2 = new Dictionary(true);
for each (_local4 in _faces) {
if ((((lightEdges[_local4] == undefined)) || ((lightFaces[_local4] == undefined)))){
_local3 = new Shape();
lightEdgesContainer.addChild(_local3);
_local1[_local4] = _local3;
_local3 = new Shape();
lightFacesContainer.addChild(_local3);
_local2[_local4] = _local3;
} else {
_local1[_local4] = lightEdges[_local4];
_local2[_local4] = lightFaces[_local4];
delete lightEdges[_local4];
delete lightFaces[_local4];
};
};
for each (_local3 in lightEdges) {
lightEdgesContainer.removeChild(_local3);
};
for each (_local3 in lightFaces) {
lightFacesContainer.removeChild(_local3);
};
lightEdges = _local1;
lightFaces = _local2;
};
}
public function removeTextureObject(_arg1:TextureObject):void{
if (((!((_arg1 == null))) && ((_arg1.renderer == this)))){
if (textureLayer.contains(_arg1)){
textureLayer.removeChild(_arg1);
textureChanged = true;
} else {
if (lightLayer.contains(_arg1)){
lightLayer.removeChild(_arg1);
lightChanged = true;
} else {
if (bumpLayer.contains(_arg1)){
bumpLayer.removeChild(_arg1);
bumpChanged = true;
} else {
if (dynamicLayer.contains(_arg1)){
dynamicLayer.removeChild(_arg1);
};
};
};
};
mergedTextureChanged = true;
_arg1.setRenderer(null);
};
}
private function updateGI():void{
var complete:Set;
var face:Face;
var uvs:Array;
var length:uint;
var i:uint;
var v:Vertex;
var i2:uint;
var joined:Face;
var j:uint;
var j2:uint;
var strength:Number;
var color:Number;
if (((uvChanged) || (objectChanged))){
complete = new Set(true);
lightGI.graphics.clear();
for each (face in _faces) {
uvs = uv[face];
face.calculateCenter();
face.calculateNormal();
complete.add(face);
length = face.length;
i = 0;
while (i < length) {
v = Vertex(face._vertices[i]);
i2 = ((i)<(length - 1)) ? (i + 1) : 0;
for each (joined in v.faces) {
if (!complete.has(joined)){
j = joined._vertices.indexOf(v);
j2 = ((j)>0) ? (j - 1) : (joined.length - 1);
if (face._vertices[i2] == joined._vertices[j2]){
joined.calculateCenter();
joined.calculateNormal();
if (Point3D.dot(face.normal, Point3D.difference(joined.center, face.center)) > 0){
strength = (Point3D.angleFast(face.normal, joined.normal) / Math.PI);
color = ((1 - strength) * 0xFF);
var _local6 = lightGI.graphics;
with (_local6) {
lineStyle((lightGISize * strength), new RGB(color, color, color).toInt());
moveTo(uvs[i].x, uvs[i].y);
lineTo(uvs[i2].x, uvs[i2].y);
};
};
break;
};
};
};
i = (i + 1);
};
};
lightChanged = true;
mergedTextureChanged = true;
};
}
private function updateBumpSize():void{
var tw:uint;
var th:uint;
var create:Function = function ():void{
if (_bumpEnabled){
bump = new BitmapData(tw, th, true, 0);
bumpMap = new BitmapData(tw, th, true, 0);
};
bumpChanged = true;
mergedTextureChanged = true;
};
if (((((((((uvChanged) || (mipmapChanged))) || (textureResolutionChanged))) || (bumpResolutionChanged))) || (bumpEnabledChanged))){
tw = (Math.ceil((uvWidth / mipmapBumpResolution)) + 2);
th = (Math.ceil((uvHeight / mipmapBumpResolution)) + 2);
tw = (tw + (((tw % 2))==0) ? 1 : 0);
th = (th + (((th % 2))==0) ? 1 : 0);
if (bump != null){
if (((((!((bump.width == tw))) || (!((bump.height == th))))) || (!(_bumpEnabled)))){
if (bump != null){
bump.dispose();
bump = null;
};
if (bumpMap != null){
bumpMap.dispose();
bumpMap = null;
};
create();
};
} else {
create();
};
};
}
private function updateLightSize():void{
var _local1:uint;
var _local2:uint;
if (((((((uvChanged) || (mipmapChanged))) || (textureResolutionChanged))) || (lightResolutionChanged))){
_local1 = (Math.ceil((uvWidth / mipmapLightResolution)) + 2);
_local2 = (Math.ceil((uvHeight / mipmapLightResolution)) + 2);
_local1 = (_local1 + (((_local1 % 2))==0) ? 1 : 0);
_local2 = (_local2 + (((_local2 % 2))==0) ? 1 : 0);
if (light != null){
if (((!((light.width == _local1))) || (!((light.height == _local2))))){
if (light != null){
light.dispose();
light = null;
};
light = new BitmapData(_local1, _local2, true, 0);
lightChanged = true;
mergedTextureChanged = true;
};
} else {
light = new BitmapData(_local1, _local2, true, 0);
lightChanged = true;
mergedTextureChanged = true;
};
};
}
private function updateLight():void{
var _local1:Set;
var _local2:RGB;
var _local3:Ambient;
if (lightChanged){
_local1 = _object.getSolidObjects(Ambient);
_local2 = new RGB();
for each (_local3 in _local1) {
_local2.add(_local3._color);
};
light.fillRect(light.rect, (4278190080 + _local2.toInt()));
light.draw(lightContainer, new Matrix((1 / mipmapLightResolution), 0, 0, (1 / mipmapLightResolution), 1, 1), null, null, null, true);
if (mipmapLightResolution < lightBlur){
light.applyFilter(light, light.rect, new Point(), new BlurFilter((lightBlur / mipmapLightResolution), (lightBlur / mipmapLightResolution), 2));
};
};
}
override public function clear():void{
super.clear();
if (((!((_object == null))) && (!((_object._view == null))))){
mergedTexture.dispose();
cacheTexture.dispose();
texture.dispose();
light.dispose();
bump.dispose();
mergedTexture = null;
cacheTexture = null;
texture = null;
light = null;
bump = null;
};
}
public static function get bumpResolution():int{
return (_bumpResolution);
}
public static function set bumpResolution(_arg1:int):void{
_arg1 = ((_arg1)>lowestResolution) ? lowestResolution : ((_arg1)<highestResolution) ? highestResolution : _arg1;
if (_bumpResolution != _arg1){
_bumpResolution = _arg1;
realBumpResolution = Math.max(_textureResolution, _bumpResolution);
bumpResolutionChanged = true;
};
}
public static function get textureResolution():int{
return (_textureResolution);
}
public static function get bumpEnabled():Boolean{
return (_bumpEnabled);
}
public static function get smooth():Boolean{
return (_smooth);
}
public static function get lightMapResolution():int{
return (_lightResolution);
}
public static function set textureResolution(_arg1:int):void{
_arg1 = ((_arg1)>lowestResolution) ? lowestResolution : ((_arg1)<highestResolution) ? highestResolution : _arg1;
if (_textureResolution != _arg1){
_textureResolution = _arg1;
realLightResolution = Math.max(_textureResolution, _lightResolution);
realBumpResolution = Math.max(_textureResolution, _bumpResolution);
textureResolutionChanged = true;
};
}
public static function set bumpEnabled(_arg1:Boolean):void{
if (_bumpEnabled != _arg1){
_bumpEnabled = _arg1;
bumpEnabledChanged = true;
};
}
public static function set smooth(_arg1:Boolean):void{
_smooth = _arg1;
smoothChanged = true;
}
public static function set lightMapResolution(_arg1:int):void{
_arg1 = ((_arg1)>lowestResolution) ? lowestResolution : ((_arg1)<highestResolution) ? highestResolution : _arg1;
if (_lightResolution != _arg1){
_lightResolution = _arg1;
realLightResolution = Math.max(_textureResolution, _lightResolution);
lightResolutionChanged = true;
};
}
}
}//package com.alternativagame.engine3d
Section 30
//UVRenderer (com.alternativagame.engine3d.UVRenderer)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
import flash.utils.*;
import com.alternativagame.engine3d.skin.*;
public class UVRenderer extends InteractiveSurfaceRenderer {
protected var directionUVMatrix:Matrix3D;
protected var uvMatrix:Matrix3D;
var uvChanged:Boolean;// = false
var uv:Dictionary;
var uvDepth:uint;
var uvWidth:uint;
var uvHeight:uint;
private var uvData:SkinData;
protected var inverseUVMatrix:Matrix3D;
private static var num:uint = 0;
protected function calculateUVCoords():void{
var _local1:Dictionary;
var _local2:Point3D;
var _local3:uint;
var _local4:Array;
var _local5:Face;
var _local6:uint;
var _local7:Point3D;
var _local8:Point3D;
var _local9:Number;
var _local10:Number;
var _local11:Number;
var _local12:Number;
var _local13:Number;
var _local14:Number;
var _local15:Point3D;
var _local16:*;
var _local17:Array;
if (((((((((_object.geometryChanged) || (_object.facesChanged))) || (_object.viewChanged))) || (facesChanged))) || (objectChanged))){
_local1 = new Dictionary(true);
_local2 = new Point3D();
for each (_local5 in _faces) {
_local5.calculateNormal();
_local2.add(_local5.normal);
_local4 = _local5._vertices;
_local3 = _local4.length;
_local6 = 0;
while (_local6 < _local3) {
if (_local1[_local4[_local6]] == undefined){
_local1[_local4[_local6]] = new Point3D();
};
_local6++;
};
};
if (_local2.length < 0.1){
_local2 = new Point3D(0, -1, 0);
} else {
_local2.normalize();
};
_local7 = new Point3D();
_local8 = new Point3D();
if (Math.abs(_local2.z) > 0.9){
_local7.x = _local2.z;
_local7.z = -(_local2.x);
} else {
_local7.x = -(_local2.y);
_local7.y = _local2.x;
};
_local7.normalize();
_local8 = Point3D.cross(_local7, _local2);
uvMatrix = new Matrix3D(_local7.x, _local8.x, _local2.x, 0, _local7.y, _local8.y, _local2.y, 0, _local7.z, _local8.z, _local2.z, 0);
inverseUVMatrix = Matrix3D.inverseMatrix(uvMatrix);
_local9 = Number.MAX_VALUE;
_local10 = -(Number.MAX_VALUE);
_local11 = Number.MAX_VALUE;
_local12 = -(Number.MAX_VALUE);
_local13 = Number.MAX_VALUE;
_local14 = -(Number.MAX_VALUE);
for (_local16 in _local1) {
_local15 = Vertex(_local16).coords.clone();
_local15.transform(inverseUVMatrix);
Point3D(_local1[_local16]).copy(_local15);
_local9 = ((_local15.x)<_local9) ? _local15.x : _local9;
_local10 = ((_local15.x)>_local10) ? _local15.x : _local10;
_local11 = ((_local15.y)<_local11) ? _local15.y : _local11;
_local12 = ((_local15.y)>_local12) ? _local15.y : _local12;
_local13 = ((_local15.z)<_local13) ? _local15.z : _local13;
_local14 = ((_local15.z)>_local14) ? _local15.z : _local14;
};
uvWidth = (_local10 - _local9);
uvHeight = (_local12 - _local11);
uvDepth = (_local14 - _local13);
for (_local16 in _local1) {
_local15 = Point3D(_local1[_local16]);
Point3D(_local1[_local16]).x = (_local15.x - _local9);
_local15.y = (_local15.y - _local11);
_local15.z = (_local15.z - _local13);
};
uv = new Dictionary(true);
for each (_local5 in _faces) {
_local17 = new Array();
_local4 = _local5._vertices;
_local3 = _local4.length;
_local6 = 0;
while (_local6 < _local3) {
_local17.push(_local1[_local4[_local6]]);
_local6++;
};
uv[_local5] = _local17;
};
directionUVMatrix = Matrix3D.inverseMatrix(uvMatrix);
uvMatrix.translateLocal(_local9, _local11, _local13);
inverseUVMatrix = Matrix3D.inverseMatrix(uvMatrix);
uvChanged = true;
};
}
public function uvToLocal(_arg1:Point3D):Point3D{
var _local2:Point3D = _arg1.clone();
_local2.transform(uvMatrix);
return (_local2);
}
public function localDirectionToUV(_arg1:Point3D):Point3D{
var _local2:Point3D = _arg1.clone();
_local2.transform(directionUVMatrix);
return (_local2);
}
public function localToUV(_arg1:Point3D):Point3D{
var _local2:Point3D = _arg1.clone();
_local2.transform(inverseUVMatrix);
return (_local2);
}
override protected function defaultName():String{
num++;
return (("uvRenderer" + num));
}
override public function render():void{
var _local1:Matrix3D;
var _local2:Point3D;
var _local3:Point3D;
var _local4:Point3D;
var _local5:Point3D;
var _local6:Array;
var _local7:Array;
var _local8:uint;
var _local9:Point3D;
var _local10:Face;
var _local11:uint;
if (uvData == null){
uvData = new SkinData(this, 4);
uvData.skin = new UVSkin();
_object._view.addSkin(uvData);
};
calculateUVCoords();
if (((((((((((((((_object.coordsChanged) || (_object.transformChanged))) || (_object.geometryChanged))) || (_object.facesChanged))) || (_object.viewChanged))) || (_object.parentChanged))) || (facesChanged))) || (objectChanged))){
_local1 = uvMatrix.clone();
_local1.translateLocal(0, 0, (uvDepth + 50));
_local1.combine(_object.transformMatrix);
_local2 = new Point3D(_local1.d, _local1.h, _local1.l);
_local3 = new Point3D((_local1.d + (_local1.b * uvHeight)), (_local1.h + (_local1.f * uvHeight)), (_local1.l + (_local1.j * uvWidth)));
_local4 = new Point3D(((_local1.d + (_local1.a * uvWidth)) + (_local1.b * uvHeight)), ((_local1.h + (_local1.e * uvWidth)) + (_local1.f * uvHeight)), ((_local1.l + (_local1.i * uvWidth)) + (_local1.j * uvWidth)));
_local5 = new Point3D((_local1.d + (_local1.a * uvWidth)), (_local1.h + (_local1.e * uvWidth)), (_local1.l + (_local1.i * uvWidth)));
uvData.points[0] = _local2;
uvData.points[1] = _local3;
uvData.points[2] = _local4;
uvData.points[3] = _local5;
if ((((_local3.x - _local2.x) * (_local4.y - _local2.y)) - ((_local3.y - _local2.y) * (_local4.x - _local2.x))) < 0){
_object._view.addSkin(uvData);
_object._view.changeSkin(uvData);
UVSkin(uvData.skin).clear();
UVSkin(uvData.skin).drawGizmo(uvData.points, 1, 0xFF00, 0xFF00, 0.2, 0xFF0000);
for each (_local10 in _faces) {
_local6 = new Array();
_local7 = uv[_local10];
_local8 = _local7.length;
_local11 = 0;
while (_local11 < _local8) {
_local9 = Point3D(_local7[_local11]).clone();
_local9.z = 0;
_local9.transform(_local1);
_local6.push(_local9);
_local11++;
};
UVSkin(uvData.skin).drawFaceUV(_local6, 1, 0xFFFF00, 0.4);
};
} else {
_object._view.removeSkin(uvData);
};
};
}
override public function drop():void{
super.drop();
uvChanged = false;
}
override public function clone():IRenderer{
var _local1:UVRenderer = new UVRenderer();
return (_local1);
}
}
}//package com.alternativagame.engine3d
Section 31
//Vertex (com.alternativagame.engine3d.Vertex)
package com.alternativagame.engine3d {
import com.alternativagame.type.*;
public class Vertex {
var faces:Set;
var meshChanged:Boolean;// = false
var canvasCoords:Point3D;
var facesChanged:Boolean;// = false
var mesh:Mesh;
var coordsChanged:Boolean;// = true
private var _coords:Point3D;
public function Vertex(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0){
_coords = new Point3D(_arg1, _arg2, _arg3);
faces = new Set(true);
canvasCoords = new Point3D();
}
public function clone():Vertex{
return (new Vertex(x, y, z));
}
public function get coords():Point3D{
return (_coords);
}
function calculate(_arg1:Matrix3D):void{
if (((((coordsChanged) || (meshChanged))) || (mesh.viewChanged))){
canvasCoords.copy(_coords);
canvasCoords.transform(_arg1);
};
}
function drop():void{
coordsChanged = false;
facesChanged = false;
meshChanged = false;
}
public function set x(_arg1:Number):void{
_coords.x = _arg1;
setChangedCoords();
}
public function set y(_arg1:Number):void{
_coords.y = _arg1;
setChangedCoords();
}
public function set z(_arg1:Number):void{
_coords.z = _arg1;
setChangedCoords();
}
private function setChangedCoords():void{
var _local1:Face;
coordsChanged = true;
for each (_local1 in faces) {
_local1.transformChanged = true;
_local1.visibleCalculated = false;
_local1.centerCalculated = false;
_local1.canvasCenterCalculated = false;
_local1.normalCalculated = false;
_local1.canvasNormalCalculated = false;
};
if (mesh != null){
mesh.geometryChanged = true;
};
}
public function get x():Number{
return (_coords.x);
}
public function get y():Number{
return (_coords.y);
}
public function get z():Number{
return (_coords.z);
}
public function set coords(_arg1:Point3D):void{
_coords.copy(_arg1);
setChangedCoords();
}
function setMesh(_arg1:Mesh):void{
mesh = _arg1;
meshChanged = true;
}
}
}//package com.alternativagame.engine3d
Section 32
//View (com.alternativagame.engine3d.View)
package com.alternativagame.engine3d {
import flash.events.*;
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import com.alternativagame.admin.*;
import com.alternativagame.utility.*;
import flash.filters.*;
public class View extends Sprite {
private var pressedSkinData:SkinData;
private var arrangeMap:Dictionary;
private var mouseCoords:Point3D;
private var compareSkinDatas:Set;
private var readySkinDatas:Set;
var directionChanged:Boolean;// = true
private var changedSkinDatas:Set;
private var _pitch:Number;// = 0
private var _height:uint;
var transformMatrix:Matrix3D;
public var canvas:Sprite;
private var overedSkinData:SkinData;
private var _roll:Number;// = 0
private var _object:Object3D;// = null
var zoomChanged:Boolean;// = true
var objectChanged:Boolean;// = false
private var _crop:Boolean;// = false
private var shiftKey:Boolean;// = false
private var mouseSkinData:SkinData;
private var canvasCoords:Point3D;
private var _hold:Boolean;// = false
private var _targetX:Number;// = 0
private var _targetY:Number;// = 0
private var _targetZ:Number;// = 0
private var _zoom:Number;// = 1
private var _yaw:Number;// = 0
private var _width:uint;
private var mouseBound:Point;
var targetChanged:Boolean;// = true
private var mouseDown:Boolean;// = false
private var ctrlKey:Boolean;// = false
private var altKey:Boolean;// = false
private var boundMap:Array;
static var boundMapSize:Number = 60;
public function View(_arg1:uint=0, _arg2:uint=0){
var width = _arg1;
var height = _arg2;
super();
readySkinDatas = new Set(true);
changedSkinDatas = new Set(true);
compareSkinDatas = new Set(true);
arrangeMap = new Dictionary(true);
boundMap = new Array();
hitArea = new Sprite();
hitArea.mouseEnabled = false;
hitArea.visible = false;
var _local4 = hitArea.graphics;
with (_local4) {
beginFill(0);
drawRect(0, 0, 100, 100);
};
addChild(hitArea);
canvas = new Sprite();
canvas.mouseEnabled = false;
canvas.mouseChildren = false;
addChild(canvas);
canvasCoords = new Point3D();
this.width = width;
this.height = height;
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
addEventListener(Event.ADDED_TO_STAGE, onMouseAdd);
addEventListener(Event.REMOVED_FROM_STAGE, onMouseRemove);
addEventListener(Event.MOUSE_LEAVE, onMouseRemove);
}
private function onKey(_arg1:KeyboardEvent):void{
ctrlKey = _arg1.ctrlKey;
altKey = _arg1.altKey;
shiftKey = _arg1.shiftKey;
}
public function set roll(_arg1:Number):void{
_roll = _arg1;
if (!directionChanged){
setTransformChanged();
directionChanged = true;
};
}
function removeSkin(_arg1:SkinData):void{
if (changedSkinDatas.has(_arg1)){
changedSkinDatas.remove(_arg1);
updateArrangeMap(_arg1, _arg1.layer, -1);
if (_arg1 == mouseSkinData){
onMouseSkinData();
};
} else {
if (readySkinDatas.has(_arg1)){
removeFromBoundMap(_arg1);
_arg1.breakLinks();
readySkinDatas.remove(_arg1);
updateArrangeMap(_arg1, _arg1.layer, -1);
if (_arg1 == mouseSkinData){
onMouseSkinData();
};
};
};
}
private function onMouseRemove(_arg1:Event):void{
mouseCoords = null;
mouseBound = null;
mouseSkinData = null;
}
override public function get height():Number{
return (_height);
}
public function set crop(_arg1:Boolean):void{
_crop = _arg1;
if (_arg1){
scrollRect = new Rectangle(0, 0, width, height);
} else {
scrollRect = null;
};
}
private function setTransformChanged():void{
if (object != null){
object.setCoordsChanged();
object.setTransformChanged();
};
}
public function get object():Object3D{
return (_object);
}
public function get pitch():Number{
return (_pitch);
}
private function onMouseUp(_arg1:MouseEvent):void{
if (mouseSkinData != null){
sendInteraction(Interaction.UP);
if (pressedSkinData != null){
if (mouseSkinData == pressedSkinData){
sendInteraction(Interaction.SKIN_CLICK);
};
if (mouseSkinData.renderer == pressedSkinData.renderer){
sendInteraction(Interaction.RENDERER_CLICK);
};
if (mouseSkinData.renderer.object == pressedSkinData.renderer.object){
sendInteraction(Interaction.OBJECT_CLICK);
};
};
};
pressedSkinData = null;
mouseDown = false;
}
private function arrangeSkins():void{
var _local2:ArrangeData;
var _local3:uint;
var _local4:Sprite;
var _local5:DisplayObject;
var _local1:uint = canvas.numChildren;
for each (_local2 in arrangeMap) {
if ((_local2.newLayer + 1) > _local1){
_local1 = (_local2.newLayer + 1);
};
};
if (_local1 > 0){
_local3 = canvas.numChildren;
while (_local3 < _local1) {
_local4 = new Sprite();
canvas.addChild(_local4);
_local3++;
};
for each (_local2 in arrangeMap) {
_local5 = _local2.data.skin;
if (_local2.oldLayer >= 0){
Sprite(canvas.getChildAt(_local2.oldLayer)).removeChild(_local5);
};
if (_local2.newLayer < 0){
readySkinDatas.remove(_local2.data);
} else {
Sprite(canvas.getChildAt(_local2.newLayer)).addChild(_local5);
};
delete arrangeMap[_local2.data];
_local2.data = null;
};
while ((((canvas.numChildren > 0)) && ((Sprite(canvas.getChildAt((canvas.numChildren - 1))).numChildren == 0)))) {
canvas.removeChildAt((canvas.numChildren - 1));
};
};
}
function changeSkin(_arg1:SkinData):void{
if (readySkinDatas.has(_arg1)){
removeFromBoundMap(_arg1);
readySkinDatas.remove(_arg1);
};
_arg1.calculate();
_arg1.breakLinks();
changedSkinDatas.add(_arg1);
}
override public function set height(_arg1:Number):void{
_height = _arg1;
hitArea.height = _height;
canvas.y = ((_height / 2) + canvasCoords.y);
if (crop){
scrollRect = new Rectangle(0, 0, width, _height);
};
}
public function drawBoundMap():void{
var _local2:int;
canvas.graphics.clear();
var _local1 = -20;
while (_local1 <= 20) {
if (boundMap[_local1] != undefined){
_local2 = -20;
while (_local2 <= 20) {
if (boundMap[_local1][_local2] != undefined){
if ((((mouseBound.x == _local1)) && ((mouseBound.y == _local2)))){
canvas.graphics.beginFill(16764108, (Set(boundMap[_local1][_local2]).length / 10));
} else {
canvas.graphics.beginFill(0xFFFFFF, (Set(boundMap[_local1][_local2]).length / 10));
};
canvas.graphics.drawRect((_local1 * boundMapSize), (_local2 * boundMapSize), boundMapSize, boundMapSize);
canvas.graphics.lineStyle();
};
_local2++;
};
};
_local1++;
};
}
private function boundSkinCompares(_arg1:SkinData):void{
var _local2:Set;
var _local4:int;
var _local5:SkinData;
compareSkinDatas = new Set(true);
var _local3:int = _arg1.boundMapLeft;
while (_local3 <= _arg1.boundMapRight) {
if (boundMap[_local3] != undefined){
_local4 = _arg1.boundMapTop;
while (_local4 <= _arg1.boundMapBottom) {
if (boundMap[_local3][_local4] != undefined){
for each (_local5 in Set(boundMap[_local3][_local4])) {
compareSkinDatas.add(_local5);
};
};
_local4++;
};
};
_local3++;
};
}
private function removeFromBoundMap(_arg1:SkinData):void{
var _local2:Set;
var _local4:int;
var _local3:int = _arg1.boundMapLeft;
while (_local3 <= _arg1.boundMapRight) {
if (boundMap[_local3] != undefined){
_local4 = _arg1.boundMapTop;
while (_local4 <= _arg1.boundMapBottom) {
if (boundMap[_local3][_local4] != undefined){
_local2 = Set(boundMap[_local3][_local4]);
_local2.remove(_arg1);
if (_local2.length == 0){
delete boundMap[_local3][_local4];
if (boundMap[_local3].length == 0){
delete boundMap[_local3];
break;
};
};
};
_local4++;
};
};
_local3++;
};
}
public function get yaw():Number{
return (_yaw);
}
private function sendInteraction(_arg1:uint, _arg2:SkinData=null):void{
if (_arg2 == null){
mouseSkinData.renderer.interaction(_arg1, mouseSkinData, mouseCoords, mouseDown, ctrlKey, altKey, shiftKey);
} else {
_arg2.renderer.interaction(_arg1, _arg2, mouseCoords, mouseDown, ctrlKey, altKey, shiftKey);
};
}
public function drawLayersShift():void{
var _local2:DisplayObject;
var _local1:uint = canvas.numChildren;
var _local3:uint;
while (_local3 < _local1) {
_local2 = canvas.getChildAt(_local3);
_local2.filters = [new DropShadowFilter(10, 45, 0, 1, 10, 10, 0.5, 2)];
_local2.x = (_local3 * 20);
_local2.y = (_local3 * 20);
_local3++;
};
}
public function get roll():Number{
return (_roll);
}
public function set object(_arg1:Object3D):void{
if (_object != _arg1){
if (_object != null){
object.setView(null);
};
if (_arg1 != null){
if (((!((_arg1._view == null))) && ((_arg1 === _arg1._view.object)))){
_arg1._view.object = null;
} else {
if (_arg1.parent != null){
_arg1.parent.detach(_arg1);
};
};
_arg1.setView(this);
};
_object = _arg1;
objectChanged = true;
};
}
public function set pitch(_arg1:Number):void{
_pitch = _arg1;
if (!directionChanged){
setTransformChanged();
directionChanged = true;
};
}
public function canvasToGlobal(_arg1:Point3D):Point3D{
return (new Point3D(((_arg1.x - canvasCoords.x) + (_width / 2)), ((_arg1.y - canvasCoords.y) + (_height / 2)), (_arg1.z - canvasCoords.z)));
}
public function get crop():Boolean{
return (_crop);
}
override public function set width(_arg1:Number):void{
_width = _arg1;
hitArea.width = _width;
canvas.x = ((_width / 2) + canvasCoords.x);
if (crop){
scrollRect = new Rectangle(0, 0, _width, height);
};
}
public function render():void{
var _local1:uint;
var _local2:uint;
if (object != null){
if (((directionChanged) || (zoomChanged))){
transformMatrix = Matrix3D.inverseTransformMatrix(0, 0, 0, _pitch, _roll, _yaw, _zoom, _zoom, _zoom);
transformMatrix.convertToScreen();
};
if (((((directionChanged) || (targetChanged))) || (zoomChanged))){
canvasCoords = new Point3D(-(_targetX), -(_targetY), -(_targetZ));
canvasCoords.transform(transformMatrix);
canvas.x = ((_width / 2) + canvasCoords.x);
canvas.y = ((_height / 2) + canvasCoords.y);
};
if (!_hold){
object.calculate();
object.render();
object.drop();
_local1 = readySkinDatas.length;
_local2 = changedSkinDatas.length;
FPS.addSkins((_local1 + _local2), _local2);
calculateSkins();
};
drop();
} else {
FPS.addSkins(0, 0);
};
arrangeSkins();
}
public function set zoom(_arg1:Number):void{
_zoom = (1 / _arg1);
if (!zoomChanged){
setTransformChanged();
zoomChanged = true;
};
}
public function drawLayers():void{
var _local1:uint = canvas.numChildren;
var _local2:uint;
while (_local2 < _local1) {
canvas.getChildAt(_local2).transform.colorTransform = new ColorTransform(0, 0, 0, 1, ((_local2 * 20) + 50), ((_local2 * 20) + 50), ((_local2 * 20) + 50));
_local2++;
};
}
private function onMouseAdd(_arg1:Event):void{
calculateMouse();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
stage.addEventListener(KeyboardEvent.KEY_UP, onKey);
}
function addSkin(_arg1:SkinData):void{
if (((!(changedSkinDatas.has(_arg1))) && (!(readySkinDatas.has(_arg1))))){
updateArrangeMap(_arg1, -1, 0);
};
}
public function hold():void{
_hold = true;
canvas.cacheAsBitmap = true;
}
function updateArrangeMap(_arg1:SkinData, _arg2:int, _arg3:int):void{
if (arrangeMap[_arg1] == undefined){
arrangeMap[_arg1] = new ArrangeData();
arrangeMap[_arg1].data = _arg1;
arrangeMap[_arg1].oldLayer = _arg2;
};
if (ArrangeData(arrangeMap[_arg1]).oldLayer == _arg3){
delete arrangeMap[_arg1];
} else {
ArrangeData(arrangeMap[_arg1]).newLayer = _arg3;
};
}
private function onMouseDown(_arg1:MouseEvent):void{
if (mouseSkinData != null){
sendInteraction(Interaction.DOWN);
};
pressedSkinData = mouseSkinData;
mouseDown = true;
}
private function calculateMouseSkinData():void{
var _local1:SkinData;
var _local2:Array;
var _local3:uint;
var _local4:Object3D;
var _local5:Number;
var _local6:uint;
mouseSkinData = null;
if (((!((boundMap[mouseBound.x] == undefined))) && (!((boundMap[mouseBound.x][mouseBound.y] == undefined))))){
_local2 = new Array();
for each (_local1 in Set(boundMap[mouseBound.x][mouseBound.y])) {
_local2.push(_local1);
};
_local2.sortOn("layer", (Array.NUMERIC | Array.DESCENDING));
_local3 = _local2.length;
_local5 = -(Number.MAX_VALUE);
_local6 = 0;
while (_local6 < _local3) {
_local1 = _local2[_local6];
_local1.calculateInteractionCoords(mouseCoords);
if (((!(isNaN(mouseCoords.z))) && ((mouseCoords.z > _local5)))){
mouseSkinData = _local1;
_local5 = mouseCoords.z;
};
if (((((!((mouseSkinData == null))) && ((_local6 < (_local3 - 1))))) && (!((SkinData(_local2[(_local6 + 1)]).layer == _local1.layer))))){
break;
};
_local6++;
};
if (mouseSkinData != null){
mouseCoords.z = _local5;
};
};
}
public function set targetY(_arg1:Number):void{
_targetY = _arg1;
targetChanged = true;
}
public function set targetZ(_arg1:Number):void{
_targetZ = _arg1;
targetChanged = true;
}
public function get zoom():Number{
return ((1 / _zoom));
}
public function set targetX(_arg1:Number):void{
_targetX = _arg1;
targetChanged = true;
}
private function calculateSkins():void{
var _local1:int;
var _local2:Boolean;
var _local3:SkinData;
var _local4:SkinData;
var _local5:int;
var _local6:int;
if (changedSkinDatas.length > 0){
_local2 = false;
for each (_local3 in changedSkinDatas) {
boundSkinCompares(_local3);
for each (_local4 in compareSkinDatas) {
_local1 = _local3.compare(_local4);
if (_local1 != SkinData.NOINTERSECTION){
if (_local1 == SkinData.BEHIND){
_local3.linkBehind(_local4);
} else {
_local3.linkInfront(_local4);
};
};
};
_local5 = _local3.boundMapLeft;
while (_local5 <= _local3.boundMapRight) {
if (boundMap[_local5] == undefined){
boundMap[_local5] = new Array();
};
_local6 = _local3.boundMapTop;
while (_local6 <= _local3.boundMapBottom) {
if (boundMap[_local5][_local6] == undefined){
boundMap[_local5][_local6] = new Set(true);
};
Set(boundMap[_local5][_local6]).add(_local3);
if ((((_local5 == mouseBound.x)) && ((_local6 == mouseBound.y)))){
_local2 = true;
};
_local6++;
};
_local5++;
};
if ((((((((mouseBound.x >= _local3.boundMapLeft)) && ((mouseBound.x <= _local3.boundMapRight)))) && ((mouseBound.y >= _local3.boundMapTop)))) && ((mouseBound.y <= _local3.boundMapBottom)))){
_local2 = true;
};
readySkinDatas.add(_local3);
};
changedSkinDatas = new Set(true);
if (_local2){
onMouseSkinData();
};
};
}
public function unhold():void{
_hold = false;
canvas.cacheAsBitmap = false;
}
private function calculateMouse():void{
var _local1:Point = MouseUtility.localCoords(canvas);
mouseCoords = new Point3D(_local1.x, _local1.y, NaN);
mouseBound = new Point(Math.floor((mouseCoords.x / boundMapSize)), Math.floor((mouseCoords.y / boundMapSize)));
calculateMouseSkinData();
}
public function set yaw(_arg1:Number):void{
_yaw = _arg1;
if (!directionChanged){
setTransformChanged();
directionChanged = true;
};
}
public function get targetX():Number{
return (_targetX);
}
public function get targetY():Number{
return (_targetY);
}
public function get targetZ():Number{
return (_targetZ);
}
private function onMouseSkinData():void{
calculateMouseSkinData();
onMouseOverOut();
}
private function drop():void{
targetChanged = false;
directionChanged = false;
zoomChanged = false;
objectChanged = false;
}
override public function get width():Number{
return (_width);
}
private function onMouseMove(_arg1:MouseEvent):void{
calculateMouse();
onMouseOverOut();
if (mouseSkinData != null){
sendInteraction(Interaction.MOVE);
};
}
private function onMouseOverOut():void{
if (mouseSkinData != overedSkinData){
if (overedSkinData != null){
sendInteraction(Interaction.SKIN_OUT, overedSkinData);
if (mouseSkinData != null){
if (mouseSkinData.renderer != overedSkinData.renderer){
sendInteraction(Interaction.RENDERER_OUT, overedSkinData);
if (mouseSkinData.renderer.object != overedSkinData.renderer.object){
sendInteraction(Interaction.OBJECT_OUT, overedSkinData);
};
};
} else {
sendInteraction(Interaction.RENDERER_OUT, overedSkinData);
sendInteraction(Interaction.OBJECT_OUT, overedSkinData);
};
};
if (mouseSkinData != null){
sendInteraction(Interaction.SKIN_OVER);
if (overedSkinData != null){
if (mouseSkinData.renderer != overedSkinData.renderer){
sendInteraction(Interaction.RENDERER_OVER);
if (mouseSkinData.renderer.object != overedSkinData.renderer.object){
sendInteraction(Interaction.OBJECT_OVER);
};
};
} else {
sendInteraction(Interaction.RENDERER_OVER);
sendInteraction(Interaction.OBJECT_OVER);
};
};
};
overedSkinData = mouseSkinData;
}
}
}//package com.alternativagame.engine3d
class ArrangeData {
public var newLayer:int;
public var data:SkinData;
public var oldLayer:int;
private function ArrangeData(){
}
}
Section 33
//Matrix3D (com.alternativagame.type.Matrix3D)
package com.alternativagame.type {
public final class Matrix3D {
public var a:Number;
public var b:Number;
public var c:Number;
public var d:Number;
public var e:Number;
public var f:Number;
public var g:Number;
public var h:Number;
public var i:Number;
public var j:Number;
public var k:Number;
public var l:Number;
public function Matrix3D(_arg1:Number=1, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0, _arg5:Number=0, _arg6:Number=1, _arg7:Number=0, _arg8:Number=0, _arg9:Number=0, _arg10:Number=0, _arg11:Number=1, _arg12:Number=0){
this.a = _arg1;
this.b = _arg2;
this.c = _arg3;
this.d = _arg4;
this.e = _arg5;
this.f = _arg6;
this.g = _arg7;
this.h = _arg8;
this.i = _arg9;
this.j = _arg10;
this.k = _arg11;
this.l = _arg12;
}
public function toString():String{
return (((((((((((((((((((((((("Matrix:\r" + a.toFixed(3)) + "\t") + b.toFixed(3)) + "\t") + c.toFixed(3)) + "\t") + d.toFixed(3)) + "\r") + e.toFixed(3)) + "\t") + f.toFixed(3)) + "\t") + g.toFixed(3)) + "\t") + h.toFixed(3)) + "\r") + i.toFixed(3)) + "\t") + j.toFixed(3)) + "\t") + k.toFixed(3)) + "\t") + l.toFixed(3)));
}
public function scale(_arg1:Number, _arg2:Number, _arg3:Number):void{
combine(scaleMatrix(_arg1, _arg2, _arg3));
}
public function translate(_arg1:Number, _arg2:Number, _arg3:Number):void{
d = (d + _arg1);
h = (h + _arg2);
l = (l + _arg3);
}
public function inverseConvertToScreen():void{
var _local1:Number = b;
var _local2:Number = f;
var _local3:Number = j;
b = -(c);
f = -(g);
j = -(k);
c = -(_local1);
g = -(_local2);
k = -(_local3);
}
public function convertToScreen():void{
var _local1:Number = e;
var _local2:Number = f;
var _local3:Number = g;
var _local4:Number = h;
e = -(i);
f = -(j);
g = -(k);
h = -(l);
i = -(_local1);
j = -(_local2);
k = -(_local3);
l = -(_local4);
}
public function rotate(_arg1:Number, _arg2:Number, _arg3:Number):void{
combine(rotateMatrix(_arg1, _arg2, _arg3));
}
public function inverseTransform(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0, _arg5:Number=0, _arg6:Number=0, _arg7:Number=1, _arg8:Number=1, _arg9:Number=1):void{
combine(inverseTransformMatrix(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9));
}
public function invert():void{
var _local1:Number = a;
var _local2:Number = b;
var _local3:Number = c;
var _local4:Number = d;
var _local5:Number = e;
var _local6:Number = f;
var _local7:Number = g;
var _local8:Number = h;
var _local9:Number = i;
var _local10:Number = j;
var _local11:Number = k;
var _local12:Number = l;
var _local13:Number = (((((((-(_local3) * _local6) * _local9) + ((_local2 * _local7) * _local9)) + ((_local3 * _local5) * _local10)) - ((_local1 * _local7) * _local10)) - ((_local2 * _local5) * _local11)) + ((_local1 * _local6) * _local11));
a = (((-(_local7) * _local10) + (_local6 * _local11)) / _local13);
b = (((_local3 * _local10) - (_local2 * _local11)) / _local13);
c = (((-(_local3) * _local6) + (_local2 * _local7)) / _local13);
d = ((((((((_local4 * _local7) * _local10) - ((_local3 * _local8) * _local10)) - ((_local4 * _local6) * _local11)) + ((_local2 * _local8) * _local11)) + ((_local3 * _local6) * _local12)) - ((_local2 * _local7) * _local12)) / _local13);
e = (((_local7 * _local9) - (_local5 * _local11)) / _local13);
f = (((-(_local3) * _local9) + (_local1 * _local11)) / _local13);
g = (((_local3 * _local5) - (_local1 * _local7)) / _local13);
h = ((((((((_local3 * _local8) * _local9) - ((_local4 * _local7) * _local9)) + ((_local4 * _local5) * _local11)) - ((_local1 * _local8) * _local11)) - ((_local3 * _local5) * _local12)) + ((_local1 * _local7) * _local12)) / _local13);
i = (((-(_local6) * _local9) + (_local5 * _local10)) / _local13);
j = (((_local2 * _local9) - (_local1 * _local10)) / _local13);
k = (((-(_local2) * _local5) + (_local1 * _local6)) / _local13);
l = ((((((((_local4 * _local6) * _local9) - ((_local2 * _local8) * _local9)) - ((_local4 * _local5) * _local10)) + ((_local1 * _local8) * _local10)) + ((_local2 * _local5) * _local12)) - ((_local1 * _local6) * _local12)) / _local13);
}
public function inverseCombine(_arg1:Matrix3D):void{
var _local2:Number = a;
var _local3:Number = b;
var _local4:Number = c;
var _local5:Number = d;
var _local6:Number = e;
var _local7:Number = f;
var _local8:Number = g;
var _local9:Number = h;
var _local10:Number = i;
var _local11:Number = j;
var _local12:Number = k;
var _local13:Number = l;
a = (((_local2 * _arg1.a) + (_local3 * _arg1.e)) + (_local4 * _arg1.i));
b = (((_local2 * _arg1.b) + (_local3 * _arg1.f)) + (_local4 * _arg1.j));
c = (((_local2 * _arg1.c) + (_local3 * _arg1.g)) + (_local4 * _arg1.k));
d = ((((_local2 * _arg1.d) + (_local3 * _arg1.h)) + (_local4 * _arg1.l)) + _local5);
e = (((_local6 * _arg1.a) + (_local7 * _arg1.e)) + (_local8 * _arg1.i));
f = (((_local6 * _arg1.b) + (_local7 * _arg1.f)) + (_local8 * _arg1.j));
g = (((_local6 * _arg1.c) + (_local7 * _arg1.g)) + (_local8 * _arg1.k));
h = ((((_local6 * _arg1.d) + (_local7 * _arg1.h)) + (_local8 * _arg1.l)) + _local9);
i = (((_local10 * _arg1.a) + (_local11 * _arg1.e)) + (_local12 * _arg1.i));
j = (((_local10 * _arg1.b) + (_local11 * _arg1.f)) + (_local12 * _arg1.j));
k = (((_local10 * _arg1.c) + (_local11 * _arg1.g)) + (_local12 * _arg1.k));
l = ((((_local10 * _arg1.d) + (_local11 * _arg1.h)) + (_local12 * _arg1.l)) + _local13);
}
public function clone():Matrix3D{
var _local1:Matrix3D = new Matrix3D();
_local1.a = a;
_local1.b = b;
_local1.c = c;
_local1.d = d;
_local1.e = e;
_local1.f = f;
_local1.g = g;
_local1.h = h;
_local1.i = i;
_local1.j = j;
_local1.k = k;
_local1.l = l;
return (_local1);
}
public function inverseRotate(_arg1:Number, _arg2:Number, _arg3:Number):void{
combine(inverseRotateMatrix(_arg1, _arg2, _arg3));
}
public function copy(_arg1:Matrix3D):void{
a = _arg1.a;
b = _arg1.b;
c = _arg1.c;
d = _arg1.d;
e = _arg1.e;
f = _arg1.f;
g = _arg1.g;
h = _arg1.h;
i = _arg1.i;
j = _arg1.j;
k = _arg1.k;
l = _arg1.l;
}
public function inverseScale(_arg1:Number, _arg2:Number, _arg3:Number):void{
combine(inverseScaleMatrix(_arg1, _arg2, _arg3));
}
public function transform(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0, _arg5:Number=0, _arg6:Number=0, _arg7:Number=1, _arg8:Number=1, _arg9:Number=1):void{
combine(transformMatrix(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9));
}
public function translateLocal(_arg1:Number, _arg2:Number, _arg3:Number):void{
d = (d + (((a * _arg1) + (b * _arg2)) + (c * _arg3)));
h = (h + (((e * _arg1) + (f * _arg2)) + (g * _arg3)));
l = (l + (((i * _arg1) + (j * _arg2)) + (k * _arg3)));
}
public function inverseTranslate(_arg1:Number, _arg2:Number, _arg3:Number):void{
d = (d - _arg1);
h = (h - _arg2);
l = (l - _arg3);
}
public function combine(_arg1:Matrix3D):void{
var _local2:Number = a;
var _local3:Number = b;
var _local4:Number = c;
var _local5:Number = d;
var _local6:Number = e;
var _local7:Number = f;
var _local8:Number = g;
var _local9:Number = h;
var _local10:Number = i;
var _local11:Number = j;
var _local12:Number = k;
var _local13:Number = l;
a = (((_arg1.a * _local2) + (_arg1.b * _local6)) + (_arg1.c * _local10));
b = (((_arg1.a * _local3) + (_arg1.b * _local7)) + (_arg1.c * _local11));
c = (((_arg1.a * _local4) + (_arg1.b * _local8)) + (_arg1.c * _local12));
d = ((((_arg1.a * _local5) + (_arg1.b * _local9)) + (_arg1.c * _local13)) + _arg1.d);
e = (((_arg1.e * _local2) + (_arg1.f * _local6)) + (_arg1.g * _local10));
f = (((_arg1.e * _local3) + (_arg1.f * _local7)) + (_arg1.g * _local11));
g = (((_arg1.e * _local4) + (_arg1.f * _local8)) + (_arg1.g * _local12));
h = ((((_arg1.e * _local5) + (_arg1.f * _local9)) + (_arg1.g * _local13)) + _arg1.h);
i = (((_arg1.i * _local2) + (_arg1.j * _local6)) + (_arg1.k * _local10));
j = (((_arg1.i * _local3) + (_arg1.j * _local7)) + (_arg1.k * _local11));
k = (((_arg1.i * _local4) + (_arg1.j * _local8)) + (_arg1.k * _local12));
l = ((((_arg1.i * _local5) + (_arg1.j * _local9)) + (_arg1.k * _local13)) + _arg1.l);
}
public static function inverseMatrix(_arg1:Matrix3D):Matrix3D{
var _local2:Matrix3D = _arg1.clone();
_local2.invert();
return (_local2);
}
public static function inverseRotateMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Number = Math.cos(-(_arg1));
var _local5:Number = Math.sin(-(_arg1));
var _local6:Number = Math.cos(-(_arg2));
var _local7:Number = Math.sin(-(_arg2));
var _local8:Number = Math.cos(-(_arg3));
var _local9:Number = Math.sin(-(_arg3));
var _local10:Number = (_local5 * _local7);
var _local11:Matrix3D = new (Matrix3D);
_local11.a = (_local6 * _local8);
_local11.b = (-(_local6) * _local9);
_local11.c = _local7;
_local11.e = ((_local4 * _local9) + (_local10 * _local8));
_local11.f = ((_local4 * _local8) - (_local10 * _local9));
_local11.g = (-(_local5) * _local6);
_local11.i = ((_local5 * _local9) - ((_local4 * _local8) * _local7));
_local11.j = ((_local5 * _local8) + ((_local4 * _local7) * _local9));
_local11.k = (_local4 * _local6);
return (_local11);
}
public static function inverseTransformMatrix(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0, _arg5:Number=0, _arg6:Number=0, _arg7:Number=1, _arg8:Number=1, _arg9:Number=1):Matrix3D{
var _local10:Matrix3D = inverseTranslateMatrix(_arg1, _arg2, _arg3);
_local10.inverseRotate(_arg4, _arg5, _arg6);
_local10.inverseScale(_arg7, _arg8, _arg9);
return (_local10);
}
public static function translateMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Matrix3D = new (Matrix3D);
_local4.d = _arg1;
_local4.h = _arg2;
_local4.l = _arg3;
return (_local4);
}
public static function inverseScaleMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Matrix3D = new (Matrix3D);
_local4.a = (1 / _arg1);
_local4.f = (1 / _arg2);
_local4.k = (1 / _arg3);
return (_local4);
}
public static function scaleMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Matrix3D = new (Matrix3D);
_local4.a = _arg1;
_local4.f = _arg2;
_local4.k = _arg3;
return (_local4);
}
public static function rotateMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Number = Math.cos(_arg1);
var _local5:Number = Math.sin(_arg1);
var _local6:Number = Math.cos(_arg2);
var _local7:Number = Math.sin(_arg2);
var _local8:Number = Math.cos(_arg3);
var _local9:Number = Math.sin(_arg3);
var _local10:Number = (_local8 * _local7);
var _local11:Number = (_local9 * _local7);
var _local12:Matrix3D = new (Matrix3D);
_local12.a = (_local8 * _local6);
_local12.b = ((_local10 * _local5) - (_local9 * _local4));
_local12.c = ((_local10 * _local4) + (_local9 * _local5));
_local12.e = (_local9 * _local6);
_local12.f = ((_local11 * _local5) + (_local8 * _local4));
_local12.g = ((_local11 * _local4) - (_local8 * _local5));
_local12.i = -(_local7);
_local12.j = (_local6 * _local5);
_local12.k = (_local6 * _local4);
return (_local12);
}
public static function transformMatrix(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0, _arg4:Number=0, _arg5:Number=0, _arg6:Number=0, _arg7:Number=1, _arg8:Number=1, _arg9:Number=1):Matrix3D{
var _local10:Number = Math.cos(_arg4);
var _local11:Number = Math.sin(_arg4);
var _local12:Number = Math.cos(_arg5);
var _local13:Number = Math.sin(_arg5);
var _local14:Number = Math.cos(_arg6);
var _local15:Number = Math.sin(_arg6);
var _local16:Number = (_local14 * _local13);
var _local17:Number = (_local15 * _local13);
var _local18:Matrix3D = new (Matrix3D);
_local18.a = ((_local14 * _local12) * _arg7);
_local18.b = (((_local16 * _local11) - (_local15 * _local10)) * _arg8);
_local18.c = (((_local16 * _local10) + (_local15 * _local11)) * _arg9);
_local18.d = _arg1;
_local18.e = ((_local15 * _local12) * _arg7);
_local18.f = (((_local17 * _local11) + (_local14 * _local10)) * _arg8);
_local18.g = (((_local17 * _local10) - (_local14 * _local11)) * _arg9);
_local18.h = _arg2;
_local18.i = (-(_local13) * _arg7);
_local18.j = ((_local12 * _local11) * _arg8);
_local18.k = ((_local12 * _local10) * _arg9);
_local18.l = _arg3;
return (_local18);
}
public static function product(_arg1:Matrix3D, _arg2:Matrix3D):Matrix3D{
var _local3:Matrix3D = _arg2.clone();
_local3.combine(_arg1);
return (_local3);
}
public static function inverseTranslateMatrix(_arg1:Number, _arg2:Number, _arg3:Number):Matrix3D{
var _local4:Matrix3D = new (Matrix3D);
_local4.d = -(_arg1);
_local4.h = -(_arg2);
_local4.l = -(_arg3);
return (_local4);
}
}
}//package com.alternativagame.type
Section 34
//Point3D (com.alternativagame.type.Point3D)
package com.alternativagame.type {
import flash.geom.*;
import com.alternativagame.utility.*;
public final class Point3D {
public var x:Number;
public var y:Number;
public var z:Number;
public function Point3D(_arg1:Number=0, _arg2:Number=0, _arg3:Number=0){
this.x = _arg1;
this.y = _arg2;
this.z = _arg3;
}
public function transform(_arg1:Matrix3D):void{
var _local2:Number = x;
var _local3:Number = y;
var _local4:Number = z;
x = ((((_arg1.a * _local2) + (_arg1.b * _local3)) + (_arg1.c * _local4)) + _arg1.d);
y = ((((_arg1.e * _local2) + (_arg1.f * _local3)) + (_arg1.g * _local4)) + _arg1.h);
z = ((((_arg1.i * _local2) + (_arg1.j * _local3)) + (_arg1.k * _local4)) + _arg1.l);
}
public function add(_arg1:Point3D):void{
x = (x + _arg1.x);
y = (y + _arg1.y);
z = (z + _arg1.z);
}
public function toString():String{
return (((((("X: " + x.toFixed(3)) + " Y:") + y.toFixed(3)) + " Z:") + z.toFixed(3)));
}
public function multiply(_arg1:Number):void{
x = (x * _arg1);
y = (y * _arg1);
z = (z * _arg1);
}
public function floor():void{
x = Math.floor(x);
y = Math.floor(y);
z = Math.floor(z);
}
public function get length():Number{
return (Math.sqrt((((x * x) + (y * y)) + (z * z))));
}
public function set length(_arg1:Number):void{
var _local2:Number = length;
var _local3:Number = ((_local2)!=0) ? (_arg1 / length) : 0;
x = (x * _local3);
y = (y * _local3);
z = (z * _local3);
}
public function normalize():void{
length = 1;
}
public function get lengthSqr():Number{
return ((((x * x) + (y * y)) + (z * z)));
}
public function reset():void{
x = 0;
y = 0;
z = 0;
}
public function round():void{
x = Math.round(x);
y = Math.round(y);
z = Math.round(z);
}
public function invert():void{
x = -(x);
y = -(y);
z = -(z);
}
public function toPoint():Point{
return (new Point(x, y));
}
public function subtract(_arg1:Point3D):void{
x = (x - _arg1.x);
y = (y - _arg1.y);
z = (z - _arg1.z);
}
public function copy(_arg1:Point3D):void{
x = _arg1.x;
y = _arg1.y;
z = _arg1.z;
}
public function clone():Point3D{
return (new Point3D(x, y, z));
}
public function equals(_arg1:Point3D, _arg2:Number=0):Boolean{
var _local3:Point3D = difference(this, _arg1);
return ((((((Math.abs(_local3.x) <= _arg2)) && ((Math.abs(_local3.y) <= _arg2)))) && ((Math.abs(_local3.z) <= _arg2))));
}
public static function cross(_arg1:Point3D, _arg2:Point3D):Point3D{
return (new Point3D(((_arg1.y * _arg2.z) - (_arg1.z * _arg2.y)), ((_arg1.z * _arg2.x) - (_arg1.x * _arg2.z)), ((_arg1.x * _arg2.y) - (_arg1.y * _arg2.x))));
}
public static function cross2D(_arg1:Point3D, _arg2:Point3D):Number{
return (((_arg1.x * _arg2.y) - (_arg1.y * _arg2.x)));
}
public static function angle(_arg1:Point3D, _arg2:Point3D):Number{
var _local3:Number = (_arg1.length * _arg2.length);
var _local4:Number = ((_local3)!=0) ? (dot(_arg1, _arg2) / _local3) : 1;
return (Math.acos(_local4));
}
public static function average(_arg1:Point3D, _arg2:Point3D=null, _arg3:Point3D=null, _arg4:Point3D=null):Point3D{
if (_arg2 == null){
return (_arg1.clone());
};
if (_arg3 == null){
return (new Point3D(((_arg1.x + _arg2.x) / 2), ((_arg1.y + _arg2.y) / 2), ((_arg1.z + _arg2.z) / 2)));
};
if (_arg4 == null){
return (new Point3D((((_arg1.x + _arg2.x) + _arg3.x) / 3), (((_arg1.y + _arg2.y) + _arg3.y) / 3), (((_arg1.z + _arg2.z) + _arg3.z) / 3)));
};
return (new Point3D(((((_arg1.x + _arg2.x) + _arg3.x) + _arg4.x) / 4), ((((_arg1.y + _arg2.y) + _arg3.y) + _arg4.y) / 4), ((((_arg1.z + _arg2.z) + _arg3.z) + _arg4.z) / 4)));
}
public static function random(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number, _arg5:Number, _arg6:Number):Point3D{
return (new Point3D(MathUtility.random(_arg1, _arg2), MathUtility.random(_arg3, _arg4), MathUtility.random(_arg5, _arg6)));
}
public static function interpolate(_arg1:Point3D, _arg2:Point3D, _arg3:Number=0.5):Point3D{
return (new Point3D((_arg1.x + ((_arg2.x - _arg1.x) * _arg3)), (_arg1.y + ((_arg2.y - _arg1.y) * _arg3)), (_arg1.z + ((_arg2.z - _arg1.z) * _arg3))));
}
public static function dot(_arg1:Point3D, _arg2:Point3D):Number{
return ((((_arg1.x * _arg2.x) + (_arg1.y * _arg2.y)) + (_arg1.z * _arg2.z)));
}
public static function sum(_arg1:Point3D, _arg2:Point3D):Point3D{
return (new Point3D((_arg1.x + _arg2.x), (_arg1.y + _arg2.y), (_arg1.z + _arg2.z)));
}
public static function dot2D(_arg1:Point3D, _arg2:Point3D):Number{
return (((_arg1.x * _arg2.x) + (_arg1.y * _arg2.y)));
}
public static function difference(_arg1:Point3D, _arg2:Point3D):Point3D{
return (new Point3D((_arg1.x - _arg2.x), (_arg1.y - _arg2.y), (_arg1.z - _arg2.z)));
}
public static function angleFast(_arg1:Point3D, _arg2:Point3D):Number{
var _local3:Number = dot(_arg1, _arg2);
if (Math.abs(_local3) > 1){
_local3 = ((_local3)>0) ? 1 : -1;
};
return (Math.acos(_local3));
}
}
}//package com.alternativagame.type
Section 35
//RGB (com.alternativagame.type.RGB)
package com.alternativagame.type {
import com.alternativagame.utility.*;
public final class RGB {
public var green:uint;// = 0
public var red:uint;// = 0
public var blue:uint;// = 0
public function RGB(... _args){
if (_args.length > 0){
if (_args.length > 1){
red = _args[0];
green = _args[1];
blue = _args[2];
} else {
red = ((_args[0] & 0xFF0000) >>> 16);
green = ((_args[0] & 0xFF00) >>> 8);
blue = (_args[0] & 0xFF);
};
};
}
public function add(_arg1:RGB):void{
red = (red + _arg1.red);
green = (green + _arg1.green);
blue = (blue + _arg1.blue);
}
public function multiply(_arg1:Number):void{
red = (red * _arg1);
green = (green * _arg1);
blue = (blue * _arg1);
}
public function subtract(_arg1:RGB):void{
red = ((red)<_arg1.red) ? 0 : (red - _arg1.red);
green = ((green)<_arg1.green) ? 0 : (green - _arg1.green);
blue = ((blue)<_arg1.blue) ? 0 : (blue - _arg1.blue);
}
public function toString():String{
var _local1:String = red.toString(16).toUpperCase();
var _local2:String = green.toString(16).toUpperCase();
var _local3:String = blue.toString(16).toUpperCase();
_local1 = ((_local1.length)==1) ? ("0" + _local1) : _local1;
_local2 = ((_local2.length)==1) ? ("0" + _local2) : _local2;
_local3 = ((_local3.length)==1) ? ("0" + _local3) : _local3;
return ((((("[RGB: " + _local1) + _local2) + _local3) + "]"));
}
public function toInt():uint{
return ((((((red >>> 8)) ? 0xFF : red << 16) + (((green >>> 8)) ? 0xFF : green << 8)) + ((blue >>> 8)) ? 0xFF : blue));
}
public function clone():RGB{
return (new RGB(red, green, blue));
}
public function equals(_arg1:RGB):Boolean{
return ((((((red == _arg1.red)) && ((green == _arg1.green)))) && ((blue == _arg1.blue))));
}
public static function random(_arg1:uint=0, _arg2:uint=0xFF, _arg3:uint=0, _arg4:uint=0xFF, _arg5:uint=0, _arg6:uint=0xFF):RGB{
return (new RGB(MathUtility.random(_arg1, _arg2), MathUtility.random(_arg3, _arg4), MathUtility.random(_arg5, _arg6)));
}
public static function average(_arg1:RGB, _arg2:RGB):RGB{
return (new RGB(((_arg1.red + _arg2.red) >>> 1), ((_arg1.green + _arg2.green) >>> 1), ((_arg1.blue + _arg2.blue) >>> 1)));
}
}
}//package com.alternativagame.type
Section 36
//Set (com.alternativagame.type.Set)
package com.alternativagame.type {
import flash.utils.*;
import com.alternativagame.utility.*;
public final class Set extends Dictionary {
private var weakKeys:Boolean;
public function Set(_arg1:Boolean=false):void{
this.weakKeys = _arg1;
super(_arg1);
}
public function add(_arg1):void{
this[_arg1] = _arg1;
}
public function remove(_arg1):void{
delete this[_arg1];
}
public function get length():uint{
var _local2:*;
var _local1:uint;
for each (_local2 in this) {
_local1++;
};
return (_local1);
}
public function clear():void{
var _local1:*;
for each (_local1 in this) {
delete this[_local1];
};
}
public function toString():String{
var _local2:*;
var _local1 = "";
for each (_local2 in this) {
_local1 = (_local1 + ("," + _local2.toString()));
};
return (_local1.substring(1));
}
public function first(){
var _local1:*;
for each (_local1 in this) {
return (_local1);
};
return (null);
}
public function concat(_arg1:Set):void{
var _local2:*;
for (_local2 in _arg1) {
this[_local2] = _local2;
};
}
public function has(_arg1):Boolean{
return (!((this[_arg1] == undefined)));
}
public function any(){
var _local3:*;
var _local1:uint;
var _local2:uint = MathUtility.random(0, length);
for each (_local3 in this) {
if (_local1 == _local2){
return (_local3);
};
_local1++;
};
return (null);
}
public function clone():Set{
var _local2:*;
var _local1:Set = new Set(weakKeys);
for each (_local2 in this) {
_local1.add(_local2);
};
return (_local1);
}
}
}//package com.alternativagame.type
Section 37
//MathUtility (com.alternativagame.utility.MathUtility)
package com.alternativagame.utility {
import flash.geom.*;
public final class MathUtility {
public static const degree60:Number = (Math.PI / 3);
private static const toDeg:Number = (180 / Math.PI);
public static const degree45:Number = (Math.PI / 4);
private static const toRad:Number = (Math.PI / 180);
public static const degree180:Number = Math.PI;
public static const degree360:Number = (Math.PI + Math.PI);
public static const degree90:Number = (Math.PI / 2);
public static const degree1:Number = toRad;
public static const degree30:Number = (Math.PI / 6);
public static const degree10:Number = (Math.PI / 18);
public static const degree5:Number = (Math.PI / 36);
public static function random(_arg1:Number=0, _arg2:Number=0):Number{
if (arguments.length == 0){
return (Math.random());
};
if (arguments.length == 1){
return ((Math.random() * _arg1));
};
return (((Math.random() * (_arg2 - _arg1)) + _arg1));
}
public static function segmentDistance(_arg1:Point, _arg2:Point, _arg3:Point):Number{
var _local4:Number = (_arg2.x - _arg1.x);
var _local5:Number = (_arg2.y - _arg1.y);
var _local6:Number = (_arg3.x - _arg1.x);
var _local7:Number = (_arg3.y - _arg1.y);
return ((((_local4 * _local7) - (_local5 * _local6)) / Math.sqrt(((_local4 * _local4) + (_local5 * _local5)))));
}
public static function randomAngle():Number{
return ((Math.random() * degree360));
}
public static function vectorAngle(_arg1:Point, _arg2:Point):Number{
var _local3:Number = (_arg1.length * _arg2.length);
var _local4:Number = ((_local3)!=0) ? (vectorDot(_arg1, _arg2) / _local3) : 1;
return (Math.acos(_local4));
}
public static function limitAngle(_arg1:Number):Number{
var _local2:Number = (_arg1 % degree360);
_local2 = ((_local2)>0) ? ((_local2)>degree180) ? (_local2 - degree360) : _local2 : ((_local2)<-(degree180)) ? (_local2 + degree360) : _local2;
return (_local2);
}
public static function vectorDot(_arg1:Point, _arg2:Point):Number{
return (((_arg1.x * _arg2.x) + (_arg1.y * _arg2.y)));
}
public static function toDegree(_arg1:Number):Number{
return ((_arg1 * toDeg));
}
public static function deltaAngle(_arg1:Number, _arg2:Number):Number{
var _local3:Number = (_arg2 - _arg1);
if (_local3 > degree180){
return ((_local3 - degree360));
};
if (_local3 < -(degree180)){
return ((_local3 + degree360));
};
return (_local3);
}
public static function toRadian(_arg1:Number):Number{
return ((_arg1 * toRad));
}
public static function vectorCross(_arg1:Point, _arg2:Point):Number{
return (((_arg1.x * _arg2.y) - (_arg1.y * _arg2.x)));
}
public static function triangleHasPoint(_arg1:Point, _arg2:Point, _arg3:Point, _arg4:Point):Boolean{
if (vectorCross(_arg3.subtract(_arg1), _arg4.subtract(_arg1)) <= 0){
if (vectorCross(_arg2.subtract(_arg3), _arg4.subtract(_arg3)) <= 0){
if (vectorCross(_arg1.subtract(_arg2), _arg4.subtract(_arg2)) <= 0){
return (true);
};
return (false);
} else {
return (false);
};
//unresolved jump
};
return (false);
}
}
}//package com.alternativagame.utility
Section 38
//MouseUtility (com.alternativagame.utility.MouseUtility)
package com.alternativagame.utility {
import flash.display.*;
import flash.geom.*;
public class MouseUtility {
private static var _stage:Stage = null;
public static function init(_arg1:Stage):void{
_stage = _arg1;
}
public static function localCoords(_arg1:DisplayObject):Point{
return (_arg1.globalToLocal(globalCoords()));
}
public static function globalCoords(_arg1:Boolean=true):Point{
var _local3:int;
var _local4:int;
var _local2:Point;
if (_stage != null){
_local3 = _stage.mouseX;
_local4 = _stage.mouseY;
if (_arg1){
_local3 = ((_local3)<0) ? 0 : ((_local3)>_stage.stageWidth) ? _stage.stageWidth : _local3;
_local4 = ((_local4)<0) ? 0 : ((_local4)>_stage.stageHeight) ? _stage.stageHeight : _local4;
};
_local2 = new Point(_local3, _local4);
} else {
throw (new Error("MouseUtility don't have link to stage. Use MouseUtility.init(stage) before."));
};
return (_local2);
}
}
}//package com.alternativagame.utility
Section 39
//ObjectUtility (com.alternativagame.utility.ObjectUtility)
package com.alternativagame.utility {
import flash.utils.*;
public class ObjectUtility {
public static function getClassTree(_arg1, _arg2:Class=null):Array{
var _local3:Array = new Array();
var _local4:Class = Class(getDefinitionByName(getQualifiedClassName(_arg1)));
_arg2 = ((_arg2)==null) ? Object : _arg2;
while (_local4 != _arg2) {
_local3.push(_local4);
_local4 = Class(getDefinitionByName(getQualifiedSuperclassName(_local4)));
};
_local3.push(_local4);
return (_local3);
}
public static function getClassName(_arg1):String{
var _local2:String = getQualifiedClassName(_arg1);
return (_local2.substring((_local2.indexOf("::") + 2)));
}
}
}//package com.alternativagame.utility
Section 40
//BitmapAsset (mx.core.BitmapAsset)
package mx.core {
import flash.display.*;
public class BitmapAsset extends FlexBitmap implements IFlexAsset, IFlexDisplayObject {
mx_internal static const VERSION:String = "3.0.0.0";
public function BitmapAsset(_arg1:BitmapData=null, _arg2:String="auto", _arg3:Boolean=false){
super(_arg1, _arg2, _arg3);
}
public function get measuredHeight():Number{
if (bitmapData){
return (bitmapData.height);
};
return (0);
}
public function move(_arg1:Number, _arg2:Number):void{
this.x = _arg1;
this.y = _arg2;
}
public function get measuredWidth():Number{
if (bitmapData){
return (bitmapData.width);
};
return (0);
}
public function setActualSize(_arg1:Number, _arg2:Number):void{
width = _arg1;
height = _arg2;
}
}
}//package mx.core
Section 41
//FlexBitmap (mx.core.FlexBitmap)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexBitmap extends Bitmap {
mx_internal static const VERSION:String = "3.0.0.0";
public function FlexBitmap(_arg1:BitmapData=null, _arg2:String="auto", _arg3:Boolean=false){
var bitmapData = _arg1;
var pixelSnapping = _arg2;
var smoothing = _arg3;
super(bitmapData, pixelSnapping, smoothing);
try {
name = NameUtil.createUniqueName(this);
} catch(e:Error) {
};
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 42
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 43
//IFlexDisplayObject (mx.core.IFlexDisplayObject)
package mx.core {
import flash.events.*;
import flash.display.*;
public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher {
function get y():Number;
function get width():Number;
function get name():String;
function set width(_arg1:Number):void;
function get measuredHeight():Number;
function get scaleX():Number;
function get scaleY():Number;
function move(_arg1:Number, _arg2:Number):void;
function set height(_arg1:Number):void;
function set name(_arg1:String):void;
function set mask(_arg1:DisplayObject):void;
function set scaleX(_arg1:Number):void;
function set scaleY(_arg1:Number):void;
function get measuredWidth():Number;
function set visible(_arg1:Boolean):void;
function get alpha():Number;
function get height():Number;
function get parent():DisplayObjectContainer;
function get mask():DisplayObject;
function set x(_arg1:Number):void;
function setActualSize(_arg1:Number, _arg2:Number):void;
function get visible():Boolean;
function get x():Number;
function set y(_arg1:Number):void;
function set alpha(_arg1:Number):void;
}
}//package mx.core
Section 44
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(_arg1:Array):void;
function get isDocument():Boolean;
function set repeaters(_arg1:Array):void;
function initializeRepeaterArrays(_arg1:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(_arg1:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 45
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 46
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import mx.core.*;
import flash.utils.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.0.0.0";
private static var counter:int = 0;
public static function displayObjectToString(_arg1:DisplayObject):String{
var _local2:String;
var _local4:String;
var _local5:Array;
var _local3:DisplayObject = _arg1;
while (_local3 != null) {
if (((((_local3.parent) && (_local3.stage))) && ((_local3.parent == _local3.stage)))){
break;
};
_local4 = _local3.name;
if ((_local3 is IRepeaterClient)){
_local5 = IRepeaterClient(_local3).instanceIndices;
if (_local5){
_local4 = (_local4 + (("[" + _local5.join("][")) + "]"));
};
};
_local2 = ((_local2 == null)) ? _local4 : ((_local4 + ".") + _local2);
_local3 = _local3.parent;
};
return (_local2);
}
public static function createUniqueName(_arg1:Object):String{
if (!_arg1){
return (null);
};
var _local2:String = getQualifiedClassName(_arg1);
var _local3:int = _local2.indexOf("::");
if (_local3 != -1){
_local2 = _local2.substr((_local3 + 2));
};
var _local4:int = _local2.charCodeAt((_local2.length - 1));
if ((((_local4 >= 48)) && ((_local4 <= 57)))){
_local2 = (_local2 + "_");
};
return ((_local2 + counter++));
}
}
}//package mx.utils
Section 47
//Test3D (Test3D)
package {
import flash.events.*;
import com.alternativagame.engine3d.*;
import com.alternativagame.type.*;
import flash.display.*;
import flash.geom.*;
import com.alternativagame.engine3d.primitive.*;
import com.alternativagame.admin.*;
import flash.text.*;
import com.alternativagame.utility.*;
import flash.ui.*;
public class Test3D extends Sprite {
private var lights1:Object3D;
private var anim:Boolean;// = true
private var lightLayer:Boolean;// = false
private var plane:Mesh;
private var mode:uint;// = 0
private var view:View;
private var drag:Point;
private var lights2:Object3D;
private var object:Object3D;
private static const dryTexture:TextureData = new TextureData(new bmpDryTexture().bitmapData, 2);
private static const grassTexture:TextureData = new TextureData(new bmpGrassTexture().bitmapData, 1);
private static const bmpGrassTexture:Class = Test3D_bmpGrassTexture;
private static const bmpDryTexture:Class = Test3D_bmpDryTexture;
public function Test3D(){
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 100;
var _local1:TextField = new TextField();
_local1.defaultTextFormat = new TextFormat("Tahoma", 10, 0x666666);
_local1.autoSize = TextFieldAutoSize.LEFT;
_local1.selectable = false;
_local1.appendText("Spacebar - start/stop animation\n");
_local1.appendText("Enter - change object\n");
_local1.appendText("Mouse wheel/Down/Up - change scale\n");
_local1.appendText("Ctrl + Mouse wheel/Left/Right - tex quality\n");
_local1.appendText("L - static lightmap/dynamic lightmap\n");
_local1.appendText("Q - tex interpolation on/off\n");
addChild(_local1);
mouseEnabled = false;
MouseUtility.init(stage);
view = new View(stage.stageWidth, stage.stageHeight);
view.pitch = -(MathUtility.degree30);
view.yaw = MathUtility.degree30;
view.zoom = 0.75;
addChild(view);
FPS.init(this);
view.object = new Object3D();
lights1 = new Object3D();
lights2 = new Object3D();
view.object.attach(lights1);
view.object.attach(lights2);
view.object.attach(new Ambient(new RGB(0x202020)));
var _local2:Directional = new Directional(new RGB(0xFF9900));
_local2.addRenderer(new HelperRenderer(false, false));
_local2.coords = new Point3D(0, -150, 300);
_local2.rotX = -(MathUtility.degree45);
lights1.attach(_local2);
_local2 = new Directional(new RGB(26265));
_local2.addRenderer(new HelperRenderer(false, false));
_local2.coords = new Point3D(100, -200, 200);
_local2.rotX = -(MathUtility.degree45);
_local2.rotZ = MathUtility.degree30;
lights2.attach(_local2);
TextureRenderer.textureResolution = 7;
TextureRenderer.lightMapResolution = 10;
var _local3:TextureRenderer = new TextureRenderer(2);
plane = new Box(700, 700, 700, _local3, 1, 1, 1, true);
view.object.attach(plane);
var _local4:PolyTextureObject = new PolyTextureObject(null, dryTexture, new Point3D(-400, -400, 400), new Point3D(-400, -400, -400), new Point3D(400, 400, -400), new Point3D(400, 400, 400));
_local3 = TextureRenderer(plane.getRendererByName(Box.FRONT));
_local3.addTextureObject(_local4.clone());
_local3 = TextureRenderer(plane.getRendererByName(Box.BACK));
_local3.addTextureObject(_local4.clone());
_local3 = TextureRenderer(plane.getRendererByName(Box.LEFT));
_local3.addTextureObject(_local4.clone());
_local3 = TextureRenderer(plane.getRendererByName(Box.RIGHT));
_local3.addTextureObject(_local4.clone());
_local4 = new PolyTextureObject(null, grassTexture, new Point3D(-400, -400, 0), new Point3D(-400, 400, 0), new Point3D(400, 400, 0), new Point3D(400, -400, 0));
_local3 = TextureRenderer(plane.getRendererByName(Box.TOP));
_local3.addTextureObject(_local4.clone());
_local3 = TextureRenderer(plane.getRendererByName(Box.BOTTOM));
_local3.addTextureObject(_local4.clone());
object = new Object3D();
view.object.attach(object);
setMode(mode);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(Event.RESIZE, onResize);
}
private function onMouseUp(_arg1:MouseEvent):void{
drag = null;
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onKeyDown(_arg1:KeyboardEvent):void{
switch (_arg1.keyCode){
case 81:
TextureRenderer.smooth = !(TextureRenderer.smooth);
break;
case Keyboard.UP:
view.zoom = (view.zoom * 1.5);
break;
case Keyboard.DOWN:
view.zoom = (view.zoom / 1.5);
break;
case Keyboard.LEFT:
TextureRenderer.textureResolution = (TextureRenderer.textureResolution + 1);
break;
case Keyboard.RIGHT:
TextureRenderer.textureResolution = (TextureRenderer.textureResolution - 1);
break;
case 76:
lightLayer = !(lightLayer);
setMode(mode);
break;
case Keyboard.SPACE:
anim = !(anim);
break;
case Keyboard.ENTER:
mode = ((mode)>=3) ? 0 : (mode + 1);
setMode(mode);
break;
};
}
private function onMouseDown(_arg1:MouseEvent):void{
drag = MouseUtility.globalCoords(false);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function setMode(_arg1:uint):void{
var _local2:TextureRenderer;
var _local3:Set;
var _local4:Object3D;
var _local5:Mesh;
var _local6:Array;
var _local7:Array;
var _local8:ShadowTextureObject;
for each (_local2 in plane.renderers) {
_local6 = _local2.getTextureObjects(TextureRenderer.LIGHT_LAYER);
_local7 = _local2.getTextureObjects(TextureRenderer.DYNAMIC_LAYER);
if (_local6 != null){
for each (_local8 in _local6) {
_local2.removeTextureObject(_local8);
};
};
if (_local7 != null){
for each (_local8 in _local7) {
_local2.removeTextureObject(_local8);
};
};
};
_local3 = object.objects.clone();
for each (_local4 in _local3) {
object.detach(_local4);
};
switch (_arg1){
case 0:
_local5 = new Box(150, 300, 150, new FillRenderer(new RGB(0xCCCCCC), 1, 2));
break;
case 1:
_local5 = new Cone(300, 200, 0, new FillRenderer(new RGB(0xCCCCCC), 1, 2), 1, 3);
break;
case 2:
_local5 = new Cone(300, 100, 100, new FillRenderer(new RGB(0xCCCCCC), 1, 2));
break;
case 3:
_local5 = new GeoSphere(200, new FillRenderer(new RGB(0xCCCCCC), 1, 2), 1);
break;
};
object.attach(_local5);
for each (_local2 in plane.renderers) {
_local2.addTextureObject(new ShadowTextureObject(_local5), -1, (lightLayer) ? TextureRenderer.LIGHT_LAYER : TextureRenderer.DYNAMIC_LAYER);
};
}
private function onEnterFrame(_arg1:Event):void{
if (anim){
lights1.rotX = (lights1.rotX + 0.02);
lights1.rotY = (lights1.rotY + 0.015);
lights1.rotZ = (lights1.rotZ + 0.01);
lights2.rotX = (lights2.rotX + 0.01);
lights2.rotY = (lights2.rotY + 0.01);
lights2.rotZ = (lights2.rotZ + 0.02);
object.rotX = (object.rotX + 0.012);
object.rotY = (object.rotY + 0.016);
object.rotZ = (object.rotZ + 0.02);
};
view.render();
}
private function onMouseWheel(_arg1:MouseEvent):void{
if (_arg1.ctrlKey){
TextureRenderer.textureResolution = (TextureRenderer.textureResolution - (_arg1.delta / 3));
} else {
view.zoom = (view.zoom * (1 + (_arg1.delta / 20)));
view.zoom = ((view.zoom)<0.1) ? 0.1 : ((view.zoom > 10)) ? 10 : view.zoom;
};
}
private function onMouseMove(_arg1:MouseEvent):void{
var _local2:Point = MouseUtility.globalCoords(false);
var _local3:Point = drag.subtract(_local2);
view.yaw = (view.yaw + (_local3.x / 100));
view.pitch = (view.pitch + (_local3.y / 100));
drag = _local2;
}
private function onResize(_arg1:Event):void{
view.width = stage.stageWidth;
view.height = stage.stageHeight;
}
}
}//package
Section 48
//Test3D_bmpDryTexture (Test3D_bmpDryTexture)
package {
import mx.core.*;
public class Test3D_bmpDryTexture extends BitmapAsset {
}
}//package
Section 49
//Test3D_bmpGrassTexture (Test3D_bmpGrassTexture)
package {
import mx.core.*;
public class Test3D_bmpGrassTexture extends BitmapAsset {
}
}//package