lythreeframe 1.2.43 → 1.2.44

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.
@@ -81,6 +81,9 @@ class Component extends BaseObject {
81
81
  }
82
82
  set name(name) {
83
83
  this._name = name;
84
+ if (this.obj) {
85
+ this.obj.name = name;
86
+ }
84
87
  }
85
88
  constructor(uuid) {
86
89
  super(uuid ? uuid : webgpu.MathUtils.generateUUID());
@@ -642,6 +645,7 @@ class SceneComponent extends Component {
642
645
  throw Error("targetComponent threeObject is invalid");
643
646
  }
644
647
  this.obj.remove(targetComponent.threeObject);
648
+ console.log("removeChildComponent");
645
649
  targetComponent.destroy();
646
650
  }
647
651
  detachFromParentComponent() {
@@ -1499,8 +1503,11 @@ class WebGPUPostProcessFactory {
1499
1503
  }
1500
1504
 
1501
1505
  class Viewport {
1506
+ get uiDom() {
1507
+ return this._uiDom;
1508
+ }
1502
1509
  get canvas() {
1503
- return this._canvas;
1510
+ return this._canvasContainer;
1504
1511
  }
1505
1512
  get renderer() {
1506
1513
  if (!this._renderer) {
@@ -1515,19 +1522,20 @@ class Viewport {
1515
1522
  return this._app;
1516
1523
  }
1517
1524
  constructor(app, viewportParam, rendererParam, postProcessParam) {
1518
- this.uiDom = null;
1525
+ this._uiDom = null;
1519
1526
  this._renderer = null;
1520
1527
  this.labelRenderer = null;
1521
1528
  this._app = null;
1522
1529
  this.resizeObserver = null;
1523
- this._canvas = null;
1530
+ this._outerContainer = null;
1531
+ this._canvasContainer = null;
1524
1532
  this.isRenderStateDirty = true;
1525
1533
  this.postProcessing = null;
1526
1534
  this.outlineObjects = [];
1527
1535
  this.postProcessParam = Object.assign({}, postProcessParam);
1528
1536
  this._app = app;
1529
1537
  if (viewportParam.elementId) {
1530
- this._canvas = document.getElementById(viewportParam.elementId);
1538
+ this._outerContainer = document.getElementById(viewportParam.elementId);
1531
1539
  }
1532
1540
  this.createRenderer(rendererParam);
1533
1541
  if (viewportParam.isLabelRendererNeeded) {
@@ -1536,7 +1544,7 @@ class Viewport {
1536
1544
  if (viewportParam.isUILayerNeeded) {
1537
1545
  this.createUILayer();
1538
1546
  }
1539
- if (this._canvas) {
1547
+ if (this._outerContainer) {
1540
1548
  this.resizeObserver = new ResizeObserver((entries) => {
1541
1549
  for (let entry of entries) {
1542
1550
  if (entry.contentBoxSize) {
@@ -1544,14 +1552,22 @@ class Viewport {
1544
1552
  }
1545
1553
  }
1546
1554
  });
1547
- this.resizeObserver.observe(this._canvas);
1555
+ this.resizeObserver.observe(this._outerContainer);
1548
1556
  }
1549
1557
  this.app.onCameraChangedDelegate.add(() => {
1550
1558
  this.setupPostProcess();
1551
1559
  });
1552
1560
  }
1553
1561
  createRenderer(rendererParam) {
1554
- const element = this._canvas;
1562
+ if (this._outerContainer) {
1563
+ this._canvasContainer = document.createElement("div");
1564
+ this._canvasContainer.style.left = "0px";
1565
+ this._canvasContainer.style.top = "0px";
1566
+ this._canvasContainer.style.width = "100%";
1567
+ this._canvasContainer.style.height = "100%";
1568
+ this._outerContainer.appendChild(this._canvasContainer);
1569
+ }
1570
+ const element = this._canvasContainer;
1555
1571
  if (this._renderer) {
1556
1572
  if (element) {
1557
1573
  element.removeChild(this._renderer.domElement);
@@ -1581,7 +1597,7 @@ class Viewport {
1581
1597
  }
1582
1598
  }
1583
1599
  createLabelRenderer() {
1584
- const element = this._canvas;
1600
+ const element = this._outerContainer;
1585
1601
  if (this.labelRenderer) {
1586
1602
  if (element) {
1587
1603
  element.removeChild(this.labelRenderer.domElement);
@@ -1601,13 +1617,14 @@ class Viewport {
1601
1617
  }
1602
1618
  }
1603
1619
  createUILayer() {
1604
- if (!this._canvas)
1620
+ if (!this._outerContainer)
1605
1621
  return;
1606
1622
  // 检查是否已存在 UI 层,避免重复创建
1607
- let uiLayer = this._canvas.querySelector('.scene-uiLayer');
1623
+ let uiLayer = this._outerContainer.querySelector('.scene-uiLayer');
1608
1624
  if (!uiLayer) {
1609
1625
  uiLayer = document.createElement('div');
1610
1626
  uiLayer.className = 'scene-uiLayer';
1627
+ uiLayer.id = "scene-uiLayer";
1611
1628
  uiLayer.style.position = 'absolute';
1612
1629
  uiLayer.style.left = '0';
1613
1630
  uiLayer.style.top = '0';
@@ -1615,29 +1632,13 @@ class Viewport {
1615
1632
  uiLayer.style.height = '100%';
1616
1633
  uiLayer.style.pointerEvents = 'none'; // UI层默认不响应鼠标事件
1617
1634
  uiLayer.style.zIndex = '10'; // 保证在渲染层之上
1618
- this._canvas.appendChild(uiLayer);
1619
- this.uiDom = uiLayer;
1635
+ this._outerContainer.appendChild(uiLayer);
1636
+ this._uiDom = uiLayer;
1620
1637
  }
1621
1638
  }
1622
1639
  init() {
1623
1640
  this.setupPostProcess();
1624
1641
  }
1625
- // addWidget(widget: HTMLElement)
1626
- // {
1627
- // if (!this._canvas) return;
1628
- // let uiLayer = this._canvas.querySelector('.scene-uiLayer') as HTMLDivElement;
1629
- // if(!uiLayer)
1630
- // {
1631
- // console.warn("UI Layer not found, check your settings.");
1632
- // return
1633
- // }
1634
- // uiLayer.appendChild(widget);
1635
- // }
1636
- addWidget(widget) {
1637
- if (!this.uiDom)
1638
- return;
1639
- widget.mount(this.uiDom);
1640
- }
1641
1642
  setupPostProcess() {
1642
1643
  if (this.postProcessParam.steps.length === 0) {
1643
1644
  this.destroyPostProcess();
@@ -1796,7 +1797,7 @@ class Viewport {
1796
1797
  }
1797
1798
  onWindowResize() {
1798
1799
  //console.log("resize")
1799
- let ele = this._canvas;
1800
+ let ele = this._outerContainer;
1800
1801
  if (!ele) {
1801
1802
  return;
1802
1803
  }
@@ -1833,6 +1834,17 @@ class Viewport {
1833
1834
  else {
1834
1835
  await this.renderer.renderAsync(this.app.world.scene, this.app.camera);
1835
1836
  }
1837
+ // 检查 renderer.domElement 的尺寸
1838
+ const sourceWidth = this.renderer.domElement.width;
1839
+ const sourceHeight = this.renderer.domElement.height;
1840
+ // 如果源尺寸为0,则使用容器尺寸
1841
+ let actualWidth = sourceWidth || width;
1842
+ let actualHeight = sourceHeight || height;
1843
+ if (actualWidth <= 0 || actualHeight <= 0) {
1844
+ // 如果仍然无效,则使用默认值
1845
+ actualWidth = width;
1846
+ actualHeight = height;
1847
+ }
1836
1848
  const offscreenCanvas = document.createElement('canvas');
1837
1849
  offscreenCanvas.width = width;
1838
1850
  offscreenCanvas.height = height;
@@ -1840,7 +1852,8 @@ class Viewport {
1840
1852
  if (!context) {
1841
1853
  throw Error("Can not create context");
1842
1854
  }
1843
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1855
+ // 使用实际尺寸进行绘制
1856
+ context.drawImage(this.renderer.domElement, 0, 0, actualWidth, actualHeight, 0, 0, width, height);
1844
1857
  const ret = offscreenCanvas.toDataURL('image/jpeg');
1845
1858
  offscreenCanvas.remove();
1846
1859
  resolve(ret);
@@ -1916,7 +1929,7 @@ class Viewport {
1916
1929
  this._renderer = null;
1917
1930
  }
1918
1931
  (_a = this.postProcessing) === null || _a === void 0 ? void 0 : _a.dispose();
1919
- this._canvas = null;
1932
+ this._outerContainer = null;
1920
1933
  this._app = null;
1921
1934
  this._renderer = null;
1922
1935
  this.outlineObjects = [];
@@ -2120,7 +2133,6 @@ class Controller {
2120
2133
  }
2121
2134
  updateCamera() {
2122
2135
  var _a, _b;
2123
- console.log("update camera");
2124
2136
  let isPawnEnabled = this.pawn.enabled;
2125
2137
  (_a = this._pawn) === null || _a === void 0 ? void 0 : _a.unpossess();
2126
2138
  (_b = this._pawn) === null || _b === void 0 ? void 0 : _b.destroy();
@@ -2925,7 +2937,8 @@ class ThreeJsApp {
2925
2937
  this._controller = new this._appParam.classes.controllerClass(this);
2926
2938
  this._assetManager = new this._appParam.classes.assetManagerClass(this);
2927
2939
  this.viewport.renderer.setAnimationLoop(() => {
2928
- this.tick();
2940
+ const delta = this._clock.getDelta();
2941
+ this.tick(delta);
2929
2942
  });
2930
2943
  this.postConstruct();
2931
2944
  }
@@ -2936,12 +2949,11 @@ class ThreeJsApp {
2936
2949
  }
2937
2950
  init() {
2938
2951
  }
2939
- tick() {
2940
- const delta = this._clock.getDelta();
2941
- this._controller.tick(delta);
2942
- this.world.tick(delta);
2952
+ tick(deltaTime) {
2953
+ this._controller.tick(deltaTime);
2954
+ this.world.tick(deltaTime);
2943
2955
  this._tickingFunctions.forEach(func => {
2944
- func(delta);
2956
+ func(deltaTime);
2945
2957
  });
2946
2958
  if (this._appParam.isRenderEveryFrame) {
2947
2959
  this.viewport.markRenderStateDirty();
@@ -79,6 +79,9 @@ class Component extends BaseObject {
79
79
  }
80
80
  set name(name) {
81
81
  this._name = name;
82
+ if (this.obj) {
83
+ this.obj.name = name;
84
+ }
82
85
  }
83
86
  constructor(uuid) {
84
87
  super(uuid ? uuid : MathUtils.generateUUID());
@@ -640,6 +643,7 @@ class SceneComponent extends Component {
640
643
  throw Error("targetComponent threeObject is invalid");
641
644
  }
642
645
  this.obj.remove(targetComponent.threeObject);
646
+ console.log("removeChildComponent");
643
647
  targetComponent.destroy();
644
648
  }
645
649
  detachFromParentComponent() {
@@ -1497,8 +1501,11 @@ class WebGPUPostProcessFactory {
1497
1501
  }
1498
1502
 
1499
1503
  class Viewport {
1504
+ get uiDom() {
1505
+ return this._uiDom;
1506
+ }
1500
1507
  get canvas() {
1501
- return this._canvas;
1508
+ return this._canvasContainer;
1502
1509
  }
1503
1510
  get renderer() {
1504
1511
  if (!this._renderer) {
@@ -1513,19 +1520,20 @@ class Viewport {
1513
1520
  return this._app;
1514
1521
  }
1515
1522
  constructor(app, viewportParam, rendererParam, postProcessParam) {
1516
- this.uiDom = null;
1523
+ this._uiDom = null;
1517
1524
  this._renderer = null;
1518
1525
  this.labelRenderer = null;
1519
1526
  this._app = null;
1520
1527
  this.resizeObserver = null;
1521
- this._canvas = null;
1528
+ this._outerContainer = null;
1529
+ this._canvasContainer = null;
1522
1530
  this.isRenderStateDirty = true;
1523
1531
  this.postProcessing = null;
1524
1532
  this.outlineObjects = [];
1525
1533
  this.postProcessParam = Object.assign({}, postProcessParam);
1526
1534
  this._app = app;
1527
1535
  if (viewportParam.elementId) {
1528
- this._canvas = document.getElementById(viewportParam.elementId);
1536
+ this._outerContainer = document.getElementById(viewportParam.elementId);
1529
1537
  }
1530
1538
  this.createRenderer(rendererParam);
1531
1539
  if (viewportParam.isLabelRendererNeeded) {
@@ -1534,7 +1542,7 @@ class Viewport {
1534
1542
  if (viewportParam.isUILayerNeeded) {
1535
1543
  this.createUILayer();
1536
1544
  }
1537
- if (this._canvas) {
1545
+ if (this._outerContainer) {
1538
1546
  this.resizeObserver = new ResizeObserver((entries) => {
1539
1547
  for (let entry of entries) {
1540
1548
  if (entry.contentBoxSize) {
@@ -1542,14 +1550,22 @@ class Viewport {
1542
1550
  }
1543
1551
  }
1544
1552
  });
1545
- this.resizeObserver.observe(this._canvas);
1553
+ this.resizeObserver.observe(this._outerContainer);
1546
1554
  }
1547
1555
  this.app.onCameraChangedDelegate.add(() => {
1548
1556
  this.setupPostProcess();
1549
1557
  });
1550
1558
  }
1551
1559
  createRenderer(rendererParam) {
1552
- const element = this._canvas;
1560
+ if (this._outerContainer) {
1561
+ this._canvasContainer = document.createElement("div");
1562
+ this._canvasContainer.style.left = "0px";
1563
+ this._canvasContainer.style.top = "0px";
1564
+ this._canvasContainer.style.width = "100%";
1565
+ this._canvasContainer.style.height = "100%";
1566
+ this._outerContainer.appendChild(this._canvasContainer);
1567
+ }
1568
+ const element = this._canvasContainer;
1553
1569
  if (this._renderer) {
1554
1570
  if (element) {
1555
1571
  element.removeChild(this._renderer.domElement);
@@ -1579,7 +1595,7 @@ class Viewport {
1579
1595
  }
1580
1596
  }
1581
1597
  createLabelRenderer() {
1582
- const element = this._canvas;
1598
+ const element = this._outerContainer;
1583
1599
  if (this.labelRenderer) {
1584
1600
  if (element) {
1585
1601
  element.removeChild(this.labelRenderer.domElement);
@@ -1599,13 +1615,14 @@ class Viewport {
1599
1615
  }
1600
1616
  }
1601
1617
  createUILayer() {
1602
- if (!this._canvas)
1618
+ if (!this._outerContainer)
1603
1619
  return;
1604
1620
  // 检查是否已存在 UI 层,避免重复创建
1605
- let uiLayer = this._canvas.querySelector('.scene-uiLayer');
1621
+ let uiLayer = this._outerContainer.querySelector('.scene-uiLayer');
1606
1622
  if (!uiLayer) {
1607
1623
  uiLayer = document.createElement('div');
1608
1624
  uiLayer.className = 'scene-uiLayer';
1625
+ uiLayer.id = "scene-uiLayer";
1609
1626
  uiLayer.style.position = 'absolute';
1610
1627
  uiLayer.style.left = '0';
1611
1628
  uiLayer.style.top = '0';
@@ -1613,29 +1630,13 @@ class Viewport {
1613
1630
  uiLayer.style.height = '100%';
1614
1631
  uiLayer.style.pointerEvents = 'none'; // UI层默认不响应鼠标事件
1615
1632
  uiLayer.style.zIndex = '10'; // 保证在渲染层之上
1616
- this._canvas.appendChild(uiLayer);
1617
- this.uiDom = uiLayer;
1633
+ this._outerContainer.appendChild(uiLayer);
1634
+ this._uiDom = uiLayer;
1618
1635
  }
1619
1636
  }
1620
1637
  init() {
1621
1638
  this.setupPostProcess();
1622
1639
  }
1623
- // addWidget(widget: HTMLElement)
1624
- // {
1625
- // if (!this._canvas) return;
1626
- // let uiLayer = this._canvas.querySelector('.scene-uiLayer') as HTMLDivElement;
1627
- // if(!uiLayer)
1628
- // {
1629
- // console.warn("UI Layer not found, check your settings.");
1630
- // return
1631
- // }
1632
- // uiLayer.appendChild(widget);
1633
- // }
1634
- addWidget(widget) {
1635
- if (!this.uiDom)
1636
- return;
1637
- widget.mount(this.uiDom);
1638
- }
1639
1640
  setupPostProcess() {
1640
1641
  if (this.postProcessParam.steps.length === 0) {
1641
1642
  this.destroyPostProcess();
@@ -1794,7 +1795,7 @@ class Viewport {
1794
1795
  }
1795
1796
  onWindowResize() {
1796
1797
  //console.log("resize")
1797
- let ele = this._canvas;
1798
+ let ele = this._outerContainer;
1798
1799
  if (!ele) {
1799
1800
  return;
1800
1801
  }
@@ -1831,6 +1832,17 @@ class Viewport {
1831
1832
  else {
1832
1833
  await this.renderer.renderAsync(this.app.world.scene, this.app.camera);
1833
1834
  }
1835
+ // 检查 renderer.domElement 的尺寸
1836
+ const sourceWidth = this.renderer.domElement.width;
1837
+ const sourceHeight = this.renderer.domElement.height;
1838
+ // 如果源尺寸为0,则使用容器尺寸
1839
+ let actualWidth = sourceWidth || width;
1840
+ let actualHeight = sourceHeight || height;
1841
+ if (actualWidth <= 0 || actualHeight <= 0) {
1842
+ // 如果仍然无效,则使用默认值
1843
+ actualWidth = width;
1844
+ actualHeight = height;
1845
+ }
1834
1846
  const offscreenCanvas = document.createElement('canvas');
1835
1847
  offscreenCanvas.width = width;
1836
1848
  offscreenCanvas.height = height;
@@ -1838,7 +1850,8 @@ class Viewport {
1838
1850
  if (!context) {
1839
1851
  throw Error("Can not create context");
1840
1852
  }
1841
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1853
+ // 使用实际尺寸进行绘制
1854
+ context.drawImage(this.renderer.domElement, 0, 0, actualWidth, actualHeight, 0, 0, width, height);
1842
1855
  const ret = offscreenCanvas.toDataURL('image/jpeg');
1843
1856
  offscreenCanvas.remove();
1844
1857
  resolve(ret);
@@ -1914,7 +1927,7 @@ class Viewport {
1914
1927
  this._renderer = null;
1915
1928
  }
1916
1929
  (_a = this.postProcessing) === null || _a === void 0 ? void 0 : _a.dispose();
1917
- this._canvas = null;
1930
+ this._outerContainer = null;
1918
1931
  this._app = null;
1919
1932
  this._renderer = null;
1920
1933
  this.outlineObjects = [];
@@ -2118,7 +2131,6 @@ class Controller {
2118
2131
  }
2119
2132
  updateCamera() {
2120
2133
  var _a, _b;
2121
- console.log("update camera");
2122
2134
  let isPawnEnabled = this.pawn.enabled;
2123
2135
  (_a = this._pawn) === null || _a === void 0 ? void 0 : _a.unpossess();
2124
2136
  (_b = this._pawn) === null || _b === void 0 ? void 0 : _b.destroy();
@@ -2923,7 +2935,8 @@ class ThreeJsApp {
2923
2935
  this._controller = new this._appParam.classes.controllerClass(this);
2924
2936
  this._assetManager = new this._appParam.classes.assetManagerClass(this);
2925
2937
  this.viewport.renderer.setAnimationLoop(() => {
2926
- this.tick();
2938
+ const delta = this._clock.getDelta();
2939
+ this.tick(delta);
2927
2940
  });
2928
2941
  this.postConstruct();
2929
2942
  }
@@ -2934,12 +2947,11 @@ class ThreeJsApp {
2934
2947
  }
2935
2948
  init() {
2936
2949
  }
2937
- tick() {
2938
- const delta = this._clock.getDelta();
2939
- this._controller.tick(delta);
2940
- this.world.tick(delta);
2950
+ tick(deltaTime) {
2951
+ this._controller.tick(deltaTime);
2952
+ this.world.tick(deltaTime);
2941
2953
  this._tickingFunctions.forEach(func => {
2942
- func(delta);
2954
+ func(deltaTime);
2943
2955
  });
2944
2956
  if (this._appParam.isRenderEveryFrame) {
2945
2957
  this.viewport.markRenderStateDirty();
@@ -3,9 +3,9 @@ import { ThreeJsApp } from "../ThreeJsApp";
3
3
  import { PostProcessParam, PostProcessStepParam } from './../PostProcess/PostProcessParam';
4
4
  import { RendererParameters } from './Parameters/RendererParameters';
5
5
  import { ViewportParam } from './Parameters/ViewportParameters';
6
- import { Widget } from "@/script/scene/Editor/Widget/Widget";
7
6
  export declare class Viewport {
8
- protected uiDom: HTMLDivElement | null;
7
+ get uiDom(): HTMLDivElement | null;
8
+ protected _uiDom: HTMLDivElement | null;
9
9
  get canvas(): HTMLElement | null;
10
10
  get renderer(): WebGPURenderer;
11
11
  get app(): ThreeJsApp;
@@ -13,7 +13,8 @@ export declare class Viewport {
13
13
  private labelRenderer;
14
14
  protected _app: ThreeJsApp | null;
15
15
  private resizeObserver;
16
- private _canvas;
16
+ private _outerContainer;
17
+ private _canvasContainer;
17
18
  private isRenderStateDirty;
18
19
  private postProcessParam;
19
20
  private postProcessing;
@@ -23,7 +24,6 @@ export declare class Viewport {
23
24
  protected createLabelRenderer(): void;
24
25
  protected createUILayer(): void;
25
26
  init(): void;
26
- addWidget(widget: Widget): void;
27
27
  setupPostProcess(): void;
28
28
  updatePostProcess(steps: PostProcessStepParam[]): void;
29
29
  updateRendererSettings(data: RendererParameters): void;
@@ -27,7 +27,7 @@ export declare class ThreeJsApp {
27
27
  constructor(appParam?: AppParam);
28
28
  protected postConstruct(): void;
29
29
  init(): void;
30
- tick(): void;
30
+ protected tick(deltaTime: number): void;
31
31
  addTickingFunction(func: (deltaTime: number) => void): void;
32
32
  removeTickingFunction(func: (deltaTime: number) => void): void;
33
33
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lythreeframe",
3
- "version": "1.2.43",
3
+ "version": "1.2.44",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",