lythreeframe 1.2.43 → 1.2.45

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,14 @@ 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;
1511
+ }
1512
+ get outer() {
1513
+ return this._outerContainer;
1504
1514
  }
1505
1515
  get renderer() {
1506
1516
  if (!this._renderer) {
@@ -1515,19 +1525,20 @@ class Viewport {
1515
1525
  return this._app;
1516
1526
  }
1517
1527
  constructor(app, viewportParam, rendererParam, postProcessParam) {
1518
- this.uiDom = null;
1528
+ this._uiDom = null;
1519
1529
  this._renderer = null;
1520
1530
  this.labelRenderer = null;
1521
1531
  this._app = null;
1522
1532
  this.resizeObserver = null;
1523
- this._canvas = null;
1533
+ this._outerContainer = null;
1534
+ this._canvasContainer = null;
1524
1535
  this.isRenderStateDirty = true;
1525
1536
  this.postProcessing = null;
1526
1537
  this.outlineObjects = [];
1527
1538
  this.postProcessParam = Object.assign({}, postProcessParam);
1528
1539
  this._app = app;
1529
1540
  if (viewportParam.elementId) {
1530
- this._canvas = document.getElementById(viewportParam.elementId);
1541
+ this._outerContainer = document.getElementById(viewportParam.elementId);
1531
1542
  }
1532
1543
  this.createRenderer(rendererParam);
1533
1544
  if (viewportParam.isLabelRendererNeeded) {
@@ -1536,7 +1547,7 @@ class Viewport {
1536
1547
  if (viewportParam.isUILayerNeeded) {
1537
1548
  this.createUILayer();
1538
1549
  }
1539
- if (this._canvas) {
1550
+ if (this._outerContainer) {
1540
1551
  this.resizeObserver = new ResizeObserver((entries) => {
1541
1552
  for (let entry of entries) {
1542
1553
  if (entry.contentBoxSize) {
@@ -1544,14 +1555,22 @@ class Viewport {
1544
1555
  }
1545
1556
  }
1546
1557
  });
1547
- this.resizeObserver.observe(this._canvas);
1558
+ this.resizeObserver.observe(this._outerContainer);
1548
1559
  }
1549
1560
  this.app.onCameraChangedDelegate.add(() => {
1550
1561
  this.setupPostProcess();
1551
1562
  });
1552
1563
  }
1553
1564
  createRenderer(rendererParam) {
1554
- const element = this._canvas;
1565
+ if (this._outerContainer) {
1566
+ this._canvasContainer = document.createElement("div");
1567
+ this._canvasContainer.style.left = "0px";
1568
+ this._canvasContainer.style.top = "0px";
1569
+ this._canvasContainer.style.width = "100%";
1570
+ this._canvasContainer.style.height = "100%";
1571
+ this._outerContainer.appendChild(this._canvasContainer);
1572
+ }
1573
+ const element = this._canvasContainer;
1555
1574
  if (this._renderer) {
1556
1575
  if (element) {
1557
1576
  element.removeChild(this._renderer.domElement);
@@ -1581,7 +1600,7 @@ class Viewport {
1581
1600
  }
1582
1601
  }
1583
1602
  createLabelRenderer() {
1584
- const element = this._canvas;
1603
+ const element = this._outerContainer;
1585
1604
  if (this.labelRenderer) {
1586
1605
  if (element) {
1587
1606
  element.removeChild(this.labelRenderer.domElement);
@@ -1601,13 +1620,14 @@ class Viewport {
1601
1620
  }
1602
1621
  }
1603
1622
  createUILayer() {
1604
- if (!this._canvas)
1623
+ if (!this._outerContainer)
1605
1624
  return;
1606
1625
  // 检查是否已存在 UI 层,避免重复创建
1607
- let uiLayer = this._canvas.querySelector('.scene-uiLayer');
1626
+ let uiLayer = this._outerContainer.querySelector('.scene-uiLayer');
1608
1627
  if (!uiLayer) {
1609
1628
  uiLayer = document.createElement('div');
1610
1629
  uiLayer.className = 'scene-uiLayer';
1630
+ uiLayer.id = "scene-uiLayer";
1611
1631
  uiLayer.style.position = 'absolute';
1612
1632
  uiLayer.style.left = '0';
1613
1633
  uiLayer.style.top = '0';
@@ -1615,29 +1635,13 @@ class Viewport {
1615
1635
  uiLayer.style.height = '100%';
1616
1636
  uiLayer.style.pointerEvents = 'none'; // UI层默认不响应鼠标事件
1617
1637
  uiLayer.style.zIndex = '10'; // 保证在渲染层之上
1618
- this._canvas.appendChild(uiLayer);
1619
- this.uiDom = uiLayer;
1638
+ this._outerContainer.appendChild(uiLayer);
1639
+ this._uiDom = uiLayer;
1620
1640
  }
1621
1641
  }
1622
1642
  init() {
1623
1643
  this.setupPostProcess();
1624
1644
  }
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
1645
  setupPostProcess() {
1642
1646
  if (this.postProcessParam.steps.length === 0) {
1643
1647
  this.destroyPostProcess();
@@ -1796,7 +1800,7 @@ class Viewport {
1796
1800
  }
1797
1801
  onWindowResize() {
1798
1802
  //console.log("resize")
1799
- let ele = this._canvas;
1803
+ let ele = this._outerContainer;
1800
1804
  if (!ele) {
1801
1805
  return;
1802
1806
  }
@@ -1816,7 +1820,7 @@ class Viewport {
1816
1820
  if (this.postProcessing) {
1817
1821
  this.postProcessing.render();
1818
1822
  }
1819
- else { //console.log("render renderer");
1823
+ else {
1820
1824
  this.renderer.render(this.app.world.scene, this.app.camera);
1821
1825
  }
1822
1826
  if (this.labelRenderer) {
@@ -1833,6 +1837,17 @@ class Viewport {
1833
1837
  else {
1834
1838
  await this.renderer.renderAsync(this.app.world.scene, this.app.camera);
1835
1839
  }
1840
+ // 检查 renderer.domElement 的尺寸
1841
+ const sourceWidth = this.renderer.domElement.width;
1842
+ const sourceHeight = this.renderer.domElement.height;
1843
+ // 如果源尺寸为0,则使用容器尺寸
1844
+ let actualWidth = sourceWidth || width;
1845
+ let actualHeight = sourceHeight || height;
1846
+ if (actualWidth <= 0 || actualHeight <= 0) {
1847
+ // 如果仍然无效,则使用默认值
1848
+ actualWidth = width;
1849
+ actualHeight = height;
1850
+ }
1836
1851
  const offscreenCanvas = document.createElement('canvas');
1837
1852
  offscreenCanvas.width = width;
1838
1853
  offscreenCanvas.height = height;
@@ -1840,7 +1855,8 @@ class Viewport {
1840
1855
  if (!context) {
1841
1856
  throw Error("Can not create context");
1842
1857
  }
1843
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1858
+ // 使用实际尺寸进行绘制
1859
+ context.drawImage(this.renderer.domElement, 0, 0, actualWidth, actualHeight, 0, 0, width, height);
1844
1860
  const ret = offscreenCanvas.toDataURL('image/jpeg');
1845
1861
  offscreenCanvas.remove();
1846
1862
  resolve(ret);
@@ -1916,7 +1932,7 @@ class Viewport {
1916
1932
  this._renderer = null;
1917
1933
  }
1918
1934
  (_a = this.postProcessing) === null || _a === void 0 ? void 0 : _a.dispose();
1919
- this._canvas = null;
1935
+ this._outerContainer = null;
1920
1936
  this._app = null;
1921
1937
  this._renderer = null;
1922
1938
  this.outlineObjects = [];
@@ -2120,7 +2136,6 @@ class Controller {
2120
2136
  }
2121
2137
  updateCamera() {
2122
2138
  var _a, _b;
2123
- console.log("update camera");
2124
2139
  let isPawnEnabled = this.pawn.enabled;
2125
2140
  (_a = this._pawn) === null || _a === void 0 ? void 0 : _a.unpossess();
2126
2141
  (_b = this._pawn) === null || _b === void 0 ? void 0 : _b.destroy();
@@ -2925,7 +2940,8 @@ class ThreeJsApp {
2925
2940
  this._controller = new this._appParam.classes.controllerClass(this);
2926
2941
  this._assetManager = new this._appParam.classes.assetManagerClass(this);
2927
2942
  this.viewport.renderer.setAnimationLoop(() => {
2928
- this.tick();
2943
+ const delta = this._clock.getDelta();
2944
+ this.tick(delta);
2929
2945
  });
2930
2946
  this.postConstruct();
2931
2947
  }
@@ -2936,12 +2952,11 @@ class ThreeJsApp {
2936
2952
  }
2937
2953
  init() {
2938
2954
  }
2939
- tick() {
2940
- const delta = this._clock.getDelta();
2941
- this._controller.tick(delta);
2942
- this.world.tick(delta);
2955
+ tick(deltaTime) {
2956
+ this._controller.tick(deltaTime);
2957
+ this.world.tick(deltaTime);
2943
2958
  this._tickingFunctions.forEach(func => {
2944
- func(delta);
2959
+ func(deltaTime);
2945
2960
  });
2946
2961
  if (this._appParam.isRenderEveryFrame) {
2947
2962
  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,14 @@ 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;
1509
+ }
1510
+ get outer() {
1511
+ return this._outerContainer;
1502
1512
  }
1503
1513
  get renderer() {
1504
1514
  if (!this._renderer) {
@@ -1513,19 +1523,20 @@ class Viewport {
1513
1523
  return this._app;
1514
1524
  }
1515
1525
  constructor(app, viewportParam, rendererParam, postProcessParam) {
1516
- this.uiDom = null;
1526
+ this._uiDom = null;
1517
1527
  this._renderer = null;
1518
1528
  this.labelRenderer = null;
1519
1529
  this._app = null;
1520
1530
  this.resizeObserver = null;
1521
- this._canvas = null;
1531
+ this._outerContainer = null;
1532
+ this._canvasContainer = null;
1522
1533
  this.isRenderStateDirty = true;
1523
1534
  this.postProcessing = null;
1524
1535
  this.outlineObjects = [];
1525
1536
  this.postProcessParam = Object.assign({}, postProcessParam);
1526
1537
  this._app = app;
1527
1538
  if (viewportParam.elementId) {
1528
- this._canvas = document.getElementById(viewportParam.elementId);
1539
+ this._outerContainer = document.getElementById(viewportParam.elementId);
1529
1540
  }
1530
1541
  this.createRenderer(rendererParam);
1531
1542
  if (viewportParam.isLabelRendererNeeded) {
@@ -1534,7 +1545,7 @@ class Viewport {
1534
1545
  if (viewportParam.isUILayerNeeded) {
1535
1546
  this.createUILayer();
1536
1547
  }
1537
- if (this._canvas) {
1548
+ if (this._outerContainer) {
1538
1549
  this.resizeObserver = new ResizeObserver((entries) => {
1539
1550
  for (let entry of entries) {
1540
1551
  if (entry.contentBoxSize) {
@@ -1542,14 +1553,22 @@ class Viewport {
1542
1553
  }
1543
1554
  }
1544
1555
  });
1545
- this.resizeObserver.observe(this._canvas);
1556
+ this.resizeObserver.observe(this._outerContainer);
1546
1557
  }
1547
1558
  this.app.onCameraChangedDelegate.add(() => {
1548
1559
  this.setupPostProcess();
1549
1560
  });
1550
1561
  }
1551
1562
  createRenderer(rendererParam) {
1552
- const element = this._canvas;
1563
+ if (this._outerContainer) {
1564
+ this._canvasContainer = document.createElement("div");
1565
+ this._canvasContainer.style.left = "0px";
1566
+ this._canvasContainer.style.top = "0px";
1567
+ this._canvasContainer.style.width = "100%";
1568
+ this._canvasContainer.style.height = "100%";
1569
+ this._outerContainer.appendChild(this._canvasContainer);
1570
+ }
1571
+ const element = this._canvasContainer;
1553
1572
  if (this._renderer) {
1554
1573
  if (element) {
1555
1574
  element.removeChild(this._renderer.domElement);
@@ -1579,7 +1598,7 @@ class Viewport {
1579
1598
  }
1580
1599
  }
1581
1600
  createLabelRenderer() {
1582
- const element = this._canvas;
1601
+ const element = this._outerContainer;
1583
1602
  if (this.labelRenderer) {
1584
1603
  if (element) {
1585
1604
  element.removeChild(this.labelRenderer.domElement);
@@ -1599,13 +1618,14 @@ class Viewport {
1599
1618
  }
1600
1619
  }
1601
1620
  createUILayer() {
1602
- if (!this._canvas)
1621
+ if (!this._outerContainer)
1603
1622
  return;
1604
1623
  // 检查是否已存在 UI 层,避免重复创建
1605
- let uiLayer = this._canvas.querySelector('.scene-uiLayer');
1624
+ let uiLayer = this._outerContainer.querySelector('.scene-uiLayer');
1606
1625
  if (!uiLayer) {
1607
1626
  uiLayer = document.createElement('div');
1608
1627
  uiLayer.className = 'scene-uiLayer';
1628
+ uiLayer.id = "scene-uiLayer";
1609
1629
  uiLayer.style.position = 'absolute';
1610
1630
  uiLayer.style.left = '0';
1611
1631
  uiLayer.style.top = '0';
@@ -1613,29 +1633,13 @@ class Viewport {
1613
1633
  uiLayer.style.height = '100%';
1614
1634
  uiLayer.style.pointerEvents = 'none'; // UI层默认不响应鼠标事件
1615
1635
  uiLayer.style.zIndex = '10'; // 保证在渲染层之上
1616
- this._canvas.appendChild(uiLayer);
1617
- this.uiDom = uiLayer;
1636
+ this._outerContainer.appendChild(uiLayer);
1637
+ this._uiDom = uiLayer;
1618
1638
  }
1619
1639
  }
1620
1640
  init() {
1621
1641
  this.setupPostProcess();
1622
1642
  }
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
1643
  setupPostProcess() {
1640
1644
  if (this.postProcessParam.steps.length === 0) {
1641
1645
  this.destroyPostProcess();
@@ -1794,7 +1798,7 @@ class Viewport {
1794
1798
  }
1795
1799
  onWindowResize() {
1796
1800
  //console.log("resize")
1797
- let ele = this._canvas;
1801
+ let ele = this._outerContainer;
1798
1802
  if (!ele) {
1799
1803
  return;
1800
1804
  }
@@ -1814,7 +1818,7 @@ class Viewport {
1814
1818
  if (this.postProcessing) {
1815
1819
  this.postProcessing.render();
1816
1820
  }
1817
- else { //console.log("render renderer");
1821
+ else {
1818
1822
  this.renderer.render(this.app.world.scene, this.app.camera);
1819
1823
  }
1820
1824
  if (this.labelRenderer) {
@@ -1831,6 +1835,17 @@ class Viewport {
1831
1835
  else {
1832
1836
  await this.renderer.renderAsync(this.app.world.scene, this.app.camera);
1833
1837
  }
1838
+ // 检查 renderer.domElement 的尺寸
1839
+ const sourceWidth = this.renderer.domElement.width;
1840
+ const sourceHeight = this.renderer.domElement.height;
1841
+ // 如果源尺寸为0,则使用容器尺寸
1842
+ let actualWidth = sourceWidth || width;
1843
+ let actualHeight = sourceHeight || height;
1844
+ if (actualWidth <= 0 || actualHeight <= 0) {
1845
+ // 如果仍然无效,则使用默认值
1846
+ actualWidth = width;
1847
+ actualHeight = height;
1848
+ }
1834
1849
  const offscreenCanvas = document.createElement('canvas');
1835
1850
  offscreenCanvas.width = width;
1836
1851
  offscreenCanvas.height = height;
@@ -1838,7 +1853,8 @@ class Viewport {
1838
1853
  if (!context) {
1839
1854
  throw Error("Can not create context");
1840
1855
  }
1841
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1856
+ // 使用实际尺寸进行绘制
1857
+ context.drawImage(this.renderer.domElement, 0, 0, actualWidth, actualHeight, 0, 0, width, height);
1842
1858
  const ret = offscreenCanvas.toDataURL('image/jpeg');
1843
1859
  offscreenCanvas.remove();
1844
1860
  resolve(ret);
@@ -1914,7 +1930,7 @@ class Viewport {
1914
1930
  this._renderer = null;
1915
1931
  }
1916
1932
  (_a = this.postProcessing) === null || _a === void 0 ? void 0 : _a.dispose();
1917
- this._canvas = null;
1933
+ this._outerContainer = null;
1918
1934
  this._app = null;
1919
1935
  this._renderer = null;
1920
1936
  this.outlineObjects = [];
@@ -2118,7 +2134,6 @@ class Controller {
2118
2134
  }
2119
2135
  updateCamera() {
2120
2136
  var _a, _b;
2121
- console.log("update camera");
2122
2137
  let isPawnEnabled = this.pawn.enabled;
2123
2138
  (_a = this._pawn) === null || _a === void 0 ? void 0 : _a.unpossess();
2124
2139
  (_b = this._pawn) === null || _b === void 0 ? void 0 : _b.destroy();
@@ -2923,7 +2938,8 @@ class ThreeJsApp {
2923
2938
  this._controller = new this._appParam.classes.controllerClass(this);
2924
2939
  this._assetManager = new this._appParam.classes.assetManagerClass(this);
2925
2940
  this.viewport.renderer.setAnimationLoop(() => {
2926
- this.tick();
2941
+ const delta = this._clock.getDelta();
2942
+ this.tick(delta);
2927
2943
  });
2928
2944
  this.postConstruct();
2929
2945
  }
@@ -2934,12 +2950,11 @@ class ThreeJsApp {
2934
2950
  }
2935
2951
  init() {
2936
2952
  }
2937
- tick() {
2938
- const delta = this._clock.getDelta();
2939
- this._controller.tick(delta);
2940
- this.world.tick(delta);
2953
+ tick(deltaTime) {
2954
+ this._controller.tick(deltaTime);
2955
+ this.world.tick(deltaTime);
2941
2956
  this._tickingFunctions.forEach(func => {
2942
- func(delta);
2957
+ func(deltaTime);
2943
2958
  });
2944
2959
  if (this._appParam.isRenderEveryFrame) {
2945
2960
  this.viewport.markRenderStateDirty();
@@ -3,17 +3,19 @@ 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
+ get outer(): HTMLElement | null;
10
11
  get renderer(): WebGPURenderer;
11
12
  get app(): ThreeJsApp;
12
13
  private _renderer;
13
14
  private labelRenderer;
14
15
  protected _app: ThreeJsApp | null;
15
16
  private resizeObserver;
16
- private _canvas;
17
+ private _outerContainer;
18
+ private _canvasContainer;
17
19
  private isRenderStateDirty;
18
20
  private postProcessParam;
19
21
  private postProcessing;
@@ -23,7 +25,6 @@ export declare class Viewport {
23
25
  protected createLabelRenderer(): void;
24
26
  protected createUILayer(): void;
25
27
  init(): void;
26
- addWidget(widget: Widget): void;
27
28
  setupPostProcess(): void;
28
29
  updatePostProcess(steps: PostProcessStepParam[]): void;
29
30
  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.45",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",