UNPKG

awayjs-display

Version:
1,151 lines 1.08 MB
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ "use strict"; var adapters = require("./lib/adapters"); exports.adapters = adapters; var animators = require("./lib/animators"); exports.animators = animators; var base = require("./lib/base"); exports.base = base; var bounds = require("./lib/bounds"); exports.bounds = bounds; var controllers = require("./lib/controllers"); exports.controllers = controllers; var display = require("./lib/display"); exports.display = display; var draw = require("./lib/draw"); exports.draw = draw; var errors = require("./lib/errors"); exports.errors = errors; var events = require("./lib/events"); exports.events = events; var factories = require("./lib/factories"); exports.factories = factories; var graphics = require("./lib/graphics"); exports.graphics = graphics; var managers = require("./lib/managers"); exports.managers = managers; var materials = require("./lib/materials"); exports.materials = materials; var partition = require("./lib/partition"); exports.partition = partition; var pick = require("./lib/pick"); exports.pick = pick; var prefabs = require("./lib/prefabs"); exports.prefabs = prefabs; var text = require("./lib/text"); exports.text = text; var textures = require("./lib/textures"); exports.textures = textures; var utils = require("./lib/utils"); exports.utils = utils; var View_1 = require("./lib/View"); exports.View = View_1.View; partition.PartitionBase.registerAbstraction(partition.CameraNode, display.Camera); partition.PartitionBase.registerAbstraction(partition.DirectionalLightNode, display.DirectionalLight); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.Sprite); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.Shape); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.MovieClip); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.Billboard); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.LineSegment); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.TextField); partition.PartitionBase.registerAbstraction(partition.EntityNode, display.TextFieldMultiRender); partition.PartitionBase.registerAbstraction(partition.LightProbeNode, display.LightProbe); partition.PartitionBase.registerAbstraction(partition.PointLightNode, display.PointLight); partition.PartitionBase.registerAbstraction(partition.SkyboxNode, display.Skybox); },{"./lib/View":"awayjs-display/lib/View","./lib/adapters":"awayjs-display/lib/adapters","./lib/animators":"awayjs-display/lib/animators","./lib/base":"awayjs-display/lib/base","./lib/bounds":"awayjs-display/lib/bounds","./lib/controllers":"awayjs-display/lib/controllers","./lib/display":"awayjs-display/lib/display","./lib/draw":"awayjs-display/lib/draw","./lib/errors":"awayjs-display/lib/errors","./lib/events":"awayjs-display/lib/events","./lib/factories":"awayjs-display/lib/factories","./lib/graphics":"awayjs-display/lib/graphics","./lib/managers":"awayjs-display/lib/managers","./lib/materials":"awayjs-display/lib/materials","./lib/partition":"awayjs-display/lib/partition","./lib/pick":"awayjs-display/lib/pick","./lib/prefabs":"awayjs-display/lib/prefabs","./lib/text":"awayjs-display/lib/text","./lib/textures":"awayjs-display/lib/textures","./lib/utils":"awayjs-display/lib/utils"}],"awayjs-display/lib/IRenderer":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/ITraverser":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/View":[function(require,module,exports){ "use strict"; var getTimer_1 = require("awayjs-core/lib/utils/getTimer"); var TouchPoint_1 = require("./base/TouchPoint"); var Scene_1 = require("./display/Scene"); var RaycastPicker_1 = require("./pick/RaycastPicker"); var Camera_1 = require("./display/Camera"); var CameraEvent_1 = require("./events/CameraEvent"); var DisplayObjectEvent_1 = require("./events/DisplayObjectEvent"); var RendererEvent_1 = require("./events/RendererEvent"); var MouseManager_1 = require("./managers/MouseManager"); var View = (function () { /* *********************************************************************** * Disabled / Not yet implemented *********************************************************************** * * private _background:away.textures.Texture2DBase; * * public _pTouch3DManager:away.managers.Touch3DManager; * */ function View(renderer, scene, camera) { var _this = this; if (scene === void 0) { scene = null; } if (camera === void 0) { camera = null; } this._width = 0; this._height = 0; this._time = 0; this._deltaTime = 0; this._backgroundColor = 0x000000; this._backgroundAlpha = 1; this._viewportDirty = true; this._scissorDirty = true; this._mousePicker = new RaycastPicker_1.RaycastPicker(); this._pTouchPoints = new Array(); this._onPartitionChangedDelegate = function (event) { return _this._onPartitionChanged(event); }; this._onProjectionChangedDelegate = function (event) { return _this._onProjectionChanged(event); }; this._onViewportUpdatedDelegate = function (event) { return _this._onViewportUpdated(event); }; this._onScissorUpdatedDelegate = function (event) { return _this._onScissorUpdated(event); }; this.scene = scene || new Scene_1.Scene(); this.camera = camera || new Camera_1.Camera(); this.renderer = renderer; //make sure document border is zero if (document) { document.body.style.margin = "0px"; this._htmlElement = document.createElement("div"); this._htmlElement.style.position = "absolute"; document.body.appendChild(this._htmlElement); } this._mouseManager = MouseManager_1.MouseManager.getInstance(); this._mouseManager.registerView(this); // if (this._shareContext) // this._mouse3DManager.addViewLayer(this); } Object.defineProperty(View.prototype, "mouseX", { get: function () { return this._pMouseX; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "mouseY", { get: function () { return this._pMouseY; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "touchPoints", { get: function () { return this._pTouchPoints; }, enumerable: true, configurable: true }); View.prototype.getLocalMouseX = function (displayObject) { return displayObject.inverseSceneTransform.transformVector(this.unproject(this._pMouseX, this._pMouseY, 1000)).x; }; View.prototype.getLocalMouseY = function (displayObject) { return displayObject.inverseSceneTransform.transformVector(this.unproject(this._pMouseX, this._pMouseY, 1000)).y; }; View.prototype.getLocalTouchPoints = function (displayObject) { var localPosition; var localTouchPoints = new Array(); var len = this._pTouchPoints.length; for (var i = 0; i < len; i++) { localPosition = displayObject.inverseSceneTransform.transformVector(this.unproject(this._pTouchPoints[i].x, this._pTouchPoints[i].y, 1000)); localTouchPoints.push(new TouchPoint_1.TouchPoint(localPosition.x, localPosition.y, this._pTouchPoints[i].id)); } return localTouchPoints; }; Object.defineProperty(View.prototype, "htmlElement", { /** * */ get: function () { return this._htmlElement; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "renderer", { /** * */ get: function () { return this._pRenderer; }, set: function (value) { if (this._pRenderer == value) return; if (this._pRenderer) { this._pRenderer.dispose(); this._pRenderer.removeEventListener(RendererEvent_1.RendererEvent.VIEWPORT_UPDATED, this._onViewportUpdatedDelegate); this._pRenderer.removeEventListener(RendererEvent_1.RendererEvent.SCISSOR_UPDATED, this._onScissorUpdatedDelegate); } this._pRenderer = value; this._pRenderer.addEventListener(RendererEvent_1.RendererEvent.VIEWPORT_UPDATED, this._onViewportUpdatedDelegate); this._pRenderer.addEventListener(RendererEvent_1.RendererEvent.SCISSOR_UPDATED, this._onScissorUpdatedDelegate); //reset back buffer this._pRenderer._iBackgroundR = ((this._backgroundColor >> 16) & 0xff) / 0xff; this._pRenderer._iBackgroundG = ((this._backgroundColor >> 8) & 0xff) / 0xff; this._pRenderer._iBackgroundB = (this._backgroundColor & 0xff) / 0xff; this._pRenderer._iBackgroundAlpha = this._backgroundAlpha; this._pRenderer.width = this._width; this._pRenderer.height = this._height; this._pRenderer.shareContext = this._shareContext; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "shareContext", { /** * */ get: function () { return this._shareContext; }, set: function (value) { if (this._shareContext == value) return; this._shareContext = value; if (this._pRenderer) this._pRenderer.shareContext = this._shareContext; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "backgroundColor", { /** * */ get: function () { return this._backgroundColor; }, set: function (value) { if (this._backgroundColor == value) return; this._backgroundColor = value; this._pRenderer._iBackgroundR = ((value >> 16) & 0xff) / 0xff; this._pRenderer._iBackgroundG = ((value >> 8) & 0xff) / 0xff; this._pRenderer._iBackgroundB = (value & 0xff) / 0xff; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "backgroundAlpha", { /** * * @returns {number} */ get: function () { return this._backgroundAlpha; }, /** * * @param value */ set: function (value) { if (value > 1) value = 1; else if (value < 0) value = 0; if (this._backgroundAlpha == value) return; this._pRenderer._iBackgroundAlpha = this._backgroundAlpha = value; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "camera", { /** * * @returns {Camera3D} */ get: function () { return this._pCamera; }, /** * Set camera that's used to render the scene for this viewport */ set: function (value) { if (this._pCamera == value) return; if (this._pCamera) this._pCamera.removeEventListener(CameraEvent_1.CameraEvent.PROJECTION_CHANGED, this._onProjectionChangedDelegate); this._pCamera = value; if (this._pScene) this._pScene.partition._iRegisterEntity(this._pCamera); this._pCamera.addEventListener(CameraEvent_1.CameraEvent.PROJECTION_CHANGED, this._onProjectionChangedDelegate); this._scissorDirty = true; this._viewportDirty = true; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "scene", { /** * * @returns {away.containers.Scene3D} */ get: function () { return this._pScene; }, /** * Set the scene that's used to render for this viewport */ set: function (value) { if (this._pScene == value) return; if (this._pScene) this._pScene.removeEventListener(DisplayObjectEvent_1.DisplayObjectEvent.PARTITION_CHANGED, this._onPartitionChangedDelegate); this._pScene = value; this._pScene.addEventListener(DisplayObjectEvent_1.DisplayObjectEvent.PARTITION_CHANGED, this._onPartitionChangedDelegate); if (this._pCamera) this._pScene.partition._iRegisterEntity(this._pCamera); }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "deltaTime", { /** * * @returns {number} */ get: function () { return this._deltaTime; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "width", { /** * */ get: function () { return this._width; }, set: function (value) { if (this._width == value) return; this._width = value; this._aspectRatio = this._width / this._height; this._pCamera.projection._iAspectRatio = this._aspectRatio; this._pRenderer.width = value; if (this._htmlElement) { this._htmlElement.style.width = value + "px"; } }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "height", { /** * */ get: function () { return this._height; }, set: function (value) { if (this._height == value) return; this._height = value; this._aspectRatio = this._width / this._height; this._pCamera.projection._iAspectRatio = this._aspectRatio; this._pRenderer.height = value; if (this._htmlElement) { this._htmlElement.style.height = value + "px"; } }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "mousePicker", { /** * */ get: function () { return this._mousePicker; }, set: function (value) { if (this._mousePicker == value) return; if (value == null) this._mousePicker = new RaycastPicker_1.RaycastPicker(); else this._mousePicker = value; }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "x", { /** * */ get: function () { return this._pRenderer.x; }, set: function (value) { if (this._pRenderer.x == value) return; this._pRenderer.x == value; if (this._htmlElement) { this._htmlElement.style.left = value + "px"; } }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "y", { /** * */ get: function () { return this._pRenderer.y; }, set: function (value) { if (this._pRenderer.y == value) return; this._pRenderer.y == value; if (this._htmlElement) { this._htmlElement.style.top = value + "px"; } }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "visible", { /** * */ get: function () { return (this._htmlElement && this._htmlElement.style.visibility == "visible"); }, set: function (value) { if (this._htmlElement) { this._htmlElement.style.visibility = value ? "visible" : "hidden"; } //TODO transfer visible property to associated context (if one exists) }, enumerable: true, configurable: true }); Object.defineProperty(View.prototype, "renderedFacesCount", { /** * * @returns {number} */ get: function () { return 0; //TODO //return this._pEntityCollector._pNumTriangles;//numTriangles; }, enumerable: true, configurable: true }); /** * Renders the view. */ View.prototype.render = function () { this.pUpdateTime(); //update view and size data this._pCamera.projection._iAspectRatio = this._aspectRatio; if (this._scissorDirty) { this._scissorDirty = false; this._pCamera.projection._iUpdateScissorRect(this._pRenderer.scissorRect.x, this._pRenderer.scissorRect.y, this._pRenderer.scissorRect.width, this._pRenderer.scissorRect.height); } if (this._viewportDirty) { this._viewportDirty = false; this._pCamera.projection._iUpdateViewport(this._pRenderer.viewPort.x, this._pRenderer.viewPort.y, this._pRenderer.viewPort.width, this._pRenderer.viewPort.height); } // update picking if (!this._shareContext) { if (this.forceMouseMove && this._htmlElement == this._mouseManager._iActiveDiv && !this._mouseManager._iUpdateDirty) this._mouseManager._iCollision = this.mousePicker.getViewCollision(this._pMouseX, this._pMouseY, this); this._mouseManager.fireMouseEvents(this.forceMouseMove); } //_touch3DManager.updateCollider(); //render the contents of the scene this._pRenderer.render(this._pCamera, this._pScene); }; /** * */ View.prototype.pUpdateTime = function () { var time = getTimer_1.getTimer(); if (this._time == 0) this._time = time; this._deltaTime = time - this._time; this._time = time; }; /** * */ View.prototype.dispose = function () { this._pRenderer.dispose(); // TODO: imeplement mouseManager / touch3DManager this._mouseManager.unregisterView(this); //this._touch3DManager.disableTouchListeners(this); //this._touch3DManager.dispose(); this._mouseManager = null; //this._touch3DManager = null; this._pRenderer = null; }; /** * * @param e */ View.prototype._onPartitionChanged = function (event) { if (this._pCamera) this._pScene.partition._iRegisterEntity(this._pCamera); }; /** * */ View.prototype._onProjectionChanged = function (event) { this._scissorDirty = true; this._viewportDirty = true; }; /** * */ View.prototype._onViewportUpdated = function (event) { this._viewportDirty = true; }; /** * */ View.prototype._onScissorUpdated = function (event) { this._scissorDirty = true; }; View.prototype.project = function (point3d) { var v = this._pCamera.project(point3d); v.x = v.x * this._pRenderer.viewPort.width / 2 + this._width * this._pCamera.projection.originX; v.y = v.y * this._pRenderer.viewPort.height / 2 + this._height * this._pCamera.projection.originY; return v; }; View.prototype.unproject = function (sX, sY, sZ) { return this._pCamera.unproject(2 * (sX - this._width * this._pCamera.projection.originX) / this._pRenderer.viewPort.width, 2 * (sY - this._height * this._pCamera.projection.originY) / this._pRenderer.viewPort.height, sZ); }; View.prototype.getRay = function (sX, sY, sZ) { return this._pCamera.getRay((sX * 2 - this._width) / this._width, (sY * 2 - this._height) / this._height, sZ); }; /*TODO: implement Background public get background():away.textures.Texture2DBase { return this._background; } */ /*TODO: implement Background public set background( value:away.textures.Texture2DBase ) { this._background = value; this._renderer.background = _background; } */ // TODO: required dependency stageGL View.prototype.updateCollider = function () { if (!this._shareContext) { if (this._htmlElement == this._mouseManager._iActiveDiv) this._mouseManager._iCollision = this.mousePicker.getViewCollision(this._pMouseX, this._pMouseY, this); } else { var collidingObject = this.mousePicker.getViewCollision(this._pMouseX, this._pMouseY, this); if (this.layeredView || this._mouseManager._iCollision == null || collidingObject.rayEntryDistance < this._mouseManager._iCollision.rayEntryDistance) this._mouseManager._iCollision = collidingObject; } }; return View; }()); exports.View = View; },{"./base/TouchPoint":"awayjs-display/lib/base/TouchPoint","./display/Camera":"awayjs-display/lib/display/Camera","./display/Scene":"awayjs-display/lib/display/Scene","./events/CameraEvent":"awayjs-display/lib/events/CameraEvent","./events/DisplayObjectEvent":"awayjs-display/lib/events/DisplayObjectEvent","./events/RendererEvent":"awayjs-display/lib/events/RendererEvent","./managers/MouseManager":"awayjs-display/lib/managers/MouseManager","./pick/RaycastPicker":"awayjs-display/lib/pick/RaycastPicker","awayjs-core/lib/utils/getTimer":undefined}],"awayjs-display/lib/adapters/IDisplayObjectAdapter":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/adapters/IMovieClipAdapter":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/adapters":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/animators/IAnimationSet":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/animators/IAnimator":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/animators/data/ParticleData":[function(require,module,exports){ "use strict"; var ParticleData = (function () { function ParticleData() { } return ParticleData; }()); exports.ParticleData = ParticleData; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = ParticleData; },{}],"awayjs-display/lib/animators/nodes/AnimationNodeBase":[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var AssetBase_1 = require("awayjs-core/lib/library/AssetBase"); /** * Provides an abstract base class for nodes in an animation blend tree. */ var AnimationNodeBase = (function (_super) { __extends(AnimationNodeBase, _super); /** * Creates a new <code>AnimationNodeBase</code> object. */ function AnimationNodeBase() { _super.call(this); } Object.defineProperty(AnimationNodeBase.prototype, "stateClass", { get: function () { return this._pStateClass; }, enumerable: true, configurable: true }); /** * @inheritDoc */ AnimationNodeBase.prototype.dispose = function () { }; Object.defineProperty(AnimationNodeBase.prototype, "assetType", { /** * @inheritDoc */ get: function () { return AnimationNodeBase.assetType; }, enumerable: true, configurable: true }); AnimationNodeBase.assetType = "[asset AnimationNodeBase]"; return AnimationNodeBase; }(AssetBase_1.AssetBase)); exports.AnimationNodeBase = AnimationNodeBase; },{"awayjs-core/lib/library/AssetBase":undefined}],"awayjs-display/lib/animators":[function(require,module,exports){ "use strict"; var ParticleData_1 = require("./animators/data/ParticleData"); exports.ParticleData = ParticleData_1.ParticleData; var AnimationNodeBase_1 = require("./animators/nodes/AnimationNodeBase"); exports.AnimationNodeBase = AnimationNodeBase_1.AnimationNodeBase; },{"./animators/data/ParticleData":"awayjs-display/lib/animators/data/ParticleData","./animators/nodes/AnimationNodeBase":"awayjs-display/lib/animators/nodes/AnimationNodeBase"}],"awayjs-display/lib/base/AlignmentMode":[function(require,module,exports){ "use strict"; /** * */ var AlignmentMode = (function () { function AlignmentMode() { } /** * */ AlignmentMode.REGISTRATION_POINT = "registrationPoint"; /** * */ AlignmentMode.PIVOT_POINT = "pivot"; return AlignmentMode; }()); exports.AlignmentMode = AlignmentMode; },{}],"awayjs-display/lib/base/HierarchicalProperties":[function(require,module,exports){ "use strict"; /** * */ var HierarchicalProperties = (function () { function HierarchicalProperties() { } /** * */ HierarchicalProperties.MOUSE_ENABLED = 1; /** * */ HierarchicalProperties.VISIBLE = 2; /** * */ HierarchicalProperties.MASK_ID = 4; /** * */ HierarchicalProperties.MASKS = 8; /** * */ HierarchicalProperties.COLOR_TRANSFORM = 16; /** * */ HierarchicalProperties.SCENE_TRANSFORM = 32; /** * */ HierarchicalProperties.ALL = 63; return HierarchicalProperties; }()); exports.HierarchicalProperties = HierarchicalProperties; },{}],"awayjs-display/lib/base/IBitmapDrawable":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/base/IRenderable":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/base/ISurface":[function(require,module,exports){ "use strict"; },{}],"awayjs-display/lib/base/OrientationMode":[function(require,module,exports){ "use strict"; var OrientationMode = (function () { function OrientationMode() { } /** * */ OrientationMode.DEFAULT = "default"; /** * */ OrientationMode.CAMERA_PLANE = "cameraPlane"; /** * */ OrientationMode.CAMERA_POSITION = "cameraPosition"; return OrientationMode; }()); exports.OrientationMode = OrientationMode; },{}],"awayjs-display/lib/base/Style":[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var EventDispatcher_1 = require("awayjs-core/lib/events/EventDispatcher"); var StyleEvent_1 = require("../events/StyleEvent"); /** * */ var Style = (function (_super) { __extends(Style, _super); function Style() { _super.call(this); this._samplers = new Object(); this._images = new Object(); this._color = 0xFFFFFF; } Object.defineProperty(Style.prototype, "sampler", { get: function () { return this._sampler; }, set: function (value) { if (this._sampler == value) return; this._sampler = value; this._invalidateProperties(); }, enumerable: true, configurable: true }); Object.defineProperty(Style.prototype, "image", { get: function () { return this._image; }, set: function (value) { if (this._image == value) return; this._image = value; this._invalidateProperties(); }, enumerable: true, configurable: true }); Object.defineProperty(Style.prototype, "uvMatrix", { get: function () { return this._uvMatrix; }, set: function (value) { if (this._uvMatrix == value) return; this._uvMatrix = value; this._invalidateProperties(); }, enumerable: true, configurable: true }); Object.defineProperty(Style.prototype, "color", { /** * The diffuse reflectivity color of the surface. */ get: function () { return this._color; }, set: function (value) { if (this._color == value) return; this._color = value; this._invalidateProperties(); }, enumerable: true, configurable: true }); Style.prototype.getImageAt = function (texture, index) { if (index === void 0) { index = 0; } return (this._images[texture.id] ? this._images[texture.id][index] : null) || this._image; }; Style.prototype.getSamplerAt = function (texture, index) { if (index === void 0) { index = 0; } return (this._samplers[texture.id] ? this._samplers[texture.id][index] : null) || this._sampler; }; Style.prototype.addImageAt = function (image, texture, index) { if (index === void 0) { index = 0; } if (!this._images[texture.id]) this._images[texture.id] = new Array(); this._images[texture.id][index] = image; }; Style.prototype.addSamplerAt = function (sampler, texture, index) { if (index === void 0) { index = 0; } if (!this._samplers[texture.id]) this._samplers[texture.id] = new Array(); this._samplers[texture.id][index] = sampler; this._invalidateProperties(); }; Style.prototype.removeImageAt = function (texture, index) { if (index === void 0) { index = 0; } if (!this._images[texture.id]) return; this._images[texture.id][index] = null; this._invalidateProperties(); }; Style.prototype.removeSamplerAt = function (texture, index) { if (index === void 0) { index = 0; } if (!this._samplers[texture.id]) return; this._samplers[texture.id][index] = null; this._invalidateProperties(); }; Style.prototype._invalidateProperties = function () { this.dispatchEvent(new StyleEvent_1.StyleEvent(StyleEvent_1.StyleEvent.INVALIDATE_PROPERTIES, this)); }; return Style; }(EventDispatcher_1.EventDispatcher)); exports.Style = Style; },{"../events/StyleEvent":"awayjs-display/lib/events/StyleEvent","awayjs-core/lib/events/EventDispatcher":undefined}],"awayjs-display/lib/base/Timeline":[function(require,module,exports){ "use strict"; var HierarchicalProperties_1 = require("../base/HierarchicalProperties"); var ColorTransform_1 = require("awayjs-core/lib/geom/ColorTransform"); var FrameScriptManager_1 = require("../managers/FrameScriptManager"); var Timeline = (function () { function Timeline() { this._functions = []; this._update_indices = []; this.numKeyFrames = 0; this.keyframe_indices = []; this._potentialPrototypes = []; this._labels = {}; this._framescripts = {}; this._framescripts_translated = {}; //cache functions this._functions[1] = this.update_mtx_all; this._functions[2] = this.update_colortransform; this._functions[3] = this.update_masks; this._functions[4] = this.update_name; this._functions[5] = this.update_button_name; this._functions[6] = this.update_visibility; this._functions[7] = this.update_blendmode; this._functions[8] = this.update_rendermode; this._functions[11] = this.update_mtx_scale_rot; this._functions[12] = this.update_mtx_pos; this._functions[200] = this.enable_maskmode; this._functions[201] = this.remove_masks; } Timeline.prototype.init = function () { if ((this.frame_command_indices == null) || (this.frame_recipe == null) || (this.keyframe_durations == null)) return; this.keyframe_firstframes = []; this.keyframe_constructframes = []; var frame_cnt = 0; var ic = 0; var ic2 = 0; var keyframe_cnt = 0; var last_construct_frame = 0; for (ic = 0; ic < this.numKeyFrames; ic++) { var duration = this.keyframe_durations[(ic)]; if (this.frame_recipe[ic] & 1) last_construct_frame = keyframe_cnt; this.keyframe_firstframes[keyframe_cnt] = frame_cnt; this.keyframe_constructframes[keyframe_cnt++] = last_construct_frame; for (ic2 = 0; ic2 < duration; ic2++) this.keyframe_indices[frame_cnt++] = ic; } }; Timeline.prototype.get_framescript = function (keyframe_index) { if (this._framescripts[keyframe_index] == null) return ""; if (typeof this._framescripts[keyframe_index] == "string") return this._framescripts[keyframe_index]; else { throw new Error("Framescript is already translated to Function!!!"); } }; Timeline.prototype.add_framescript = function (value, keyframe_index) { if (FrameScriptManager_1.FrameScriptManager.frameScriptDebug) { // if we are in debug mode, we try to extract the function name from the first line of framescript code, // and check if this function is available on the object that is set as frameScriptDebug // try to get the functions name (it should be the first line as comment) var functionname = value.split(/[\r\n]+/g)[0].split("//")[1]; if (FrameScriptManager_1.FrameScriptManager.frameScriptDebug[functionname]) { this._framescripts[keyframe_index] = FrameScriptManager_1.FrameScriptManager.frameScriptDebug[functionname]; this._framescripts_translated[keyframe_index] = true; return; } else { throw new Error("Framescript could not be found on FrameScriptManager.frameScriptDebug.\n the Object set as FrameScriptmanager.frameScriptDebug should contain a function with the name '" + functionname + "' !!!"); } } this._framescripts[keyframe_index] = value; }; Timeline.prototype.regexIndexOf = function (str, regex, startpos) { var indexOf = str.substring(startpos || 0).search(regex); return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf; }; Timeline.prototype.add_script_for_postcontruct = function (target_mc, keyframe_idx, scriptPass1) { if (scriptPass1 === void 0) { scriptPass1 = false; } if (this._framescripts[keyframe_idx] != null) { if (this._framescripts_translated[keyframe_idx] == null) { this._framescripts[keyframe_idx] = target_mc.adapter.evalScript(this._framescripts[keyframe_idx]); this._framescripts_translated[keyframe_idx] = true; } if (scriptPass1) FrameScriptManager_1.FrameScriptManager.add_script_to_queue(target_mc, this._framescripts[keyframe_idx]); else FrameScriptManager_1.FrameScriptManager.add_script_to_queue_pass2(target_mc, this._framescripts[keyframe_idx]); } }; Object.defineProperty(Timeline.prototype, "numFrames", { get: function () { return this.keyframe_indices.length; }, enumerable: true, configurable: true }); Timeline.prototype.getPotentialChildPrototype = function (id) { return this._potentialPrototypes[id]; }; Timeline.prototype.getKeyframeIndexForFrameIndex = function (frame_index) { return this.keyframe_indices[frame_index]; }; Timeline.prototype.getPotentialChildInstance = function (id) { var this_clone = this._potentialPrototypes[id].clone(); this_clone.name = ""; return this_clone; }; Timeline.prototype.registerPotentialChild = function (prototype) { var id = this._potentialPrototypes.length; this._potentialPrototypes[id] = prototype; }; Timeline.prototype.jumpToLabel = function (target_mc, label) { var key_frame_index = this._labels[label]; if (key_frame_index >= 0) target_mc.currentFrameIndex = this.keyframe_firstframes[key_frame_index]; }; Timeline.prototype.gotoFrame = function (target_mc, value, skip_script) { if (skip_script === void 0) { skip_script = false; } var current_keyframe_idx = target_mc.constructedKeyFrameIndex; var target_keyframe_idx = this.keyframe_indices[value]; if (current_keyframe_idx == target_keyframe_idx) return; if (current_keyframe_idx + 1 == target_keyframe_idx) { this.constructNextFrame(target_mc, !skip_script, true); return; } var break_frame_idx = this.keyframe_constructframes[target_keyframe_idx]; //we now have 3 index to keyframes: current_keyframe_idx / target_keyframe_idx / break_frame_idx var jump_forward = (target_keyframe_idx > current_keyframe_idx); var jump_gap = (break_frame_idx > current_keyframe_idx); // in case we jump forward, but not jump a gap, we start at current_keyframe_idx + 1 // in case we jump back or we jump a gap, we want to start constructing at BreakFrame var start_construct_idx = (jump_forward && !jump_gap) ? current_keyframe_idx + 1 : break_frame_idx; var i; var k; if (jump_gap) for (i = target_mc.numChildren - 1; i >= 0; i--) if (target_mc._children[i]._depthID < 0) target_mc.removeChildAt(i); //if we jump back, we want to reset all objects (but not the timelines of the mcs) if (!jump_forward) target_mc.resetSessionIDs(); // in other cases, we want to collect the current objects to compare state of targetframe with state of currentframe var depth_sessionIDs = target_mc.getSessionIDDepths(); //pass1: only apply add/remove commands into depth_sessionIDs. this.pass1(start_construct_idx, target_keyframe_idx, depth_sessionIDs); // check what childs are alive on both frames. // childs that are not alive anymore get removed and unregistered // childs that are alive on both frames have their properties reset if we are jumping back var child; for (i = target_mc.numChildren - 1; i >= 0; i--) { child = target_mc._children[i]; if (child._depthID < 0) { if (depth_sessionIDs[child._depthID] != child._sessionID) { target_mc.removeChildAt(i); } else if (!jump_forward) { if (child.adapter) { if (!child.adapter.isBlockedByScript()) { child.transform.clearMatrix3D(); child.transform.clearColorTransform(); //this.name=""; child.masks = null; child.maskMode = false; } if (!child.adapter.isVisibilityByScript()) { child.visible = true; } } } } } // now we need to addchild the objects that were added before targetframe first // than we can add the script of the targetframe // than we can addchild objects added on targetframe for (var key in depth_sessionIDs) { child = target_mc.getPotentialChildInstance(this.add_child_stream[depth_sessionIDs[key] * 2]); if (child._sessionID == -1) target_mc._addTimelineChildAt(child, Number(key), depth_sessionIDs[key]); } if (!skip_script && this.keyframe_firstframes[target_keyframe_idx] == value) this.add_script_for_postcontruct(target_mc, target_keyframe_idx, true); //pass2: apply update commands for objects on stage (only if they are not blocked by script) this.pass2(target_mc); target_mc.constructedKeyFrameIndex = target_keyframe_idx; }; Timeline.prototype.pass1 = function (start_construct_idx, target_keyframe_idx, depth_sessionIDs) { var i; var k; this._update_indices.length = 0; // store a list of updatecommand_indices, so we dont have to read frame_recipe again var update_cnt = 0; var start_index; var end_index; for (k = start_construct_idx; k <= target_keyframe_idx; k++) { var frame_command_idx = this.frame_command_indices[k]; var frame_recipe = this.frame_recipe[k]; if (frame_recipe & 2) { // remove childs start_index = this.command_index_stream[frame_command_idx]; end_index = start_index + this.command_length_stream[frame_command_idx++]; for (i = start_index; i < end_index; i++) delete depth_sessionIDs[this.remove_child_stream[i] - 16383]; } if (frame_recipe & 4) { start_index = this.command_index_stream[frame_command_idx]; end_index = start_index + this.command_length_stream[frame_command_idx++]; // apply add commands in reversed order to have script exeucted in correct order. // this could be changed in exporter for (i = end_index - 1; i >= start_index; i--) depth_sessionIDs[this.add_child_stream[i * 2 + 1] - 16383] = i; } if (frame_recipe & 8) this._update_indices[update_cnt++] = frame_command_idx; // execute update command later } }; Timeline.prototype.pass2 = function (target_mc) { var k; var len = this._update_indices.length; for (k = 0; k < len; k++) this.update_childs(target_mc, this._update_indices[k]); }; Timeline.prototype.constructNextFrame = function (target_mc, queueScript, scriptPass1) { if (queueScript === void 0) { queueScript = true; } if (scriptPass1 === void 0) { scriptPass1 = false; } var frameIndex = target_mc.currentFrameIndex; var new_keyFrameIndex = this.keyframe_indices[frameIndex]; if (queueScript && this.keyframe_firstframes[new_keyFrameIndex] == frameIndex) this.add_script_for_postcontruct(target_mc, new_keyFrameIndex, scriptPass1); if (target_mc.constructedKeyFrameIndex != new_keyFrameIndex) { target_mc.constructedKeyFrameIndex = new_keyFrameIndex; var frame_command_idx = this.frame_command_indices[new_keyFrameIndex]; var frame_recipe = this.frame_recipe[new_keyFrameIndex]; if (frame_recipe & 1) { for (var i = target_mc.numChildren - 1; i >= 0; i--) if (target_mc._children[i]._depthID < 0) target_mc.removeChildAt(i); } else if (frame_recipe & 2) { this.remove_childs_continous(target_mc, frame_command_idx++); } if (frame_recipe & 4) this.add_childs_continous(target_mc, frame_command_idx++); if (frame_recipe & 8) this.update_childs(target_mc, frame_command_idx++); } }; Timeline.prototype.remove_childs_continous = function (sourceMovieClip, frame_command_idx) { var start_index = this.command_index_stream[frame_command_idx]; var end_index = start_index + this.command_length_stream[frame_command_idx]; for (var i = start_index; i < end_index; i++) sourceMovieClip.removeChildAt(sourceMovieClip.getDepthIndexInternal(this.remove_child_stream[i] - 16383)); }; // used to add childs when jumping between frames Timeline.prototype.add_childs_continous = function (sourceMovieClip, frame_command_idx) { // apply add commands in reversed order to have script exeucted in correct order. // this could be changed in exporter var idx; var start_index = this.command_index_stream[frame_command_idx]; var end_index = start_index + this.command_length_stream[frame_command_idx]; for (var i = end_index - 1; i >= start_index; i--) { idx = i * 2; sourceMovieClip._addTimelineChildAt(sourceMovieClip.getPotentialChildInstance(this.add_child_stream[idx]), this.add_child_stream[idx + 1] - 16383, i); } }; Timeline.prototype.update_childs = function (target_mc, frame_command_idx) { var p; var props_start_idx; var props_end_index; var start_index = this.command_index_stream[frame_command_idx]; var end_index = start_index + this.command_length_stream[frame_command_idx]; var child; for (var i = start_index; i < end_index; i++) { child = target_mc.getChildAtSessionID(this.update_child_stream[i]); if (child) { // check if the child is active + not blocked by script this._blocked = Boolean(child.adapter && child.adapter.isBlockedByScript()); props_start_idx = this.update_child_props_indices_stream[i]; props_end_index = props_start_idx + this.update_child_props_length_stream[i]; for (p = props_start_idx; p < props_end_index; p++) this._functions[this.property_type_stream[p]].call(this, child, target_mc, this.property_index_stream[p]); } } }; Timeline.prototype.update_mtx_all = function (child, target_mc, i) { if (this._blocked) return; i *= 6; var new_matrix = child.transform.matrix3D; new_matrix.rawData[0] = this.properties_stream_f32_mtx_all[i++]; new_matrix.rawData[1] = this.properties_stream_f32_mtx_all[i++]; new_matrix.rawData[4] = this.properties_stream_f32_mtx_all[i++]; new_matrix.rawData[5] = this.properties_stream_f32_mtx_all[i++]; new_matrix.rawData[12] = this.properties_stream_f32_mtx_all[i++]; new_matrix.rawData[13] = this.properties_stream_f32_mtx_all[i]; child.transform.invalidateComponents(); }; Timeline.prototype.update_colortransform = function (child, target_mc, i) { if (this._blocked) return; i *= 8; var new_ct = child.transform.colorTransform || (child.transform.colorTransform = new ColorTransform_1.ColorTransform()); new_ct.rawData[0] = this.properties_stream_f32_ct[i++]; new_ct.rawData[1] = this.properties_stream_f32_ct[i++]; new_ct.rawData[2] = this.properties_stream_f32_ct[i++]; new_ct.rawData[3] = this.properties_stream_f32_ct[i++]; new_ct.rawData[4] = this.properties_stream_f32_ct[i++]; new_ct.rawData[5] = this.properties_stream_f32_ct[i++]; new_ct.rawData[6] = this.properties_stream_f32_ct[i++]; new_ct.rawData[7] = this.properties_stream_f32_ct[i]; child.transform.invalidateColorTransform(); }; Timeline.prototype.update_masks = function (child, target_mc, i) { // an object could have multiple groups of masks, in case a graphic clip was merged into the timeline // this is not implmeented in the runtime yet // for now, a second mask-groupd would overwrite the first one var mask; var masks = new Array(); var numMasks = this.properties_stream_int[i++]; //mask may not exist if a goto command moves the playhead to a point in the timeline after //one of the masks in a mask array has already been removed. Therefore a check is needed. for (var m = 0; m < numMasks; m++) if ((mask = target_mc.getChildAtSessionID(this.properties_stream_int[i++]))) masks.push(mask); child.masks = masks; }; Timeline.prototype.update_name = function (child, target_mc, i) { child.name = this.properties_stream_strings[i]; target_mc.adapter.registerScriptObject(ch