three-base 1.0.50 → 1.0.52
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/declare.d.ts +6 -0
- package/index.ts +3 -0
- package/lib/Sky/Sky.ts +36 -0
- package/lib/Sky/bluesky.jpg +0 -0
- package/lib/ThreeBase.ts +12 -0
- package/lib/Transition.ts +5 -1
- package/lib/type.ts +6 -4
- package/package.json +1 -1
package/declare.d.ts
ADDED
package/index.ts
CHANGED
|
@@ -21,6 +21,9 @@ export { default as InstancedGroupMesh } from "./lib/InstancedGroupMesh";
|
|
|
21
21
|
//点光源
|
|
22
22
|
export { default as PointLight } from "./lib/PointLight";
|
|
23
23
|
|
|
24
|
+
//天空球
|
|
25
|
+
export { default as Sky } from "./lib/Sky/Sky";
|
|
26
|
+
|
|
24
27
|
//键盘控制器
|
|
25
28
|
export { default as keyContorls } from "./lib/keyContorls";
|
|
26
29
|
|
package/lib/Sky/Sky.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-20 18:03:58
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-12-27 09:54:23
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
9
|
+
import threeLoader from "../threeLoader";
|
|
10
|
+
|
|
11
|
+
import blueskyJPG from "./blueSky.jpg";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 天空球
|
|
15
|
+
*/
|
|
16
|
+
export default class Sky extends Mesh {
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super(Sky.geometry);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static geometry = new SphereGeometry(500000, 100, 100);
|
|
23
|
+
|
|
24
|
+
material = new MeshBasicMaterial({
|
|
25
|
+
side: DoubleSide,
|
|
26
|
+
map: threeLoader.getTexture(blueskyJPG)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*设置贴图
|
|
31
|
+
*/
|
|
32
|
+
setMap(src: string) {
|
|
33
|
+
this.material.map = threeLoader.getTexture(src);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
Binary file
|
package/lib/ThreeBase.ts
CHANGED
|
@@ -15,6 +15,7 @@ import threeLoader from "./threeLoader";
|
|
|
15
15
|
import ThreeMouse from "./ThreeMouse";
|
|
16
16
|
import threeUtils from "./threeUtils";
|
|
17
17
|
import Transition from "./Transition";
|
|
18
|
+
import Canvas2image from "canvas-to-png";
|
|
18
19
|
|
|
19
20
|
// three.js 的基础对象
|
|
20
21
|
export default class ThreeBase extends EventDispatcher {
|
|
@@ -322,6 +323,17 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
322
323
|
|
|
323
324
|
renderBindThis = this.render.bind(this);
|
|
324
325
|
|
|
326
|
+
// 下载渲染图
|
|
327
|
+
download(fileName: string = "download") {
|
|
328
|
+
this.render();
|
|
329
|
+
const base64 = this.renderer.domElement.toDataURL('image/png');
|
|
330
|
+
let saveLink = document.createElement("a");
|
|
331
|
+
saveLink.download = `${fileName}.png`;
|
|
332
|
+
saveLink.href = base64;
|
|
333
|
+
document.body.append(saveLink);
|
|
334
|
+
saveLink.click();
|
|
335
|
+
}
|
|
336
|
+
|
|
325
337
|
// 清理渲染目标
|
|
326
338
|
clearRendererTargte(rendererTarget: WebGLRenderTarget | null) {
|
|
327
339
|
const originTarget = this.renderer.getRenderTarget();
|
package/lib/Transition.ts
CHANGED
|
@@ -184,9 +184,13 @@ export default class Transition {
|
|
|
184
184
|
this._isDone = false;
|
|
185
185
|
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
187
189
|
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
if (!this._isDone) {
|
|
192
|
+
await new Promise(resolve => setTimeout(resolve, this._duration));
|
|
193
|
+
}
|
|
190
194
|
|
|
191
195
|
return this;
|
|
192
196
|
}
|
package/lib/type.ts
CHANGED