@galacean/effects-plugin-model 2.10.3 → 2.11.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.
package/dist/loader.mjs CHANGED
@@ -3,11 +3,10 @@
3
3
  * Description: Galacean Effects player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.10.3
6
+ * Version: v2.11.0-alpha.0
7
7
  */
8
8
 
9
- import * as EFFECTS from '@galacean/effects';
10
- import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, VertexBuffer, glContext, Material, Mesh, Geometry, ShaderFactory, GLSLVersion, VFXItem, Plugin, effectsClass, Behaviour, registerPlugin, logger, RendererComponent, HitTestType, AnimationClip, TextureSourceType, Texture, DestroyOptions, RenderPassDestroyAttachmentType, getDefaultTextureFactory, Player, loadImage, generateGUID, addItem, removeItem, glType2VertexFormatType, Downloader, getStandardJSON, isObject } from '@galacean/effects';
9
+ import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, VertexElementType, glContext, Material, Mesh, Geometry, ShaderFactory, GLSLVersion, VFXItem, Plugin, effectsClass, Behaviour, RendererComponent, HitTestType, AnimationClip, TextureSourceType, Texture, DestroyOptions, RenderPassDestroyAttachmentType, getDefaultTextureFactory, Player, loadImage, generateGUID, addItem, removeItem, glType2VertexFormatType, Downloader, getStandardJSON, isObject } from '@galacean/effects';
11
10
 
12
11
  var Vector2 = math.Vector2, Vector3 = math.Vector3, Vector4 = math.Vector4, Matrix3 = math.Matrix3, Matrix4 = math.Matrix4, Color = math.Color, Euler = math.Euler, EulerOrder = math.EulerOrder, Quaternion = math.Quaternion, Box3 = math.Box3; math.Sphere; math.Ray; var DEG2RAD = math.DEG2RAD;
13
12
 
@@ -938,78 +937,6 @@ var objectIndex = 1;
938
937
  return PEntity;
939
938
  }(PObject);
940
939
 
941
- /**
942
- * Model 插件元素类型
943
- */ var VFX_ITEM_TYPE_3D = "PluginModel";
944
-
945
- function _is_native_reflect_construct() {
946
- // Since Reflect.construct can't be properly polyfilled, some
947
- // implementations (e.g. core-js@2) don't set the correct internal slots.
948
- // Those polyfills don't allow us to subclass built-ins, so we need to
949
- // use our fallback implementation.
950
- try {
951
- // If the internal slots aren't set, this throws an error similar to
952
- // TypeError: this is not a Boolean object.
953
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
954
- } catch (_) {}
955
- return (_is_native_reflect_construct = function _is_native_reflect_construct() {
956
- return !!result;
957
- })();
958
- }
959
-
960
- function _construct(Parent, args, Class) {
961
- if (_is_native_reflect_construct()) _construct = Reflect.construct;
962
- else {
963
- _construct = function construct(Parent, args, Class) {
964
- var a = [
965
- null
966
- ];
967
- a.push.apply(a, args);
968
- var Constructor = Function.bind.apply(Parent, a);
969
- var instance = new Constructor();
970
- if (Class) _set_prototype_of(instance, Class.prototype);
971
- return instance;
972
- };
973
- }
974
- return _construct.apply(null, arguments);
975
- }
976
-
977
- function _get_prototype_of(o) {
978
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
979
- return o.__proto__ || Object.getPrototypeOf(o);
980
- };
981
- return _get_prototype_of(o);
982
- }
983
-
984
- function _is_native_function(fn) {
985
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
986
- }
987
-
988
- function _wrap_native_super(Class) {
989
- var _cache = typeof Map === "function" ? new Map() : undefined;
990
- _wrap_native_super = function _wrap_native_super(Class) {
991
- if (Class === null || !_is_native_function(Class)) return Class;
992
- if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
993
- if (typeof _cache !== "undefined") {
994
- if (_cache.has(Class)) return _cache.get(Class);
995
- _cache.set(Class, Wrapper);
996
- }
997
- function Wrapper() {
998
- return _construct(Class, arguments, _get_prototype_of(this).constructor);
999
- }
1000
- Wrapper.prototype = Object.create(Class.prototype, {
1001
- constructor: {
1002
- value: Wrapper,
1003
- enumerable: false,
1004
- writable: true,
1005
- configurable: true
1006
- }
1007
- });
1008
- return _set_prototype_of(Wrapper, Class);
1009
- };
1010
- return _wrap_native_super(Class);
1011
- }
1012
-
1013
940
  /**
1014
941
  * 包围盒 Mesh 类,负责 3D Mesh 测试包围盒的显示
1015
942
  */ var BoxMesh = /*#__PURE__*/ function() {
@@ -1112,7 +1039,7 @@ function _wrap_native_super(Class) {
1112
1039
  ]);
1113
1040
  var _obj;
1114
1041
  return {
1115
- attributes: (_obj = {}, _obj[VertexBuffer.PositionKind] = {
1042
+ attributes: (_obj = {}, _obj[VertexElementType.Position] = {
1116
1043
  type: glContext.FLOAT,
1117
1044
  size: 1,
1118
1045
  data: data,
@@ -1415,9 +1342,77 @@ function getQuadFilterVS() {
1415
1342
  return TwoStatesSet;
1416
1343
  }();
1417
1344
 
1345
+ function _is_native_reflect_construct() {
1346
+ // Since Reflect.construct can't be properly polyfilled, some
1347
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
1348
+ // Those polyfills don't allow us to subclass built-ins, so we need to
1349
+ // use our fallback implementation.
1350
+ try {
1351
+ // If the internal slots aren't set, this throws an error similar to
1352
+ // TypeError: this is not a Boolean object.
1353
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
1354
+ } catch (_) {}
1355
+ return (_is_native_reflect_construct = function _is_native_reflect_construct() {
1356
+ return !!result;
1357
+ })();
1358
+ }
1359
+
1360
+ function _construct(Parent, args, Class) {
1361
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
1362
+ else {
1363
+ _construct = function construct(Parent, args, Class) {
1364
+ var a = [
1365
+ null
1366
+ ];
1367
+ a.push.apply(a, args);
1368
+ var Constructor = Function.bind.apply(Parent, a);
1369
+ var instance = new Constructor();
1370
+ if (Class) _set_prototype_of(instance, Class.prototype);
1371
+ return instance;
1372
+ };
1373
+ }
1374
+ return _construct.apply(null, arguments);
1375
+ }
1376
+
1377
+ function _get_prototype_of(o) {
1378
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
1379
+ return o.__proto__ || Object.getPrototypeOf(o);
1380
+ };
1381
+ return _get_prototype_of(o);
1382
+ }
1383
+
1384
+ function _is_native_function(fn) {
1385
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
1386
+ }
1387
+
1388
+ function _wrap_native_super(Class) {
1389
+ var _cache = typeof Map === "function" ? new Map() : undefined;
1390
+ _wrap_native_super = function _wrap_native_super(Class) {
1391
+ if (Class === null || !_is_native_function(Class)) return Class;
1392
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
1393
+ if (typeof _cache !== "undefined") {
1394
+ if (_cache.has(Class)) return _cache.get(Class);
1395
+ _cache.set(Class, Wrapper);
1396
+ }
1397
+ function Wrapper() {
1398
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
1399
+ }
1400
+ Wrapper.prototype = Object.create(Class.prototype, {
1401
+ constructor: {
1402
+ value: Wrapper,
1403
+ enumerable: false,
1404
+ writable: true,
1405
+ configurable: true
1406
+ }
1407
+ });
1408
+ return _set_prototype_of(Wrapper, Class);
1409
+ };
1410
+ return _wrap_native_super(Class);
1411
+ }
1412
+
1418
1413
  /**
1419
1414
  * Model 插件类,负责支持播放器中的 3D 功能
1420
- */ var ModelPlugin = /*#__PURE__*/ function(Plugin) {
1415
+ */ /*#__PURE__*/ (function(Plugin) {
1421
1416
  _inherits(ModelPlugin, Plugin);
1422
1417
  function ModelPlugin() {
1423
1418
  var _this;
@@ -1476,7 +1471,7 @@ function getQuadFilterVS() {
1476
1471
  //
1477
1472
  PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode);
1478
1473
  // Add PBR and Unlit shader data
1479
- var isWebGL2 = engine.gpuCapability.level === 2;
1474
+ var isWebGL2 = engine.displayServer.renderingDevice.gpuCapability.level === 2;
1480
1475
  var pbrShaderCode = fetchPBRShaderCode();
1481
1476
  var unlitShaderCode = fetchUnlitShaderCode();
1482
1477
  var pbrShaderData = {
@@ -1497,8 +1492,8 @@ function getQuadFilterVS() {
1497
1492
  // @ts-expect-error
1498
1493
  glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1
1499
1494
  };
1500
- engine.addEffectsObjectData(pbrShaderData);
1501
- engine.addEffectsObjectData(unlitShaderData);
1495
+ engine.assetServer.addEffectsObjectData(pbrShaderData);
1496
+ engine.assetServer.addEffectsObjectData(unlitShaderData);
1502
1497
  };
1503
1498
  /**
1504
1499
  * 创建 3D 场景管理器和缓存器
@@ -1518,7 +1513,7 @@ function getQuadFilterVS() {
1518
1513
  modelPluginComponent.sceneParams = (_scene_storage = scene == null ? void 0 : scene.storage) != null ? _scene_storage : {};
1519
1514
  };
1520
1515
  return ModelPlugin;
1521
- }(_wrap_native_super(Plugin));
1516
+ })(_wrap_native_super(Plugin));
1522
1517
  var ModelPluginComponent = /*#__PURE__*/ function(Behaviour) {
1523
1518
  _inherits(ModelPluginComponent, Behaviour);
1524
1519
  function ModelPluginComponent(engine) {
@@ -1581,18 +1576,16 @@ var ModelPluginComponent = /*#__PURE__*/ function(Behaviour) {
1581
1576
  // 更新相机的位置,主要是composition的camera数据,以及camera item数据
1582
1577
  composition.camera.position = position;
1583
1578
  (_composition_items = composition.items) == null ? void 0 : _composition_items.forEach(function(item) {
1584
- if (item.type === VFX_ITEM_TYPE_3D) {
1585
- var component = item.getComponent(ModelCameraComponent);
1586
- if (component == null ? void 0 : component.content) {
1587
- var _item_transform_parentTransform;
1588
- var worldMatrix = ((_item_transform_parentTransform = item.transform.parentTransform) == null ? void 0 : _item_transform_parentTransform.getWorldMatrix()) || Matrix4.IDENTITY.clone();
1589
- var invWorldMatrix = worldMatrix.invert();
1590
- var newPosition = invWorldMatrix.transformPoint(position);
1591
- component.setTransform(newPosition);
1592
- // 正式版本不会走到这个流程,只在测试时使用
1593
- console.info("Scene AABB [" + sceneAABB.min.toArray() + "], [" + sceneAABB.max.toArray() + "].");
1594
- console.info("Update camera position [" + newPosition.toArray() + "].");
1595
- }
1579
+ var component = item.getComponent(ModelCameraComponent);
1580
+ if (component == null ? void 0 : component.content) {
1581
+ var _item_transform_parentTransform;
1582
+ var worldMatrix = ((_item_transform_parentTransform = item.transform.parentTransform) == null ? void 0 : _item_transform_parentTransform.getWorldMatrix()) || Matrix4.IDENTITY.clone();
1583
+ var invWorldMatrix = worldMatrix.invert();
1584
+ var newPosition = invWorldMatrix.transformPoint(position);
1585
+ component.setTransform(newPosition);
1586
+ // 正式版本不会走到这个流程,只在测试时使用
1587
+ console.info("Scene AABB [" + sceneAABB.min.toArray() + "], [" + sceneAABB.max.toArray() + "].");
1588
+ console.info("Update camera position [" + newPosition.toArray() + "].");
1596
1589
  }
1597
1590
  });
1598
1591
  }
@@ -1705,593 +1698,329 @@ ModelPluginComponent = __decorate([
1705
1698
  return pluginComp == null ? void 0 : pluginComp.scene;
1706
1699
  }
1707
1700
 
1708
- var ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
1709
- _inherits(ModelTreeComponent, Behaviour);
1710
- function ModelTreeComponent(engine, options) {
1701
+ var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
1702
+ _inherits(ModelMeshComponent, RendererComponent);
1703
+ function ModelMeshComponent(engine, data) {
1711
1704
  var _this;
1712
- _this = Behaviour.call(this, engine) || this;
1713
- if (options) {
1714
- _this.fromData(options);
1705
+ _this = RendererComponent.call(this, engine) || this;
1706
+ /**
1707
+ * morph 动画权重
1708
+ */ _this.morphWeights = [];
1709
+ _this.firstUpdate = true;
1710
+ /**
1711
+ * 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
1712
+ * @param force - 是否强制进行点击测试
1713
+ * @returns 点击测试参数
1714
+ */ _this.getHitTestParams = function(force) {
1715
+ _this.computeBoundingBox();
1716
+ var bounding = _this.bounding;
1717
+ if (bounding && (force || Number.isInteger(bounding.behavior))) {
1718
+ var type = bounding.type;
1719
+ if (type === spec.ModelBoundingType.box) {
1720
+ if (_instanceof1(_this.content, PMesh)) {
1721
+ var mesh = _this.content;
1722
+ var customHitTest = {
1723
+ behavior: bounding.behavior,
1724
+ type: HitTestType.custom,
1725
+ clipMasks: _this.frameClipMasks,
1726
+ collect: function collect(ray, pointInCanvas) {
1727
+ var result = mesh.hitTesting(ray.origin, ray.direction);
1728
+ return result;
1729
+ }
1730
+ };
1731
+ return customHitTest;
1732
+ } else {
1733
+ var worldMatrixData = _this.transform.getWorldMatrix();
1734
+ var customHitTest1 = {
1735
+ behavior: bounding.behavior,
1736
+ type: HitTestType.custom,
1737
+ clipMasks: _this.frameClipMasks,
1738
+ collect: function collect(ray, pointInCanvas) {
1739
+ var result = RayIntersectsBoxWithRotation(ray, worldMatrixData, bounding);
1740
+ return result;
1741
+ }
1742
+ };
1743
+ return customHitTest1;
1744
+ }
1745
+ } else if (type === spec.ModelBoundingType.sphere) {
1746
+ var pos = new Vector3();
1747
+ _this.transform.assignWorldTRS(pos);
1748
+ var center = new Vector3();
1749
+ if (bounding.center) {
1750
+ center.setFromArray(bounding.center);
1751
+ }
1752
+ center.add(pos);
1753
+ return {
1754
+ type: type,
1755
+ behavior: bounding.behavior,
1756
+ radius: bounding.radius || 0,
1757
+ center: center,
1758
+ clipMasks: _this.frameClipMasks
1759
+ };
1760
+ }
1761
+ }
1762
+ };
1763
+ if (data) {
1764
+ _this.fromData(data);
1715
1765
  }
1716
1766
  return _this;
1717
1767
  }
1718
- var _proto = ModelTreeComponent.prototype;
1768
+ var _proto = ModelMeshComponent.prototype;
1719
1769
  /**
1720
- * 反序列化,保存入参和创建节点树元素
1721
- * @param options
1722
- */ _proto.fromData = function fromData(options) {
1723
- Behaviour.prototype.fromData.call(this, options);
1724
- this.options = options;
1725
- };
1726
- return ModelTreeComponent;
1727
- }(Behaviour);
1728
- ModelTreeComponent = __decorate([
1729
- effectsClass(spec.DataType.TreeComponent)
1730
- ], ModelTreeComponent);
1731
-
1732
- var CameraGestureType;
1733
- (function(CameraGestureType) {
1734
- CameraGestureType[CameraGestureType["none"] = 0] = "none";
1735
- CameraGestureType[CameraGestureType["translate"] = 1] = "translate";
1736
- CameraGestureType[CameraGestureType["rotate_focus"] = 2] = "rotate_focus";
1737
- CameraGestureType[CameraGestureType["rotate_self"] = 3] = "rotate_self";
1738
- CameraGestureType[CameraGestureType["scale"] = 4] = "scale";
1739
- })(CameraGestureType || (CameraGestureType = {}));
1740
-
1741
- var CameraGestureHandlerImp = /*#__PURE__*/ function() {
1742
- function CameraGestureHandlerImp(composition) {
1743
- this.composition = composition;
1744
- this.cameraTransform = new PTransform();
1745
- this.cameraCoordiante = new PCoordinate();
1746
- this.startParams = {
1747
- type: CameraGestureType.none,
1748
- mouseEvent: false,
1749
- clientX: 0,
1750
- clientY: 0,
1751
- clientWidth: 512,
1752
- clientHeight: 512,
1753
- target: ""
1754
- };
1755
- }
1756
- var _proto = CameraGestureHandlerImp.prototype;
1757
- _proto.updateComposition = function updateComposition(composition) {
1758
- this.composition = composition;
1759
- };
1760
- _proto.getItem = function getItem() {
1761
- var _this = this;
1762
- var _this_composition_items;
1763
- return (_this_composition_items = this.composition.items) == null ? void 0 : _this_composition_items.find(function(item) {
1764
- return item.name === _this.getCurrentTarget();
1765
- });
1766
- };
1767
- _proto.getCurrentTarget = function getCurrentTarget() {
1768
- return this.startParams.target;
1770
+ * 组件开始,需要创建内部对象,更新父元素信息和添加到场景管理器中
1771
+ */ _proto.onStart = function onStart() {
1772
+ var _this_sceneManager;
1773
+ this.sceneManager = getSceneManager(this);
1774
+ this.createContent();
1775
+ this.priority = this.item.renderOrder;
1776
+ (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.addItem(this.content);
1777
+ if (this.item.parentId && this.item.parent) {
1778
+ this.content.updateParentInfo(this.item.parentId, this.item.parent);
1779
+ }
1780
+ this.setVisible(true);
1781
+ this.item.getHitTestParams = this.getHitTestParams;
1769
1782
  };
1770
- _proto.getCurrentType = function getCurrentType() {
1771
- return this.startParams.type;
1772
- };
1773
- _proto.onKeyEvent = function onKeyEvent(event) {
1774
- // check event camera ID at first
1775
- if (this.startParams.target !== event.cameraID) {
1776
- this.startParams.target = event.cameraID;
1777
- this.startParams.type = CameraGestureType.translate;
1778
- }
1779
- // can't find camera item, throw error message
1780
- var item = this.getItem();
1781
- if (item === undefined) {
1782
- console.warn("[CameraGestureHandlerImp] Unable to locate camera item with ID: " + this.startParams.target + ".");
1783
- return this.composition.camera.getOptions();
1784
- }
1785
- var camera = this.composition.camera;
1786
- var effectsTransfrom = new Transform(_extends({}, camera.getOptions(), {
1787
- valid: true
1788
- }));
1789
- var cameraTransform = new PTransform().fromEffectsTransform(effectsTransfrom);
1790
- var cameraCoordiante = new PCoordinate().fromPTransform(cameraTransform);
1791
- var _event_xAxis;
1792
- // compute move direction
1793
- var xAxis = (_event_xAxis = event.xAxis) != null ? _event_xAxis : 0;
1794
- var _event_yAxis;
1795
- var yAxis = (_event_yAxis = event.yAxis) != null ? _event_yAxis : 0;
1796
- var _event_zAxis;
1797
- var zAxis = (_event_zAxis = event.zAxis) != null ? _event_zAxis : 0;
1798
- var dir = cameraCoordiante.xAxis.clone().multiply(xAxis);
1799
- dir.add(cameraCoordiante.yAxis.clone().multiply(yAxis));
1800
- dir.add(cameraCoordiante.zAxis.clone().multiply(zAxis));
1801
- if (dir.lengthSquared() < 0.00001) {
1802
- return camera.getOptions();
1803
- }
1804
- dir.normalize();
1805
- var _event_speed;
1806
- // update camera position
1807
- var speed = (_event_speed = event.speed) != null ? _event_speed : 0.1;
1808
- var pos = cameraTransform.getPosition();
1809
- pos.add(dir.clone().multiply(speed));
1810
- this.setTransform(item, pos);
1811
- // update camera transform and coordinates
1812
- if (this.startParams.type === CameraGestureType.rotate_self) {
1813
- this.cameraTransform.setPosition(pos);
1814
- this.cameraCoordiante.origin = pos;
1783
+ /**
1784
+ * 组件更新,更新内部对象状态
1785
+ * @param dt - 更新间隔
1786
+ */ _proto.onUpdate = function onUpdate(dt) {
1787
+ if (this.sceneManager) {
1788
+ this.content.build(this.sceneManager);
1789
+ if (this.firstUpdate) {
1790
+ this.materials = this.content.subMeshes.map(function(subMesh) {
1791
+ return subMesh.getEffectsMaterial();
1792
+ });
1793
+ this.firstUpdate = false;
1794
+ }
1815
1795
  }
1816
- return camera.getOptions();
1796
+ this.content.update();
1817
1797
  };
1818
- _proto.onXYMoveBegin = function onXYMoveBegin(x, y, width, height, cameraID) {
1819
- var args = {
1820
- type: CameraGestureType.translate,
1821
- mouseEvent: true,
1822
- clientX: x,
1823
- clientY: y,
1824
- clientWidth: width,
1825
- clientHeight: height,
1826
- target: cameraID
1827
- };
1828
- return this.startGesture(args);
1798
+ /**
1799
+ * 组件晚更新,晚更新内部对象状态
1800
+ * @param dt - 更新间隔
1801
+ */ _proto.onLateUpdate = function onLateUpdate(dt) {
1802
+ this.content.lateUpdate();
1829
1803
  };
1830
- _proto.onXYMoving = function onXYMoving(x, y, speed) {
1831
- if (!this.startParams.mouseEvent) {
1832
- return this.composition.camera.getOptions();
1804
+ /**
1805
+ * 组件渲染,需要检查可见性
1806
+ * @param renderer - 渲染器
1807
+ * @returns
1808
+ */ _proto.render = function render(renderer) {
1809
+ if (!this.getVisible() || !this.sceneManager) {
1810
+ return;
1833
1811
  }
1834
- var arg0 = this.startParams;
1835
- var arg = {
1836
- type: CameraGestureType.translate,
1837
- mouseEvent: true,
1838
- clientX: x,
1839
- clientY: y,
1840
- clientWidth: arg0.clientWidth,
1841
- clientHeight: arg0.clientHeight,
1842
- target: arg0.target,
1843
- speed: speed != null ? speed : 0.015
1844
- };
1845
- return this.moveGesture(arg);
1846
- };
1847
- _proto.onXYMoveEnd = function onXYMoveEnd() {
1848
- this.endGesture();
1812
+ this.maskManager.drawStencilMask(renderer, this);
1813
+ this.content.render(this.sceneManager, renderer);
1849
1814
  };
1850
- _proto.onZMoveBegin = function onZMoveBegin(x, y, width, height, cameraID) {
1851
- var arg = {
1852
- type: CameraGestureType.scale,
1853
- mouseEvent: true,
1854
- clientX: x,
1855
- clientY: y,
1856
- clientWidth: width,
1857
- clientHeight: height,
1858
- target: cameraID
1859
- };
1860
- return this.startGesture(arg);
1815
+ /**
1816
+ * 组件销毁,需要重场景管理器中删除
1817
+ */ _proto.onDestroy = function onDestroy() {
1818
+ var _this_sceneManager;
1819
+ (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.removeItem(this.content);
1820
+ this.sceneManager = undefined;
1821
+ this.content.dispose();
1861
1822
  };
1862
- _proto.onZMoving = function onZMoving(x, y, speed) {
1863
- if (speed === void 0) speed = 0.015;
1864
- if (!this.startParams.mouseEvent) {
1865
- return this.composition.camera.getOptions();
1823
+ /**
1824
+ * 反序列化,记录传入参数
1825
+ * @param data - 组件参数
1826
+ */ _proto.fromData = function fromData(data) {
1827
+ RendererComponent.prototype.fromData.call(this, data);
1828
+ this.data = _extends({}, data, {
1829
+ materials: []
1830
+ });
1831
+ this.data.rootBone = data.rootBone ? this.findObject(data.rootBone) : undefined;
1832
+ this.data.geometry = this.findObject(data.geometry);
1833
+ if (data.materials) {
1834
+ for(var i = 0; i < data.materials.length; i++){
1835
+ this.data.materials[i] = this.findObject(data.materials[i]);
1836
+ }
1866
1837
  }
1867
- var arg0 = this.startParams;
1868
- var arg = {
1869
- type: CameraGestureType.scale,
1870
- mouseEvent: true,
1871
- clientX: x,
1872
- clientY: y,
1873
- clientWidth: arg0.clientWidth,
1874
- clientHeight: arg0.clientHeight,
1875
- target: arg0.target,
1876
- speed: speed
1877
- };
1878
- return this.moveGesture(arg);
1879
- };
1880
- _proto.onZMoveEnd = function onZMoveEnd() {
1881
- this.endGesture();
1882
- };
1883
- _proto.onRotateBegin = function onRotateBegin(x, y, width, height, cameraID) {
1884
- var arg = {
1885
- type: CameraGestureType.rotate_self,
1886
- mouseEvent: true,
1887
- clientX: x,
1888
- clientY: y,
1889
- clientWidth: width,
1890
- clientHeight: height,
1891
- target: cameraID
1892
- };
1893
- return this.startGesture(arg);
1894
1838
  };
1895
- _proto.onRotating = function onRotating(x, y, speed) {
1896
- if (!this.startParams.mouseEvent) {
1897
- return this.composition.camera.getOptions();
1839
+ /**
1840
+ * 创建内部对象
1841
+ */ _proto.createContent = function createContent() {
1842
+ if (this.data) {
1843
+ var bounding = this.data.interaction;
1844
+ this.bounding = bounding && JSON.parse(JSON.stringify(bounding));
1845
+ this.content = new PMesh(this.engine, this.item.name, this.data, this, this.item.parentId);
1898
1846
  }
1899
- var arg0 = this.startParams;
1900
- var arg = {
1901
- type: CameraGestureType.rotate_self,
1902
- mouseEvent: true,
1903
- clientX: x,
1904
- clientY: y,
1905
- clientWidth: arg0.clientWidth,
1906
- clientHeight: arg0.clientHeight,
1907
- target: arg0.target,
1908
- speed: speed != null ? speed : 1.5
1909
- };
1910
- return this.moveGesture(arg);
1911
1847
  };
1912
- _proto.onRotateEnd = function onRotateEnd() {
1913
- this.endGesture();
1848
+ /**
1849
+ * 设置当前 Mesh 的可见性。
1850
+ * @param visible - true:可见,false:不可见
1851
+ */ _proto.setVisible = function setVisible(visible) {
1852
+ var _this_content;
1853
+ (_this_content = this.content) == null ? void 0 : _this_content.onVisibleChanged(visible);
1914
1854
  };
1915
- _proto.onRotatePointBegin = function onRotatePointBegin(x, y, width, height, point, cameraID) {
1916
- var arg = {
1917
- type: CameraGestureType.rotate_focus,
1918
- mouseEvent: true,
1919
- clientX: x,
1920
- clientY: y,
1921
- clientWidth: width,
1922
- clientHeight: height,
1923
- focusPoint: point,
1924
- target: cameraID
1925
- };
1926
- return this.startGesture(arg);
1855
+ /**
1856
+ * 获取当前 Mesh 的可见性。
1857
+ */ _proto.getVisible = function getVisible() {
1858
+ var _this_content;
1859
+ var _this_content_visible;
1860
+ return (_this_content_visible = (_this_content = this.content) == null ? void 0 : _this_content.visible) != null ? _this_content_visible : false;
1927
1861
  };
1928
- _proto.onRotatingPoint = function onRotatingPoint(x, y, speed) {
1929
- if (!this.startParams.mouseEvent) {
1930
- return this.composition.camera.getOptions();
1862
+ /**
1863
+ * 计算元素包围盒,只针对 Mesh 对象
1864
+ * @returns 包围盒
1865
+ */ _proto.computeBoundingBox = function computeBoundingBox() {
1866
+ if (this.content && _instanceof1(this.content, PMesh)) {
1867
+ var _this_bounding;
1868
+ var worldMatrix = this.transform.getWorldMatrix();
1869
+ var bbox = this.content.computeBoundingBox(worldMatrix);
1870
+ var center = bbox.getCenter(new Vector3());
1871
+ var size = bbox.getSize(new Vector3());
1872
+ this.bounding = {
1873
+ behavior: (_this_bounding = this.bounding) == null ? void 0 : _this_bounding.behavior,
1874
+ type: spec.ModelBoundingType.box,
1875
+ center: [
1876
+ center.x,
1877
+ center.y,
1878
+ center.z
1879
+ ],
1880
+ size: [
1881
+ size.x,
1882
+ size.y,
1883
+ size.z
1884
+ ]
1885
+ };
1886
+ return this.bounding;
1887
+ } else {
1888
+ return;
1931
1889
  }
1932
- var arg0 = this.startParams;
1933
- var arg = {
1934
- type: CameraGestureType.rotate_focus,
1935
- mouseEvent: true,
1936
- clientX: x,
1937
- clientY: y,
1938
- clientWidth: arg0.clientWidth,
1939
- clientHeight: arg0.clientHeight,
1940
- focusPoint: arg0.focusPoint,
1941
- target: arg0.target,
1942
- speed: speed != null ? speed : 8.0
1943
- };
1944
- return this.moveGesture(arg);
1945
- };
1946
- _proto.onRotatePointEnd = function onRotatePointEnd() {
1947
- this.endGesture();
1948
1890
  };
1949
- _proto.moveTo = function moveTo(cameraID, position) {
1950
- this.startParams.target = cameraID;
1951
- this.startParams.type = CameraGestureType.none;
1952
- var item = this.getItem();
1953
- if (item === undefined) {
1954
- console.warn("[CameraGestureHandlerImp] Can't find camera item.");
1955
- return;
1891
+ return ModelMeshComponent;
1892
+ }(RendererComponent);
1893
+ ModelMeshComponent = __decorate([
1894
+ effectsClass(spec.DataType.MeshComponent)
1895
+ ], ModelMeshComponent);
1896
+ var ModelSkyboxComponent = /*#__PURE__*/ function(RendererComponent) {
1897
+ _inherits(ModelSkyboxComponent, RendererComponent);
1898
+ function ModelSkyboxComponent(engine, data) {
1899
+ var _this;
1900
+ _this = RendererComponent.call(this, engine) || this;
1901
+ if (data) {
1902
+ _this.fromData(data);
1956
1903
  }
1957
- this.setPosition(item, position);
1958
- };
1959
- _proto.rotateTo = function rotateTo(cameraID, quat) {
1960
- this.startParams.target = cameraID;
1961
- this.startParams.type = CameraGestureType.none;
1962
- var item = this.getItem();
1963
- if (item === undefined) {
1964
- console.warn("[CameraGestureHandlerImp] Can't find camera item.");
1965
- return;
1904
+ return _this;
1905
+ }
1906
+ var _proto = ModelSkyboxComponent.prototype;
1907
+ /**
1908
+ * 组件开始,需要创建内部对象和添加到场景管理器中
1909
+ */ _proto.onStart = function onStart() {
1910
+ var _this_sceneManager;
1911
+ this.createContent();
1912
+ this.priority = this.item.renderOrder;
1913
+ this.sceneManager = getSceneManager(this);
1914
+ (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.addItem(this.content);
1915
+ this.setVisible(true);
1916
+ if (this.content.skyboxMesh) {
1917
+ this.materials = [
1918
+ this.content.skyboxMesh.material
1919
+ ];
1966
1920
  }
1967
- this.setQuaternion(item, quat);
1968
1921
  };
1969
- _proto.onFocusPoint = function onFocusPoint(cameraID, point, distance) {
1970
- this.startParams.target = cameraID;
1971
- this.startParams.type = CameraGestureType.none;
1972
- var item = this.getItem();
1973
- if (item === undefined) {
1974
- console.warn("[CameraGestureHandlerImp] Can't find camera item.");
1922
+ /**
1923
+ * 组件渲染,需要检查可见性
1924
+ * @param renderer - 渲染器
1925
+ * @returns
1926
+ */ _proto.render = function render(renderer) {
1927
+ if (!this.getVisible() || !this.sceneManager) {
1975
1928
  return;
1976
1929
  }
1977
- var newDistance = distance != null ? distance : 5;
1978
- var targetPoint = Vector3.fromArray(point);
1979
- //
1980
- var transform = new PTransform().fromEffectsTransform(item.transform);
1981
- var coordinate = new PCoordinate().fromPTransform(transform);
1982
- // FIXME: MATH
1983
- var lookatDir = Vector3.fromArray(coordinate.zAxis.toArray()).multiply(1.0);
1984
- //
1985
- var newOffset = lookatDir.clone().multiply(newDistance);
1986
- var newPosition = targetPoint.clone().add(newOffset);
1987
- //
1988
- this.setTransform(item, newPosition);
1989
- //
1990
- // z+方向优先
1991
- // const cameraPos = Vector3.fromArray(item.transform.position);
1992
- // const newLookatDir = targetPoint.clone().subVector(cameraPos).normalize();
1993
- // const newOffset = newLookatDir.clone().multiplyScalar(newDistance);
1994
- // const newPosition = targetPoint.clone().subVector(newOffset);
1995
- // const newUpVector = Vector3.tryZUpVector(newLookatDir, new Vector3);
1996
- // const viewMatrix = Matrix4.computeLookAt(newPosition, targetPoint, newUpVector, new Matrix4);
1997
- // const tranform = new PTransform().fromMatrix4(viewMatrix);
1998
- // const newRotation = tranform.rotation;
1999
- // item.transform.setQuat(-newRotation.x, -newRotation.y, -newRotation.z, newRotation.w);
2000
- // item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
2001
- //
2002
- // 旋转优先
2003
- // const cameraPos = Vector3.fromArray(item.transform.position);
2004
- // const newLookatDir = targetPoint.clone().subVector(cameraPos).normalize();
2005
- // const newOffset = newLookatDir.clone().multiplyScalar(newDistance);
2006
- // const newPosition = targetPoint.clone().subVector(newOffset);
2007
- // const oldTransform = new PTransform().fromEffectsTransform(item.transform);
2008
- // const oldCoordinate = new PCoordinate().fromPTransform(oldTransform)
2009
- // const oldLookatDir = oldCoordinate.zAxis.clone().multiplyScalar(-1.0);
2010
- // const rotateAxis = oldLookatDir.cross(newLookatDir);
2011
- // const sinTheta = rotateAxis.length();
2012
- // const theta = Math.asin(sinTheta);
2013
- // const deltaRotation = Quaternion.fromAxisAngle(rotateAxis, theta, new Quaternion);
2014
- // const newRotation = Quaternion.multiply(deltaRotation, oldTransform.rotation, new Quaternion);
2015
- // item.transform.setQuat(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
2016
- // item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
2017
- //
2018
- //
2019
- this.startParams.target = "";
1930
+ this.maskManager.drawStencilMask(renderer, this);
1931
+ this.content.render(this.sceneManager, renderer);
2020
1932
  };
2021
- _proto.getCameraTransform = function getCameraTransform() {
2022
- var camera = this.composition.camera;
2023
- var transform = new Transform(camera.getOptions());
2024
- transform.setValid(true);
2025
- return transform;
1933
+ /**
1934
+ * 组件销毁,需要重场景管理器中删除
1935
+ */ _proto.onDestroy = function onDestroy() {
1936
+ var _this_sceneManager;
1937
+ (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.removeItem(this.content);
1938
+ this.sceneManager = undefined;
1939
+ this.content.dispose();
2026
1940
  };
2027
- _proto.startGesture = function startGesture(args) {
2028
- this.startParams = args;
2029
- this.updateCameraTransform(this.composition.camera.getOptions());
2030
- if (!this.getItem()) {
2031
- console.warn("[CameraGestureHandlerImp] Invalid target specified in startGesture.");
2032
- }
2033
- return this.composition.camera.getOptions();
1941
+ /**
1942
+ * 反序列化,记录传入参数
1943
+ * @param data - 组件参数
1944
+ */ _proto.fromData = function fromData(data) {
1945
+ RendererComponent.prototype.fromData.call(this, data);
1946
+ data.diffuseImage = data.diffuseImage ? this.findObject(data.diffuseImage) : undefined;
1947
+ data.specularImage = this.findObject(data.specularImage);
1948
+ this.data = data;
2034
1949
  };
2035
- _proto.moveGesture = function moveGesture(arg) {
2036
- if (this.getCurrentType() === arg.type) {
2037
- var item = this.getItem();
2038
- if (item === undefined) {
2039
- console.warn("[CameraGestureHandlerImp] Can't find camera item.");
2040
- return this.composition.camera.getOptions();
2041
- }
2042
- var _arg_speed;
2043
- var speed = (_arg_speed = arg.speed) != null ? _arg_speed : 1.015;
2044
- var xAxis = this.cameraCoordiante.xAxis;
2045
- var yAxis = this.cameraCoordiante.yAxis;
2046
- var zAxis = this.cameraCoordiante.zAxis;
2047
- var dx = arg.clientX - this.startParams.clientX;
2048
- var dy = arg.clientY - this.startParams.clientY;
2049
- if (arg.type === CameraGestureType.translate) {
2050
- var pos = this.cameraTransform.getPosition();
2051
- var newPos = pos.clone();
2052
- newPos.add(xAxis.clone().multiply(-dx * speed));
2053
- newPos.add(yAxis.clone().multiply(dy * speed));
2054
- item.transform.setPosition(newPos.x, newPos.y, newPos.z);
2055
- this.setTransform(item, item.transform.position, item.transform.rotation);
2056
- } else if (arg.type === CameraGestureType.scale) {
2057
- var pos1 = this.cameraTransform.getPosition();
2058
- var newPos1 = pos1.clone();
2059
- newPos1.add(zAxis.clone().multiply(dy * speed));
2060
- item.transform.setPosition(newPos1.x, newPos1.y, newPos1.z);
2061
- this.setTransform(item, item.transform.position, item.transform.rotation);
2062
- } else if (arg.type === CameraGestureType.rotate_self) {
2063
- var ndx = dx / arg.clientWidth;
2064
- var ndy = dy / arg.clientHeight;
2065
- var dxAngle = ndx * Math.PI * speed * 0.5;
2066
- var dyAngle = ndy * Math.PI * speed * 0.5;
2067
- var newRotation = Quaternion.fromAxisAngle(Vector3.Y, -dxAngle);
2068
- // FIXME: MATH
2069
- var tempRotation = Quaternion.fromAxisAngle(xAxis, -dyAngle);
2070
- newRotation.multiply(tempRotation);
2071
- // FIXME: MATH
2072
- newRotation.multiply(this.cameraTransform.getRotation());
2073
- item.transform.setQuaternion(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
2074
- this.setTransform(item, item.transform.position, item.transform.rotation);
2075
- } else if (arg.type === CameraGestureType.rotate_focus) {
2076
- var ndx1 = dx / arg.clientWidth;
2077
- var ndy1 = dy / arg.clientHeight;
2078
- var dxAngle1 = ndx1 * Math.PI * speed;
2079
- var dyAngle1 = ndy1 * Math.PI * speed;
2080
- var newRotation1 = Quaternion.fromAxisAngle(Vector3.Y, -dxAngle1);
2081
- var tempRotation1 = Quaternion.fromAxisAngle(xAxis, -dyAngle1);
2082
- newRotation1.multiply(tempRotation1);
2083
- var rotateMatrix = newRotation1.toMatrix4(new Matrix4());
2084
- var targetPoint = Vector3.fromArray(arg.focusPoint);
2085
- var deltaPosition = this.cameraCoordiante.origin.clone().subtract(targetPoint);
2086
- rotateMatrix.transformPoint(deltaPosition);
2087
- var newPosition = deltaPosition.add(targetPoint);
2088
- newRotation1.multiply(this.cameraTransform.getRotation());
2089
- item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
2090
- item.transform.setQuaternion(newRotation1.x, newRotation1.y, newRotation1.z, newRotation1.w);
2091
- this.setTransform(item, newPosition, item.transform.rotation);
2092
- } else {
2093
- console.warn("[CameraGestureHandlerImp] Movement type not implemented.");
2094
- }
2095
- } else {
2096
- console.warn("[CameraGestureHandlerImp] Invalid move type specified: " + arg.type);
1950
+ /**
1951
+ * 创建内部对象
1952
+ */ _proto.createContent = function createContent() {
1953
+ if (this.data) {
1954
+ var skyboxData = this.data;
1955
+ this.content = new PSkybox(this.item.name, skyboxData, this);
2097
1956
  }
2098
- return this.composition.camera.getOptions();
2099
1957
  };
2100
- _proto.setTransform = function setTransform(item, position, rotation) {
2101
- var camera = item.getComponent(ModelCameraComponent);
2102
- if (camera !== undefined) {
2103
- camera.setTransform(position, rotation);
2104
- }
1958
+ /**
1959
+ * 设置当前可见性。
1960
+ * @param visible - true:可见,false:不可见
1961
+ */ _proto.setVisible = function setVisible(visible) {
1962
+ var _this_content;
1963
+ (_this_content = this.content) == null ? void 0 : _this_content.onVisibleChanged(visible);
2105
1964
  };
2106
- _proto.setPosition = function setPosition(item, position) {
2107
- var _item_transform;
2108
- (_item_transform = item.transform).setPosition.apply(_item_transform, [].concat(position));
2109
- var camera = item.getComponent(ModelCameraComponent);
2110
- if (camera !== undefined) {
2111
- camera.updateMainCamera();
2112
- }
1965
+ /**
1966
+ * 获取当前可见性。
1967
+ */ _proto.getVisible = function getVisible() {
1968
+ var _this_content;
1969
+ var _this_content_visible;
1970
+ return (_this_content_visible = (_this_content = this.content) == null ? void 0 : _this_content.visible) != null ? _this_content_visible : false;
2113
1971
  };
2114
- _proto.setQuaternion = function setQuaternion(item, quat) {
2115
- var _item_transform;
2116
- (_item_transform = item.transform).setQuaternion.apply(_item_transform, [].concat(quat));
2117
- var camera = item.getComponent(ModelCameraComponent);
2118
- if (camera !== undefined) {
2119
- camera.updateMainCamera();
1972
+ return ModelSkyboxComponent;
1973
+ }(RendererComponent);
1974
+ ModelSkyboxComponent = __decorate([
1975
+ effectsClass(spec.DataType.SkyboxComponent)
1976
+ ], ModelSkyboxComponent);
1977
+ var ModelLightComponent = /*#__PURE__*/ function(Behaviour) {
1978
+ _inherits(ModelLightComponent, Behaviour);
1979
+ function ModelLightComponent(engine, data) {
1980
+ var _this;
1981
+ _this = Behaviour.call(this, engine) || this;
1982
+ if (data) {
1983
+ _this.fromData(data);
2120
1984
  }
2121
- };
2122
- _proto.endGesture = function endGesture() {
2123
- this.startParams.type = CameraGestureType.none;
2124
- this.startParams.mouseEvent = false;
2125
- this.startParams.target = "";
2126
- };
2127
- _proto.updateCameraTransform = function updateCameraTransform(cameraOptions) {
2128
- var effectsTransfrom = new Transform(cameraOptions);
2129
- effectsTransfrom.setValid(true);
2130
- this.cameraTransform.fromEffectsTransform(effectsTransfrom);
2131
- this.cameraCoordiante.fromPTransform(this.cameraTransform);
2132
- };
2133
- return CameraGestureHandlerImp;
2134
- }();
2135
-
2136
- registerPlugin("model", ModelPlugin);
2137
- /**
2138
- * 插件版本号
2139
- */ var version = "2.10.3";
2140
- logger.info("Plugin model version: " + version + ".");
2141
- if (version !== EFFECTS.version) {
2142
- console.error("注意:请统一 Model 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Model plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
2143
- }
2144
-
2145
- var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
2146
- _inherits(ModelMeshComponent, RendererComponent);
2147
- function ModelMeshComponent(engine, data) {
2148
- var _this;
2149
- _this = RendererComponent.call(this, engine) || this;
2150
- /**
2151
- * morph 动画权重
2152
- */ _this.morphWeights = [];
2153
- _this.firstUpdate = true;
2154
- /**
2155
- * 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
2156
- * @param force - 是否强制进行点击测试
2157
- * @returns 点击测试参数
2158
- */ _this.getHitTestParams = function(force) {
2159
- _this.computeBoundingBox();
2160
- var bounding = _this.bounding;
2161
- if (bounding && (force || Number.isInteger(bounding.behavior))) {
2162
- var type = bounding.type;
2163
- if (type === spec.ModelBoundingType.box) {
2164
- if (_instanceof1(_this.content, PMesh)) {
2165
- var mesh = _this.content;
2166
- var customHitTest = {
2167
- behavior: bounding.behavior,
2168
- type: HitTestType.custom,
2169
- clipMasks: _this.frameClipMasks,
2170
- collect: function collect(ray, pointInCanvas) {
2171
- var result = mesh.hitTesting(ray.origin, ray.direction);
2172
- return result;
2173
- }
2174
- };
2175
- return customHitTest;
2176
- } else {
2177
- var worldMatrixData = _this.transform.getWorldMatrix();
2178
- var customHitTest1 = {
2179
- behavior: bounding.behavior,
2180
- type: HitTestType.custom,
2181
- clipMasks: _this.frameClipMasks,
2182
- collect: function collect(ray, pointInCanvas) {
2183
- var result = RayIntersectsBoxWithRotation(ray, worldMatrixData, bounding);
2184
- return result;
2185
- }
2186
- };
2187
- return customHitTest1;
2188
- }
2189
- } else if (type === spec.ModelBoundingType.sphere) {
2190
- var pos = new Vector3();
2191
- _this.transform.assignWorldTRS(pos);
2192
- var center = new Vector3();
2193
- if (bounding.center) {
2194
- center.setFromArray(bounding.center);
2195
- }
2196
- center.add(pos);
2197
- return {
2198
- type: type,
2199
- behavior: bounding.behavior,
2200
- radius: bounding.radius || 0,
2201
- center: center,
2202
- clipMasks: _this.frameClipMasks
2203
- };
2204
- }
2205
- }
2206
- };
2207
- if (data) {
2208
- _this.fromData(data);
2209
- }
2210
- return _this;
2211
- }
2212
- var _proto = ModelMeshComponent.prototype;
2213
- /**
2214
- * 组件开始,需要创建内部对象,更新父元素信息和添加到场景管理器中
2215
- */ _proto.onStart = function onStart() {
2216
- var _this_sceneManager;
2217
- this.sceneManager = getSceneManager(this);
2218
- this.createContent();
2219
- this.item.type = VFX_ITEM_TYPE_3D;
2220
- this.priority = this.item.renderOrder;
2221
- (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.addItem(this.content);
2222
- if (this.item.parentId && this.item.parent) {
2223
- this.content.updateParentInfo(this.item.parentId, this.item.parent);
2224
- }
2225
- this.setVisible(true);
2226
- this.item.getHitTestParams = this.getHitTestParams;
1985
+ return _this;
1986
+ }
1987
+ var _proto = ModelLightComponent.prototype;
1988
+ /**
1989
+ * 组件开始,需要创建内部对象和添加到场景管理器中
1990
+ */ _proto.onStart = function onStart() {
1991
+ this.createContent();
1992
+ var scene = getSceneManager(this);
1993
+ scene == null ? void 0 : scene.addItem(this.content);
1994
+ this.setVisible(true);
2227
1995
  };
2228
1996
  /**
2229
1997
  * 组件更新,更新内部对象状态
2230
1998
  * @param dt - 更新间隔
2231
1999
  */ _proto.onUpdate = function onUpdate(dt) {
2232
- if (this.sceneManager) {
2233
- this.content.build(this.sceneManager);
2234
- if (this.firstUpdate) {
2235
- this.materials = this.content.subMeshes.map(function(subMesh) {
2236
- return subMesh.getEffectsMaterial();
2237
- });
2238
- this.firstUpdate = false;
2239
- }
2240
- }
2241
2000
  this.content.update();
2242
2001
  };
2243
2002
  /**
2244
- * 组件晚更新,晚更新内部对象状态
2245
- * @param dt - 更新间隔
2246
- */ _proto.onLateUpdate = function onLateUpdate(dt) {
2247
- this.content.lateUpdate();
2248
- };
2249
- /**
2250
- * 组件渲染,需要检查可见性
2251
- * @param renderer - 渲染器
2252
- * @returns
2253
- */ _proto.render = function render(renderer) {
2254
- if (!this.getVisible() || !this.sceneManager) {
2255
- return;
2256
- }
2257
- this.maskManager.drawStencilMask(renderer, this);
2258
- this.content.render(this.sceneManager, renderer);
2259
- };
2260
- /**
2261
- * 组件销毁,需要重场景管理器中删除
2003
+ * 组件销毁
2262
2004
  */ _proto.onDestroy = function onDestroy() {
2263
- var _this_sceneManager;
2264
- (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.removeItem(this.content);
2265
- this.sceneManager = undefined;
2266
2005
  this.content.dispose();
2267
2006
  };
2268
2007
  /**
2269
2008
  * 反序列化,记录传入参数
2270
2009
  * @param data - 组件参数
2271
2010
  */ _proto.fromData = function fromData(data) {
2272
- RendererComponent.prototype.fromData.call(this, data);
2273
- this.data = _extends({}, data, {
2274
- materials: []
2275
- });
2276
- this.data.rootBone = data.rootBone ? this.engine.findObject(data.rootBone) : undefined;
2277
- this.data.geometry = this.engine.findObject(data.geometry);
2278
- if (data.materials) {
2279
- for(var i = 0; i < data.materials.length; i++){
2280
- this.data.materials[i] = this.engine.findObject(data.materials[i]);
2281
- }
2282
- }
2011
+ Behaviour.prototype.fromData.call(this, data);
2012
+ this.data = data;
2283
2013
  };
2284
2014
  /**
2285
2015
  * 创建内部对象
2286
2016
  */ _proto.createContent = function createContent() {
2287
2017
  if (this.data) {
2288
- var bounding = this.data.interaction;
2289
- this.bounding = bounding && JSON.parse(JSON.stringify(bounding));
2290
- this.content = new PMesh(this.engine, this.item.name, this.data, this, this.item.parentId);
2018
+ var lightData = this.data;
2019
+ this.content = new PLight(this.item.name, lightData, this);
2291
2020
  }
2292
2021
  };
2293
2022
  /**
2294
- * 设置当前 Mesh 的可见性。
2023
+ * 设置当前可见性。
2295
2024
  * @param visible - true:可见,false:不可见
2296
2025
  */ _proto.setVisible = function setVisible(visible) {
2297
2026
  var _this_content;
@@ -2304,248 +2033,71 @@ var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
2304
2033
  var _this_content_visible;
2305
2034
  return (_this_content_visible = (_this_content = this.content) == null ? void 0 : _this_content.visible) != null ? _this_content_visible : false;
2306
2035
  };
2307
- /**
2308
- * 计算元素包围盒,只针对 Mesh 对象
2309
- * @returns 包围盒
2310
- */ _proto.computeBoundingBox = function computeBoundingBox() {
2311
- if (this.content && _instanceof1(this.content, PMesh)) {
2312
- var _this_bounding;
2313
- var worldMatrix = this.transform.getWorldMatrix();
2314
- var bbox = this.content.computeBoundingBox(worldMatrix);
2315
- var center = bbox.getCenter(new Vector3());
2316
- var size = bbox.getSize(new Vector3());
2317
- this.bounding = {
2318
- behavior: (_this_bounding = this.bounding) == null ? void 0 : _this_bounding.behavior,
2319
- type: spec.ModelBoundingType.box,
2320
- center: [
2321
- center.x,
2322
- center.y,
2323
- center.z
2324
- ],
2325
- size: [
2326
- size.x,
2327
- size.y,
2328
- size.z
2329
- ]
2330
- };
2331
- return this.bounding;
2332
- } else {
2333
- return;
2334
- }
2335
- };
2336
- return ModelMeshComponent;
2337
- }(RendererComponent);
2338
- ModelMeshComponent = __decorate([
2339
- effectsClass(spec.DataType.MeshComponent)
2340
- ], ModelMeshComponent);
2341
- var ModelSkyboxComponent = /*#__PURE__*/ function(RendererComponent) {
2342
- _inherits(ModelSkyboxComponent, RendererComponent);
2343
- function ModelSkyboxComponent(engine, data) {
2036
+ return ModelLightComponent;
2037
+ }(Behaviour);
2038
+ ModelLightComponent = __decorate([
2039
+ effectsClass(spec.DataType.LightComponent)
2040
+ ], ModelLightComponent);
2041
+ var ModelCameraComponent = /*#__PURE__*/ function(Behaviour) {
2042
+ _inherits(ModelCameraComponent, Behaviour);
2043
+ function ModelCameraComponent(engine, data) {
2344
2044
  var _this;
2345
- _this = RendererComponent.call(this, engine) || this;
2045
+ _this = Behaviour.call(this, engine) || this;
2346
2046
  if (data) {
2347
2047
  _this.fromData(data);
2348
2048
  }
2349
2049
  return _this;
2350
2050
  }
2351
- var _proto = ModelSkyboxComponent.prototype;
2051
+ var _proto = ModelCameraComponent.prototype;
2352
2052
  /**
2353
2053
  * 组件开始,需要创建内部对象和添加到场景管理器中
2354
2054
  */ _proto.onStart = function onStart() {
2355
- var _this_sceneManager;
2356
2055
  this.createContent();
2357
- this.item.type = VFX_ITEM_TYPE_3D;
2358
- this.priority = this.item.renderOrder;
2359
- this.sceneManager = getSceneManager(this);
2360
- (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.addItem(this.content);
2361
- this.setVisible(true);
2362
- if (this.content.skyboxMesh) {
2363
- this.materials = [
2364
- this.content.skyboxMesh.material
2365
- ];
2366
- }
2056
+ var scene = getSceneManager(this);
2057
+ scene == null ? void 0 : scene.addItem(this.content);
2058
+ this.updateMainCamera();
2367
2059
  };
2368
2060
  /**
2369
- * 组件渲染,需要检查可见性
2370
- * @param renderer - 渲染器
2371
- * @returns
2372
- */ _proto.render = function render(renderer) {
2373
- if (!this.getVisible() || !this.sceneManager) {
2374
- return;
2375
- }
2376
- this.maskManager.drawStencilMask(renderer, this);
2377
- this.content.render(this.sceneManager, renderer);
2061
+ * 组件更新,更新内部对象状态
2062
+ * @param dt - 更新间隔
2063
+ */ _proto.onUpdate = function onUpdate(dt) {
2064
+ this.content.update();
2065
+ this.updateMainCamera();
2378
2066
  };
2379
2067
  /**
2380
- * 组件销毁,需要重场景管理器中删除
2068
+ * 组件销毁
2381
2069
  */ _proto.onDestroy = function onDestroy() {
2382
- var _this_sceneManager;
2383
- (_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.removeItem(this.content);
2384
- this.sceneManager = undefined;
2385
- this.content.dispose();
2070
+ var _this_content;
2071
+ (_this_content = this.content) == null ? void 0 : _this_content.dispose();
2386
2072
  };
2387
2073
  /**
2388
2074
  * 反序列化,记录传入参数
2389
2075
  * @param data - 组件参数
2390
2076
  */ _proto.fromData = function fromData(data) {
2391
- RendererComponent.prototype.fromData.call(this, data);
2392
- data.diffuseImage = data.diffuseImage ? this.engine.findObject(data.diffuseImage) : undefined;
2393
- data.specularImage = this.engine.findObject(data.specularImage);
2077
+ Behaviour.prototype.fromData.call(this, data);
2394
2078
  this.data = data;
2395
2079
  };
2396
2080
  /**
2397
2081
  * 创建内部对象
2398
2082
  */ _proto.createContent = function createContent() {
2399
2083
  if (this.data) {
2400
- var skyboxData = this.data;
2401
- this.content = new PSkybox(this.item.name, skyboxData, this);
2084
+ var cameraData = this.data;
2085
+ var width = this.engine.renderer.getWidth();
2086
+ var height = this.engine.renderer.getHeight();
2087
+ this.content = new PCamera(this.item.name, width, height, cameraData, this);
2402
2088
  }
2403
2089
  };
2404
2090
  /**
2405
- * 设置当前可见性。
2406
- * @param visible - true:可见,false:不可见
2407
- */ _proto.setVisible = function setVisible(visible) {
2408
- var _this_content;
2409
- (_this_content = this.content) == null ? void 0 : _this_content.onVisibleChanged(visible);
2410
- };
2411
- /**
2412
- * 获取当前可见性。
2413
- */ _proto.getVisible = function getVisible() {
2414
- var _this_content;
2415
- var _this_content_visible;
2416
- return (_this_content_visible = (_this_content = this.content) == null ? void 0 : _this_content.visible) != null ? _this_content_visible : false;
2417
- };
2418
- return ModelSkyboxComponent;
2419
- }(RendererComponent);
2420
- ModelSkyboxComponent = __decorate([
2421
- effectsClass(spec.DataType.SkyboxComponent)
2422
- ], ModelSkyboxComponent);
2423
- var ModelLightComponent = /*#__PURE__*/ function(Behaviour) {
2424
- _inherits(ModelLightComponent, Behaviour);
2425
- function ModelLightComponent(engine, data) {
2426
- var _this;
2427
- _this = Behaviour.call(this, engine) || this;
2428
- if (data) {
2429
- _this.fromData(data);
2430
- }
2431
- return _this;
2432
- }
2433
- var _proto = ModelLightComponent.prototype;
2434
- /**
2435
- * 组件开始,需要创建内部对象和添加到场景管理器中
2436
- */ _proto.onStart = function onStart() {
2437
- this.createContent();
2438
- this.item.type = VFX_ITEM_TYPE_3D;
2439
- var scene = getSceneManager(this);
2440
- scene == null ? void 0 : scene.addItem(this.content);
2441
- this.setVisible(true);
2442
- };
2443
- /**
2444
- * 组件更新,更新内部对象状态
2445
- * @param dt - 更新间隔
2446
- */ _proto.onUpdate = function onUpdate(dt) {
2447
- this.content.update();
2448
- };
2449
- /**
2450
- * 组件销毁
2451
- */ _proto.onDestroy = function onDestroy() {
2452
- this.content.dispose();
2453
- };
2454
- /**
2455
- * 反序列化,记录传入参数
2456
- * @param data - 组件参数
2457
- */ _proto.fromData = function fromData(data) {
2458
- Behaviour.prototype.fromData.call(this, data);
2459
- this.data = data;
2460
- };
2461
- /**
2462
- * 创建内部对象
2463
- */ _proto.createContent = function createContent() {
2464
- if (this.data) {
2465
- var lightData = this.data;
2466
- this.content = new PLight(this.item.name, lightData, this);
2467
- }
2468
- };
2469
- /**
2470
- * 设置当前可见性。
2471
- * @param visible - true:可见,false:不可见
2472
- */ _proto.setVisible = function setVisible(visible) {
2473
- var _this_content;
2474
- (_this_content = this.content) == null ? void 0 : _this_content.onVisibleChanged(visible);
2475
- };
2476
- /**
2477
- * 获取当前 Mesh 的可见性。
2478
- */ _proto.getVisible = function getVisible() {
2479
- var _this_content;
2480
- var _this_content_visible;
2481
- return (_this_content_visible = (_this_content = this.content) == null ? void 0 : _this_content.visible) != null ? _this_content_visible : false;
2482
- };
2483
- return ModelLightComponent;
2484
- }(Behaviour);
2485
- ModelLightComponent = __decorate([
2486
- effectsClass(spec.DataType.LightComponent)
2487
- ], ModelLightComponent);
2488
- var ModelCameraComponent = /*#__PURE__*/ function(Behaviour) {
2489
- _inherits(ModelCameraComponent, Behaviour);
2490
- function ModelCameraComponent(engine, data) {
2491
- var _this;
2492
- _this = Behaviour.call(this, engine) || this;
2493
- if (data) {
2494
- _this.fromData(data);
2495
- }
2496
- return _this;
2497
- }
2498
- var _proto = ModelCameraComponent.prototype;
2499
- /**
2500
- * 组件开始,需要创建内部对象和添加到场景管理器中
2501
- */ _proto.onStart = function onStart() {
2502
- this.createContent();
2503
- this.item.type = VFX_ITEM_TYPE_3D;
2504
- var scene = getSceneManager(this);
2505
- scene == null ? void 0 : scene.addItem(this.content);
2506
- this.updateMainCamera();
2507
- };
2508
- /**
2509
- * 组件更新,更新内部对象状态
2510
- * @param dt - 更新间隔
2511
- */ _proto.onUpdate = function onUpdate(dt) {
2512
- this.content.update();
2513
- this.updateMainCamera();
2514
- };
2515
- /**
2516
- * 组件销毁
2517
- */ _proto.onDestroy = function onDestroy() {
2518
- var _this_content;
2519
- (_this_content = this.content) == null ? void 0 : _this_content.dispose();
2520
- };
2521
- /**
2522
- * 反序列化,记录传入参数
2523
- * @param data - 组件参数
2524
- */ _proto.fromData = function fromData(data) {
2525
- Behaviour.prototype.fromData.call(this, data);
2526
- this.data = data;
2527
- };
2528
- /**
2529
- * 创建内部对象
2530
- */ _proto.createContent = function createContent() {
2531
- if (this.data) {
2532
- var cameraData = this.data;
2533
- var width = this.engine.renderer.getWidth();
2534
- var height = this.engine.renderer.getHeight();
2535
- this.content = new PCamera(this.item.name, width, height, cameraData, this);
2536
- }
2537
- };
2538
- /**
2539
- * 更新合成主相机,更加当前相机元素状态
2540
- */ _proto.updateMainCamera = function updateMainCamera() {
2541
- this.content.matrix = this.transform.getWorldMatrix();
2542
- var composition = this.item.composition;
2543
- if (composition) {
2544
- composition.camera.near = this.content.nearPlane;
2545
- composition.camera.far = this.content.farPlane;
2546
- composition.camera.fov = this.content.fov;
2547
- composition.camera.setTransform(this.transform);
2548
- }
2091
+ * 更新合成主相机,更加当前相机元素状态
2092
+ */ _proto.updateMainCamera = function updateMainCamera() {
2093
+ this.content.matrix = this.transform.getWorldMatrix();
2094
+ var composition = this.item.composition;
2095
+ if (composition) {
2096
+ composition.camera.near = this.content.nearPlane;
2097
+ composition.camera.far = this.content.farPlane;
2098
+ composition.camera.fov = this.content.fov;
2099
+ composition.camera.setTransform(this.transform);
2100
+ }
2549
2101
  };
2550
2102
  /**
2551
2103
  * 设置变换
@@ -2580,7 +2132,6 @@ var AnimationComponent = /*#__PURE__*/ function(Behaviour) {
2580
2132
  * 组件开始,需要创建内部对象和添加到场景管理器中
2581
2133
  */ _proto.onStart = function onStart() {
2582
2134
  this.elapsedTime = 0;
2583
- this.item.type = VFX_ITEM_TYPE_3D;
2584
2135
  };
2585
2136
  /**
2586
2137
  * 组件更新,更新内部对象状态
@@ -2609,7 +2160,7 @@ var AnimationComponent = /*#__PURE__*/ function(Behaviour) {
2609
2160
  this.clips = [];
2610
2161
  data.animationClips.forEach(function(clipData) {
2611
2162
  var clipObj = new ModelAnimationClip(_this.engine);
2612
- var animationClip = _this.engine.findObject(clipData);
2163
+ var animationClip = _this.findObject(clipData);
2613
2164
  clipObj.setFromAnimationClip(animationClip);
2614
2165
  _this.clips.push(clipObj);
2615
2166
  });
@@ -3311,9 +2862,6 @@ var normal = new Vector3();
3311
2862
  * @param pass - 渲染 Pass
3312
2863
  */ WebGLHelper.deleteRenderPass = function deleteRenderPass(pass) {
3313
2864
  pass.dispose({
3314
- meshes: {
3315
- geometries: DestroyOptions.destroy
3316
- },
3317
2865
  depthStencilAttachment: RenderPassDestroyAttachmentType.force,
3318
2866
  colorAttachment: RenderPassDestroyAttachmentType.force
3319
2867
  });
@@ -3330,14 +2878,14 @@ var normal = new Vector3();
3330
2878
  * @param engine - 引擎对象
3331
2879
  * @returns
3332
2880
  */ WebGLHelper.isSupportFloatTexture = function isSupportFloatTexture(engine) {
3333
- var capability = engine.gpuCapability;
2881
+ var capability = engine.displayServer.renderingDevice.gpuCapability;
3334
2882
  return capability.detail.floatTexture !== 0;
3335
2883
  };
3336
2884
  /**
3337
2885
  * renderer 是否支持 HalfFloat 纹理
3338
2886
  * @returns
3339
2887
  */ WebGLHelper.isSupportHalfFloatTexture = function isSupportHalfFloatTexture(engine) {
3340
- var capability = engine.gpuCapability;
2888
+ var capability = engine.displayServer.renderingDevice.gpuCapability;
3341
2889
  return capability.detail.halfFloatTexture !== 0;
3342
2890
  };
3343
2891
  /**
@@ -3381,7 +2929,7 @@ var normal = new Vector3();
3381
2929
  var vertexShader = material.vertexShaderCode;
3382
2930
  var fragmentShader = material.fragmentShaderCode;
3383
2931
  var geometry = Geometry.create(engine, MeshHelper.getPlaneGeometry());
3384
- var isWebGL2 = engine.gpuCapability.level === 2;
2932
+ var isWebGL2 = engine.displayServer.renderingDevice.gpuCapability.level === 2;
3385
2933
  var effectsMaterial = Material.create(engine, {
3386
2934
  shader: {
3387
2935
  vertex: vertexShader,
@@ -3405,24 +2953,24 @@ var normal = new Vector3();
3405
2953
  var data = MeshHelper.getPlaneVertexArray();
3406
2954
  var _obj;
3407
2955
  return {
3408
- attributes: (_obj = {}, _obj[VertexBuffer.PositionKind] = {
2956
+ attributes: (_obj = {}, _obj[VertexElementType.Position] = {
3409
2957
  type: glContext.FLOAT,
3410
2958
  size: 3,
3411
2959
  data: data,
3412
2960
  stride: Float32Array.BYTES_PER_ELEMENT * 8,
3413
2961
  offset: 0
3414
- }, _obj[VertexBuffer.UVKind] = {
2962
+ }, _obj[VertexElementType.TexCoord0] = {
3415
2963
  type: glContext.FLOAT,
3416
2964
  size: 2,
3417
2965
  stride: Float32Array.BYTES_PER_ELEMENT * 8,
3418
2966
  offset: Float32Array.BYTES_PER_ELEMENT * 3,
3419
- dataSource: VertexBuffer.PositionKind
3420
- }, _obj[VertexBuffer.NormalKind] = {
2967
+ dataSource: VertexElementType.Position
2968
+ }, _obj[VertexElementType.Normal] = {
3421
2969
  type: glContext.FLOAT,
3422
2970
  size: 3,
3423
2971
  stride: Float32Array.BYTES_PER_ELEMENT * 8,
3424
2972
  offset: Float32Array.BYTES_PER_ELEMENT * 5,
3425
- dataSource: VertexBuffer.PositionKind
2973
+ dataSource: VertexElementType.Position
3426
2974
  }, _obj),
3427
2975
  drawStart: 0,
3428
2976
  drawCount: data.length / 8
@@ -3850,19 +3398,19 @@ var normal = new Vector3();
3850
3398
  */ PluginHelper.getAttributeName = function getAttributeName(name) {
3851
3399
  switch(name){
3852
3400
  case "POSITION":
3853
- return VertexBuffer.PositionKind;
3401
+ return VertexElementType.Position;
3854
3402
  case "NORMAL":
3855
- return VertexBuffer.NormalKind;
3403
+ return VertexElementType.Normal;
3856
3404
  case "TANGENT":
3857
- return VertexBuffer.TangentKind;
3405
+ return VertexElementType.Tangent;
3858
3406
  case "TEXCOORD_0":
3859
- return VertexBuffer.UVKind;
3407
+ return VertexElementType.TexCoord0;
3860
3408
  case "TEXCOORD_1":
3861
- return VertexBuffer.UV2Kind;
3409
+ return VertexElementType.TexCoord1;
3862
3410
  case "JOINTS_0":
3863
- return VertexBuffer.JointsKind;
3411
+ return VertexElementType.BlendIndices;
3864
3412
  case "WEIGHTS_0":
3865
- return VertexBuffer.WeightsKind;
3413
+ return VertexElementType.BlendWeights;
3866
3414
  }
3867
3415
  if (!name.startsWith("a")) {
3868
3416
  // aPos, aNormal, aTangent,
@@ -4215,16 +3763,16 @@ var AttributeArray = /*#__PURE__*/ function() {
4215
3763
  this.drawCount = Math.abs(geometry.getDrawCount());
4216
3764
  //
4217
3765
  this.index = geometry.getIndexData();
4218
- var positionAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.PositionKind));
4219
- var positionArray = geometry.getAttributeData(VertexBuffer.PositionKind);
3766
+ var positionAttrib = getAttributeLayout(geometry, VertexElementType.Position);
3767
+ var positionArray = geometry.getAttributeData(VertexElementType.Position);
4220
3768
  this.position = new AttributeArray();
4221
3769
  this.position.create(positionAttrib, positionArray);
4222
3770
  //
4223
- var jointAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.JointsKind));
4224
- var weightAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.WeightsKind));
3771
+ var jointAttrib = getAttributeLayout(geometry, VertexElementType.BlendIndices);
3772
+ var weightAttrib = getAttributeLayout(geometry, VertexElementType.BlendWeights);
4225
3773
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
4226
- var jointArray = geometry.getAttributeData(VertexBuffer.JointsKind);
4227
- var weightArray = geometry.getAttributeData(VertexBuffer.WeightsKind);
3774
+ var jointArray = geometry.getAttributeData(VertexElementType.BlendIndices);
3775
+ var weightArray = geometry.getAttributeData(VertexElementType.BlendWeights);
4228
3776
  this.joint = new AttributeArray();
4229
3777
  this.joint.create(jointAttrib, jointArray);
4230
3778
  this.weight = new AttributeArray();
@@ -4326,16 +3874,16 @@ var AttributeArray = /*#__PURE__*/ function() {
4326
3874
  this.drawCount = Math.abs(geometry.getDrawCount());
4327
3875
  //
4328
3876
  this.index = geometry.getIndexData();
4329
- var positionAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.PositionKind));
4330
- var positionArray = geometry.getAttributeData(VertexBuffer.PositionKind);
3877
+ var positionAttrib = getAttributeLayout(geometry, VertexElementType.Position);
3878
+ var positionArray = geometry.getAttributeData(VertexElementType.Position);
4331
3879
  this.position = new AttributeArray();
4332
3880
  this.position.create(positionAttrib, positionArray);
4333
3881
  //
4334
- var jointAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.JointsKind));
4335
- var weightAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.WeightsKind));
3882
+ var jointAttrib = getAttributeLayout(geometry, VertexElementType.BlendIndices);
3883
+ var weightAttrib = getAttributeLayout(geometry, VertexElementType.BlendWeights);
4336
3884
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
4337
- var jointArray = geometry.getAttributeData(VertexBuffer.JointsKind);
4338
- var weightArray = geometry.getAttributeData(VertexBuffer.WeightsKind);
3885
+ var jointArray = geometry.getAttributeData(VertexElementType.BlendIndices);
3886
+ var weightArray = geometry.getAttributeData(VertexElementType.BlendWeights);
4339
3887
  this.joint = new AttributeArray();
4340
3888
  this.joint.create(jointAttrib, jointArray);
4341
3889
  this.weight = new AttributeArray();
@@ -4417,15 +3965,16 @@ var AttributeArray = /*#__PURE__*/ function() {
4417
3965
  };
4418
3966
  return HitTestingProxy;
4419
3967
  }();
4420
- function getAttributeLayout(vertexBuffer) {
3968
+ function getAttributeLayout(geometry, name) {
3969
+ var vertexBuffer = geometry.getVertexElement(name);
4421
3970
  if (!vertexBuffer) {
4422
3971
  return;
4423
3972
  }
4424
3973
  return {
4425
3974
  type: vertexBuffer.type,
4426
- size: vertexBuffer.getSize(),
3975
+ size: vertexBuffer.size,
4427
3976
  offset: vertexBuffer.byteOffset,
4428
- stride: vertexBuffer.byteStride,
3977
+ stride: geometry.getAttributeStride(name),
4429
3978
  normalize: vertexBuffer.normalized
4430
3979
  };
4431
3980
  }
@@ -4630,7 +4179,7 @@ var TextureDataMode;
4630
4179
  };
4631
4180
  _proto.getTextureDataMode = function getTextureDataMode(jointCount, engine) {
4632
4181
  var uniformsRequiredForMostFeatures = 25;
4633
- var detail = engine.gpuCapability.detail;
4182
+ var detail = engine.displayServer.renderingDevice.gpuCapability.detail;
4634
4183
  var availableJointUniforms = detail.maxVertexUniforms - uniformsRequiredForMostFeatures;
4635
4184
  var uniformsRequiredPerJoint = 8;
4636
4185
  if (jointCount > Math.floor(availableJointUniforms / uniformsRequiredPerJoint)) {
@@ -7236,12 +6785,12 @@ function _assert_this_initialized(self) {
7236
6785
  }
7237
6786
 
7238
6787
  var uvKinds = [
7239
- VertexBuffer.UVKind,
7240
- VertexBuffer.UV2Kind,
7241
- VertexBuffer.UV3Kind,
7242
- VertexBuffer.UV4Kind,
7243
- VertexBuffer.UV5Kind,
7244
- VertexBuffer.UV6Kind
6788
+ VertexElementType.TexCoord0,
6789
+ VertexElementType.TexCoord1,
6790
+ VertexElementType.TexCoord2,
6791
+ VertexElementType.TexCoord3,
6792
+ VertexElementType.TexCoord4,
6793
+ VertexElementType.TexCoord5
7245
6794
  ];
7246
6795
  /**
7247
6796
  * Mesh 类,负责 Mesh 相关的骨骼动画和 PBR 渲染
@@ -8152,7 +7701,7 @@ var uvKinds = [
8152
7701
  * 是否压缩格式
8153
7702
  * @returns
8154
7703
  */ _proto.isCompressed = function isCompressed() {
8155
- var positionAttrib = this.geometry.getAttributeData(VertexBuffer.PositionKind);
7704
+ var positionAttrib = this.geometry.getAttributeData(VertexElementType.Position);
8156
7705
  if (positionAttrib === undefined) {
8157
7706
  return false;
8158
7707
  }
@@ -8164,19 +7713,19 @@ var uvKinds = [
8164
7713
  * 是否有位置属性
8165
7714
  * @returns
8166
7715
  */ _proto.hasPositions = function hasPositions() {
8167
- return this.hasAttribute(VertexBuffer.PositionKind);
7716
+ return this.hasAttribute(VertexElementType.Position);
8168
7717
  };
8169
7718
  /**
8170
7719
  * 是否有法线属性
8171
7720
  * @returns
8172
7721
  */ _proto.hasNormals = function hasNormals() {
8173
- return this.hasAttribute(VertexBuffer.NormalKind);
7722
+ return this.hasAttribute(VertexElementType.Normal);
8174
7723
  };
8175
7724
  /**
8176
7725
  * 是否有切线属性
8177
7726
  * @returns
8178
7727
  */ _proto.hasTangents = function hasTangents() {
8179
- return this.hasAttribute(VertexBuffer.TangentKind);
7728
+ return this.hasAttribute(VertexElementType.Tangent);
8180
7729
  };
8181
7730
  /**
8182
7731
  * 是否有纹理坐标属性
@@ -8190,19 +7739,19 @@ var uvKinds = [
8190
7739
  * 是否有颜色属性
8191
7740
  * @returns
8192
7741
  */ _proto.hasColors = function hasColors() {
8193
- return this.hasAttribute(VertexBuffer.ColorKind);
7742
+ return this.hasAttribute(VertexElementType.Color);
8194
7743
  };
8195
7744
  /**
8196
7745
  * 是否有关节点属性
8197
7746
  * @returns
8198
7747
  */ _proto.hasJoints = function hasJoints() {
8199
- return this.hasAttribute(VertexBuffer.JointsKind);
7748
+ return this.hasAttribute(VertexElementType.BlendIndices);
8200
7749
  };
8201
7750
  /**
8202
7751
  * 是否有权重属性
8203
7752
  * @returns
8204
7753
  */ _proto.hasWeights = function hasWeights() {
8205
- return this.hasAttribute(VertexBuffer.WeightsKind);
7754
+ return this.hasAttribute(VertexElementType.BlendWeights);
8206
7755
  };
8207
7756
  return PGeometry;
8208
7757
  }();
@@ -8325,7 +7874,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
8325
7874
  }
8326
7875
  };
8327
7876
  _proto.initGlobalState = function initGlobalState(opts) {
8328
- var capbility = this.engine.gpuCapability;
7877
+ var capbility = this.engine.displayServer.renderingDevice.gpuCapability;
8329
7878
  var globalState = PGlobalState.getInstance();
8330
7879
  globalState.reset();
8331
7880
  globalState.isWebGL2 = capbility.level === 2;
@@ -8894,11 +8443,6 @@ var JSONConverter = /*#__PURE__*/ function() {
8894
8443
  (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeInfo.getAllTreeNodeList()));
8895
8444
  newScene.compositionId = oldScene.compositionId;
8896
8445
  newScene.compositions = oldScene.compositions;
8897
- newScene.items.forEach(function(item) {
8898
- if (item.type === "root") {
8899
- item.type = "ECS";
8900
- }
8901
- });
8902
8446
  //@ts-expect-error
8903
8447
  newScene.compositions[0].items = newScene.items.map(function(item) {
8904
8448
  return {
@@ -9077,8 +8621,7 @@ var JSONConverter = /*#__PURE__*/ function() {
9077
8621
  parentId: treeItem.id,
9078
8622
  name: (_node_name = node.name) != null ? _node_name : "node" + index,
9079
8623
  duration: treeItem.duration,
9080
- // @ts-expect-error
9081
- type: "ECS",
8624
+ type: spec.ItemType.tree,
9082
8625
  dataType: spec.DataType.VFXItemData,
9083
8626
  visible: treeItem.visible,
9084
8627
  endBehavior: treeItem.endBehavior,
@@ -9658,7 +9201,7 @@ function getGeometryDataFromOptions(geomOptions) {
9658
9201
  verticesNormalize = (_attribData_normalize = attribData.normalize) != null ? _attribData_normalize : false;
9659
9202
  var _attribData_type;
9660
9203
  verticesType = glType2VertexFormatType((_attribData_type = attribData.type) != null ? _attribData_type : glContext.FLOAT);
9661
- } else if (attrib === VertexBuffer.NormalKind) {
9204
+ } else if (attrib === VertexElementType.Normal) {
9662
9205
  // @ts-expect-error
9663
9206
  modelData.normals = attribData.data;
9664
9207
  var _attribData_normalize1;
@@ -9974,7 +9517,7 @@ function mergeTypedArray(array1, array2, offset) {
9974
9517
  }
9975
9518
  }
9976
9519
  var _obj;
9977
- var vertexBufferSemanticMap = (_obj = {}, _obj[VertexBuffer.PositionKind] = "POSITION", _obj[VertexBuffer.UVKind] = "TEXCOORD0", _obj[VertexBuffer.UV2Kind] = "TEXCOORD1", _obj[VertexBuffer.NormalKind] = "NORMAL", _obj[VertexBuffer.TangentKind] = "TANGENT", _obj[VertexBuffer.ColorKind] = "COLOR", _obj[VertexBuffer.JointsKind] = "JOINTS", _obj[VertexBuffer.WeightsKind] = "WEIGHTS", //
9520
+ var vertexBufferSemanticMap = (_obj = {}, _obj[VertexElementType.Position] = "POSITION", _obj[VertexElementType.TexCoord0] = "TEXCOORD0", _obj[VertexElementType.TexCoord1] = "TEXCOORD1", _obj[VertexElementType.Normal] = "NORMAL", _obj[VertexElementType.Tangent] = "TANGENT", _obj[VertexElementType.Color] = "COLOR", _obj[VertexElementType.BlendIndices] = "JOINTS", _obj[VertexElementType.BlendWeights] = "WEIGHTS", //
9978
9521
  _obj.a_Position = "POSITION", _obj.a_UV = "TEXCOORD0", _obj.a_UV1 = "TEXCOORD0", _obj.a_UV2 = "TEXCOORD1", _obj.a_Normal = "NORMAL", _obj.a_Tangent = "TANGENT", _obj.a_Color = "COLOR", _obj.a_Joints = "JOINTS", _obj.a_Joint1 = "JOINTS", _obj.a_Weights = "WEIGHTS", _obj.a_Weight1 = "WEIGHTS", //
9979
9522
  _obj.a_Target_Position0 = "POSITION_BS0", _obj.a_Target_Position1 = "POSITION_BS1", _obj.a_Target_Position2 = "POSITION_BS2", _obj.a_Target_Position3 = "POSITION_BS3", _obj.a_Target_Position4 = "POSITION_BS4", _obj.a_Target_Position5 = "POSITION_BS5", _obj.a_Target_Position6 = "POSITION_BS6", _obj.a_Target_Position7 = "POSITION_BS7", _obj.a_Target_Normal0 = "NORMAL_BS0", _obj.a_Target_Normal1 = "NORMAL_BS1", _obj.a_Target_Normal2 = "NORMAL_BS2", _obj.a_Target_Normal3 = "NORMAL_BS3", _obj.a_Target_Tangent0 = "TANGENT_BS0", _obj.a_Target_Tangent1 = "TANGENT_BS1", _obj.a_Target_Tangent2 = "TANGENT_BS2", _obj.a_Target_Tangent3 = "TANGENT_BS3", _obj);
9980
9523
 
@@ -10144,11 +9687,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
10144
9687
  case 2:
10145
9688
  _state.sent();
10146
9689
  (_this_items = _this.items).push.apply(_this_items, [].concat(gltfResource.scenes[0].vfxItemData));
10147
- _this.items.forEach(function(item) {
10148
- if (item.type === "root") {
10149
- item.type = "ECS";
10150
- }
10151
- });
10152
9690
  return [
10153
9691
  2,
10154
9692
  _this.getLoadResult()
@@ -11700,5 +11238,409 @@ var GLTFHelper = /*#__PURE__*/ function() {
11700
11238
  return GLTFHelper;
11701
11239
  }();
11702
11240
 
11241
+ var CameraGestureType;
11242
+ (function(CameraGestureType) {
11243
+ CameraGestureType[CameraGestureType["none"] = 0] = "none";
11244
+ CameraGestureType[CameraGestureType["translate"] = 1] = "translate";
11245
+ CameraGestureType[CameraGestureType["rotate_focus"] = 2] = "rotate_focus";
11246
+ CameraGestureType[CameraGestureType["rotate_self"] = 3] = "rotate_self";
11247
+ CameraGestureType[CameraGestureType["scale"] = 4] = "scale";
11248
+ })(CameraGestureType || (CameraGestureType = {}));
11249
+
11250
+ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
11251
+ function CameraGestureHandlerImp(composition) {
11252
+ this.composition = composition;
11253
+ this.cameraTransform = new PTransform();
11254
+ this.cameraCoordiante = new PCoordinate();
11255
+ this.startParams = {
11256
+ type: CameraGestureType.none,
11257
+ mouseEvent: false,
11258
+ clientX: 0,
11259
+ clientY: 0,
11260
+ clientWidth: 512,
11261
+ clientHeight: 512,
11262
+ target: ""
11263
+ };
11264
+ }
11265
+ var _proto = CameraGestureHandlerImp.prototype;
11266
+ _proto.updateComposition = function updateComposition(composition) {
11267
+ this.composition = composition;
11268
+ };
11269
+ _proto.getItem = function getItem() {
11270
+ var _this = this;
11271
+ var _this_composition_items;
11272
+ return (_this_composition_items = this.composition.items) == null ? void 0 : _this_composition_items.find(function(item) {
11273
+ return item.name === _this.getCurrentTarget();
11274
+ });
11275
+ };
11276
+ _proto.getCurrentTarget = function getCurrentTarget() {
11277
+ return this.startParams.target;
11278
+ };
11279
+ _proto.getCurrentType = function getCurrentType() {
11280
+ return this.startParams.type;
11281
+ };
11282
+ _proto.onKeyEvent = function onKeyEvent(event) {
11283
+ // check event camera ID at first
11284
+ if (this.startParams.target !== event.cameraID) {
11285
+ this.startParams.target = event.cameraID;
11286
+ this.startParams.type = CameraGestureType.translate;
11287
+ }
11288
+ // can't find camera item, throw error message
11289
+ var item = this.getItem();
11290
+ if (item === undefined) {
11291
+ console.warn("[CameraGestureHandlerImp] Unable to locate camera item with ID: " + this.startParams.target + ".");
11292
+ return this.composition.camera.getOptions();
11293
+ }
11294
+ var camera = this.composition.camera;
11295
+ var effectsTransfrom = new Transform(_extends({}, camera.getOptions(), {
11296
+ valid: true
11297
+ }));
11298
+ var cameraTransform = new PTransform().fromEffectsTransform(effectsTransfrom);
11299
+ var cameraCoordiante = new PCoordinate().fromPTransform(cameraTransform);
11300
+ var _event_xAxis;
11301
+ // compute move direction
11302
+ var xAxis = (_event_xAxis = event.xAxis) != null ? _event_xAxis : 0;
11303
+ var _event_yAxis;
11304
+ var yAxis = (_event_yAxis = event.yAxis) != null ? _event_yAxis : 0;
11305
+ var _event_zAxis;
11306
+ var zAxis = (_event_zAxis = event.zAxis) != null ? _event_zAxis : 0;
11307
+ var dir = cameraCoordiante.xAxis.clone().multiply(xAxis);
11308
+ dir.add(cameraCoordiante.yAxis.clone().multiply(yAxis));
11309
+ dir.add(cameraCoordiante.zAxis.clone().multiply(zAxis));
11310
+ if (dir.lengthSquared() < 0.00001) {
11311
+ return camera.getOptions();
11312
+ }
11313
+ dir.normalize();
11314
+ var _event_speed;
11315
+ // update camera position
11316
+ var speed = (_event_speed = event.speed) != null ? _event_speed : 0.1;
11317
+ var pos = cameraTransform.getPosition();
11318
+ pos.add(dir.clone().multiply(speed));
11319
+ this.setTransform(item, pos);
11320
+ // update camera transform and coordinates
11321
+ if (this.startParams.type === CameraGestureType.rotate_self) {
11322
+ this.cameraTransform.setPosition(pos);
11323
+ this.cameraCoordiante.origin = pos;
11324
+ }
11325
+ return camera.getOptions();
11326
+ };
11327
+ _proto.onXYMoveBegin = function onXYMoveBegin(x, y, width, height, cameraID) {
11328
+ var args = {
11329
+ type: CameraGestureType.translate,
11330
+ mouseEvent: true,
11331
+ clientX: x,
11332
+ clientY: y,
11333
+ clientWidth: width,
11334
+ clientHeight: height,
11335
+ target: cameraID
11336
+ };
11337
+ return this.startGesture(args);
11338
+ };
11339
+ _proto.onXYMoving = function onXYMoving(x, y, speed) {
11340
+ if (!this.startParams.mouseEvent) {
11341
+ return this.composition.camera.getOptions();
11342
+ }
11343
+ var arg0 = this.startParams;
11344
+ var arg = {
11345
+ type: CameraGestureType.translate,
11346
+ mouseEvent: true,
11347
+ clientX: x,
11348
+ clientY: y,
11349
+ clientWidth: arg0.clientWidth,
11350
+ clientHeight: arg0.clientHeight,
11351
+ target: arg0.target,
11352
+ speed: speed != null ? speed : 0.015
11353
+ };
11354
+ return this.moveGesture(arg);
11355
+ };
11356
+ _proto.onXYMoveEnd = function onXYMoveEnd() {
11357
+ this.endGesture();
11358
+ };
11359
+ _proto.onZMoveBegin = function onZMoveBegin(x, y, width, height, cameraID) {
11360
+ var arg = {
11361
+ type: CameraGestureType.scale,
11362
+ mouseEvent: true,
11363
+ clientX: x,
11364
+ clientY: y,
11365
+ clientWidth: width,
11366
+ clientHeight: height,
11367
+ target: cameraID
11368
+ };
11369
+ return this.startGesture(arg);
11370
+ };
11371
+ _proto.onZMoving = function onZMoving(x, y, speed) {
11372
+ if (speed === void 0) speed = 0.015;
11373
+ if (!this.startParams.mouseEvent) {
11374
+ return this.composition.camera.getOptions();
11375
+ }
11376
+ var arg0 = this.startParams;
11377
+ var arg = {
11378
+ type: CameraGestureType.scale,
11379
+ mouseEvent: true,
11380
+ clientX: x,
11381
+ clientY: y,
11382
+ clientWidth: arg0.clientWidth,
11383
+ clientHeight: arg0.clientHeight,
11384
+ target: arg0.target,
11385
+ speed: speed
11386
+ };
11387
+ return this.moveGesture(arg);
11388
+ };
11389
+ _proto.onZMoveEnd = function onZMoveEnd() {
11390
+ this.endGesture();
11391
+ };
11392
+ _proto.onRotateBegin = function onRotateBegin(x, y, width, height, cameraID) {
11393
+ var arg = {
11394
+ type: CameraGestureType.rotate_self,
11395
+ mouseEvent: true,
11396
+ clientX: x,
11397
+ clientY: y,
11398
+ clientWidth: width,
11399
+ clientHeight: height,
11400
+ target: cameraID
11401
+ };
11402
+ return this.startGesture(arg);
11403
+ };
11404
+ _proto.onRotating = function onRotating(x, y, speed) {
11405
+ if (!this.startParams.mouseEvent) {
11406
+ return this.composition.camera.getOptions();
11407
+ }
11408
+ var arg0 = this.startParams;
11409
+ var arg = {
11410
+ type: CameraGestureType.rotate_self,
11411
+ mouseEvent: true,
11412
+ clientX: x,
11413
+ clientY: y,
11414
+ clientWidth: arg0.clientWidth,
11415
+ clientHeight: arg0.clientHeight,
11416
+ target: arg0.target,
11417
+ speed: speed != null ? speed : 1.5
11418
+ };
11419
+ return this.moveGesture(arg);
11420
+ };
11421
+ _proto.onRotateEnd = function onRotateEnd() {
11422
+ this.endGesture();
11423
+ };
11424
+ _proto.onRotatePointBegin = function onRotatePointBegin(x, y, width, height, point, cameraID) {
11425
+ var arg = {
11426
+ type: CameraGestureType.rotate_focus,
11427
+ mouseEvent: true,
11428
+ clientX: x,
11429
+ clientY: y,
11430
+ clientWidth: width,
11431
+ clientHeight: height,
11432
+ focusPoint: point,
11433
+ target: cameraID
11434
+ };
11435
+ return this.startGesture(arg);
11436
+ };
11437
+ _proto.onRotatingPoint = function onRotatingPoint(x, y, speed) {
11438
+ if (!this.startParams.mouseEvent) {
11439
+ return this.composition.camera.getOptions();
11440
+ }
11441
+ var arg0 = this.startParams;
11442
+ var arg = {
11443
+ type: CameraGestureType.rotate_focus,
11444
+ mouseEvent: true,
11445
+ clientX: x,
11446
+ clientY: y,
11447
+ clientWidth: arg0.clientWidth,
11448
+ clientHeight: arg0.clientHeight,
11449
+ focusPoint: arg0.focusPoint,
11450
+ target: arg0.target,
11451
+ speed: speed != null ? speed : 8.0
11452
+ };
11453
+ return this.moveGesture(arg);
11454
+ };
11455
+ _proto.onRotatePointEnd = function onRotatePointEnd() {
11456
+ this.endGesture();
11457
+ };
11458
+ _proto.moveTo = function moveTo(cameraID, position) {
11459
+ this.startParams.target = cameraID;
11460
+ this.startParams.type = CameraGestureType.none;
11461
+ var item = this.getItem();
11462
+ if (item === undefined) {
11463
+ console.warn("[CameraGestureHandlerImp] Can't find camera item.");
11464
+ return;
11465
+ }
11466
+ this.setPosition(item, position);
11467
+ };
11468
+ _proto.rotateTo = function rotateTo(cameraID, quat) {
11469
+ this.startParams.target = cameraID;
11470
+ this.startParams.type = CameraGestureType.none;
11471
+ var item = this.getItem();
11472
+ if (item === undefined) {
11473
+ console.warn("[CameraGestureHandlerImp] Can't find camera item.");
11474
+ return;
11475
+ }
11476
+ this.setQuaternion(item, quat);
11477
+ };
11478
+ _proto.onFocusPoint = function onFocusPoint(cameraID, point, distance) {
11479
+ this.startParams.target = cameraID;
11480
+ this.startParams.type = CameraGestureType.none;
11481
+ var item = this.getItem();
11482
+ if (item === undefined) {
11483
+ console.warn("[CameraGestureHandlerImp] Can't find camera item.");
11484
+ return;
11485
+ }
11486
+ var newDistance = distance != null ? distance : 5;
11487
+ var targetPoint = Vector3.fromArray(point);
11488
+ //
11489
+ var transform = new PTransform().fromEffectsTransform(item.transform);
11490
+ var coordinate = new PCoordinate().fromPTransform(transform);
11491
+ // FIXME: MATH
11492
+ var lookatDir = Vector3.fromArray(coordinate.zAxis.toArray()).multiply(1.0);
11493
+ //
11494
+ var newOffset = lookatDir.clone().multiply(newDistance);
11495
+ var newPosition = targetPoint.clone().add(newOffset);
11496
+ //
11497
+ this.setTransform(item, newPosition);
11498
+ //
11499
+ // z+方向优先
11500
+ // const cameraPos = Vector3.fromArray(item.transform.position);
11501
+ // const newLookatDir = targetPoint.clone().subVector(cameraPos).normalize();
11502
+ // const newOffset = newLookatDir.clone().multiplyScalar(newDistance);
11503
+ // const newPosition = targetPoint.clone().subVector(newOffset);
11504
+ // const newUpVector = Vector3.tryZUpVector(newLookatDir, new Vector3);
11505
+ // const viewMatrix = Matrix4.computeLookAt(newPosition, targetPoint, newUpVector, new Matrix4);
11506
+ // const tranform = new PTransform().fromMatrix4(viewMatrix);
11507
+ // const newRotation = tranform.rotation;
11508
+ // item.transform.setQuat(-newRotation.x, -newRotation.y, -newRotation.z, newRotation.w);
11509
+ // item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
11510
+ //
11511
+ // 旋转优先
11512
+ // const cameraPos = Vector3.fromArray(item.transform.position);
11513
+ // const newLookatDir = targetPoint.clone().subVector(cameraPos).normalize();
11514
+ // const newOffset = newLookatDir.clone().multiplyScalar(newDistance);
11515
+ // const newPosition = targetPoint.clone().subVector(newOffset);
11516
+ // const oldTransform = new PTransform().fromEffectsTransform(item.transform);
11517
+ // const oldCoordinate = new PCoordinate().fromPTransform(oldTransform)
11518
+ // const oldLookatDir = oldCoordinate.zAxis.clone().multiplyScalar(-1.0);
11519
+ // const rotateAxis = oldLookatDir.cross(newLookatDir);
11520
+ // const sinTheta = rotateAxis.length();
11521
+ // const theta = Math.asin(sinTheta);
11522
+ // const deltaRotation = Quaternion.fromAxisAngle(rotateAxis, theta, new Quaternion);
11523
+ // const newRotation = Quaternion.multiply(deltaRotation, oldTransform.rotation, new Quaternion);
11524
+ // item.transform.setQuat(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
11525
+ // item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
11526
+ //
11527
+ //
11528
+ this.startParams.target = "";
11529
+ };
11530
+ _proto.getCameraTransform = function getCameraTransform() {
11531
+ var camera = this.composition.camera;
11532
+ var transform = new Transform(camera.getOptions());
11533
+ transform.setValid(true);
11534
+ return transform;
11535
+ };
11536
+ _proto.startGesture = function startGesture(args) {
11537
+ this.startParams = args;
11538
+ this.updateCameraTransform(this.composition.camera.getOptions());
11539
+ if (!this.getItem()) {
11540
+ console.warn("[CameraGestureHandlerImp] Invalid target specified in startGesture.");
11541
+ }
11542
+ return this.composition.camera.getOptions();
11543
+ };
11544
+ _proto.moveGesture = function moveGesture(arg) {
11545
+ if (this.getCurrentType() === arg.type) {
11546
+ var item = this.getItem();
11547
+ if (item === undefined) {
11548
+ console.warn("[CameraGestureHandlerImp] Can't find camera item.");
11549
+ return this.composition.camera.getOptions();
11550
+ }
11551
+ var _arg_speed;
11552
+ var speed = (_arg_speed = arg.speed) != null ? _arg_speed : 1.015;
11553
+ var xAxis = this.cameraCoordiante.xAxis;
11554
+ var yAxis = this.cameraCoordiante.yAxis;
11555
+ var zAxis = this.cameraCoordiante.zAxis;
11556
+ var dx = arg.clientX - this.startParams.clientX;
11557
+ var dy = arg.clientY - this.startParams.clientY;
11558
+ if (arg.type === CameraGestureType.translate) {
11559
+ var pos = this.cameraTransform.getPosition();
11560
+ var newPos = pos.clone();
11561
+ newPos.add(xAxis.clone().multiply(-dx * speed));
11562
+ newPos.add(yAxis.clone().multiply(dy * speed));
11563
+ item.transform.setPosition(newPos.x, newPos.y, newPos.z);
11564
+ this.setTransform(item, item.transform.position, item.transform.rotation);
11565
+ } else if (arg.type === CameraGestureType.scale) {
11566
+ var pos1 = this.cameraTransform.getPosition();
11567
+ var newPos1 = pos1.clone();
11568
+ newPos1.add(zAxis.clone().multiply(dy * speed));
11569
+ item.transform.setPosition(newPos1.x, newPos1.y, newPos1.z);
11570
+ this.setTransform(item, item.transform.position, item.transform.rotation);
11571
+ } else if (arg.type === CameraGestureType.rotate_self) {
11572
+ var ndx = dx / arg.clientWidth;
11573
+ var ndy = dy / arg.clientHeight;
11574
+ var dxAngle = ndx * Math.PI * speed * 0.5;
11575
+ var dyAngle = ndy * Math.PI * speed * 0.5;
11576
+ var newRotation = Quaternion.fromAxisAngle(Vector3.Y, -dxAngle);
11577
+ // FIXME: MATH
11578
+ var tempRotation = Quaternion.fromAxisAngle(xAxis, -dyAngle);
11579
+ newRotation.multiply(tempRotation);
11580
+ // FIXME: MATH
11581
+ newRotation.multiply(this.cameraTransform.getRotation());
11582
+ item.transform.setQuaternion(newRotation.x, newRotation.y, newRotation.z, newRotation.w);
11583
+ this.setTransform(item, item.transform.position, item.transform.rotation);
11584
+ } else if (arg.type === CameraGestureType.rotate_focus) {
11585
+ var ndx1 = dx / arg.clientWidth;
11586
+ var ndy1 = dy / arg.clientHeight;
11587
+ var dxAngle1 = ndx1 * Math.PI * speed;
11588
+ var dyAngle1 = ndy1 * Math.PI * speed;
11589
+ var newRotation1 = Quaternion.fromAxisAngle(Vector3.Y, -dxAngle1);
11590
+ var tempRotation1 = Quaternion.fromAxisAngle(xAxis, -dyAngle1);
11591
+ newRotation1.multiply(tempRotation1);
11592
+ var rotateMatrix = newRotation1.toMatrix4(new Matrix4());
11593
+ var targetPoint = Vector3.fromArray(arg.focusPoint);
11594
+ var deltaPosition = this.cameraCoordiante.origin.clone().subtract(targetPoint);
11595
+ rotateMatrix.transformPoint(deltaPosition);
11596
+ var newPosition = deltaPosition.add(targetPoint);
11597
+ newRotation1.multiply(this.cameraTransform.getRotation());
11598
+ item.transform.setPosition(newPosition.x, newPosition.y, newPosition.z);
11599
+ item.transform.setQuaternion(newRotation1.x, newRotation1.y, newRotation1.z, newRotation1.w);
11600
+ this.setTransform(item, newPosition, item.transform.rotation);
11601
+ } else {
11602
+ console.warn("[CameraGestureHandlerImp] Movement type not implemented.");
11603
+ }
11604
+ } else {
11605
+ console.warn("[CameraGestureHandlerImp] Invalid move type specified: " + arg.type);
11606
+ }
11607
+ return this.composition.camera.getOptions();
11608
+ };
11609
+ _proto.setTransform = function setTransform(item, position, rotation) {
11610
+ var camera = item.getComponent(ModelCameraComponent);
11611
+ if (camera !== undefined) {
11612
+ camera.setTransform(position, rotation);
11613
+ }
11614
+ };
11615
+ _proto.setPosition = function setPosition(item, position) {
11616
+ var _item_transform;
11617
+ (_item_transform = item.transform).setPosition.apply(_item_transform, [].concat(position));
11618
+ var camera = item.getComponent(ModelCameraComponent);
11619
+ if (camera !== undefined) {
11620
+ camera.updateMainCamera();
11621
+ }
11622
+ };
11623
+ _proto.setQuaternion = function setQuaternion(item, quat) {
11624
+ var _item_transform;
11625
+ (_item_transform = item.transform).setQuaternion.apply(_item_transform, [].concat(quat));
11626
+ var camera = item.getComponent(ModelCameraComponent);
11627
+ if (camera !== undefined) {
11628
+ camera.updateMainCamera();
11629
+ }
11630
+ };
11631
+ _proto.endGesture = function endGesture() {
11632
+ this.startParams.type = CameraGestureType.none;
11633
+ this.startParams.mouseEvent = false;
11634
+ this.startParams.target = "";
11635
+ };
11636
+ _proto.updateCameraTransform = function updateCameraTransform(cameraOptions) {
11637
+ var effectsTransfrom = new Transform(cameraOptions);
11638
+ effectsTransfrom.setValid(true);
11639
+ this.cameraTransform.fromEffectsTransform(effectsTransfrom);
11640
+ this.cameraCoordiante.fromPTransform(this.cameraTransform);
11641
+ };
11642
+ return CameraGestureHandlerImp;
11643
+ }();
11644
+
11703
11645
  export { CameraGestureHandlerImp, CameraGestureType, JSONConverter, LoaderHelper, LoaderImpl, getDefaultEffectsGLTFLoader, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getGeometryDataFromOptions, getGeometryDataFromPropsList, getPBRShaderProperties, getUnlitShaderProperties, setDefaultEffectsGLTFLoader };
11704
11646
  //# sourceMappingURL=loader.mjs.map