@galacean/effects-core 2.2.6 → 2.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/components/base-render-component.d.ts +10 -4
  2. package/dist/components/shape-component.d.ts +5 -2
  3. package/dist/composition.d.ts +62 -2
  4. package/dist/config.d.ts +11 -0
  5. package/dist/downloader.d.ts +15 -0
  6. package/dist/index.js +1605 -1020
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +1605 -1021
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/math/value-getters/index.d.ts +1 -1
  11. package/dist/math/value-getters/{vector4-curve.d.ts → vector-curves.d.ts} +8 -0
  12. package/dist/plugins/shape/build-line.d.ts +32 -0
  13. package/dist/plugins/shape/graphics-path.d.ts +0 -4
  14. package/dist/plugins/shape/polygon.d.ts +0 -4
  15. package/dist/plugins/shape/shape-path.d.ts +0 -4
  16. package/dist/plugins/timeline/playable-assets/index.d.ts +1 -1
  17. package/dist/plugins/timeline/playable-assets/{vector4-property-playable-asset.d.ts → vector-property-playable-assets.d.ts} +5 -1
  18. package/dist/plugins/timeline/playables/color-property-mixer-playable.d.ts +5 -5
  19. package/dist/plugins/timeline/playables/float-property-mixer-playable.d.ts +4 -5
  20. package/dist/plugins/timeline/playables/index.d.ts +1 -1
  21. package/dist/plugins/timeline/playables/property-mixer-playable.d.ts +9 -0
  22. package/dist/plugins/timeline/playables/vector-property-mixer-playable.d.ts +11 -0
  23. package/dist/plugins/timeline/tracks/index.d.ts +1 -1
  24. package/dist/plugins/timeline/tracks/{vector4-property-track.d.ts → vector-property-track.d.ts} +3 -0
  25. package/package.json +2 -2
  26. package/dist/plugins/timeline/playables/vector4-property-mixer-playable.d.ts +0 -6
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.2.6
6
+ * Version: v2.3.0-alpha.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -1022,6 +1022,26 @@ function _inherits(subClass, superClass) {
1022
1022
  if (superClass) _set_prototype_of(subClass, superClass);
1023
1023
  }
1024
1024
 
1025
+ /**
1026
+ * JSON 版本
1027
+ */ var JSONSceneVersion;
1028
+ (function(JSONSceneVersion) {
1029
+ JSONSceneVersion["1_0"] = "1.0";
1030
+ JSONSceneVersion["1_1"] = "1.1";
1031
+ JSONSceneVersion["1_2"] = "1.2";
1032
+ JSONSceneVersion["1_3"] = "1.3";
1033
+ JSONSceneVersion["1_5"] = "1.5";
1034
+ JSONSceneVersion["1_8"] = "1.8";
1035
+ JSONSceneVersion["2_0"] = "2.0";
1036
+ JSONSceneVersion["2_1"] = "2.1";
1037
+ JSONSceneVersion["2_2"] = "2.2";
1038
+ JSONSceneVersion["2_3"] = "2.3";
1039
+ JSONSceneVersion["2_4"] = "2.4";
1040
+ JSONSceneVersion["3_0"] = "3.0";
1041
+ JSONSceneVersion["3_1"] = "3.1";
1042
+ JSONSceneVersion["LATEST"] = "3.1";
1043
+ })(JSONSceneVersion || (JSONSceneVersion = {}));
1044
+
1025
1045
  /*********************************************/ /* 元素属性参数类型 */ /*********************************************/ /**
1026
1046
  * 渲染等级
1027
1047
  */ var RenderLevel;
@@ -1327,8 +1347,12 @@ var RenderFace;
1327
1347
  */ var END_BEHAVIOR_DESTROY_CHILDREN = 6;
1328
1348
  var CAMERA_CLIP_MODE_VERTICAL = 1;
1329
1349
  var CAMERA_CLIP_MODE_NORMAL = 0;
1330
- var MESSAGE_ITEM_PHRASE_BEGIN = 2;
1331
- var MESSAGE_ITEM_PHRASE_END = 1;
1350
+ /**
1351
+ * 消息开始
1352
+ */ var MESSAGE_ITEM_PHRASE_BEGIN = 2;
1353
+ /**
1354
+ * 消息结束
1355
+ */ var MESSAGE_ITEM_PHRASE_END = 1;
1332
1356
 
1333
1357
  var CameraClipMode;
1334
1358
  (function(CameraClipMode) {
@@ -1402,6 +1426,9 @@ var CameraClipMode;
1402
1426
  /**
1403
1427
  * Vector4 曲线
1404
1428
  */ ValueType[ValueType["VECTOR4_CURVE"] = 25] = "VECTOR4_CURVE";
1429
+ /**
1430
+ * Vector2 曲线
1431
+ */ ValueType[ValueType["VECTOR2_CURVE"] = 26] = "VECTOR2_CURVE";
1405
1432
  })(ValueType || (ValueType = {}));
1406
1433
  /**
1407
1434
  * 关键帧类型
@@ -1670,19 +1697,13 @@ var ShapePointType;
1670
1697
  var DataType;
1671
1698
  (function(DataType) {
1672
1699
  DataType["VFXItemData"] = "VFXItemData";
1673
- DataType["EffectComponent"] = "EffectComponent";
1700
+ // Assets
1674
1701
  DataType["Material"] = "Material";
1675
1702
  DataType["Shader"] = "Shader";
1676
- DataType["SpriteComponent"] = "SpriteComponent";
1677
- DataType["ParticleSystem"] = "ParticleSystem";
1678
- DataType["InteractComponent"] = "InteractComponent";
1679
- DataType["CameraController"] = "CameraController";
1680
- DataType["PostProcessVolume"] = "PostProcessVolume";
1681
1703
  DataType["Geometry"] = "Geometry";
1682
1704
  DataType["Texture"] = "Texture";
1683
1705
  DataType["Image"] = "Image";
1684
1706
  DataType["AnimationClip"] = "AnimationClip";
1685
- DataType["TextComponent"] = "TextComponent";
1686
1707
  DataType["BinaryAsset"] = "BinaryAsset";
1687
1708
  // Timeline
1688
1709
  DataType["TrackAsset"] = "TrackAsset";
@@ -1694,6 +1715,7 @@ var DataType;
1694
1715
  DataType["SubCompositionTrack"] = "SubCompositionTrack";
1695
1716
  DataType["FloatPropertyTrack"] = "FloatPropertyTrack";
1696
1717
  DataType["ColorPropertyTrack"] = "ColorPropertyTrack";
1718
+ DataType["Vector2PropertyTrack"] = "Vector2PropertyTrack";
1697
1719
  DataType["Vector4PropertyTrack"] = "Vector4PropertyTrack";
1698
1720
  DataType["TransformPlayableAsset"] = "TransformPlayableAsset";
1699
1721
  DataType["SpriteColorPlayableAsset"] = "SpriteColorPlayableAsset";
@@ -1701,6 +1723,9 @@ var DataType;
1701
1723
  DataType["SubCompositionPlayableAsset"] = "SubCompositionPlayableAsset";
1702
1724
  DataType["FloatPropertyPlayableAsset"] = "FloatPropertyPlayableAsset";
1703
1725
  DataType["ColorPropertyPlayableAsset"] = "ColorPropertyPlayableAsset";
1726
+ DataType["Vector2PropertyPlayableAsset"] = "Vector2PropertyPlayableAsset";
1727
+ DataType["Vector4PropertyPlayableAsset"] = "Vector4PropertyPlayableAsset";
1728
+ // Components
1704
1729
  DataType["MeshComponent"] = "MeshComponent";
1705
1730
  DataType["SkyboxComponent"] = "SkyboxComponent";
1706
1731
  DataType["LightComponent"] = "LightComponent";
@@ -1714,6 +1739,13 @@ var DataType;
1714
1739
  DataType["RichTextComponent"] = "RichTextComponent";
1715
1740
  DataType["OrientationComponent"] = "OrientationComponent";
1716
1741
  DataType["ShapeComponent"] = "ShapeComponent";
1742
+ DataType["SpriteComponent"] = "SpriteComponent";
1743
+ DataType["ParticleSystem"] = "ParticleSystem";
1744
+ DataType["InteractComponent"] = "InteractComponent";
1745
+ DataType["CameraController"] = "CameraController";
1746
+ DataType["PostProcessVolume"] = "PostProcessVolume";
1747
+ DataType["EffectComponent"] = "EffectComponent";
1748
+ DataType["TextComponent"] = "TextComponent";
1717
1749
  // Non-EffectObject
1718
1750
  DataType["TimelineClip"] = "TimelineClip";
1719
1751
  })(DataType || (DataType = {}));
@@ -1802,8 +1834,11 @@ var VertexBufferSemantic;
1802
1834
  VertexBufferSemantic["TangentBS3"] = "TANGENT_BS3";
1803
1835
  })(VertexBufferSemantic || (VertexBufferSemantic = {}));
1804
1836
 
1837
+ var LATEST_VERSION = JSONSceneVersion.LATEST;
1838
+
1805
1839
  var index$1 = /*#__PURE__*/Object.freeze({
1806
1840
  __proto__: null,
1841
+ LATEST_VERSION: LATEST_VERSION,
1807
1842
  get RenderLevel () { return RenderLevel; },
1808
1843
  get BlendingMode () { return BlendingMode; },
1809
1844
  get SideMode () { return SideMode; },
@@ -1831,6 +1866,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
1831
1866
  MESSAGE_ITEM_PHRASE_END: MESSAGE_ITEM_PHRASE_END,
1832
1867
  get ValueType () { return ValueType; },
1833
1868
  get BezierKeyframeType () { return BezierKeyframeType; },
1869
+ get JSONSceneVersion () { return JSONSceneVersion; },
1834
1870
  get EndBehavior () { return EndBehavior; },
1835
1871
  get ParentItemEndBehavior () { return ParentItemEndBehavior; },
1836
1872
  get ParticleInteractionBehavior () { return ParticleInteractionBehavior; },
@@ -5278,988 +5314,719 @@ Matrix4.tempVec1 = new Vector3();
5278
5314
  Matrix4.tempVec2 = new Vector3();
5279
5315
  Matrix4.tempMat0 = new Matrix4();
5280
5316
 
5281
- function _array_like_to_array(arr, len) {
5282
- if (len == null || len > arr.length) len = arr.length;
5283
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5284
- return arr2;
5285
- }
5286
-
5287
- function _unsupported_iterable_to_array(o, minLen) {
5288
- if (!o) return;
5289
- if (typeof o === "string") return _array_like_to_array(o, minLen);
5290
- var n = Object.prototype.toString.call(o).slice(8, -1);
5291
- if (n === "Object" && o.constructor) n = o.constructor.name;
5292
- if (n === "Map" || n === "Set") return Array.from(n);
5293
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
5317
+ function _extends() {
5318
+ _extends = Object.assign || function assign(target) {
5319
+ for(var i = 1; i < arguments.length; i++){
5320
+ var source = arguments[i];
5321
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
5322
+ }
5323
+ return target;
5324
+ };
5325
+ return _extends.apply(this, arguments);
5294
5326
  }
5295
5327
 
5296
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
5297
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
5298
- if (it) return (it = it.call(o)).next.bind(it);
5299
- // Fallback for engines without symbol support
5300
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
5301
- if (it) o = it;
5302
- var i = 0;
5303
- return function() {
5304
- if (i >= o.length) return {
5305
- done: true
5306
- };
5307
- return {
5308
- done: false,
5309
- value: o[i++]
5310
- };
5311
- };
5312
- }
5313
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5314
- }
5328
+ exports.TextureLoadAction = void 0;
5329
+ (function(TextureLoadAction) {
5330
+ TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
5331
+ //preserve previous attachment
5332
+ //load = 1,
5333
+ //clear attachment
5334
+ TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
5335
+ })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
5336
+ exports.TextureSourceType = void 0;
5337
+ (function(TextureSourceType) {
5338
+ TextureSourceType[TextureSourceType["none"] = 0] = "none";
5339
+ TextureSourceType[TextureSourceType["data"] = 1] = "data";
5340
+ TextureSourceType[TextureSourceType["image"] = 2] = "image";
5341
+ TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
5342
+ TextureSourceType[TextureSourceType["video"] = 4] = "video";
5343
+ TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
5344
+ TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
5345
+ TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
5346
+ })(exports.TextureSourceType || (exports.TextureSourceType = {}));
5315
5347
 
5316
- exports.ShaderCompileResultStatus = void 0;
5317
- (function(ShaderCompileResultStatus) {
5318
- ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
5319
- ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
5320
- ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
5321
- ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
5322
- })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
5323
- exports.GLSLVersion = void 0;
5324
- (function(GLSLVersion) {
5325
- GLSLVersion["GLSL1"] = "100";
5326
- GLSLVersion["GLSL3"] = "300 es";
5327
- })(exports.GLSLVersion || (exports.GLSLVersion = {}));
5328
- var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
5329
- _inherits(ShaderVariant, EffectsObject);
5330
- function ShaderVariant(engine, source) {
5331
- var _this;
5332
- _this = EffectsObject.call(this, engine) || this;
5333
- _this.source = source;
5334
- return _this;
5335
- }
5336
- return ShaderVariant;
5337
- }(EffectsObject);
5338
- exports.Shader = /*#__PURE__*/ function(EffectsObject) {
5339
- _inherits(Shader, EffectsObject);
5340
- function Shader() {
5341
- return EffectsObject.apply(this, arguments);
5348
+ /**
5349
+ * 负责下载各种资源,并提供了一些异步加载和缓存管理的功能
5350
+ */ var Downloader = /*#__PURE__*/ function() {
5351
+ function Downloader() {
5352
+ /**
5353
+ * 存储多个回调函数的对象
5354
+ */ this.callbacks = {};
5342
5355
  }
5343
- var _proto = Shader.prototype;
5344
- _proto.createVariant = function createVariant(macros) {
5345
- var shaderMacros = [];
5346
- if (macros) {
5347
- for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
5348
- var key = _step.value;
5349
- shaderMacros.push([
5350
- key,
5351
- macros[key]
5352
- ]);
5353
- }
5354
- }
5355
- var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
5356
- shaderVariant.shader = this;
5357
- return shaderVariant;
5356
+ var _proto = Downloader.prototype;
5357
+ /**
5358
+ * 下载一个 JSON 文件
5359
+ * @param url - 要下载的 JSON 文件的 URL
5360
+ * @param onSuccess - 下载成功后的回调函数
5361
+ * @param onError - 下载失败后的回调函数
5362
+ */ _proto.downloadJSON = function downloadJSON(url, onSuccess, onError) {
5363
+ this.download(url, "json", onSuccess, onError);
5358
5364
  };
5359
- _proto.fromData = function fromData(data) {
5360
- EffectsObject.prototype.fromData.call(this, data);
5361
- this.shaderData = data;
5365
+ /**
5366
+ * 下载一个二进制文件
5367
+ * @param url - 要下载的二进制文件的 URL
5368
+ * @param onSuccess - 下载成功后的回调函数
5369
+ * @param onError - 下载失败后的回调函数
5370
+ */ _proto.downloadBinary = function downloadBinary(url, onSuccess, onError) {
5371
+ this.download(url, "arraybuffer", onSuccess, onError);
5362
5372
  };
5363
- return Shader;
5364
- }(EffectsObject);
5365
- exports.Shader = __decorate([
5366
- effectsClass(DataType.Shader)
5367
- ], exports.Shader);
5368
-
5369
- var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
5370
- var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
5371
- var COPY_VERTEX_SHADER = "\nprecision highp float;\nattribute vec2 aPos;\nvarying vec2 vTex;\nvoid main(){\n gl_Position = vec4(aPos,0.,1.0);\n vTex = (aPos + vec2(1.0))/2.;\n}";
5372
- var COPY_FRAGMENT_SHADER = "precision mediump float;\nvarying vec2 vTex;\n\n#ifdef DEPTH_TEXTURE\nuniform sampler2D uDepth;\n#extension GL_EXT_frag_depth : enable\n#endif\nvoid main(){\n #ifdef DEPTH_TEXTURE\n gl_FragDepthEXT = texture2D(uDepth,vTex).r;\n #endif\n}\n";
5373
- function createCopyShader(level, writeDepth) {
5374
- var webgl2 = level === 2;
5375
- return {
5376
- name: EFFECTS_COPY_MESH_NAME,
5377
- vertex: COPY_VERTEX_SHADER,
5378
- fragment: COPY_FRAGMENT_SHADER,
5379
- glslVersion: webgl2 ? exports.GLSLVersion.GLSL3 : exports.GLSLVersion.GLSL1,
5380
- macros: [
5381
- [
5382
- "DEPTH_TEXTURE",
5383
- !!writeDepth
5384
- ]
5385
- ],
5386
- // @ts-expect-error
5387
- cacheId: COPY_MESH_SHADER_ID + +writeDepth
5373
+ /**
5374
+ * 下载一个 Blob 文件
5375
+ * @param url - 要下载的 Blob 文件的 URL
5376
+ * @param onSuccess - 下载成功后的回调函数
5377
+ * @param onError - 下载失败后的回调函数
5378
+ */ _proto.downloadBlob = function downloadBlob(url, onSuccess, onError) {
5379
+ this.download(url, "blob", onSuccess, onError);
5388
5380
  };
5389
- }
5390
-
5391
- /**
5392
- * Helper class to create a WebGL Context
5393
- *
5394
- * @param canvas
5395
- * @param glType
5396
- * @param options
5397
- * @returns
5398
- */ function createGLContext(canvas, glType, options) {
5399
- if (glType === void 0) glType = "webgl";
5400
- var context;
5401
- if (glType === "webgl2") {
5402
- context = canvas.getContext("webgl2", options);
5403
- if (!context) {
5404
- console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
5405
- }
5406
- }
5407
- if (!context || glType === "webgl") {
5408
- context = canvas.getContext("webgl", options);
5409
- }
5410
- if (!context) {
5411
- throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
5412
- }
5413
- return context;
5414
- }
5415
-
5416
- function gpuTimer(gl) {
5417
- var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
5418
- if (ext) {
5419
- var query = gl.createQuery();
5420
- var getTime = /*#__PURE__*/ _async_to_generator(function() {
5421
- return __generator(this, function(_state) {
5422
- return [
5423
- 2,
5424
- new Promise(function(resolve, reject) {
5425
- if (query) {
5426
- var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
5427
- var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
5428
- if (available && !disjoint) {
5429
- // See how much time the rendering of the object took in nanoseconds.
5430
- var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
5431
- // taken to use all significant bits of the result, not just the
5432
- // least significant 32 bits.
5433
- resolve(timeElapsed / 1000 / 1000);
5434
- }
5435
- if (available || disjoint) {
5436
- // Clean up the query object.
5437
- gl.deleteQuery(query); // Don't re-enter this polling loop.
5438
- query = null;
5439
- }
5440
- available !== null && query && window.setTimeout(function() {
5441
- getTime().then(resolve).catch;
5442
- }, 1);
5443
- }
5444
- })
5445
- ];
5446
- });
5447
- });
5448
- if (!query) {
5381
+ _proto.download = function download(url, responseType, onSuccess, onError) {
5382
+ var _this = this;
5383
+ if (responseType === void 0) responseType = "json";
5384
+ if (this.start(url, onSuccess, onError)) {
5449
5385
  return;
5450
5386
  }
5451
- return {
5452
- begin: function() {
5453
- query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
5454
- },
5455
- end: function() {
5456
- gl.endQuery(ext.TIME_ELAPSED_EXT);
5457
- },
5458
- getTime: getTime
5387
+ var xhr = new XMLHttpRequest();
5388
+ var handleError = function() {
5389
+ _this.finish(url, xhr.status, xhr.response);
5459
5390
  };
5460
- }
5461
- }
5462
-
5463
- var initErrors = [];
5464
- // @ts-expect-error
5465
- var glContext = {};
5466
- if (!initErrors.length) {
5467
- initGLContext();
5468
- }
5469
- function initGLContext() {
5470
- // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
5471
- if (typeof WebGL2RenderingContext === "function") {
5472
- copy(WebGL2RenderingContext);
5473
- } else if (typeof WebGLRenderingContext !== "undefined") {
5474
- copy(WebGLRenderingContext);
5475
- copy(WebGLRenderingContext.prototype);
5476
- } else {
5477
- initErrors.push(// iOS 16 lockdown mode
5478
- "iOS16 lockdown mode, WebGL Constants not in global");
5479
- }
5480
- if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
5481
- // @ts-expect-error set default value
5482
- glContext["HALF_FLOAT"] = 5131;
5483
- }
5391
+ var handleLoad = function() {
5392
+ if (xhr.status == 200) {
5393
+ _this.finish(url, 200, xhr.response);
5394
+ } else {
5395
+ handleError();
5396
+ }
5397
+ };
5398
+ xhr.responseType = responseType;
5399
+ xhr.addEventListener("load", handleLoad);
5400
+ xhr.addEventListener("error", handleError);
5401
+ xhr.open("GET", url, true);
5402
+ xhr.send();
5403
+ };
5404
+ _proto.start = function start(url, onSuccess, onError) {
5405
+ var callbacks = this.callbacks[url];
5406
+ try {
5407
+ if (callbacks) {
5408
+ return true;
5409
+ }
5410
+ this.callbacks[url] = callbacks = [];
5411
+ } finally{
5412
+ callbacks.push(onSuccess, onError);
5413
+ }
5414
+ };
5415
+ _proto.finish = function finish(url, status, data) {
5416
+ var callbacks = this.callbacks[url];
5417
+ delete this.callbacks[url];
5418
+ var args = status == 200 ? [
5419
+ data
5420
+ ] : [
5421
+ status,
5422
+ data
5423
+ ];
5424
+ for(var i = args.length - 1, n = callbacks.length; i < n; i += 2){
5425
+ callbacks[i].apply(null, args);
5426
+ }
5427
+ };
5428
+ return Downloader;
5429
+ }();
5430
+ var webPFailed = false;
5431
+ var avifFailed = false;
5432
+ /**
5433
+ * 异步加载一个 WebP 图片文件,如果不支持 WebP,则加载 PNG 图片文件
5434
+ * @param png - PNG 图片文件的 URL
5435
+ * @param webp - WebP 图片文件的 URL
5436
+ */ function loadWebPOptional(png, webp) {
5437
+ return _loadWebPOptional.apply(this, arguments);
5484
5438
  }
5485
- function isWebGL2(gl) {
5486
- return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
5439
+ function _loadWebPOptional() {
5440
+ _loadWebPOptional = _async_to_generator(function(png, webp) {
5441
+ var image, image1, image2;
5442
+ return __generator(this, function(_state) {
5443
+ switch(_state.label){
5444
+ case 0:
5445
+ if (!(webPFailed || !webp)) return [
5446
+ 3,
5447
+ 2
5448
+ ];
5449
+ return [
5450
+ 4,
5451
+ loadImage(png)
5452
+ ];
5453
+ case 1:
5454
+ image = _state.sent();
5455
+ return [
5456
+ 2,
5457
+ {
5458
+ image: image,
5459
+ url: png
5460
+ }
5461
+ ];
5462
+ case 2:
5463
+ _state.trys.push([
5464
+ 2,
5465
+ 4,
5466
+ ,
5467
+ 6
5468
+ ]);
5469
+ return [
5470
+ 4,
5471
+ loadImage(webp)
5472
+ ];
5473
+ case 3:
5474
+ image1 = _state.sent();
5475
+ return [
5476
+ 2,
5477
+ {
5478
+ image: image1,
5479
+ url: webp
5480
+ }
5481
+ ];
5482
+ case 4:
5483
+ _state.sent();
5484
+ webPFailed = true;
5485
+ return [
5486
+ 4,
5487
+ loadImage(png)
5488
+ ];
5489
+ case 5:
5490
+ image2 = _state.sent();
5491
+ return [
5492
+ 2,
5493
+ {
5494
+ image: image2,
5495
+ url: png
5496
+ }
5497
+ ];
5498
+ case 6:
5499
+ return [
5500
+ 2
5501
+ ];
5502
+ }
5503
+ });
5504
+ });
5505
+ return _loadWebPOptional.apply(this, arguments);
5487
5506
  }
5488
- function copy(target) {
5489
- for(var name in target){
5490
- if (/^[A-Z_]/.test(name)) {
5491
- // @ts-expect-error safe to assign
5492
- glContext[name] = target[name];
5493
- }
5494
- }
5507
+ /**
5508
+ * 异步加载一个 AVIF 图片文件,如果不支持 AVIF,则加载 PNG 图片文件
5509
+ * @param png - PNG 图片文件的 URL
5510
+ * @param avif - AVIF 图片文件的 URL
5511
+ */ function loadAVIFOptional(png, avif) {
5512
+ return _loadAVIFOptional.apply(this, arguments);
5495
5513
  }
5496
- function vertexFormatType2GLType(formatType) {
5497
- switch(formatType){
5498
- case VertexFormatType.Float32:
5499
- return WebGLRenderingContext["FLOAT"];
5500
- case VertexFormatType.Int16:
5501
- return WebGLRenderingContext["SHORT"];
5502
- case VertexFormatType.Int8:
5503
- return WebGLRenderingContext["BYTE"];
5504
- case VertexFormatType.UInt16:
5505
- return WebGLRenderingContext["UNSIGNED_SHORT"];
5506
- case VertexFormatType.UInt8:
5507
- return WebGLRenderingContext["UNSIGNED_BYTE"];
5508
- default:
5509
- return WebGLRenderingContext["FLOAT"];
5510
- }
5514
+ function _loadAVIFOptional() {
5515
+ _loadAVIFOptional = _async_to_generator(function(png, avif) {
5516
+ var image, image1, image2;
5517
+ return __generator(this, function(_state) {
5518
+ switch(_state.label){
5519
+ case 0:
5520
+ if (!(avifFailed || !avif)) return [
5521
+ 3,
5522
+ 2
5523
+ ];
5524
+ return [
5525
+ 4,
5526
+ loadImage(png)
5527
+ ];
5528
+ case 1:
5529
+ image = _state.sent();
5530
+ return [
5531
+ 2,
5532
+ {
5533
+ image: image,
5534
+ url: png
5535
+ }
5536
+ ];
5537
+ case 2:
5538
+ _state.trys.push([
5539
+ 2,
5540
+ 4,
5541
+ ,
5542
+ 6
5543
+ ]);
5544
+ return [
5545
+ 4,
5546
+ loadImage(avif)
5547
+ ];
5548
+ case 3:
5549
+ image1 = _state.sent();
5550
+ return [
5551
+ 2,
5552
+ {
5553
+ image: image1,
5554
+ url: avif
5555
+ }
5556
+ ];
5557
+ case 4:
5558
+ _state.sent();
5559
+ avifFailed = true;
5560
+ return [
5561
+ 4,
5562
+ loadImage(png)
5563
+ ];
5564
+ case 5:
5565
+ image2 = _state.sent();
5566
+ return [
5567
+ 2,
5568
+ {
5569
+ image: image2,
5570
+ url: png
5571
+ }
5572
+ ];
5573
+ case 6:
5574
+ return [
5575
+ 2
5576
+ ];
5577
+ }
5578
+ });
5579
+ });
5580
+ return _loadAVIFOptional.apply(this, arguments);
5511
5581
  }
5512
- function glType2VertexFormatType(webglType) {
5513
- switch(webglType){
5514
- case WebGLRenderingContext["FLOAT"]:
5515
- return VertexFormatType.Float32;
5516
- case WebGLRenderingContext["SHORT"]:
5517
- return VertexFormatType.Int16;
5518
- case WebGLRenderingContext["BYTE"]:
5519
- return VertexFormatType.Int8;
5520
- case WebGLRenderingContext["UNSIGNED_SHORT"]:
5521
- return VertexFormatType.UInt16;
5522
- case WebGLRenderingContext["UNSIGNED_BYTE"]:
5523
- return VertexFormatType.UInt8;
5524
- default:
5525
- return VertexFormatType.Float32;
5526
- }
5582
+ /**
5583
+ * 异步加载一个图片文件
5584
+ * @param source - 图片文件的 URL、Blob 或 HTMLImageElement 对象
5585
+ */ function loadImage(source) {
5586
+ return _loadImage.apply(this, arguments);
5527
5587
  }
5528
-
5529
- exports.ShaderType = void 0;
5530
- (function(ShaderType) {
5531
- ShaderType[ShaderType["vertex"] = 0] = "vertex";
5532
- ShaderType[ShaderType["fragment"] = 1] = "fragment";
5533
- })(exports.ShaderType || (exports.ShaderType = {}));
5534
-
5535
- function valIfUndefined(val, def) {
5536
- if (val === undefined || val === null) {
5537
- return def;
5538
- }
5539
- return val;
5588
+ function _loadImage() {
5589
+ _loadImage = _async_to_generator(function(source) {
5590
+ var url, revokeURL;
5591
+ return __generator(this, function(_state) {
5592
+ url = "";
5593
+ // 1. string | Blob | HTMLImageElement 处理逻辑
5594
+ if (_instanceof1(source, HTMLImageElement)) {
5595
+ if (source.complete) {
5596
+ return [
5597
+ 2,
5598
+ source
5599
+ ];
5600
+ }
5601
+ url = source.src;
5602
+ } else if (_instanceof1(source, Blob)) {
5603
+ url = URL.createObjectURL(source);
5604
+ revokeURL = true;
5605
+ } else if (typeof source === "string") {
5606
+ url = source;
5607
+ }
5608
+ // 2. 非法类型
5609
+ if (!url) {
5610
+ throw new Error("Invalid url type: " + JSON.stringify(source) + ".");
5611
+ }
5612
+ return [
5613
+ 2,
5614
+ new Promise(function(resolve, reject) {
5615
+ var img = new Image();
5616
+ if (!/^data:/.test(url)) {
5617
+ img.crossOrigin = "*";
5618
+ }
5619
+ img.onload = function() {
5620
+ img.onload = null;
5621
+ if (revokeURL) {
5622
+ URL.revokeObjectURL(url);
5623
+ }
5624
+ return resolve(img);
5625
+ };
5626
+ img.onerror = function(e) {
5627
+ img.onerror = null;
5628
+ if (revokeURL) {
5629
+ URL.revokeObjectURL(url);
5630
+ }
5631
+ return reject("Load image fail: " + url + ", reason: " + JSON.stringify(e));
5632
+ };
5633
+ img.src = url;
5634
+ })
5635
+ ];
5636
+ });
5637
+ });
5638
+ return _loadImage.apply(this, arguments);
5540
5639
  }
5541
- function getPreMultiAlpha(blending) {
5542
- switch(blending){
5543
- case BlendingMode.ALPHA:
5544
- return 1;
5545
- case BlendingMode.ADD:
5546
- return 1;
5547
- case BlendingMode.SUBTRACTION:
5548
- return 1;
5549
- case BlendingMode.STRONG_LIGHT:
5550
- return 1;
5551
- case BlendingMode.WEAK_LIGHT:
5552
- return 1;
5553
- case BlendingMode.SUPERPOSITION:
5554
- return 2;
5555
- case BlendingMode.BRIGHTNESS:
5556
- return 3;
5557
- case BlendingMode.MULTIPLY:
5558
- return 0;
5559
- default:
5560
- // 处理undefined
5561
- return 1;
5562
- }
5640
+ /**
5641
+ * 异步加载一个二进制文件
5642
+ * @param url - 二进制文件的 URL
5643
+ */ function loadBinary(url) {
5644
+ return _loadBinary.apply(this, arguments);
5563
5645
  }
5564
- function setBlendMode(material, blendMode) {
5565
- switch(blendMode){
5566
- case undefined:
5567
- material.blendFunction = [
5568
- glContext.ONE,
5569
- glContext.ONE_MINUS_SRC_ALPHA,
5570
- glContext.ONE,
5571
- glContext.ONE_MINUS_SRC_ALPHA
5572
- ];
5573
- break;
5574
- case BlendingMode.ALPHA:
5575
- material.blendFunction = [
5576
- glContext.ONE,
5577
- glContext.ONE_MINUS_SRC_ALPHA,
5578
- glContext.ONE,
5579
- glContext.ONE_MINUS_SRC_ALPHA
5580
- ];
5581
- break;
5582
- case BlendingMode.ADD:
5583
- material.blendFunction = [
5584
- glContext.ONE,
5585
- glContext.ONE,
5586
- glContext.ONE,
5587
- glContext.ONE
5588
- ];
5589
- break;
5590
- case BlendingMode.SUBTRACTION:
5591
- material.blendFunction = [
5592
- glContext.ONE,
5593
- glContext.ONE,
5594
- glContext.ZERO,
5595
- glContext.ONE
5596
- ];
5597
- material.blendEquation = [
5598
- glContext.FUNC_REVERSE_SUBTRACT,
5599
- glContext.FUNC_REVERSE_SUBTRACT
5600
- ];
5601
- break;
5602
- case BlendingMode.SUPERPOSITION:
5603
- material.blendFunction = [
5604
- glContext.ONE,
5605
- glContext.ONE,
5606
- glContext.ONE,
5607
- glContext.ONE
5608
- ];
5609
- break;
5610
- case BlendingMode.MULTIPLY:
5611
- material.blendFunction = [
5612
- glContext.DST_COLOR,
5613
- glContext.ONE_MINUS_SRC_ALPHA,
5614
- glContext.DST_COLOR,
5615
- glContext.ONE_MINUS_SRC_ALPHA
5616
- ];
5617
- break;
5618
- case BlendingMode.BRIGHTNESS:
5619
- material.blendFunction = [
5620
- glContext.ONE,
5621
- glContext.ONE_MINUS_SRC_ALPHA,
5622
- glContext.ONE,
5623
- glContext.ONE_MINUS_SRC_ALPHA
5624
- ];
5625
- break;
5626
- case BlendingMode.STRONG_LIGHT:
5627
- material.blendFunction = [
5628
- glContext.DST_COLOR,
5629
- glContext.DST_ALPHA,
5630
- glContext.ZERO,
5631
- glContext.ONE
5632
- ];
5633
- break;
5634
- case BlendingMode.WEAK_LIGHT:
5635
- material.blendFunction = [
5636
- glContext.DST_COLOR,
5637
- glContext.ZERO,
5638
- glContext.ZERO,
5639
- glContext.ONE
5646
+ function _loadBinary() {
5647
+ _loadBinary = _async_to_generator(function(url) {
5648
+ return __generator(this, function(_state) {
5649
+ return [
5650
+ 2,
5651
+ new Promise(function(resolve, reject) {
5652
+ new Downloader().downloadBinary(url, resolve, function(status, responseText) {
5653
+ reject("Couldn't load bins " + url + ": status " + status + ", " + responseText);
5654
+ });
5655
+ })
5640
5656
  ];
5641
- break;
5642
- default:
5643
- console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
5644
- }
5657
+ });
5658
+ });
5659
+ return _loadBinary.apply(this, arguments);
5645
5660
  }
5646
- function setSideMode(material, side) {
5647
- if (side === SideMode.DOUBLE) {
5648
- material.culling = false;
5649
- } else {
5650
- material.culling = true;
5651
- material.frontFace = glContext.CW;
5652
- material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
5653
- }
5661
+ /**
5662
+ * 异步加载一个 Blob 文件
5663
+ * @param url - Blob 文件的 URL
5664
+ */ function loadBlob(url) {
5665
+ return _loadBlob.apply(this, arguments);
5654
5666
  }
5655
- function setMaskMode(material, maskMode) {
5656
- switch(maskMode){
5657
- case undefined:
5658
- material.stencilTest = false;
5659
- break;
5660
- case MaskMode.MASK:
5661
- material.stencilTest = true;
5662
- material.stencilFunc = [
5663
- glContext.ALWAYS,
5664
- glContext.ALWAYS
5665
- ];
5666
- material.stencilOpZPass = [
5667
- glContext.REPLACE,
5668
- glContext.REPLACE
5669
- ];
5670
- break;
5671
- case MaskMode.OBSCURED:
5672
- material.stencilTest = true;
5673
- material.stencilFunc = [
5674
- glContext.EQUAL,
5675
- glContext.EQUAL
5676
- ];
5677
- break;
5678
- case MaskMode.REVERSE_OBSCURED:
5679
- material.stencilTest = true;
5680
- material.stencilFunc = [
5681
- glContext.NOTEQUAL,
5682
- glContext.NOTEQUAL
5667
+ function _loadBlob() {
5668
+ _loadBlob = _async_to_generator(function(url) {
5669
+ return __generator(this, function(_state) {
5670
+ return [
5671
+ 2,
5672
+ new Promise(function(resolve, reject) {
5673
+ new Downloader().downloadBlob(url, resolve, function(status, responseText) {
5674
+ reject("Couldn't load blob " + url + ": status " + status + ", " + responseText);
5675
+ });
5676
+ })
5683
5677
  ];
5684
- break;
5685
- case MaskMode.NONE:
5686
- material.stencilTest = false;
5687
- break;
5688
- default:
5689
- console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
5690
- }
5678
+ });
5679
+ });
5680
+ return _loadBlob.apply(this, arguments);
5691
5681
  }
5692
-
5693
- function _extends() {
5694
- _extends = Object.assign || function assign(target) {
5695
- for(var i = 1; i < arguments.length; i++){
5696
- var source = arguments[i];
5697
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
5698
- }
5699
- return target;
5700
- };
5701
- return _extends.apply(this, arguments);
5682
+ /**
5683
+ * 异步加载一个视频文件
5684
+ * @param url - 视频文件的 URL 或 MediaProvider 对象
5685
+ */ function loadVideo(url) {
5686
+ return _loadVideo.apply(this, arguments);
5702
5687
  }
5703
-
5704
- exports.TextureLoadAction = void 0;
5705
- (function(TextureLoadAction) {
5706
- TextureLoadAction[TextureLoadAction["whatever"] = 0] = "whatever";
5707
- //preserve previous attachment
5708
- //load = 1,
5709
- //clear attachment
5710
- TextureLoadAction[TextureLoadAction["clear"] = 2] = "clear";
5711
- })(exports.TextureLoadAction || (exports.TextureLoadAction = {}));
5712
- exports.TextureSourceType = void 0;
5713
- (function(TextureSourceType) {
5714
- TextureSourceType[TextureSourceType["none"] = 0] = "none";
5715
- TextureSourceType[TextureSourceType["data"] = 1] = "data";
5716
- TextureSourceType[TextureSourceType["image"] = 2] = "image";
5717
- TextureSourceType[TextureSourceType["compressed"] = 3] = "compressed";
5718
- TextureSourceType[TextureSourceType["video"] = 4] = "video";
5719
- TextureSourceType[TextureSourceType["canvas"] = 5] = "canvas";
5720
- TextureSourceType[TextureSourceType["framebuffer"] = 6] = "framebuffer";
5721
- TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
5722
- })(exports.TextureSourceType || (exports.TextureSourceType = {}));
5723
-
5724
- /**
5725
- * 负责下载各种资源,并提供了一些异步加载和缓存管理的功能
5726
- */ var Downloader = /*#__PURE__*/ function() {
5727
- function Downloader() {
5728
- /**
5729
- * 存储多个回调函数的对象
5730
- */ this.callbacks = {};
5731
- }
5732
- var _proto = Downloader.prototype;
5733
- /**
5734
- * 下载一个 JSON 文件
5735
- * @param url - 要下载的 JSON 文件的 URL
5736
- * @param onSuccess - 下载成功后的回调函数
5737
- * @param onError - 下载失败后的回调函数
5738
- */ _proto.downloadJSON = function downloadJSON(url, onSuccess, onError) {
5739
- this.download(url, "json", onSuccess, onError);
5740
- };
5741
- /**
5742
- * 下载一个二进制文件
5743
- * @param url - 要下载的二进制文件的 URL
5744
- * @param onSuccess - 下载成功后的回调函数
5745
- * @param onError - 下载失败后的回调函数
5746
- */ _proto.downloadBinary = function downloadBinary(url, onSuccess, onError) {
5747
- this.download(url, "arraybuffer", onSuccess, onError);
5748
- };
5749
- /**
5750
- * 下载一个 Blob 文件
5751
- * @param url - 要下载的 Blob 文件的 URL
5752
- * @param onSuccess - 下载成功后的回调函数
5753
- * @param onError - 下载失败后的回调函数
5754
- */ _proto.downloadBlob = function downloadBlob(url, onSuccess, onError) {
5755
- this.download(url, "blob", onSuccess, onError);
5756
- };
5757
- _proto.download = function download(url, responseType, onSuccess, onError) {
5758
- var _this = this;
5759
- if (responseType === void 0) responseType = "json";
5760
- if (this.start(url, onSuccess, onError)) {
5761
- return;
5762
- }
5763
- var xhr = new XMLHttpRequest();
5764
- var handleError = function() {
5765
- _this.finish(url, xhr.status, xhr.response);
5766
- };
5767
- var handleLoad = function() {
5768
- if (xhr.status == 200) {
5769
- _this.finish(url, 200, xhr.response);
5688
+ function _loadVideo() {
5689
+ _loadVideo = _async_to_generator(function(url) {
5690
+ var video;
5691
+ return __generator(this, function(_state) {
5692
+ video = document.createElement("video");
5693
+ if (typeof url === "string") {
5694
+ video.src = url;
5770
5695
  } else {
5771
- handleError();
5696
+ video.srcObject = url;
5772
5697
  }
5773
- };
5774
- xhr.responseType = responseType;
5775
- xhr.addEventListener("load", handleLoad);
5776
- xhr.addEventListener("error", handleError);
5777
- xhr.open("GET", url, true);
5778
- xhr.send();
5779
- };
5780
- _proto.start = function start(url, onSuccess, onError) {
5781
- var callbacks = this.callbacks[url];
5782
- try {
5783
- if (callbacks) {
5784
- return true;
5698
+ video.crossOrigin = "anonymous";
5699
+ video.muted = true;
5700
+ if (isAndroid()) {
5701
+ video.setAttribute("renderer", "standard");
5785
5702
  }
5786
- this.callbacks[url] = callbacks = [];
5787
- } finally{
5788
- callbacks.push(onSuccess, onError);
5789
- }
5790
- };
5791
- _proto.finish = function finish(url, status, data) {
5792
- var callbacks = this.callbacks[url];
5793
- delete this.callbacks[url];
5794
- var args = status == 200 ? [
5795
- data
5796
- ] : [
5797
- status,
5798
- data
5799
- ];
5800
- for(var i = args.length - 1, n = callbacks.length; i < n; i += 2){
5801
- callbacks[i].apply(null, args);
5802
- }
5803
- };
5804
- return Downloader;
5805
- }();
5806
- var webPFailed = false;
5807
- var avifFailed = false;
5703
+ video.setAttribute("playsinline", "playsinline");
5704
+ return [
5705
+ 2,
5706
+ new Promise(function(resolve, reject) {
5707
+ var pending = video.play();
5708
+ if (pending) {
5709
+ void pending.then(function() {
5710
+ return resolve(video);
5711
+ });
5712
+ } else {
5713
+ video.addEventListener("loadeddata", function listener() {
5714
+ resolve(video);
5715
+ video.removeEventListener("loadeddata", listener);
5716
+ }, true);
5717
+ }
5718
+ video.addEventListener("error", function(e) {
5719
+ reject("Load video fail.");
5720
+ });
5721
+ })
5722
+ ];
5723
+ });
5724
+ });
5725
+ return _loadVideo.apply(this, arguments);
5726
+ }
5808
5727
  /**
5809
- * 异步加载一个 WebP 图片文件,如果不支持 WebP,则加载 PNG 图片文件
5810
- * @param png - PNG 图片文件的 URL
5811
- * @param webp - WebP 图片文件的 URL
5812
- */ function loadWebPOptional(png, webp) {
5813
- return _loadWebPOptional.apply(this, arguments);
5728
+ * 异步加载一个媒体文件
5729
+ * @param url
5730
+ * @param loadFn
5731
+ * @returns
5732
+ */ function loadMedia(url, loadFn) {
5733
+ return _loadMedia.apply(this, arguments);
5814
5734
  }
5815
- function _loadWebPOptional() {
5816
- _loadWebPOptional = _async_to_generator(function(png, webp) {
5817
- var image, image1, image2;
5735
+ function _loadMedia() {
5736
+ _loadMedia = _async_to_generator(function(url, loadFn) {
5818
5737
  return __generator(this, function(_state) {
5819
5738
  switch(_state.label){
5820
5739
  case 0:
5821
- if (!(webPFailed || !webp)) return [
5740
+ if (!Array.isArray(url)) return [
5822
5741
  3,
5823
- 2
5824
- ];
5825
- return [
5826
- 4,
5827
- loadImage(png)
5742
+ 5
5828
5743
  ];
5744
+ _state.label = 1;
5829
5745
  case 1:
5830
- image = _state.sent();
5831
- return [
5832
- 2,
5833
- {
5834
- image: image,
5835
- url: png
5836
- }
5837
- ];
5838
- case 2:
5839
5746
  _state.trys.push([
5840
- 2,
5841
- 4,
5747
+ 1,
5748
+ 3,
5842
5749
  ,
5843
- 6
5750
+ 5
5844
5751
  ]);
5845
5752
  return [
5846
5753
  4,
5847
- loadImage(webp)
5754
+ loadFn(url[0])
5848
5755
  ];
5849
- case 3:
5850
- image1 = _state.sent();
5756
+ case 2:
5851
5757
  return [
5852
5758
  2,
5853
- {
5854
- image: image1,
5855
- url: webp
5856
- }
5759
+ _state.sent()
5857
5760
  ];
5858
- case 4:
5761
+ case 3:
5859
5762
  _state.sent();
5860
- webPFailed = true;
5861
5763
  return [
5862
5764
  4,
5863
- loadImage(png)
5765
+ loadFn(url[1])
5864
5766
  ];
5865
- case 5:
5866
- image2 = _state.sent();
5767
+ case 4:
5867
5768
  return [
5868
5769
  2,
5869
- {
5870
- image: image2,
5871
- url: png
5872
- }
5770
+ _state.sent()
5873
5771
  ];
5874
- case 6:
5772
+ case 5:
5875
5773
  return [
5876
- 2
5774
+ 2,
5775
+ loadFn(url)
5877
5776
  ];
5878
5777
  }
5879
5778
  });
5880
5779
  });
5881
- return _loadWebPOptional.apply(this, arguments);
5780
+ return _loadMedia.apply(this, arguments);
5882
5781
  }
5883
- /**
5884
- * 异步加载一个 AVIF 图片文件,如果不支持 AVIF,则加载 PNG 图片文件
5885
- * @param png - PNG 图片文件的 URL
5886
- * @param avif - AVIF 图片文件的 URL
5887
- */ function loadAVIFOptional(png, avif) {
5888
- return _loadAVIFOptional.apply(this, arguments);
5782
+
5783
+ function deserializeMipmapTexture(textureOptions, bins, assets) {
5784
+ return _deserializeMipmapTexture.apply(this, arguments);
5889
5785
  }
5890
- function _loadAVIFOptional() {
5891
- _loadAVIFOptional = _async_to_generator(function(png, avif) {
5892
- var image, image1, image2;
5786
+ function _deserializeMipmapTexture() {
5787
+ _deserializeMipmapTexture = _async_to_generator(function(textureOptions, bins, assets, files) {
5788
+ var mipmaps, target, jobs, loadedMipmaps, mipmaps1, target1, jobs1, loadedMipmaps1, bin;
5893
5789
  return __generator(this, function(_state) {
5894
5790
  switch(_state.label){
5895
5791
  case 0:
5896
- if (!(avifFailed || !avif)) return [
5792
+ if (files === void 0) files = [];
5793
+ if (!(textureOptions.target === 34067)) return [
5897
5794
  3,
5898
5795
  2
5899
5796
  ];
5797
+ mipmaps = textureOptions.mipmaps, target = textureOptions.target;
5798
+ jobs = mipmaps.map(function(mipmap) {
5799
+ return Promise.all(mipmap.map(function(pointer) {
5800
+ // @ts-expect-error
5801
+ if (pointer.id) {
5802
+ // @ts-expect-error
5803
+ var loadedImage = assets[pointer.id];
5804
+ return loadedImage;
5805
+ } else {
5806
+ return loadMipmapImage(pointer, bins);
5807
+ }
5808
+ }));
5809
+ });
5900
5810
  return [
5901
5811
  4,
5902
- loadImage(png)
5812
+ Promise.all(jobs)
5903
5813
  ];
5904
5814
  case 1:
5905
- image = _state.sent();
5815
+ loadedMipmaps = _state.sent();
5906
5816
  return [
5907
5817
  2,
5908
- {
5909
- image: image,
5910
- url: png
5911
- }
5818
+ _extends({
5819
+ keepImageSource: false
5820
+ }, textureOptions, {
5821
+ mipmaps: loadedMipmaps,
5822
+ sourceFrom: {
5823
+ target: target,
5824
+ // bin,
5825
+ type: exports.TextureSourceType.mipmaps
5826
+ }
5827
+ })
5912
5828
  ];
5913
5829
  case 2:
5914
- _state.trys.push([
5915
- 2,
5916
- 4,
5917
- ,
5918
- 6
5919
- ]);
5830
+ // TODO: 补充测试用例
5831
+ mipmaps1 = textureOptions.mipmaps, target1 = textureOptions.target;
5832
+ jobs1 = mipmaps1.map(function(pointer) {
5833
+ return loadMipmapImage(pointer, bins);
5834
+ });
5920
5835
  return [
5921
5836
  4,
5922
- loadImage(avif)
5837
+ Promise.all(jobs1)
5923
5838
  ];
5924
5839
  case 3:
5925
- image1 = _state.sent();
5840
+ loadedMipmaps1 = _state.sent();
5841
+ bin = files[mipmaps1[0][1][0]].url;
5926
5842
  return [
5927
5843
  2,
5928
- {
5929
- image: image1,
5930
- url: avif
5931
- }
5844
+ _extends({
5845
+ keepImageSource: false
5846
+ }, textureOptions, {
5847
+ mipmaps: loadedMipmaps1,
5848
+ sourceType: exports.TextureSourceType.mipmaps,
5849
+ sourceFrom: {
5850
+ target: target1,
5851
+ bin: bin,
5852
+ type: exports.TextureSourceType.mipmaps,
5853
+ mipmaps: mipmaps1.map(function(pointer) {
5854
+ return [
5855
+ pointer[1][1],
5856
+ pointer[1][2]
5857
+ ];
5858
+ })
5859
+ }
5860
+ })
5932
5861
  ];
5933
5862
  case 4:
5934
- _state.sent();
5935
- avifFailed = true;
5936
- return [
5937
- 4,
5938
- loadImage(png)
5939
- ];
5940
- case 5:
5941
- image2 = _state.sent();
5942
- return [
5943
- 2,
5944
- {
5945
- image: image2,
5946
- url: png
5947
- }
5948
- ];
5949
- case 6:
5950
5863
  return [
5951
5864
  2
5952
5865
  ];
5953
5866
  }
5954
5867
  });
5955
5868
  });
5956
- return _loadAVIFOptional.apply(this, arguments);
5869
+ return _deserializeMipmapTexture.apply(this, arguments);
5957
5870
  }
5958
- /**
5959
- * 异步加载一个图片文件
5960
- * @param source - 图片文件的 URL、Blob 或 HTMLImageElement 对象
5961
- */ function loadImage(source) {
5962
- return _loadImage.apply(this, arguments);
5871
+ function loadMipmapImage(pointer, bins) {
5872
+ return _loadMipmapImage.apply(this, arguments);
5963
5873
  }
5964
- function _loadImage() {
5965
- _loadImage = _async_to_generator(function(source) {
5966
- var url, revokeURL;
5874
+ function _loadMipmapImage() {
5875
+ _loadMipmapImage = _async_to_generator(function(pointer, bins) {
5876
+ var _pointer_, index, start, length, bin;
5967
5877
  return __generator(this, function(_state) {
5968
- url = "";
5969
- // 1. string | Blob | HTMLImageElement 处理逻辑
5970
- if (_instanceof1(source, HTMLImageElement)) {
5971
- if (source.complete) {
5972
- return [
5973
- 2,
5974
- source
5975
- ];
5976
- }
5977
- url = source.src;
5978
- } else if (_instanceof1(source, Blob)) {
5979
- url = URL.createObjectURL(source);
5980
- revokeURL = true;
5981
- } else if (typeof source === "string") {
5982
- url = source;
5983
- }
5984
- // 2. 非法类型
5985
- if (!url) {
5986
- throw new Error("Invalid url type: " + JSON.stringify(source) + ".");
5878
+ _pointer_ = pointer[1], index = _pointer_[0], start = _pointer_[1], length = _pointer_[2];
5879
+ bin = bins[index];
5880
+ if (!bin) {
5881
+ throw new Error("Invalid bin pointer: " + JSON.stringify(pointer) + ".");
5987
5882
  }
5988
5883
  return [
5989
5884
  2,
5990
- new Promise(function(resolve, reject) {
5991
- var img = new Image();
5992
- if (!/^data:/.test(url)) {
5993
- img.crossOrigin = "*";
5994
- }
5995
- img.onload = function() {
5996
- img.onload = null;
5997
- if (revokeURL) {
5998
- URL.revokeObjectURL(url);
5999
- }
6000
- return resolve(img);
6001
- };
6002
- img.onerror = function(e) {
6003
- img.onerror = null;
6004
- if (revokeURL) {
6005
- URL.revokeObjectURL(url);
6006
- }
6007
- return reject("Load image fail: " + url + ", reason: " + JSON.stringify(e));
6008
- };
6009
- img.src = url;
6010
- })
5885
+ loadImage(new Blob([
5886
+ new Uint8Array(bin, start, length)
5887
+ ]))
6011
5888
  ];
6012
5889
  });
6013
5890
  });
6014
- return _loadImage.apply(this, arguments);
5891
+ return _loadMipmapImage.apply(this, arguments);
6015
5892
  }
5893
+
6016
5894
  /**
6017
- * 异步加载一个二进制文件
6018
- * @param url - 二进制文件的 URL
6019
- */ function loadBinary(url) {
6020
- return _loadBinary.apply(this, arguments);
5895
+ * Helper class to create a WebGL Context
5896
+ *
5897
+ * @param canvas
5898
+ * @param glType
5899
+ * @param options
5900
+ * @returns
5901
+ */ function createGLContext(canvas, glType, options) {
5902
+ if (glType === void 0) glType = "webgl";
5903
+ var context;
5904
+ if (glType === "webgl2") {
5905
+ context = canvas.getContext("webgl2", options);
5906
+ if (!context) {
5907
+ console.debug("WebGL2 context retrieval failed, falling back to WebGL context.");
5908
+ }
5909
+ }
5910
+ if (!context || glType === "webgl") {
5911
+ context = canvas.getContext("webgl", options);
5912
+ }
5913
+ if (!context) {
5914
+ throw new Error("This browser does not support WebGL or the WebGL version is incorrect. Please check your WebGL version.");
5915
+ }
5916
+ return context;
6021
5917
  }
6022
- function _loadBinary() {
6023
- _loadBinary = _async_to_generator(function(url) {
6024
- return __generator(this, function(_state) {
6025
- return [
6026
- 2,
6027
- new Promise(function(resolve, reject) {
6028
- new Downloader().downloadBinary(url, resolve, function(status, responseText) {
6029
- reject("Couldn't load bins " + url + ": status " + status + ", " + responseText);
6030
- });
6031
- })
6032
- ];
5918
+
5919
+ function gpuTimer(gl) {
5920
+ var ext = gl.getExtension("EXT_disjoint_timer_query_webgl2");
5921
+ if (ext) {
5922
+ var query = gl.createQuery();
5923
+ var getTime = /*#__PURE__*/ _async_to_generator(function() {
5924
+ return __generator(this, function(_state) {
5925
+ return [
5926
+ 2,
5927
+ new Promise(function(resolve, reject) {
5928
+ if (query) {
5929
+ var available = gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE);
5930
+ var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
5931
+ if (available && !disjoint) {
5932
+ // See how much time the rendering of the object took in nanoseconds.
5933
+ var timeElapsed = gl.getQueryParameter(query, gl.QUERY_RESULT); // Do something useful with the time. Note that care should be
5934
+ // taken to use all significant bits of the result, not just the
5935
+ // least significant 32 bits.
5936
+ resolve(timeElapsed / 1000 / 1000);
5937
+ }
5938
+ if (available || disjoint) {
5939
+ // Clean up the query object.
5940
+ gl.deleteQuery(query); // Don't re-enter this polling loop.
5941
+ query = null;
5942
+ }
5943
+ available !== null && query && window.setTimeout(function() {
5944
+ getTime().then(resolve).catch;
5945
+ }, 1);
5946
+ }
5947
+ })
5948
+ ];
5949
+ });
6033
5950
  });
6034
- });
6035
- return _loadBinary.apply(this, arguments);
5951
+ if (!query) {
5952
+ return;
5953
+ }
5954
+ return {
5955
+ begin: function() {
5956
+ query && gl.beginQuery(ext.TIME_ELAPSED_EXT, query);
5957
+ },
5958
+ end: function() {
5959
+ gl.endQuery(ext.TIME_ELAPSED_EXT);
5960
+ },
5961
+ getTime: getTime
5962
+ };
5963
+ }
6036
5964
  }
6037
- /**
6038
- * 异步加载一个 Blob 文件
6039
- * @param url - Blob 文件的 URL
6040
- */ function loadBlob(url) {
6041
- return _loadBlob.apply(this, arguments);
5965
+
5966
+ var initErrors = [];
5967
+ // @ts-expect-error
5968
+ var glContext = {};
5969
+ if (!initErrors.length) {
5970
+ initGLContext();
6042
5971
  }
6043
- function _loadBlob() {
6044
- _loadBlob = _async_to_generator(function(url) {
6045
- return __generator(this, function(_state) {
6046
- return [
6047
- 2,
6048
- new Promise(function(resolve, reject) {
6049
- new Downloader().downloadBlob(url, resolve, function(status, responseText) {
6050
- reject("Couldn't load blob " + url + ": status " + status + ", " + responseText);
6051
- });
6052
- })
6053
- ];
6054
- });
6055
- });
6056
- return _loadBlob.apply(this, arguments);
5972
+ function initGLContext() {
5973
+ // 重要:iOS 9/10 低版本需要拷贝 gl context 的 prototype,要不然会有属性值的缺失
5974
+ if (typeof WebGL2RenderingContext === "function") {
5975
+ copy(WebGL2RenderingContext);
5976
+ } else if (typeof WebGLRenderingContext !== "undefined") {
5977
+ copy(WebGLRenderingContext);
5978
+ copy(WebGLRenderingContext.prototype);
5979
+ } else {
5980
+ initErrors.push(// iOS 16 lockdown mode
5981
+ "iOS16 lockdown mode, WebGL Constants not in global");
5982
+ }
5983
+ if (!initErrors.length && !("HALF_FLOAT" in glContext)) {
5984
+ // @ts-expect-error set default value
5985
+ glContext["HALF_FLOAT"] = 5131;
5986
+ }
6057
5987
  }
6058
- /**
6059
- * 异步加载一个视频文件
6060
- * @param url - 视频文件的 URL 或 MediaProvider 对象
6061
- */ function loadVideo(url) {
6062
- return _loadVideo.apply(this, arguments);
5988
+ function isWebGL2(gl) {
5989
+ return typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext";
6063
5990
  }
6064
- function _loadVideo() {
6065
- _loadVideo = _async_to_generator(function(url) {
6066
- var video;
6067
- return __generator(this, function(_state) {
6068
- video = document.createElement("video");
6069
- if (typeof url === "string") {
6070
- video.src = url;
6071
- } else {
6072
- video.srcObject = url;
6073
- }
6074
- video.crossOrigin = "anonymous";
6075
- video.muted = true;
6076
- if (isAndroid()) {
6077
- video.setAttribute("renderer", "standard");
6078
- }
6079
- video.setAttribute("playsinline", "playsinline");
6080
- return [
6081
- 2,
6082
- new Promise(function(resolve, reject) {
6083
- var pending = video.play();
6084
- if (pending) {
6085
- void pending.then(function() {
6086
- return resolve(video);
6087
- });
6088
- } else {
6089
- video.addEventListener("loadeddata", function listener() {
6090
- resolve(video);
6091
- video.removeEventListener("loadeddata", listener);
6092
- }, true);
6093
- }
6094
- video.addEventListener("error", function(e) {
6095
- reject("Load video fail.");
6096
- });
6097
- })
6098
- ];
6099
- });
6100
- });
6101
- return _loadVideo.apply(this, arguments);
6102
- }
6103
- function loadMedia(url, loadFn) {
6104
- return _loadMedia.apply(this, arguments);
6105
- }
6106
- function _loadMedia() {
6107
- _loadMedia = _async_to_generator(function(url, loadFn) {
6108
- return __generator(this, function(_state) {
6109
- switch(_state.label){
6110
- case 0:
6111
- if (!Array.isArray(url)) return [
6112
- 3,
6113
- 5
6114
- ];
6115
- _state.label = 1;
6116
- case 1:
6117
- _state.trys.push([
6118
- 1,
6119
- 3,
6120
- ,
6121
- 5
6122
- ]);
6123
- return [
6124
- 4,
6125
- loadFn(url[0])
6126
- ];
6127
- case 2:
6128
- return [
6129
- 2,
6130
- _state.sent()
6131
- ];
6132
- case 3:
6133
- _state.sent();
6134
- return [
6135
- 4,
6136
- loadFn(url[1])
6137
- ];
6138
- case 4:
6139
- return [
6140
- 2,
6141
- _state.sent()
6142
- ];
6143
- case 5:
6144
- return [
6145
- 2,
6146
- loadFn(url)
6147
- ];
6148
- }
6149
- });
6150
- });
6151
- return _loadMedia.apply(this, arguments);
6152
- }
6153
-
6154
- function deserializeMipmapTexture(textureOptions, bins, assets) {
6155
- return _deserializeMipmapTexture.apply(this, arguments);
6156
- }
6157
- function _deserializeMipmapTexture() {
6158
- _deserializeMipmapTexture = _async_to_generator(function(textureOptions, bins, assets, files) {
6159
- var mipmaps, target, jobs, loadedMipmaps, mipmaps1, target1, jobs1, loadedMipmaps1, bin;
6160
- return __generator(this, function(_state) {
6161
- switch(_state.label){
6162
- case 0:
6163
- if (files === void 0) files = [];
6164
- if (!(textureOptions.target === 34067)) return [
6165
- 3,
6166
- 2
6167
- ];
6168
- mipmaps = textureOptions.mipmaps, target = textureOptions.target;
6169
- jobs = mipmaps.map(function(mipmap) {
6170
- return Promise.all(mipmap.map(function(pointer) {
6171
- // @ts-expect-error
6172
- if (pointer.id) {
6173
- // @ts-expect-error
6174
- var loadedImage = assets[pointer.id];
6175
- return loadedImage;
6176
- } else {
6177
- return loadMipmapImage(pointer, bins);
6178
- }
6179
- }));
6180
- });
6181
- return [
6182
- 4,
6183
- Promise.all(jobs)
6184
- ];
6185
- case 1:
6186
- loadedMipmaps = _state.sent();
6187
- return [
6188
- 2,
6189
- _extends({
6190
- keepImageSource: false
6191
- }, textureOptions, {
6192
- mipmaps: loadedMipmaps,
6193
- sourceFrom: {
6194
- target: target,
6195
- // bin,
6196
- type: exports.TextureSourceType.mipmaps
6197
- }
6198
- })
6199
- ];
6200
- case 2:
6201
- // TODO: 补充测试用例
6202
- mipmaps1 = textureOptions.mipmaps, target1 = textureOptions.target;
6203
- jobs1 = mipmaps1.map(function(pointer) {
6204
- return loadMipmapImage(pointer, bins);
6205
- });
6206
- return [
6207
- 4,
6208
- Promise.all(jobs1)
6209
- ];
6210
- case 3:
6211
- loadedMipmaps1 = _state.sent();
6212
- bin = files[mipmaps1[0][1][0]].url;
6213
- return [
6214
- 2,
6215
- _extends({
6216
- keepImageSource: false
6217
- }, textureOptions, {
6218
- mipmaps: loadedMipmaps1,
6219
- sourceType: exports.TextureSourceType.mipmaps,
6220
- sourceFrom: {
6221
- target: target1,
6222
- bin: bin,
6223
- type: exports.TextureSourceType.mipmaps,
6224
- mipmaps: mipmaps1.map(function(pointer) {
6225
- return [
6226
- pointer[1][1],
6227
- pointer[1][2]
6228
- ];
6229
- })
6230
- }
6231
- })
6232
- ];
6233
- case 4:
6234
- return [
6235
- 2
6236
- ];
6237
- }
6238
- });
6239
- });
6240
- return _deserializeMipmapTexture.apply(this, arguments);
5991
+ function copy(target) {
5992
+ for(var name in target){
5993
+ if (/^[A-Z_]/.test(name)) {
5994
+ // @ts-expect-error safe to assign
5995
+ glContext[name] = target[name];
5996
+ }
5997
+ }
6241
5998
  }
6242
- function loadMipmapImage(pointer, bins) {
6243
- return _loadMipmapImage.apply(this, arguments);
5999
+ function vertexFormatType2GLType(formatType) {
6000
+ switch(formatType){
6001
+ case VertexFormatType.Float32:
6002
+ return WebGLRenderingContext["FLOAT"];
6003
+ case VertexFormatType.Int16:
6004
+ return WebGLRenderingContext["SHORT"];
6005
+ case VertexFormatType.Int8:
6006
+ return WebGLRenderingContext["BYTE"];
6007
+ case VertexFormatType.UInt16:
6008
+ return WebGLRenderingContext["UNSIGNED_SHORT"];
6009
+ case VertexFormatType.UInt8:
6010
+ return WebGLRenderingContext["UNSIGNED_BYTE"];
6011
+ default:
6012
+ return WebGLRenderingContext["FLOAT"];
6013
+ }
6244
6014
  }
6245
- function _loadMipmapImage() {
6246
- _loadMipmapImage = _async_to_generator(function(pointer, bins) {
6247
- var _pointer_, index, start, length, bin;
6248
- return __generator(this, function(_state) {
6249
- _pointer_ = pointer[1], index = _pointer_[0], start = _pointer_[1], length = _pointer_[2];
6250
- bin = bins[index];
6251
- if (!bin) {
6252
- throw new Error("Invalid bin pointer: " + JSON.stringify(pointer) + ".");
6253
- }
6254
- return [
6255
- 2,
6256
- loadImage(new Blob([
6257
- new Uint8Array(bin, start, length)
6258
- ]))
6259
- ];
6260
- });
6261
- });
6262
- return _loadMipmapImage.apply(this, arguments);
6015
+ function glType2VertexFormatType(webglType) {
6016
+ switch(webglType){
6017
+ case WebGLRenderingContext["FLOAT"]:
6018
+ return VertexFormatType.Float32;
6019
+ case WebGLRenderingContext["SHORT"]:
6020
+ return VertexFormatType.Int16;
6021
+ case WebGLRenderingContext["BYTE"]:
6022
+ return VertexFormatType.Int8;
6023
+ case WebGLRenderingContext["UNSIGNED_SHORT"]:
6024
+ return VertexFormatType.UInt16;
6025
+ case WebGLRenderingContext["UNSIGNED_BYTE"]:
6026
+ return VertexFormatType.UInt8;
6027
+ default:
6028
+ return VertexFormatType.Float32;
6029
+ }
6263
6030
  }
6264
6031
 
6265
6032
  var seed$9 = 1;
@@ -6890,10 +6657,284 @@ function getDefaultTextureFactory() {
6890
6657
  if (!g) {
6891
6658
  g = new TextureFactory();
6892
6659
  }
6893
- return g;
6894
- }
6895
- function setDefaultTextureFactory(factory) {
6896
- g = factory;
6660
+ return g;
6661
+ }
6662
+ function setDefaultTextureFactory(factory) {
6663
+ g = factory;
6664
+ }
6665
+
6666
+ function _array_like_to_array(arr, len) {
6667
+ if (len == null || len > arr.length) len = arr.length;
6668
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
6669
+ return arr2;
6670
+ }
6671
+
6672
+ function _unsupported_iterable_to_array(o, minLen) {
6673
+ if (!o) return;
6674
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
6675
+ var n = Object.prototype.toString.call(o).slice(8, -1);
6676
+ if (n === "Object" && o.constructor) n = o.constructor.name;
6677
+ if (n === "Map" || n === "Set") return Array.from(n);
6678
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
6679
+ }
6680
+
6681
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
6682
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
6683
+ if (it) return (it = it.call(o)).next.bind(it);
6684
+ // Fallback for engines without symbol support
6685
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
6686
+ if (it) o = it;
6687
+ var i = 0;
6688
+ return function() {
6689
+ if (i >= o.length) return {
6690
+ done: true
6691
+ };
6692
+ return {
6693
+ done: false,
6694
+ value: o[i++]
6695
+ };
6696
+ };
6697
+ }
6698
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
6699
+ }
6700
+
6701
+ exports.ShaderCompileResultStatus = void 0;
6702
+ (function(ShaderCompileResultStatus) {
6703
+ ShaderCompileResultStatus[ShaderCompileResultStatus["noShader"] = 0] = "noShader";
6704
+ ShaderCompileResultStatus[ShaderCompileResultStatus["success"] = 1] = "success";
6705
+ ShaderCompileResultStatus[ShaderCompileResultStatus["fail"] = 2] = "fail";
6706
+ ShaderCompileResultStatus[ShaderCompileResultStatus["compiling"] = 3] = "compiling";
6707
+ })(exports.ShaderCompileResultStatus || (exports.ShaderCompileResultStatus = {}));
6708
+ exports.GLSLVersion = void 0;
6709
+ (function(GLSLVersion) {
6710
+ GLSLVersion["GLSL1"] = "100";
6711
+ GLSLVersion["GLSL3"] = "300 es";
6712
+ })(exports.GLSLVersion || (exports.GLSLVersion = {}));
6713
+ var ShaderVariant = /*#__PURE__*/ function(EffectsObject) {
6714
+ _inherits(ShaderVariant, EffectsObject);
6715
+ function ShaderVariant(engine, source) {
6716
+ var _this;
6717
+ _this = EffectsObject.call(this, engine) || this;
6718
+ _this.source = source;
6719
+ return _this;
6720
+ }
6721
+ return ShaderVariant;
6722
+ }(EffectsObject);
6723
+ exports.Shader = /*#__PURE__*/ function(EffectsObject) {
6724
+ _inherits(Shader, EffectsObject);
6725
+ function Shader() {
6726
+ return EffectsObject.apply(this, arguments);
6727
+ }
6728
+ var _proto = Shader.prototype;
6729
+ _proto.createVariant = function createVariant(macros) {
6730
+ var shaderMacros = [];
6731
+ if (macros) {
6732
+ for(var _iterator = _create_for_of_iterator_helper_loose(Object.keys(macros)), _step; !(_step = _iterator()).done;){
6733
+ var key = _step.value;
6734
+ shaderMacros.push([
6735
+ key,
6736
+ macros[key]
6737
+ ]);
6738
+ }
6739
+ }
6740
+ var shaderVariant = this.engine.getShaderLibrary().createShader(this.shaderData, shaderMacros);
6741
+ shaderVariant.shader = this;
6742
+ return shaderVariant;
6743
+ };
6744
+ _proto.fromData = function fromData(data) {
6745
+ EffectsObject.prototype.fromData.call(this, data);
6746
+ this.shaderData = data;
6747
+ };
6748
+ return Shader;
6749
+ }(EffectsObject);
6750
+ exports.Shader = __decorate([
6751
+ effectsClass(DataType.Shader)
6752
+ ], exports.Shader);
6753
+
6754
+ var EFFECTS_COPY_MESH_NAME = "effects-internal-copy";
6755
+ var COPY_MESH_SHADER_ID = "effects-internal-copy-mesh";
6756
+ var COPY_VERTEX_SHADER = "\nprecision highp float;\nattribute vec2 aPos;\nvarying vec2 vTex;\nvoid main(){\n gl_Position = vec4(aPos,0.,1.0);\n vTex = (aPos + vec2(1.0))/2.;\n}";
6757
+ var COPY_FRAGMENT_SHADER = "precision mediump float;\nvarying vec2 vTex;\n\n#ifdef DEPTH_TEXTURE\nuniform sampler2D uDepth;\n#extension GL_EXT_frag_depth : enable\n#endif\nvoid main(){\n #ifdef DEPTH_TEXTURE\n gl_FragDepthEXT = texture2D(uDepth,vTex).r;\n #endif\n}\n";
6758
+ function createCopyShader(level, writeDepth) {
6759
+ var webgl2 = level === 2;
6760
+ return {
6761
+ name: EFFECTS_COPY_MESH_NAME,
6762
+ vertex: COPY_VERTEX_SHADER,
6763
+ fragment: COPY_FRAGMENT_SHADER,
6764
+ glslVersion: webgl2 ? exports.GLSLVersion.GLSL3 : exports.GLSLVersion.GLSL1,
6765
+ macros: [
6766
+ [
6767
+ "DEPTH_TEXTURE",
6768
+ !!writeDepth
6769
+ ]
6770
+ ],
6771
+ // @ts-expect-error
6772
+ cacheId: COPY_MESH_SHADER_ID + +writeDepth
6773
+ };
6774
+ }
6775
+
6776
+ exports.ShaderType = void 0;
6777
+ (function(ShaderType) {
6778
+ ShaderType[ShaderType["vertex"] = 0] = "vertex";
6779
+ ShaderType[ShaderType["fragment"] = 1] = "fragment";
6780
+ })(exports.ShaderType || (exports.ShaderType = {}));
6781
+
6782
+ function valIfUndefined(val, def) {
6783
+ if (val === undefined || val === null) {
6784
+ return def;
6785
+ }
6786
+ return val;
6787
+ }
6788
+ function getPreMultiAlpha(blending) {
6789
+ switch(blending){
6790
+ case BlendingMode.ALPHA:
6791
+ return 1;
6792
+ case BlendingMode.ADD:
6793
+ return 1;
6794
+ case BlendingMode.SUBTRACTION:
6795
+ return 1;
6796
+ case BlendingMode.STRONG_LIGHT:
6797
+ return 1;
6798
+ case BlendingMode.WEAK_LIGHT:
6799
+ return 1;
6800
+ case BlendingMode.SUPERPOSITION:
6801
+ return 2;
6802
+ case BlendingMode.BRIGHTNESS:
6803
+ return 3;
6804
+ case BlendingMode.MULTIPLY:
6805
+ return 0;
6806
+ default:
6807
+ // 处理undefined
6808
+ return 1;
6809
+ }
6810
+ }
6811
+ function setBlendMode(material, blendMode) {
6812
+ switch(blendMode){
6813
+ case undefined:
6814
+ material.blendFunction = [
6815
+ glContext.ONE,
6816
+ glContext.ONE_MINUS_SRC_ALPHA,
6817
+ glContext.ONE,
6818
+ glContext.ONE_MINUS_SRC_ALPHA
6819
+ ];
6820
+ break;
6821
+ case BlendingMode.ALPHA:
6822
+ material.blendFunction = [
6823
+ glContext.ONE,
6824
+ glContext.ONE_MINUS_SRC_ALPHA,
6825
+ glContext.ONE,
6826
+ glContext.ONE_MINUS_SRC_ALPHA
6827
+ ];
6828
+ break;
6829
+ case BlendingMode.ADD:
6830
+ material.blendFunction = [
6831
+ glContext.ONE,
6832
+ glContext.ONE,
6833
+ glContext.ONE,
6834
+ glContext.ONE
6835
+ ];
6836
+ break;
6837
+ case BlendingMode.SUBTRACTION:
6838
+ material.blendFunction = [
6839
+ glContext.ONE,
6840
+ glContext.ONE,
6841
+ glContext.ZERO,
6842
+ glContext.ONE
6843
+ ];
6844
+ material.blendEquation = [
6845
+ glContext.FUNC_REVERSE_SUBTRACT,
6846
+ glContext.FUNC_REVERSE_SUBTRACT
6847
+ ];
6848
+ break;
6849
+ case BlendingMode.SUPERPOSITION:
6850
+ material.blendFunction = [
6851
+ glContext.ONE,
6852
+ glContext.ONE,
6853
+ glContext.ONE,
6854
+ glContext.ONE
6855
+ ];
6856
+ break;
6857
+ case BlendingMode.MULTIPLY:
6858
+ material.blendFunction = [
6859
+ glContext.DST_COLOR,
6860
+ glContext.ONE_MINUS_SRC_ALPHA,
6861
+ glContext.DST_COLOR,
6862
+ glContext.ONE_MINUS_SRC_ALPHA
6863
+ ];
6864
+ break;
6865
+ case BlendingMode.BRIGHTNESS:
6866
+ material.blendFunction = [
6867
+ glContext.ONE,
6868
+ glContext.ONE_MINUS_SRC_ALPHA,
6869
+ glContext.ONE,
6870
+ glContext.ONE_MINUS_SRC_ALPHA
6871
+ ];
6872
+ break;
6873
+ case BlendingMode.STRONG_LIGHT:
6874
+ material.blendFunction = [
6875
+ glContext.DST_COLOR,
6876
+ glContext.DST_ALPHA,
6877
+ glContext.ZERO,
6878
+ glContext.ONE
6879
+ ];
6880
+ break;
6881
+ case BlendingMode.WEAK_LIGHT:
6882
+ material.blendFunction = [
6883
+ glContext.DST_COLOR,
6884
+ glContext.ZERO,
6885
+ glContext.ZERO,
6886
+ glContext.ONE
6887
+ ];
6888
+ break;
6889
+ default:
6890
+ console.warn("BlendMode " + blendMode + " not in specification, please set blend params separately.");
6891
+ }
6892
+ }
6893
+ function setSideMode(material, side) {
6894
+ if (side === SideMode.DOUBLE) {
6895
+ material.culling = false;
6896
+ } else {
6897
+ material.culling = true;
6898
+ material.frontFace = glContext.CW;
6899
+ material.cullFace = side === SideMode.BACK ? glContext.BACK : glContext.FRONT;
6900
+ }
6901
+ }
6902
+ function setMaskMode(material, maskMode) {
6903
+ switch(maskMode){
6904
+ case undefined:
6905
+ material.stencilTest = false;
6906
+ break;
6907
+ case MaskMode.MASK:
6908
+ material.stencilTest = true;
6909
+ material.stencilFunc = [
6910
+ glContext.ALWAYS,
6911
+ glContext.ALWAYS
6912
+ ];
6913
+ material.stencilOpZPass = [
6914
+ glContext.REPLACE,
6915
+ glContext.REPLACE
6916
+ ];
6917
+ break;
6918
+ case MaskMode.OBSCURED:
6919
+ material.stencilTest = true;
6920
+ material.stencilFunc = [
6921
+ glContext.EQUAL,
6922
+ glContext.EQUAL
6923
+ ];
6924
+ break;
6925
+ case MaskMode.REVERSE_OBSCURED:
6926
+ material.stencilTest = true;
6927
+ material.stencilFunc = [
6928
+ glContext.NOTEQUAL,
6929
+ glContext.NOTEQUAL
6930
+ ];
6931
+ break;
6932
+ case MaskMode.NONE:
6933
+ material.stencilTest = false;
6934
+ break;
6935
+ default:
6936
+ console.warn("MaskMode " + maskMode + " not in specification, please set stencil params seperately.");
6937
+ }
6897
6938
  }
6898
6939
 
6899
6940
  /**
@@ -13106,6 +13147,27 @@ var Vector4Curve = /*#__PURE__*/ function(ValueGetter) {
13106
13147
  };
13107
13148
  return Vector4Curve;
13108
13149
  }(ValueGetter);
13150
+ var Vector2Curve = /*#__PURE__*/ function(ValueGetter) {
13151
+ _inherits(Vector2Curve, ValueGetter);
13152
+ function Vector2Curve() {
13153
+ var _this;
13154
+ _this = ValueGetter.apply(this, arguments) || this;
13155
+ _this.value = new Vector2();
13156
+ return _this;
13157
+ }
13158
+ var _proto = Vector2Curve.prototype;
13159
+ _proto.onCreate = function onCreate(arg) {
13160
+ this.xCurve = createValueGetter(arg[0]);
13161
+ this.yCurve = createValueGetter(arg[1]);
13162
+ };
13163
+ _proto.getValue = function getValue(t) {
13164
+ var x = this.xCurve.getValue(t);
13165
+ var y = this.yCurve.getValue(t);
13166
+ this.value.set(x, y);
13167
+ return this.value;
13168
+ };
13169
+ return Vector2Curve;
13170
+ }(ValueGetter);
13109
13171
 
13110
13172
  var SPRITE_VERTEX_STRIDE = 6;
13111
13173
  var SEMANTIC_PRE_COLOR_ATTACHMENT_0 = "PRE_COLOR_0";
@@ -13169,6 +13231,8 @@ var map$1 = (_obj$3 = {}, _obj$3[ValueType.RANDOM] = function(props) {
13169
13231
  return new ColorCurve(props);
13170
13232
  }, _obj$3[ValueType.VECTOR4_CURVE] = function(props) {
13171
13233
  return new Vector4Curve(props);
13234
+ }, _obj$3[ValueType.VECTOR2_CURVE] = function(props) {
13235
+ return new Vector2Curve(props);
13172
13236
  }, _obj$3);
13173
13237
  function createValueGetter(args) {
13174
13238
  if (!args || !isNaN(+args)) {
@@ -13293,13 +13357,39 @@ var ColorCurve = /*#__PURE__*/ function(ValueGetter) {
13293
13357
  this.color = color;
13294
13358
  this.material.setVector4("_Color", new Vector4().setFromArray(color));
13295
13359
  };
13296
- /**
13297
- * 设置当前 Mesh 的纹理
13298
- * @since 2.0.0
13299
- * @param texture - 纹理对象
13300
- */ _proto.setTexture = function setTexture(texture) {
13301
- this.renderer.texture = texture;
13302
- this.material.setTexture("_MainTex", texture);
13360
+ _proto.setTexture = function setTexture(input) {
13361
+ var _this = this;
13362
+ return _async_to_generator(function() {
13363
+ var texture;
13364
+ return __generator(this, function(_state) {
13365
+ switch(_state.label){
13366
+ case 0:
13367
+ if (!(typeof input === "string")) return [
13368
+ 3,
13369
+ 2
13370
+ ];
13371
+ return [
13372
+ 4,
13373
+ Texture.fromImage(input, _this.item.engine)
13374
+ ];
13375
+ case 1:
13376
+ texture = _state.sent();
13377
+ return [
13378
+ 3,
13379
+ 3
13380
+ ];
13381
+ case 2:
13382
+ texture = input;
13383
+ _state.label = 3;
13384
+ case 3:
13385
+ _this.renderer.texture = texture;
13386
+ _this.material.setTexture("_MainTex", texture);
13387
+ return [
13388
+ 2
13389
+ ];
13390
+ }
13391
+ });
13392
+ })();
13303
13393
  };
13304
13394
  /**
13305
13395
  * @internal
@@ -13561,6 +13651,8 @@ function getImageItemRenderInfo(item) {
13561
13651
  };
13562
13652
  }
13563
13653
 
13654
+ // Based on:
13655
+ // https://github.com/pixijs/pixijs/blob/dev/src/maths/shapes/ShapePrimitive.ts
13564
13656
  var ShapePrimitive = function ShapePrimitive() {
13565
13657
  };
13566
13658
 
@@ -14666,6 +14758,7 @@ function triangulate(contours) {
14666
14758
  return triangleVerts;
14667
14759
  }
14668
14760
 
14761
+ // Based on:
14669
14762
  /**
14670
14763
  * A class to define a shape via user defined coordinates.
14671
14764
  */ var Polygon = /*#__PURE__*/ function(ShapePrimitive) {
@@ -14765,12 +14858,13 @@ function triangulate(contours) {
14765
14858
  var triangles = triangulate([
14766
14859
  points
14767
14860
  ]);
14861
+ var indexStart = vertices.length / 2;
14768
14862
  for(var i = 0; i < triangles.length; i++){
14769
- vertices[verticesOffset + i] = triangles[i];
14863
+ vertices[verticesOffset * 2 + i] = triangles[i];
14770
14864
  }
14771
14865
  var vertexCount = triangles.length / 2;
14772
14866
  for(var i1 = 0; i1 < vertexCount; i1++){
14773
- indices[indicesOffset + i1] = i1;
14867
+ indices[indicesOffset + i1] = indexStart + i1;
14774
14868
  }
14775
14869
  };
14776
14870
  _create_class(Polygon, [
@@ -14892,6 +14986,7 @@ function recursive(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance, le
14892
14986
  recursive(x1234, y1234, x234, y234, x34, y34, x4, y4, points, distanceTolerance, level + 1);
14893
14987
  }
14894
14988
 
14989
+ // Based on:
14895
14990
  /**
14896
14991
  * The Ellipse object is used to help draw graphics and can also be used to specify a hit area for containers.
14897
14992
  */ var Ellipse = /*#__PURE__*/ function(ShapePrimitive) {
@@ -15098,6 +15193,7 @@ function recursive(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance, le
15098
15193
  return Ellipse;
15099
15194
  }(ShapePrimitive);
15100
15195
 
15196
+ // Based on:
15101
15197
  var StarType;
15102
15198
  (function(StarType) {
15103
15199
  StarType[StarType["Star"] = 0] = "Star";
@@ -15166,12 +15262,13 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15166
15262
  var triangles = triangulate([
15167
15263
  points
15168
15264
  ]);
15265
+ var indexStart = vertices.length / 2;
15169
15266
  for(var i = 0; i < triangles.length; i++){
15170
- vertices[verticesOffset + i] = triangles[i];
15267
+ vertices[verticesOffset * 2 + i] = triangles[i];
15171
15268
  }
15172
15269
  var vertexCount = triangles.length / 2;
15173
15270
  for(var i1 = 0; i1 < vertexCount; i1++){
15174
- indices[indicesOffset + i1] = i1;
15271
+ indices[indicesOffset + i1] = indexStart + i1;
15175
15272
  }
15176
15273
  };
15177
15274
  _proto.buildStarPath = function buildStarPath() {
@@ -15242,6 +15339,7 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15242
15339
  return PolyStar;
15243
15340
  }(ShapePrimitive);
15244
15341
 
15342
+ // Based on:
15245
15343
  // const tempPoints = [new Point(), new Point(), new Point(), new Point()];
15246
15344
  /**
15247
15345
  * The `Rectangle` object is an area defined by its position, as indicated by its upper-left corner
@@ -15565,6 +15663,7 @@ var PolyStar = /*#__PURE__*/ function(ShapePrimitive) {
15565
15663
  return Rectangle;
15566
15664
  }(ShapePrimitive);
15567
15665
 
15666
+ // Based on:
15568
15667
  var ShapePath = /*#__PURE__*/ function() {
15569
15668
  function ShapePath(graphicsPath) {
15570
15669
  this.graphicsPath = graphicsPath;
@@ -15723,6 +15822,7 @@ var ShapePath = /*#__PURE__*/ function() {
15723
15822
  return ShapePath;
15724
15823
  }();
15725
15824
 
15825
+ // Based on:
15726
15826
  var GraphicsPath = /*#__PURE__*/ function() {
15727
15827
  function GraphicsPath() {
15728
15828
  this.instructions = [];
@@ -15860,14 +15960,433 @@ var GraphicsPath = /*#__PURE__*/ function() {
15860
15960
  return GraphicsPath;
15861
15961
  }();
15862
15962
 
15963
+ // Based on:
15964
+ /**
15965
+ * The Point object represents a location in a two-dimensional coordinate system, where `x` represents
15966
+ * the position on the horizontal axis and `y` represents the position on the vertical axis.
15967
+ */ var Point = /*#__PURE__*/ function() {
15968
+ function Point(x, y) {
15969
+ if (x === void 0) x = 0;
15970
+ if (y === void 0) y = 0;
15971
+ /**
15972
+ * Position of the point on the x axis
15973
+ */ this.x = 0;
15974
+ /**
15975
+ * Position of the point on the y axis
15976
+ */ this.y = 0;
15977
+ this.x = x;
15978
+ this.y = y;
15979
+ }
15980
+ var _proto = Point.prototype;
15981
+ /**
15982
+ * Creates a clone of this point
15983
+ * @returns A clone of this point
15984
+ */ _proto.clone = function clone() {
15985
+ return new Point(this.x, this.y);
15986
+ };
15987
+ /**
15988
+ * Copies `x` and `y` from the given point into this point
15989
+ * @param p - The point to copy from
15990
+ * @returns The point instance itself
15991
+ */ _proto.copyFrom = function copyFrom(p) {
15992
+ this.set(p.x, p.y);
15993
+ return this;
15994
+ };
15995
+ /**
15996
+ * Copies this point's x and y into the given point (`p`).
15997
+ * @param p - The point to copy to. Can be any of type that is or extends `PointData`
15998
+ * @returns The point (`p`) with values updated
15999
+ */ _proto.copyTo = function copyTo(p) {
16000
+ p.set(this.x, this.y);
16001
+ return p;
16002
+ };
16003
+ /**
16004
+ * Accepts another point (`p`) and returns `true` if the given point is equal to this point
16005
+ * @param p - The point to check
16006
+ * @returns Returns `true` if both `x` and `y` are equal
16007
+ */ _proto.equals = function equals(p) {
16008
+ return p.x === this.x && p.y === this.y;
16009
+ };
16010
+ /**
16011
+ * Sets the point to a new `x` and `y` position.
16012
+ * If `y` is omitted, both `x` and `y` will be set to `x`.
16013
+ * @param {number} [x=0] - position of the point on the `x` axis
16014
+ * @param {number} [y=x] - position of the point on the `y` axis
16015
+ * @returns The point instance itself
16016
+ */ _proto.set = function set(x, y) {
16017
+ if (x === void 0) x = 0;
16018
+ if (y === void 0) y = x;
16019
+ this.x = x;
16020
+ this.y = y;
16021
+ return this;
16022
+ };
16023
+ _create_class(Point, null, [
16024
+ {
16025
+ key: "shared",
16026
+ get: /**
16027
+ * A static Point object with `x` and `y` values of `0`. Can be used to avoid creating new objects multiple times.
16028
+ * @readonly
16029
+ */ function get() {
16030
+ tempPoint.x = 0;
16031
+ tempPoint.y = 0;
16032
+ return tempPoint;
16033
+ }
16034
+ }
16035
+ ]);
16036
+ return Point;
16037
+ }();
16038
+ var tempPoint = new Point();
16039
+
16040
+ // Based on:
16041
+ var closePointEps = 1e-4;
16042
+ var curveEps = 0.0001;
16043
+ /**
16044
+ * Buffers vertices to draw a square cap.
16045
+ *
16046
+ * @internal
16047
+ * @private
16048
+ * @param x - X-coord of end point
16049
+ * @param y - Y-coord of end point
16050
+ * @param nx - X-coord of line normal pointing inside
16051
+ * @param ny - Y-coord of line normal pointing inside
16052
+ * @param innerWeight - Weight of inner points
16053
+ * @param outerWeight - Weight of outer points
16054
+ * @param clockwise - Whether the cap is drawn clockwise
16055
+ * @param verts - vertex buffer
16056
+ * @returns - no. of vertices pushed
16057
+ */ function square(x, y, nx, ny, innerWeight, outerWeight, clockwise, /* rotation for square (true at left end, false at right end) */ verts) {
16058
+ var ix = x - nx * innerWeight;
16059
+ var iy = y - ny * innerWeight;
16060
+ var ox = x + nx * outerWeight;
16061
+ var oy = y + ny * outerWeight;
16062
+ /* Rotate nx,ny for extension vector */ var exx;
16063
+ var eyy;
16064
+ if (clockwise) {
16065
+ exx = ny;
16066
+ eyy = -nx;
16067
+ } else {
16068
+ exx = -ny;
16069
+ eyy = nx;
16070
+ }
16071
+ /* [i|0]x,y extended at cap */ var eix = ix + exx;
16072
+ var eiy = iy + eyy;
16073
+ var eox = ox + exx;
16074
+ var eoy = oy + eyy;
16075
+ /* Square itself must be inserted clockwise*/ verts.push(eix, eiy);
16076
+ verts.push(eox, eoy);
16077
+ return 2;
16078
+ }
16079
+ /**
16080
+ * Buffers vertices to draw an arc at the line joint or cap.
16081
+ *
16082
+ * @internal
16083
+ * @private
16084
+ * @param cx - X-coord of center
16085
+ * @param cy - Y-coord of center
16086
+ * @param sx - X-coord of arc start
16087
+ * @param sy - Y-coord of arc start
16088
+ * @param ex - X-coord of arc end
16089
+ * @param ey - Y-coord of arc end
16090
+ * @param verts - buffer of vertices
16091
+ * @param clockwise - orientation of vertices
16092
+ * @returns - no. of vertices pushed
16093
+ */ function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
16094
+ var cx2p0x = sx - cx;
16095
+ var cy2p0y = sy - cy;
16096
+ var angle0 = Math.atan2(cx2p0x, cy2p0y);
16097
+ var angle1 = Math.atan2(ex - cx, ey - cy);
16098
+ if (clockwise && angle0 < angle1) {
16099
+ angle0 += Math.PI * 2;
16100
+ } else if (!clockwise && angle0 > angle1) {
16101
+ angle1 += Math.PI * 2;
16102
+ }
16103
+ var startAngle = angle0;
16104
+ var angleDiff = angle1 - angle0;
16105
+ var absAngleDiff = Math.abs(angleDiff);
16106
+ var radius = Math.sqrt(cx2p0x * cx2p0x + cy2p0y * cy2p0y);
16107
+ var segCount = (15 * absAngleDiff * Math.sqrt(radius) / Math.PI >> 0) + 1;
16108
+ var angleInc = angleDiff / segCount;
16109
+ startAngle += angleInc;
16110
+ if (clockwise) {
16111
+ verts.push(cx, cy);
16112
+ verts.push(sx, sy);
16113
+ for(var i = 1, angle = startAngle; i < segCount; i++, angle += angleInc){
16114
+ verts.push(cx, cy);
16115
+ verts.push(cx + Math.sin(angle) * radius, cy + Math.cos(angle) * radius);
16116
+ }
16117
+ verts.push(cx, cy);
16118
+ verts.push(ex, ey);
16119
+ } else {
16120
+ verts.push(sx, sy);
16121
+ verts.push(cx, cy);
16122
+ for(var i1 = 1, angle2 = startAngle; i1 < segCount; i1++, angle2 += angleInc){
16123
+ verts.push(cx + Math.sin(angle2) * radius, cy + Math.cos(angle2) * radius);
16124
+ verts.push(cx, cy);
16125
+ }
16126
+ verts.push(ex, ey);
16127
+ verts.push(cx, cy);
16128
+ }
16129
+ return segCount * 2;
16130
+ }
16131
+ function getOrientationOfPoints(points) {
16132
+ var m = points.length;
16133
+ if (m < 6) {
16134
+ return 1;
16135
+ }
16136
+ var area = 0;
16137
+ for(var i = 0, x1 = points[m - 2], y1 = points[m - 1]; i < m; i += 2){
16138
+ var x2 = points[i];
16139
+ var y2 = points[i + 1];
16140
+ area += (x2 - x1) * (y2 + y1);
16141
+ x1 = x2;
16142
+ y1 = y2;
16143
+ }
16144
+ if (area < 0) {
16145
+ return -1;
16146
+ }
16147
+ return 1;
16148
+ }
16149
+ /**
16150
+ * Builds a line to draw using the polygon method.
16151
+ * @param points
16152
+ * @param lineStyle
16153
+ * @param flipAlignment
16154
+ * @param closed
16155
+ * @param vertices
16156
+ * @param _verticesStride
16157
+ * @param _verticesOffset
16158
+ * @param indices
16159
+ * @param _indicesOffset
16160
+ */ function buildLine(points, lineStyle, flipAlignment, closed, // alignment:number,
16161
+ vertices, _verticesStride, _verticesOffset, indices, _indicesOffset) {
16162
+ // const shape = graphicsData.shape as Polygon;
16163
+ // let points = graphicsData.points || shape.points.slice();
16164
+ var eps = closePointEps;
16165
+ if (points.length === 0) {
16166
+ return;
16167
+ }
16168
+ var style = lineStyle;
16169
+ var alignment = style.alignment;
16170
+ if (lineStyle.alignment !== 0.5) {
16171
+ // rotate the points!
16172
+ var orientation = getOrientationOfPoints(points);
16173
+ if (flipAlignment) {
16174
+ orientation *= -1;
16175
+ }
16176
+ alignment = (alignment - 0.5) * orientation + 0.5;
16177
+ }
16178
+ // get first and last point.. figure out the middle!
16179
+ var firstPoint = new Point(points[0], points[1]);
16180
+ var lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
16181
+ var closedShape = closed;
16182
+ var closedPath = Math.abs(firstPoint.x - lastPoint.x) < eps && Math.abs(firstPoint.y - lastPoint.y) < eps;
16183
+ // if the first point is the last point - gonna have issues :)
16184
+ if (closedShape) {
16185
+ // need to clone as we are going to slightly modify the shape..
16186
+ points = points.slice();
16187
+ if (closedPath) {
16188
+ points.pop();
16189
+ points.pop();
16190
+ lastPoint.set(points[points.length - 2], points[points.length - 1]);
16191
+ }
16192
+ var midPointX = (firstPoint.x + lastPoint.x) * 0.5;
16193
+ var midPointY = (lastPoint.y + firstPoint.y) * 0.5;
16194
+ points.unshift(midPointX, midPointY);
16195
+ points.push(midPointX, midPointY);
16196
+ }
16197
+ var verts = vertices;
16198
+ var length = points.length / 2;
16199
+ var indexCount = points.length;
16200
+ var indexStart = verts.length / 2;
16201
+ // Max. inner and outer width
16202
+ var width = style.width / 2;
16203
+ var widthSquared = width * width;
16204
+ var miterLimitSquared = style.miterLimit * style.miterLimit;
16205
+ /* Line segments of interest where (x1,y1) forms the corner. */ var x0 = points[0];
16206
+ var y0 = points[1];
16207
+ var x1 = points[2];
16208
+ var y1 = points[3];
16209
+ var x2 = 0;
16210
+ var y2 = 0;
16211
+ /* perp[?](x|y) = the line normal with magnitude lineWidth. */ var perpX = -(y0 - y1);
16212
+ var perpY = x0 - x1;
16213
+ var perp1x = 0;
16214
+ var perp1y = 0;
16215
+ var dist = Math.sqrt(perpX * perpX + perpY * perpY);
16216
+ perpX /= dist;
16217
+ perpY /= dist;
16218
+ perpX *= width;
16219
+ perpY *= width;
16220
+ var ratio = alignment; // 0.5;
16221
+ var innerWeight = (1 - ratio) * 2;
16222
+ var outerWeight = ratio * 2;
16223
+ if (!closedShape) {
16224
+ if (style.cap === "round") {
16225
+ indexCount += round(x0 - perpX * (innerWeight - outerWeight) * 0.5, y0 - perpY * (innerWeight - outerWeight) * 0.5, x0 - perpX * innerWeight, y0 - perpY * innerWeight, x0 + perpX * outerWeight, y0 + perpY * outerWeight, verts, true) + 2;
16226
+ } else if (style.cap === "square") {
16227
+ indexCount += square(x0, y0, perpX, perpY, innerWeight, outerWeight, true, verts);
16228
+ }
16229
+ }
16230
+ // Push first point (below & above vertices)
16231
+ verts.push(x0 - perpX * innerWeight, y0 - perpY * innerWeight);
16232
+ verts.push(x0 + perpX * outerWeight, y0 + perpY * outerWeight);
16233
+ for(var i = 1; i < length - 1; ++i){
16234
+ x0 = points[(i - 1) * 2];
16235
+ y0 = points[(i - 1) * 2 + 1];
16236
+ x1 = points[i * 2];
16237
+ y1 = points[i * 2 + 1];
16238
+ x2 = points[(i + 1) * 2];
16239
+ y2 = points[(i + 1) * 2 + 1];
16240
+ perpX = -(y0 - y1);
16241
+ perpY = x0 - x1;
16242
+ dist = Math.sqrt(perpX * perpX + perpY * perpY);
16243
+ perpX /= dist;
16244
+ perpY /= dist;
16245
+ perpX *= width;
16246
+ perpY *= width;
16247
+ perp1x = -(y1 - y2);
16248
+ perp1y = x1 - x2;
16249
+ dist = Math.sqrt(perp1x * perp1x + perp1y * perp1y);
16250
+ perp1x /= dist;
16251
+ perp1y /= dist;
16252
+ perp1x *= width;
16253
+ perp1y *= width;
16254
+ /* d[x|y](0|1) = the component displacement between points p(0,1|1,2) */ var dx0 = x1 - x0;
16255
+ var dy0 = y0 - y1;
16256
+ var dx1 = x1 - x2;
16257
+ var dy1 = y2 - y1;
16258
+ /* +ve if internal angle < 90 degree, -ve if internal angle > 90 degree. */ var dot = dx0 * dx1 + dy0 * dy1;
16259
+ /* +ve if internal angle counterclockwise, -ve if internal angle clockwise. */ var cross = dy0 * dx1 - dy1 * dx0;
16260
+ var clockwise = cross < 0;
16261
+ /* Going nearly parallel? */ /* atan(0.001) ~= 0.001 rad ~= 0.057 degree */ if (Math.abs(cross) < 0.001 * Math.abs(dot)) {
16262
+ verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16263
+ verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16264
+ /* 180 degree corner? */ if (dot >= 0) {
16265
+ if (style.join === "round") {
16266
+ indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 4;
16267
+ } else {
16268
+ indexCount += 2;
16269
+ }
16270
+ verts.push(x1 - perp1x * outerWeight, y1 - perp1y * outerWeight);
16271
+ verts.push(x1 + perp1x * innerWeight, y1 + perp1y * innerWeight);
16272
+ }
16273
+ continue;
16274
+ }
16275
+ /* p[x|y] is the miter point. pDist is the distance between miter point and p1. */ var c1 = (-perpX + x0) * (-perpY + y1) - (-perpX + x1) * (-perpY + y0);
16276
+ var c2 = (-perp1x + x2) * (-perp1y + y1) - (-perp1x + x1) * (-perp1y + y2);
16277
+ var px = (dx0 * c2 - dx1 * c1) / cross;
16278
+ var py = (dy1 * c1 - dy0 * c2) / cross;
16279
+ var pDist = (px - x1) * (px - x1) + (py - y1) * (py - y1);
16280
+ /* Inner miter point */ var imx = x1 + (px - x1) * innerWeight;
16281
+ var imy = y1 + (py - y1) * innerWeight;
16282
+ /* Outer miter point */ var omx = x1 - (px - x1) * outerWeight;
16283
+ var omy = y1 - (py - y1) * outerWeight;
16284
+ /* Is the inside miter point too far away, creating a spike? */ var smallerInsideSegmentSq = Math.min(dx0 * dx0 + dy0 * dy0, dx1 * dx1 + dy1 * dy1);
16285
+ var insideWeight = clockwise ? innerWeight : outerWeight;
16286
+ var smallerInsideDiagonalSq = smallerInsideSegmentSq + insideWeight * insideWeight * widthSquared;
16287
+ var insideMiterOk = pDist <= smallerInsideDiagonalSq;
16288
+ if (insideMiterOk) {
16289
+ if (style.join === "bevel" || pDist / widthSquared > miterLimitSquared) {
16290
+ if (clockwise) /* rotating at inner angle */ {
16291
+ verts.push(imx, imy); // inner miter point
16292
+ verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
16293
+ verts.push(imx, imy); // inner miter point
16294
+ verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight); // second segment's outer vertex
16295
+ } else /* rotating at outer angle */ {
16296
+ verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight); // first segment's inner vertex
16297
+ verts.push(omx, omy); // outer miter point
16298
+ verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight); // second segment's outer vertex
16299
+ verts.push(omx, omy); // outer miter point
16300
+ }
16301
+ indexCount += 2;
16302
+ } else if (style.join === "round") {
16303
+ if (clockwise) /* arc is outside */ {
16304
+ verts.push(imx, imy);
16305
+ verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16306
+ indexCount += round(x1, y1, x1 + perpX * outerWeight, y1 + perpY * outerWeight, x1 + perp1x * outerWeight, y1 + perp1y * outerWeight, verts, true) + 4;
16307
+ verts.push(imx, imy);
16308
+ verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight);
16309
+ } else /* arc is inside */ {
16310
+ verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16311
+ verts.push(omx, omy);
16312
+ indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 4;
16313
+ verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight);
16314
+ verts.push(omx, omy);
16315
+ }
16316
+ } else {
16317
+ verts.push(imx, imy);
16318
+ verts.push(omx, omy);
16319
+ }
16320
+ } else {
16321
+ verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight); // first segment's inner vertex
16322
+ verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight); // first segment's outer vertex
16323
+ if (style.join === "round") {
16324
+ if (clockwise) /* arc is outside */ {
16325
+ indexCount += round(x1, y1, x1 + perpX * outerWeight, y1 + perpY * outerWeight, x1 + perp1x * outerWeight, y1 + perp1y * outerWeight, verts, true) + 2;
16326
+ } else /* arc is inside */ {
16327
+ indexCount += round(x1, y1, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 - perp1x * innerWeight, y1 - perp1y * innerWeight, verts, false) + 2;
16328
+ }
16329
+ } else if (style.join === "miter" && pDist / widthSquared <= miterLimitSquared) {
16330
+ if (clockwise) {
16331
+ verts.push(omx, omy); // inner miter point
16332
+ verts.push(omx, omy); // inner miter point
16333
+ } else {
16334
+ verts.push(imx, imy); // outer miter point
16335
+ verts.push(imx, imy); // outer miter point
16336
+ }
16337
+ indexCount += 2;
16338
+ }
16339
+ verts.push(x1 - perp1x * innerWeight, y1 - perp1y * innerWeight); // second segment's inner vertex
16340
+ verts.push(x1 + perp1x * outerWeight, y1 + perp1y * outerWeight); // second segment's outer vertex
16341
+ indexCount += 2;
16342
+ }
16343
+ }
16344
+ x0 = points[(length - 2) * 2];
16345
+ y0 = points[(length - 2) * 2 + 1];
16346
+ x1 = points[(length - 1) * 2];
16347
+ y1 = points[(length - 1) * 2 + 1];
16348
+ perpX = -(y0 - y1);
16349
+ perpY = x0 - x1;
16350
+ dist = Math.sqrt(perpX * perpX + perpY * perpY);
16351
+ perpX /= dist;
16352
+ perpY /= dist;
16353
+ perpX *= width;
16354
+ perpY *= width;
16355
+ verts.push(x1 - perpX * innerWeight, y1 - perpY * innerWeight);
16356
+ verts.push(x1 + perpX * outerWeight, y1 + perpY * outerWeight);
16357
+ if (!closedShape) {
16358
+ if (style.cap === "round") {
16359
+ indexCount += round(x1 - perpX * (innerWeight - outerWeight) * 0.5, y1 - perpY * (innerWeight - outerWeight) * 0.5, x1 - perpX * innerWeight, y1 - perpY * innerWeight, x1 + perpX * outerWeight, y1 + perpY * outerWeight, verts, false) + 2;
16360
+ } else if (style.cap === "square") {
16361
+ indexCount += square(x1, y1, perpX, perpY, innerWeight, outerWeight, false, verts);
16362
+ }
16363
+ }
16364
+ // const indices = graphicsGeometry.indices;
16365
+ var eps2 = curveEps * curveEps;
16366
+ // indices.push(indexStart);
16367
+ for(var i1 = indexStart; i1 < indexCount + indexStart - 2; ++i1){
16368
+ x0 = verts[i1 * 2];
16369
+ y0 = verts[i1 * 2 + 1];
16370
+ x1 = verts[(i1 + 1) * 2];
16371
+ y1 = verts[(i1 + 1) * 2 + 1];
16372
+ x2 = verts[(i1 + 2) * 2];
16373
+ y2 = verts[(i1 + 2) * 2 + 1];
16374
+ /* Skip zero area triangles */ if (Math.abs(x0 * (y1 - y2) + x1 * (y2 - y0) + x2 * (y0 - y1)) < eps2) {
16375
+ continue;
16376
+ }
16377
+ indices.push(i1, i1 + 1, i1 + 2);
16378
+ }
16379
+ }
16380
+
15863
16381
  exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15864
16382
  _inherits(ShapeComponent, MeshComponent);
15865
16383
  function ShapeComponent(engine) {
15866
16384
  var _this;
15867
16385
  _this = MeshComponent.call(this, engine) || this;
15868
- _this.path = new GraphicsPath();
16386
+ _this.isStroke = false;
16387
+ _this.graphicsPath = new GraphicsPath();
15869
16388
  _this.curveValues = [];
15870
- _this.animated = true;
16389
+ _this.shapeDirty = true;
15871
16390
  _this.vert = "\nprecision highp float;\n\nattribute vec3 aPos;//x y\n\nuniform mat4 effects_MatrixVP;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_ObjectToWorld;\n\nvoid main() {\n vec4 pos = vec4(aPos.xyz, 1.0);\n gl_Position = effects_MatrixVP * effects_ObjectToWorld * pos;\n}\n";
15872
16391
  _this.frag = "\nprecision highp float;\n\nuniform vec4 _Color;\n\nvoid main() {\n vec4 color = _Color;\n color.rgb *= color.a;\n gl_FragColor = color;\n}\n";
15873
16392
  if (!_this.geometry) {
@@ -15915,6 +16434,13 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15915
16434
  _this.material.depthTest = true;
15916
16435
  _this.material.blending = true;
15917
16436
  }
16437
+ _this.strokeAttributes = {
16438
+ width: 1,
16439
+ alignment: 0.5,
16440
+ cap: "butt",
16441
+ join: "miter",
16442
+ miterLimit: 10
16443
+ };
15918
16444
  return _this;
15919
16445
  }
15920
16446
  var _proto = ShapeComponent.prototype;
@@ -15922,10 +16448,10 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15922
16448
  this.item.getHitTestParams = this.getHitTestParams;
15923
16449
  };
15924
16450
  _proto.onUpdate = function onUpdate(dt) {
15925
- if (this.animated) {
16451
+ if (this.shapeDirty) {
15926
16452
  this.buildPath(this.data);
15927
- this.buildGeometryFromPath(this.path.shapePath);
15928
- this.animated = false;
16453
+ this.buildGeometryFromPath(this.graphicsPath.shapePath);
16454
+ this.shapeDirty = false;
15929
16455
  }
15930
16456
  };
15931
16457
  _proto.buildGeometryFromPath = function buildGeometryFromPath(shapePath) {
@@ -15940,7 +16466,13 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15940
16466
  var indexOffset = indices.length;
15941
16467
  var vertOffset = vertices.length / 2;
15942
16468
  shape.build(points);
15943
- shape.triangulate(points, vertices, vertOffset, indices, indexOffset);
16469
+ if (!this.isStroke) {
16470
+ shape.triangulate(points, vertices, vertOffset, indices, indexOffset);
16471
+ } else {
16472
+ var close = true;
16473
+ var lineStyle = this.strokeAttributes;
16474
+ buildLine(points, lineStyle, false, close, vertices, 2, vertOffset, indices);
16475
+ }
15944
16476
  }
15945
16477
  var vertexCount = vertices.length / 2;
15946
16478
  // get the current attribute and index arrays from the geometry, avoiding re-creation
@@ -15953,7 +16485,7 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15953
16485
  if (!uvArray || uvArray.length < vertexCount * 2) {
15954
16486
  uvArray = new Float32Array(vertexCount * 2);
15955
16487
  }
15956
- if (!indexArray) {
16488
+ if (!indexArray || indexArray.length < indices.length) {
15957
16489
  indexArray = new Uint16Array(indices.length);
15958
16490
  }
15959
16491
  // set position and uv attribute array
@@ -15976,7 +16508,7 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15976
16508
  this.geometry.setDrawCount(indices.length);
15977
16509
  };
15978
16510
  _proto.buildPath = function buildPath(data) {
15979
- this.path.clear();
16511
+ this.graphicsPath.clear();
15980
16512
  var shapeData = data;
15981
16513
  switch(shapeData.type){
15982
16514
  case ShapePrimitiveType.Custom:
@@ -15985,9 +16517,9 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
15985
16517
  var points = customData.points;
15986
16518
  var easingIns = customData.easingIns;
15987
16519
  var easingOuts = customData.easingOuts;
15988
- this.curveValues = [];
15989
16520
  for(var _iterator = _create_for_of_iterator_helper_loose(customData.shapes), _step; !(_step = _iterator()).done;){
15990
16521
  var shape = _step.value;
16522
+ this.curveValues = [];
15991
16523
  this.setFillColor(shape.fill);
15992
16524
  var indices = shape.indexes;
15993
16525
  for(var i = 1; i < indices.length; i++){
@@ -16005,42 +16537,42 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16005
16537
  controlPoint1: easingOuts[indices[indices.length - 1].easingOut],
16006
16538
  controlPoint2: easingIns[indices[0].easingIn]
16007
16539
  });
16008
- }
16009
- this.path.moveTo(this.curveValues[this.curveValues.length - 1].point.x, this.curveValues[this.curveValues.length - 1].point.y);
16010
- for(var _iterator1 = _create_for_of_iterator_helper_loose(this.curveValues), _step1; !(_step1 = _iterator1()).done;){
16011
- var curveValue = _step1.value;
16012
- var point = curveValue.point;
16013
- var control1 = curveValue.controlPoint1;
16014
- var control2 = curveValue.controlPoint2;
16015
- this.path.bezierCurveTo(control1.x, control1.y, control2.x, control2.y, point.x, point.y, 1);
16540
+ this.graphicsPath.moveTo(this.curveValues[this.curveValues.length - 1].point.x, this.curveValues[this.curveValues.length - 1].point.y);
16541
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.curveValues), _step1; !(_step1 = _iterator1()).done;){
16542
+ var curveValue = _step1.value;
16543
+ var point = curveValue.point;
16544
+ var control1 = curveValue.controlPoint1;
16545
+ var control2 = curveValue.controlPoint2;
16546
+ this.graphicsPath.bezierCurveTo(control1.x, control1.y, control2.x, control2.y, point.x, point.y, 1);
16547
+ }
16016
16548
  }
16017
16549
  break;
16018
16550
  }
16019
16551
  case ShapePrimitiveType.Ellipse:
16020
16552
  {
16021
16553
  var ellipseData = shapeData;
16022
- this.path.ellipse(0, 0, ellipseData.xRadius, ellipseData.yRadius);
16554
+ this.graphicsPath.ellipse(0, 0, ellipseData.xRadius, ellipseData.yRadius);
16023
16555
  this.setFillColor(ellipseData.fill);
16024
16556
  break;
16025
16557
  }
16026
16558
  case ShapePrimitiveType.Rectangle:
16027
16559
  {
16028
16560
  var rectangleData = shapeData;
16029
- this.path.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height);
16561
+ this.graphicsPath.rect(-rectangleData.width / 2, -rectangleData.height / 2, rectangleData.width, rectangleData.height);
16030
16562
  this.setFillColor(rectangleData.fill);
16031
16563
  break;
16032
16564
  }
16033
16565
  case ShapePrimitiveType.Star:
16034
16566
  {
16035
16567
  var starData = shapeData;
16036
- this.path.polyStar(starData.pointCount, starData.outerRadius, starData.innerRadius, starData.outerRoundness, starData.innerRoundness, StarType.Star);
16568
+ this.graphicsPath.polyStar(starData.pointCount, starData.outerRadius, starData.innerRadius, starData.outerRoundness, starData.innerRoundness, StarType.Star);
16037
16569
  this.setFillColor(starData.fill);
16038
16570
  break;
16039
16571
  }
16040
16572
  case ShapePrimitiveType.Polygon:
16041
16573
  {
16042
16574
  var polygonData = shapeData;
16043
- this.path.polyStar(polygonData.pointCount, polygonData.radius, polygonData.radius, polygonData.roundness, polygonData.roundness, StarType.Polygon);
16575
+ this.graphicsPath.polyStar(polygonData.pointCount, polygonData.radius, polygonData.radius, polygonData.roundness, polygonData.roundness, StarType.Polygon);
16044
16576
  this.setFillColor(polygonData.fill);
16045
16577
  break;
16046
16578
  }
@@ -16055,6 +16587,12 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16055
16587
  _proto.fromData = function fromData(data) {
16056
16588
  MeshComponent.prototype.fromData.call(this, data);
16057
16589
  this.data = data;
16590
+ this.shapeDirty = true;
16591
+ var strokeParam = data.stroke;
16592
+ if (strokeParam) {
16593
+ this.isStroke = true;
16594
+ this.strokeAttributes.width = strokeParam.width;
16595
+ }
16058
16596
  var material = this.material;
16059
16597
  //@ts-expect-error // TODO 新版蒙版上线后重构
16060
16598
  material.stencilRef = data.renderer.mask !== undefined ? [
@@ -16064,6 +16602,15 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16064
16602
  //@ts-expect-error // TODO 新版蒙版上线后重构
16065
16603
  setMaskMode(material, data.renderer.maskMode);
16066
16604
  };
16605
+ _create_class(ShapeComponent, [
16606
+ {
16607
+ key: "path",
16608
+ get: function get() {
16609
+ this.shapeDirty = true;
16610
+ return this.data;
16611
+ }
16612
+ }
16613
+ ]);
16067
16614
  return ShapeComponent;
16068
16615
  }(MeshComponent);
16069
16616
  exports.ShapeComponent = __decorate([
@@ -18751,10 +19298,19 @@ var TEMPLATE_USE_OFFSCREEN_CANVAS = "offscreen_canvas";
18751
19298
  // 后处理配置相关
18752
19299
  var POST_PROCESS_SETTINGS = "post_process_settings";
18753
19300
  var config = {};
18754
- function getConfig(name) {
19301
+ /**
19302
+ * 获取全局配置项
19303
+ * @param name
19304
+ * @returns
19305
+ */ function getConfig(name) {
18755
19306
  return config[name];
18756
19307
  }
18757
- function setConfig(name, value) {
19308
+ /**
19309
+ * 设置全局配置项
19310
+ * @param name
19311
+ * @param value
19312
+ * @returns
19313
+ */ function setConfig(name, value) {
18758
19314
  return config[name] = value;
18759
19315
  }
18760
19316
 
@@ -23101,88 +23657,81 @@ var PropertyClipPlayable = /*#__PURE__*/ function(Playable) {
23101
23657
  return PropertyClipPlayable;
23102
23658
  }(Playable);
23103
23659
 
23104
- var ColorPropertyMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23105
- _inherits(ColorPropertyMixerPlayable, TrackMixerPlayable);
23106
- function ColorPropertyMixerPlayable() {
23660
+ var PropertyMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23661
+ _inherits(PropertyMixerPlayable, TrackMixerPlayable);
23662
+ function PropertyMixerPlayable() {
23107
23663
  var _this;
23108
23664
  _this = TrackMixerPlayable.apply(this, arguments) || this;
23109
23665
  _this.propertyName = "";
23110
23666
  return _this;
23111
23667
  }
23112
- var _proto = ColorPropertyMixerPlayable.prototype;
23668
+ var _proto = PropertyMixerPlayable.prototype;
23113
23669
  _proto.evaluate = function evaluate(context) {
23114
23670
  var boundObject = context.output.getUserData();
23115
23671
  if (!boundObject) {
23116
23672
  return;
23117
23673
  }
23118
23674
  var hasInput = false;
23119
- var value = boundObject[this.propertyName];
23120
- if (!_instanceof1(value, Color)) {
23675
+ this.propertyValue = boundObject[this.propertyName];
23676
+ if (this.propertyValue === undefined || this.propertyValue === null) {
23121
23677
  return;
23122
23678
  }
23123
- value.setZero();
23679
+ this.resetPropertyValue();
23124
23680
  // evaluate the curve
23125
23681
  for(var i = 0; i < this.clipPlayables.length; i++){
23126
23682
  var weight = this.getClipWeight(i);
23127
23683
  if (weight > 0) {
23128
23684
  var propertyClipPlayable = this.getClipPlayable(i);
23129
23685
  if (!_instanceof1(propertyClipPlayable, PropertyClipPlayable)) {
23130
- console.error("ColorPropertyMixerPlayable received incompatible input");
23686
+ console.error("PropertyTrack added non-PropertyPlayableAsset");
23131
23687
  continue;
23132
23688
  }
23133
23689
  var curveValue = propertyClipPlayable.value;
23134
- value.r += curveValue.r * weight;
23135
- value.g += curveValue.g * weight;
23136
- value.b += curveValue.b * weight;
23137
- value.a += curveValue.a * weight;
23690
+ this.addWeightedValue(curveValue, weight);
23138
23691
  hasInput = true;
23139
23692
  }
23140
23693
  }
23141
23694
  // set value
23142
23695
  if (hasInput) {
23143
- boundObject[this.propertyName] = value;
23696
+ boundObject[this.propertyName] = this.propertyValue;
23144
23697
  }
23145
23698
  };
23146
- return ColorPropertyMixerPlayable;
23699
+ return PropertyMixerPlayable;
23147
23700
  }(TrackMixerPlayable);
23148
23701
 
23149
- var FloatPropertyMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23150
- _inherits(FloatPropertyMixerPlayable, TrackMixerPlayable);
23702
+ var ColorPropertyMixerPlayable = /*#__PURE__*/ function(PropertyMixerPlayable) {
23703
+ _inherits(ColorPropertyMixerPlayable, PropertyMixerPlayable);
23704
+ function ColorPropertyMixerPlayable() {
23705
+ return PropertyMixerPlayable.apply(this, arguments);
23706
+ }
23707
+ var _proto = ColorPropertyMixerPlayable.prototype;
23708
+ _proto.resetPropertyValue = function resetPropertyValue() {
23709
+ this.propertyValue.setZero();
23710
+ };
23711
+ _proto.addWeightedValue = function addWeightedValue(curveValue, weight) {
23712
+ var result = this.propertyValue;
23713
+ result.r += curveValue.r * weight;
23714
+ result.g += curveValue.g * weight;
23715
+ result.b += curveValue.b * weight;
23716
+ result.a += curveValue.a * weight;
23717
+ };
23718
+ return ColorPropertyMixerPlayable;
23719
+ }(PropertyMixerPlayable);
23720
+
23721
+ var FloatPropertyMixerPlayable = /*#__PURE__*/ function(PropertyMixerPlayable) {
23722
+ _inherits(FloatPropertyMixerPlayable, PropertyMixerPlayable);
23151
23723
  function FloatPropertyMixerPlayable() {
23152
- var _this;
23153
- _this = TrackMixerPlayable.apply(this, arguments) || this;
23154
- _this.propertyName = "";
23155
- return _this;
23724
+ return PropertyMixerPlayable.apply(this, arguments);
23156
23725
  }
23157
23726
  var _proto = FloatPropertyMixerPlayable.prototype;
23158
- _proto.evaluate = function evaluate(context) {
23159
- var boundObject = context.output.getUserData();
23160
- if (!boundObject) {
23161
- return;
23162
- }
23163
- var hasInput = false;
23164
- var value = 0;
23165
- // evaluate the curve
23166
- for(var i = 0; i < this.clipPlayables.length; i++){
23167
- var weight = this.getClipWeight(i);
23168
- if (weight > 0) {
23169
- var propertyClipPlayable = this.getClipPlayable(i);
23170
- if (!_instanceof1(propertyClipPlayable, PropertyClipPlayable)) {
23171
- console.error("FloatPropertyTrack added non-FloatPropertyPlayableAsset");
23172
- continue;
23173
- }
23174
- var curveValue = propertyClipPlayable.value;
23175
- value += curveValue * weight;
23176
- hasInput = true;
23177
- }
23178
- }
23179
- // set value
23180
- if (hasInput) {
23181
- boundObject[this.propertyName] = value;
23182
- }
23727
+ _proto.resetPropertyValue = function resetPropertyValue() {
23728
+ this.propertyValue = 0;
23729
+ };
23730
+ _proto.addWeightedValue = function addWeightedValue(curveValue, weight) {
23731
+ this.propertyValue += curveValue * weight;
23183
23732
  };
23184
23733
  return FloatPropertyMixerPlayable;
23185
- }(TrackMixerPlayable);
23734
+ }(PropertyMixerPlayable);
23186
23735
 
23187
23736
  var ParticleMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23188
23737
  _inherits(ParticleMixerPlayable, TrackMixerPlayable);
@@ -23926,50 +24475,40 @@ var TransformMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23926
24475
  return TransformMixerPlayable;
23927
24476
  }(TrackMixerPlayable);
23928
24477
 
23929
- var Vector4PropertyMixerPlayable = /*#__PURE__*/ function(TrackMixerPlayable) {
23930
- _inherits(Vector4PropertyMixerPlayable, TrackMixerPlayable);
24478
+ var Vector4PropertyMixerPlayable = /*#__PURE__*/ function(PropertyMixerPlayable) {
24479
+ _inherits(Vector4PropertyMixerPlayable, PropertyMixerPlayable);
23931
24480
  function Vector4PropertyMixerPlayable() {
23932
- var _this;
23933
- _this = TrackMixerPlayable.apply(this, arguments) || this;
23934
- _this.propertyName = "";
23935
- return _this;
24481
+ return PropertyMixerPlayable.apply(this, arguments);
23936
24482
  }
23937
24483
  var _proto = Vector4PropertyMixerPlayable.prototype;
23938
- _proto.evaluate = function evaluate(context) {
23939
- var boundObject = context.output.getUserData();
23940
- if (!boundObject) {
23941
- return;
23942
- }
23943
- var hasInput = false;
23944
- var value = boundObject[this.propertyName];
23945
- if (!_instanceof1(value, Vector4)) {
23946
- return;
23947
- }
23948
- value.setZero();
23949
- // evaluate the curve
23950
- for(var i = 0; i < this.clipPlayables.length; i++){
23951
- var weight = this.getClipWeight(i);
23952
- if (weight > 0) {
23953
- var propertyClipPlayable = this.getClipPlayable(i);
23954
- if (!_instanceof1(propertyClipPlayable, PropertyClipPlayable)) {
23955
- console.error("Vector4PropertyTrack added non-Vector4PropertyPlayableAsset");
23956
- continue;
23957
- }
23958
- var curveValue = propertyClipPlayable.value;
23959
- value.x += curveValue.x * weight;
23960
- value.y += curveValue.y * weight;
23961
- value.z += curveValue.z * weight;
23962
- value.w += curveValue.w * weight;
23963
- hasInput = true;
23964
- }
23965
- }
23966
- // set value
23967
- if (hasInput) {
23968
- boundObject[this.propertyName] = value;
23969
- }
24484
+ _proto.resetPropertyValue = function resetPropertyValue() {
24485
+ this.propertyValue.setZero();
24486
+ };
24487
+ _proto.addWeightedValue = function addWeightedValue(curveValue, weight) {
24488
+ var result = this.propertyValue;
24489
+ result.x += curveValue.x * weight;
24490
+ result.y += curveValue.y * weight;
24491
+ result.z += curveValue.z * weight;
24492
+ result.w += curveValue.w * weight;
23970
24493
  };
23971
24494
  return Vector4PropertyMixerPlayable;
23972
- }(TrackMixerPlayable);
24495
+ }(PropertyMixerPlayable);
24496
+ var Vector2PropertyMixerPlayable = /*#__PURE__*/ function(PropertyMixerPlayable) {
24497
+ _inherits(Vector2PropertyMixerPlayable, PropertyMixerPlayable);
24498
+ function Vector2PropertyMixerPlayable() {
24499
+ return PropertyMixerPlayable.apply(this, arguments);
24500
+ }
24501
+ var _proto = Vector2PropertyMixerPlayable.prototype;
24502
+ _proto.resetPropertyValue = function resetPropertyValue() {
24503
+ this.propertyValue.setZero();
24504
+ };
24505
+ _proto.addWeightedValue = function addWeightedValue(curveValue, weight) {
24506
+ var result = this.propertyValue;
24507
+ result.x += curveValue.x * weight;
24508
+ result.y += curveValue.y * weight;
24509
+ };
24510
+ return Vector2PropertyMixerPlayable;
24511
+ }(PropertyMixerPlayable);
23973
24512
 
23974
24513
  /**
23975
24514
  * @since 2.0.0
@@ -24350,6 +24889,26 @@ exports.Vector4PropertyTrack = /*#__PURE__*/ function(PropertyTrack) {
24350
24889
  exports.Vector4PropertyTrack = __decorate([
24351
24890
  effectsClass(DataType.Vector4PropertyTrack)
24352
24891
  ], exports.Vector4PropertyTrack);
24892
+ exports.Vector2PropertyTrack = /*#__PURE__*/ function(PropertyTrack) {
24893
+ _inherits(Vector2PropertyTrack, PropertyTrack);
24894
+ function Vector2PropertyTrack() {
24895
+ return PropertyTrack.apply(this, arguments);
24896
+ }
24897
+ var _proto = Vector2PropertyTrack.prototype;
24898
+ _proto.createTrackMixer = function createTrackMixer(graph) {
24899
+ var mixer = new Vector2PropertyMixerPlayable(graph);
24900
+ var propertyNames = this.propertyNames;
24901
+ if (propertyNames.length > 0) {
24902
+ var propertyName = propertyNames[propertyNames.length - 1];
24903
+ mixer.propertyName = propertyName;
24904
+ }
24905
+ return mixer;
24906
+ };
24907
+ return Vector2PropertyTrack;
24908
+ }(PropertyTrack);
24909
+ exports.Vector2PropertyTrack = __decorate([
24910
+ effectsClass("Vector2PropertyTrack")
24911
+ ], exports.Vector2PropertyTrack);
24353
24912
 
24354
24913
  exports.ColorPropertyTrack = /*#__PURE__*/ function(PropertyTrack) {
24355
24914
  _inherits(ColorPropertyTrack, PropertyTrack);
@@ -24616,8 +25175,28 @@ __decorate([
24616
25175
  serialize()
24617
25176
  ], exports.Vector4PropertyPlayableAsset.prototype, "curveData", void 0);
24618
25177
  exports.Vector4PropertyPlayableAsset = __decorate([
24619
- effectsClass("Vector4PropertyPlayableAsset")
25178
+ effectsClass(DataType.Vector4PropertyPlayableAsset)
24620
25179
  ], exports.Vector4PropertyPlayableAsset);
25180
+ exports.Vector2PropertyPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
25181
+ _inherits(Vector2PropertyPlayableAsset, PlayableAsset);
25182
+ function Vector2PropertyPlayableAsset() {
25183
+ return PlayableAsset.apply(this, arguments);
25184
+ }
25185
+ var _proto = Vector2PropertyPlayableAsset.prototype;
25186
+ _proto.createPlayable = function createPlayable(graph) {
25187
+ var clipPlayable = new PropertyClipPlayable(graph);
25188
+ clipPlayable.curve = createValueGetter(this.curveData);
25189
+ clipPlayable.value = clipPlayable.curve.getValue(0);
25190
+ return clipPlayable;
25191
+ };
25192
+ return Vector2PropertyPlayableAsset;
25193
+ }(PlayableAsset);
25194
+ __decorate([
25195
+ serialize()
25196
+ ], exports.Vector2PropertyPlayableAsset.prototype, "curveData", void 0);
25197
+ exports.Vector2PropertyPlayableAsset = __decorate([
25198
+ effectsClass(DataType.Vector2PropertyPlayableAsset)
25199
+ ], exports.Vector2PropertyPlayableAsset);
24621
25200
 
24622
25201
  exports.ObjectBindingTrack = /*#__PURE__*/ function(TrackAsset) {
24623
25202
  _inherits(ObjectBindingTrack, TrackAsset);
@@ -26000,7 +26579,7 @@ function getStandardInteractContent(ui) {
26000
26579
  }
26001
26580
  });
26002
26581
  });
26003
- json.version = "2.1";
26582
+ json.version = JSONSceneVersion["2_1"];
26004
26583
  return json;
26005
26584
  }
26006
26585
  /**
@@ -26339,7 +26918,7 @@ function getStandardInteractContent(ui) {
26339
26918
  break;
26340
26919
  }
26341
26920
  }
26342
- result.version = "3.0";
26921
+ result.version = JSONSceneVersion["3_0"];
26343
26922
  return result;
26344
26923
  }
26345
26924
  /**
@@ -26881,13 +27460,13 @@ function getStandardJSON(json) {
26881
27460
  }
26882
27461
  throw new Error("Invalid JSON version: " + json.version + ".");
26883
27462
  }
26884
- var currentVersion = "1.0";
27463
+ var currentVersion = JSONSceneVersion["1_0"];
26885
27464
  function getStandardJSONFromV0(json) {
26886
27465
  var _json_bins;
26887
- currentVersion = "1.0";
27466
+ currentVersion = JSONSceneVersion["1_0"];
26888
27467
  var plugins = json.plugins || [];
26889
27468
  if ((_json_bins = json.bins) == null ? void 0 : _json_bins.length) {
26890
- currentVersion = "1.3";
27469
+ currentVersion = JSONSceneVersion["1_3"];
26891
27470
  }
26892
27471
  var requires = (json.requires || []).slice();
26893
27472
  var images = json.images.map(function(img, index) {
@@ -28810,7 +29389,9 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
28810
29389
  */ _proto.getSpeed = function getSpeed() {
28811
29390
  return this.speed;
28812
29391
  };
28813
- _proto.play = function play() {
29392
+ /**
29393
+ *
29394
+ */ _proto.play = function play() {
28814
29395
  if (this.isEnded && this.reusable) {
28815
29396
  this.restart();
28816
29397
  }
@@ -28825,7 +29406,10 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
28825
29406
  */ _proto.pause = function pause() {
28826
29407
  this.paused = true;
28827
29408
  };
28828
- _proto.getPaused = function getPaused() {
29409
+ /**
29410
+ *
29411
+ * @returns
29412
+ */ _proto.getPaused = function getPaused() {
28829
29413
  return this.paused;
28830
29414
  };
28831
29415
  /**
@@ -31403,7 +31987,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
31403
31987
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
31404
31988
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
31405
31989
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
31406
- var version = "2.2.6";
31990
+ var version = "2.3.0-alpha.0";
31407
31991
  logger.info("Core version: " + version + ".");
31408
31992
 
31409
31993
  exports.AbstractPlugin = AbstractPlugin;
@@ -31512,6 +32096,7 @@ exports.TrackSortWrapper = TrackSortWrapper;
31512
32096
  exports.Transform = Transform;
31513
32097
  exports.TransformAnimationPlayable = TransformAnimationPlayable;
31514
32098
  exports.ValueGetter = ValueGetter;
32099
+ exports.Vector2Curve = Vector2Curve;
31515
32100
  exports.Vector4Curve = Vector4Curve;
31516
32101
  exports.addByOrder = addByOrder;
31517
32102
  exports.addItem = addItem;