@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
1,574 lines (1,478 loc) • 18.9 MB
JavaScript
/**
* @license
* PlayCanvas Engine v1.78.0-animech revision e1c6c734d (DEBUG)
* Copyright 2011-2025 PlayCanvas Ltd. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pc = {}));
})(this, (function (exports) { 'use strict';
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
/**
* A short hand function to polyfill prototype methods which are not iterated in e.g. for-in loops.
*
* @param {ObjectConstructor} cls
* @param {string} name
* @param {Function} func
* @ignore
*/
function defineProtoFunc(cls, name, func) {
if (!cls.prototype[name]) {
Object.defineProperty(cls.prototype, name, {
value: func,
configurable: true,
enumerable: false,
writable: true
});
}
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill#polyfill
defineProtoFunc(Array, 'fill', function (value) {
// Steps 1-2.
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this);
// Steps 3-5.
var len = O.length >>> 0;
// Steps 6-7.
var start = arguments[1];
var relativeStart = start >> 0;
// Step 8.
var k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
// Steps 9-10.
var end = arguments[2];
var relativeEnd = end === undefined ? len : end >> 0;
// Step 11.
var finalValue = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
// Step 12.
while (k < finalValue) {
O[k] = value;
k++;
}
// Step 13.
return O;
});
// https://tc39.github.io/ecma262/#sec-array.prototype.find
defineProtoFunc(Array, 'find', function (predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
}
// e. Increase k by 1.
k++;
}
// 7. Return undefined.
return undefined;
});
// https://tc39.github.io/ecma262/#sec-array.prototype.findindex
defineProtoFunc(Array, 'findIndex', function (predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return k.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return k;
}
// e. Increase k by 1.
k++;
}
// 7. Return -1.
return -1;
});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2#Polyfill
Math.log2 = Math.log2 || function (x) {
return Math.log(x) * Math.LOG2E;
};
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign#Polyfill
if (!Math.sign) {
Math.sign = function (x) {
// If x is NaN, the result is NaN.
// If x is -0, the result is -0.
// If x is +0, the result is +0.
// If x is negative and not -0, the result is -1.
// If x is positive and not +0, the result is +1.
return (x > 0) - (x < 0) || +x;
// A more aesthetic pseudo-representation:
//
// ( (x > 0) ? 1 : 0 ) // if x is positive, then positive one
// + // else (because you can't be both - and +)
// ( (x < 0) ? -1 : 0 ) // if x is negative, then negative one
// || // if x is 0, -0, or NaN, or not a number,
// +x // then the result will be x, (or) if x is
// // not a number, then x converts to number
};
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite#polyfill
if (Number.isFinite === undefined) Number.isFinite = function (value) {
return typeof value === 'number' && isFinite(value);
};
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) {
// .length of function is 2
'use strict';
if (target == null) {
// TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
// Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries
// https://stackoverflow.com/questions/68654735/ie11-compatible-object-fromentries
Object.fromEntries = Object.fromEntries || function fromEntries(entries) {
if (!entries || !entries[Symbol.iterator]) {
throw new Error('Object.fromEntries() requires a single iterable argument');
}
var res = {};
for (var i = 0; i < entries.length; i++) {
res[entries[i][0]] = entries[i][1];
}
return res;
};
Object.entries = Object.entries || function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--) resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
Object.values = Object.values || function (object) {
return Object.keys(object).map(function (key) {
return object[key];
});
};
// Apply PointerLock shims
(function () {
// Old API
if (typeof navigator === 'undefined' || typeof document === 'undefined') {
// Not running in a browser
return;
}
navigator.pointer = navigator.pointer || navigator.webkitPointer || navigator.mozPointer;
// Events
var pointerlockchange = function pointerlockchange() {
var e = document.createEvent('CustomEvent');
e.initCustomEvent('pointerlockchange', true, false, null);
document.dispatchEvent(e);
};
var pointerlockerror = function pointerlockerror() {
var e = document.createEvent('CustomEvent');
e.initCustomEvent('pointerlockerror', true, false, null);
document.dispatchEvent(e);
};
document.addEventListener('webkitpointerlockchange', pointerlockchange, false);
document.addEventListener('webkitpointerlocklost', pointerlockchange, false);
document.addEventListener('mozpointerlockchange', pointerlockchange, false);
document.addEventListener('mozpointerlocklost', pointerlockchange, false);
document.addEventListener('webkitpointerlockerror', pointerlockerror, false);
document.addEventListener('mozpointerlockerror', pointerlockerror, false);
// requestPointerLock
if (Element.prototype.mozRequestPointerLock) {
// FF requires a new function for some reason
Element.prototype.requestPointerLock = function () {
this.mozRequestPointerLock();
};
} else {
Element.prototype.requestPointerLock = Element.prototype.requestPointerLock || Element.prototype.webkitRequestPointerLock || Element.prototype.mozRequestPointerLock;
}
if (!Element.prototype.requestPointerLock && navigator.pointer) {
Element.prototype.requestPointerLock = function () {
var el = this;
document.pointerLockElement = el;
navigator.pointer.lock(el, pointerlockchange, pointerlockerror);
};
}
// exitPointerLock
document.exitPointerLock = document.exitPointerLock || document.webkitExitPointerLock || document.mozExitPointerLock;
if (!document.exitPointerLock) {
document.exitPointerLock = function () {
if (navigator.pointer) {
document.pointerLockElement = null;
navigator.pointer.unlock();
}
};
}
})();
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith#Polyfill
defineProtoFunc(String, 'endsWith', function (search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Polyfill
defineProtoFunc(String, 'includes', function (search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
defineProtoFunc(String, 'startsWith', function (search, rawPos) {
var pos = rawPos > 0 ? rawPos | 0 : 0;
return this.substring(pos, pos + search.length) === search;
});
// https://vanillajstoolkit.com/polyfills/stringtrimend/
defineProtoFunc(String, 'trimEnd', function () {
return this.replace(new RegExp(/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/.source + '$', 'g'), '');
});
var typedArrays = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array];
for (var _i = 0, _typedArrays = typedArrays; _i < _typedArrays.length; _i++) {
var typedArray = _typedArrays[_i];
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill#polyfill
defineProtoFunc(typedArray, "fill", Array.prototype.fill);
defineProtoFunc(typedArray, "join", Array.prototype.join);
}
/**
* Logs a frame number.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_FRAME = 'RenderFrame';
/**
* Logs a frame time.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_FRAME_TIME = 'RenderFrameTime';
/**
* Logs basic information about generated render passes.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_PASS = 'RenderPass';
/**
* Logs additional detail for render passes.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_PASS_DETAIL = 'RenderPassDetail';
/**
* Logs render actions created by the layer composition. Only executes when the
* layer composition changes.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_ACTION = 'RenderAction';
/**
* Logs the allocation of render targets.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_TARGET_ALLOC = 'RenderTargetAlloc';
/**
* Logs the allocation of textures.
*
* @type {string}
* @category Debug
*/
var TRACEID_TEXTURE_ALLOC = 'TextureAlloc';
/**
* Logs the creation of shaders.
*
* @type {string}
* @category Debug
*/
var TRACEID_SHADER_ALLOC = 'ShaderAlloc';
/**
* Logs the compilation time of shaders.
*
* @type {string}
* @category Debug
*/
var TRACEID_SHADER_COMPILE = 'ShaderCompile';
/**
* Logs the vram use by the textures.
*
* @type {string}
* @category Debug
*/
var TRACEID_VRAM_TEXTURE = 'VRAM.Texture';
/**
* Logs the vram use by the vertex buffers.
*
* @type {string}
* @category Debug
*/
var TRACEID_VRAM_VB = 'VRAM.Vb';
/**
* Logs the vram use by the index buffers.
*
* @type {string}
* @category Debug
*/
var TRACEID_VRAM_IB = 'VRAM.Ib';
/**
* Logs the vram use by the storage buffers.
*
* @type {string}
* @category Debug
*/
var TRACEID_VRAM_SB = 'VRAM.Sb';
/**
* Logs the creation of bind groups.
*
* @type {string}
* @category Debug
*/
var TRACEID_BINDGROUP_ALLOC = 'BindGroupAlloc';
/**
* Logs the creation of bind group formats.
*
* @type {string}
* @category Debug
*/
var TRACEID_BINDGROUPFORMAT_ALLOC = 'BindGroupFormatAlloc';
/**
* Logs the creation of render pipelines. WebBPU only.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDERPIPELINE_ALLOC = 'RenderPipelineAlloc';
/**
* Logs the creation of compute pipelines. WebGPU only.
*
* @type {string}
* @category Debug
*/
var TRACEID_COMPUTEPIPELINE_ALLOC = 'ComputePipelineAlloc';
/**
* Logs the creation of pipeline layouts. WebBPU only.
*
* @type {string}
* @category Debug
*/
var TRACEID_PIPELINELAYOUT_ALLOC = 'PipelineLayoutAlloc';
/**
* Logs the internal debug information for Elements.
*
* @type {string}
* @category Debug
*/
var TRACE_ID_ELEMENT = 'Element';
/**
* Logs the vram use by all textures in memory.
*
* @type {string}
* @category Debug
*/
var TRACEID_TEXTURES = 'Textures';
/**
* Logs the render queue commands.
*
* @type {string}
* @category Debug
*/
var TRACEID_RENDER_QUEUE = 'RenderQueue';
/**
* Logs the GPU timings.
*
* @type {string}
* @category Debug
*/
var TRACEID_GPU_TIMINGS = 'GpuTimings';
/**
* The engine version number. This is in semantic versioning format (MAJOR.MINOR.PATCH).
*/
var version = '1.78.0-animech';
/**
* The engine revision number. This is the Git hash of the last commit made to the branch
* from which the engine was built.
*/
var revision = 'e1c6c734d';
var config = {};
var common = {};
var apps = {}; // Storage for the applications using the PlayCanvas Engine
var data$1 = {}; // Storage for exported entity data
var typeofs = ['undefined', 'number', 'string', 'boolean'];
var objectTypes = {
'[object Array]': 'array',
'[object Object]': 'object',
'[object Function]': 'function',
'[object Date]': 'date',
'[object RegExp]': 'regexp',
'[object Float32Array]': 'float32array'
};
/**
* Extended typeof() function, returns the type of the object.
*
* @param {object} obj - The object to get the type of.
* @returns {string} The type string: "null", "undefined", "number", "string", "boolean", "array", "object", "function", "date", "regexp" or "float32array".
* @ignore
*/
function type$1(obj) {
if (obj === null) {
return 'null';
}
var typeString = typeof obj;
if (typeofs.includes(typeString)) {
return typeString;
}
return objectTypes[Object.prototype.toString.call(obj)];
}
/**
* Merge the contents of two objects into a single object.
*
* @param {object} target - The target object of the merge.
* @param {object} ex - The object that is merged with target.
* @returns {object} The target object.
* @example
* const A = {
* a: function () {
* console.log(this.a);
* }
* };
* const B = {
* b: function () {
* console.log(this.b);
* }
* };
*
* pc.extend(A, B);
* A.a();
* // logs "a"
* A.b();
* // logs "b"
* @ignore
*/
function extend(target, ex) {
for (var prop in ex) {
var copy = ex[prop];
if (type$1(copy) === 'object') {
target[prop] = extend({}, copy);
} else if (type$1(copy) === 'array') {
target[prop] = extend([], copy);
} else {
target[prop] = copy;
}
}
return target;
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c),
u = i.value;
} catch (n) {
return void e(n);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function () {
var t = this,
e = arguments;
return new Promise(function (r, o) {
var a = n.apply(t, e);
function _next(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
}
function _throw(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
}
_next(void 0);
});
};
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _createForOfIteratorHelperLoose(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (t) return (t = t.call(r)).next.bind(t);
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
t && (r = t);
var o = 0;
return function () {
return o >= r.length ? {
done: !0
} : {
done: !1,
value: r[o++]
};
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function (n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
function _inheritsLoose(t, o) {
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
}
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
return e;
};
var t,
e = {},
r = Object.prototype,
n = r.hasOwnProperty,
o = Object.defineProperty || function (t, e, r) {
t[e] = r.value;
},
i = "function" == typeof Symbol ? Symbol : {},
a = i.iterator || "@@iterator",
c = i.asyncIterator || "@@asyncIterator",
u = i.toStringTag || "@@toStringTag";
function define(t, e, r) {
return Object.defineProperty(t, e, {
value: r,
enumerable: !0,
configurable: !0,
writable: !0
}), t[e];
}
try {
define({}, "");
} catch (t) {
define = function (t, e, r) {
return t[e] = r;
};
}
function wrap(t, e, r, n) {
var i = e && e.prototype instanceof Generator ? e : Generator,
a = Object.create(i.prototype),
c = new Context(n || []);
return o(a, "_invoke", {
value: makeInvokeMethod(t, r, c)
}), a;
}
function tryCatch(t, e, r) {
try {
return {
type: "normal",
arg: t.call(e, r)
};
} catch (t) {
return {
type: "throw",
arg: t
};
}
}
e.wrap = wrap;
var h = "suspendedStart",
l = "suspendedYield",
f = "executing",
s = "completed",
y = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var p = {};
define(p, a, function () {
return this;
});
var d = Object.getPrototypeOf,
v = d && d(d(values([])));
v && v !== r && n.call(v, a) && (p = v);
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
function defineIteratorMethods(t) {
["next", "throw", "return"].forEach(function (e) {
define(t, e, function (t) {
return this._invoke(e, t);
});
});
}
function AsyncIterator(t, e) {
function invoke(r, o, i, a) {
var c = tryCatch(t[r], t, o);
if ("throw" !== c.type) {
var u = c.arg,
h = u.value;
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
invoke("next", t, i, a);
}, function (t) {
invoke("throw", t, i, a);
}) : e.resolve(h).then(function (t) {
u.value = t, i(u);
}, function (t) {
return invoke("throw", t, i, a);
});
}
a(c.arg);
}
var r;
o(this, "_invoke", {
value: function (t, n) {
function callInvokeWithMethodAndArg() {
return new e(function (e, r) {
invoke(t, n, e, r);
});
}
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
});
}
function makeInvokeMethod(e, r, n) {
var o = h;
return function (i, a) {
if (o === f) throw Error("Generator is already running");
if (o === s) {
if ("throw" === i) throw a;
return {
value: t,
done: !0
};
}
for (n.method = i, n.arg = a;;) {
var c = n.delegate;
if (c) {
var u = maybeInvokeDelegate(c, n);
if (u) {
if (u === y) continue;
return u;
}
}
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
if (o === h) throw o = s, n.arg;
n.dispatchException(n.arg);
} else "return" === n.method && n.abrupt("return", n.arg);
o = f;
var p = tryCatch(e, r, n);
if ("normal" === p.type) {
if (o = n.done ? s : l, p.arg === y) continue;
return {
value: p.arg,
done: n.done
};
}
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
}
};
}
function maybeInvokeDelegate(e, r) {
var n = r.method,
o = e.iterator[n];
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
var i = tryCatch(o, e.iterator, r.arg);
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
var a = i.arg;
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
}
function pushTryEntry(t) {
var e = {
tryLoc: t[0]
};
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
}
function resetTryEntry(t) {
var e = t.completion || {};
e.type = "normal", delete e.arg, t.completion = e;
}
function Context(t) {
this.tryEntries = [{
tryLoc: "root"
}], t.forEach(pushTryEntry, this), this.reset(!0);
}
function values(e) {
if (e || "" === e) {
var r = e[a];
if (r) return r.call(e);
if ("function" == typeof e.next) return e;
if (!isNaN(e.length)) {
var o = -1,
i = function next() {
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
return next.value = t, next.done = !0, next;
};
return i.next = i;
}
}
throw new TypeError(typeof e + " is not iterable");
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), o(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
var e = "function" == typeof t && t.constructor;
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
}, e.mark = function (t) {
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
}, e.awrap = function (t) {
return {
__await: t
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
return this;
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
void 0 === i && (i = Promise);
var a = new AsyncIterator(wrap(t, r, n, o), i);
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
return t.done ? t.value : a.next();
});
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
return this;
}), define(g, "toString", function () {
return "[object Generator]";
}), e.keys = function (t) {
var e = Object(t),
r = [];
for (var n in e) r.push(n);
return r.reverse(), function next() {
for (; r.length;) {
var t = r.pop();
if (t in e) return next.value = t, next.done = !1, next;
}
return next.done = !0, next;
};
}, e.values = values, Context.prototype = {
constructor: Context,
reset: function (e) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
},
stop: function () {
this.done = !0;
var t = this.tryEntries[0].completion;
if ("throw" === t.type) throw t.arg;
return this.rval;
},
dispatchException: function (e) {
if (this.done) throw e;
var r = this;
function handle(n, o) {
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
}
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
var i = this.tryEntries[o],
a = i.completion;
if ("root" === i.tryLoc) return handle("end");
if (i.tryLoc <= this.prev) {
var c = n.call(i, "catchLoc"),
u = n.call(i, "finallyLoc");
if (c && u) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
} else if (c) {
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
} else {
if (!u) throw Error("try statement without catch or finally");
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
}
}
}
},
abrupt: function (t, e) {
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
var o = this.tryEntries[r];
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
var i = o;
break;
}
}
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
var a = i ? i.completion : {};
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
},
complete: function (t, e) {
if ("throw" === t.type) throw t.arg;
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
},
finish: function (t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
}
},
catch: function (t) {
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
var r = this.tryEntries[e];
if (r.tryLoc === t) {
var n = r.completion;
if ("throw" === n.type) {
var o = n.arg;
resetTryEntry(r);
}
return o;
}
}
throw Error("illegal catch attempt");
},
delegateYield: function (e, r, n) {
return this.delegate = {
iterator: values(e),
resultName: r,
nextLoc: n
}, "next" === this.method && (this.arg = t), y;
}
}, e;
}
function _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r);
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (String )(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
/**
* Log tracing functionality, allowing for tracing of the internal functionality of the engine.
* Note that the trace logging only takes place in the debug build of the engine and is stripped
* out in other builds.
*
* @category Debug
*/
var Tracing = /*#__PURE__*/function () {
function Tracing() {}
/**
* Enable or disable a trace channel.
*
* @param {string} channel - Name of the trace channel. Can be:
*
* - {@link TRACEID_RENDER_FRAME}
* - {@link TRACEID_RENDER_FRAME_TIME}
* - {@link TRACEID_RENDER_PASS}
* - {@link TRACEID_RENDER_PASS_DETAIL}
* - {@link TRACEID_RENDER_ACTION}
* - {@link TRACEID_RENDER_TARGET_ALLOC}
* - {@link TRACEID_TEXTURE_ALLOC}
* - {@link TRACEID_SHADER_ALLOC}
* - {@link TRACEID_SHADER_COMPILE}
* - {@link TRACEID_VRAM_TEXTURE}
* - {@link TRACEID_VRAM_VB}
* - {@link TRACEID_VRAM_IB}
* - {@link TRACEID_RENDERPIPELINE_ALLOC}
* - {@link TRACEID_COMPUTEPIPELINE_ALLOC}
* - {@link TRACEID_PIPELINELAYOUT_ALLOC}
* - {@link TRACEID_TEXTURES}
* - {@link TRACEID_GPU_TIMINGS}
*
* @param {boolean} enabled - New enabled state for the channel.
*/
Tracing.set = function set(channel, enabled) {
if (enabled === void 0) {
enabled = true;
}
if (enabled) {
Tracing._traceChannels.add(channel);
} else {
Tracing._traceChannels.delete(channel);
}
}
/**
* Test if the trace channel is enabled.
*
* @param {string} channel - Name of the trace channel.
* @returns {boolean} - True if the trace channel is enabled.
*/;
Tracing.get = function get(channel) {
return Tracing._traceChannels.has(channel);
};
return Tracing;
}();
/**
* Set storing the names of enabled trace channels.
*
* @type {Set<string>}
* @private
*/
Tracing._traceChannels = new Set();
/**
* Enable call stack logging for trace calls. Defaults to false.
*
* @type {boolean}
*/
Tracing.stack = false;
/**
* Engine debug log system. Note that the logging only executes in the
* debug build of the engine, and is stripped out in other builds.
*
* @ignore
*/
var Debug = /*#__PURE__*/function () {
function Debug() {}
/**
* Deprecated warning message.
*
* @param {string} message - The message to log.
*/
Debug.deprecated = function deprecated(message) {
if (!Debug._loggedMessages.has(message)) {
Debug._loggedMessages.add(message);
console.warn("DEPRECATED: " + message);
}
}
/**
* Assertion deprecated message. If the assertion is false, the deprecated message is written to the log.
*
* @param {boolean|object} assertion - The assertion to check.
* @param {string} message - The message to log.
*/;
Debug.assertDeprecated = function assertDeprecated(assertion, message) {
if (!assertion) {
Debug.deprecated(message);
}
}
/**
* Assertion error message. If the assertion is false, the error message is written to the log.
*
* @param {boolean|object} assertion - The assertion to check.
* @param {...*} args - The values to be written to the log.
*/;
Debug.assert = function assert(assertion) {
if (!assertion) {
var _console;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_console = console).error.apply(_console, ['ASSERT FAILED: '].concat(args));
}
}
/**
* Assertion error message that writes an error message to the log if the object has already
* been destroyed. To be used along setDestroyed.
*
* @param {object} object - The object to check.
*/;
Debug.assertDestroyed = function assertDestroyed(object) {
if (object != null && object.__alreadyDestroyed) {
var _object$constructor;
var message = "[" + ((_object$constructor = object.constructor) == null ? void 0 : _object$constructor.name) + "] with name [" + object.name + "] has already been destroyed, and cannot be used.";
if (!Debug._loggedMessages.has(message)) {
Debug._loggedMessages.add(message);
console.error('ASSERT FAILED: ', message, object);
}
}
}
/**
* Executes a function in debug mode only.
*
* @param {Function} func - Function to call.
*/;
Debug.call = function call(func) {
func();
}
/**
* Info message.
*
* @param {...*} args - The values to be written to the log.
*/;
Debug.log = function log() {
var _console2;
(_console2 = console).log.apply(_console2, arguments);
}
/**
* Info message logged no more than once.
*
* @param {string} message - The message to log.
* @param {...*} args - The values to be written to the log.
*/;
Debug.logOnce = function logOnce(message) {
if (!Debug._loggedMessages.has(message)) {
var _console3;
Debug._loggedMessages.add(message);
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_console3 = console).log.apply(_console3, [message].concat(args));
}
}
/**
* Warning message.
*
* @param {...*} args - The values to be written to the log.
*/;
Debug.warn = function warn() {
var _console4;
(_console4 = console).warn.apply(_console4, arguments);
}
/**
* Warning message logged no more than once.
*
* @param {string} message - The message to log.
* @param {...*} args - The values to be written to the log.
*/;
Debug.warnOnce = function warnOnce(message) {
if (!Debug._loggedMessages.has(message)) {
var _console5;
Debug._loggedMessages.add(message);
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
(_console5 = console).warn.apply(_console5, [message].concat(args));
}
}
/**
* Error message.
*
* @param {...*} args - The values to be written to the log.
*/;
Debug.error = function error() {
var _console6;
(_console6 = console).error.apply(_console6, arguments);
}
/**
* Error message logged no more than once.
*
* @param {string} message - The message to log.
* @param {...*} args - The values to be written to the log.
*/;
Debug.errorOnce = function errorOnce(message) {
if (!Debug._loggedMessages.has(message)) {
var _console7;
Debug._loggedMessages.add(message);
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
args[_key4 - 1] = arguments[_key4];
}
(_console7 = console).error.apply(_console7, [message].concat(args));
}
}
/**
* Trace message, which is logged to the console if the tracing for the channel is enabled
*
* @param {string} channel - The trace channel
* @param {...*} args - The values to be written to the log.
*/;
Debug.trace = function trace(channel) {
if (Tracing.get(channel)) {
var _console8;
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
args[_key5 - 1] = arguments[_key5];
}
(_console8 = console).groupCollapsed.apply(_console8, [channel.padEnd(20, ' ') + "|"].concat(args));
if (Tracing.stack) {
console.trace();
}
console.groupEnd();
}
};
return Debug;
}();
/**
* A helper debug functionality.
*
* @ignore
*/
/**
* Set storing already logged messages, to only print each unique message one time.
*
* @type {Set<string>}
* @private
*/
Debug._loggedMessages = new Set();
var DebugHelper = /*#__PURE__*/function () {
function DebugHelper() {}
/**
* Set a name to the name property of the object. Executes only in the debug build.
*
* @param {object} object - The object to assign the name to.
* @param {string} name - The name to assign.
*/
DebugHelper.setName = function setName(object, name) {
if (object) {
object.name = name;
}
}
/**
* Set a label to the label property of the object. Executes only in the debug build.
*
* @param {object} object - The object to assign the name to.
* @param {string} label - The label to assign.
*/;
DebugHelper.setLabel = function setLabel(object, label) {
if (object) {
object.label = label;
}
}
/**
* Marks object as destroyed. Executes only in the debug build. To be used along assertDestroyed.
*
* @param {object} object - The object to mark as destroyed.
*/;
DebugHelper.setDestroyed = function setDestroyed(object) {
if (object) {
object.__alreadyDestroyed = true;
}
};
return DebugHelper;
}();
/**
* @import { EventHandler } from './event-handler.js'
*/
/**
* Callback used by {@link EventHandler} functions. Note the callback is limited to 8 arguments.
*
* @callback HandleEventCallback
* @param {*} [arg1] - First argument that is passed from caller.
* @param {*} [arg2] - Second argument that is passed from caller.
* @param {*} [arg3] - Third argument that is passed from caller.
* @param {*} [arg4] - Fourth argument that is passed from caller.
* @param {*} [arg5] - Fifth argument that is passed from caller.
* @param {*} [arg6] - Sixth argument that is passed from caller.
* @param {*} [arg7] - Seventh argument that is passed from caller.
* @param {*} [arg8] - Eighth argument that is passed from caller.
*/
/**
* Event Handle that is created by {@link EventHandler} and can be used for easier event removal and management.
* @example
* const evt = obj.on('test', (a, b) => {
* console.log(a + b);
* });
* obj.fire('test');
*
* evt.off(); // easy way to remove this event
* obj.fire('test'); // this will not trigger an event
* @example
* // store an array of event handles
* let events = [ ];
*
* events.push(objA.on('testA', () => { }));
* events.push(objB.on('testB', () => { }));
*
* // when needed, remove all events
* events.forEach((evt) => {
* evt.off();
* });
* events = [ ];
*/
var EventHandle = /*#__PURE__*/function () {
/**
* @param {EventHandler} handler - source object of the event.
* @param {string} name - Name of the event.
* @param {HandleEventCallback} callback - Function that is called when event is fired.
* @param {object} scope - Object that is used as `this` when event is fired.
* @param {boolean} [once] - If this is a single event and will be removed after event is fired.
*/
function EventHandle(handler, name, callback, scope, once) {
if (once === void 0) {
once = false;
}
/**
* @type {EventHandler}
* @private
*/
this.handler = void 0;
/**
* @type {string}
* @ignore
*/
this.name = void 0;
/**
* @type {HandleEventCallback}
* @ignore
*/
this.callback = void 0;
/**
* @type {object}
* @ignore
*/
this.scope = void 0;
/**
* @type {boolean}
* @ignore
*/
this._once = void 0;
/**
* True if event has been removed.
* @type {boolean}
* @private
*/
this._removed = false;
this.handler = handler;
this.name = name;
this.callback = callback;
this.scope = scope;
this._once = once;
}
/**
* Remove this event from its handler.
*/
var _proto = EventHandle.prototype;
_proto.off = function off() {
if (this._removed) return;
this.handler.offByHandle(this);
};
_proto.on = function on(name, callback, scope) {
if (scope === void 0) {
scope = this;
}
Debug.deprecated('Using chaining with EventHandler.on is deprecated, subscribe to an event from EventHandler directly instead.');
return this.handler._addCallback(name, callback, scope, false);
};
_proto.once = function once(name, callback, scope) {
if (scope === void 0) {
scope = this;
}
Debug.deprecated('Using chaining with EventHandler.once is deprecated, subscribe to an event from EventHandler directly instead.');
return this.handler._addCallback(name, callback, scope, true);
}
/**
* Mark if event has been removed.
* @type {boolean}
* @ignore
*/;
return _createClass(EventHandle, [{
key: "removed",
get:
/**
* True if event has been removed.
* @type {boolean}
*/
function get() {
return this._removed;
},
set: function set(value) {
if (!value) return;
this._removed = true;
}
}]);
}();
/**
* @import { HandleEventCallback } from './event-handle.js'
*/
/**
* Abstract base class that implements functionality for event handling.
*
* ```javascript
* const obj = new EventHandlerSubclass();
*
* // subscribe to an event
* obj.on('hello', function (str) {
* console.log('event hello is fired', str);
* });
*
* // fire event
* obj.fire('hello', 'world');
* ```
*/
var EventHandler = /*#__PURE__*/function () {
function EventHandler() {
/**
* @type {Map<string,Array<EventHandle>>}
* @private
*/
this._callbacks = new Map();
/**
* @type {Map<string,Array<EventHandle>>}
* @private
*/
this._callbackActive = new Map();
}
var _proto = EventHandler.prototype;
/**
* Reinitialize the event handler.
* @ignore
*/
_proto.initEventHandler = function initEventHandler() {
this._callbacks = new Map();
this._callbackActive = new Map();
}
/**
* Registers a new event handler.
*
* @param {string} name - Name of the event to bind the callback to.
* @param {HandleEventCallback} callback - Function that is called when event is fired. Note
* the callback is limited to 8 arguments.
* @param {object} scope - Object to use as 'this' when the event is fired, defaults to
* current this.
* @param {boolean} once - If true, the callback will be unbound after being fired once.
* @returns {EventHandle} Created {@link EventHandle}.
* @ignore
*/;
_proto._addCallback = function _addCallback(name, callback, scope, once) {
if (!name || typeof name !== 'string' || !callback) {
console.warn("EventHandler: subscribing to an event (" + name + ") with missing arguments", callback);
}
if (!this._callbacks.has(name)) {
this._callbacks.set(name, []);
}
// if we are adding a callback to the list that is executing right now
// ensure we preserve initial list before modifications
if (this._callbackActive.has(name)) {
var callbackActive = this._callbackActive.get(name);
if (callbackActive && callbackActive === this._callbacks.get(name)) {
this._callbackActive.set(name, callbackActive.slice());
}
}
var evt = new EventHandle(this, name, callback, scope, once);
this._callbacks.get(name).push(evt);
return evt;
}
/**
* Attach an event handler to an event.
*
* @param {string} name - Name of the event to bind the callback to.
* @param {HandleEventCallback} callback - Function that is called when event is fired. Note
* the callback is limited to 8 arguments.
* @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to
* current this.
* @returns {EventHandle} Can be used for removing event in the future.
* @example
* obj.on('test', function (a, b) {
* console.log(a + b);
* });
* obj.fire('test', 1, 2); // prints 3 to the console
* @example
* const evt = obj.on('test', function (a, b) {
* console.log(a + b);
* });
* // some time later
* evt.off();
*/;
_proto.on = function on(name, callback, scope) {
if (scope === void 0) {
scope = this;
}
return this._addCallback(name, callback, scope, false);
}
/**
* Attach an event handler to an event. This handler will be removed after being fired once.
*
* @param {string} name - Name of the event to bind the callback to.
* @param {HandleEventCallback} callback - Function that is called when event is fired. Note
* the callback is limited to 8 arguments.
* @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to
* current this.
* @returns {EventHandle} - can be used for removing event in the future.
* @example
* obj.once('test', function (a, b) {
* console.log(a + b);
* });
* obj.fire('test', 1, 2); // prints 3 to the console
* obj.fire('test', 1, 2); // not going to get handled
*/;
_proto.once = function once(name, callback, scope) {
if (scope === void 0) {
scope = this;
}
return this._addCallback(name, callback, scope, true);
}
/**
* Detach an event handler from an event. If callback is not provided then all callbacks are
* unbound from the event, if scope is not provided then all events with the callback will be
* unbound.
*
* @param {string} [name] - Name of the event to unbind.
* @param {HandleEventCallback} [callback] - Function to be unbound.
* @param {object} [scope] - Scope that was used as the this when the event is fired.
* @returns {EventHandler} Self for chaining.
* @example
* const handler = function () {
* };
* obj.on('test', handler);
*
* obj.off(); // Removes all events
* obj.off('test'); // Removes all events called 'test'
* obj.off('test', handler); // Removes all handler functions, called 'test'
* obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
*/;
_proto.off = function off(name, callback, scope) {
if (name) {
// if we are removing a callback from the list that is executing right now
// ensure we preserve initial list before modifications
if (this._callbackActive.has(name) && this._callbackActive.get(nam