three-base 1.129.10 → 1.129.14
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/lib/ThreeBase.d.ts +1 -1
- package/lib/ThreeBase.js +8 -14
- package/lib/ThreeBase.ts +9 -15
- package/package.json +1 -1
package/lib/ThreeBase.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
16
16
|
controls: OrbitControls;
|
|
17
17
|
isRendererContextLost: boolean;
|
|
18
18
|
setContainer(div: HTMLDivElement | null): Promise<void>;
|
|
19
|
-
|
|
19
|
+
setsize(width: number, height: number): void;
|
|
20
20
|
controlsPosition: Transition;
|
|
21
21
|
controlsCenter: Transition;
|
|
22
22
|
init(): void;
|
package/lib/ThreeBase.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-03-30 11:00:20
|
|
6
6
|
*/
|
|
7
|
-
import elementResizeEvent from "element-resize-event";
|
|
8
7
|
import { round } from "lodash";
|
|
9
8
|
import { AxesHelper, EventDispatcher, GridHelper, LinearFilter, Mesh, MOUSE, NoBlending, NormalBlending, PerspectiveCamera, RGBAFormat, Scene, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
10
9
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
@@ -76,13 +75,6 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
76
75
|
for (let c of canvas)
|
|
77
76
|
c.remove();
|
|
78
77
|
div.append(this.renderer.domElement);
|
|
79
|
-
// 监听容器的尺寸的改变
|
|
80
|
-
elementResizeEvent(div, () => {
|
|
81
|
-
let rect = window.getComputedStyle(div);
|
|
82
|
-
let width = parseInt(rect.width);
|
|
83
|
-
let height = parseInt(rect.height);
|
|
84
|
-
this.resize(width, height);
|
|
85
|
-
});
|
|
86
78
|
// 如果上下文被销毁了, 就恢复上下文
|
|
87
79
|
if (this.isRendererContextLost) {
|
|
88
80
|
//@ts-ignore
|
|
@@ -91,17 +83,14 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
91
83
|
await new Promise(resolve => requestAnimationFrame(resolve));
|
|
92
84
|
this.renderer.domElement.style.opacity = "1";
|
|
93
85
|
}
|
|
94
|
-
|
|
95
|
-
let width = parseInt(rect.width);
|
|
96
|
-
let height = parseInt(rect.height);
|
|
97
|
-
this.resize(width, height);
|
|
86
|
+
this.setsize(div.clientWidth, div.clientHeight);
|
|
98
87
|
// 开启时时渲染
|
|
99
88
|
threeUtils.removeEventListener("requestAnimationFrame", this.renderBindThis);
|
|
100
89
|
threeUtils.addEventListener("requestAnimationFrame", this.renderBindThis);
|
|
101
90
|
}
|
|
102
91
|
}
|
|
103
92
|
// 修改尺寸
|
|
104
|
-
|
|
93
|
+
setsize(width, height) {
|
|
105
94
|
this.camera.aspect = width / height;
|
|
106
95
|
this.camera.updateProjectionMatrix();
|
|
107
96
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
@@ -234,7 +223,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
234
223
|
this.renderer.forceContextLoss();
|
|
235
224
|
// 标记上下文被销毁了
|
|
236
225
|
this.isRendererContextLost = true;
|
|
237
|
-
this.
|
|
226
|
+
this.setsize(100, 100);
|
|
238
227
|
this.renderer.domElement.style.opacity = "0";
|
|
239
228
|
}
|
|
240
229
|
// 渲染场景
|
|
@@ -246,6 +235,11 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
246
235
|
this.stopRender();
|
|
247
236
|
return;
|
|
248
237
|
}
|
|
238
|
+
//判断尺寸发生改变时重置尺寸
|
|
239
|
+
const parentNode = this.renderer.domElement.parentNode;
|
|
240
|
+
if (parentNode.clientWidth !== this.size.x || parentNode.clientHeight !== this.size.y) {
|
|
241
|
+
this.setsize(parentNode.clientWidth, parentNode.clientHeight);
|
|
242
|
+
}
|
|
249
243
|
// 分发鼠标事件
|
|
250
244
|
this.threeMouse.dispatchEvent();
|
|
251
245
|
// 在不自动渲染时, needRender=false 就跳过渲染
|
package/lib/ThreeBase.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @Last Modified time: 2023-03-30 11:00:20
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import elementResizeEvent from "element-resize-event";
|
|
9
8
|
import { round } from "lodash";
|
|
10
9
|
import { AxesHelper, BufferGeometry, EventDispatcher, GridHelper, LinearFilter, Mesh, MeshBasicMaterial, MOUSE, NoBlending, NormalBlending, Object3D, PerspectiveCamera, RGBAFormat, Scene, Texture, TOUCH, Vector2, Vector3, WebGLRenderer, WebGLRenderTarget } from "three";
|
|
11
10
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
@@ -92,14 +91,6 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
92
91
|
for (let c of canvas) c.remove();
|
|
93
92
|
div.append(this.renderer.domElement);
|
|
94
93
|
|
|
95
|
-
// 监听容器的尺寸的改变
|
|
96
|
-
elementResizeEvent(div, () => {
|
|
97
|
-
let rect = window.getComputedStyle(div);
|
|
98
|
-
let width = parseInt(rect.width);
|
|
99
|
-
let height = parseInt(rect.height);
|
|
100
|
-
this.resize(width, height);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
94
|
// 如果上下文被销毁了, 就恢复上下文
|
|
104
95
|
if (this.isRendererContextLost) {
|
|
105
96
|
//@ts-ignore
|
|
@@ -109,10 +100,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
109
100
|
this.renderer.domElement.style.opacity = "1";
|
|
110
101
|
}
|
|
111
102
|
|
|
112
|
-
|
|
113
|
-
let width = parseInt(rect.width);
|
|
114
|
-
let height = parseInt(rect.height);
|
|
115
|
-
this.resize(width, height);
|
|
103
|
+
this.setsize(div.clientWidth, div.clientHeight);
|
|
116
104
|
|
|
117
105
|
// 开启时时渲染
|
|
118
106
|
threeUtils.removeEventListener("requestAnimationFrame", this.renderBindThis);
|
|
@@ -121,7 +109,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
121
109
|
}
|
|
122
110
|
|
|
123
111
|
// 修改尺寸
|
|
124
|
-
|
|
112
|
+
setsize(width: number, height: number) {
|
|
125
113
|
this.camera.aspect = width / height;
|
|
126
114
|
this.camera.updateProjectionMatrix();
|
|
127
115
|
this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
@@ -277,7 +265,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
277
265
|
this.renderer.forceContextLoss();
|
|
278
266
|
// 标记上下文被销毁了
|
|
279
267
|
this.isRendererContextLost = true;
|
|
280
|
-
this.
|
|
268
|
+
this.setsize(100, 100);
|
|
281
269
|
this.renderer.domElement.style.opacity = "0";
|
|
282
270
|
}
|
|
283
271
|
|
|
@@ -293,6 +281,12 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
293
281
|
return;
|
|
294
282
|
}
|
|
295
283
|
|
|
284
|
+
//判断尺寸发生改变时重置尺寸
|
|
285
|
+
const parentNode = this.renderer.domElement.parentNode as HTMLDivElement;
|
|
286
|
+
if (parentNode.clientWidth !== this.size.x || parentNode.clientHeight !== this.size.y) {
|
|
287
|
+
this.setsize(parentNode.clientWidth, parentNode.clientHeight);
|
|
288
|
+
}
|
|
289
|
+
|
|
296
290
|
// 分发鼠标事件
|
|
297
291
|
this.threeMouse.dispatchEvent();
|
|
298
292
|
|