Section 1
//DebugDispatcher (com.blitzagency.xray.logger.events.DebugDispatcher)
package com.blitzagency.xray.logger.events {
import flash.events.*;
public class DebugDispatcher extends EventDispatcher {
public static var TRACE:String = "trace";
public function DebugDispatcher(){
super();
}
public function sendEvent(eventName:String, obj:Object):void{
trace(obj.message);
dispatchEvent(new DebugEvent(DebugDispatcher.TRACE, false, false, obj));
}
}
}//package com.blitzagency.xray.logger.events
Section 2
//DebugEvent (com.blitzagency.xray.logger.events.DebugEvent)
package com.blitzagency.xray.logger.events {
import flash.events.*;
public class DebugEvent extends Event {
public var obj:Object;
public function DebugEvent(type:String, bubbles:Boolean, cancelable:Boolean, p_obj:Object):void{
obj = new Object();
super(type, bubbles, cancelable);
obj = p_obj;
}
}
}//package com.blitzagency.xray.logger.events
Section 3
//ObjectTools (com.blitzagency.xray.logger.util.ObjectTools)
package com.blitzagency.xray.logger.util {
import com.blitzagency.xray.logger.*;
import flash.utils.*;
public class ObjectTools {
private static var log:XrayLog = new XrayLog();
public function ObjectTools(){
super();
}
public function resolveBaseType(obj:Object):String{
return ("");
}
public static function getImmediateClassPath(obj:Object):String{
var className:String = getQualifiedClassName(obj);
var superClassName:String = getQualifiedSuperclassName(obj);
className = ((className.indexOf("::") > -1)) ? className.split("::").join(".") : className;
if (superClassName == null){
return (className);
};
superClassName = ((superClassName.indexOf("::") > -1)) ? superClassName.split("::").join(".") : superClassName;
return (((superClassName + ".") + className));
}
public static function getFullClassPath(obj:Object):String{
var item:XML;
var extClass:String;
var xmlDoc:XML = describeType(obj);
var ary:Array = [];
var className:String = getQualifiedClassName(obj);
className = ((className.indexOf("::") > -1)) ? className.split("::").join(".") : className;
ary.push(className);
for each (item in xmlDoc.extendsClass) {
extClass = ((item.@type.toString().indexOf("::") > -1)) ? item.@type.toString().split("::")[1] : item.@type.toString();
ary.push(extClass);
};
return (ary.join("."));
}
}
}//package com.blitzagency.xray.logger.util
Section 4
//PropertyTools (com.blitzagency.xray.logger.util.PropertyTools)
package com.blitzagency.xray.logger.util {
import flash.utils.*;
public class PropertyTools {
public function PropertyTools(){
super();
}
private static function getVariables():void{
}
public static function getProperties(obj:Object):Array{
var xmlDoc:XML;
var item:XML;
var name:String;
var type:String;
var value:Object;
var obj = obj;
var ary:Array = [];
xmlDoc = describeType(obj);
for each (item in xmlDoc.variable) {
name = item.@name.toString();
type = item.@type.toString();
value = ((obj[name])!=null) ? obj[name] : "";
ary.push({name:name, type:type, value:value});
};
//unresolved jump
var _slot1 = e;
return (ary);
}
private static function getMethods():void{
}
}
}//package com.blitzagency.xray.logger.util
Section 5
//Debug (com.blitzagency.xray.logger.Debug)
package com.blitzagency.xray.logger {
import flash.events.*;
import flash.utils.*;
import com.blitzagency.xray.logger.events.*;
import flash.net.*;
public class Debug {
private static var connected:Boolean = false;
private static var xrayLC:LocalConnection;
private static var ed:DebugDispatcher = new DebugDispatcher();
public function Debug(){
super();
}
public static function traceObject(o:Object, pRecurseDepth:Number=254, pIndent:Number=0, pPackage:String="", pLevel:Number=0):void{
var recurseDepth:Number;
var indent:Number;
var prop:String;
var lead:String;
var i:Number;
var obj:String;
var o = o;
var pRecurseDepth = pRecurseDepth;
var pIndent = pIndent;
var pPackage = pPackage;
var pLevel = pLevel;
recurseDepth = pRecurseDepth;
indent = pIndent;
for (prop in o) {
lead = "";
i = 0;
while (i < indent) {
lead = (lead + " ");
i = (i + 1);
};
obj = o[prop].toString();
if ((o[prop] is Array)){
obj = "[Array]";
};
if (obj == "[object Object]"){
obj = "[Object]";
};
Debug.trace((((lead + prop) + ": ") + obj), pPackage, pLevel);
if (recurseDepth > 0){
Debug.traceObject(o[prop], (recurseDepth - 1), (indent + 1), pPackage, pLevel);
};
};
//unresolved jump
var _slot1 = e;
}
public static function trace(pMsg:Object, pPackage:String="", pLevel:Number=0):void{
var msg:String;
var pMsg = pMsg;
var pPackage = pPackage;
var pLevel = pLevel;
ed.sendEvent(DebugDispatcher.TRACE, {message:pMsg, classPackage:pPackage});
if (!connected){
makeConnection();
};
if (connected){
msg = ((String(pMsg).length >= 39995)) ? (String(pMsg).substr(0, 39995) + "...") : String(pMsg);
xrayLC.send("_xray_view_conn", "setTrace", msg, pLevel, pPackage);
//unresolved jump
var _slot1 = e;
LogError("No Xray Interface running");
};
}
private static function makeConnection():void{
var err:LogError;
xrayLC = new LocalConnection();
xrayLC.addEventListener("status", statusHandler);
xrayLC.allowDomain("*");
try {
xrayLC.connect(("_xray_standAlone_debug" + getTimer()));
connected = true;
//unresolved jump
var _slot1 = e;
err = new LogError("log");
setTimeout(makeConnection, 1000);
} finally {
};
}
public static function addEventListener(type:String, listener:Function):void{
ed.addEventListener(type, listener);
}
private static function initialize():Boolean{
ed = new DebugDispatcher();
return (true);
}
private static function statusHandler(event:StatusEvent):void{
if ((((((event.code == null)) && ((event.level == "error")))) && (connected))){
connected = false;
} else {
if ((((event.level == "status")) && ((event.code == null)))){
connected = true;
};
};
}
}
}//package com.blitzagency.xray.logger
class LogError extends Error {
private function LogError(message:String){
super(message);
}
}
Section 6
//Log (com.blitzagency.xray.logger.Log)
package com.blitzagency.xray.logger {
import com.blitzagency.xray.logger.util.*;
public class Log {
private var level:Number;
private var message:String;
private var caller:String;// = ""
private var classPackage:String;
private var dump:Object;
public function Log(p_message:String, p_dump:Object, p_level:Number, ... _args){
var err:LogError;
var nullArray:Array;
var str:String;
var p_message = p_message;
var p_dump = p_dump;
var p_level = p_level;
var rest = _args;
super();
try {
nullArray.push("bogus");
//unresolved jump
var _slot1 = e;
err = new LogError("log");
} finally {
if (err.hasOwnProperty("getStackTrace")){
str = err.getStackTrace();
setCaller(resolveCaller(str));
} else {
setCaller("");
};
setMessage(p_message);
setDump(p_dump);
setLevel(p_level);
setClassPackage(p_dump);
};
}
public function getCaller():String{
return (caller);
}
public function setLevel(p_level:Number):void{
level = p_level;
}
public function setMessage(p_message:String):void{
message = p_message;
}
public function getLevel():Number{
return (level);
}
public function getDump():Object{
return (dump);
}
public function setCaller(p_caller:String):void{
caller = p_caller;
}
public function setClassPackage(obj:Object):void{
classPackage = ObjectTools.getImmediateClassPath(obj);
}
public function getMessage():String{
return (message);
}
private function resolveCaller(str:String):String{
var str = str;
var ary:Array = [];
try {
str = str.split("\n").join("");
ary = str.split("\tat ");
str = ary[3];
//unresolved jump
var _slot1 = e;
} finally {
str = "";
};
return (str);
}
public function getClassPackage():String{
return (classPackage);
}
public function setDump(p_dump:Object):void{
dump = p_dump;
}
}
}//package com.blitzagency.xray.logger
class LogError extends Error {
private function LogError(message:String){
super(message);
}
}
Section 7
//Logger (com.blitzagency.xray.logger.Logger)
package com.blitzagency.xray.logger {
public interface Logger {
function setLevel(:Number=0):void;
function debug(:Log):void;
function fatal(:Log):void;
function warn(:Log):void;
function error(:Log):void;
function log(_arg1:String, _arg2:String, _arg3:String, _arg4:Number, _arg5:Object=null):void;
function info(:Log):void;
}
}//package com.blitzagency.xray.logger
Section 8
//XrayLog (com.blitzagency.xray.logger.XrayLog)
package com.blitzagency.xray.logger {
public class XrayLog {
private var logger:XrayLogger;
public function XrayLog(){
super();
logger = XrayLogger.getInstance();
}
public function debug(message:String, ... _args):void{
if (_args.length == 0){
logger.debug(new Log(message, null, XrayLogger.DEBUG));
};
var i:Number = 0;
while (i < _args.length) {
if (i > 0){
message = "";
};
logger.debug(new Log(message, _args[i], XrayLogger.DEBUG));
i++;
};
}
public function fatal(message:String, ... _args):void{
if (_args.length == 0){
logger.fatal(new Log(message, null, XrayLogger.FATAL));
};
var i:Number = 0;
while (i < _args.length) {
if (i > 0){
message = "";
};
logger.fatal(new Log(message, _args[i], XrayLogger.FATAL));
i++;
};
}
public function warn(message:String, ... _args):void{
if (_args.length == 0){
logger.warn(new Log(message, null, XrayLogger.WARN));
};
var i:Number = 0;
while (i < _args.length) {
if (i > 0){
message = "";
};
logger.warn(new Log(message, _args[i], XrayLogger.WARN));
i++;
};
}
public function error(message:String, ... _args):void{
if (_args.length == 0){
logger.error(new Log(message, null, XrayLogger.ERROR));
};
var i:Number = 0;
while (i < _args.length) {
if (i > 0){
message = "";
};
logger.error(new Log(message, _args[i], XrayLogger.ERROR));
i++;
};
}
public function info(message:String, ... _args):void{
if (_args.length == 0){
logger.info(new Log(message, null, XrayLogger.INFO));
};
var i:Number = 0;
while (i < _args.length) {
if (i > 0){
message = "";
};
logger.info(new Log(message, _args[i], XrayLogger.INFO));
i++;
};
}
}
}//package com.blitzagency.xray.logger
Section 9
//XrayLogger (com.blitzagency.xray.logger.XrayLogger)
package com.blitzagency.xray.logger {
import flash.events.*;
import flash.utils.*;
import com.blitzagency.xray.logger.util.*;
public class XrayLogger extends EventDispatcher implements Logger {
private var displayObjectRecursionDepth:Number;// = 3
private var level:Number;// = 0
private var indentation:Number;// = 0
private var objectRecursionDepth:Number;// = 254
private var filters:Array;
public static var FATAL:Number = 4;
public static var WARN:Number = 2;
public static var ERROR:Number = 3;
public static var INFO:Number = 1;
public static var DEBUG:Number = 0;
private static var _instance:XrayLogger = null;
public static var NONE:Number = 5;
public function XrayLogger(){
filters = [];
super();
}
public function warn(obj:Log):void{
if (obj.getLevel() >= level){
log(obj.getMessage(), obj.getCaller(), obj.getClassPackage(), 2, obj.getDump());
};
}
public function setIndentation(p_indentation:Number=0):void{
indentation = p_indentation;
}
public function setLevel(p_level:Number=0):void{
level = p_level;
}
public function debug(obj:Log):void{
if (obj.getLevel() == level){
log(obj.getMessage(), obj.getCaller(), obj.getClassPackage(), 0, obj.getDump());
};
}
public function error(obj:Log):void{
if (obj.getLevel() >= level){
log(obj.getMessage(), obj.getCaller(), obj.getClassPackage(), 3, obj.getDump());
};
}
public function setDisplayClipRecursionDepth(p_recursionDepth:Number):void{
displayObjectRecursionDepth = p_recursionDepth;
}
public function fatal(obj:Log):void{
if (obj.getLevel() >= level){
log(obj.getMessage(), obj.getCaller(), obj.getClassPackage(), 4, obj.getDump());
};
}
public function setObjectRecursionDepth(p_recursionDepth:Number):void{
objectRecursionDepth = p_recursionDepth;
}
public function checkFilters():Boolean{
if (filters.length == 0){
return (true);
};
var i:uint;
while (i < filters.length) {
i++;
};
return (true);
}
public function log(message:String, caller:String, classPackage:String, level:Number, dump:Object=null):void{
var objType:String;
var obj:Object;
var traceMessage = (("(" + getTimer()) + ") ");
if (classPackage.length > 0){
traceMessage = (traceMessage + (caller + "\n"));
};
traceMessage = (traceMessage + message);
if (message.length > 0){
Debug.trace(traceMessage, classPackage, level);
};
if (dump == null){
return;
};
var type = typeof(dump);
if ((((((((((type == "string")) || ((type == "number")))) || ((type == "boolean")))) || ((type == "undefined")))) || ((type == "null")))){
Debug.trace(dump, classPackage, level);
} else {
if (type == "xml"){
Debug.trace(dump.toString(), classPackage, level);
} else {
objType = ObjectTools.getImmediateClassPath(dump);
if ((((objType == "Object")) || ((objType == "Object.Array")))){
Debug.traceObject(dump, objectRecursionDepth, indentation, classPackage, level);
} else {
obj = PropertyTools.getProperties(dump);
Debug.traceObject(obj, displayObjectRecursionDepth, indentation, classPackage, level);
};
};
};
}
public function info(obj:Log):void{
if (obj.getLevel() >= level){
log(obj.getMessage(), obj.getCaller(), obj.getClassPackage(), 1, obj.getDump());
};
}
public function setFilters(p_filters:Array):void{
filters = p_filters;
}
public static function getInstance():XrayLogger{
if (_instance == null){
_instance = new (XrayLogger);
};
return (_instance);
}
public static function resolveLevelAsName(p_level:Number):String{
switch (p_level){
case 0:
return ("debug");
case 1:
return ("info");
case 2:
return ("warn");
case 3:
return ("error");
case 4:
return ("fatal");
default:
return ("debug");
};
}
}
}//package com.blitzagency.xray.logger
Section 10
//MakeOfLength (com.bnj.string.MakeOfLength)
package com.bnj.string {
public function MakeOfLength(string:String, length:int):String{
if (string.length > length){
string = string.substr(0, length);
};
while (string.length < length) {
string = (string + " ");
};
return (string);
}
}//package com.bnj.string
Section 11
//FpsCounter (com.bnj.utils.FpsCounter)
package com.bnj.utils {
import flash.events.*;
import flash.display.*;
import flash.text.*;
import flash.utils.*;
import com.bnj.string.*;
import flash.system.*;
public class FpsCounter extends Sprite {
private var secondTime:Number;
private var textFormat:TextFormat;
private var frames:Number;// = 0
private var prevFrameTime:Number;
private var frameTime:Number;
private var time:Number;
private var fps:String;// = "..."
private var bar:Sprite;
private var prevSecondTime:Number;
private var field:TextField;
public function FpsCounter(){
prevFrameTime = getTimer();
prevSecondTime = getTimer();
super();
bar = new Sprite();
bar.graphics.beginFill(0xFF0066, 0.6);
bar.graphics.drawRect(0, 0, 1, 1);
bar.height = 15;
addChild(bar);
textFormat = new TextFormat();
textFormat.font = "Arial";
textFormat.bold = true;
textFormat.color = 0xFFFFFF;
textFormat.size = 10;
field = new TextField();
field.autoSize = TextFieldAutoSize.LEFT;
field.embedFonts = false;
field.setTextFormat(textFormat);
addChild(field);
mouseEnabled = false;
mouseChildren = false;
addEventListener(Event.ADDED_TO_STAGE, addEventListeners);
addEventListener(Event.REMOVED_FROM_STAGE, removeEventListeners);
}
private function onFrameTick(event:Event):void{
time = getTimer();
frameTime = (time - prevFrameTime);
secondTime = (time - prevSecondTime);
if (secondTime >= 1000){
fps = frames.toString();
frames = 0;
prevSecondTime = time;
} else {
frames++;
};
prevFrameTime = time;
var memory:int = ((System.totalMemory / 0x0400) / 0x0400);
var text:String = "";
text = (text + (("Target FPS: " + MakeOfLength(String(stage.frameRate), 10)) + " "));
text = (text + (("Actual FPS: " + MakeOfLength(String(fps), 10)) + " "));
text = (text + (("Frame Time: " + MakeOfLength(String(frameTime), 10)) + " "));
text = (text + (("Memory Use: " + MakeOfLength((String(memory) + " MB"), 10)) + " "));
text = (text + (("Quality Setting: " + stage.quality) + " "));
field.text = text.toUpperCase();
field.setTextFormat(textFormat);
var targetWidth:Number = (stage.stageWidth * (Number(fps) / stage.frameRate));
bar.width = ((targetWidth + bar.width) / 2);
}
private function removeEventListeners(event:Event):void{
removeEventListener(Event.ENTER_FRAME, onFrameTick);
}
private function addEventListeners(event:Event):void{
addEventListener(Event.ENTER_FRAME, onFrameTick);
}
}
}//package com.bnj.utils
Section 12
//FullscreenButton (com.bnj.utils.FullscreenButton)
package com.bnj.utils {
import flash.events.*;
import flash.display.*;
public class FullscreenButton extends Sprite {
private var fill:Sprite;
private var outerFrame:Sprite;
private var stepX:Number;// = 0
private var targetAlpha:Number;
private var step:int;// = 0
private var stepY:Number;// = 0
private var stepScale:Number;// = 0
private var targetX:Number;
private var targetY:Number;
private var shrinkX:Number;
private var shrinkY:Number;
private var stepAlpha:Number;// = 0
private var steps:int;// = 10
private var innerFrame:Sprite;
private var targetScale:Number;
public function FullscreenButton(){
super();
fill = new Sprite();
fill.graphics.beginFill(0, 0.3);
fill.graphics.drawRect(0, 0, 42, 24);
fill.graphics.endFill();
fill.alpha = 0.5;
addChild(fill);
outerFrame = new Sprite();
outerFrame.graphics.lineStyle(1, 0xFFFFFF, 1, true);
outerFrame.graphics.moveTo(0, 0);
outerFrame.graphics.lineTo(0, 21);
outerFrame.graphics.lineTo(39, 21);
outerFrame.graphics.lineTo(39, 0);
outerFrame.graphics.lineTo(0, 0);
outerFrame.x = (outerFrame.y = 1);
addChild(outerFrame);
innerFrame = new Sprite();
innerFrame.graphics.lineStyle(1, 0xFFFFFF, 1, true);
innerFrame.graphics.moveTo(0, 0);
innerFrame.graphics.lineTo(0, 21);
innerFrame.graphics.lineTo(39, 21);
innerFrame.graphics.lineTo(39, 0);
innerFrame.graphics.lineTo(0, 0);
innerFrame.scaleX = (innerFrame.scaleY = 0.5);
shrinkX = ((fill.width - innerFrame.width) / 2);
shrinkY = ((fill.height - innerFrame.height) / 2);
innerFrame.x = shrinkX;
innerFrame.y = shrinkY;
addChild(innerFrame);
buttonMode = true;
mouseChildren = false;
addEventListener(MouseEvent.CLICK, toggleFullScreen);
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
}
private function onMouseOut(event:MouseEvent):void{
targetScale = 0.5;
targetAlpha = 0.5;
targetX = shrinkX;
targetY = shrinkY;
setSteps();
startAnim();
}
public function toggleFullScreen(event:MouseEvent):void{
var event = event;
switch (stage.displayState){
case StageDisplayState.FULL_SCREEN:
stage.displayState = StageDisplayState.NORMAL;
break;
default:
onMouseOut(null);
stage.displayState = StageDisplayState.FULL_SCREEN;
break;
};
//unresolved jump
var _slot1 = err;
}
private function startAnim():void{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function setSteps():void{
stepScale = ((targetScale - innerFrame.scaleX) / steps);
stepX = ((targetX - innerFrame.x) / steps);
stepY = ((targetY - innerFrame.y) / steps);
stepAlpha = ((targetAlpha - fill.alpha) / steps);
step = 0;
}
private function onEnterFrame(e:Event):void{
if (step < steps){
innerFrame.scaleX = (innerFrame.scaleX + stepScale);
innerFrame.scaleY = (innerFrame.scaleY + stepScale);
innerFrame.x = (innerFrame.x + stepX);
innerFrame.y = (innerFrame.y + stepY);
fill.alpha = (fill.alpha + stepAlpha);
step++;
} else {
innerFrame.scaleX = targetScale;
innerFrame.scaleY = targetScale;
innerFrame.x = targetX;
innerFrame.y = targetY;
fill.alpha = targetAlpha;
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
};
}
private function onMouseOver(event:MouseEvent):void{
targetScale = 1;
targetAlpha = 1;
targetX = 1;
targetY = 1;
setSteps();
startAnim();
}
}
}//package com.bnj.utils
Section 13
//FrustumCamera3D (org.papervision3d.cameras.FrustumCamera3D)
package org.papervision3d.cameras {
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.math.*;
public class FrustumCamera3D extends CameraObject3D implements IObjectCuller {
private var _viewport:Rectangle;
private var _near:Number;// = 10
private var _projectionType:uint;// = 0
private var _fov:Number;// = 50
private var _far:Number;// = 1000
private var _rotation:Quaternion;
public var planes:Array;
private var _objpos:Vertex3D;
private var _viewport3D:Viewport3D;
private var _ortho:Boolean;// = false
public var _projection:Matrix3D;
private var _aspect:Number;
private var _target:Vertex3D;
public static const INSIDE:int = 1;
public static const OUTSIDE:int = -1;
public static const INTERSECT:int = 0;
public static const LEFT:uint = 1;
public static const PERSPECTIVE_PROJECTION:uint = 0;
public static const ORTHO_PROJECTION:uint = 1;
public static const NEAR:uint = 0;
public static const BOTTOM:uint = 4;
public static const TOP:uint = 3;
public static const FAR:uint = 5;
public static const TYPE:String = "FRUSTRUMCAMERA3D";
public static const RIGHT:uint = 2;
public function FrustumCamera3D(viewport3D:Viewport3D, fov:Number=90, near:Number=10, far:Number=2000):void{
super();
_fov = fov;
_near = near;
_far = far;
this.viewport3D = viewport3D;
init();
}
override public function transformView(trans:Matrix3D=null):void{
super.transformView();
this.eye.calculateMultiply4x4(_projection, this.eye);
extractPlanes(this.eye);
}
public function testObject(obj:DisplayObject3D):int{
if (((((!(obj.geometry)) || (!(obj.geometry.vertices)))) || (!(obj.geometry.vertices.length)))){
return (INSIDE);
};
var radius:Number = obj.geometry.boundingSphere2;
_objpos.x = obj.world.n14;
_objpos.y = obj.world.n24;
_objpos.z = obj.world.n34;
return (sphereInFrustum(_objpos, (radius * radius)));
}
public function get fov():Number{
return (_fov);
}
public function get projection():uint{
return (_projectionType);
}
public function set near(distance:Number):void{
_near = Math.abs(distance);
init();
}
public function get far():Number{
return (_far);
}
public function set fov(degrees:Number):void{
_fov = degrees;
init();
}
public function set viewport3D(viewport3D:Viewport3D):void{
_viewport3D = viewport3D;
viewport = viewport3D.sizeRectangle;
}
private function init():void{
var w:Number;
var h:Number;
_objpos = new Vertex3D();
_rotation = Quaternion.createFromMatrix(Matrix3D.IDENTITY);
_viewport = this.viewport;
_aspect = (_viewport.width / _viewport.height);
if (_projectionType == PERSPECTIVE_PROJECTION){
_projection = createPerspectiveMatrix(_fov, _aspect, _near, _far);
} else {
w = (_viewport.width / 2);
h = (_viewport.height / 2);
_projection = createOrthoMatrix(-(w), w, -(h), h, -(_far), _far);
};
this.planes = new Array(6);
var i:int;
while (i < 6) {
this.planes[i] = new Plane3D();
i++;
};
}
public function set projection(type:uint):void{
_projectionType = type;
init();
}
public function get viewport3D():Viewport3D{
return (_viewport3D);
}
public function get near():Number{
return (_near);
}
public function set far(distance:Number):void{
_far = distance;
init();
}
public function sphereInFrustum(center:Vertex3D, radius:Number):int{
var distance:Number;
var result:int = INSIDE;
var i:int;
while (i < planes.length) {
distance = planes[i].distance(center);
if (distance < -(radius)){
return (OUTSIDE);
};
if (distance < radius){
result = INTERSECT;
};
i++;
};
return (result);
}
public function extractPlanes(m:Matrix3D):void{
var m11:Number = m.n11;
var m12:Number = m.n12;
var m13:Number = m.n13;
var m14:Number = m.n14;
var m21:Number = m.n21;
var m22:Number = m.n22;
var m23:Number = m.n23;
var m24:Number = m.n24;
var m31:Number = m.n31;
var m32:Number = m.n32;
var m33:Number = m.n33;
var m34:Number = m.n34;
var m41:Number = m.n41;
var m42:Number = m.n42;
var m43:Number = m.n43;
var m44:Number = m.n44;
planes[NEAR].setCoefficients((m31 + m41), (m32 + m42), (m33 + m43), (m34 + m44));
planes[FAR].setCoefficients((-(m31) + m41), (-(m32) + m42), (-(m33) + m43), (-(m34) + m44));
planes[BOTTOM].setCoefficients((m21 + m41), (m22 + m42), (m23 + m43), (m24 + m44));
planes[TOP].setCoefficients((-(m21) + m41), (-(m22) + m42), (-(m23) + m43), (-(m24) + m44));
planes[LEFT].setCoefficients((m11 + m41), (m12 + m42), (m13 + m43), (m14 + m44));
planes[RIGHT].setCoefficients((-(m11) + m41), (-(m12) + m42), (-(m13) + m43), (-(m14) + m44));
}
public static function createPerspectiveMatrix(fov:Number, aspect:Number, near:Number, far:Number):Matrix3D{
var fov2:Number = ((fov / 2) * (Math.PI / 180));
var tan:Number = Math.tan(fov2);
var f:Number = (1 / tan);
return (new Matrix3D([(f / aspect), 0, 0, 0, 0, f, 0, 0, 0, 0, -(((near + far) / (near - far))), (((2 * far) * near) / (near - far)), 0, 0, 1, 0]));
}
public static function createOrthoMatrix(left:Number, right:Number, bottom:Number, top:Number, near:Number, far:Number):Matrix3D{
var tx:Number = ((right + left) / (right - left));
var ty:Number = ((top + bottom) / (top - bottom));
var tz:Number = ((far + near) / (far - near));
var matrix:Matrix3D = new Matrix3D([(2 / (right - left)), 0, 0, tx, 0, (2 / (top - bottom)), 0, ty, 0, 0, (-2 / (far - near)), tz, 0, 0, 0, 1]);
matrix.calculateMultiply(Matrix3D.scaleMatrix(1, 1, -1), matrix);
return (matrix);
}
}
}//package org.papervision3d.cameras
Section 14
//AbstractController (org.papervision3d.core.animation.core.AbstractController)
package org.papervision3d.core.animation.core {
import flash.events.*;
public class AbstractController extends EventDispatcher {
protected var engine:AnimationEngine;
protected var totalFrames:uint;// = 0
protected var split:Number;
public var duration:uint;// = 0
protected var firstFrame:uint;// = 0
public var frames:Array;
public var playing:Boolean;
protected var currentFrame:int;// = 0
protected var lastFrame:uint;// = 0
protected var nextFrame:int;// = 0
public function AbstractController():void{
super();
this.frames = new Array();
this.engine = AnimationEngine.getInstance();
playing = false;
currentFrame = 0;
nextFrame = 1;
firstFrame = uint.MAX_VALUE;
lastFrame = uint.MIN_VALUE;
}
public function gotoAndPlay(frame:uint=0):void{
currentFrame = (frame % this.frames.length);
nextFrame = ((frame + 1) % this.frames.length);
playing = true;
}
public function stop():void{
playing = false;
}
public function addFrame(frame:AnimationFrame):void{
this.frames[frame.frame] = frame;
totalFrames++;
firstFrame = Math.min(firstFrame, frame.frame);
lastFrame = Math.max(lastFrame, frame.frame);
}
public function findFrameByName(name:String, ignoreTrailingDigits:Boolean):AnimationFrame{
var frame:AnimationFrame;
var pattern:RegExp;
var matches:Object;
if (ignoreTrailingDigits){
pattern = /^([a-z]+)(\d+)$/i;
matches = pattern.exec(name);
if (((((matches) && (matches[1]))) && (matches[2]))){
name = matches[1];
};
};
for each (frame in this.frames) {
if (frame.name == name){
return (frame);
};
};
return (null);
}
public function tick(dt:Number):void{
}
public function gotoAndStop(frame:uint=0):void{
currentFrame = (frame % this.frames.length);
nextFrame = ((frame + 1) % this.frames.length);
}
public function play():void{
gotoAndPlay(currentFrame);
}
}
}//package org.papervision3d.core.animation.core
Section 15
//AnimationEngine (org.papervision3d.core.animation.core.AnimationEngine)
package org.papervision3d.core.animation.core {
import org.papervision3d.objects.*;
import flash.utils.*;
import org.papervision3d.*;
import org.papervision3d.core.animation.controllers.*;
public class AnimationEngine {
public var maxTime:Number;
public var currentFrame:uint;// = 0
public var time:Number;// = 0
public static var TICK:Number = 50;
private static var _controllers:Array;
private static var _animatedObjects:Dictionary;
private static var instance:AnimationEngine = new (AnimationEngine);
;
private static var _time:Number;
public static var NUM_FRAMES:uint = 100;
public function AnimationEngine():void{
maxTime = (NUM_FRAMES * TICK);
super();
if (instance){
throw (new Error("org.papervision3d.animation.AnimationEngine is a singleton class!"));
};
_animatedObjects = new Dictionary();
_controllers = new Array();
_time = getTimer();
Papervision3D.log(((("[AnimationEngine] initialized => NUM_FRAMES:" + NUM_FRAMES) + " TICK:") + TICK));
}
public function tick():void{
var obj:*;
var controllers:Array;
var i:int;
time = (getTimer() - _time);
if (time > TICK){
_time = getTimer();
currentFrame = ((currentFrame < (NUM_FRAMES - 1))) ? (currentFrame + 1) : 0;
};
for (obj in _animatedObjects) {
controllers = _animatedObjects[obj];
i = 0;
while (i < controllers.length) {
controllers[i].tick(time);
i++;
};
};
}
public static function getControllers(object:DisplayObject3D):Array{
if (_animatedObjects[object]){
return (_animatedObjects[object]);
};
return (null);
}
public static function getInstance():AnimationEngine{
return (instance);
}
public static function millisToFrame(millis:Number):uint{
return (Math.floor((millis / TICK)));
}
public static function secondsToFrame(seconds:Number):uint{
return (millisToFrame((seconds * 1000)));
}
public static function setControllers(object:DisplayObject3D, controllers:Array, overwrite:Boolean=false):void{
if (overwrite){
_animatedObjects[object] = new Array();
};
var i:int;
while (i < controllers.length) {
addController(object, controllers[i]);
i++;
};
}
public static function addController(object:DisplayObject3D, controller:AbstractController):AbstractController{
var frame:AnimationFrame;
var framenum:uint;
var nframes:uint = NUM_FRAMES;
if (!_animatedObjects[object]){
_animatedObjects[object] = new Array();
};
for each (frame in controller.frames) {
framenum = frame.frame;
if (framenum > NUM_FRAMES){
NUM_FRAMES = framenum;
};
};
instance.maxTime = (NUM_FRAMES * TICK);
if (NUM_FRAMES > nframes){
Papervision3D.log((("[AnimationEngine] resizing timeline to " + NUM_FRAMES) + " frames"));
};
_animatedObjects[object].push(controller);
return (controller);
}
}
}//package org.papervision3d.core.animation.core
Section 16
//AnimationFrame (org.papervision3d.core.animation.core.AnimationFrame)
package org.papervision3d.core.animation.core {
public class AnimationFrame {
public var type:uint;
public var values:Array;
public var nextFrame:uint;
public var name:String;
public var frame:uint;
public var duration:uint;
public function AnimationFrame(frame:uint, duration:uint=1, values:Array=null, name:String=""):void{
super();
this.frame = frame;
this.duration = duration;
this.values = ((values) || (new Array()));
this.name = name;
}
}
}//package org.papervision3d.core.animation.core
Section 17
//CoordinateTools (org.papervision3d.core.components.as3.utils.CoordinateTools)
package org.papervision3d.core.components.as3.utils {
import flash.geom.*;
import flash.display.*;
public class CoordinateTools {
public function CoordinateTools(){
super();
}
public static function random(range:Number):Number{
return (Math.floor((Math.random() * range)));
}
public static function localToLocal(containerFrom:DisplayObject, containerTo:DisplayObject, origin:Point=null):Point{
var point:Point = (origin) ? origin : new Point();
point = containerFrom.localToGlobal(point);
point = containerTo.globalToLocal(point);
return (point);
}
}
}//package org.papervision3d.core.components.as3.utils
Section 18
//DefaultParticleCuller (org.papervision3d.core.culling.DefaultParticleCuller)
package org.papervision3d.core.culling {
import org.papervision3d.core.geom.renderables.*;
public class DefaultParticleCuller implements IParticleCuller {
public function DefaultParticleCuller(){
super();
}
public function testParticle(particle:Particle):Boolean{
if (particle.material.invisible == false){
if (particle.vertex3D.vertex3DInstance.visible == true){
return (true);
};
};
return (false);
}
}
}//package org.papervision3d.core.culling
Section 19
//DefaultTriangleCuller (org.papervision3d.core.culling.DefaultTriangleCuller)
package org.papervision3d.core.culling {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.renderables.*;
public class DefaultTriangleCuller implements ITriangleCuller {
private static var y2:Number;
private static var y1:Number;
private static var y0:Number;
private static var x0:Number;
private static var x1:Number;
private static var x2:Number;
public function DefaultTriangleCuller(){
super();
}
public function testFace(face:Triangle3D, vertex0:Vertex3DInstance, vertex1:Vertex3DInstance, vertex2:Vertex3DInstance):Boolean{
var material:MaterialObject3D;
if (((((vertex0.visible) && (vertex1.visible))) && (vertex2.visible))){
material = (face.material) ? face.material : face.instance.material;
if (material.invisible){
return (false);
};
x0 = vertex0.x;
y0 = vertex0.y;
x1 = vertex1.x;
y1 = vertex1.y;
x2 = vertex2.x;
y2 = vertex2.y;
if (material.oneSide){
if (material.opposite){
if ((((x2 - x0) * (y1 - y0)) - ((y2 - y0) * (x1 - x0))) > 0){
return (false);
};
} else {
if ((((x2 - x0) * (y1 - y0)) - ((y2 - y0) * (x1 - x0))) < 0){
return (false);
};
};
};
return (true);
};
return (false);
}
}
}//package org.papervision3d.core.culling
Section 20
//IObjectCuller (org.papervision3d.core.culling.IObjectCuller)
package org.papervision3d.core.culling {
import org.papervision3d.objects.*;
public interface IObjectCuller {
function testObject(:DisplayObject3D):int;
}
}//package org.papervision3d.core.culling
Section 21
//IParticleCuller (org.papervision3d.core.culling.IParticleCuller)
package org.papervision3d.core.culling {
import org.papervision3d.core.geom.renderables.*;
public interface IParticleCuller {
function testParticle(:Particle):Boolean;
}
}//package org.papervision3d.core.culling
Section 22
//ITriangleCuller (org.papervision3d.core.culling.ITriangleCuller)
package org.papervision3d.core.culling {
import org.papervision3d.core.geom.renderables.*;
public interface ITriangleCuller {
function testFace(_arg1:Triangle3D, _arg2:Vertex3DInstance, _arg3:Vertex3DInstance, _arg4:Vertex3DInstance):Boolean;
}
}//package org.papervision3d.core.culling
Section 23
//RectangleParticleCuller (org.papervision3d.core.culling.RectangleParticleCuller)
package org.papervision3d.core.culling {
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
public class RectangleParticleCuller implements IParticleCuller {
public var cullingRectangle:Rectangle;
private static var vInstance:Vertex3DInstance;
private static var testPoint:Point;
public function RectangleParticleCuller(cullingRectangle:Rectangle=null){
super();
this.cullingRectangle = cullingRectangle;
testPoint = new Point();
}
public function testParticle(particle:Particle):Boolean{
vInstance = particle.vertex3D.vertex3DInstance;
if (particle.material.invisible == false){
if (vInstance.visible){
if (particle.renderRect.intersects(cullingRectangle)){
return (true);
};
};
};
return (false);
}
}
}//package org.papervision3d.core.culling
Section 24
//RectangleTriangleCuller (org.papervision3d.core.culling.RectangleTriangleCuller)
package org.papervision3d.core.culling {
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
public class RectangleTriangleCuller extends DefaultTriangleCuller implements ITriangleCuller {
public var cullingRectangle:Rectangle;
private static const DEFAULT_RECT_X:Number = -((DEFAULT_RECT_W / 2));
private static const DEFAULT_RECT_W:Number = 640;
private static const DEFAULT_RECT_H:Number = 480;
private static const DEFAULT_RECT_Y:Number = -((DEFAULT_RECT_H / 2));
private static var hitRect:Rectangle = new Rectangle();
public function RectangleTriangleCuller(cullingRectangle:Rectangle=null):void{
cullingRectangle = new Rectangle(DEFAULT_RECT_X, DEFAULT_RECT_Y, DEFAULT_RECT_W, DEFAULT_RECT_H);
super();
if (cullingRectangle){
this.cullingRectangle = cullingRectangle;
};
}
override public function testFace(face:Triangle3D, vertex0:Vertex3DInstance, vertex1:Vertex3DInstance, vertex2:Vertex3DInstance):Boolean{
if (super.testFace(face, vertex0, vertex1, vertex2)){
hitRect.x = Math.min(vertex2.x, Math.min(vertex1.x, vertex0.x));
hitRect.width = (Math.max(vertex2.x, Math.max(vertex1.x, vertex0.x)) + Math.abs(hitRect.x));
hitRect.y = Math.min(vertex2.y, Math.min(vertex1.y, vertex0.y));
hitRect.height = (Math.max(vertex2.y, Math.max(vertex1.y, vertex0.y)) + Math.abs(hitRect.y));
return (cullingRectangle.intersects(hitRect));
};
return (false);
}
}
}//package org.papervision3d.core.culling
Section 25
//ViewportObjectFilter (org.papervision3d.core.culling.ViewportObjectFilter)
package org.papervision3d.core.culling {
import org.papervision3d.objects.*;
import flash.utils.*;
public class ViewportObjectFilter implements IObjectCuller {
protected var _mode:int;
protected var objects:Dictionary;
public function ViewportObjectFilter(mode:int):void{
super();
this.mode = mode;
init();
}
public function addObject(do3d:DisplayObject3D):void{
objects[do3d] = do3d;
}
public function get mode():int{
return (_mode);
}
public function set mode(mode:int):void{
_mode = mode;
}
public function removeObject(do3d:DisplayObject3D):void{
delete objects[do3d];
}
private function init():void{
objects = new Dictionary(true);
}
public function testObject(object:DisplayObject3D):int{
if (objects[object]){
if (_mode == ViewportObjectFilterMode.INCLUSIVE){
return (1);
};
if (_mode == ViewportObjectFilterMode.EXCLUSIVE){
return (0);
};
} else {
if (_mode == ViewportObjectFilterMode.INCLUSIVE){
return (0);
};
if (_mode == ViewportObjectFilterMode.EXCLUSIVE){
return (1);
};
};
return (0);
}
public function destroy():void{
objects = null;
}
}
}//package org.papervision3d.core.culling
Section 26
//ViewportObjectFilterMode (org.papervision3d.core.culling.ViewportObjectFilterMode)
package org.papervision3d.core.culling {
public class ViewportObjectFilterMode {
public static const INCLUSIVE:int = 0;
public static const EXCLUSIVE:int = 1;
public function ViewportObjectFilterMode(){
super();
}
}
}//package org.papervision3d.core.culling
Section 27
//AbstractEffect (org.papervision3d.core.effects.AbstractEffect)
package org.papervision3d.core.effects {
import flash.filters.*;
import org.papervision3d.core.layers.*;
public class AbstractEffect implements IEffect {
public function AbstractEffect(){
super();
}
public function preRender():void{
}
public function postRender():void{
}
public function getEffect():BitmapFilter{
return (null);
}
public function attachEffect(layer:EffectLayer):void{
}
}
}//package org.papervision3d.core.effects
Section 28
//IEffect (org.papervision3d.core.effects.IEffect)
package org.papervision3d.core.effects {
import flash.filters.*;
import org.papervision3d.core.layers.*;
public interface IEffect {
function preRender():void;
function postRender():void;
function attachEffect(:EffectLayer):void;
function getEffect():BitmapFilter;
}
}//package org.papervision3d.core.effects
Section 29
//IRenderable (org.papervision3d.core.geom.renderables.IRenderable)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.render.command.*;
public interface IRenderable {
function getRenderListItem():IRenderListItem;
}
}//package org.papervision3d.core.geom.renderables
Section 30
//Particle (org.papervision3d.core.geom.renderables.Particle)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.render.command.*;
import flash.geom.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.core.geom.*;
public class Particle implements IRenderable {
public var size:Number;
public var renderCommand:RenderParticle;
public var material:ParticleMaterial;
public var renderScale:Number;
public var instance:Particles;
public var renderRect:Rectangle;
public var vertex3D:Vertex3D;
public function Particle(material:ParticleMaterial, size:Number=1, x:Number=0, y:Number=0, z:Number=0){
super();
this.material = material;
this.size = size;
this.renderCommand = new RenderParticle(this);
this.renderRect = new Rectangle();
vertex3D = new Vertex3D(x, y, z);
}
public function get y():Number{
return (vertex3D.y);
}
public function updateRenderRect():void{
material.updateRenderRect(this);
}
public function get z():Number{
return (vertex3D.z);
}
public function set z(z:Number):void{
vertex3D.z = z;
}
public function set x(x:Number):void{
vertex3D.x = x;
}
public function set y(y:Number):void{
vertex3D.y = y;
}
public function get x():Number{
return (vertex3D.x);
}
public function getRenderListItem():IRenderListItem{
return (renderCommand);
}
}
}//package org.papervision3d.core.geom.renderables
Section 31
//Triangle3D (org.papervision3d.core.geom.renderables.Triangle3D)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.render.command.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.math.*;
public class Triangle3D implements IRenderable {
private var _uvArray:Array;
public var face3DInstance:Triangle3DInstance;
public var instance:DisplayObject3D;
public var id:Number;
public var material:MaterialObject3D;
public var faceNormal:Number3D;
public var renderCommand:RenderTriangle;
public var screenZ:Number;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var _materialName:String;
public var visible:Boolean;
public var uv2:NumberUV;
public var vertices:Array;
public var v0:Vertex3D;
public var v1:Vertex3D;
public var v2:Vertex3D;
private static var _totalFaces:Number = 0;
public function Triangle3D(do3dInstance:DisplayObject3D, vertices:Array, material:MaterialObject3D=null, uv:Array=null){
super();
this.instance = do3dInstance;
this.renderCommand = new RenderTriangle(this);
face3DInstance = new Triangle3DInstance(this, do3dInstance);
this.vertices = vertices;
v0 = vertices[0];
v1 = vertices[1];
v2 = vertices[2];
this.material = material;
this.uv = uv;
this.id = _totalFaces++;
createNormal();
}
public function set uv(uv:Array):void{
uv0 = NumberUV(uv[0]);
uv1 = NumberUV(uv[1]);
uv2 = NumberUV(uv[2]);
_uvArray = uv;
}
public function getRenderListItem():IRenderListItem{
return (renderCommand);
}
public function createNormal():void{
var vn0:Number3D = v0.toNumber3D();
var vn1:Number3D = v1.toNumber3D();
var vn2:Number3D = v2.toNumber3D();
var vt1:Number3D = Number3D.sub(vn1, vn0);
var vt2:Number3D = Number3D.sub(vn2, vn0);
faceNormal = Number3D.cross(vt1, vt2);
faceNormal.normalize();
}
public function get uv():Array{
return (_uvArray);
}
}
}//package org.papervision3d.core.geom.renderables
Section 32
//Triangle3DInstance (org.papervision3d.core.geom.renderables.Triangle3DInstance)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.objects.*;
import flash.display.*;
import org.papervision3d.core.math.*;
public class Triangle3DInstance {
public var container:Sprite;
public var instance:DisplayObject3D;
public var visible:Boolean;// = false
public var faceNormal:Number3D;
public var screenZ:Number;
public function Triangle3DInstance(face:Triangle3D, instance:DisplayObject3D){
super();
this.instance = instance;
faceNormal = new Number3D();
}
}
}//package org.papervision3d.core.geom.renderables
Section 33
//Vertex3D (org.papervision3d.core.geom.renderables.Vertex3D)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.render.command.*;
import org.papervision3d.core.math.*;
import flash.utils.*;
public class Vertex3D implements IRenderable {
public var normal:Number3D;
public var vertex3DInstance:Vertex3DInstance;
public var connectedFaces:Dictionary;
public var extra:Object;
public var x:Number;
public var y:Number;
public var z:Number;
public function Vertex3D(x:Number=0, y:Number=0, z:Number=0){
super();
this.x = x;
this.y = y;
this.z = z;
this.vertex3DInstance = new Vertex3DInstance();
this.normal = new Number3D();
this.connectedFaces = new Dictionary();
}
public function getRenderListItem():IRenderListItem{
return (null);
}
public function toNumber3D():Number3D{
return (new Number3D(x, y, z));
}
public function calculateNormal():void{
var face:Triangle3D;
var count:Number;
normal = new Number3D();
count = 0;
for each (face in connectedFaces) {
count++;
normal = Number3D.add(face.faceNormal, normal);
};
normal.x = (normal.x / count);
normal.y = (normal.y / count);
normal.z = (normal.z / count);
normal.normalize();
}
public function clone():Vertex3D{
var clone:Vertex3D = new Vertex3D(x, y, z);
clone.extra = extra;
clone.vertex3DInstance = vertex3DInstance.clone();
clone.normal = normal.clone();
return (clone);
}
}
}//package org.papervision3d.core.geom.renderables
Section 34
//Vertex3DInstance (org.papervision3d.core.geom.renderables.Vertex3DInstance)
package org.papervision3d.core.geom.renderables {
import org.papervision3d.core.math.*;
public class Vertex3DInstance {
public var y:Number;
public var normal:Number3D;
public var visible:Boolean;
public var extra:Object;
public var x:Number;
public var z:Number;
public function Vertex3DInstance(x:Number=0, y:Number=0, z:Number=0){
super();
this.x = x;
this.y = y;
this.z = z;
this.visible = false;
this.normal = new Number3D();
}
public function clone():Vertex3DInstance{
var clone:Vertex3DInstance = new Vertex3DInstance(x, y, z);
clone.visible = visible;
clone.extra = extra;
return (clone);
}
public static function cross(v0:Vertex3DInstance, v1:Vertex3DInstance):Number{
return (((v0.x * v1.y) - (v1.x * v0.y)));
}
public static function dot(v0:Vertex3DInstance, v1:Vertex3DInstance):Number{
return (((v0.x * v1.x) + (v0.y * v1.y)));
}
public static function sub(v0:Vertex3DInstance, v1:Vertex3DInstance):Vertex3DInstance{
return (new Vertex3DInstance((v1.x - v0.x), (v1.y - v0.y)));
}
}
}//package org.papervision3d.core.geom.renderables
Section 35
//Particles (org.papervision3d.core.geom.Particles)
package org.papervision3d.core.geom {
import org.papervision3d.core.render.data.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
public class Particles extends Vertices3D {
private var vertices:Array;
public var particles:Array;
public function Particles(name:String="VertexParticles"){
this.vertices = new Array();
this.particles = new Array();
super(vertices, name);
}
public function removeParticle(particle:Particle):void{
particle.instance = null;
particles.splice(particles.indexOf(particle, 0));
vertices.splice(vertices.indexOf(particle.vertex3D, 0));
}
public function addParticle(particle:Particle):void{
particle.instance = this;
particles.push(particle);
vertices.push(particle.vertex3D);
}
override public function project(parent:DisplayObject3D, renderSessionData:RenderSessionData):Number{
var p:Particle;
super.project(parent, renderSessionData);
var fz:Number = (renderSessionData.camera.focus * renderSessionData.camera.zoom);
for each (p in particles) {
p.renderScale = (fz / (renderSessionData.camera.focus + p.vertex3D.vertex3DInstance.z));
p.updateRenderRect();
if (renderSessionData.viewPort.particleCuller.testParticle(p)){
p.renderCommand.screenDepth = p.vertex3D.vertex3DInstance.z;
renderSessionData.renderer.addToRenderList(p.renderCommand);
} else {
renderSessionData.renderStatistics.culledParticles++;
};
};
return (1);
}
public function removeAllParticles():void{
particles = new Array();
vertices = new Array();
geometry.vertices = vertices;
}
}
}//package org.papervision3d.core.geom
Section 36
//TriangleMesh3D (org.papervision3d.core.geom.TriangleMesh3D)
package org.papervision3d.core.geom {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.render.command.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.math.*;
import flash.utils.*;
import org.papervision3d.core.render.draw.*;
public class TriangleMesh3D extends Vertices3D {
public function TriangleMesh3D(material:MaterialObject3D, vertices:Array, faces:Array, name:String=null, initObject:Object=null){
super(vertices, name, initObject);
this.geometry.faces = ((faces) || (new Array()));
this.material = ((material) || (MaterialObject3D.DEFAULT));
}
public function mergeVertices():void{
var v:Vertex3D;
var f:Triangle3D;
var vu:Vertex3D;
var uniqueDic:Dictionary = new Dictionary();
var uniqueList:Array = new Array();
for each (v in this.geometry.vertices) {
for each (vu in uniqueDic) {
if ((((((v.x == vu.x)) && ((v.y == vu.y)))) && ((v.z == vu.z)))){
uniqueDic[v] = vu;
break;
};
};
if (!uniqueDic[v]){
uniqueDic[v] = v;
uniqueList.push(v);
};
};
this.geometry.vertices = uniqueList;
for each (f in geometry.faces) {
f.v0 = uniqueDic[f.v0];
f.v1 = uniqueDic[f.v1];
f.v2 = uniqueDic[f.v2];
};
}
override public function project(parent:DisplayObject3D, renderSessionData:RenderSessionData):Number{
var faces:Array;
var screenZs:Number;
var visibleFaces:Number;
var triCuller:ITriangleCuller;
var vertex0:Vertex3DInstance;
var vertex1:Vertex3DInstance;
var vertex2:Vertex3DInstance;
var iFace:Triangle3DInstance;
var face:Triangle3D;
var mat:MaterialObject3D;
var rc:RenderTriangle;
super.project(parent, renderSessionData);
if (!this.culled){
faces = this.geometry.faces;
screenZs = 0;
visibleFaces = 0;
triCuller = renderSessionData.triangleCuller;
for each (face in faces) {
mat = (face.material) ? face.material : material;
iFace = face.face3DInstance;
vertex0 = face.v0.vertex3DInstance;
vertex1 = face.v1.vertex3DInstance;
vertex2 = face.v2.vertex3DInstance;
if ((iFace.visible = triCuller.testFace(face, vertex0, vertex1, vertex2))){
screenZs = (screenZs + (iFace.screenZ = (((vertex0.z + vertex1.z) + vertex2.z) / 3)));
rc = face.renderCommand;
visibleFaces++;
rc.renderer = (mat as ITriangleDrawer);
rc.screenDepth = iFace.screenZ;
renderSessionData.renderer.addToRenderList(rc);
} else {
renderSessionData.renderStatistics.culledTriangles++;
};
};
return ((this.screenZ = (screenZs / visibleFaces)));
//unresolved jump
};
return (0);
}
public function projectTexture(u:String="x", v:String="y"):void{
var i:String;
var myFace:Triangle3D;
var myVertices:Array;
var a:Vertex3D;
var b:Vertex3D;
var c:Vertex3D;
var uvA:NumberUV;
var uvB:NumberUV;
var uvC:NumberUV;
var faces:Array = this.geometry.faces;
var bBox:Object = this.boundingBox();
var minX:Number = bBox.min[u];
var sizeX:Number = bBox.size[u];
var minY:Number = bBox.min[v];
var sizeY:Number = bBox.size[v];
var objectMaterial:MaterialObject3D = this.material;
for (i in faces) {
myFace = faces[Number(i)];
myVertices = myFace.vertices;
a = myVertices[0];
b = myVertices[1];
c = myVertices[2];
uvA = new NumberUV(((a[u] - minX) / sizeX), ((a[v] - minY) / sizeY));
uvB = new NumberUV(((b[u] - minX) / sizeX), ((b[v] - minY) / sizeY));
uvC = new NumberUV(((c[u] - minX) / sizeX), ((c[v] - minY) / sizeY));
myFace.uv = [uvA, uvB, uvC];
};
}
public function quarterFaces():void{
var face:Triangle3D;
var v0:Vertex3D;
var v1:Vertex3D;
var v2:Vertex3D;
var v01:Vertex3D;
var v12:Vertex3D;
var v20:Vertex3D;
var t0:NumberUV;
var t1:NumberUV;
var t2:NumberUV;
var t01:NumberUV;
var t12:NumberUV;
var t20:NumberUV;
var f0:Triangle3D;
var f1:Triangle3D;
var f2:Triangle3D;
var f3:Triangle3D;
var newverts:Array = new Array();
var newfaces:Array = new Array();
var faces:Array = this.geometry.faces;
var i:int = faces.length;
while ((face = faces[--i])) {
v0 = face.v0;
v1 = face.v1;
v2 = face.v2;
v01 = new Vertex3D(((v0.x + v1.x) / 2), ((v0.y + v1.y) / 2), ((v0.z + v1.z) / 2));
v12 = new Vertex3D(((v1.x + v2.x) / 2), ((v1.y + v2.y) / 2), ((v1.z + v2.z) / 2));
v20 = new Vertex3D(((v2.x + v0.x) / 2), ((v2.y + v0.y) / 2), ((v2.z + v0.z) / 2));
this.geometry.vertices.push(v01, v12, v20);
t0 = face.uv[0];
t1 = face.uv[1];
t2 = face.uv[2];
t01 = new NumberUV(((t0.u + t1.u) / 2), ((t0.v + t1.v) / 2));
t12 = new NumberUV(((t1.u + t2.u) / 2), ((t1.v + t2.v) / 2));
t20 = new NumberUV(((t2.u + t0.u) / 2), ((t2.v + t0.v) / 2));
f0 = new Triangle3D(this, [v0, v01, v20], face.material, [t0, t01, t20]);
f1 = new Triangle3D(this, [v01, v1, v12], face.material, [t01, t1, t12]);
f2 = new Triangle3D(this, [v20, v12, v2], face.material, [t20, t12, t2]);
f3 = new Triangle3D(this, [v01, v12, v20], face.material, [t01, t12, t20]);
newfaces.push(f0, f1, f2, f3);
};
this.geometry.faces = newfaces;
this.mergeVertices();
this.geometry.ready = true;
}
}
}//package org.papervision3d.core.geom
Section 37
//Vertices3D (org.papervision3d.core.geom.Vertices3D)
package org.papervision3d.core.geom {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.math.*;
public class Vertices3D extends DisplayObject3D {
public function Vertices3D(vertices:Array, name:String=null, initObject:Object=null){
super(name, new GeometryObject3D(), initObject);
this.geometry.vertices = ((vertices) || (new Array()));
}
public function projectFrustum(parent:DisplayObject3D, renderSessionData:RenderSessionData):Number{
var vx:Number;
var vy:Number;
var vz:Number;
var s_x:Number;
var s_y:Number;
var s_z:Number;
var s_w:Number;
var vertex:Vertex3D;
var screen:Vertex3DInstance;
var view:Matrix3D = this.view;
var viewport:Rectangle = renderSessionData.camera.viewport;
var m11:Number = view.n11;
var m12:Number = view.n12;
var m13:Number = view.n13;
var m21:Number = view.n21;
var m22:Number = view.n22;
var m23:Number = view.n23;
var m31:Number = view.n31;
var m32:Number = view.n32;
var m33:Number = view.n33;
var m41:Number = view.n41;
var m42:Number = view.n42;
var m43:Number = view.n43;
var vpw:Number = (viewport.width / 2);
var vph:Number = (viewport.height / 2);
var vertices:Array = this.geometry.vertices;
var i:int = vertices.length;
while ((vertex = vertices[--i])) {
vx = vertex.x;
vy = vertex.y;
vz = vertex.z;
s_z = ((((vx * m31) + (vy * m32)) + (vz * m33)) + view.n34);
s_w = ((((vx * m41) + (vy * m42)) + (vz * m43)) + view.n44);
screen = vertex.vertex3DInstance;
s_z = (s_z / s_w);
if ((screen.visible = (((s_z > 0)) && ((s_z < 1))))){
s_x = (((((vx * m11) + (vy * m12)) + (vz * m13)) + view.n14) / s_w);
s_y = (((((vx * m21) + (vy * m22)) + (vz * m23)) + view.n24) / s_w);
screen.x = (s_x * vpw);
screen.y = (s_y * vph);
screen.z = s_z;
};
};
return (0);
}
override public function project(parent:DisplayObject3D, renderSessionData:RenderSessionData):Number{
var vx:Number;
var vy:Number;
var vz:Number;
var s_x:Number;
var s_y:Number;
var s_z:Number;
var vertex:Vertex3D;
var screen:Vertex3DInstance;
var persp:Number;
super.project(parent, renderSessionData);
if (this.culled){
return (0);
};
if ((renderSessionData.camera is IObjectCuller)){
return (projectFrustum(parent, renderSessionData));
};
var view:Matrix3D = this.view;
var m11:Number = view.n11;
var m12:Number = view.n12;
var m13:Number = view.n13;
var m21:Number = view.n21;
var m22:Number = view.n22;
var m23:Number = view.n23;
var m31:Number = view.n31;
var m32:Number = view.n32;
var m33:Number = view.n33;
var vertices:Array = this.geometry.vertices;
var i:int = vertices.length;
var focus:Number = renderSessionData.camera.focus;
var fz:Number = (focus * renderSessionData.camera.zoom);
while ((vertex = vertices[--i])) {
vx = vertex.x;
vy = vertex.y;
vz = vertex.z;
s_z = ((((vx * m31) + (vy * m32)) + (vz * m33)) + view.n34);
screen = vertex.vertex3DInstance;
if ((screen.visible = (s_z > 0))){
s_x = ((((vx * m11) + (vy * m12)) + (vz * m13)) + view.n14);
s_y = ((((vx * m21) + (vy * m22)) + (vz * m23)) + view.n24);
persp = (fz / (focus + s_z));
screen.x = (s_x * persp);
screen.y = (s_y * persp);
screen.z = s_z;
};
};
return (0);
}
public function transformVertices(transformation:Matrix3D):void{
var vertex:Vertex3D;
var vx:Number;
var vy:Number;
var vz:Number;
var tx:Number;
var ty:Number;
var tz:Number;
var m11:Number = transformation.n11;
var m12:Number = transformation.n12;
var m13:Number = transformation.n13;
var m21:Number = transformation.n21;
var m22:Number = transformation.n22;
var m23:Number = transformation.n23;
var m31:Number = transformation.n31;
var m32:Number = transformation.n32;
var m33:Number = transformation.n33;
var m14:Number = transformation.n14;
var m24:Number = transformation.n24;
var m34:Number = transformation.n34;
var vertices:Array = this.geometry.vertices;
var i:int = vertices.length;
while ((vertex = vertices[--i])) {
vx = vertex.x;
vy = vertex.y;
vz = vertex.z;
tx = ((((vx * m11) + (vy * m12)) + (vz * m13)) + m14);
ty = ((((vx * m21) + (vy * m22)) + (vz * m23)) + m24);
tz = ((((vx * m31) + (vy * m32)) + (vz * m33)) + m34);
vertex.x = tx;
vertex.y = ty;
vertex.z = tz;
};
}
public function boundingBox():Object{
var i:String;
var v:Vertex3D;
var vertices:Object = this.geometry.vertices;
var bBox:Object = new Object();
bBox.min = new Number3D();
bBox.max = new Number3D();
bBox.size = new Number3D();
for (i in vertices) {
v = vertices[Number(i)];
bBox.min.x = ((bBox.min.x)==undefined) ? v.x : Math.min(v.x, bBox.min.x);
bBox.max.x = ((bBox.max.x)==undefined) ? v.x : Math.max(v.x, bBox.max.x);
bBox.min.y = ((bBox.min.y)==undefined) ? v.y : Math.min(v.y, bBox.min.y);
bBox.max.y = ((bBox.max.y)==undefined) ? v.y : Math.max(v.y, bBox.max.y);
bBox.min.z = ((bBox.min.z)==undefined) ? v.z : Math.min(v.z, bBox.min.z);
bBox.max.z = ((bBox.max.z)==undefined) ? v.z : Math.max(v.z, bBox.max.z);
};
bBox.size.x = (bBox.max.x - bBox.min.x);
bBox.size.y = (bBox.max.y - bBox.min.y);
bBox.size.z = (bBox.max.z - bBox.min.z);
return (bBox);
}
}
}//package org.papervision3d.core.geom
Section 38
//RenderLayerManager (org.papervision3d.core.layers.utils.RenderLayerManager)
package org.papervision3d.core.layers.utils {
import flash.events.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import org.papervision3d.objects.*;
import flash.display.*;
import org.papervision3d.core.layers.*;
import flash.utils.*;
public class RenderLayerManager extends EventDispatcher {
public var sortMode:int;
public var layers:Dictionary;
private var containerLayers:Dictionary;
public var defaultLayer:RenderLayer;
public var effectLayers:Dictionary;
private static var _instance:RenderLayerManager;
public function RenderLayerManager(){
sortMode = RenderLayerSortMode.Z_SORT;
super();
layers = new Dictionary();
effectLayers = new Dictionary();
containerLayers = new Dictionary();
}
private function zSort(container:Sprite):void{
var layer:RenderLayer;
var elayer:EffectLayer;
var c:int;
var i:uint;
var sort:Array = [];
for each (layer in layers) {
layer.screenDepth = (layer.screenDepth / layer.faceCount);
sort.push({layer:layer, screenDepth:layer.screenDepth});
};
for each (elayer in effectLayers) {
elayer.screenDepth = (elayer.screenDepth / elayer.faceCount);
sort.push({layer:elayer, screenDepth:elayer.screenDepth});
};
sort.sortOn("screenDepth", (Array.DESCENDING | Array.NUMERIC));
c = -1;
i = 0;
while (i < sort.length) {
if (sort[i].layer.parent == container){
++c;
container.setChildIndex(sort[i].layer, c);
};
i++;
};
}
public function sortlayers(container:Sprite):void{
if (sortMode == RenderLayerSortMode.Z_SORT){
zSort(container);
} else {
if (sortMode == RenderLayerSortMode.INDEX_SORT){
indexSort(container);
};
};
}
public function checkIndividualLayers(scene:SceneObject3D, viewport:Viewport3D):void{
var rl:RenderLayer;
var do3d:DisplayObject3D;
for each (do3d in scene.children) {
if (do3d.hasOwnRenderLayer){
if (do3d.renderLayer == null){
rl = new RenderLayer();
viewport.addRenderLayer(rl);
do3d.renderLayer = rl;
viewport.containers[do3d] = rl;
};
do3d.renderLayer.filters = do3d.filters;
} else {
if (viewport.containers[do3d]){
viewport.removeRenderLayer(viewport.containers[do3d]);
viewport.containers[do3d] = null;
delete viewport.containers[do3d];
};
};
};
}
public function updateAfterRender():void{
var el:EffectLayer;
for each (el in effectLayers) {
el.renderEffects();
};
}
public function resetLayers():void{
var layer:RenderLayer;
var elayer:RenderLayer;
for each (layer in layers) {
layer.faceCount = 0;
layer.screenDepth = 0;
layer.graphics.clear();
};
for each (elayer in effectLayers) {
elayer.faceCount = 0;
elayer.screenDepth = 0;
elayer.graphics.clear();
};
}
public function addRenderLayer(layer:RenderLayer):void{
if ((layer is EffectLayer)){
effectLayers[layer] = layer;
} else {
layers[layer] = layer;
};
}
public function getDefaultLayer():RenderLayer{
return (defaultLayer);
}
public function removeRenderLayer(layer:RenderLayer):void{
if ((layer is EffectLayer)){
effectLayers[layer] = null;
delete effectLayers[layer];
} else {
layers[layer] = null;
delete layers[layer];
};
}
public function addDefaultLayer(layer:RenderLayer):void{
defaultLayer = layer;
addRenderLayer(layer);
}
public function updateBeforeRender():void{
var el:EffectLayer;
for each (el in effectLayers) {
el.updateBeforeRender();
};
}
private function indexSort(container:Sprite):void{
var layer:RenderLayer;
var elayer:EffectLayer;
var c:int;
var i:uint;
var sort:Array = [];
for each (layer in layers) {
layer.screenDepth = (layer.screenDepth / layer.faceCount);
sort.push({layer:layer, screenDepth:layer.layerIndex});
};
for each (elayer in effectLayers) {
elayer.screenDepth = (elayer.screenDepth / elayer.faceCount);
sort.push({layer:elayer, screenDepth:elayer.layerIndex});
};
sort.sortOn("screenDepth", (Array.DESCENDING | Array.NUMERIC));
c = -1;
i = 0;
while (i < sort.length) {
if (sort[i].layer.parent == container){
c++;
container.setChildIndex(sort[i].layer, c);
};
i++;
};
}
public static function getInstance():RenderLayerManager{
if (_instance == null){
_instance = new (RenderLayerManager);
};
return (_instance);
}
}
}//package org.papervision3d.core.layers.utils
Section 39
//RenderLayerSortMode (org.papervision3d.core.layers.utils.RenderLayerSortMode)
package org.papervision3d.core.layers.utils {
public class RenderLayerSortMode {
public static var Z_SORT:int = 0;
public static var INDEX_SORT:int = 1;
public function RenderLayerSortMode(){
super();
}
}
}//package org.papervision3d.core.layers.utils
Section 40
//EffectLayer (org.papervision3d.core.layers.EffectLayer)
package org.papervision3d.core.layers {
import org.papervision3d.core.effects.*;
public class EffectLayer extends RenderLayer {
public var effects:Array;
public function EffectLayer(){
super();
effects = new Array();
drawLayer = this;
}
public function addEffect(fx:AbstractEffect):void{
fx.attachEffect(this);
effects.push(fx);
}
public function removeEffect(fx:AbstractEffect):void{
var e:AbstractEffect;
this.filters = [];
effects.splice(effects.indexOf(fx), 1);
for each (e in effects) {
e.attachEffect(this);
};
}
public function renderEffects():void{
var e:AbstractEffect;
for each (e in effects) {
e.postRender();
};
}
public function removeAllEffects():void{
this.filters = [];
effects = [];
}
public function updateBeforeRender():void{
var e:AbstractEffect;
faceCount = 0;
screenDepth = 0;
for each (e in effects) {
e.preRender();
};
this.graphics.clear();
}
}
}//package org.papervision3d.core.layers
Section 41
//RenderLayer (org.papervision3d.core.layers.RenderLayer)
package org.papervision3d.core.layers {
import flash.display.*;
public class RenderLayer extends Sprite {
public var layerIndex:Number;// = 1
public var faceCount:Number;// = 0
public var screenDepth:Number;// = 0
public var drawLayer:Sprite;
public function RenderLayer(){
super();
drawLayer = this;
}
}
}//package org.papervision3d.core.layers
Section 42
//AbstractLightShadeMaterial (org.papervision3d.core.material.AbstractLightShadeMaterial)
package org.papervision3d.core.material {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.render.material.*;
import flash.utils.*;
import org.papervision3d.core.render.draw.*;
public class AbstractLightShadeMaterial extends TriangleMaterial implements ITriangleDrawer, IUpdateBeforeMaterial {
public var lightMatrices:Dictionary;
private var _light:LightObject3D;
protected static var lightMatrix:Matrix3D;
public function AbstractLightShadeMaterial(){
super();
init();
}
public function updateBeforeRender(renderSessionData:RenderSessionData):void{
var object:DisplayObject3D;
for each (object in objects) {
lightMatrices[object] = LightMatrix.getLightMatrix(light, object, renderSessionData);
};
}
protected function init():void{
lightMatrices = new Dictionary();
}
public function get light():LightObject3D{
return (_light);
}
public function set light(light:LightObject3D):void{
_light = light;
}
}
}//package org.papervision3d.core.material
Section 43
//TriangleMaterial (org.papervision3d.core.material.TriangleMaterial)
package org.papervision3d.core.material {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.render.draw.*;
public class TriangleMaterial extends MaterialObject3D implements ITriangleDrawer {
public function TriangleMaterial(){
super();
}
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
}
}
}//package org.papervision3d.core.material
Section 44
//Matrix3D (org.papervision3d.core.math.Matrix3D)
package org.papervision3d.core.math {
public class Matrix3D {
public var n31:Number;
public var n32:Number;
public var n11:Number;
public var n34:Number;
public var n13:Number;
public var n14:Number;
public var n33:Number;
public var n12:Number;
public var n41:Number;
public var n42:Number;
public var n21:Number;
public var n22:Number;
public var n23:Number;
public var n24:Number;
public var n44:Number;
public var n43:Number;
private static var _cos:Function = Math.cos;
private static var _sin:Function = Math.sin;
private static var temp:Matrix3D = Matrix3D.IDENTITY;
private static var n3Di:Number3D = Number3D.ZERO;
private static var n3Dj:Number3D = Number3D.ZERO;
private static var n3Dk:Number3D = Number3D.ZERO;
private static var toDEGREES:Number = 57.2957795130823;
private static var toRADIANS:Number = 0.0174532925199433;
public function Matrix3D(args:Array=null){
super();
reset(args);
}
public function calculateMultiply3x3(a:Matrix3D, b:Matrix3D):void{
var a11:Number = a.n11;
var b11:Number = b.n11;
var a21:Number = a.n21;
var b21:Number = b.n21;
var a31:Number = a.n31;
var b31:Number = b.n31;
var a12:Number = a.n12;
var b12:Number = b.n12;
var a22:Number = a.n22;
var b22:Number = b.n22;
var a32:Number = a.n32;
var b32:Number = b.n32;
var a13:Number = a.n13;
var b13:Number = b.n13;
var a23:Number = a.n23;
var b23:Number = b.n23;
var a33:Number = a.n33;
var b33:Number = b.n33;
this.n11 = (((a11 * b11) + (a12 * b21)) + (a13 * b31));
this.n12 = (((a11 * b12) + (a12 * b22)) + (a13 * b32));
this.n13 = (((a11 * b13) + (a12 * b23)) + (a13 * b33));
this.n21 = (((a21 * b11) + (a22 * b21)) + (a23 * b31));
this.n22 = (((a21 * b12) + (a22 * b22)) + (a23 * b32));
this.n23 = (((a21 * b13) + (a22 * b23)) + (a23 * b33));
this.n31 = (((a31 * b11) + (a32 * b21)) + (a33 * b31));
this.n32 = (((a31 * b12) + (a32 * b22)) + (a33 * b32));
this.n33 = (((a31 * b13) + (a32 * b23)) + (a33 * b33));
}
public function calculateMultiply4x4(a:Matrix3D, b:Matrix3D):void{
var a11:Number = a.n11;
var b11:Number = b.n11;
var a21:Number = a.n21;
var b21:Number = b.n21;
var a31:Number = a.n31;
var b31:Number = b.n31;
var a41:Number = a.n41;
var b41:Number = b.n41;
var a12:Number = a.n12;
var b12:Number = b.n12;
var a22:Number = a.n22;
var b22:Number = b.n22;
var a32:Number = a.n32;
var b32:Number = b.n32;
var a42:Number = a.n42;
var b42:Number = b.n42;
var a13:Number = a.n13;
var b13:Number = b.n13;
var a23:Number = a.n23;
var b23:Number = b.n23;
var a33:Number = a.n33;
var b33:Number = b.n33;
var a43:Number = a.n43;
var b43:Number = b.n43;
var a14:Number = a.n14;
var b14:Number = b.n14;
var a24:Number = a.n24;
var b24:Number = b.n24;
var a34:Number = a.n34;
var b34:Number = b.n34;
var a44:Number = a.n44;
var b44:Number = b.n44;
this.n11 = (((a11 * b11) + (a12 * b21)) + (a13 * b31));
this.n12 = (((a11 * b12) + (a12 * b22)) + (a13 * b32));
this.n13 = (((a11 * b13) + (a12 * b23)) + (a13 * b33));
this.n14 = ((((a11 * b14) + (a12 * b24)) + (a13 * b34)) + a14);
this.n21 = (((a21 * b11) + (a22 * b21)) + (a23 * b31));
this.n22 = (((a21 * b12) + (a22 * b22)) + (a23 * b32));
this.n23 = (((a21 * b13) + (a22 * b23)) + (a23 * b33));
this.n24 = ((((a21 * b14) + (a22 * b24)) + (a23 * b34)) + a24);
this.n31 = (((a31 * b11) + (a32 * b21)) + (a33 * b31));
this.n32 = (((a31 * b12) + (a32 * b22)) + (a33 * b32));
this.n33 = (((a31 * b13) + (a32 * b23)) + (a33 * b33));
this.n34 = ((((a31 * b14) + (a32 * b24)) + (a33 * b34)) + a34);
this.n41 = (((a41 * b11) + (a42 * b21)) + (a43 * b31));
this.n42 = (((a41 * b12) + (a42 * b22)) + (a43 * b32));
this.n43 = (((a41 * b13) + (a42 * b23)) + (a43 * b33));
this.n44 = ((((a41 * b14) + (a42 * b24)) + (a43 * b34)) + a44);
}
public function get det():Number{
return ((((((this.n11 * this.n22) - (this.n21 * this.n12)) * this.n33) - (((this.n11 * this.n32) - (this.n31 * this.n12)) * this.n23)) + (((this.n21 * this.n32) - (this.n31 * this.n22)) * this.n13)));
}
public function copy(m:Matrix3D):Matrix3D{
this.n11 = m.n11;
this.n12 = m.n12;
this.n13 = m.n13;
this.n14 = m.n14;
this.n21 = m.n21;
this.n22 = m.n22;
this.n23 = m.n23;
this.n24 = m.n24;
this.n31 = m.n31;
this.n32 = m.n32;
this.n33 = m.n33;
this.n34 = m.n34;
return (this);
}
public function copy3x3(m:Matrix3D):Matrix3D{
this.n11 = m.n11;
this.n12 = m.n12;
this.n13 = m.n13;
this.n21 = m.n21;
this.n22 = m.n22;
this.n23 = m.n23;
this.n31 = m.n31;
this.n32 = m.n32;
this.n33 = m.n33;
return (this);
}
public function calculateAdd(a:Matrix3D, b:Matrix3D):void{
this.n11 = (a.n11 + b.n11);
this.n12 = (a.n12 + b.n12);
this.n13 = (a.n13 + b.n13);
this.n14 = (a.n14 + b.n14);
this.n21 = (a.n21 + b.n21);
this.n22 = (a.n22 + b.n22);
this.n23 = (a.n23 + b.n23);
this.n24 = (a.n24 + b.n24);
this.n31 = (a.n31 + b.n31);
this.n32 = (a.n32 + b.n32);
this.n33 = (a.n33 + b.n33);
this.n34 = (a.n34 + b.n34);
}
public function calculateMultiply(a:Matrix3D, b:Matrix3D):void{
var a11:Number = a.n11;
var b11:Number = b.n11;
var a21:Number = a.n21;
var b21:Number = b.n21;
var a31:Number = a.n31;
var b31:Number = b.n31;
var a12:Number = a.n12;
var b12:Number = b.n12;
var a22:Number = a.n22;
var b22:Number = b.n22;
var a32:Number = a.n32;
var b32:Number = b.n32;
var a13:Number = a.n13;
var b13:Number = b.n13;
var a23:Number = a.n23;
var b23:Number = b.n23;
var a33:Number = a.n33;
var b33:Number = b.n33;
var a14:Number = a.n14;
var b14:Number = b.n14;
var a24:Number = a.n24;
var b24:Number = b.n24;
var a34:Number = a.n34;
var b34:Number = b.n34;
this.n11 = (((a11 * b11) + (a12 * b21)) + (a13 * b31));
this.n12 = (((a11 * b12) + (a12 * b22)) + (a13 * b32));
this.n13 = (((a11 * b13) + (a12 * b23)) + (a13 * b33));
this.n14 = ((((a11 * b14) + (a12 * b24)) + (a13 * b34)) + a14);
this.n21 = (((a21 * b11) + (a22 * b21)) + (a23 * b31));
this.n22 = (((a21 * b12) + (a22 * b22)) + (a23 * b32));
this.n23 = (((a21 * b13) + (a22 * b23)) + (a23 * b33));
this.n24 = ((((a21 * b14) + (a22 * b24)) + (a23 * b34)) + a24);
this.n31 = (((a31 * b11) + (a32 * b21)) + (a33 * b31));
this.n32 = (((a31 * b12) + (a32 * b22)) + (a33 * b32));
this.n33 = (((a31 * b13) + (a32 * b23)) + (a33 * b33));
this.n34 = ((((a31 * b14) + (a32 * b24)) + (a33 * b34)) + a34);
}
public function reset(args:Array=null):void{
if (((!(args)) || ((args.length < 12)))){
n11 = (n22 = (n33 = (n44 = 1)));
n12 = (n13 = (n14 = (n21 = (n23 = (n24 = (n31 = (n32 = (n34 = (n41 = (n42 = (n43 = 0)))))))))));
} else {
n11 = args[0];
n12 = args[1];
n13 = args[2];
n14 = args[3];
n21 = args[4];
n22 = args[5];
n23 = args[6];
n24 = args[7];
n31 = args[8];
n32 = args[9];
n33 = args[10];
n34 = args[11];
if (args.length == 16){
n41 = args[12];
n42 = args[13];
n43 = args[14];
n44 = args[15];
} else {
n41 = (n42 = (n43 = (n44 = 0)));
};
};
}
public function invert():void{
temp.copy(this);
calculateInverse(temp);
}
public function calculateInverse(m:Matrix3D):void{
var m11:Number;
var m21:Number;
var m31:Number;
var m12:Number;
var m22:Number;
var m32:Number;
var m13:Number;
var m23:Number;
var m33:Number;
var m14:Number;
var m24:Number;
var m34:Number;
var d:Number = m.det;
if (Math.abs(d) > 0.001){
d = (1 / d);
m11 = m.n11;
m21 = m.n21;
m31 = m.n31;
m12 = m.n12;
m22 = m.n22;
m32 = m.n32;
m13 = m.n13;
m23 = m.n23;
m33 = m.n33;
m14 = m.n14;
m24 = m.n24;
m34 = m.n34;
this.n11 = (d * ((m22 * m33) - (m32 * m23)));
this.n12 = (-(d) * ((m12 * m33) - (m32 * m13)));
this.n13 = (d * ((m12 * m23) - (m22 * m13)));
this.n14 = (-(d) * (((m12 * ((m23 * m34) - (m33 * m24))) - (m22 * ((m13 * m34) - (m33 * m14)))) + (m32 * ((m13 * m24) - (m23 * m14)))));
this.n21 = (-(d) * ((m21 * m33) - (m31 * m23)));
this.n22 = (d * ((m11 * m33) - (m31 * m13)));
this.n23 = (-(d) * ((m11 * m23) - (m21 * m13)));
this.n24 = (d * (((m11 * ((m23 * m34) - (m33 * m24))) - (m21 * ((m13 * m34) - (m33 * m14)))) + (m31 * ((m13 * m24) - (m23 * m14)))));
this.n31 = (d * ((m21 * m32) - (m31 * m22)));
this.n32 = (-(d) * ((m11 * m32) - (m31 * m12)));
this.n33 = (d * ((m11 * m22) - (m21 * m12)));
this.n34 = (-(d) * (((m11 * ((m22 * m34) - (m32 * m24))) - (m21 * ((m12 * m34) - (m32 * m14)))) + (m31 * ((m12 * m24) - (m22 * m14)))));
};
}
public function toString():String{
var s:String = "";
s = (s + ((((((((int((n11 * 1000)) / 1000) + "\t\t") + (int((n12 * 1000)) / 1000)) + "\t\t") + (int((n13 * 1000)) / 1000)) + "\t\t") + (int((n14 * 1000)) / 1000)) + "\n"));
s = (s + ((((((((int((n21 * 1000)) / 1000) + "\t\t") + (int((n22 * 1000)) / 1000)) + "\t\t") + (int((n23 * 1000)) / 1000)) + "\t\t") + (int((n24 * 1000)) / 1000)) + "\n"));
s = (s + ((((((((int((n31 * 1000)) / 1000) + "\t\t") + (int((n32 * 1000)) / 1000)) + "\t\t") + (int((n33 * 1000)) / 1000)) + "\t\t") + (int((n34 * 1000)) / 1000)) + "\n"));
s = (s + ((((((((int((n41 * 1000)) / 1000) + "\t\t") + (int((n42 * 1000)) / 1000)) + "\t\t") + (int((n43 * 1000)) / 1000)) + "\t\t") + (int((n44 * 1000)) / 1000)) + "\n"));
return (s);
}
public static function rotationMatrixWithReference(axis:Number3D, rad:Number, ref:Number3D):Matrix3D{
var m:Matrix3D = Matrix3D.translationMatrix(ref.x, -(ref.y), ref.z);
m.calculateMultiply(m, Matrix3D.rotationMatrix(axis.x, axis.y, axis.z, rad));
m.calculateMultiply(m, Matrix3D.translationMatrix(-(ref.x), ref.y, -(ref.z)));
return (m);
}
public static function multiplyVector(m:Matrix3D, v:Number3D):void{
var vy:Number;
var vz:Number;
var vx:Number = v.x;
vy = v.y;
vz = v.z;
v.x = ((((vx * m.n11) + (vy * m.n12)) + (vz * m.n13)) + m.n14);
v.y = ((((vx * m.n21) + (vy * m.n22)) + (vz * m.n23)) + m.n24);
v.z = ((((vx * m.n31) + (vy * m.n32)) + (vz * m.n33)) + m.n34);
}
public static function multiplyVector4x4(m:Matrix3D, v:Number3D):void{
var vx:Number;
var vz:Number;
var vw:Number;
vx = v.x;
var vy:Number = v.y;
vz = v.z;
vw = (1 / ((((vx * m.n41) + (vy * m.n42)) + (vz * m.n43)) + m.n44));
v.x = ((((vx * m.n11) + (vy * m.n12)) + (vz * m.n13)) + m.n14);
v.y = ((((vx * m.n21) + (vy * m.n22)) + (vz * m.n23)) + m.n24);
v.z = ((((vx * m.n31) + (vy * m.n32)) + (vz * m.n33)) + m.n34);
v.x = (v.x * vw);
v.y = (v.y * vw);
v.z = (v.z * vw);
}
public static function multiply3x3(a:Matrix3D, b:Matrix3D):Matrix3D{
var m:Matrix3D = new (Matrix3D);
m.calculateMultiply3x3(a, b);
return (m);
}
public static function normalizeQuaternion(q:Object):Object{
var mag:Number = magnitudeQuaternion(q);
q.x = (q.x / mag);
q.y = (q.y / mag);
q.z = (q.z / mag);
q.w = (q.w / mag);
return (q);
}
public static function multiplyVector3x3(m:Matrix3D, v:Number3D):void{
var vz:Number;
var vx:Number = v.x;
var vy:Number = v.y;
vz = v.z;
v.x = (((vx * m.n11) + (vy * m.n12)) + (vz * m.n13));
v.y = (((vx * m.n21) + (vy * m.n22)) + (vz * m.n23));
v.z = (((vx * m.n31) + (vy * m.n32)) + (vz * m.n33));
}
public static function axis2quaternion(x:Number, y:Number, z:Number, angle:Number):Object{
var sin:Number = Math.sin((angle / 2));
var cos:Number = Math.cos((angle / 2));
var q:Object = new Object();
q.x = (x * sin);
q.y = (y * sin);
q.z = (z * sin);
q.w = cos;
return (normalizeQuaternion(q));
}
public static function translationMatrix(x:Number, y:Number, z:Number):Matrix3D{
var m:Matrix3D = IDENTITY;
m.n14 = x;
m.n24 = y;
m.n34 = z;
return (m);
}
public static function magnitudeQuaternion(q:Object):Number{
return (Math.sqrt(((((q.w * q.w) + (q.x * q.x)) + (q.y * q.y)) + (q.z * q.z))));
}
public static function rotationX(rad:Number):Matrix3D{
var m:Matrix3D = IDENTITY;
var c:Number = Math.cos(rad);
var s:Number = Math.sin(rad);
m.n22 = c;
m.n23 = -(s);
m.n32 = s;
m.n33 = c;
return (m);
}
public static function rotationY(rad:Number):Matrix3D{
var m:Matrix3D = IDENTITY;
var c:Number = Math.cos(rad);
var s:Number = Math.sin(rad);
m.n11 = c;
m.n13 = -(s);
m.n31 = s;
m.n33 = c;
return (m);
}
public static function rotationZ(rad:Number):Matrix3D{
var m:Matrix3D = IDENTITY;
var c:Number = Math.cos(rad);
var s:Number = Math.sin(rad);
m.n11 = c;
m.n12 = -(s);
m.n21 = s;
m.n22 = c;
return (m);
}
public static function clone(m:Matrix3D):Matrix3D{
return (new Matrix3D([m.n11, m.n12, m.n13, m.n14, m.n21, m.n22, m.n23, m.n24, m.n31, m.n32, m.n33, m.n34]));
}
public static function rotationMatrix(x:Number, y:Number, z:Number, rad:Number, targetmatrix:Matrix3D=null):Matrix3D{
var m:Matrix3D;
if (!targetmatrix){
m = IDENTITY;
} else {
m = targetmatrix;
};
var nCos:Number = Math.cos(rad);
var nSin:Number = Math.sin(rad);
var scos:Number = (1 - nCos);
var sxy:Number = ((x * y) * scos);
var syz:Number = ((y * z) * scos);
var sxz:Number = ((x * z) * scos);
var sz:Number = (nSin * z);
var sy:Number = (nSin * y);
var sx:Number = (nSin * x);
m.n11 = (nCos + ((x * x) * scos));
m.n12 = (-(sz) + sxy);
m.n13 = (sy + sxz);
m.n21 = (sz + sxy);
m.n22 = (nCos + ((y * y) * scos));
m.n23 = (-(sx) + syz);
m.n31 = (-(sy) + sxz);
m.n32 = (sx + syz);
m.n33 = (nCos + ((z * z) * scos));
return (m);
}
public static function add(a:Matrix3D, b:Matrix3D):Matrix3D{
var m:Matrix3D = new (Matrix3D);
m.calculateAdd(a, b);
return (m);
}
public static function multiply(a:Matrix3D, b:Matrix3D):Matrix3D{
var m:Matrix3D = new (Matrix3D);
m.calculateMultiply(a, b);
return (m);
}
public static function euler2quaternion(ax:Number, ay:Number, az:Number, targetquat:Quaternion=null):Quaternion{
var q:Quaternion;
var fSinPitch:Number = Math.sin((ax * 0.5));
var fCosPitch:Number = Math.cos((ax * 0.5));
var fSinYaw:Number = Math.sin((ay * 0.5));
var fCosYaw:Number = Math.cos((ay * 0.5));
var fSinRoll:Number = Math.sin((az * 0.5));
var fCosRoll:Number = Math.cos((az * 0.5));
var fCosPitchCosYaw:Number = (fCosPitch * fCosYaw);
var fSinPitchSinYaw:Number = (fSinPitch * fSinYaw);
if (!targetquat){
q = new Quaternion();
} else {
q = targetquat;
};
q.x = ((fSinRoll * fCosPitchCosYaw) - (fCosRoll * fSinPitchSinYaw));
q.y = (((fCosRoll * fSinPitch) * fCosYaw) + ((fSinRoll * fCosPitch) * fSinYaw));
q.z = (((fCosRoll * fCosPitch) * fSinYaw) - ((fSinRoll * fSinPitch) * fCosYaw));
q.w = ((fCosRoll * fCosPitchCosYaw) + (fSinRoll * fSinPitchSinYaw));
return (q);
}
public static function quaternion2matrix(x:Number, y:Number, z:Number, w:Number, targetmatrix:Matrix3D=null):Matrix3D{
var m:Matrix3D;
var xx:Number = (x * x);
var xy:Number = (x * y);
var xz:Number = (x * z);
var xw:Number = (x * w);
var yy:Number = (y * y);
var yz:Number = (y * z);
var yw:Number = (y * w);
var zz:Number = (z * z);
var zw:Number = (z * w);
if (!targetmatrix){
m = IDENTITY;
} else {
m = targetmatrix;
};
m.n11 = (1 - (2 * (yy + zz)));
m.n12 = (2 * (xy - zw));
m.n13 = (2 * (xz + yw));
m.n21 = (2 * (xy + zw));
m.n22 = (1 - (2 * (xx + zz)));
m.n23 = (2 * (yz - xw));
m.n31 = (2 * (xz - yw));
m.n32 = (2 * (yz + xw));
m.n33 = (1 - (2 * (xx + yy)));
return (m);
}
public static function inverse(m:Matrix3D):Matrix3D{
var inv:Matrix3D = new (Matrix3D);
inv.calculateInverse(m);
return (inv);
}
public static function euler2matrix(deg:Number3D):Matrix3D{
temp.reset();
var m:Matrix3D = temp;
m = temp;
var ax:Number = (deg.x * toRADIANS);
var ay:Number = (deg.y * toRADIANS);
var az:Number = (deg.z * toRADIANS);
var a:Number = Math.cos(ax);
var b:Number = Math.sin(ax);
var c:Number = Math.cos(ay);
var d:Number = Math.sin(ay);
var e:Number = Math.cos(az);
var f:Number = Math.sin(az);
var ad:Number = (a * d);
var bd:Number = (b * d);
m.n11 = (c * e);
m.n12 = (-(c) * f);
m.n13 = d;
m.n21 = ((bd * e) + (a * f));
m.n22 = ((-(bd) * f) + (a * e));
m.n23 = (-(b) * c);
m.n31 = ((-(ad) * e) + (b * f));
m.n32 = ((ad * f) + (b * e));
m.n33 = (a * c);
return (m);
}
public static function scaleMatrix(x:Number, y:Number, z:Number):Matrix3D{
var m:Matrix3D = IDENTITY;
m.n11 = x;
m.n22 = y;
m.n33 = z;
return (m);
}
public static function rotateAxis(m:Matrix3D, v:Number3D):void{
var vx:Number = v.x;
var vy:Number = v.y;
var vz:Number = v.z;
v.x = (((vx * m.n11) + (vy * m.n12)) + (vz * m.n13));
v.y = (((vx * m.n21) + (vy * m.n22)) + (vz * m.n23));
v.z = (((vx * m.n31) + (vy * m.n32)) + (vz * m.n33));
v.normalize();
}
public static function matrix2euler(t:Matrix3D, rot:Number3D=null):Number3D{
if (!rot){
rot = Number3D.ZERO;
};
n3Di.reset(t.n11, t.n21, t.n31);
n3Dj.reset(t.n12, t.n22, t.n32);
n3Dk.reset(t.n13, t.n23, t.n33);
n3Di.normalize();
n3Dj.normalize();
n3Dk.normalize();
temp.reset([n3Di.x, n3Dj.x, n3Dk.x, 0, n3Di.y, n3Dj.y, n3Dk.y, 0, n3Di.z, n3Dj.z, n3Dk.z, 0]);
var m:Matrix3D = temp;
rot.x = Math.atan2(m.n23, m.n33);
var rx:Matrix3D = Matrix3D.rotationX(-(rot.x));
var n:Matrix3D = Matrix3D.multiply(rx, m);
var cy:Number = Math.sqrt(((n.n11 * n.n11) + (n.n21 * n.n21)));
rot.y = Math.atan2(-(n.n31), cy);
rot.z = Math.atan2(-(n.n12), n.n11);
if (rot.x == Math.PI){
if (rot.y > 0){
rot.y = (rot.y - Math.PI);
} else {
rot.y = (rot.y + Math.PI);
};
rot.x = 0;
rot.z = (rot.z + Math.PI);
};
rot.x = (rot.x * toDEGREES);
rot.y = (rot.y * toDEGREES);
rot.z = (rot.z * toDEGREES);
return (rot);
}
public static function multiplyQuaternion(a:Object, b:Object):Object{
var ax:Number = a.x;
var ay:Number = a.y;
var az:Number = a.z;
var aw:Number = a.w;
var bx:Number = b.x;
var by:Number = b.y;
var bz:Number = b.z;
var bw:Number = b.w;
var q:Object = new Object();
q.x = ((((aw * bx) + (ax * bw)) + (ay * bz)) - (az * by));
q.y = ((((aw * by) + (ay * bw)) + (az * bx)) - (ax * bz));
q.z = ((((aw * bz) + (az * bw)) + (ax * by)) - (ay * bx));
q.w = ((((aw * bw) - (ax * bx)) - (ay * by)) - (az * bz));
return (q);
}
public static function get IDENTITY():Matrix3D{
return (new Matrix3D([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]));
}
}
}//package org.papervision3d.core.math
Section 45
//Number3D (org.papervision3d.core.math.Number3D)
package org.papervision3d.core.math {
import org.papervision3d.*;
public class Number3D {
public var x:Number;
public var y:Number;
public var z:Number;
public static var toDEGREES:Number = 57.2957795130823;
private static var temp:Number3D = Number3D.ZERO;
public static var toRADIANS:Number = 0.0174532925199433;
public function Number3D(x:Number=0, y:Number=0, z:Number=0){
super();
this.x = x;
this.y = y;
this.z = z;
}
public function isModuloLessThan(v:Number):Boolean{
return ((moduloSquared < (v * v)));
}
public function rotateX(angle:Number):void{
if (Papervision3D.useDEGREES){
angle = (angle * toRADIANS);
};
var cosRY:Number = Math.cos(angle);
var sinRY:Number = Math.sin(angle);
temp.copyFrom(this);
this.y = ((temp.y * cosRY) - (temp.z * sinRY));
this.z = ((temp.y * sinRY) + (temp.z * cosRY));
}
public function rotateY(angle:Number):void{
if (Papervision3D.useDEGREES){
angle = (angle * toRADIANS);
};
var cosRY:Number = Math.cos(angle);
var sinRY:Number = Math.sin(angle);
temp.copyFrom(this);
this.x = ((temp.x * cosRY) + (temp.z * sinRY));
this.z = ((temp.x * -(sinRY)) + (temp.z * cosRY));
}
public function plusEq(v:Number3D):void{
x = (x + v.x);
y = (y + v.y);
z = (z + v.z);
}
public function multiplyEq(n:Number):void{
x = (x * n);
y = (y * n);
z = (z * n);
}
public function toString():String{
return (((((("x:" + (Math.round((x * 100)) / 100)) + " y:") + (Math.round((y * 100)) / 100)) + " z:") + (Math.round((z * 100)) / 100)));
}
public function normalize():void{
var mod:Number = this.modulo;
if (((!((mod == 0))) && (!((mod == 1))))){
this.x = (this.x / mod);
this.y = (this.y / mod);
this.z = (this.z / mod);
};
}
public function rotateZ(angle:Number):void{
if (Papervision3D.useDEGREES){
angle = (angle * toRADIANS);
};
var cosRY:Number = Math.cos(angle);
var sinRY:Number = Math.sin(angle);
temp.copyFrom(this);
this.x = ((temp.x * cosRY) - (temp.y * sinRY));
this.y = ((temp.x * sinRY) + (temp.y * cosRY));
}
public function reset(newx:Number=0, newy:Number=0, newz:Number=0):void{
x = newx;
y = newy;
z = newz;
}
public function get moduloSquared():Number{
return ((((this.x * this.x) + (this.y * this.y)) + (this.z * this.z)));
}
public function get modulo():Number{
return (Math.sqrt((((this.x * this.x) + (this.y * this.y)) + (this.z * this.z))));
}
public function copyTo(n:Number3D):void{
n.x = x;
n.y = y;
n.z = z;
}
public function isModuloGreaterThan(v:Number):Boolean{
return ((moduloSquared > (v * v)));
}
public function minusEq(v:Number3D):void{
x = (x - v.x);
y = (y - v.y);
z = (z - v.z);
}
public function clone():Number3D{
return (new Number3D(this.x, this.y, this.z));
}
public function isModuloEqualTo(v:Number):Boolean{
return ((moduloSquared == (v * v)));
}
public function copyFrom(n:Number3D):void{
x = n.x;
y = n.y;
z = n.z;
}
public static function sub(v:Number3D, w:Number3D):Number3D{
return (new Number3D((v.x - w.x), (v.y - w.y), (v.z - w.z)));
}
public static function add(v:Number3D, w:Number3D):Number3D{
return (new Number3D((v.x + w.x), (v.y + w.y), (v.z + w.z)));
}
public static function cross(v:Number3D, w:Number3D, targetN:Number3D=null):Number3D{
if (!targetN){
targetN = ZERO;
};
targetN.reset(((w.y * v.z) - (w.z * v.y)), ((w.z * v.x) - (w.x * v.z)), ((w.x * v.y) - (w.y * v.x)));
return (targetN);
}
public static function dot(v:Number3D, w:Number3D):Number{
return ((((v.x * w.x) + (v.y * w.y)) + (w.z * v.z)));
}
public static function get ZERO():Number3D{
return (new Number3D(0, 0, 0));
}
}
}//package org.papervision3d.core.math
Section 46
//NumberUV (org.papervision3d.core.math.NumberUV)
package org.papervision3d.core.math {
public class NumberUV {
public var u:Number;
public var v:Number;
public function NumberUV(u:Number=0, v:Number=0){
super();
this.u = u;
this.v = v;
}
public function toString():String{
return (((("u:" + u) + " v:") + v));
}
public function clone():NumberUV{
return (new NumberUV(this.u, this.v));
}
public static function get ZERO():NumberUV{
return (new NumberUV(0, 0));
}
}
}//package org.papervision3d.core.math
Section 47
//Plane3D (org.papervision3d.core.math.Plane3D)
package org.papervision3d.core.math {
import org.papervision3d.core.geom.renderables.*;
public class Plane3D {
public var d:Number;
public var normal:Number3D;
public function Plane3D(){
super();
this.normal = new Number3D();
this.d = 0;
}
public function setCoefficients(a:Number, b:Number, c:Number, d:Number):void{
this.normal.x = a;
this.normal.y = b;
this.normal.z = c;
this.d = d;
normalize();
}
public function setNormalAndPoint(normal:Number3D, pt:Number3D):void{
this.normal = normal;
this.d = -(Number3D.dot(normal, pt));
}
public function distance(pt):Number{
var p:Number3D = ((pt is Vertex3D)) ? pt.toNumber3D() : pt;
return ((Number3D.dot(p, normal) + d));
}
public function toString():String{
return ((((((((("[a:" + normal.x) + " b:") + normal.y) + " c:") + normal.z) + " d:") + d) + "]"));
}
public function normalize():void{
var n:Number3D = this.normal;
var len:Number = Math.sqrt((((n.x * n.x) + (n.y * n.y)) + (n.z * n.z)));
n.x = (n.x / len);
n.y = (n.y / len);
n.z = (n.z / len);
this.d = (this.d / len);
}
public function setThreePoints(n0:Number3D, n1:Number3D, n2:Number3D):void{
var ab:Number3D = Number3D.sub(n1, n0);
var ac:Number3D = Number3D.sub(n2, n0);
this.normal = Number3D.cross(ab, ac);
this.normal.normalize();
this.d = -(Number3D.dot(normal, n0));
}
public static function fromThreePoints(n0, n1, n2):Plane3D{
var plane:Plane3D = new (Plane3D);
plane.setThreePoints(new Number3D(n0.x, n0.y, n0.z), new Number3D(n1.x, n1.y, n1.z), new Number3D(n2.x, n2.y, n2.z));
return (plane);
}
}
}//package org.papervision3d.core.math
Section 48
//Quaternion (org.papervision3d.core.math.Quaternion)
package org.papervision3d.core.math {
public class Quaternion {
private var _matrix:Matrix3D;
public var w:Number;
public var x:Number;
public var y:Number;
public var z:Number;
public static const EPSILON:Number = 1E-6;
public static const DEGTORAD:Number = 0.0174532925199433;
public static const RADTODEG:Number = 57.2957795130823;
public function Quaternion(x:Number=0, y:Number=0, z:Number=0, w:Number=1):void{
super();
this.x = x;
this.y = y;
this.z = z;
this.w = w;
_matrix = Matrix3D.IDENTITY;
}
public function normalize():void{
var m:Number;
var len:Number = this.modulo;
if (Math.abs(len) < EPSILON){
x = (y = (z = 0));
w = 1;
} else {
m = (1 / len);
x = (x * m);
y = (y * m);
z = (z * m);
w = (w * m);
};
}
public function get modulo():Number{
return (Math.sqrt(((((x * x) + (y * y)) + (z * z)) + (w * w))));
}
public function toMatrix():Matrix3D{
var xx:Number = (x * x);
var xy:Number = (x * y);
var xz:Number = (x * z);
var xw:Number = (x * w);
var yy:Number = (y * y);
var yz:Number = (y * z);
var yw:Number = (y * w);
var zz:Number = (z * z);
var zw:Number = (z * w);
_matrix.n11 = (1 - (2 * (yy + zz)));
_matrix.n12 = (2 * (xy - zw));
_matrix.n13 = (2 * (xz + yw));
_matrix.n21 = (2 * (xy + zw));
_matrix.n22 = (1 - (2 * (xx + zz)));
_matrix.n23 = (2 * (yz - xw));
_matrix.n31 = (2 * (xz - yw));
_matrix.n32 = (2 * (yz + xw));
_matrix.n33 = (1 - (2 * (xx + yy)));
return (_matrix);
}
public function mult(b:Quaternion):void{
var aw:Number = this.w;
var ax:Number = this.x;
var ay:Number = this.y;
var az:Number = this.z;
x = ((((aw * b.x) + (ax * b.w)) + (ay * b.z)) - (az * b.y));
y = ((((aw * b.y) - (ax * b.z)) + (ay * b.w)) + (az * b.x));
z = ((((aw * b.z) + (ax * b.y)) - (ay * b.x)) + (az * b.w));
w = ((((aw * b.w) - (ax * b.x)) - (ay * b.y)) - (az * b.z));
}
public static function createFromEuler(ax:Number, ay:Number, az:Number, useDegrees:Boolean=false):Quaternion{
if (useDegrees){
ax = (ax * DEGTORAD);
ay = (ay * DEGTORAD);
az = (az * DEGTORAD);
};
var fSinPitch:Number = Math.sin((ax * 0.5));
var fCosPitch:Number = Math.cos((ax * 0.5));
var fSinYaw:Number = Math.sin((ay * 0.5));
var fCosYaw:Number = Math.cos((ay * 0.5));
var fSinRoll:Number = Math.sin((az * 0.5));
var fCosRoll:Number = Math.cos((az * 0.5));
var fCosPitchCosYaw:Number = (fCosPitch * fCosYaw);
var fSinPitchSinYaw:Number = (fSinPitch * fSinYaw);
var q:Quaternion = new (Quaternion);
q.x = ((fSinRoll * fCosPitchCosYaw) - (fCosRoll * fSinPitchSinYaw));
q.y = (((fCosRoll * fSinPitch) * fCosYaw) + ((fSinRoll * fCosPitch) * fSinYaw));
q.z = (((fCosRoll * fCosPitch) * fSinYaw) - ((fSinRoll * fSinPitch) * fCosYaw));
q.w = ((fCosRoll * fCosPitchCosYaw) + (fSinRoll * fSinPitchSinYaw));
return (q);
}
public static function createFromMatrix(matrix:Matrix3D):Quaternion{
var s:Number;
var i:int;
var j:int;
var k:int;
var nxt:Array;
var m:Array;
var quat:Quaternion = new (Quaternion);
var q:Array = new Array(4);
var tr:Number = ((matrix.n11 + matrix.n22) + matrix.n33);
if (tr > 0){
s = Math.sqrt((tr + 1));
quat.w = (s / 2);
s = (0.5 / s);
quat.x = ((matrix.n32 - matrix.n23) * s);
quat.y = ((matrix.n13 - matrix.n31) * s);
quat.z = ((matrix.n21 - matrix.n12) * s);
} else {
nxt = [1, 2, 0];
m = [[matrix.n11, matrix.n12, matrix.n13, matrix.n14], [matrix.n21, matrix.n22, matrix.n23, matrix.n24], [matrix.n31, matrix.n32, matrix.n33, matrix.n34]];
i = 0;
if (m[1][1] > m[0][0]){
i = 1;
};
if (m[2][2] > m[i][i]){
i = 2;
};
j = nxt[i];
k = nxt[j];
s = Math.sqrt(((m[i][i] - (m[j][j] + m[k][k])) + 1));
q[i] = (s * 0.5);
if (s != 0){
s = (0.5 / s);
};
q[3] = ((m[k][j] - m[j][k]) * s);
q[j] = ((m[j][i] + m[i][j]) * s);
q[k] = ((m[k][i] + m[i][k]) * s);
quat.x = q[0];
quat.y = q[1];
quat.z = q[2];
quat.w = q[3];
};
return (quat);
}
public static function dot(a:Quaternion, b:Quaternion):Number{
return (((((a.x * b.x) + (a.y * b.y)) + (a.z * b.z)) + (a.w * b.w)));
}
public static function multiply(a:Quaternion, b:Quaternion):Quaternion{
var c:Quaternion = new (Quaternion);
c.x = ((((a.w * b.x) + (a.x * b.w)) + (a.y * b.z)) - (a.z * b.y));
c.y = ((((a.w * b.y) - (a.x * b.z)) + (a.y * b.w)) + (a.z * b.x));
c.z = ((((a.w * b.z) + (a.x * b.y)) - (a.y * b.x)) + (a.z * b.w));
c.w = ((((a.w * b.w) - (a.x * b.x)) - (a.y * b.y)) - (a.z * b.z));
return (c);
}
public static function createFromAxisAngle(x:Number, y:Number, z:Number, angle:Number):Quaternion{
var sin:Number = Math.sin((angle / 2));
var cos:Number = Math.cos((angle / 2));
var q:Quaternion = new (Quaternion);
q.x = (x * sin);
q.y = (y * sin);
q.z = (z * sin);
q.w = cos;
q.normalize();
return (q);
}
public static function slerp(qa:Quaternion, qb:Quaternion, alpha:Number):Quaternion{
var qm:Quaternion = new (Quaternion);
var cosHalfTheta:Number = ((((qa.w * qb.w) + (qa.x * qb.x)) + (qa.y * qb.y)) + (qa.z * qb.z));
if (Math.abs(cosHalfTheta) >= 1){
qm.w = qa.w;
qm.x = qa.x;
qm.y = qa.y;
qm.z = qa.z;
return (qm);
};
var halfTheta:Number = Math.acos(cosHalfTheta);
var sinHalfTheta:Number = Math.sqrt((1 - (cosHalfTheta * cosHalfTheta)));
if (Math.abs(sinHalfTheta) < 0.001){
qm.w = ((qa.w * 0.5) + (qb.w * 0.5));
qm.x = ((qa.x * 0.5) + (qb.x * 0.5));
qm.y = ((qa.y * 0.5) + (qb.y * 0.5));
qm.z = ((qa.z * 0.5) + (qb.z * 0.5));
return (qm);
};
var ratioA:Number = (Math.sin(((1 - alpha) * halfTheta)) / sinHalfTheta);
var ratioB:Number = (Math.sin((alpha * halfTheta)) / sinHalfTheta);
qm.w = ((qa.w * ratioA) + (qb.w * ratioB));
qm.x = ((qa.x * ratioA) + (qb.x * ratioB));
qm.y = ((qa.y * ratioA) + (qb.y * ratioB));
qm.z = ((qa.z * ratioA) + (qb.z * ratioB));
return (qm);
}
public static function createFromOrthoMatrix(m:Matrix3D):Quaternion{
var q:Quaternion = new (Quaternion);
q.w = (Math.sqrt(Math.max(0, (((1 + m.n11) + m.n22) + m.n33))) / 2);
q.x = (Math.sqrt(Math.max(0, (((1 + m.n11) - m.n22) - m.n33))) / 2);
q.y = (Math.sqrt(Math.max(0, (((1 - m.n11) + m.n22) - m.n33))) / 2);
q.z = (Math.sqrt(Math.max(0, (((1 - m.n11) - m.n22) + m.n33))) / 2);
q.x = (((m.n32 - m.n23) < 0)) ? ((q.x < 0)) ? q.x : -(q.x) : ((q.x < 0)) ? -(q.x) : q.x;
q.y = (((m.n13 - m.n31) < 0)) ? ((q.y < 0)) ? q.y : -(q.y) : ((q.y < 0)) ? -(q.y) : q.y;
q.z = (((m.n21 - m.n12) < 0)) ? ((q.z < 0)) ? q.z : -(q.z) : ((q.z < 0)) ? -(q.z) : q.z;
return (q);
}
public static function conjugate(a:Quaternion):Quaternion{
var q:Quaternion = new (Quaternion);
q.x = -(a.x);
q.y = -(a.y);
q.z = -(a.z);
q.w = a.w;
return (q);
}
}
}//package org.papervision3d.core.math
Section 49
//CameraObject3D (org.papervision3d.core.proto.CameraObject3D)
package org.papervision3d.core.proto {
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.math.*;
public class CameraObject3D extends DisplayObject3D {
public var viewport:Rectangle;
public var eye:Matrix3D;
public var zoom:Number;
public var focus:Number;
public var sort:Boolean;
public static const TYPE:String = "ABSTRACT";
public static var DEFAULT_POS:Number3D = new Number3D(0, 0, -1000);
private static var _flipY:Matrix3D = Matrix3D.scaleMatrix(1, -1, 1);
public function CameraObject3D(zoom:Number=3, focus:Number=500, initObject:Object=null){
super();
this.x = (initObject) ? ((initObject.x) || (DEFAULT_POS.x)) : DEFAULT_POS.x;
this.y = (initObject) ? ((initObject.y) || (DEFAULT_POS.y)) : DEFAULT_POS.y;
this.z = (initObject) ? ((initObject.z) || (DEFAULT_POS.z)) : DEFAULT_POS.z;
this.zoom = zoom;
this.focus = focus;
this.eye = Matrix3D.IDENTITY;
this.sort = (initObject) ? !((initObject.sort == false)) : true;
}
public function transformView(transform:Matrix3D=null):void{
eye.calculateMultiply(((transform) || (this.transform)), _flipY);
eye.invert();
}
public function pan(angle:Number):void{
super.yaw(angle);
}
public function tilt(angle:Number):void{
super.pitch(angle);
}
}
}//package org.papervision3d.core.proto
Section 50
//DisplayObjectContainer3D (org.papervision3d.core.proto.DisplayObjectContainer3D)
package org.papervision3d.core.proto {
import flash.events.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.objects.*;
import flash.utils.*;
import org.papervision3d.*;
public class DisplayObjectContainer3D extends EventDispatcher {
public var root:DisplayObjectContainer3D;
private var _childrenTotal:int;
protected var _childrenByName:Object;
protected var _children:Dictionary;
public function DisplayObjectContainer3D():void{
super();
this._children = new Dictionary(false);
this._childrenByName = new Dictionary(true);
this._childrenTotal = 0;
}
public function addChildren(parent:DisplayObject3D):DisplayObjectContainer3D{
var child:DisplayObject3D;
for each (child in parent.children) {
parent.removeChild(child);
this.addChild(child);
};
return (this);
}
public function get numChildren():int{
return (this._childrenTotal);
}
public function getChildByName(name:String):DisplayObject3D{
return (this._childrenByName[name]);
}
override public function toString():String{
return (childrenList());
}
public function addCollada(filename:String, materials:MaterialsList=null, scale:Number=1):void{
Papervision3D.log("The addCollada() method has been deprecated. Use addChildren( new Collada( filename ) )");
}
public function removeChild(child:DisplayObject3D):DisplayObject3D{
if (child){
delete this._childrenByName[this._children[child]];
if (this._children[child]){
_childrenTotal--;
};
delete this._children[child];
child.parent = null;
child.root = null;
return (child);
};
return (null);
}
public function removeChildByName(name:String):DisplayObject3D{
return (removeChild(getChildByName(name)));
}
public function addChild(child:DisplayObject3D, name:String=null):DisplayObject3D{
name = ((((name) || (child.name))) || (String(child.id)));
this._children[child] = name;
this._childrenByName[name] = child;
this._childrenTotal++;
child.parent = this;
child.root = this.root;
return (child);
}
public function childrenList():String{
var name:String;
var list:String = "";
for (name in this._children) {
list = (list + (name + "\n"));
};
return (list);
}
public function get children():Object{
return (this._childrenByName);
}
}
}//package org.papervision3d.core.proto
Section 51
//GeometryObject3D (org.papervision3d.core.proto.GeometryObject3D)
package org.papervision3d.core.proto {
import flash.events.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.math.*;
import flash.utils.*;
public class GeometryObject3D extends EventDispatcher {
protected var _boundingSphere2:Number;
protected var _boundingSphereDirty:Boolean;// = true
public var _ready:Boolean;// = false
public var dirty:Boolean;
public var faces:Array;
public var vertices:Array;
public function GeometryObject3D(initObject:Object=null):void{
super();
this.dirty = true;
}
public function get boundingSphere2():Number{
if (_boundingSphereDirty){
return (getBoundingSphere2());
};
return (_boundingSphere2);
}
public function get ready():Boolean{
return (_ready);
}
public function transformVertices(transformation:Matrix3D):void{
}
public function set ready(b:Boolean):void{
if (b){
createVertexNormals();
this.dirty = false;
};
_ready = b;
}
public function transformUV(material:MaterialObject3D):void{
var i:String;
if (material.bitmap){
for (i in this.faces) {
faces[i].transformUV(material);
};
};
}
public function getBoundingSphere2():Number{
var d:Number;
var v:Vertex3D;
var max:Number = 0;
for each (v in this.vertices) {
d = (((v.x * v.x) + (v.y * v.y)) + (v.z * v.z));
max = ((d)>max) ? d : max;
};
this._boundingSphereDirty = false;
return ((_boundingSphere2 = max));
}
private function createVertexNormals():void{
var face:Triangle3D;
var vertex3D:Vertex3D;
var tempVertices:Dictionary = new Dictionary(true);
for each (face in faces) {
face.v0.connectedFaces[face] = face;
face.v1.connectedFaces[face] = face;
face.v2.connectedFaces[face] = face;
tempVertices[face.v0] = face.v0;
tempVertices[face.v1] = face.v1;
tempVertices[face.v2] = face.v2;
};
for each (vertex3D in tempVertices) {
vertex3D.calculateNormal();
};
}
}
}//package org.papervision3d.core.proto
Section 52
//LightObject3D (org.papervision3d.core.proto.LightObject3D)
package org.papervision3d.core.proto {
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import org.papervision3d.core.math.*;
import org.papervision3d.objects.primitives.*;
public class LightObject3D extends DisplayObject3D {
public var flipped:Boolean;
public var lightMatrix:Matrix3D;
private var _showLight:Boolean;
private var displaySphere:Sphere;
public function LightObject3D(showLight:Boolean=false, flipped:Boolean=false){
super();
this.lightMatrix = Matrix3D.IDENTITY;
this.showLight = showLight;
this.flipped = flipped;
}
public function get showLight():Boolean{
return (_showLight);
}
public function set showLight(show:Boolean):void{
if (_showLight){
removeChild(displaySphere);
};
if (show){
displaySphere = new Sphere(new WireframeMaterial(0xFFFF00), 10, 3, 2);
addChild(displaySphere);
};
_showLight = show;
}
}
}//package org.papervision3d.core.proto
Section 53
//MaterialObject3D (org.papervision3d.core.proto.MaterialObject3D)
package org.papervision3d.core.proto {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.materials.*;
import org.papervision3d.core.render.material.*;
import flash.utils.*;
import org.papervision3d.core.render.draw.*;
public class MaterialObject3D extends EventDispatcher implements ITriangleDrawer {
public var widthOffset:Number;// = 0
public var name:String;
public var scene:SceneObject3D;
protected var objects:Dictionary;
public var heightOffset:Number;// = 0
public var fillColor:Number;
public var fillAlpha:Number;// = 0
public var id:Number;
public var invisible:Boolean;// = false
public var smooth:Boolean;// = false
public var bitmap:BitmapData;
public var lineAlpha:Number;// = 0
public var lineColor:Number;
public var renderLayer:RenderLayer;// = null
public var lineThickness:Number;// = 1
public var interactive:Boolean;// = false
public var oneSide:Boolean;// = true
public var opposite:Boolean;// = false
public var maxU:Number;
public var tiled:Boolean;// = false
public var maxV:Number;
public static var DEFAULT_COLOR:int = 0;
public static var DEBUG_COLOR:int = 0xFF00FF;
private static var _totalMaterialObjects:Number = 0;
public function MaterialObject3D(){
lineColor = DEFAULT_COLOR;
fillColor = DEFAULT_COLOR;
super();
this.id = _totalMaterialObjects++;
MaterialManager.registerMaterial(this);
objects = new Dictionary();
}
override public function toString():String{
return (((((("[MaterialObject3D] bitmap:" + this.bitmap) + " lineColor:") + this.lineColor) + " fillColor:") + fillColor));
}
public function get doubleSided():Boolean{
return (!(this.oneSide));
}
public function set doubleSided(double:Boolean):void{
this.oneSide = !(double);
}
public function registerObject(displayObject3D:DisplayObject3D):void{
objects[displayObject3D] = displayObject3D;
}
public function unregisterObject(displayObject3D:DisplayObject3D):void{
if (objects[displayObject3D] != null){
delete objects[displayObject3D];
};
}
public function updateBitmap():void{
}
public function clone():MaterialObject3D{
var cloned:MaterialObject3D = new MaterialObject3D();
cloned.copy(this);
return (cloned);
}
public function copy(material:MaterialObject3D):void{
this.bitmap = material.bitmap;
this.smooth = material.smooth;
this.lineColor = material.lineColor;
this.lineAlpha = material.lineAlpha;
this.fillColor = material.fillColor;
this.fillAlpha = material.fillAlpha;
this.oneSide = material.oneSide;
this.opposite = material.opposite;
this.invisible = material.invisible;
this.scene = material.scene;
this.name = material.name;
this.maxU = material.maxU;
this.maxV = material.maxV;
}
protected function destroy():void{
MaterialManager.unRegisterMaterial(this);
}
public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
}
public static function get DEFAULT():MaterialObject3D{
var defMaterial:MaterialObject3D = new WireframeMaterial();
defMaterial.lineColor = (0xFFFFFF * Math.random());
defMaterial.lineAlpha = 1;
defMaterial.fillColor = DEFAULT_COLOR;
defMaterial.fillAlpha = 1;
defMaterial.doubleSided = false;
return (defMaterial);
}
public static function get DEBUG():MaterialObject3D{
var defMaterial:MaterialObject3D = new (MaterialObject3D);
defMaterial.lineColor = (0xFFFFFF * Math.random());
defMaterial.lineAlpha = 1;
defMaterial.fillColor = DEBUG_COLOR;
defMaterial.fillAlpha = 0.37;
defMaterial.doubleSided = true;
return (defMaterial);
}
}
}//package org.papervision3d.core.proto
Section 54
//SceneObject3D (org.papervision3d.core.proto.SceneObject3D)
package org.papervision3d.core.proto {
import org.papervision3d.materials.utils.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.animation.core.*;
import org.papervision3d.*;
public class SceneObject3D extends DisplayObjectContainer3D {
public var animated:Boolean;// = false
public var objects:Array;
public var materials:MaterialsList;
public var animationEngine:AnimationEngine;
public function SceneObject3D(){
super();
this.objects = new Array();
this.materials = new MaterialsList();
Papervision3D.log((((((Papervision3D.NAME + " ") + Papervision3D.VERSION) + " (") + Papervision3D.DATE) + ")\n"));
this.root = this;
}
override public function addChild(child:DisplayObject3D, name:String=null):DisplayObject3D{
var newChild:DisplayObject3D = super.addChild(child, name);
child.scene = this;
this.objects.push(newChild);
return (newChild);
}
override public function removeChild(child:DisplayObject3D):DisplayObject3D{
super.removeChild(child);
var i:int;
while (i < this.objects.length) {
if (this.objects[i] === child){
this.objects.splice(i, 1);
return (child);
};
i++;
};
return (child);
}
}
}//package org.papervision3d.core.proto
Section 55
//AbstractRenderListItem (org.papervision3d.core.render.command.AbstractRenderListItem)
package org.papervision3d.core.render.command {
import org.papervision3d.core.render.data.*;
public class AbstractRenderListItem implements IRenderListItem {
public var screenDepth:Number;
public function AbstractRenderListItem(){
super();
}
public function render(renderSessionData:RenderSessionData):void{
}
}
}//package org.papervision3d.core.render.command
Section 56
//IRenderListItem (org.papervision3d.core.render.command.IRenderListItem)
package org.papervision3d.core.render.command {
import org.papervision3d.core.render.data.*;
public interface IRenderListItem {
function render(:RenderSessionData):void;
}
}//package org.papervision3d.core.render.command
Section 57
//RenderableListItem (org.papervision3d.core.render.command.RenderableListItem)
package org.papervision3d.core.render.command {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
public class RenderableListItem extends AbstractRenderListItem {
public var renderable:Class;
public var renderableInstance:IRenderable;
public function RenderableListItem(){
super();
}
public function hitTestPoint2D(point:Point, renderHitData:RenderHitData):RenderHitData{
return (renderHitData);
}
}
}//package org.papervision3d.core.render.command
Section 58
//RenderParticle (org.papervision3d.core.render.command.RenderParticle)
package org.papervision3d.core.render.command {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.materials.special.*;
public class RenderParticle extends RenderableListItem implements IRenderListItem {
public var container:RenderLayer;
public var particle:Particle;
public var renderMat:ParticleMaterial;
public function RenderParticle(particle:Particle){
super();
this.particle = particle;
}
override public function render(renderSessionData:RenderSessionData):void{
container = ((((particle.material.renderLayer) || (particle.instance.renderLayer))) || (renderSessionData.defaultRenderLayer));
particle.material.drawParticle(particle, container.drawLayer.graphics, renderSessionData);
container.faceCount++;
container.screenDepth = (container.screenDepth + this.screenDepth);
}
override public function hitTestPoint2D(point:Point, rhd:RenderHitData):RenderHitData{
renderMat = particle.material;
if (renderMat.interactive){
if (particle.renderRect.contains(point.x, point.y)){
rhd.displayObject3D = particle.instance;
rhd.material = renderMat;
rhd.renderable = particle;
rhd.hasHit = true;
rhd.x = particle.x;
rhd.y = particle.y;
rhd.z = particle.z;
rhd.u = 0;
rhd.v = 0;
return (rhd);
};
};
return (rhd);
}
}
}//package org.papervision3d.core.render.command
Section 59
//RenderTriangle (org.papervision3d.core.render.command.RenderTriangle)
package org.papervision3d.core.render.command {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.render.draw.*;
public class RenderTriangle extends RenderableListItem implements IRenderListItem {
public var container:RenderLayer;
public var renderer:ITriangleDrawer;
public var triangle:Triangle3D;
private var position:Number3D;
public var renderMat:MaterialObject3D;
public function RenderTriangle(triangle:Triangle3D):void{
position = new Number3D();
super();
this.triangle = triangle;
renderableInstance = triangle;
renderable = Triangle3D;
}
override public function hitTestPoint2D(point:Point, renderhitData:RenderHitData):RenderHitData{
var vPoint:Vertex3DInstance;
var vx0:Vertex3DInstance;
var vx1:Vertex3DInstance;
var vx2:Vertex3DInstance;
renderMat = ((triangle.material is ShadedMaterial)) ? ShadedMaterial(triangle.material).material : triangle.material;
if (!renderMat){
renderMat = ((triangle.material is ShadedMaterial)) ? ShadedMaterial(triangle.instance.material).material : triangle.instance.material;
};
if (renderMat.interactive){
vPoint = new Vertex3DInstance(point.x, point.y);
vx0 = triangle.v0.vertex3DInstance;
vx1 = triangle.v1.vertex3DInstance;
vx2 = triangle.v2.vertex3DInstance;
if (sameSide(vPoint, vx0, vx1, vx2)){
if (sameSide(vPoint, vx1, vx0, vx2)){
if (sameSide(vPoint, vx2, vx0, vx1)){
return (deepHitTest(triangle, vPoint, renderhitData));
};
};
};
};
return (renderhitData);
}
public function sameSide(point:Vertex3DInstance, ref:Vertex3DInstance, a:Vertex3DInstance, b:Vertex3DInstance):Boolean{
var n:Number = (Vertex3DInstance.cross(Vertex3DInstance.sub(b, a), Vertex3DInstance.sub(point, a)) * Vertex3DInstance.cross(Vertex3DInstance.sub(b, a), Vertex3DInstance.sub(ref, a)));
return ((n > 0));
}
override public function render(renderSessionData:RenderSessionData):void{
container = ((((triangle.material.renderLayer) || (triangle.instance.renderLayer))) || (renderSessionData.defaultRenderLayer));
container.faceCount++;
container.screenDepth = (container.screenDepth + this.screenDepth);
renderer.drawTriangle(triangle, container.drawLayer.graphics, renderSessionData);
}
private function deepHitTest(face:Triangle3D, vPoint:Vertex3DInstance, rhd:RenderHitData):RenderHitData{
var v0:Vertex3DInstance = face.v0.vertex3DInstance;
var v1:Vertex3DInstance = face.v1.vertex3DInstance;
var v2:Vertex3DInstance = face.v2.vertex3DInstance;
var v0_x:Number = (v2.x - v0.x);
var v0_y:Number = (v2.y - v0.y);
var v1_x:Number = (v1.x - v0.x);
var v1_y:Number = (v1.y - v0.y);
var v2_x:Number = (vPoint.x - v0.x);
var v2_y:Number = (vPoint.y - v0.y);
var dot00:Number = ((v0_x * v0_x) + (v0_y * v0_y));
var dot01:Number = ((v0_x * v1_x) + (v0_y * v1_y));
var dot02:Number = ((v0_x * v2_x) + (v0_y * v2_y));
var dot11:Number = ((v1_x * v1_x) + (v1_y * v1_y));
var dot12:Number = ((v1_x * v2_x) + (v1_y * v2_y));
var invDenom:Number = (1 / ((dot00 * dot11) - (dot01 * dot01)));
var u:Number = (((dot11 * dot02) - (dot01 * dot12)) * invDenom);
var v:Number = (((dot00 * dot12) - (dot01 * dot02)) * invDenom);
var rv0_x:Number = (face.v2.x - face.v0.x);
var rv0_y:Number = (face.v2.y - face.v0.y);
var rv0_z:Number = (face.v2.z - face.v0.z);
var rv1_x:Number = (face.v1.x - face.v0.x);
var rv1_y:Number = (face.v1.y - face.v0.y);
var rv1_z:Number = (face.v1.z - face.v0.z);
var hx:Number = ((face.v0.x + (rv0_x * u)) + (rv1_x * v));
var hy:Number = ((face.v0.y + (rv0_y * u)) + (rv1_y * v));
var hz:Number = ((face.v0.z + (rv0_z * u)) + (rv1_z * v));
var uv:Array = face.uv;
var uu0:Number = uv[0].u;
var uu1:Number = uv[1].u;
var uu2:Number = uv[2].u;
var uv0:Number = uv[0].v;
var uv1:Number = uv[1].v;
var uv2:Number = uv[2].v;
var v_x:Number = ((((uu1 - uu0) * v) + ((uu2 - uu0) * u)) + uu0);
var v_y:Number = ((((uv1 - uv0) * v) + ((uv2 - uv0) * u)) + uv0);
renderMat = ((face.material is ShadedMaterial)) ? ShadedMaterial(face.material).material : face.material;
if (!renderMat){
renderMat = ((face.material is ShadedMaterial)) ? ShadedMaterial(face.instance.material).material : face.instance.material;
};
var bitmap:BitmapData = renderMat.bitmap;
var width:Number = 1;
var height:Number = 1;
if (bitmap){
width = (BitmapMaterial.AUTO_MIP_MAPPING) ? renderMat.widthOffset : bitmap.width;
height = (BitmapMaterial.AUTO_MIP_MAPPING) ? renderMat.heightOffset : bitmap.height;
};
rhd.displayObject3D = face.instance;
rhd.material = renderMat;
rhd.renderable = face;
rhd.hasHit = true;
position.x = hx;
position.y = hy;
position.z = hz;
Matrix3D.multiplyVector(face.instance.world, position);
rhd.x = position.x;
rhd.y = position.y;
rhd.z = position.z;
rhd.u = (v_x * width);
rhd.v = (height - (v_y * height));
return (rhd);
}
}
}//package org.papervision3d.core.render.command
Section 60
//RenderHitData (org.papervision3d.core.render.data.RenderHitData)
package org.papervision3d.core.render.data {
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
public class RenderHitData {
public var material:MaterialObject3D;
public var endTime:int;// = 0
public var startTime:int;// = 0
public var hasHit:Boolean;// = false
public var displayObject3D:DisplayObject3D;
public var u:Number;
public var v:Number;
public var renderable:IRenderable;
public var x:Number;
public var z:Number;
public var y:Number;
public function RenderHitData(){
super();
}
public function toString():String{
return (((displayObject3D + " ") + renderable));
}
}
}//package org.papervision3d.core.render.data
Section 61
//RenderSessionData (org.papervision3d.core.render.data.RenderSessionData)
package org.papervision3d.core.render.data {
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import flash.display.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.core.render.*;
public class RenderSessionData {
public var container:Sprite;
public var renderer:IRenderEngine;
public var particleCuller:IParticleCuller;
public var viewPort:Viewport3D;
public var triangleCuller:ITriangleCuller;
public var defaultRenderLayer:RenderLayer;
public var scene:SceneObject3D;
public var camera:CameraObject3D;
public var renderStatistics:RenderStatistics;
public var sorted:Boolean;
public function RenderSessionData():void{
super();
this.renderStatistics = new RenderStatistics();
}
}
}//package org.papervision3d.core.render.data
Section 62
//RenderStatistics (org.papervision3d.core.render.data.RenderStatistics)
package org.papervision3d.core.render.data {
public class RenderStatistics {
public var renderTime:int;// = 0
public var triangles:int;// = 0
public var particles:int;// = 0
public var lines:int;// = 0
public var culledObjects:int;// = 0
public var rendered:int;// = 0
public var culledTriangles:int;// = 0
public var shadedTriangles:int;// = 0
public var projectionTime:int;// = 0
public var filteredObjects:int;// = 0
public var culledParticles:int;// = 0
public function RenderStatistics(){
super();
}
public function toString():String{
return (new String((((((((((((((((((("ProjectionTime:" + projectionTime) + " RenderTime:") + renderTime) + " Particles:") + particles) + " CulledParticles :") + culledParticles) + " Triangles:") + triangles) + " ShadedTriangles :") + shadedTriangles) + " CulledTriangles:") + culledTriangles) + " FilteredObjects:") + filteredObjects) + " CulledObjects:") + culledObjects) + "")));
}
public function clear():void{
projectionTime = 0;
renderTime = 0;
rendered = 0;
particles = 0;
triangles = 0;
culledTriangles = 0;
culledParticles = 0;
lines = 0;
shadedTriangles = 0;
filteredObjects = 0;
culledObjects = 0;
}
}
}//package org.papervision3d.core.render.data
Section 63
//IParticleDrawer (org.papervision3d.core.render.draw.IParticleDrawer)
package org.papervision3d.core.render.draw {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
public interface IParticleDrawer {
function drawParticle(_arg1:Particle, _arg2:Graphics, _arg3:RenderSessionData):void;
function updateRenderRect(:Particle):void;
}
}//package org.papervision3d.core.render.draw
Section 64
//ITriangleDrawer (org.papervision3d.core.render.draw.ITriangleDrawer)
package org.papervision3d.core.render.draw {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
public interface ITriangleDrawer {
function drawTriangle(_arg1:Triangle3D, _arg2:Graphics, _arg3:RenderSessionData, _arg4:BitmapData=null, _arg5:Matrix=null):void;
}
}//package org.papervision3d.core.render.draw
Section 65
//BasicRenderFilter (org.papervision3d.core.render.filter.BasicRenderFilter)
package org.papervision3d.core.render.filter {
public class BasicRenderFilter implements IRenderFilter {
public function BasicRenderFilter(){
super();
}
public function filter(array:Array):int{
return (0);
}
}
}//package org.papervision3d.core.render.filter
Section 66
//IRenderFilter (org.papervision3d.core.render.filter.IRenderFilter)
package org.papervision3d.core.render.filter {
public interface IRenderFilter {
function filter(:Array):int;
}
}//package org.papervision3d.core.render.filter
Section 67
//IUpdateAfterMaterial (org.papervision3d.core.render.material.IUpdateAfterMaterial)
package org.papervision3d.core.render.material {
import org.papervision3d.core.render.data.*;
public interface IUpdateAfterMaterial {
function updateAfterRender(:RenderSessionData):void;
}
}//package org.papervision3d.core.render.material
Section 68
//IUpdateBeforeMaterial (org.papervision3d.core.render.material.IUpdateBeforeMaterial)
package org.papervision3d.core.render.material {
import org.papervision3d.core.render.data.*;
public interface IUpdateBeforeMaterial {
function updateBeforeRender(:RenderSessionData):void;
}
}//package org.papervision3d.core.render.material
Section 69
//MaterialManager (org.papervision3d.core.render.material.MaterialManager)
package org.papervision3d.core.render.material {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.utils.*;
public class MaterialManager {
private var materials:Dictionary;
private static var instance:MaterialManager;
public function MaterialManager():void{
super();
if (instance){
throw (new Error("Only 1 instance of materialmanager allowed"));
};
init();
}
private function init():void{
materials = new Dictionary();
}
private function _unRegisterMaterial(material:MaterialObject3D):void{
delete materials[material];
}
public function updateMaterialsAfterRender(renderSessionData:RenderSessionData):void{
var um:IUpdateAfterMaterial;
var m:MaterialObject3D;
for each (m in materials) {
if ((m is IUpdateAfterMaterial)){
um = (m as IUpdateAfterMaterial);
um.updateAfterRender(renderSessionData);
};
};
}
private function _registerMaterial(material:MaterialObject3D):void{
materials[material] = material;
}
public function updateMaterialsBeforeRender(renderSessionData:RenderSessionData):void{
var um:IUpdateBeforeMaterial;
var m:MaterialObject3D;
for each (m in materials) {
if ((m is IUpdateBeforeMaterial)){
um = (m as IUpdateBeforeMaterial);
um.updateBeforeRender(renderSessionData);
};
};
}
public static function getInstance():MaterialManager{
if (!instance){
instance = new (MaterialManager);
};
return (instance);
}
public static function unRegisterMaterial(material:MaterialObject3D):void{
getInstance()._unRegisterMaterial(material);
}
public static function registerMaterial(material:MaterialObject3D):void{
getInstance()._registerMaterial(material);
}
}
}//package org.papervision3d.core.render.material
Section 70
//IShaderRenderer (org.papervision3d.core.render.shader.IShaderRenderer)
package org.papervision3d.core.render.shader {
import org.papervision3d.core.render.data.*;
import flash.display.*;
import org.papervision3d.materials.shaders.*;
public interface IShaderRenderer {
function destroy():void;
function getLayerForShader(renderSessionData:Shader):Sprite;
function clear():void;
function render(:RenderSessionData):void;
}
}//package org.papervision3d.core.render.shader
Section 71
//ShaderObjectData (org.papervision3d.core.render.shader.ShaderObjectData)
package org.papervision3d.core.render.shader {
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shaders.*;
import flash.utils.*;
public class ShaderObjectData {
public var shaderRenderer:ShaderRenderer;
public var triangleUVS:Dictionary;
public var renderTriangleUVS:Dictionary;
public var lightMatrices:Dictionary;
public var shadedMaterial:ShadedMaterial;
public var uvMatrices:Dictionary;
private var origin:Point;
public var material:BitmapMaterial;
public var triangleRects:Dictionary;
protected var triangleBitmaps:Dictionary;
public var object:DisplayObject3D;
public function ShaderObjectData(object:DisplayObject3D, material:BitmapMaterial, shadedMaterial:ShadedMaterial):void{
origin = new Point(0, 0);
super();
shaderRenderer = new ShaderRenderer();
lightMatrices = new Dictionary();
uvMatrices = new Dictionary();
this.object = object;
this.material = material;
this.shadedMaterial = shadedMaterial;
triangleUVS = new Dictionary();
renderTriangleUVS = new Dictionary();
triangleBitmaps = new Dictionary();
triangleRects = new Dictionary();
}
public function getPerTriUVForDraw(triangle:Triangle3D):Matrix{
var mat:Matrix;
var txWidth:Number;
var txHeight:Number;
var x0:Number;
var y0:Number;
var x1:Number;
var y1:Number;
var x2:Number;
var y2:Number;
var r:Rectangle;
if (!triangleUVS[triangle]){
mat = (triangleUVS[triangle] = new Matrix());
txWidth = material.bitmap.width;
txHeight = material.bitmap.height;
x0 = (triangle.uv[0].u * txWidth);
y0 = ((1 - triangle.uv[0].v) * txHeight);
x1 = (triangle.uv[1].u * txWidth);
y1 = ((1 - triangle.uv[1].v) * txHeight);
x2 = (triangle.uv[2].u * txWidth);
y2 = ((1 - triangle.uv[2].v) * txHeight);
r = getRectFor(triangle);
mat.tx = (x0 - r.x);
mat.ty = (y0 - r.y);
mat.a = (x1 - x0);
mat.b = (y1 - y0);
mat.c = (x2 - x0);
mat.d = (y2 - y0);
mat.invert();
};
return (triangleUVS[triangle]);
}
public function getRectFor(triangle:Triangle3D):Rectangle{
var w:Number;
var h:Number;
var u0:Number;
var v0:Number;
var u1:Number;
var v1:Number;
var u2:Number;
var v2:Number;
var minU:Number;
var minV:Number;
var maxU:Number;
var maxV:Number;
var rw:Number;
var rh:Number;
if (!triangleRects[triangle]){
w = material.bitmap.width;
h = material.bitmap.height;
u0 = (triangle.uv[0].u * w);
v0 = ((1 - triangle.uv[0].v) * h);
u1 = (triangle.uv[1].u * w);
v1 = ((1 - triangle.uv[1].v) * h);
u2 = (triangle.uv[2].u * w);
v2 = ((1 - triangle.uv[2].v) * h);
minU = Math.min(Math.min(u0, u1), u2);
minV = Math.min(Math.min(v0, v1), v2);
maxU = Math.max(Math.max(u0, u1), u2);
maxV = Math.max(Math.max(v0, v1), v2);
rw = (maxU - minU);
rh = (maxV - minV);
if (rw <= 0){
rw = 1;
};
if (rh <= 0){
rh = 1;
};
return ((triangleRects[triangle] = new Rectangle(minU, minV, rw, rh)));
};
return (triangleRects[triangle]);
}
private function perturbUVMatrix(matrix:Matrix, triangle:Triangle3D, numPixels:Number=2):void{
var txWidth:Number = material.bitmap.width;
var txHeight:Number = material.bitmap.height;
var u0:Number = triangle.uv[0].u;
var v0:Number = (1 - triangle.uv[0].v);
var u1:Number = triangle.uv[1].u;
var v1:Number = (1 - triangle.uv[1].v);
var u2:Number = triangle.uv[2].u;
var v2:Number = (1 - triangle.uv[2].v);
var x0:Number = (u0 * txWidth);
var y0:Number = (v0 * txHeight);
var x1:Number = (u1 * txWidth);
var y1:Number = (v1 * txHeight);
var x2:Number = (u2 * txWidth);
var y2:Number = (v2 * txHeight);
var centroidX:Number = (((u2 + u1) + u0) / 3);
var centroidY:Number = (((v2 + v1) + v0) / 3);
var xdir0:Number = (u0 - centroidX);
var ydir0:Number = (v0 - centroidY);
var xdir1:Number = (u1 - centroidX);
var ydir1:Number = (v1 - centroidY);
var xdir2:Number = (u2 - centroidX);
var ydir2:Number = (v2 - centroidY);
var xAbsDir0:Number = ((xdir0)<0) ? -(xdir0) : xdir0;
var yAbsDir0:Number = ((ydir0)<0) ? -(ydir0) : ydir0;
var xAbsDir1:Number = ((xdir1)<0) ? -(xdir1) : xdir1;
var yAbsDir1:Number = ((ydir1)<0) ? -(ydir1) : ydir1;
var xAbsDir2:Number = ((xdir2)<0) ? -(xdir2) : xdir2;
var yAbsDir2:Number = ((ydir2)<0) ? -(ydir2) : ydir2;
var percentDist0:Number = ((xAbsDir0)>yAbsDir0) ? (1 / xAbsDir0) : (1 / yAbsDir0);
var percentDist1:Number = ((xAbsDir1)>yAbsDir1) ? (1 / xAbsDir1) : (1 / yAbsDir1);
var percentDist2:Number = ((xAbsDir2)>yAbsDir2) ? (1 / xAbsDir2) : (1 / yAbsDir2);
x0 = (x0 - ((-(xdir0) * percentDist0) * numPixels));
y0 = (y0 - ((-(ydir0) * percentDist0) * numPixels));
x1 = (x1 - ((-(xdir1) * percentDist1) * numPixels));
y1 = (y1 - ((-(ydir1) * percentDist1) * numPixels));
x2 = (x2 - ((-(xdir2) * percentDist2) * numPixels));
y2 = (y2 - ((-(ydir2) * percentDist2) * numPixels));
matrix.tx = x0;
matrix.ty = y0;
matrix.a = (x1 - x0);
matrix.b = (y1 - y0);
matrix.c = (x2 - x0);
matrix.d = (y2 - y0);
}
public function getOutputBitmapFor(triangle:Triangle3D):BitmapData{
var r:Rectangle;
var bmp:BitmapData;
var r2:Rectangle;
if (!triangleBitmaps[triangle]){
r = getRectFor(triangle);
bmp = (triangleBitmaps[triangle] = new BitmapData(Math.ceil(r.width), Math.ceil(r.height), false, 0));
r2 = new Rectangle(0, 0, bmp.width, bmp.height);
bmp.copyPixels(material.bitmap, r2, origin);
} else {
r = getRectFor(triangle);
};
if (((material.bitmap) && (r))){
triangleBitmaps[triangle].copyPixels(material.bitmap, r, origin);
};
return (triangleBitmaps[triangle]);
}
public function updateBeforeRender():void{
}
public function getPerTriUVForShader(triangle:Triangle3D):Matrix{
var mat:Matrix;
var txWidth:Number;
var txHeight:Number;
var x0:Number;
var y0:Number;
var x1:Number;
var y1:Number;
var x2:Number;
var y2:Number;
var r:Rectangle;
if (!renderTriangleUVS[triangle]){
mat = (renderTriangleUVS[triangle] = new Matrix());
txWidth = material.bitmap.width;
txHeight = material.bitmap.height;
x0 = (triangle.uv[0].u * txWidth);
y0 = ((1 - triangle.uv[0].v) * txHeight);
x1 = (triangle.uv[1].u * txWidth);
y1 = ((1 - triangle.uv[1].v) * txHeight);
x2 = (triangle.uv[2].u * txWidth);
y2 = ((1 - triangle.uv[2].v) * txHeight);
r = getRectFor(triangle);
mat.tx = (x0 - r.x);
mat.ty = (y0 - r.y);
mat.a = (x1 - x0);
mat.b = (y1 - y0);
mat.c = (x2 - x0);
mat.d = (y2 - y0);
};
return (renderTriangleUVS[triangle]);
}
public function getUVMatrixForTriangle(triangle:Triangle3D, perturb:Boolean=false):Matrix{
var mat:Matrix;
var txWidth:Number;
var txHeight:Number;
var x0:Number;
var y0:Number;
var x1:Number;
var y1:Number;
var x2:Number;
var y2:Number;
mat = uvMatrices[triangle];
if (!mat){
mat = new Matrix();
if (perturb){
perturbUVMatrix(mat, triangle, 2);
} else {
txWidth = material.bitmap.width;
txHeight = material.bitmap.height;
x0 = (triangle.uv[0].u * txWidth);
y0 = ((1 - triangle.uv[0].v) * txHeight);
x1 = (triangle.uv[1].u * txWidth);
y1 = ((1 - triangle.uv[1].v) * txHeight);
x2 = (triangle.uv[2].u * txWidth);
y2 = ((1 - triangle.uv[2].v) * txHeight);
mat.tx = x0;
mat.ty = y0;
mat.a = (x1 - x0);
mat.b = (y1 - y0);
mat.c = (x2 - x0);
mat.d = (y2 - y0);
};
uvMatrices[triangle] = mat;
};
return (mat);
}
public function destroy():void{
var o:Object;
for each (o in uvMatrices) {
uvMatrices[o] = null;
};
uvMatrices = null;
shaderRenderer.destroy();
shaderRenderer = null;
lightMatrices = null;
}
}
}//package org.papervision3d.core.render.shader
Section 72
//ShaderRenderer (org.papervision3d.core.render.shader.ShaderRenderer)
package org.papervision3d.core.render.shader {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import flash.display.*;
import org.papervision3d.materials.shaders.*;
import flash.utils.*;
public class ShaderRenderer extends EventDispatcher implements IShaderRenderer {
public var container:Sprite;
public var bitmapLayer:Sprite;
private var _inputBitmapData:BitmapData;
public var shadeLayers:Dictionary;
public var outputBitmap:BitmapData;
public var bitmapContainer:Bitmap;
public function ShaderRenderer(){
super();
container = new Sprite();
bitmapLayer = new Sprite();
bitmapContainer = new Bitmap();
bitmapLayer.addChild(bitmapContainer);
bitmapLayer.blendMode = BlendMode.NORMAL;
shadeLayers = new Dictionary();
container.addChild(bitmapLayer);
}
public function clear():void{
var sprite:Sprite;
for each (sprite in shadeLayers) {
sprite.graphics.clear();
sprite.graphics.beginFill(0, 1);
sprite.graphics.drawRect(0, 0, inputBitmap.width, inputBitmap.height);
sprite.graphics.endFill();
};
}
public function get inputBitmap():BitmapData{
return (_inputBitmapData);
}
public function getLayerForShader(shader:Shader):Sprite{
var layer:Sprite = new Sprite();
shadeLayers[shader] = layer;
var rect:Sprite = new Sprite();
layer.addChild(rect);
rect.graphics.beginFill(0, 0);
rect.graphics.drawRect(0, 0, inputBitmap.width, inputBitmap.height);
rect.graphics.endFill();
container.addChild(layer);
layer.blendMode = shader.layerBlendMode;
return (layer);
}
public function render(renderSessionData:RenderSessionData):void{
outputBitmap.fillRect(outputBitmap.rect, 0);
bitmapContainer.bitmapData = inputBitmap;
outputBitmap.draw(container, null, null, null, outputBitmap.rect, false);
}
public function set inputBitmap(bitmapData:BitmapData):void{
_inputBitmapData = bitmapData;
outputBitmap = _inputBitmapData.clone();
}
public function destroy():void{
bitmapLayer = null;
outputBitmap.dispose();
}
}
}//package org.papervision3d.core.render.shader
Section 73
//BasicRenderSorter (org.papervision3d.core.render.sort.BasicRenderSorter)
package org.papervision3d.core.render.sort {
public class BasicRenderSorter implements IRenderSorter {
public function BasicRenderSorter(){
super();
}
public function sort(array:Array):void{
array.sortOn("screenDepth", Array.NUMERIC);
}
}
}//package org.papervision3d.core.render.sort
Section 74
//IRenderSorter (org.papervision3d.core.render.sort.IRenderSorter)
package org.papervision3d.core.render.sort {
public interface IRenderSorter {
function sort(:Array):void;
}
}//package org.papervision3d.core.render.sort
Section 75
//AbstractRenderEngine (org.papervision3d.core.render.AbstractRenderEngine)
package org.papervision3d.core.render {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import org.papervision3d.core.render.command.*;
public class AbstractRenderEngine extends EventDispatcher implements IRenderEngine {
public function AbstractRenderEngine(target:IEventDispatcher=null){
super(target);
}
public function addToRenderList(renderCommand:IRenderListItem):int{
return (0);
}
public function removeFromRenderList(renderCommand:IRenderListItem):int{
return (0);
}
public function renderScene(scene:SceneObject3D, camera:CameraObject3D, viewPort:Viewport3D, updateAnimation:Boolean=true):RenderStatistics{
return (null);
}
}
}//package org.papervision3d.core.render
Section 76
//IRenderEngine (org.papervision3d.core.render.IRenderEngine)
package org.papervision3d.core.render {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import org.papervision3d.core.render.command.*;
public interface IRenderEngine {
function addToRenderList(updateAnimation:IRenderListItem):int;
function removeFromRenderList(updateAnimation:IRenderListItem):int;
function renderScene(_arg1:SceneObject3D, _arg2:CameraObject3D, _arg3:Viewport3D, _arg4:Boolean=true):RenderStatistics;
}
}//package org.papervision3d.core.render
Section 77
//IVirtualMouseEvent (org.papervision3d.core.utils.virtualmouse.IVirtualMouseEvent)
package org.papervision3d.core.utils.virtualmouse {
public interface IVirtualMouseEvent {
}
}//package org.papervision3d.core.utils.virtualmouse
Section 78
//VirtualMouse (org.papervision3d.core.utils.virtualmouse.VirtualMouse)
package org.papervision3d.core.utils.virtualmouse {
import flash.events.*;
import flash.geom.*;
import flash.display.*;
import com.blitzagency.xray.logger.*;
import flash.utils.*;
import org.papervision3d.core.components.as3.utils.*;
public class VirtualMouse extends EventDispatcher {
private var lastMouseDown:Boolean;// = false
private var _container:Sprite;
private var _stage:Stage;
private var lastDownTarget:DisplayObject;
private var target:InteractiveObject;
private var updateMouseDown:Boolean;// = false
private var eventEvent:Class;
private var mouseEventEvent:Class;
private var _lastEvent:Event;
private var location:Point;
private var delta:int;// = 0
private var log:XrayLog;
private var disabledEvents:Object;
private var isLocked:Boolean;// = false
private var lastWithinStage:Boolean;// = true
private var lastLocation:Point;
private var isDoubleClickEvent:Boolean;// = false
private var ctrlKey:Boolean;// = false
private var altKey:Boolean;// = false
private var _useNativeEvents:Boolean;// = false
private var shiftKey:Boolean;// = false
public static const UPDATE:String = "update";
private static var _mouseIsDown:Boolean = false;
private static var ignoredInstances:Dictionary = new Dictionary(true);
public function VirtualMouse(stage:Stage=null, container:Sprite=null, startX:Number=0, startY:Number=0){
disabledEvents = new Object();
eventEvent = VirtualMouseEvent;
mouseEventEvent = VirtualMouseMouseEvent;
log = new XrayLog();
super();
this.stage = stage;
this.container = container;
location = new Point(startX, startY);
trace("Location point?");
lastLocation = location.clone();
addEventListener(UPDATE, handleUpdate);
update();
}
public function get container():Sprite{
return (_container);
}
public function exitContainer():void{
var targetLocal:Point = target.globalToLocal(location);
if (!disabledEvents[MouseEvent.MOUSE_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
container.dispatchEvent(new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
dispatchEvent(new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
};
if (!disabledEvents[MouseEvent.ROLL_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
container.dispatchEvent(new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
dispatchEvent(new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
};
if (target != container){
if (!disabledEvents[MouseEvent.MOUSE_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
dispatchEvent(new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
};
if (!disabledEvents[MouseEvent.ROLL_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
dispatchEvent(new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta));
};
};
target = _stage;
}
public function release():void{
updateMouseDown = true;
_mouseIsDown = false;
if (!isLocked){
update();
};
}
private function keyHandler(event:KeyboardEvent):void{
altKey = event.altKey;
ctrlKey = event.ctrlKey;
shiftKey = event.shiftKey;
}
public function click():void{
press();
release();
}
private function handleUpdate(event:Event):void{
var currentTarget:InteractiveObject;
var currentParent:DisplayObject;
var withinStage:Boolean;
if (!container){
return;
};
var p:Point = CoordinateTools.localToLocal(container, stage, location);
var objectsUnderPoint:Array = container.getObjectsUnderPoint(location);
var i:int = objectsUnderPoint.length;
while (i--) {
currentParent = objectsUnderPoint[i];
while (currentParent) {
if (ignoredInstances[currentParent]){
currentTarget = null;
break;
};
if (((currentTarget) && ((currentParent is SimpleButton)))){
currentTarget = null;
} else {
if (((currentTarget) && (!(DisplayObjectContainer(currentParent).mouseChildren)))){
currentTarget = null;
};
};
if (((((!(currentTarget)) && ((currentParent is InteractiveObject)))) && (InteractiveObject(currentParent).mouseEnabled))){
currentTarget = InteractiveObject(currentParent);
};
currentParent = currentParent.parent;
};
if (currentTarget){
break;
};
};
if (!currentTarget){
currentTarget = _stage;
};
var targetLocal:Point = target.globalToLocal(location);
var currentTargetLocal:Point = currentTarget.globalToLocal(location);
if (((!((lastLocation.x == location.x))) || (!((lastLocation.y == location.y))))){
withinStage = false;
if (stage){
withinStage = (((((((location.x >= 0)) && ((location.y >= 0)))) && ((location.x <= stage.stageWidth)))) && ((location.y <= stage.stageHeight)));
};
if (((((!(withinStage)) && (lastWithinStage))) && (!(disabledEvents[Event.MOUSE_LEAVE])))){
_lastEvent = new eventEvent(Event.MOUSE_LEAVE, false, false);
stage.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
if (((withinStage) && (!(disabledEvents[MouseEvent.MOUSE_MOVE])))){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_MOVE, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
lastWithinStage = withinStage;
};
if (currentTarget != target){
if (!disabledEvents[MouseEvent.MOUSE_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
if (!disabledEvents[MouseEvent.ROLL_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
if (!disabledEvents[MouseEvent.MOUSE_OVER]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OVER, true, false, currentTargetLocal.x, currentTargetLocal.y, target, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
if (!disabledEvents[MouseEvent.ROLL_OVER]){
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OVER, false, false, currentTargetLocal.x, currentTargetLocal.y, target, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
};
if (updateMouseDown){
if (_mouseIsDown){
if (!disabledEvents[MouseEvent.MOUSE_DOWN]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_DOWN, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
lastDownTarget = currentTarget;
updateMouseDown = false;
} else {
if (!disabledEvents[MouseEvent.MOUSE_UP]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_UP, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
if (((!(disabledEvents[MouseEvent.CLICK])) && ((currentTarget == lastDownTarget)))){
_lastEvent = new mouseEventEvent(MouseEvent.CLICK, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
lastDownTarget = null;
updateMouseDown = false;
};
};
if (((((isDoubleClickEvent) && (!(disabledEvents[MouseEvent.DOUBLE_CLICK])))) && (currentTarget.doubleClickEnabled))){
_lastEvent = new mouseEventEvent(MouseEvent.DOUBLE_CLICK, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
};
lastLocation = location.clone();
lastMouseDown = _mouseIsDown;
target = currentTarget;
}
public function disableEvent(type:String):void{
disabledEvents[type] = true;
}
public function set container(value:Sprite):void{
_container = value;
}
public function get lastEvent():Event{
return (_lastEvent);
}
public function getLocation():Point{
return (location.clone());
}
public function lock():void{
isLocked = true;
}
public function get useNativeEvents():Boolean{
return (_useNativeEvents);
}
public function setLocation(a, b=null):void{
var loc:Point;
if ((a is Point)){
loc = (a as Point);
trace(loc);
location.x = loc.x;
location.y = loc.y;
} else {
location.x = Number(a);
location.y = Number(b);
};
if (!isLocked){
update();
};
}
public function unignore(instance:DisplayObject):void{
if ((instance in ignoredInstances)){
delete ignoredInstances[instance];
};
}
public function doubleClick():void{
if (isLocked){
release();
} else {
click();
press();
isDoubleClickEvent = true;
release();
isDoubleClickEvent = false;
};
}
public function update():void{
dispatchEvent(new Event(UPDATE, false, false));
}
public function unlock():void{
isLocked = false;
update();
}
public function press():void{
updateMouseDown = true;
_mouseIsDown = true;
if (!isLocked){
update();
};
}
public function enableEvent(type:String):void{
if ((type in disabledEvents)){
delete disabledEvents[type];
};
}
public function set useNativeEvents(b:Boolean):void{
if (b == _useNativeEvents){
return;
};
_useNativeEvents = b;
if (_useNativeEvents){
eventEvent = VirtualMouseEvent;
mouseEventEvent = VirtualMouseMouseEvent;
} else {
eventEvent = Event;
mouseEventEvent = MouseEvent;
};
}
public function set x(n:Number):void{
location.x = n;
if (!isLocked){
update();
};
}
public function get mouseIsDown():Boolean{
return (_mouseIsDown);
}
public function set y(n:Number):void{
location.y = n;
if (!isLocked){
update();
};
}
public function get y():Number{
return (location.y);
}
public function set stage(s:Stage):void{
var hadStage:Boolean;
if (_stage){
hadStage = true;
_stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
_stage.removeEventListener(KeyboardEvent.KEY_UP, keyHandler);
} else {
hadStage = false;
};
_stage = s;
if (_stage){
_stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
_stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
target = _stage;
if (!hadStage){
update();
};
};
}
public function get stage():Stage{
return (_stage);
}
public function get x():Number{
return (location.x);
}
public static function ignore(instance:DisplayObject):void{
ignoredInstances[instance] = true;
}
}
}//package org.papervision3d.core.utils.virtualmouse
Section 79
//VirtualMouseEvent (org.papervision3d.core.utils.virtualmouse.VirtualMouseEvent)
package org.papervision3d.core.utils.virtualmouse {
import flash.events.*;
public class VirtualMouseEvent extends Event implements IVirtualMouseEvent {
public function VirtualMouseEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
}
}
}//package org.papervision3d.core.utils.virtualmouse
Section 80
//VirtualMouseMouseEvent (org.papervision3d.core.utils.virtualmouse.VirtualMouseMouseEvent)
package org.papervision3d.core.utils.virtualmouse {
import flash.events.*;
import flash.display.*;
public class VirtualMouseMouseEvent extends MouseEvent implements IVirtualMouseEvent {
public function VirtualMouseMouseEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, localX:Number=NaN, localY:Number=NaN, relatedObject:InteractiveObject=null, ctrlKey:Boolean=false, altKey:Boolean=false, shiftKey:Boolean=false, buttonDown:Boolean=false, delta:int=0){
super(type, bubbles, cancelable, localX, localY, relatedObject, ctrlKey, altKey, shiftKey, buttonDown, delta);
}
}
}//package org.papervision3d.core.utils.virtualmouse
Section 81
//InteractiveSceneManager (org.papervision3d.core.utils.InteractiveSceneManager)
package org.papervision3d.core.utils {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.events.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shaders.*;
import com.blitzagency.xray.logger.*;
import org.papervision3d.core.utils.virtualmouse.*;
public class InteractiveSceneManager extends EventDispatcher {
public var currentMaterial:MaterialObject3D;
public var container:Sprite;
protected var log:XrayLog;
public var debug:Boolean;// = false
public var mouse3D:Mouse3D;
public var enableOverOut:Boolean;// = true
public var currentDisplayObject3D:DisplayObject3D;
public var virtualMouse:VirtualMouse;
public var viewport:Viewport3D;
public var renderHitData:RenderHitData;
public var currentMouseDO3D:DisplayObject3D;// = null
public static var MOUSE_IS_DOWN:Boolean = false;
public function InteractiveSceneManager(viewport:Viewport3D){
virtualMouse = new VirtualMouse();
mouse3D = new Mouse3D();
log = new XrayLog();
super();
this.viewport = viewport;
this.container = viewport.containerSprite;
init();
}
protected function initVirtualMouse():void{
virtualMouse.stage = container.stage;
virtualMouse.container = container;
}
public function initListeners():void{
if (viewport.interactive){
container.addEventListener(MouseEvent.MOUSE_DOWN, handleMousePress);
container.addEventListener(MouseEvent.MOUSE_UP, handleMouseRelease);
container.addEventListener(MouseEvent.CLICK, handleMouseClick);
container.stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
};
}
protected function handleMouseOver(DO3D:DisplayObject3D):void{
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_OVER, DO3D);
}
protected function handleMouseMove(e:MouseEvent):void{
var mat:MovieMaterial;
if ((((e is IVirtualMouseEvent)) || (!(renderHitData)))){
return;
};
if (((virtualMouse) && (renderHitData))){
mat = ((currentMaterial is ShadedMaterial)) ? (ShadedMaterial(currentMaterial).material as MovieMaterial) : (currentMaterial as MovieMaterial);
if (mat){
virtualMouse.container = (mat.movie as Sprite);
};
if (virtualMouse.container){
virtualMouse.setLocation(renderHitData.u, renderHitData.v);
};
if (((((Mouse3D.enabled) && (renderHitData))) && (!((renderHitData.renderable == null))))){
mouse3D.updatePosition(renderHitData);
};
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_MOVE, currentDisplayObject3D);
} else {
if (((renderHitData) && (renderHitData.hasHit))){
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_MOVE, currentDisplayObject3D);
};
};
}
protected function resolveRenderHitData():void{
var point:Point = new Point();
point.x = container.mouseX;
point.y = container.mouseY;
renderHitData = (viewport.hitTestPoint2D(point) as RenderHitData);
}
public function updateRenderHitData():void{
resolveRenderHitData();
currentDisplayObject3D = renderHitData.displayObject3D;
currentMaterial = renderHitData.material;
manageOverOut();
}
public function init():void{
if (container){
if (container.stage){
initVirtualMouse();
} else {
container.addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
};
};
}
protected function dispatchObjectEvent(event:String, DO3D:DisplayObject3D):void{
var x:Number;
var y:Number;
if (debug){
log.debug(event, DO3D.name);
};
if (((renderHitData) && (renderHitData.hasHit))){
x = (renderHitData.u) ? renderHitData.u : 0;
y = (renderHitData.v) ? renderHitData.v : 0;
dispatchEvent(new InteractiveScene3DEvent(event, DO3D, container, (renderHitData.renderable as Triangle3D), x, y));
DO3D.dispatchEvent(new InteractiveScene3DEvent(event, DO3D, container, (renderHitData.renderable as Triangle3D), x, y));
} else {
dispatchEvent(new InteractiveScene3DEvent(event, DO3D, container));
if (DO3D){
DO3D.dispatchEvent(new InteractiveScene3DEvent(event, DO3D, container));
};
};
}
protected function handleMouseRelease(e:MouseEvent):void{
if ((e is IVirtualMouseEvent)){
return;
};
MOUSE_IS_DOWN = false;
if (virtualMouse){
virtualMouse.release();
};
if (((((Mouse3D.enabled) && (renderHitData))) && (!((renderHitData.renderable == null))))){
mouse3D.updatePosition(renderHitData);
};
if (((renderHitData) && (renderHitData.hasHit))){
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_RELEASE, currentDisplayObject3D);
};
}
protected function handleAddedToStage(e:Event):void{
initVirtualMouse();
initListeners();
}
protected function handleMouseOut(DO3D:DisplayObject3D):void{
var mat:MovieMaterial;
if (DO3D){
mat = (DO3D.material as MovieMaterial);
if (mat){
virtualMouse.exitContainer();
};
};
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_OUT, DO3D);
}
protected function manageOverOut():void{
if (!enableOverOut){
return;
};
if (((renderHitData) && (renderHitData.hasHit))){
if (((!(currentMouseDO3D)) && (currentDisplayObject3D))){
handleMouseOver(currentDisplayObject3D);
currentMouseDO3D = currentDisplayObject3D;
} else {
if (((currentMouseDO3D) && (!((currentMouseDO3D == currentDisplayObject3D))))){
handleMouseOut(currentMouseDO3D);
handleMouseOver(currentDisplayObject3D);
currentMouseDO3D = currentDisplayObject3D;
};
};
} else {
if (currentMouseDO3D != null){
handleMouseOut(currentMouseDO3D);
currentMouseDO3D = null;
};
};
}
protected function handleMouseClick(e:MouseEvent):void{
if ((e is IVirtualMouseEvent)){
return;
};
if (((renderHitData) && (renderHitData.hasHit))){
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_CLICK, currentDisplayObject3D);
};
}
protected function handleMousePress(e:MouseEvent):void{
if ((e is IVirtualMouseEvent)){
return;
};
MOUSE_IS_DOWN = true;
if (virtualMouse){
virtualMouse.press();
};
if (((((Mouse3D.enabled) && (renderHitData))) && (!((renderHitData.renderable == null))))){
mouse3D.updatePosition(renderHitData);
};
if (((renderHitData) && (renderHitData.hasHit))){
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_PRESS, currentDisplayObject3D);
};
}
}
}//package org.papervision3d.core.utils
Section 82
//Mouse3D (org.papervision3d.core.utils.Mouse3D)
package org.papervision3d.core.utils {
import org.papervision3d.core.render.data.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.math.*;
public class Mouse3D extends DisplayObject3D {
public static var enabled:Boolean = false;
private static var UP:Number3D = new Number3D(0, 1, 0);
public function Mouse3D(initObject:Object=null):void{
super();
}
public function updatePosition(rhd:RenderHitData):void{
var xAxis:Number3D;
var yAxis:Number3D;
var look:Matrix3D;
var face3d:Triangle3D = (rhd.renderable as Triangle3D);
var position:Number3D = new Number3D(0, 0, 0);
var target:Number3D = new Number3D(face3d.faceNormal.x, face3d.faceNormal.y, face3d.faceNormal.z);
var zAxis:Number3D = Number3D.sub(target, position);
zAxis.normalize();
if (zAxis.modulo > 0.1){
xAxis = Number3D.cross(zAxis, UP);
xAxis.normalize();
yAxis = Number3D.cross(zAxis, xAxis);
yAxis.normalize();
look = this.transform;
look.n11 = xAxis.x;
look.n21 = xAxis.y;
look.n31 = xAxis.z;
look.n12 = -(yAxis.x);
look.n22 = -(yAxis.y);
look.n32 = -(yAxis.z);
look.n13 = zAxis.x;
look.n23 = zAxis.y;
look.n33 = zAxis.z;
};
var m:Matrix3D = Matrix3D.IDENTITY;
this.transform = Matrix3D.multiply(face3d.instance.world, look);
x = rhd.x;
y = rhd.y;
z = rhd.z;
}
}
}//package org.papervision3d.core.utils
Section 83
//StopWatch (org.papervision3d.core.utils.StopWatch)
package org.papervision3d.core.utils {
import flash.events.*;
import flash.utils.*;
public class StopWatch extends EventDispatcher {
private var startTime:int;
private var elapsedTime:int;
private var isRunning:Boolean;
private var stopTime:int;
public function StopWatch(){
super();
}
public function start():void{
if (!isRunning){
startTime = getTimer();
isRunning = true;
};
}
public function stop():int{
if (isRunning){
stopTime = getTimer();
elapsedTime = (stopTime - startTime);
isRunning = false;
return (elapsedTime);
};
return (0);
}
public function reset():void{
isRunning = false;
}
}
}//package org.papervision3d.core.utils
Section 84
//InteractiveScene3DEvent (org.papervision3d.events.InteractiveScene3DEvent)
package org.papervision3d.events {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
public class InteractiveScene3DEvent extends Event {
public var y:Number;// = 0
public var sprite:Sprite;// = null
public var renderHitData:RenderHitData;
public var face3d:Triangle3D;// = null
public var x:Number;// = 0
public var displayObject3D:DisplayObject3D;// = null
public static const OBJECT_ADDED:String = "objectAdded";
public static const OBJECT_PRESS:String = "mousePress";
public static const OBJECT_RELEASE:String = "mouseRelease";
public static const OBJECT_CLICK:String = "mouseClick";
public static const OBJECT_RELEASE_OUTSIDE:String = "mouseReleaseOutside";
public static const OBJECT_OUT:String = "mouseOut";
public static const OBJECT_MOVE:String = "mouseMove";
public static const OBJECT_OVER:String = "mouseOver";
public function InteractiveScene3DEvent(type:String, container3d:DisplayObject3D=null, sprite:Sprite=null, face3d:Triangle3D=null, x:Number=0, y:Number=0, renderhitData:RenderHitData=null, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
this.displayObject3D = container3d;
this.sprite = sprite;
this.face3d = face3d;
this.x = x;
this.y = y;
this.renderHitData = renderhitData;
}
}
}//package org.papervision3d.events
Section 85
//RendererEvent (org.papervision3d.events.RendererEvent)
package org.papervision3d.events {
import flash.events.*;
import org.papervision3d.core.render.data.*;
public class RendererEvent extends Event {
public var renderSessionData:RenderSessionData;
public static var RENDER_DONE:String = "onRenderDone";
public function RendererEvent(type:String, renderSessionData:RenderSessionData){
super(type);
this.renderSessionData = renderSessionData;
}
}
}//package org.papervision3d.events
Section 86
//PointLight3D (org.papervision3d.lights.PointLight3D)
package org.papervision3d.lights {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.math.*;
public class PointLight3D extends LightObject3D {
public static var DEFAULT_POS:Number3D = new Number3D(0, 0, -1000);
public function PointLight3D(showLight:Boolean=false, flipped:Boolean=false){
super(showLight, flipped);
x = DEFAULT_POS.x;
y = DEFAULT_POS.y;
z = DEFAULT_POS.z;
}
}
}//package org.papervision3d.lights
Section 87
//FlatShadeMaterial (org.papervision3d.materials.shadematerials.FlatShadeMaterial)
package org.papervision3d.materials.shadematerials {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.render.draw.*;
import org.papervision3d.core.material.*;
public class FlatShadeMaterial extends AbstractLightShadeMaterial implements ITriangleDrawer {
private var _colors:Array;
private static var zd:Number;
private static var y0:Number;
private static var x0:Number;
private static var zAngle:int;
private static var currentColor:int;
public function FlatShadeMaterial(light:LightObject3D, diffuse:uint=0xFFFFFF, ambient:uint=0){
super();
this.light = light;
_colors = LightMaps.getFlatMapArray(diffuse, ambient, 1);
}
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
lightMatrix = Matrix3D(lightMatrices[face3D.instance]);
zd = (((face3D.faceNormal.x * lightMatrix.n31) + (face3D.faceNormal.y * lightMatrix.n32)) + (face3D.faceNormal.z * lightMatrix.n33));
if (zd < 0){
zd = 0;
};
x0 = face3D.v0.vertex3DInstance.x;
y0 = face3D.v0.vertex3DInstance.y;
zAngle = (zd * 0xFF);
currentColor = _colors[zAngle];
graphics.beginFill(currentColor, 1);
graphics.moveTo(x0, y0);
graphics.lineTo(face3D.v1.vertex3DInstance.x, face3D.v1.vertex3DInstance.y);
graphics.lineTo(face3D.v2.vertex3DInstance.x, face3D.v2.vertex3DInstance.y);
graphics.lineTo(x0, y0);
graphics.endFill();
renderSessionData.renderStatistics.shadedTriangles++;
}
}
}//package org.papervision3d.materials.shadematerials
Section 88
//EnvMapShader (org.papervision3d.materials.shaders.EnvMapShader)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.render.shader.*;
import flash.display.*;
import flash.filters.*;
import org.papervision3d.core.math.*;
public class EnvMapShader extends LightShader implements IShader {
protected var lightmapHalfheight:Number;
private var _ambientColor:int;
protected var lightmapHalfwidth:Number;
private var _envMap:BitmapData;
private var _backEnvMap:BitmapData;
private var _bumpMap:BitmapData;
private var _specularMap:BitmapData;
private var dFilter:DisplacementMapFilter;
private static var v0:Vertex3DInstance;
private static var v2z:Number;
private static var sod:ShaderObjectData;
private static var n0:Number3D;
private static var n1:Number3D;
private static var v2x:Number;
private static var ts:Sprite = new Sprite();
private static var v2:Vertex3DInstance;
private static var light:Number3D;
private static var lm:Matrix3D;
private static var n2:Number3D;
private static var mapOrigin:Point = new Point(0, 0);
private static var currentGraphics:Graphics;
private static var origin:Point = new Point(0, 0);
private static var v0x:Number;
private static var v0y:Number;
private static var p0:Number;
private static var p1:Number;
private static var p2:Number;
private static var transformMatrix:Matrix = new Matrix();
private static var v0z:Number;
private static var triMatrix:Matrix = new Matrix();
private static var useMap:BitmapData;
private static var v1x:Number;
private static var v1y:Number;
private static var q0:Number;
private static var q1:Number;
private static var q2:Number;
private static var v1z:Number;
private static var r:Rectangle;
private static var v1:Vertex3DInstance;
private static var v2y:Number;
public function EnvMapShader(light:LightObject3D, envmap:BitmapData, backenvmap:BitmapData=null, ambientColor:int=0, bumpMap:BitmapData=null, specularMap:BitmapData=null){
super();
this.light = light;
this.envMap = envmap;
if (!backenvmap){
this.backenvmap = this.envMap.clone();
this.backenvmap.fillRect(this.backenvmap.rect, ambientColor);
} else {
this.backenvmap = backenvmap;
};
this.specularMap = specularMap;
this.bumpmap = bumpMap;
this.ambientColor = ambientColor;
}
override public function updateAfterRender(renderSessionData:RenderSessionData, sod:ShaderObjectData):void{
var s:Sprite;
if (dFilter){
s = Sprite(layers[sod.object]);
s.filters = [dFilter];
};
}
public function set bumpmap(bumpmap:BitmapData):void{
var map:BitmapData;
if (_bumpMap){
dFilter = null;
};
if (bumpmap){
map = BumpmapGenerator.generateBumpmapFrom(bumpmap);
dFilter = new DisplacementMapFilter(map, mapOrigin, BitmapDataChannel.RED, BitmapDataChannel.GREEN, -127, -127, DisplacementMapFilterMode.WRAP, ambientColor, 0);
} else {
filter = null;
};
_bumpMap = bumpmap;
}
public function get specularMap():BitmapData{
return (_specularMap);
}
override public function renderLayer(triangle:Triangle3D, renderSessionData:RenderSessionData, sod:ShaderObjectData):void{
lm = Matrix3D(sod.lightMatrices[this]);
p0 = ((lightmapHalfwidth * (((triangle.v0.normal.x * lm.n11) + (triangle.v0.normal.y * lm.n12)) + (triangle.v0.normal.z * lm.n13))) + lightmapHalfwidth);
q0 = ((lightmapHalfheight * (((triangle.v0.normal.x * lm.n21) + (triangle.v0.normal.y * lm.n22)) + (triangle.v0.normal.z * lm.n23))) + lightmapHalfheight);
p1 = ((lightmapHalfwidth * (((triangle.v1.normal.x * lm.n11) + (triangle.v1.normal.y * lm.n12)) + (triangle.v1.normal.z * lm.n13))) + lightmapHalfwidth);
q1 = ((lightmapHalfheight * (((triangle.v1.normal.x * lm.n21) + (triangle.v1.normal.y * lm.n22)) + (triangle.v1.normal.z * lm.n23))) + lightmapHalfheight);
p2 = ((lightmapHalfwidth * (((triangle.v2.normal.x * lm.n11) + (triangle.v2.normal.y * lm.n12)) + (triangle.v2.normal.z * lm.n13))) + lightmapHalfwidth);
q2 = ((lightmapHalfheight * (((triangle.v2.normal.x * lm.n21) + (triangle.v2.normal.y * lm.n22)) + (triangle.v2.normal.z * lm.n23))) + lightmapHalfheight);
triMatrix = (sod.uvMatrices[triangle]) ? sod.uvMatrices[triangle] : sod.getUVMatrixForTriangle(triangle);
transformMatrix.tx = p0;
transformMatrix.ty = q0;
transformMatrix.a = (p1 - p0);
transformMatrix.b = (q1 - q0);
transformMatrix.c = (p2 - p0);
transformMatrix.d = (q2 - q0);
transformMatrix.invert();
transformMatrix.concat(triMatrix);
if ((((triangle.faceNormal.x * lm.n31) + (triangle.faceNormal.y * lm.n32)) + (triangle.faceNormal.z * lm.n33)) > 0){
useMap = _envMap;
} else {
useMap = backenvmap;
};
currentGraphics = Sprite(layers[sod.object]).graphics;
currentGraphics.beginBitmapFill(useMap, transformMatrix, false, false);
currentGraphics.moveTo(triMatrix.tx, triMatrix.ty);
currentGraphics.lineTo((triMatrix.a + triMatrix.tx), (triMatrix.b + triMatrix.ty));
currentGraphics.lineTo((triMatrix.c + triMatrix.tx), (triMatrix.d + triMatrix.ty));
currentGraphics.lineTo(triMatrix.tx, triMatrix.ty);
currentGraphics.endFill();
currentGraphics.lineStyle();
}
public function set envMap(lightMap:BitmapData):void{
if (lightMap){
lightmapHalfwidth = (lightMap.width / 2);
lightmapHalfheight = (lightMap.height / 2);
};
_envMap = lightMap;
}
public function set ambientColor(ambient:int):void{
_ambientColor = ambient;
}
public function get bumpmap():BitmapData{
return (_bumpMap);
}
public function get ambientColor():int{
return (_ambientColor);
}
public function set backenvmap(envmap:BitmapData):void{
_backEnvMap = envmap;
}
public function get envMap():BitmapData{
return (_envMap);
}
public function set specularMap(specularMap:BitmapData):void{
_specularMap = specularMap;
}
override public function renderTri(triangle:Triangle3D, renderSessionData:RenderSessionData, sod:ShaderObjectData, bmp:BitmapData):void{
lm = Matrix3D(sod.lightMatrices[this]);
p0 = ((lightmapHalfwidth * (((triangle.v0.normal.x * lm.n11) + (triangle.v0.normal.y * lm.n12)) + (triangle.v0.normal.z * lm.n13))) + lightmapHalfwidth);
q0 = ((lightmapHalfheight * (((triangle.v0.normal.x * lm.n21) + (triangle.v0.normal.y * lm.n22)) + (triangle.v0.normal.z * lm.n23))) + lightmapHalfheight);
p1 = ((lightmapHalfwidth * (((triangle.v1.normal.x * lm.n11) + (triangle.v1.normal.y * lm.n12)) + (triangle.v1.normal.z * lm.n13))) + lightmapHalfwidth);
q1 = ((lightmapHalfheight * (((triangle.v1.normal.x * lm.n21) + (triangle.v1.normal.y * lm.n22)) + (triangle.v1.normal.z * lm.n23))) + lightmapHalfheight);
p2 = ((lightmapHalfwidth * (((triangle.v2.normal.x * lm.n11) + (triangle.v2.normal.y * lm.n12)) + (triangle.v2.normal.z * lm.n13))) + lightmapHalfwidth);
q2 = ((lightmapHalfheight * (((triangle.v2.normal.x * lm.n21) + (triangle.v2.normal.y * lm.n22)) + (triangle.v2.normal.z * lm.n23))) + lightmapHalfheight);
triMatrix = (sod.renderTriangleUVS[triangle]) ? sod.renderTriangleUVS[triangle] : sod.getPerTriUVForShader(triangle);
transformMatrix.tx = p0;
transformMatrix.ty = q0;
transformMatrix.a = (p1 - p0);
transformMatrix.b = (q1 - q0);
transformMatrix.c = (p2 - p0);
transformMatrix.d = (q2 - q0);
transformMatrix.invert();
transformMatrix.concat(triMatrix);
if ((((triangle.faceNormal.x * lm.n31) + (triangle.faceNormal.y * lm.n32)) + (triangle.faceNormal.z * lm.n33)) > 0){
useMap = _envMap;
} else {
useMap = backenvmap;
};
ts.graphics.clear();
ts.graphics.beginBitmapFill(useMap, transformMatrix, false, false);
ts.graphics.drawRect(0, 0, bmp.rect.width, bmp.rect.height);
ts.graphics.endFill();
bmp.draw(ts, null, null, layerBlendMode, null, false);
}
public function get backenvmap():BitmapData{
return (_backEnvMap);
}
public static function get shaderLayer():Sprite{
return (ts);
}
}
}//package org.papervision3d.materials.shaders
Section 89
//ILightShader (org.papervision3d.materials.shaders.ILightShader)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.render.shader.*;
public interface ILightShader {
function updateLightMatrix(_arg1:ShaderObjectData, _arg2:RenderSessionData):void;
}
}//package org.papervision3d.materials.shaders
Section 90
//IShader (org.papervision3d.materials.shaders.IShader)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.render.shader.*;
import flash.display.*;
public interface IShader {
function updateAfterRender(_arg1:RenderSessionData, _arg2:ShaderObjectData):void;
function destroy():void;
function renderLayer(_arg1:Triangle3D, _arg2:RenderSessionData, _arg3:ShaderObjectData):void;
function renderTri(_arg1:Triangle3D, _arg2:RenderSessionData, _arg3:ShaderObjectData, _arg4:BitmapData):void;
}
}//package org.papervision3d.materials.shaders
Section 91
//LightShader (org.papervision3d.materials.shaders.LightShader)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.core.render.shader.*;
public class LightShader extends Shader implements IShader, ILightShader {
private var _light:LightObject3D;
public function LightShader():void{
super();
}
public function updateLightMatrix(sod:ShaderObjectData, renderSessionData:RenderSessionData):void{
sod.lightMatrices[this] = LightMatrix.getLightMatrix(light, sod.object, renderSessionData);
}
public function get light():LightObject3D{
return (_light);
}
public function set light(light:LightObject3D):void{
_light = light;
}
}
}//package org.papervision3d.materials.shaders
Section 92
//PhongShader (org.papervision3d.materials.shaders.PhongShader)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.utils.*;
import flash.display.*;
public class PhongShader extends EnvMapShader {
public function PhongShader(light:LightObject3D, lightColor:int, ambientColor:int=0, specularLevel:int=0, bumpMap:BitmapData=null, specularMap:BitmapData=null){
super(light, LightMaps.getPhongMap(lightColor, ambientColor, specularLevel), null, ambientColor, bumpMap, specularMap);
}
}
}//package org.papervision3d.materials.shaders
Section 93
//ShadedMaterial (org.papervision3d.materials.shaders.ShadedMaterial)
package org.papervision3d.materials.shaders {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.render.shader.*;
import flash.display.*;
import org.papervision3d.materials.*;
import org.papervision3d.core.render.material.*;
import flash.utils.*;
import org.papervision3d.core.render.draw.*;
import org.papervision3d.core.material.*;
public class ShadedMaterial extends TriangleMaterial implements ITriangleDrawer, IUpdateBeforeMaterial, IUpdateAfterMaterial {
public var shader:Shader;
private var _shaderCompositeMode:int;
public var material:BitmapMaterial;
public var shaderObjectData:Dictionary;
private static var bmp:BitmapData;
public function ShadedMaterial(material:BitmapMaterial, shader:Shader, compositeMode:int=0){
super();
this.shader = shader;
this.material = material;
shaderCompositeMode = compositeMode;
init();
}
override public function registerObject(displayObject3D:DisplayObject3D):void{
super.registerObject(displayObject3D);
var sod:ShaderObjectData = (shaderObjectData[displayObject3D] = new ShaderObjectData(displayObject3D, material, this));
sod.shaderRenderer.inputBitmap = material.bitmap;
shader.setContainerForObject(displayObject3D, sod.shaderRenderer.getLayerForShader(shader));
}
public function updateAfterRender(renderSessionData:RenderSessionData):void{
var sod:ShaderObjectData;
for each (sod in shaderObjectData) {
shader.updateAfterRender(renderSessionData, sod);
if (shaderCompositeMode == ShaderCompositeModes.PER_LAYER){
sod.shaderRenderer.render(renderSessionData);
};
};
}
private function init():void{
shaderObjectData = new Dictionary();
}
public function set shaderCompositeMode(compositeMode:int):void{
_shaderCompositeMode = compositeMode;
}
public function get shaderCompositeMode():int{
return (_shaderCompositeMode);
}
public function getOutputBitmapDataFor(object:DisplayObject3D):BitmapData{
var sod:ShaderObjectData;
if (shaderCompositeMode == ShaderCompositeModes.PER_LAYER){
if (shaderObjectData[object]){
sod = shaderObjectData[object];
return (sod.shaderRenderer.outputBitmap);
};
trace("object not registered with shaded material");
} else {
trace("getOutputBitmapDataFor only works on per layer mode");
};
return (null);
}
override protected function destroy():void{
var sod:ShaderObjectData;
super.destroy();
for each (sod in shaderObjectData) {
sod.destroy();
};
material = null;
shader = null;
}
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
var sod:ShaderObjectData = shaderObjectData[face3D.instance];
if (shaderCompositeMode == ShaderCompositeModes.PER_LAYER){
material.drawTriangle(face3D, graphics, renderSessionData, sod.shaderRenderer.outputBitmap);
shader.renderLayer(face3D, renderSessionData, sod);
} else {
if (shaderCompositeMode == ShaderCompositeModes.PER_TRIANGLE_IN_BITMAP){
bmp = sod.getOutputBitmapFor(face3D);
material.drawTriangle(face3D, graphics, renderSessionData, bmp, (sod.triangleUVS[face3D]) ? sod.triangleUVS[face3D] : sod.getPerTriUVForDraw(face3D));
shader.renderTri(face3D, renderSessionData, sod, bmp);
};
};
}
override public function unregisterObject(displayObject3D:DisplayObject3D):void{
super.unregisterObject(displayObject3D);
var sod:ShaderObjectData = shaderObjectData[displayObject3D];
sod.destroy();
delete shaderObjectData[displayObject3D];
}
public function updateBeforeRender(renderSessionData:RenderSessionData):void{
var sod:ShaderObjectData;
var ls:ILightShader;
for each (sod in shaderObjectData) {
if (shaderCompositeMode == ShaderCompositeModes.PER_LAYER){
sod.shaderRenderer.clear();
};
if ((shader is ILightShader)){
ls = (shader as ILightShader);
ls.updateLightMatrix(sod, renderSessionData);
};
};
}
}
}//package org.papervision3d.materials.shaders
Section 94
//Shader (org.papervision3d.materials.shaders.Shader)
package org.papervision3d.materials.shaders {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.render.shader.*;
import flash.display.*;
import flash.filters.*;
import flash.utils.*;
import org.papervision3d.core.utils.virtualmouse.*;
public class Shader extends EventDispatcher implements IShader {
protected var layers:Dictionary;
protected var _blendMode:String;// = "multiply"
protected var _filter:BitmapFilter;
protected var _object:DisplayObject3D;
public function Shader(){
super();
this.layers = new Dictionary(true);
}
public function set layerBlendMode(blendMode:String):void{
_blendMode = blendMode;
}
public function setContainerForObject(object:DisplayObject3D, layer:Sprite):void{
VirtualMouse.ignore(layer);
layers[object] = layer;
}
public function updateAfterRender(renderSessionData:RenderSessionData, sod:ShaderObjectData):void{
}
public function set filter(filter:BitmapFilter):void{
_filter = filter;
}
public function get layerBlendMode():String{
return (_blendMode);
}
public function get filter():BitmapFilter{
return (_filter);
}
public function destroy():void{
}
public function renderTri(triangle:Triangle3D, renderSessionData:RenderSessionData, sod:ShaderObjectData, bmp:BitmapData):void{
}
public function renderLayer(triangle:Triangle3D, renderSessionData:RenderSessionData, sod:ShaderObjectData):void{
}
}
}//package org.papervision3d.materials.shaders
Section 95
//ShaderCompositeModes (org.papervision3d.materials.shaders.ShaderCompositeModes)
package org.papervision3d.materials.shaders {
public class ShaderCompositeModes {
public static var PER_TRIANGLE_IN_BITMAP:int = 1;
public static var PER_LAYER:int = 0;
public function ShaderCompositeModes(){
super();
}
}
}//package org.papervision3d.materials.shaders
Section 96
//ParticleMaterial (org.papervision3d.materials.special.ParticleMaterial)
package org.papervision3d.materials.special {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.render.draw.*;
public class ParticleMaterial extends MaterialObject3D implements IParticleDrawer {
public var shape:int;
public static var SHAPE_SQUARE:int = 0;
public static var SHAPE_CIRCLE:int = 1;
public function ParticleMaterial(color:Number, alpha:Number, shape:int=0){
super();
this.shape = shape;
this.fillAlpha = alpha;
this.fillColor = color;
}
public function drawParticle(particle:Particle, graphics:Graphics, renderSessionData:RenderSessionData):void{
graphics.beginFill(fillColor, fillAlpha);
var renderrect:Rectangle = particle.renderRect;
if (shape == SHAPE_SQUARE){
graphics.drawRect(renderrect.x, renderrect.y, renderrect.width, renderrect.height);
} else {
if (shape == SHAPE_CIRCLE){
graphics.drawCircle((renderrect.x + (renderrect.width / 2)), (renderrect.y + (renderrect.width / 2)), (renderrect.width / 2));
} else {
trace("warning - Particle material has no valid shape - Must be ParticleMaterial.SHAPE_SQUARE or ParticleMaterial.SHAPE_CIRCLE");
};
};
graphics.endFill();
renderSessionData.renderStatistics.particles++;
}
public function updateRenderRect(particle:Particle):void{
var renderrect:Rectangle = particle.renderRect;
if (particle.size == 0){
renderrect.width = 1;
renderrect.height = 1;
} else {
renderrect.width = (particle.renderScale * particle.size);
renderrect.height = (particle.renderScale * particle.size);
};
renderrect.x = (particle.vertex3D.vertex3DInstance.x - (renderrect.width / 2));
renderrect.y = (particle.vertex3D.vertex3DInstance.y - (renderrect.width / 2));
}
}
}//package org.papervision3d.materials.special
Section 97
//BumpmapGenerator (org.papervision3d.materials.utils.BumpmapGenerator)
package org.papervision3d.materials.utils {
import flash.geom.*;
import flash.display.*;
import flash.filters.*;
public class BumpmapGenerator {
public function BumpmapGenerator(){
super();
}
public static function generateBumpmapFrom(bitmapData:BitmapData, output:BitmapData=null):BitmapData{
var tempMap:BitmapData;
var outputData:BitmapData;
var p:Point = new Point();
var convolve:ConvolutionFilter = new ConvolutionFilter();
convolve.matrixX = 3;
convolve.matrixY = 3;
convolve.divisor = 1;
convolve.bias = 127;
if (!output){
outputData = bitmapData.clone();
} else {
outputData = output;
};
convolve.matrix = new Array(0, 0, 0, -1, 0, 1, 0, 0, 0);
tempMap = bitmapData.clone();
tempMap.applyFilter(bitmapData, tempMap.rect, p, convolve);
outputData.copyPixels(tempMap, tempMap.rect, p);
convolve.matrix = new Array(0, -1, 0, 0, 0, 0, 0, 1, 0);
tempMap = bitmapData.clone();
tempMap.applyFilter(bitmapData, tempMap.rect, p, convolve);
outputData.copyChannel(tempMap, tempMap.rect, p, 1, 2);
tempMap.dispose();
return (outputData);
}
}
}//package org.papervision3d.materials.utils
Section 98
//LightMaps (org.papervision3d.materials.utils.LightMaps)
package org.papervision3d.materials.utils {
import flash.geom.*;
import flash.display.*;
import flash.filters.*;
public class LightMaps {
private static var origin:Point = new Point();
public function LightMaps(){
super();
}
public static function getPhongMap(lightColor:int, ambientColor:int, specularLevel:int, height:int=0xFF, width:int=0xFF):BitmapData{
var lw:Number = height;
var lh:Number = width;
var s:Sprite = new Sprite();
var mat:Matrix = new Matrix();
mat.createGradientBox(lw, lw, 0, 0, 0);
s.graphics.beginGradientFill(GradientType.RADIAL, [lightColor, ambientColor, ambientColor], [1, 1, 1], [0, (0xFF - specularLevel), 0xFF], mat);
s.graphics.drawRect(0, 0, lw, lw);
s.graphics.endFill();
var bmp:BitmapData = new BitmapData(lw, lw, false, 0xFF);
bmp.draw(s);
return (bmp);
}
public static function getCellMap(color_1:int, color_2:int, steps:int):BitmapData{
var bmp:BitmapData = LightMaps.getPhongMap(color_1, color_2, 0, 0xFF, 0xFF);
var n:Number = 0;
var r_1 = ((color_1 & 0xFF0000) >> 16);
var r_2 = ((color_2 & 0xFF0000) >> 16);
var rStep:int = (r_2 - r_1);
var rlut:Array = new Array();
var glut:Array = new Array();
var blut:Array = new Array();
var i:int;
while (i <= 0xFF) {
rlut[i] = ((i - (i % Math.round((0x0100 / steps)))) << 16);
glut[i] = ((i - (i % Math.round((0x0100 / steps)))) << 8);
blut[i] = (i - (i % Math.round((0x0100 / steps))));
i++;
};
bmp.paletteMap(bmp, bmp.rect, origin, rlut, glut, blut);
bmp.applyFilter(bmp, bmp.rect, origin, new BlurFilter(2, 2, 2));
return (bmp);
}
public static function getGouraudMap(lightColor:int, ambientColor:int):BitmapData{
var gouraudMap:BitmapData = new BitmapData(0x0100, 3, false, 0xFFFFFF);
var s:Sprite = new Sprite();
var m:Matrix = new Matrix();
m.createGradientBox(0x0100, 3, 0, 0, 0);
s.graphics.beginGradientFill(GradientType.LINEAR, [ambientColor, lightColor], [1, 1], [0, 0xFF], m);
s.graphics.drawRect(0, 0, 0x0100, 3);
s.graphics.endFill();
gouraudMap.draw(s);
return (gouraudMap);
}
public static function getFlatMapArray(lightColor:int, ambientColor:int, specularLevel:int):Array{
var array:Array = new Array();
var tempmap:BitmapData = new BitmapData(0xFF, 1, false, 0);
var s:Sprite = new Sprite();
var m:Matrix = new Matrix();
m.createGradientBox(0xFF, 1, 0, 0, 0);
s.graphics.beginGradientFill(GradientType.LINEAR, [lightColor, ambientColor], [1, 1], [0, 0xFF], m);
s.graphics.drawRect(0, 0, 0xFF, 1);
s.graphics.endFill();
tempmap.draw(s);
var i = 0xFF;
while (i--) {
array.push(tempmap.getPixel(i, 0));
};
return (array);
}
public static function getFlatMap(lightColor:int, ambientColor:int, specularLevel:int):BitmapData{
var array:Array = new Array();
var tempmap:BitmapData = new BitmapData(0xFF, 1, false, 0);
var s:Sprite = new Sprite();
var m:Matrix = new Matrix();
m.createGradientBox(0xFF, 1, 0, 0, 0);
s.graphics.beginGradientFill(GradientType.LINEAR, [ambientColor, lightColor], [1, 1], [0, 0xFF], m);
s.graphics.drawRect(0, 0, 0xFF, 1);
s.graphics.endFill();
tempmap.draw(s);
return (tempmap);
}
}
}//package org.papervision3d.materials.utils
Section 99
//LightMatrix (org.papervision3d.materials.utils.LightMatrix)
package org.papervision3d.materials.utils {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.math.*;
import org.papervision3d.lights.*;
public class LightMatrix {
private static var _targetPos:Number3D;
private static var _lightSide:Number3D;
private static var _lightUp:Number3D;
private static var _lightDir:Number3D;
private static var lightMatrix:Matrix3D = Matrix3D.IDENTITY;
protected static var UP:Number3D = new Number3D(0, 1, 0);
private static var _lightPos:Number3D;
public function LightMatrix(){
super();
}
public static function getLightMatrix(light:LightObject3D, object:DisplayObject3D, renderSessionData:RenderSessionData):Matrix3D{
var mo:Matrix3D;
var lightMatrix:Matrix3D = Matrix3D.IDENTITY;
if (light == null){
light = new PointLight3D();
light.copyPosition(renderSessionData.camera);
};
_targetPos = new Number3D();
_lightPos = new Number3D();
_lightDir = new Number3D();
_lightUp = new Number3D();
_lightSide = new Number3D();
var ml:Matrix3D = light.transform;
mo = object.world;
_lightPos.x = -(ml.n14);
_lightPos.y = -(ml.n24);
_lightPos.z = -(ml.n34);
_targetPos.x = -(mo.n14);
_targetPos.y = -(mo.n24);
_targetPos.z = -(mo.n34);
_lightDir.x = (_targetPos.x - _lightPos.x);
_lightDir.y = (_targetPos.y - _lightPos.y);
_lightDir.z = (_targetPos.z - _lightPos.z);
Matrix3D.multiplyVector3x3(Matrix3D.inverse(object.world), _lightDir);
_lightDir.normalize();
_lightSide.x = ((_lightDir.y * UP.z) - (_lightDir.z * UP.y));
_lightSide.y = ((_lightDir.z * UP.x) - (_lightDir.x * UP.z));
_lightSide.z = ((_lightDir.x * UP.y) - (_lightDir.y * UP.x));
_lightSide.normalize();
_lightUp.x = ((_lightSide.y * _lightDir.z) - (_lightSide.z * _lightDir.y));
_lightUp.y = ((_lightSide.z * _lightDir.x) - (_lightSide.x * _lightDir.z));
_lightUp.z = ((_lightSide.x * _lightDir.y) - (_lightSide.y * _lightDir.x));
_lightUp.normalize();
if (light.flipped){
_lightDir.x = -(_lightDir.x);
_lightDir.y = -(_lightDir.y);
_lightDir.z = -(_lightDir.z);
};
lightMatrix.n11 = _lightSide.x;
lightMatrix.n12 = _lightSide.y;
lightMatrix.n13 = _lightSide.z;
lightMatrix.n21 = _lightUp.x;
lightMatrix.n22 = _lightUp.y;
lightMatrix.n23 = _lightUp.z;
lightMatrix.n31 = _lightDir.x;
lightMatrix.n32 = _lightDir.y;
lightMatrix.n33 = _lightDir.z;
return (lightMatrix);
}
}
}//package org.papervision3d.materials.utils
Section 100
//MaterialsList (org.papervision3d.materials.utils.MaterialsList)
package org.papervision3d.materials.utils {
import org.papervision3d.core.proto.*;
import flash.utils.*;
public class MaterialsList {
protected var _materials:Dictionary;
public var materialsByName:Dictionary;
private var _materialsTotal:int;
public function MaterialsList(materials=null):void{
var i:String;
var name:String;
super();
this.materialsByName = new Dictionary(true);
this._materials = new Dictionary(false);
this._materialsTotal = 0;
if (materials){
if ((materials is Array)){
for (i in materials) {
this.addMaterial(materials[i]);
};
} else {
if ((materials is Object)){
for (name in materials) {
this.addMaterial(materials[name], name);
};
};
};
};
}
public function get numMaterials():int{
return (this._materialsTotal);
}
public function addMaterial(material:MaterialObject3D, name:String=null):MaterialObject3D{
name = ((((name) || (material.name))) || (String(material.id)));
this._materials[material] = name;
this.materialsByName[name] = material;
this._materialsTotal++;
return (material);
}
public function removeMaterial(material:MaterialObject3D):MaterialObject3D{
delete this.materialsByName[this._materials[material]];
delete this._materials[material];
return (material);
}
public function toString():String{
var m:MaterialObject3D;
var list:String = "";
for each (m in this.materialsByName) {
list = (list + (this._materials[m] + "\n"));
};
return (list);
}
public function removeMaterialByName(name:String):MaterialObject3D{
return (removeMaterial(getMaterialByName(name)));
}
public function clone():MaterialsList{
var m:MaterialObject3D;
var cloned:MaterialsList = new MaterialsList();
for each (m in this.materialsByName) {
cloned.addMaterial(m.clone(), this._materials[m]);
};
return (cloned);
}
public function getMaterialByName(name:String):MaterialObject3D{
return ((this.materialsByName[name]) ? this.materialsByName[name] : this.materialsByName["all"]);
}
}
}//package org.papervision3d.materials.utils
Section 101
//BitmapMaterial (org.papervision3d.materials.BitmapMaterial)
package org.papervision3d.materials {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import flash.utils.*;
import org.papervision3d.core.render.draw.*;
import org.papervision3d.core.material.*;
import org.papervision3d.*;
public class BitmapMaterial extends TriangleMaterial implements ITriangleDrawer {
public var focus:Number;// = 100
public var uvMatrices:Dictionary;
protected var _texture:Object;
private var _precise:Boolean;
public var minimumRenderSize:Number;// = 2
public var precision:Number;// = 8
protected static var _triMap:Matrix;
public static var AUTO_MIP_MAPPING:Boolean = false;
protected static var _localMatrix:Matrix = new Matrix();
public static var MIP_MAP_DEPTH:Number = 8;
protected static var _triMatrix:Matrix = new Matrix();
public function BitmapMaterial(asset:BitmapData=null, precise:Boolean=false){
uvMatrices = new Dictionary();
super();
if (asset){
texture = asset;
};
this.precise = precise;
}
public function set texture(asset:Object):void{
if ((asset is BitmapData) == false){
Papervision3D.log("Error: BitmapMaterial.texture requires a BitmapData object for the texture");
return;
};
bitmap = createBitmap(BitmapData(asset));
_texture = asset;
}
protected function createBitmap(asset:BitmapData):BitmapData{
resetMapping();
if (AUTO_MIP_MAPPING){
return (correctBitmap(asset));
};
this.maxU = (this.maxV = 1);
return (asset);
}
public function transformUV(face3D:Triangle3D):Matrix{
var uv:Array;
var w:Number;
var h:Number;
var u0:Number;
var v0:Number;
var u1:Number;
var v1:Number;
var u2:Number;
var v2:Number;
var at:Number;
var bt:Number;
var ct:Number;
var dt:Number;
var m:Matrix;
var mapping:Matrix;
if (!face3D.uv){
Papervision3D.log("MaterialObject3D: transformUV() uv not found!");
} else {
if (bitmap){
uv = face3D.uv;
w = (bitmap.width * maxU);
h = (bitmap.height * maxV);
u0 = (w * face3D.uv0.u);
v0 = (h * (1 - face3D.uv0.v));
u1 = (w * face3D.uv1.u);
v1 = (h * (1 - face3D.uv1.v));
u2 = (w * face3D.uv2.u);
v2 = (h * (1 - face3D.uv2.v));
if ((((((u0 == u1)) && ((v0 == v1)))) || ((((u0 == u2)) && ((v0 == v2)))))){
u0 = (u0 - ((u0)>0.05) ? 0.05 : -0.05);
v0 = (v0 - ((v0)>0.07) ? 0.07 : -0.07);
};
if ((((u2 == u1)) && ((v2 == v1)))){
u2 = (u2 - ((u2)>0.05) ? 0.04 : -0.04);
v2 = (v2 - ((v2)>0.06) ? 0.06 : -0.06);
};
at = (u1 - u0);
bt = (v1 - v0);
ct = (u2 - u0);
dt = (v2 - v0);
m = new Matrix(at, bt, ct, dt, u0, v0);
m.invert();
mapping = ((uvMatrices[face3D]) || ((uvMatrices[face3D] = m.clone())));
mapping.a = m.a;
mapping.b = m.b;
mapping.c = m.c;
mapping.d = m.d;
mapping.tx = m.tx;
mapping.ty = m.ty;
} else {
Papervision3D.log("MaterialObject3D: transformUV() material.bitmap not found!");
};
};
return (mapping);
}
public function renderTriangleBitmap(graphics:Graphics, a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number, v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean, bitmapData:BitmapData):void{
var a2:Number = (v1x - v0x);
var b2:Number = (v1y - v0y);
var c2:Number = (v2x - v0x);
var d2:Number = (v2y - v0y);
var matrix:Matrix = new Matrix(((a * a2) + (b * c2)), ((a * b2) + (b * d2)), ((c * a2) + (d * c2)), ((c * b2) + (d * d2)), (((tx * a2) + (ty * c2)) + v0x), (((tx * b2) + (ty * d2)) + v0y));
graphics.beginBitmapFill(bitmapData, matrix, repeat, smooth);
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number, ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number, renderSessionData:RenderSessionData, bitmap:BitmapData):void{
if ((((((az <= 0)) && ((bz <= 0)))) && ((cz <= 0)))){
return;
};
if ((((((((index >= 100)) || ((focus == Infinity)))) || (((Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx)) < minimumRenderSize)))) || (((Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy)) < minimumRenderSize)))){
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled, bitmap);
renderSessionData.renderStatistics.triangles++;
return;
};
var faz:Number = (focus + az);
var fbz:Number = (focus + bz);
var fcz:Number = (focus + cz);
var mabz:Number = (2 / (faz + fbz));
var mbcz:Number = (2 / (fbz + fcz));
var mcaz:Number = (2 / (fcz + faz));
var mabx:Number = (((ax * faz) + (bx * fbz)) * mabz);
var maby:Number = (((ay * faz) + (by * fbz)) * mabz);
var mbcx:Number = (((bx * fbz) + (cx * fcz)) * mbcz);
var mbcy:Number = (((by * fbz) + (cy * fcz)) * mbcz);
var mcax:Number = (((cx * fcz) + (ax * faz)) * mcaz);
var mcay:Number = (((cy * fcz) + (ay * faz)) * mcaz);
var dabx:Number = ((ax + bx) - mabx);
var daby:Number = ((ay + by) - maby);
var dbcx:Number = ((bx + cx) - mbcx);
var dbcy:Number = ((by + cy) - mbcy);
var dcax:Number = ((cx + ax) - mcax);
var dcay:Number = ((cy + ay) - mcay);
var dsab:Number = ((dabx * dabx) + (daby * daby));
var dsbc:Number = ((dbcx * dbcx) + (dbcy * dbcy));
var dsca:Number = ((dcax * dcax) + (dcay * dcay));
if ((((((dsab <= precision)) && ((dsca <= precision)))) && ((dsbc <= precision)))){
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled, bitmap);
renderSessionData.renderStatistics.triangles++;
return;
};
if ((((((dsab > precision)) && ((dsca > precision)))) && ((dsbc > precision)))){
renderRec(graphics, (ta * 2), (tb * 2), (tc * 2), (td * 2), (tx * 2), (ty * 2), ax, ay, az, (mabx * 0.5), (maby * 0.5), ((az + bz) * 0.5), (mcax * 0.5), (mcay * 0.5), ((cz + az) * 0.5), (index + 1), renderSessionData, bitmap);
renderRec(graphics, (ta * 2), (tb * 2), (tc * 2), (td * 2), ((tx * 2) - 1), (ty * 2), (mabx * 0.5), (maby * 0.5), ((az + bz) * 0.5), bx, by, bz, (mbcx * 0.5), (mbcy * 0.5), ((bz + cz) * 0.5), (index + 1), renderSessionData, bitmap);
renderRec(graphics, (ta * 2), (tb * 2), (tc * 2), (td * 2), (tx * 2), ((ty * 2) - 1), (mcax * 0.5), (mcay * 0.5), ((cz + az) * 0.5), (mbcx * 0.5), (mbcy * 0.5), ((bz + cz) * 0.5), cx, cy, cz, (index + 1), renderSessionData, bitmap);
renderRec(graphics, (-(ta) * 2), (-(tb) * 2), (-(tc) * 2), (-(td) * 2), ((-(tx) * 2) + 1), ((-(ty) * 2) + 1), (mbcx * 0.5), (mbcy * 0.5), ((bz + cz) * 0.5), (mcax * 0.5), (mcay * 0.5), ((cz + az) * 0.5), (mabx * 0.5), (maby * 0.5), ((az + bz) * 0.5), (index + 1), renderSessionData, bitmap);
return;
};
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax){
renderRec(graphics, (ta * 2), (tb * 1), (tc * 2), (td * 1), (tx * 2), (ty * 1), ax, ay, az, (mabx * 0.5), (maby * 0.5), ((az + bz) * 0.5), cx, cy, cz, (index + 1), renderSessionData, bitmap);
renderRec(graphics, ((ta * 2) + tb), (tb * 1), ((2 * tc) + td), (td * 1), (((tx * 2) + ty) - 1), (ty * 1), (mabx * 0.5), (maby * 0.5), ((az + bz) * 0.5), bx, by, bz, cx, cy, cz, (index + 1), renderSessionData, bitmap);
return;
};
if (dsca == dmax){
renderRec(graphics, (ta * 1), (tb * 2), (tc * 1), (td * 2), (tx * 1), (ty * 2), ax, ay, az, bx, by, bz, (mcax * 0.5), (mcay * 0.5), ((cz + az) * 0.5), (index + 1), renderSessionData, bitmap);
renderRec(graphics, (ta * 1), ((tb * 2) + ta), (tc * 1), ((td * 2) + tc), tx, (((ty * 2) + tx) - 1), (mcax * 0.5), (mcay * 0.5), ((cz + az) * 0.5), bx, by, bz, cx, cy, cz, (index + 1), renderSessionData, bitmap);
return;
};
renderRec(graphics, (ta - tb), (tb * 2), (tc - td), (td * 2), (tx - ty), (ty * 2), ax, ay, az, bx, by, bz, (mbcx * 0.5), (mbcy * 0.5), ((bz + cz) * 0.5), (index + 1), renderSessionData, bitmap);
renderRec(graphics, (2 * ta), (tb - ta), (tc * 2), (td - tc), (2 * tx), (ty - tx), ax, ay, az, (mbcx * 0.5), (mbcy * 0.5), ((bz + cz) * 0.5), cx, cy, cz, (index + 1), renderSessionData, bitmap);
}
override public function clone():MaterialObject3D{
var cloned:MaterialObject3D = super.clone();
cloned.maxU = this.maxU;
cloned.maxV = this.maxV;
return (cloned);
}
public function get precise():Boolean{
return (_precise);
}
public function get texture():Object{
return (this._texture);
}
protected function extendBitmapEdges(bmp:BitmapData, originalWidth:Number, originalHeight:Number):void{
var i:int;
var srcRect:Rectangle = new Rectangle();
var dstPoint:Point = new Point();
if (bmp.width > originalWidth){
srcRect.x = (originalWidth - 1);
srcRect.y = 0;
srcRect.width = 1;
srcRect.height = originalHeight;
dstPoint.y = 0;
i = originalWidth;
while (i < bmp.width) {
dstPoint.x = i;
bmp.copyPixels(bmp, srcRect, dstPoint);
i++;
};
};
if (bmp.height > originalHeight){
srcRect.x = 0;
srcRect.y = (originalHeight - 1);
srcRect.width = bmp.width;
srcRect.height = 1;
dstPoint.x = 0;
i = originalHeight;
while (i < bmp.height) {
dstPoint.y = i;
bmp.copyPixels(bmp, srcRect, dstPoint);
i++;
};
};
}
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
var x0:Number;
var y0:Number;
var x1:Number;
var y1:Number;
var x2:Number;
var y2:Number;
if (!_precise){
if (lineAlpha){
graphics.lineStyle(0, lineColor, lineAlpha);
};
if (bitmap){
_triMap = (altUV) ? altUV : ((uvMatrices[face3D]) || (transformUV(face3D)));
x0 = face3D.v0.vertex3DInstance.x;
y0 = face3D.v0.vertex3DInstance.y;
x1 = face3D.v1.vertex3DInstance.x;
y1 = face3D.v1.vertex3DInstance.y;
x2 = face3D.v2.vertex3DInstance.x;
y2 = face3D.v2.vertex3DInstance.y;
_triMatrix.a = (x1 - x0);
_triMatrix.b = (y1 - y0);
_triMatrix.c = (x2 - x0);
_triMatrix.d = (y2 - y0);
_triMatrix.tx = x0;
_triMatrix.ty = y0;
_localMatrix.a = _triMap.a;
_localMatrix.b = _triMap.b;
_localMatrix.c = _triMap.c;
_localMatrix.d = _triMap.d;
_localMatrix.tx = _triMap.tx;
_localMatrix.ty = _triMap.ty;
_localMatrix.concat(_triMatrix);
graphics.beginBitmapFill((altBitmap) ? altBitmap : bitmap, _localMatrix, tiled, smooth);
};
graphics.moveTo(x0, y0);
graphics.lineTo(x1, y1);
graphics.lineTo(x2, y2);
graphics.lineTo(x0, y0);
if (bitmap){
graphics.endFill();
};
if (lineAlpha){
graphics.lineStyle();
};
renderSessionData.renderStatistics.triangles++;
} else {
_triMap = (altUV) ? altUV : ((uvMatrices[face3D]) || (transformUV(face3D)));
focus = renderSessionData.camera.focus;
renderRec(graphics, _triMap.a, _triMap.b, _triMap.c, _triMap.d, _triMap.tx, _triMap.ty, face3D.v0.vertex3DInstance.x, face3D.v0.vertex3DInstance.y, face3D.v0.vertex3DInstance.z, face3D.v1.vertex3DInstance.x, face3D.v1.vertex3DInstance.y, face3D.v1.vertex3DInstance.z, face3D.v2.vertex3DInstance.x, face3D.v2.vertex3DInstance.y, face3D.v2.vertex3DInstance.z, 0, renderSessionData, (altBitmap) ? altBitmap : bitmap);
};
}
override public function copy(material:MaterialObject3D):void{
super.copy(material);
this.maxU = material.maxU;
this.maxV = material.maxV;
}
protected function correctBitmap(bitmap:BitmapData):BitmapData{
var okBitmap:BitmapData;
var levels:Number = (1 << MIP_MAP_DEPTH);
var bWidth:Number = (bitmap.width / levels);
bWidth = ((bWidth == uint(bWidth))) ? bWidth : (uint(bWidth) + 1);
var bHeight:Number = (bitmap.height / levels);
bHeight = ((bHeight == uint(bHeight))) ? bHeight : (uint(bHeight) + 1);
var width:Number = (levels * bWidth);
var height:Number = (levels * bHeight);
var ok:Boolean;
if (width > 2880){
width = bitmap.width;
ok = false;
};
if (height > 2880){
height = bitmap.height;
ok = false;
};
if (!ok){
Papervision3D.log((("Material " + this.name) + ": Texture too big for mip mapping. Resizing recommended for better performance and quality."));
};
if (((bitmap) && (((!(((bitmap.width % levels) == 0))) || (!(((bitmap.height % levels) == 0))))))){
okBitmap = new BitmapData(width, height, bitmap.transparent, 0);
widthOffset = bitmap.width;
heightOffset = bitmap.height;
this.maxU = (bitmap.width / width);
this.maxV = (bitmap.height / height);
okBitmap.draw(bitmap);
extendBitmapEdges(okBitmap, bitmap.width, bitmap.height);
} else {
this.maxU = (this.maxV = 1);
okBitmap = bitmap;
};
return (okBitmap);
}
override public function toString():String{
return (((((("Texture:" + this.texture) + " lineColor:") + this.lineColor) + " lineAlpha:") + this.lineAlpha));
}
public function set precise(boolean:Boolean):void{
_precise = boolean;
}
public function resetMapping():void{
uvMatrices = new Dictionary();
}
}
}//package org.papervision3d.materials
Section 102
//MovieMaterial (org.papervision3d.materials.MovieMaterial)
package org.papervision3d.materials {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import flash.display.*;
import org.papervision3d.core.render.material.*;
import org.papervision3d.core.render.draw.*;
import org.papervision3d.*;
public class MovieMaterial extends BitmapMaterial implements ITriangleDrawer, IUpdateBeforeMaterial {
public var movieTransparent:Boolean;
private var _animated:Boolean;
public var allowAutoResize:Boolean;// = true
public var movie:DisplayObject;
public function MovieMaterial(movieAsset:DisplayObject=null, transparent:Boolean=false, animated:Boolean=false, precise:Boolean=false){
super();
movieTransparent = transparent;
this.animated = animated;
this.interactive = interactive;
this.precise = precise;
if (movieAsset){
texture = movieAsset;
};
}
override protected function destroy():void{
super.destroy();
bitmap.dispose();
}
public function get animated():Boolean{
return (_animated);
}
public function set animated(status:Boolean):void{
_animated = status;
}
public function drawBitmap():void{
bitmap.fillRect(bitmap.rect, this.fillColor);
var mtx:Matrix = new Matrix();
mtx.scale(movie.scaleX, movie.scaleY);
bitmap.draw(movie, mtx, movie.transform.colorTransform);
}
override public function set texture(asset:Object):void{
if ((asset is DisplayObject) == false){
Papervision3D.log("Error: MovieMaterial.texture requires a Sprite to be passed as the object");
return;
};
bitmap = createBitmapFromSprite(DisplayObject(asset));
_texture = asset;
}
protected function createBitmapFromSprite(asset:DisplayObject):BitmapData{
movie = asset;
initBitmap(movie);
drawBitmap();
bitmap = super.createBitmap(bitmap);
return (bitmap);
}
override public function get texture():Object{
return (this._texture);
}
public function updateBeforeRender(renderSessionData:RenderSessionData):void{
var mWidth:int;
var mHeight:int;
if (_animated){
mWidth = int(movie.width);
mHeight = int(movie.height);
if (((allowAutoResize) && (((!((mWidth == bitmap.width))) || (!((mHeight == bitmap.height))))))){
initBitmap(movie);
};
drawBitmap();
};
}
protected function initBitmap(asset:DisplayObject):void{
if (bitmap){
bitmap.dispose();
};
bitmap = new BitmapData(asset.width, asset.height, this.movieTransparent);
}
}
}//package org.papervision3d.materials
Section 103
//WireframeMaterial (org.papervision3d.materials.WireframeMaterial)
package org.papervision3d.materials {
import org.papervision3d.core.render.data.*;
import flash.geom.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.core.render.draw.*;
import org.papervision3d.core.material.*;
public class WireframeMaterial extends TriangleMaterial implements ITriangleDrawer {
public function WireframeMaterial(color:Number=0xFF00FF, alpha:Number=100, thickness:Number=0){
super();
this.lineColor = color;
this.lineAlpha = alpha;
this.lineThickness = thickness;
this.doubleSided = false;
}
override public function toString():String{
return (((("WireframeMaterial - color:" + this.lineColor) + " alpha:") + this.lineAlpha));
}
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData=null, altUV:Matrix=null):void{
var x0:Number = face3D.v0.vertex3DInstance.x;
var y0:Number = face3D.v0.vertex3DInstance.y;
if (lineAlpha){
graphics.lineStyle(lineThickness, lineColor, lineAlpha);
graphics.moveTo(x0, y0);
graphics.lineTo(face3D.v1.vertex3DInstance.x, face3D.v1.vertex3DInstance.y);
graphics.lineTo(face3D.v2.vertex3DInstance.x, face3D.v2.vertex3DInstance.y);
graphics.lineTo(x0, y0);
graphics.lineStyle();
renderSessionData.renderStatistics.triangles++;
};
}
}
}//package org.papervision3d.materials
Section 104
//Plane (org.papervision3d.objects.primitives.Plane)
package org.papervision3d.objects.primitives {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.geom.*;
public class Plane extends TriangleMesh3D {
public var segmentsH:Number;
public var segmentsW:Number;
public static var DEFAULT_SCALE:Number = 1;
public static var DEFAULT_SEGMENTS:Number = 1;
public static var DEFAULT_SIZE:Number = 500;
public function Plane(material:MaterialObject3D=null, width:Number=0, height:Number=0, segmentsW:Number=0, segmentsH:Number=0, initObject:Object=null){
super(material, new Array(), new Array(), null, initObject);
this.segmentsW = ((segmentsW) || (DEFAULT_SEGMENTS));
this.segmentsH = ((segmentsH) || (this.segmentsW));
var scale:Number = DEFAULT_SCALE;
if (!height){
if (width){
scale = width;
};
if (((material) && (material.bitmap))){
width = (material.bitmap.width * scale);
height = (material.bitmap.height * scale);
} else {
width = (DEFAULT_SIZE * scale);
height = (DEFAULT_SIZE * scale);
};
};
buildPlane(width, height);
}
private function buildPlane(width:Number, height:Number):void{
var uvA:NumberUV;
var uvC:NumberUV;
var uvB:NumberUV;
var iy:int;
var x:Number;
var y:Number;
var a:Vertex3D;
var c:Vertex3D;
var b:Vertex3D;
var gridX:Number = this.segmentsW;
var gridY:Number = this.segmentsH;
var gridX1:Number = (gridX + 1);
var gridY1:Number = (gridY + 1);
var vertices:Array = this.geometry.vertices;
var faces:Array = this.geometry.faces;
var textureX:Number = (width / 2);
var textureY:Number = (height / 2);
var iW:Number = (width / gridX);
var iH:Number = (height / gridY);
var ix:int;
while (ix < (gridX + 1)) {
iy = 0;
while (iy < gridY1) {
x = ((ix * iW) - textureX);
y = ((iy * iH) - textureY);
vertices.push(new Vertex3D(x, y, 0));
iy++;
};
ix++;
};
ix = 0;
while (ix < gridX) {
iy = 0;
while (iy < gridY) {
a = vertices[((ix * gridY1) + iy)];
c = vertices[((ix * gridY1) + (iy + 1))];
b = vertices[(((ix + 1) * gridY1) + iy)];
uvA = new NumberUV((ix / gridX), (iy / gridY));
uvC = new NumberUV((ix / gridX), ((iy + 1) / gridY));
uvB = new NumberUV(((ix + 1) / gridX), (iy / gridY));
faces.push(new Triangle3D(this, [a, b, c], material, [uvA, uvB, uvC]));
a = vertices[(((ix + 1) * gridY1) + (iy + 1))];
c = vertices[(((ix + 1) * gridY1) + iy)];
b = vertices[((ix * gridY1) + (iy + 1))];
uvA = new NumberUV(((ix + 1) / gridX), ((iy + 1) / gridY));
uvC = new NumberUV(((ix + 1) / gridX), (iy / gridY));
uvB = new NumberUV((ix / gridX), ((iy + 1) / gridY));
faces.push(new Triangle3D(this, [a, b, c], material, [uvA, uvB, uvC]));
iy++;
};
ix++;
};
this.geometry.ready = true;
}
}
}//package org.papervision3d.objects.primitives
Section 105
//Sphere (org.papervision3d.objects.primitives.Sphere)
package org.papervision3d.objects.primitives {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.core.math.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.core.*;
public class Sphere extends TriangleMesh3D {
public var segmentsH:Number;
public var segmentsW:Number;
public static var MIN_SEGMENTSW:Number = 3;
public static var DEFAULT_SCALE:Number = 1;
public static var DEFAULT_RADIUS:Number = 100;
public static var DEFAULT_SEGMENTSH:Number = 6;
public static var MIN_SEGMENTSH:Number = 2;
public static var DEFAULT_SEGMENTSW:Number = 8;
public function Sphere(material:MaterialObject3D=null, radius:Number=100, segmentsW:int=8, segmentsH:int=6, initObject:Object=null){
super(material, new Array(), new Array(), null, initObject);
this.segmentsW = Math.max(MIN_SEGMENTSW, ((segmentsW) || (DEFAULT_SEGMENTSW)));
this.segmentsH = Math.max(MIN_SEGMENTSH, ((segmentsH) || (DEFAULT_SEGMENTSH)));
if (radius == 0){
radius = DEFAULT_RADIUS;
};
var scale:Number = DEFAULT_SCALE;
buildSphere(radius);
}
private function buildSphere(fRadius:Number):void{
var i:Number;
var j:Number;
var k:Number;
var fRad1:Number;
var fZ:Number;
var fRds:Number;
var aRow:Array;
var oVtx:Vertex3D;
var fRad2:Number;
var fX:Number;
var fY:Number;
var iHorNum:int;
var bEnd:Boolean;
var aP1:Vertex3D;
var aP2:Vertex3D;
var aP3:Vertex3D;
var aP4:Vertex3D;
var fJ0:Number;
var fJ1:Number;
var fI0:Number;
var fI1:Number;
var aP4uv:NumberUV;
var aP1uv:NumberUV;
var aP2uv:NumberUV;
var aP3uv:NumberUV;
var iHor:Number = Math.max(3, this.segmentsW);
var iVer:Number = Math.max(2, this.segmentsH);
var aVertice:Array = this.geometry.vertices;
var aFace:Array = this.geometry.faces;
var aVtc:Array = new Array();
j = 0;
while (j < (iVer + 1)) {
fRad1 = Number((j / iVer));
fZ = (-(fRadius) * Math.cos((fRad1 * Math.PI)));
fRds = (fRadius * Math.sin((fRad1 * Math.PI)));
aRow = new Array();
i = 0;
while (i < iHor) {
fRad2 = Number(((2 * i) / iHor));
fX = (fRds * Math.sin((fRad2 * Math.PI)));
fY = (fRds * Math.cos((fRad2 * Math.PI)));
if (!(((((j == 0)) || ((j == iVer)))) && ((i > 0)))){
oVtx = new Vertex3D(fY, fZ, fX);
aVertice.push(oVtx);
};
aRow.push(oVtx);
i++;
};
aVtc.push(aRow);
j++;
};
var iVerNum:int = aVtc.length;
j = 0;
while (j < iVerNum) {
iHorNum = aVtc[j].length;
if (j > 0){
i = 0;
while (i < iHorNum) {
bEnd = (i == (iHorNum - 0));
aP1 = aVtc[j][(bEnd) ? 0 : i];
aP2 = aVtc[j][(((i == 0)) ? iHorNum : i - 1)];
aP3 = aVtc[(j - 1)][(((i == 0)) ? iHorNum : i - 1)];
aP4 = aVtc[(j - 1)][(bEnd) ? 0 : i];
fJ0 = (j / (iVerNum - 1));
fJ1 = ((j - 1) / (iVerNum - 1));
fI0 = ((i + 1) / iHorNum);
fI1 = (i / iHorNum);
aP4uv = new NumberUV(fI0, fJ1);
aP1uv = new NumberUV(fI0, fJ0);
aP2uv = new NumberUV(fI1, fJ0);
aP3uv = new NumberUV(fI1, fJ1);
if (j < (aVtc.length - 1)){
aFace.push(new Triangle3D(this, new Array(aP1, aP2, aP3), material, new Array(aP1uv, aP2uv, aP3uv)));
};
if (j > 1){
aFace.push(new Triangle3D(this, new Array(aP1, aP3, aP4), material, new Array(aP1uv, aP3uv, aP4uv)));
};
i++;
};
};
j++;
};
this.geometry.ready = true;
}
}
}//package org.papervision3d.objects.primitives
Section 106
//DisplayObject3D (org.papervision3d.objects.DisplayObject3D)
package org.papervision3d.objects {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.utils.*;
import flash.display.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.core.math.*;
import com.blitzagency.xray.logger.*;
import org.papervision3d.*;
public class DisplayObject3D extends DisplayObjectContainer3D {
public var filters:Array;
public var extra:Object;
public var id:int;
private var _rotationY:Number;
private var _rotationZ:Number;
private var position:Number3D;
private var _rotationX:Number;
public var meshSort:uint;// = 1
public var materials:MaterialsList;
public var hasOwnRenderLayer:Boolean;
private var xAxis:Number3D;
private var zAxis:Number3D;
private var _scaleDirty:Boolean;// = false
public var renderLayer:RenderLayer;
private var _scaleX:Number;
public var screenZ:Number;
public var geometry:GeometryObject3D;
private var _scaleY:Number;
public var screen:Number3D;
private var _scaleZ:Number;
public var container:Sprite;
protected var _useOwnContainer:Boolean;
public var transform:Matrix3D;
public var visible:Boolean;
public var name:String;
protected var _scene:SceneObject3D;// = null
public var culled:Boolean;
public var world:Matrix3D;
private var _material:MaterialObject3D;
private var target:Number3D;
public var view:Matrix3D;
public var parent:DisplayObjectContainer3D;
protected var _containerSortMode:int;
public var faces:Array;
protected var _containerBlendMode:int;
private var yAxis:Number3D;
protected var _filters:Array;
private var _rotation:Number3D;
protected var _transformDirty:Boolean;// = false
private var _rotationDirty:Boolean;// = false
protected var _sorted:Array;
public static const MESH_SORT_CENTER:uint = 1;
public static const MESH_SORT_CLOSE:uint = 3;
public static const MESH_SORT_FAR:uint = 2;
private static var entry_count:uint = 0;
private static var LEFT:Number3D = new Number3D(-1, 0, 0);
private static var _totalDisplayObjects:int = 0;
private static var UP:Number3D = new Number3D(0, 1, 0);
public static var sortedArray:Array = new Array();
private static var BACKWARD:Number3D = new Number3D(0, 0, -1);
private static var FORWARD:Number3D = new Number3D(0, 0, 1);
private static var DOWN:Number3D = new Number3D(0, -1, 0);
public static var faceLevelMode:Boolean;
private static var _tempMatrix:Matrix3D = Matrix3D.IDENTITY;
private static var _tempQuat:Quaternion = new Quaternion();
private static var toDEGREES:Number = 57.2957795130823;
private static var RIGHT:Number3D = new Number3D(1, 0, 0);
private static var toRADIANS:Number = 0.0174532925199433;
public function DisplayObject3D(name:String=null, geometry:GeometryObject3D=null, initObject:Object=null):void{
screen = new Number3D();
faces = new Array();
position = Number3D.ZERO;
target = Number3D.ZERO;
zAxis = Number3D.ZERO;
xAxis = Number3D.ZERO;
yAxis = Number3D.ZERO;
_rotation = Number3D.ZERO;
super();
Papervision3D.log(("DisplayObject3D: " + name));
this.culled = false;
this.filters = new Array();
this.transform = Matrix3D.IDENTITY;
this.world = Matrix3D.IDENTITY;
this.view = Matrix3D.IDENTITY;
if (initObject != null){
this.x = (initObject.x) ? ((initObject.x) || (0)) : 0;
this.y = (initObject.y) ? ((initObject.y) || (0)) : 0;
this.z = (initObject.z) ? ((initObject.z) || (0)) : 0;
};
rotationX = (initObject) ? ((initObject.rotationX) || (0)) : 0;
rotationY = (initObject) ? ((initObject.rotationY) || (0)) : 0;
rotationZ = (initObject) ? ((initObject.rotationZ) || (0)) : 0;
var scaleDefault:Number = (Papervision3D.usePERCENT) ? 100 : 1;
scaleX = (initObject) ? ((initObject.scaleX) || (scaleDefault)) : scaleDefault;
scaleY = (initObject) ? ((initObject.scaleY) || (scaleDefault)) : scaleDefault;
scaleZ = (initObject) ? ((initObject.scaleZ) || (scaleDefault)) : scaleDefault;
if (((initObject) && (initObject.extra))){
this.extra = initObject.extra;
};
if (((initObject) && (initObject.container))){
this.container = initObject.container;
};
this.visible = true;
this.id = _totalDisplayObjects++;
this.name = ((name) || (String(this.id)));
if (geometry){
addGeometry(geometry);
};
}
public function moveDown(distance:Number):void{
translate(distance, DOWN);
}
public function set scene(p_scene:SceneObject3D):void{
var child:DisplayObject3D;
_scene = p_scene;
for each (child in this._childrenByName) {
if (child.scene == null){
child.scene = _scene;
};
};
}
public function project(parent:DisplayObject3D, renderSessionData:RenderSessionData):Number{
var child:DisplayObject3D;
if (this._transformDirty){
updateTransform();
};
this.world.calculateMultiply(parent.world, this.transform);
if ((renderSessionData.camera is IObjectCuller)){
if (this === renderSessionData.camera){
this.culled = true;
} else {
this.culled = (IObjectCuller(renderSessionData.camera).testObject(this) < 0);
};
if (this.culled){
renderSessionData.renderStatistics.culledObjects++;
return (0);
};
if (parent !== renderSessionData.camera){
this.view.calculateMultiply4x4(parent.view, this.transform);
};
} else {
if (parent !== renderSessionData.camera){
this.view.calculateMultiply(parent.view, this.transform);
};
};
calculateScreenCoords(renderSessionData.camera);
var screenZs:Number = 0;
var children:Number = 0;
for each (child in this._childrenByName) {
if (child.visible){
screenZs = (screenZs + child.project(this, renderSessionData));
children++;
};
};
return ((this.screenZ = (screenZs / children)));
}
public function get material():MaterialObject3D{
return (_material);
}
private function calculateScreenCoords(camera:CameraObject3D):void{
var persp:Number = ((camera.focus * camera.zoom) / (camera.focus + view.n34));
screen.x = (view.n14 * persp);
screen.y = (view.n24 * persp);
screen.z = view.n34;
}
public function lookAt(targetObject:DisplayObject3D, upAxis:Number3D=null):void{
var look:Matrix3D;
var log:XrayLog;
position.reset(this.x, this.y, this.z);
target.reset(targetObject.x, targetObject.y, targetObject.z);
zAxis.copyFrom(target);
zAxis.minusEq(position);
zAxis.normalize();
if (zAxis.modulo > 0.1){
xAxis = Number3D.cross(zAxis, ((upAxis) || (UP)), xAxis);
xAxis.normalize();
yAxis = Number3D.cross(zAxis, xAxis, yAxis);
yAxis.normalize();
look = this.transform;
look.n11 = (xAxis.x * _scaleX);
look.n21 = (xAxis.y * _scaleX);
look.n31 = (xAxis.z * _scaleX);
look.n12 = (-(yAxis.x) * _scaleY);
look.n22 = (-(yAxis.y) * _scaleY);
look.n32 = (-(yAxis.z) * _scaleY);
look.n13 = (zAxis.x * _scaleZ);
look.n23 = (zAxis.y * _scaleZ);
look.n33 = (zAxis.z * _scaleZ);
this._transformDirty = false;
this._rotationDirty = true;
} else {
log = new XrayLog();
log.debug("lookAt Error");
};
}
public function set rotationX(rot:Number):void{
this._rotationX = (Papervision3D.useDEGREES) ? (-(rot) * toRADIANS) : -(rot);
this._transformDirty = true;
}
public function set rotationZ(rot:Number):void{
this._rotationZ = (Papervision3D.useDEGREES) ? (-(rot) * toRADIANS) : -(rot);
this._transformDirty = true;
}
public function addGeometry(geometry:GeometryObject3D=null):void{
if (geometry){
this.geometry = geometry;
};
}
public function set rotationY(rot:Number):void{
this._rotationY = (Papervision3D.useDEGREES) ? (-(rot) * toRADIANS) : -(rot);
this._transformDirty = true;
}
public function pitch(angle:Number):void{
angle = (Papervision3D.useDEGREES) ? (angle * toRADIANS) : angle;
var vector:Number3D = RIGHT.clone();
if (this._transformDirty){
updateTransform();
};
Matrix3D.rotateAxis(transform, vector);
_tempMatrix = Matrix3D.rotationMatrix(vector.x, vector.y, vector.z, angle, _tempMatrix);
this.transform.calculateMultiply3x3(_tempMatrix, transform);
this._rotationDirty = true;
}
public function get scale():Number{
if ((((this._scaleX == this._scaleY)) && ((this._scaleX == this._scaleZ)))){
if (Papervision3D.usePERCENT){
return ((this._scaleX * 100));
};
return (this._scaleX);
//unresolved jump
};
return (NaN);
}
public function get sceneX():Number{
return (this.world.n14);
}
public function get sceneY():Number{
return (this.world.n24);
}
public function get scaleX():Number{
if (Papervision3D.usePERCENT){
return ((this._scaleX * 100));
};
return (this._scaleX);
}
public function get scaleY():Number{
if (Papervision3D.usePERCENT){
return ((this._scaleY * 100));
};
return (this._scaleY);
}
public function get scaleZ():Number{
if (Papervision3D.usePERCENT){
return ((this._scaleZ * 100));
};
return (this._scaleZ);
}
public function moveUp(distance:Number):void{
translate(distance, UP);
}
public function get sceneZ():Number{
return (this.world.n34);
}
public function distanceTo(obj:DisplayObject3D):Number{
var x:Number = (this.x - obj.x);
var y:Number = (this.y - obj.y);
var z:Number = (this.z - obj.z);
return (Math.sqrt((((x * x) + (y * y)) + (z * z))));
}
public function set material(material:MaterialObject3D):void{
if (_material){
_material.unregisterObject(this);
};
_material = material;
_material.registerObject(this);
}
public function hitTestObject(obj:DisplayObject3D, multiplier:Number=1):Boolean{
var dx:Number = (this.x - obj.x);
var dy:Number = (this.y - obj.y);
var dz:Number = (this.z - obj.z);
var d2:Number = (((dx * dx) + (dy * dy)) + (dz * dz));
var sA:Number = (this.geometry) ? this.geometry.boundingSphere2 : 0;
var sB:Number = (obj.geometry) ? obj.geometry.boundingSphere2 : 0;
sA = (sA * multiplier);
return (((sA + sB) > d2));
}
public function translate(distance:Number, axis:Number3D):void{
var vector:Number3D = axis.clone();
if (this._transformDirty){
updateTransform();
};
Matrix3D.rotateAxis(transform, vector);
this.x = (this.x + (distance * vector.x));
this.y = (this.y + (distance * vector.y));
this.z = (this.z + (distance * vector.z));
}
private function updateRotation():void{
_rotation = Matrix3D.matrix2euler(this.transform, _rotation);
this._rotationX = (_rotation.x * toRADIANS);
this._rotationY = (_rotation.y * toRADIANS);
this._rotationZ = (_rotation.z * toRADIANS);
this._rotationDirty = false;
}
public function yaw(angle:Number):void{
angle = (Papervision3D.useDEGREES) ? (angle * toRADIANS) : angle;
var vector:Number3D = UP.clone();
if (this._transformDirty){
updateTransform();
};
Matrix3D.rotateAxis(transform, vector);
_tempMatrix = Matrix3D.rotationMatrix(vector.x, vector.y, vector.z, angle, _tempMatrix);
this.transform.calculateMultiply3x3(_tempMatrix, transform);
this._rotationDirty = true;
}
override public function toString():String{
return (((((((this.name + ": x:") + Math.round(this.x)) + " y:") + Math.round(this.y)) + " z:") + Math.round(this.z)));
}
public function copyTransform(reference):void{
var trans:Matrix3D = this.transform;
var matrix:Matrix3D = ((reference is DisplayObject3D)) ? reference.transform : reference;
trans.n11 = matrix.n11;
trans.n12 = matrix.n12;
trans.n13 = matrix.n13;
trans.n14 = matrix.n14;
trans.n21 = matrix.n21;
trans.n22 = matrix.n22;
trans.n23 = matrix.n23;
trans.n24 = matrix.n24;
trans.n31 = matrix.n31;
trans.n32 = matrix.n32;
trans.n33 = matrix.n33;
trans.n34 = matrix.n34;
this._transformDirty = false;
this._rotationDirty = true;
}
public function moveLeft(distance:Number):void{
translate(distance, LEFT);
}
public function get y():Number{
return (this.transform.n24);
}
public function get z():Number{
return (this.transform.n34);
}
public function roll(angle:Number):void{
angle = (Papervision3D.useDEGREES) ? (angle * toRADIANS) : angle;
var vector:Number3D = FORWARD.clone();
if (this._transformDirty){
updateTransform();
};
Matrix3D.rotateAxis(transform, vector);
_tempMatrix = Matrix3D.rotationMatrix(vector.x, vector.y, vector.z, angle, _tempMatrix);
this.transform.calculateMultiply3x3(_tempMatrix, transform);
this._rotationDirty = true;
}
public function get x():Number{
return (this.transform.n14);
}
public function getMaterialByName(name:String):MaterialObject3D{
var child:DisplayObject3D;
var material:MaterialObject3D = this.materials.getMaterialByName(name);
if (material){
return (material);
};
for each (child in this._childrenByName) {
material = child.getMaterialByName(name);
if (material){
return (material);
};
};
return (null);
}
public function get scene():SceneObject3D{
return (_scene);
}
public function set scale(scale:Number):void{
if (Papervision3D.usePERCENT){
scale = (scale / 100);
};
this._scaleX = (this._scaleY = (this._scaleZ = scale));
this._transformDirty = true;
}
public function setRenderLayer(rlayer:RenderLayer):void{
var do3d:DisplayObject3D;
this.renderLayer = rlayer;
for each (do3d in this.children) {
do3d.setRenderLayer(rlayer);
};
}
public function get rotationX():Number{
if (this._rotationDirty){
updateRotation();
};
return ((Papervision3D.useDEGREES) ? (-(this._rotationX) * toDEGREES) : -(this._rotationX));
}
public function get rotationY():Number{
if (this._rotationDirty){
updateRotation();
};
return ((Papervision3D.useDEGREES) ? (-(this._rotationY) * toDEGREES) : -(this._rotationY));
}
public function set scaleX(scale:Number):void{
if (Papervision3D.usePERCENT){
this._scaleX = (scale / 100);
} else {
this._scaleX = scale;
};
this._transformDirty = true;
}
public function set scaleY(scale:Number):void{
if (Papervision3D.usePERCENT){
this._scaleY = (scale / 100);
} else {
this._scaleY = scale;
};
this._transformDirty = true;
}
public function set scaleZ(scale:Number):void{
if (Papervision3D.usePERCENT){
this._scaleZ = (scale / 100);
} else {
this._scaleZ = scale;
};
this._transformDirty = true;
}
public function get rotationZ():Number{
if (this._rotationDirty){
updateRotation();
};
return ((Papervision3D.useDEGREES) ? (-(this._rotationZ) * toDEGREES) : -(this._rotationZ));
}
public function updateTransform():void{
_tempQuat = Matrix3D.euler2quaternion(-(this._rotationY), -(this._rotationZ), this._rotationX, _tempQuat);
_tempMatrix = Matrix3D.quaternion2matrix(_tempQuat.x, _tempQuat.y, _tempQuat.z, _tempQuat.w, _tempMatrix);
var transform:Matrix3D = this.transform;
_tempMatrix.n14 = transform.n14;
_tempMatrix.n24 = transform.n24;
_tempMatrix.n34 = transform.n34;
transform.copy(_tempMatrix);
_tempMatrix.reset();
_tempMatrix.n11 = this._scaleX;
_tempMatrix.n22 = this._scaleY;
_tempMatrix.n33 = this._scaleZ;
this.transform.calculateMultiply(transform, _tempMatrix);
this._transformDirty = false;
}
public function moveForward(distance:Number):void{
translate(distance, FORWARD);
}
public function copyPosition(reference):void{
var trans:Matrix3D = this.transform;
var matrix:Matrix3D = ((reference is DisplayObject3D)) ? reference.transform : reference;
trans.n14 = matrix.n14;
trans.n24 = matrix.n24;
trans.n34 = matrix.n34;
}
public function hitTestPoint(x:Number, y:Number, z:Number):Boolean{
var dx:Number = (this.x - x);
var dy:Number = (this.y - y);
var dz:Number = (this.z - z);
var d2:Number = (((dx * dx) + (dy * dy)) + (dz * dz));
var sA:Number = (this.geometry) ? this.geometry.boundingSphere2 : 0;
return ((sA > d2));
}
public function moveRight(distance:Number):void{
translate(distance, RIGHT);
}
public function moveBackward(distance:Number):void{
translate(distance, BACKWARD);
}
public function materialsList():String{
var name:String;
var child:DisplayObject3D;
var list:String = "";
for (name in this.materials) {
list = (list + (name + "\n"));
};
for each (child in this._childrenByName) {
for (name in child.materials.materialsByName) {
list = (list + (("+ " + name) + "\n"));
};
};
return (list);
}
public function set x(value:Number):void{
this.transform.n14 = value;
}
public function set y(value:Number):void{
this.transform.n24 = value;
}
public function set z(value:Number):void{
this.transform.n34 = value;
}
override public function addChild(child:DisplayObject3D, name:String=null):DisplayObject3D{
child = super.addChild(child, name);
if (child.scene == null){
child.scene = scene;
};
return (child);
}
public static function get ZERO():DisplayObject3D{
return (new (DisplayObject3D));
}
}
}//package org.papervision3d.objects
Section 107
//BasicRenderEngine (org.papervision3d.render.BasicRenderEngine)
package org.papervision3d.render {
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.*;
import org.papervision3d.core.render.command.*;
import flash.geom.*;
import org.papervision3d.objects.*;
import org.papervision3d.events.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.render.material.*;
import org.papervision3d.core.layers.utils.*;
import org.papervision3d.core.render.*;
import org.papervision3d.core.render.sort.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.render.filter.*;
public class BasicRenderEngine extends AbstractRenderEngine implements IRenderEngine {
private var cleanRHD:RenderHitData;
public var sorter:IRenderSorter;
private var stopWatch:StopWatch;
private var renderSessionData:RenderSessionData;
public var filter:IRenderFilter;
private var renderStatistics:RenderStatistics;
private var renderList:Array;
public function BasicRenderEngine():void{
cleanRHD = new RenderHitData();
super();
init();
}
protected function doRender(renderSessionData:RenderSessionData):RenderStatistics{
var rc:IRenderListItem;
stopWatch.reset();
stopWatch.start();
MaterialManager.getInstance().updateMaterialsBeforeRender(renderSessionData);
filter.filter(renderList);
sorter.sort(renderList);
while ((rc = renderList.pop())) {
rc.render(renderSessionData);
renderSessionData.viewPort.lastRenderList.push(rc);
};
MaterialManager.getInstance().updateMaterialsAfterRender(renderSessionData);
renderSessionData.renderStatistics.renderTime = stopWatch.stop();
dispatchEvent(new RendererEvent(RendererEvent.RENDER_DONE, renderSessionData));
renderSessionData.viewPort.updateAfterRender();
return (renderStatistics);
}
override public function removeFromRenderList(renderCommand:IRenderListItem):int{
return (renderList.splice(renderList.indexOf(renderCommand), 1));
}
public function hitTestPoint2D(point:Point, viewPort3D:Viewport3D):RenderHitData{
return (viewPort3D.hitTestPoint2D(point));
}
protected function doProject(renderSessionData:RenderSessionData):void{
var p:DisplayObject3D;
stopWatch.reset();
stopWatch.start();
renderSessionData.camera.transformView();
var objects:Array = renderSessionData.scene.objects;
var i:Number = objects.length;
if ((renderSessionData.camera is IObjectCuller)){
for each (p in objects) {
if (p.visible){
if (renderSessionData.viewPort.viewportObjectFilter){
if (renderSessionData.viewPort.viewportObjectFilter.testObject(p)){
p.view.calculateMultiply4x4(renderSessionData.camera.eye, p.transform);
p.project(renderSessionData.camera, renderSessionData);
} else {
renderSessionData.renderStatistics.filteredObjects++;
};
} else {
p.view.calculateMultiply4x4(renderSessionData.camera.eye, p.transform);
p.project(renderSessionData.camera, renderSessionData);
};
};
};
} else {
for each (p in objects) {
if (p.visible){
if (renderSessionData.viewPort.viewportObjectFilter){
if (renderSessionData.viewPort.viewportObjectFilter.testObject(p)){
p.view.calculateMultiply(renderSessionData.camera.eye, p.transform);
p.project(renderSessionData.camera, renderSessionData);
} else {
renderSessionData.renderStatistics.filteredObjects++;
};
} else {
p.view.calculateMultiply(renderSessionData.camera.eye, p.transform);
p.project(renderSessionData.camera, renderSessionData);
};
};
};
};
renderSessionData.renderStatistics.projectionTime = stopWatch.stop();
}
protected function init():void{
renderStatistics = new RenderStatistics();
stopWatch = new StopWatch();
sorter = new BasicRenderSorter();
filter = new BasicRenderFilter();
renderList = new Array();
renderSessionData = new RenderSessionData();
renderSessionData.renderer = this;
}
override public function renderScene(scene:SceneObject3D, camera:CameraObject3D, viewPort:Viewport3D, updateAnimation:Boolean=true):RenderStatistics{
viewPort.updateBeforeRender();
viewPort.lastRenderer = this;
RenderLayerManager.getInstance().checkIndividualLayers(scene, viewPort);
if (scene.animationEngine){
scene.animationEngine.tick();
};
renderSessionData.scene = scene;
renderSessionData.camera = camera;
renderSessionData.viewPort = viewPort;
renderSessionData.container = viewPort.containerSprite;
renderSessionData.triangleCuller = viewPort.triangleCuller;
renderSessionData.particleCuller = viewPort.particleCuller;
renderSessionData.defaultRenderLayer = viewPort.renderLayerManager.defaultLayer;
renderSessionData.renderStatistics.clear();
doProject(renderSessionData);
doRender(renderSessionData);
return (renderSessionData.renderStatistics);
}
override public function addToRenderList(renderCommand:IRenderListItem):int{
return (renderList.push(renderCommand));
}
}
}//package org.papervision3d.render
Section 108
//Scene3D (org.papervision3d.scenes.Scene3D)
package org.papervision3d.scenes {
import org.papervision3d.core.proto.*;
import org.papervision3d.core.animation.core.*;
public class Scene3D extends SceneObject3D {
public function Scene3D(animated:Boolean=false){
super();
this.animated = animated;
if (animated){
this.animationEngine = AnimationEngine.getInstance();
};
}
}
}//package org.papervision3d.scenes
Section 109
//IViewport3D (org.papervision3d.view.IViewport3D)
package org.papervision3d.view {
public interface IViewport3D {
function updateAfterRender():void;
function updateBeforeRender():void;
}
}//package org.papervision3d.view
Section 110
//Viewport3D (org.papervision3d.view.Viewport3D)
package org.papervision3d.view {
import flash.events.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.render.command.*;
import flash.geom.*;
import flash.display.*;
import org.papervision3d.events.*;
import org.papervision3d.render.*;
import org.papervision3d.core.culling.*;
import org.papervision3d.core.layers.*;
import org.papervision3d.core.layers.utils.*;
import org.papervision3d.core.render.*;
import org.papervision3d.core.utils.*;
import flash.utils.*;
public class Viewport3D extends Sprite implements IViewport3D {
public var interactiveSceneManager:InteractiveSceneManager;
public var lastRenderList:Array;
public var containers:Dictionary;
public var cullingRectangle:Rectangle;
protected var _interactive:Boolean;
protected var _viewportObjectFilter:ViewportObjectFilter;
protected var _autoCulling:Boolean;
public var particleCuller:IParticleCuller;
protected var _height:Number;
protected var _width:Number;
protected var _autoScaleToStage:Boolean;
public var renderLayerManager:RenderLayerManager;
public var triangleCuller:ITriangleCuller;
protected var _lastRenderer:IRenderEngine;
protected var _hWidth:Number;
protected var _containerSprite:Sprite;
public var sizeRectangle:Rectangle;
protected var _hHeight:Number;
protected var _autoClipping:Boolean;
public function Viewport3D(viewportWidth:Number=640, viewportHeight:Number=480, autoScaleToStage:Boolean=false, interactive:Boolean=false, autoClipping:Boolean=true, autoCulling:Boolean=true){
super();
this.interactive = interactive;
init();
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
this.autoClipping = autoClipping;
this.autoCulling = autoCulling;
this.autoScaleToStage = autoScaleToStage;
}
protected function handleRenderDone(e:RendererEvent):void{
interactiveSceneManager.updateRenderHitData();
}
public function get autoCulling():Boolean{
return (_autoCulling);
}
public function set autoCulling(culling:Boolean):void{
if (culling){
triangleCuller = new RectangleTriangleCuller(cullingRectangle);
particleCuller = new RectangleParticleCuller(cullingRectangle);
} else {
if (!culling){
triangleCuller = new DefaultTriangleCuller();
particleCuller = new DefaultParticleCuller();
};
};
_autoCulling = culling;
}
public function set viewportWidth(width:Number):void{
_width = width;
_hWidth = (width / 2);
containerSprite.x = _hWidth;
sizeRectangle.width = width;
cullingRectangle.x = -(_hWidth);
cullingRectangle.width = width;
scrollRect = sizeRectangle;
}
public function updateAfterRender():void{
renderLayerManager.sortlayers(_containerSprite);
renderLayerManager.updateAfterRender();
}
protected function init():void{
containers = new Dictionary();
lastRenderList = new Array();
sizeRectangle = new Rectangle();
cullingRectangle = new Rectangle();
_containerSprite = new Sprite();
addChild(_containerSprite);
renderLayerManager = new RenderLayerManager();
var def:RenderLayer = new RenderLayer();
_containerSprite.addChild(def);
renderLayerManager.addDefaultLayer(def);
if (interactive){
interactiveSceneManager = new InteractiveSceneManager(this);
};
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
public function get autoClipping():Boolean{
return (_autoClipping);
}
public function addRenderLayer(layer:RenderLayer):void{
_containerSprite.addChild(layer);
renderLayerManager.addRenderLayer(layer);
}
protected function onAddedToStage(event:Event):void{
stage.addEventListener(Event.RESIZE, onStageResize);
onStageResize();
}
public function get containerSprite():Sprite{
return (_containerSprite);
}
public function set autoClipping(clip:Boolean):void{
if (clip){
scrollRect = sizeRectangle;
} else {
scrollRect = null;
};
_autoClipping = clip;
}
public function removeRenderLayer(layer:RenderLayer):void{
_containerSprite.removeChild(layer);
renderLayerManager.removeRenderLayer(layer);
}
public function get viewportWidth():Number{
return (_width);
}
public function set viewportObjectFilter(vof:ViewportObjectFilter):void{
_viewportObjectFilter = vof;
}
public function set interactive(b:Boolean):void{
_interactive = b;
}
public function set autoScaleToStage(scale:Boolean):void{
_autoScaleToStage = scale;
if (((scale) && (!((stage == null))))){
onStageResize();
};
}
public function set viewportHeight(height:Number):void{
_height = height;
_hHeight = (height / 2);
containerSprite.y = _hHeight;
sizeRectangle.height = height;
cullingRectangle.y = -(_hHeight);
cullingRectangle.height = height;
scrollRect = sizeRectangle;
}
public function updateBeforeRender():void{
renderLayerManager.resetLayers();
renderLayerManager.updateBeforeRender();
lastRenderList.length = 0;
_containerSprite.graphics.clear();
}
public function get interactive():Boolean{
return (_interactive);
}
public function hitTestPoint2D(point:Point):RenderHitData{
var rli:RenderableListItem;
var rhd:RenderHitData;
var rc:IRenderListItem;
var i:uint;
if (interactive){
rhd = new RenderHitData();
i = lastRenderList.length;
while ((rc = lastRenderList[--i])) {
if ((rc is RenderableListItem)){
rli = (rc as RenderableListItem);
rhd = rli.hitTestPoint2D(point, rhd);
if (rhd.hasHit){
return (rhd);
};
};
};
};
return (new RenderHitData());
}
public function get autoScaleToStage():Boolean{
return (_autoScaleToStage);
}
public function get viewportObjectFilter():ViewportObjectFilter{
return (_viewportObjectFilter);
}
public function get viewportHeight():Number{
return (_height);
}
public function set lastRenderer(value:BasicRenderEngine):void{
if (!interactive){
return;
};
value.removeEventListener(RendererEvent.RENDER_DONE, handleRenderDone);
value.addEventListener(RendererEvent.RENDER_DONE, handleRenderDone);
}
protected function onRemovedFromStage(event:Event):void{
stage.removeEventListener(Event.RESIZE, onStageResize);
}
public function hitTestMouse():RenderHitData{
var p:Point = new Point(containerSprite.mouseX, containerSprite.mouseY);
return (hitTestPoint2D(p));
}
protected function onStageResize(event:Event=null):void{
if (_autoScaleToStage){
viewportWidth = stage.stageWidth;
viewportHeight = stage.stageHeight;
};
}
}
}//package org.papervision3d.view
Section 111
//Papervision3D (org.papervision3d.Papervision3D)
package org.papervision3d {
public class Papervision3D {
public static var useDEGREES:Boolean = true;
public static var VERBOSE:Boolean = true;
public static var AUTHOR:String = "(c) 2006-2007 Copyright by Carlos Ulloa - | John Grden | Ralph Hauwert | Tim Knip";
public static var DATE:String = "21.11.07";
public static var NAME:String = "Papervision3D";
public static var VERSION:String = "Alpha 2.0 - Effects";
public static var usePERCENT:Boolean = false;
public function Papervision3D(){
super();
}
public static function log(message:String):void{
if (Papervision3D.VERBOSE){
trace(message);
};
}
}
}//package org.papervision3d
Section 112
//AnimatedNoise (AnimatedNoise)
package {
import flash.display.*;
public class AnimatedNoise extends BitmapData {
private var offsets:Array;
public var octaves:int;// = 6
public function AnimatedNoise(width:int, height:int, transparent:Boolean=true, fillColor:uint=4294967295){
super(width, height, transparent, fillColor);
initOffsets();
animateNoise();
}
private function initOffsets():void{
offsets = [];
var i:int;
while (i < octaves) {
offsets.push(new PointWave());
i++;
};
}
public function animateNoise():void{
var i:int;
while (i < octaves) {
PointWave(offsets[i]).update();
i++;
};
perlinNoise(width, height, octaves, 0, true, true, 7, false, offsets);
}
}
}//package
Section 113
//NoisePlane (NoisePlane)
package {
import flash.events.*;
import org.papervision3d.view.*;
import org.papervision3d.objects.*;
import org.papervision3d.core.geom.renderables.*;
import flash.display.*;
import org.papervision3d.render.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shaders.*;
import com.bnj.utils.*;
import org.papervision3d.scenes.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.lights.*;
import org.papervision3d.cameras.*;
import org.papervision3d.materials.shadematerials.*;
public class NoisePlane extends Sprite {
private var fullscreen:FullscreenButton;
private var renderer:BasicRenderEngine;
private var scene:Scene3D;
private var sphere:Sphere;
private var bumpMap:AnimatedNoise;
private var cameraTarget:DisplayObject3D;
private var orginalGeom:Array;
private var plane:Plane;
private var light:PointLight3D;
private var camera:FrustumCamera3D;
private var viewport:Viewport3D;
private var fps:FpsCounter;
private var noiseBitmapData:AnimatedNoise;
private var shader:PhongShader;
public function NoisePlane(){
super();
init();
}
private function hoverCamera():void{
var reach:Number = 0.01;
var ease:Number = 0.1;
var cameraDistance:Number = 700;
var targetX:Number = (Math.sin((mouseX * reach)) * cameraDistance);
var targetY:Number = (Math.sin((mouseY * reach)) * cameraDistance);
var targetZ:Number = (Math.cos((mouseX * reach)) * -(cameraDistance));
camera.x = (camera.x + ((targetX - camera.x) * ease));
camera.y = (camera.y + ((targetY - camera.y) * ease));
camera.z = (camera.z + ((targetZ - camera.z) * ease));
camera.lookAt(cameraTarget);
}
private function setupCamera():void{
camera = new FrustumCamera3D(viewport, 60, 1);
camera.z = -1000;
camera.y = 10;
}
private function onResize(e:Event):void{
fullscreen.x = (stage.stageWidth - fullscreen.width);
}
private function setupScene():void{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.quality = StageQuality.MEDIUM;
viewport = new Viewport3D(stage.stageWidth, stage.stageHeight, true, false, true, true);
addChildAt(viewport, 0);
renderer = new BasicRenderEngine();
scene = new Scene3D();
light = new PointLight3D();
light.scale = 5;
light.x = 500;
light.y = 500;
light.z = 0;
light.showLight = true;
}
private function init():void{
fullscreen = new FullscreenButton();
fullscreen.x = (stage.stageWidth - fullscreen.width);
addChild(fullscreen);
noiseBitmapData = new AnimatedNoise(21, 21);
cameraTarget = new DisplayObject3D();
setupScene();
setupPlane();
setupListeners();
setupCamera();
}
private function onRenderTick(e:Event):void{
noiseBitmapData.animateNoise();
shakeVertices();
hoverCamera();
bumpMap.animateNoise();
shader.bumpmap = bumpMap;
renderer.renderScene(scene, camera, viewport);
}
private function setupPlane():void{
var textureWidth = 128;
var textureHeight = 128;
bumpMap = new AnimatedNoise(textureWidth, textureHeight, false);
var bd:BitmapData = new BitmapData(textureWidth, textureHeight, false, 4294967295);
var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bd);
bitmapMaterial.smooth = true;
shader = new PhongShader(light, 52479, 1827, 0, bumpMap, bumpMap);
var testMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader);
testMaterial.doubleSided = true;
plane = new Plane(testMaterial, 600, 600, 20, 20);
plane.rotationX = -90;
plane.scale = 2;
scene.addChild(plane);
orginalGeom = [];
var i:int;
while (i < plane.geometry.vertices.length) {
orginalGeom.push(Vertex3D(plane.geometry.vertices[i]).clone());
i++;
};
shakeVertices();
}
private function setupListeners():void{
addEventListener(Event.ENTER_FRAME, onRenderTick);
stage.addEventListener(Event.RESIZE, onResize);
}
private function setupSphere():void{
var m:FlatShadeMaterial = new FlatShadeMaterial(light);
sphere = new Sphere(m, 50, 8, 6);
sphere.x = 800;
scene.addChild(sphere);
}
private function shakeVertices():void{
var arrayPosition:int;
var color24:uint;
var red:uint;
var green:uint;
var blue:uint;
var vertex:Vertex3D;
var vartexOriginal:Vertex3D;
var face:Triangle3D;
var iy:int;
var gridX:Number = plane.segmentsW;
var gridY:Number = plane.segmentsH;
var gridX1:Number = (gridX + 1);
var gridY1:Number = (gridY + 1);
var vertices:Array = plane.geometry.vertices;
var ix:int;
while (ix < gridX1) {
iy = 0;
while (iy < gridY1) {
color24 = noiseBitmapData.getPixel(ix, iy);
red = (color24 >> 16);
green = ((color24 >> 8) & 0xFF);
blue = (color24 & 0xFF);
arrayPosition = ((ix * gridY1) + iy);
vertex = Vertex3D(vertices[arrayPosition]);
vartexOriginal = Vertex3D(orginalGeom[arrayPosition]);
vertex.x = ((vartexOriginal.x + red) - 127);
vertex.y = ((vartexOriginal.y + green) - 127);
vertex.z = ((vartexOriginal.z + blue) - 127);
vertex.calculateNormal();
iy++;
};
ix++;
};
for each (face in plane.geometry.faces) {
face.createNormal();
};
}
}
}//package
Section 114
//PointWave (PointWave)
package {
import flash.geom.*;
public class PointWave extends Point {
public var speedX:Number;// = 1
public var speedY:Number;// = 1
public function PointWave(x:Number=0, y:Number=0){
speedX = (speedX * 0.1);
speedY = (speedY * 0.1);
super(x, y);
}
public function update():void{
x = (x + speedX);
y = (y + speedY);
}
}
}//package