three-base 1.129.17 → 2.0.2
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/planeModal1 → PlaneModal1}/PlaneModal1.d.ts +1 -1
- package/{lib/planeModal1 → PlaneModal1}/PlaneModal1.js +3 -2
- package/{lib/planeModal1 → PlaneModal1}/PlaneModal1.ts +3 -2
- package/PlaneModal1/index.d.ts +1 -0
- package/PlaneModal1/index.js +1 -0
- package/PlaneModal1/index.ts +1 -0
- package/PlaneText.d.ts +37 -0
- package/PointLight/index.d.ts +1 -0
- package/PointLight/index.js +1 -0
- package/PointLight/index.ts +1 -0
- package/README.md +1 -0
- package/Sky/index.d.ts +1 -0
- package/Sky/index.js +1 -0
- package/Sky/index.ts +1 -0
- package/{lib/spriteModal1 → SpriteModal1}/SpriteModal1.d.ts +1 -1
- package/{lib/spriteModal1 → SpriteModal1}/SpriteModal1.js +3 -2
- package/{lib/spriteModal1 → SpriteModal1}/SpriteModal1.ts +2 -1
- package/SpriteModal1/index.d.ts +1 -0
- package/SpriteModal1/index.js +1 -0
- package/SpriteModal1/index.ts +1 -0
- package/{lib/SpriteText.d.ts → SpriteText.d.ts} +3 -3
- package/{lib/SpriteText.ts → SpriteText.ts} +1 -1
- package/{lib/Text3D → Text3D}/Text3D.js +4 -3
- package/{lib/Text3D → Text3D}/Text3D.ts +4 -3
- package/{lib/Text3D → Text3D}/fontController.d.ts +1 -1
- package/{lib/Text3D → Text3D}/fontController.js +2 -2
- package/{lib/Text3D → Text3D}/fontController.ts +2 -2
- package/Text3D/index.d.ts +1 -0
- package/Text3D/index.js +1 -0
- package/Text3D/index.ts +1 -0
- package/{lib/ThreeBase.d.ts → ThreeBase.d.ts} +3 -1
- package/{lib/ThreeBase.js → ThreeBase.js} +24 -18
- package/{lib/ThreeBase.ts → ThreeBase.ts} +26 -19
- package/{lib/ThreeMouse.js → ThreeMouse.js} +2 -0
- package/{lib/ThreeMouse.ts → ThreeMouse.ts} +2 -1
- package/index.d.ts +1 -0
- package/index.js +1 -37
- package/index.ts +1 -61
- package/{lib/keyContorls.d.ts → keyContorls.d.ts} +2 -2
- package/{lib/keyContorls.ts → keyContorls.ts} +2 -2
- package/package.json +17 -22
- package/{lib/stroke_pass → pass}/FullScreenQuad.d.ts +1 -1
- package/{lib/threeLoader.d.ts → threeLoader.d.ts} +2 -2
- package/{lib/threeLoader.js → threeLoader.js} +14 -6
- package/{lib/threeLoader.ts → threeLoader.ts} +19 -8
- package/{lib/threeUtils.d.ts → threeUtils.d.ts} +4 -1
- package/{lib/threeUtils.js → threeUtils.js} +59 -5
- package/{lib/threeUtils.ts → threeUtils.ts} +68 -9
- package/tsconfig.json +39 -0
- package/lib/PlaneText.d.ts +0 -37
- package/lib/index.d.ts +0 -22
- package/lib/type.d.ts +0 -0
- package/lib/type.js +0 -10
- package/lib/type.ts +0 -13
- /package/{lib/ApngTexture.d.ts → ApngTexture.d.ts} +0 -0
- /package/{lib/ApngTexture.js → ApngTexture.js} +0 -0
- /package/{lib/ApngTexture.ts → ApngTexture.ts} +0 -0
- /package/{lib/ApngTextureManage.d.ts → ApngTextureManage.d.ts} +0 -0
- /package/{lib/ApngTextureManage.js → ApngTextureManage.js} +0 -0
- /package/{lib/ApngTextureManage.ts → ApngTextureManage.ts} +0 -0
- /package/{lib/EventMesh.d.ts → EventMesh.d.ts} +0 -0
- /package/{lib/EventMesh.js → EventMesh.js} +0 -0
- /package/{lib/EventMesh.ts → EventMesh.ts} +0 -0
- /package/{lib/ExtrudeMesh.d.ts → ExtrudeMesh.d.ts} +0 -0
- /package/{lib/ExtrudeMesh.js → ExtrudeMesh.js} +0 -0
- /package/{lib/ExtrudeMesh.ts → ExtrudeMesh.ts} +0 -0
- /package/{lib/FPScontrol.d.ts → FPScontrol.d.ts} +0 -0
- /package/{lib/FPScontrol.js → FPScontrol.js} +0 -0
- /package/{lib/FPScontrol.ts → FPScontrol.ts} +0 -0
- /package/{lib/InstancedGroupMesh.d.ts → InstancedGroupMesh.d.ts} +0 -0
- /package/{lib/InstancedGroupMesh.js → InstancedGroupMesh.js} +0 -0
- /package/{lib/InstancedGroupMesh.ts → InstancedGroupMesh.ts} +0 -0
- /package/{lib/KeyFrameAnimation.d.ts → KeyFrameAnimation.d.ts} +0 -0
- /package/{lib/KeyFrameAnimation.js → KeyFrameAnimation.js} +0 -0
- /package/{lib/KeyFrameAnimation.ts → KeyFrameAnimation.ts} +0 -0
- /package/{lib/planeModal1 → PlaneModal1}/planeModal.png +0 -0
- /package/{lib/PlaneText.js → PlaneText.js} +0 -0
- /package/{lib/PlaneText.ts → PlaneText.ts} +0 -0
- /package/{lib/PlaneWithHtml.d.ts → PlaneWithHtml.d.ts} +0 -0
- /package/{lib/PlaneWithHtml.js → PlaneWithHtml.js} +0 -0
- /package/{lib/PlaneWithHtml.ts → PlaneWithHtml.ts} +0 -0
- /package/{lib/PointLight → PointLight}/PointLight.d.ts +0 -0
- /package/{lib/PointLight → PointLight}/PointLight.js +0 -0
- /package/{lib/PointLight → PointLight}/PointLight.ts +0 -0
- /package/{lib/PointLight → PointLight}/pointLight_map.png +0 -0
- /package/{lib/Sky → Sky}/Sky.d.ts +0 -0
- /package/{lib/Sky → Sky}/Sky.js +0 -0
- /package/{lib/Sky → Sky}/Sky.ts +0 -0
- /package/{lib/Sky → Sky}/bluesky.jpg +0 -0
- /package/{lib/spriteModal1 → SpriteModal1}/spriteModal1.png +0 -0
- /package/{lib/SpriteText.js → SpriteText.js} +0 -0
- /package/{lib/SpriteText2.d.ts → SpriteText2.d.ts} +0 -0
- /package/{lib/SpriteText2.js → SpriteText2.js} +0 -0
- /package/{lib/SpriteText2.ts → SpriteText2.ts} +0 -0
- /package/{lib/Text3D → Text3D}/Text3D.d.ts +0 -0
- /package/{lib/Text3D → Text3D}/gentilis.json +0 -0
- /package/{lib/ThreeMouse.d.ts → ThreeMouse.d.ts} +0 -0
- /package/{lib/Transition.d.ts → Transition.d.ts} +0 -0
- /package/{lib/Transition.js → Transition.js} +0 -0
- /package/{lib/Transition.ts → Transition.ts} +0 -0
- /package/{lib/keyContorls.js → keyContorls.js} +0 -0
- /package/{lib/stroke_pass → pass}/FullScreenQuad.js +0 -0
- /package/{lib/stroke_pass → pass}/FullScreenQuad.ts +0 -0
- /package/{lib/stroke_pass → pass}/stroke_pass.d.ts +0 -0
- /package/{lib/stroke_pass → pass}/stroke_pass.js +0 -0
- /package/{lib/stroke_pass → pass}/stroke_pass.ts +0 -0
- /package/{lib/shaders.d.ts → shaders.d.ts} +0 -0
- /package/{lib/shaders.js → shaders.js} +0 -0
- /package/{lib/shaders.ts → shaders.ts} +0 -0
package/index.ts
CHANGED
|
@@ -1,62 +1,2 @@
|
|
|
1
1
|
// 基类
|
|
2
|
-
export { default } from "./
|
|
3
|
-
|
|
4
|
-
// 事件对象
|
|
5
|
-
export { default as EventMesh } from "./lib/EventMesh";
|
|
6
|
-
|
|
7
|
-
// 挤出模型
|
|
8
|
-
export { default as ExtrudeMesh } from "./lib/ExtrudeMesh";
|
|
9
|
-
export type { ExtrudePath } from "./lib/ExtrudeMesh";
|
|
10
|
-
export type { ExtrudeMeshProps } from "./lib/ExtrudeMesh";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// 关键帧动画对象
|
|
14
|
-
export { default as KeyFrameAnimation } from "./lib/KeyFrameAnimation";
|
|
15
|
-
export type { KeyframeAnimationProps } from "./lib/KeyFrameAnimation";
|
|
16
|
-
export type { Keyframe } from "./lib/KeyFrameAnimation";
|
|
17
|
-
|
|
18
|
-
//实例模型组对象
|
|
19
|
-
export { default as InstancedGroupMesh } from "./lib/InstancedGroupMesh";
|
|
20
|
-
|
|
21
|
-
//点光源
|
|
22
|
-
export { default as PointLight } from "./lib/PointLight/PointLight";
|
|
23
|
-
|
|
24
|
-
//天空球
|
|
25
|
-
export { default as Sky } from "./lib/Sky/Sky";
|
|
26
|
-
|
|
27
|
-
//键盘控制器
|
|
28
|
-
export { default as keyContorls } from "./lib/keyContorls";
|
|
29
|
-
|
|
30
|
-
// 动画过度对象
|
|
31
|
-
export { default as Transition } from "./lib/Transition";
|
|
32
|
-
|
|
33
|
-
// 公共方法
|
|
34
|
-
export { default as threeUtils } from "./lib/threeUtils";
|
|
35
|
-
|
|
36
|
-
// 加载器
|
|
37
|
-
export { default as threeLoader } from "./lib/threeLoader";
|
|
38
|
-
|
|
39
|
-
// 第一人称控制器
|
|
40
|
-
export { default as FPScontrol } from "./lib/FPScontrol";
|
|
41
|
-
|
|
42
|
-
// 平面文字
|
|
43
|
-
export { default as PlaneText } from "./lib/PlaneText";
|
|
44
|
-
|
|
45
|
-
// 精灵文字
|
|
46
|
-
export { default as SpriteText } from "./lib/SpriteText";
|
|
47
|
-
|
|
48
|
-
// 精灵文字样式2
|
|
49
|
-
export { default as SpriteText2 } from "./lib/SpriteText2";
|
|
50
|
-
|
|
51
|
-
//精灵文本框
|
|
52
|
-
export { default as SpriteModal1 } from "./lib/spriteModal1/SpriteModal1";
|
|
53
|
-
|
|
54
|
-
//平面文本框
|
|
55
|
-
export { default as PlaneModal1 } from "./lib/planeModal1/PlaneModal1";
|
|
56
|
-
|
|
57
|
-
// 3D文字
|
|
58
|
-
export { default as Text3D } from "./lib/Text3D/Text3D";
|
|
59
|
-
export type { Text3DProps } from "./lib/Text3D/Text3D";
|
|
60
|
-
|
|
61
|
-
// html面板
|
|
62
|
-
export { default as PlaneWithHtml } from "./lib/PlaneWithHtml";
|
|
2
|
+
export { default } from "./ThreeBase";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Event, EventDispatcher, Vector3 } from "three";
|
|
1
|
+
import { Event, EventDispatcher, EventListener, Vector3 } from "three";
|
|
2
2
|
/**
|
|
3
3
|
* 键盘 使用 ↑↓←→ 控制 x z 方向, 小键盘 1 0 控制 y 方向
|
|
4
4
|
*
|
|
@@ -17,7 +17,7 @@ declare class KeyContorls extends EventDispatcher {
|
|
|
17
17
|
[key: string]: Array<any>;
|
|
18
18
|
};
|
|
19
19
|
removeEvent: import("lodash").DebouncedFunc<(type: string) => void>;
|
|
20
|
-
addEventListener(type:
|
|
20
|
+
addEventListener<T extends string>(type: T, listener: EventListener<Event, T, this>): void;
|
|
21
21
|
addEvent(): void;
|
|
22
22
|
dispose(): void;
|
|
23
23
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { throttle } from "lodash";
|
|
9
|
-
import { Event, EventDispatcher, Vector3 } from "three";
|
|
9
|
+
import { Event, EventDispatcher, EventListener, Vector3 } from "three";
|
|
10
10
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
11
11
|
|
|
12
12
|
|
|
@@ -107,7 +107,7 @@ class KeyContorls extends EventDispatcher {
|
|
|
107
107
|
this._listeners = undefined;
|
|
108
108
|
}, 1000, { trailing: false });
|
|
109
109
|
|
|
110
|
-
addEventListener(type:
|
|
110
|
+
addEventListener<T extends string>(type: T, listener: EventListener<Event, T, this>): void {
|
|
111
111
|
this.removeEvent(type);
|
|
112
112
|
super.addEventListener(type, listener);
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "three-base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "three 3d three-base",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,34 +15,29 @@
|
|
|
15
15
|
"module": "index.js",
|
|
16
16
|
"types": "",
|
|
17
17
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"lib/**/*.gltf",
|
|
33
|
-
"lib/**/*.fbx",
|
|
34
|
-
"lib/**/*.glb",
|
|
35
|
-
"lib/**/*.json",
|
|
36
|
-
"lib/**/*.wasm"
|
|
18
|
+
"/**/*.ts",
|
|
19
|
+
"/**/*.js",
|
|
20
|
+
"/**/*.tsx",
|
|
21
|
+
"/**/*.css",
|
|
22
|
+
"/**/*.jpg",
|
|
23
|
+
"/**/*.png",
|
|
24
|
+
"/**/*.jpeg",
|
|
25
|
+
"/**/*.svg",
|
|
26
|
+
"/**/*.obj",
|
|
27
|
+
"/**/*.gltf",
|
|
28
|
+
"/**/*.fbx",
|
|
29
|
+
"/**/*.glb",
|
|
30
|
+
"/**/*.json",
|
|
31
|
+
"/**/*.wasm"
|
|
37
32
|
],
|
|
38
33
|
"license": "ISC",
|
|
39
34
|
"devDependencies": {},
|
|
40
35
|
"dependencies": {
|
|
41
36
|
"apng-js": "^1",
|
|
42
37
|
"lodash": "^4",
|
|
43
|
-
"three": "0.
|
|
38
|
+
"three": "^0.152.0",
|
|
44
39
|
"dexie": "^3",
|
|
45
|
-
"@types/three": "0.
|
|
40
|
+
"@types/three": "^0.152.0",
|
|
46
41
|
"@types/lodash": "^4",
|
|
47
42
|
"vite": "*",
|
|
48
43
|
"@types/node": "*",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BufferGeometry, Material, Mesh, OrthographicCamera, Scene, WebGLRenderer } from "three";
|
|
2
2
|
export default class FullScreenQuad extends Scene {
|
|
3
3
|
constructor();
|
|
4
|
-
mesh: Mesh<BufferGeometry
|
|
4
|
+
mesh: Mesh<BufferGeometry<import("three").NormalBufferAttributes>, Material>;
|
|
5
5
|
orthographicCamera: OrthographicCamera;
|
|
6
6
|
render(renderer: WebGLRenderer, material: Material): void;
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventDispatcher, Texture, TextureLoader } from "three";
|
|
1
|
+
import { CanvasTexture, EventDispatcher, Texture, TextureLoader } from "three";
|
|
2
2
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
3
3
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
4
4
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -9,7 +9,7 @@ declare class ThreeLoader extends EventDispatcher {
|
|
|
9
9
|
setAnisotropy(v: number): void;
|
|
10
10
|
textureMap: Map<string, Texture>;
|
|
11
11
|
textureLoader: TextureLoader;
|
|
12
|
-
getTexture(src: string): Texture;
|
|
12
|
+
getTexture(src: string | HTMLCanvasElement): CanvasTexture | Texture;
|
|
13
13
|
fbxLoader: FBXLoader;
|
|
14
14
|
objLoader: OBJLoader;
|
|
15
15
|
mtlLoader: MTLLoader;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2022-04-07 16:42:26
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-
|
|
5
|
+
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
6
|
*/
|
|
7
|
-
import { DefaultLoadingManager, EventDispatcher, RepeatWrapping, TextureLoader, VideoTexture } from "three";
|
|
7
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, RepeatWrapping, SRGBColorSpace, TextureLoader, VideoTexture } from "three";
|
|
8
8
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
9
9
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
10
10
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -12,11 +12,11 @@ import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
|
|
|
12
12
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
13
13
|
// 引入静态资源
|
|
14
14
|
//@ts-ignore
|
|
15
|
-
import dracoWasmWrapperJS from "./draco/draco_wasm_wrapper.js?url";
|
|
15
|
+
import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
16
16
|
//@ts-ignore
|
|
17
|
-
import dracoDecoderJS from "./draco/draco_decoder.js?url";
|
|
17
|
+
import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
|
|
18
18
|
//@ts-ignore
|
|
19
|
-
import dracoDecoderWASM from "./draco/draco_decoder.wasm?url";
|
|
19
|
+
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
20
20
|
// 加载器
|
|
21
21
|
class ThreeLoader extends EventDispatcher {
|
|
22
22
|
constructor() {
|
|
@@ -45,6 +45,13 @@ class ThreeLoader extends EventDispatcher {
|
|
|
45
45
|
textureLoader = new TextureLoader();
|
|
46
46
|
// 获取地址对应的单例纹理对象
|
|
47
47
|
getTexture(src) {
|
|
48
|
+
if (src instanceof HTMLCanvasElement) {
|
|
49
|
+
const canvasTexture = new CanvasTexture(src);
|
|
50
|
+
canvasTexture.wrapS = canvasTexture.wrapT = RepeatWrapping;
|
|
51
|
+
canvasTexture.anisotropy = this.anisotropy;
|
|
52
|
+
canvasTexture.colorSpace = SRGBColorSpace;
|
|
53
|
+
return canvasTexture;
|
|
54
|
+
}
|
|
48
55
|
let texture = this.textureMap.get(src);
|
|
49
56
|
if (!texture) {
|
|
50
57
|
if (/\.mp4$/.test(src)) {
|
|
@@ -70,6 +77,7 @@ class ThreeLoader extends EventDispatcher {
|
|
|
70
77
|
}
|
|
71
78
|
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
72
79
|
texture.anisotropy = this.anisotropy;
|
|
80
|
+
texture.colorSpace = SRGBColorSpace;
|
|
73
81
|
return texture;
|
|
74
82
|
}
|
|
75
83
|
;
|
|
@@ -99,7 +107,7 @@ class ThreeLoader extends EventDispatcher {
|
|
|
99
107
|
}
|
|
100
108
|
}();
|
|
101
109
|
//@ts-ignore
|
|
102
|
-
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/
|
|
110
|
+
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/jsm/libs/draco/' : '');
|
|
103
111
|
loader.setDRACOLoader(dracoLoader);
|
|
104
112
|
return loader;
|
|
105
113
|
})();
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2022-04-07 16:42:26
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-
|
|
5
|
+
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { DefaultLoadingManager, EventDispatcher, RepeatWrapping, Texture, TextureLoader, VideoTexture } from "three";
|
|
8
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, RepeatWrapping, SRGBColorSpace, Texture, TextureLoader, VideoTexture } from "three";
|
|
9
9
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
10
10
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
11
11
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -14,11 +14,11 @@ import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
|
|
14
14
|
|
|
15
15
|
// 引入静态资源
|
|
16
16
|
//@ts-ignore
|
|
17
|
-
import dracoWasmWrapperJS from "./draco/draco_wasm_wrapper.js?url";
|
|
17
|
+
import dracoWasmWrapperJS from "./lib/draco/draco_wasm_wrapper.js?url";
|
|
18
18
|
//@ts-ignore
|
|
19
|
-
import dracoDecoderJS from "./draco/draco_decoder.js?url";
|
|
19
|
+
import dracoDecoderJS from "./lib/draco/draco_decoder.js?url";
|
|
20
20
|
//@ts-ignore
|
|
21
|
-
import dracoDecoderWASM from "./draco/draco_decoder.wasm?url";
|
|
21
|
+
import dracoDecoderWASM from "./lib/draco/draco_decoder.wasm?url";
|
|
22
22
|
|
|
23
23
|
// 加载器
|
|
24
24
|
class ThreeLoader extends EventDispatcher {
|
|
@@ -55,7 +55,17 @@ class ThreeLoader extends EventDispatcher {
|
|
|
55
55
|
textureLoader = new TextureLoader();
|
|
56
56
|
|
|
57
57
|
// 获取地址对应的单例纹理对象
|
|
58
|
-
getTexture(src: string) {
|
|
58
|
+
getTexture(src: string | HTMLCanvasElement) {
|
|
59
|
+
|
|
60
|
+
if (src instanceof HTMLCanvasElement) {
|
|
61
|
+
|
|
62
|
+
const canvasTexture = new CanvasTexture(src);
|
|
63
|
+
canvasTexture.wrapS = canvasTexture.wrapT = RepeatWrapping;
|
|
64
|
+
canvasTexture.anisotropy = this.anisotropy;
|
|
65
|
+
canvasTexture.colorSpace = SRGBColorSpace;
|
|
66
|
+
|
|
67
|
+
return canvasTexture;
|
|
68
|
+
}
|
|
59
69
|
|
|
60
70
|
let texture = this.textureMap.get(src);
|
|
61
71
|
|
|
@@ -78,14 +88,15 @@ class ThreeLoader extends EventDispatcher {
|
|
|
78
88
|
texture = this.textureLoader.load(src, tex => {
|
|
79
89
|
tex.image.crossOrigin = "anonymous";
|
|
80
90
|
});
|
|
91
|
+
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
this.textureMap.set(src, texture);
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
texture.wrapS = texture.wrapT = RepeatWrapping;
|
|
87
|
-
|
|
88
98
|
texture.anisotropy = this.anisotropy;
|
|
99
|
+
texture.colorSpace = SRGBColorSpace;
|
|
89
100
|
|
|
90
101
|
return texture as Texture;
|
|
91
102
|
};
|
|
@@ -121,7 +132,7 @@ class ThreeLoader extends EventDispatcher {
|
|
|
121
132
|
|
|
122
133
|
}();
|
|
123
134
|
//@ts-ignore
|
|
124
|
-
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/
|
|
135
|
+
dracoLoader.setDecoderPath((process.env.NODE_ENV === "development") ? '/node_modules/three/examples/jsm/libs/draco/' : '');
|
|
125
136
|
loader.setDRACOLoader(dracoLoader);
|
|
126
137
|
return loader;
|
|
127
138
|
})()
|
|
@@ -35,7 +35,10 @@ declare class ThreeUtils extends EventDispatcher {
|
|
|
35
35
|
alignBottom(object3d: Object3D | BufferGeometry, y?: number): void;
|
|
36
36
|
centerObject3D(object3d: Object3D | BufferGeometry): void;
|
|
37
37
|
center(object3d: Object3D | BufferGeometry): void;
|
|
38
|
-
scaleTo(object3d: Object3D | BufferGeometry, size?: number): void;
|
|
38
|
+
scaleTo(object3d: Object3D | BufferGeometry, size?: number, key?: Partial<["x", "y", "z"]>): void;
|
|
39
|
+
exportGLB(input: Object3D): void;
|
|
40
|
+
getVolume(geometry: BufferGeometry): number;
|
|
41
|
+
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number;
|
|
39
42
|
}
|
|
40
43
|
declare const threeUtils: ThreeUtils;
|
|
41
44
|
export default threeUtils;
|
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
* @Last Modified time: 2023-05-03 00:36:18
|
|
6
6
|
*/
|
|
7
7
|
import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
8
|
+
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
8
9
|
class ThreeUtils extends EventDispatcher {
|
|
9
10
|
constructor() {
|
|
10
11
|
super();
|
|
11
12
|
this.requestAnimationFrame();
|
|
12
13
|
}
|
|
13
|
-
//@ts-ignore
|
|
14
14
|
isProd = (process.env.NODE_ENV === "production");
|
|
15
|
-
//@ts-ignore
|
|
16
15
|
isDev = (process.env.NODE_ENV === "development");
|
|
17
16
|
_timeTemp = performance.now();
|
|
18
17
|
_accumulate = 0; // 事件分发次数
|
|
@@ -162,10 +161,10 @@ class ThreeUtils extends EventDispatcher {
|
|
|
162
161
|
center(object3d) {
|
|
163
162
|
this.centerObject3D(object3d);
|
|
164
163
|
}
|
|
165
|
-
|
|
166
|
-
scaleTo(object3d, size = 1) {
|
|
164
|
+
// 使用指定的纬度计算, 缩放至指定大小
|
|
165
|
+
scaleTo(object3d, size = 1, key = ["x", "y", "z"]) {
|
|
167
166
|
const originSize = this.getSize(object3d);
|
|
168
|
-
const scale = size / Math.max(
|
|
167
|
+
const scale = size / Math.max(...key.map(k => originSize[k]));
|
|
169
168
|
if (object3d instanceof Object3D) {
|
|
170
169
|
object3d.scale.multiplyScalar(scale);
|
|
171
170
|
object3d.updateMatrixWorld(true);
|
|
@@ -174,6 +173,61 @@ class ThreeUtils extends EventDispatcher {
|
|
|
174
173
|
object3d.scale(scale, scale, scale);
|
|
175
174
|
}
|
|
176
175
|
}
|
|
176
|
+
// 导出 glb
|
|
177
|
+
exportGLB(input) {
|
|
178
|
+
const gltfExporter = new GLTFExporter();
|
|
179
|
+
gltfExporter.parse(input, (result) => {
|
|
180
|
+
if (result instanceof ArrayBuffer) {
|
|
181
|
+
const link = document.createElement('a');
|
|
182
|
+
link.style.display = 'none';
|
|
183
|
+
document.body.appendChild(link); // Firefox workaround, see #6594
|
|
184
|
+
link.href = URL.createObjectURL(new Blob([result], { type: 'application/octet-stream' }));
|
|
185
|
+
link.download = 'threeUtils.exportGLB.glb';
|
|
186
|
+
link.click();
|
|
187
|
+
}
|
|
188
|
+
}, (error) => { }, {
|
|
189
|
+
trs: true,
|
|
190
|
+
onlyVisible: true,
|
|
191
|
+
binary: true,
|
|
192
|
+
maxTextureSize: 4096
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// 计算网格的体积
|
|
196
|
+
getVolume(geometry) {
|
|
197
|
+
if (!geometry.index)
|
|
198
|
+
return;
|
|
199
|
+
if (!geometry.isBufferGeometry) {
|
|
200
|
+
console.log("'geometry' must be an indexed or non-indexed buffer geometry");
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
const isIndexed = geometry.index !== null;
|
|
204
|
+
const position = geometry.attributes.position;
|
|
205
|
+
let sum = 0;
|
|
206
|
+
const p1 = new Vector3(), p2 = new Vector3(), p3 = new Vector3();
|
|
207
|
+
if (!isIndexed) {
|
|
208
|
+
const faces = position.count / 3;
|
|
209
|
+
for (let i = 0; i < faces; i++) {
|
|
210
|
+
p1.fromBufferAttribute(position, i * 3 + 0);
|
|
211
|
+
p2.fromBufferAttribute(position, i * 3 + 1);
|
|
212
|
+
p3.fromBufferAttribute(position, i * 3 + 2);
|
|
213
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const index = geometry.index;
|
|
218
|
+
const faces = index.count / 3;
|
|
219
|
+
for (let i = 0; i < faces; i++) {
|
|
220
|
+
p1.fromBufferAttribute(position, index.array[i * 3 + 0]);
|
|
221
|
+
p2.fromBufferAttribute(position, index.array[i * 3 + 1]);
|
|
222
|
+
p3.fromBufferAttribute(position, index.array[i * 3 + 2]);
|
|
223
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return sum > 0 ? sum : 0;
|
|
227
|
+
}
|
|
228
|
+
signedVolumeOfTriangle(p1, p2, p3) {
|
|
229
|
+
return p1.dot(p2.cross(p3)) / 6.0;
|
|
230
|
+
}
|
|
177
231
|
}
|
|
178
232
|
const threeUtils = new ThreeUtils();
|
|
179
233
|
export default threeUtils;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @Last Modified time: 2023-05-03 00:36:18
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Box3, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
8
|
+
import { Box3, BufferAttribute, BufferGeometry, Clock, EventDispatcher, Object3D, Vector3 } from "three";
|
|
9
|
+
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter';
|
|
9
10
|
|
|
10
11
|
class ThreeUtils extends EventDispatcher {
|
|
11
12
|
|
|
@@ -14,10 +15,8 @@ class ThreeUtils extends EventDispatcher {
|
|
|
14
15
|
|
|
15
16
|
this.requestAnimationFrame();
|
|
16
17
|
}
|
|
17
|
-
//@ts-ignore
|
|
18
18
|
isProd = (process.env.NODE_ENV === "production");
|
|
19
19
|
|
|
20
|
-
//@ts-ignore
|
|
21
20
|
isDev = (process.env.NODE_ENV === "development");
|
|
22
21
|
|
|
23
22
|
_timeTemp = performance.now();
|
|
@@ -188,10 +187,11 @@ class ThreeUtils extends EventDispatcher {
|
|
|
188
187
|
this.centerObject3D(object3d);
|
|
189
188
|
}
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
scaleTo(object3d: Object3D | BufferGeometry, size: number = 1) {
|
|
190
|
+
// 使用指定的纬度计算, 缩放至指定大小
|
|
191
|
+
scaleTo(object3d: Object3D | BufferGeometry, size: number = 1, key: Partial<["x", "y", "z"]> = ["x", "y", "z"]) {
|
|
193
192
|
const originSize = this.getSize(object3d);
|
|
194
|
-
const scale = size / Math.max(originSize
|
|
193
|
+
const scale = size / Math.max(...key.map(k => originSize[k as "x" | "y" | "z"]));
|
|
194
|
+
|
|
195
195
|
if (object3d instanceof Object3D) {
|
|
196
196
|
object3d.scale.multiplyScalar(scale);
|
|
197
197
|
object3d.updateMatrixWorld(true);
|
|
@@ -200,10 +200,69 @@ class ThreeUtils extends EventDispatcher {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
//
|
|
204
|
-
|
|
203
|
+
// 导出 glb
|
|
204
|
+
exportGLB(input: Object3D) {
|
|
205
|
+
const gltfExporter = new GLTFExporter();
|
|
206
|
+
gltfExporter.parse(
|
|
207
|
+
input,
|
|
208
|
+
(result) => {
|
|
209
|
+
if (result instanceof ArrayBuffer) {
|
|
210
|
+
const link = document.createElement('a');
|
|
211
|
+
link.style.display = 'none';
|
|
212
|
+
document.body.appendChild(link); // Firefox workaround, see #6594
|
|
213
|
+
link.href = URL.createObjectURL(new Blob([result], { type: 'application/octet-stream' }));
|
|
214
|
+
link.download = 'threeUtils.exportGLB.glb';
|
|
215
|
+
link.click();
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
(error: ErrorEvent) => { },
|
|
219
|
+
{
|
|
220
|
+
trs: true,
|
|
221
|
+
onlyVisible: true, // 只导出可见的
|
|
222
|
+
binary: true, // glb
|
|
223
|
+
maxTextureSize: 4096
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 计算网格的体积
|
|
230
|
+
getVolume(geometry: BufferGeometry) {
|
|
231
|
+
if (!geometry.index) return;
|
|
232
|
+
if (!geometry.isBufferGeometry) {
|
|
233
|
+
console.log("'geometry' must be an indexed or non-indexed buffer geometry");
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
const isIndexed = geometry.index !== null;
|
|
237
|
+
const position = geometry.attributes.position as BufferAttribute;
|
|
238
|
+
let sum = 0;
|
|
239
|
+
const p1 = new Vector3(),
|
|
240
|
+
p2 = new Vector3(),
|
|
241
|
+
p3 = new Vector3();
|
|
242
|
+
if (!isIndexed) {
|
|
243
|
+
const faces = position.count / 3;
|
|
244
|
+
for (let i = 0; i < faces; i++) {
|
|
245
|
+
p1.fromBufferAttribute(position, i * 3 + 0);
|
|
246
|
+
p2.fromBufferAttribute(position, i * 3 + 1);
|
|
247
|
+
p3.fromBufferAttribute(position, i * 3 + 2);
|
|
248
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
const index = geometry.index;
|
|
252
|
+
const faces = index.count / 3;
|
|
253
|
+
for (let i = 0; i < faces; i++) {
|
|
254
|
+
p1.fromBufferAttribute(position, index.array[i * 3 + 0]);
|
|
255
|
+
p2.fromBufferAttribute(position, index.array[i * 3 + 1]);
|
|
256
|
+
p3.fromBufferAttribute(position, index.array[i * 3 + 2]);
|
|
257
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return sum > 0 ? sum : 0;
|
|
261
|
+
}
|
|
205
262
|
|
|
206
|
-
|
|
263
|
+
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3) {
|
|
264
|
+
return p1.dot(p2.cross(p3)) / 6.0;
|
|
265
|
+
}
|
|
207
266
|
|
|
208
267
|
}
|
|
209
268
|
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"types": [
|
|
10
|
+
"vite/client",
|
|
11
|
+
"node"
|
|
12
|
+
],
|
|
13
|
+
"typeRoots": [
|
|
14
|
+
"./",
|
|
15
|
+
],
|
|
16
|
+
"sourceMap": false,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationDir": "./",
|
|
19
|
+
"allowJs": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"allowSyntheticDefaultImports": true,
|
|
23
|
+
"strict": false,
|
|
24
|
+
"forceConsistentCasingInFileNames": true,
|
|
25
|
+
"module": "esnext",
|
|
26
|
+
"moduleResolution": "node",
|
|
27
|
+
"resolveJsonModule": true,
|
|
28
|
+
"isolatedModules": false,
|
|
29
|
+
"noEmit": false,
|
|
30
|
+
"noImplicitAny": false,
|
|
31
|
+
"locale": "zh-cn",
|
|
32
|
+
},
|
|
33
|
+
"include": [
|
|
34
|
+
"./",
|
|
35
|
+
],
|
|
36
|
+
"exclude": [
|
|
37
|
+
"./lib/draco"
|
|
38
|
+
]
|
|
39
|
+
}
|
package/lib/PlaneText.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Mesh, MeshBasicMaterial, PlaneGeometry, Vector3 } from "three";
|
|
2
|
-
import SpriteText from "./SpriteText";
|
|
3
|
-
type Props = {
|
|
4
|
-
text?: string;
|
|
5
|
-
textHeight?: number;
|
|
6
|
-
color?: string;
|
|
7
|
-
backgroundColor?: string;
|
|
8
|
-
fontFace?: string;
|
|
9
|
-
fontSize?: number;
|
|
10
|
-
fontWeight?: string;
|
|
11
|
-
padding?: number | [number, number];
|
|
12
|
-
borderWidth?: number;
|
|
13
|
-
borderRadius?: number;
|
|
14
|
-
borderColor?: string;
|
|
15
|
-
strokeWidth?: number;
|
|
16
|
-
strokeColor?: string;
|
|
17
|
-
};
|
|
18
|
-
export default class PlaneText extends Mesh {
|
|
19
|
-
constructor(text?: string);
|
|
20
|
-
type: string;
|
|
21
|
-
static geometry: PlaneGeometry;
|
|
22
|
-
spriteText: SpriteText;
|
|
23
|
-
material: MeshBasicMaterial;
|
|
24
|
-
set(parame: Props): void;
|
|
25
|
-
get(prop: keyof SpriteText): string | number | boolean | import("three").BufferGeometry | import("three").Matrix3 | import("three").Matrix4 | import("three").Material | import("three").Object3D<import("three").Event> | Vector3 | import("three").Object3D<import("three").Event>[] | import("three").Euler | import("three").Quaternion | import("three").Layers | import("three").AnimationClip[] | {
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
} | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry, material: import("three").Material, group: import("three").Group) => void) | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry, material: import("three").Material, group: import("three").Group) => void) | ((matrix: import("three").Matrix4) => void) | ((axis: Vector3, angle: number) => void) | ((euler: import("three").Euler) => void) | ((m: import("three").Matrix4) => void) | ((q: import("three").Quaternion) => void) | ((vector: Vector3) => Vector3) | ((vector: Vector3) => Vector3) | {
|
|
28
|
-
(vector: Vector3): void;
|
|
29
|
-
(x: number, y: number, z: number): void;
|
|
30
|
-
} | ((id: number) => import("three").Object3D<import("three").Event>) | ((name: string) => import("three").Object3D<import("three").Event>) | ((name: string, value: any) => import("three").Object3D<import("three").Event>) | ((name: string, value: any) => import("three").Object3D<import("three").Event>[]) | ((target: Vector3) => Vector3) | ((target: import("three").Quaternion) => import("three").Quaternion) | ((target: Vector3) => Vector3) | ((target: Vector3) => Vector3) | ((callback: (object: import("three").Object3D<import("three").Event>) => any) => void) | ((callback: (object: import("three").Object3D<import("three").Event>) => any) => void) | ((callback: (object: import("three").Object3D<import("three").Event>) => any) => void) | (() => void) | ((force?: boolean) => void) | ((updateParents: boolean, updateChildren: boolean) => void) | ((meta?: {
|
|
31
|
-
geometries: any;
|
|
32
|
-
materials: any;
|
|
33
|
-
textures: any;
|
|
34
|
-
images: any;
|
|
35
|
-
}) => any) | ((event: import("three").Event) => void) | import("three").Vector2 | HTMLCanvasElement | import("three").SpriteMaterial | ((raycaster: import("three").Raycaster, intersects: import("three").Intersection<import("three").Object3D<import("three").Event>>[]) => void) | ((quaternion: import("three").Quaternion) => SpriteText) | ((axis: Vector3, angle: number) => SpriteText) | ((axis: Vector3, angle: number) => SpriteText) | ((angle: number) => SpriteText) | ((angle: number) => SpriteText) | ((angle: number) => SpriteText) | ((axis: Vector3, distance: number) => SpriteText) | ((distance: number) => SpriteText) | ((distance: number) => SpriteText) | ((distance: number) => SpriteText) | ((...object: import("three").Object3D<import("three").Event>[]) => SpriteText) | ((...object: import("three").Object3D<import("three").Event>[]) => SpriteText) | (() => SpriteText) | (() => SpriteText) | ((object: import("three").Object3D<import("three").Event>) => SpriteText) | ((recursive?: boolean) => SpriteText) | ((source: SpriteText) => SpriteText) | (<T extends string>(type: T, listener: import("three").EventListener<import("three").Event, T, SpriteText>) => void) | (<T_1 extends string>(type: T_1, listener: import("three").EventListener<import("three").Event, T_1, SpriteText>) => boolean) | (<T_2 extends string>(type: T_2, listener: import("three").EventListener<import("three").Event, T_2, SpriteText>) => void) | (() => void);
|
|
36
|
-
}
|
|
37
|
-
export {};
|
package/lib/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export { default } from "./lib/ThreeBase";
|
|
2
|
-
export { default as EventMesh } from "./lib/EventMesh";
|
|
3
|
-
export { default as ExtrudeMesh } from "./lib/ExtrudeMesh";
|
|
4
|
-
export type { ExtrudePath } from "./lib/ExtrudeMesh";
|
|
5
|
-
export type { ExtrudeMeshProps } from "./lib/ExtrudeMesh";
|
|
6
|
-
export { default as KeyFrameAnimation } from "./lib/KeyFrameAnimation";
|
|
7
|
-
export type { KeyframeAnimationProps } from "./lib/KeyFrameAnimation";
|
|
8
|
-
export type { Keyframe } from "./lib/KeyFrameAnimation";
|
|
9
|
-
export { default as InstancedGroupMesh } from "./lib/InstancedGroupMesh";
|
|
10
|
-
export { default as PointLight } from "./lib/PointLight";
|
|
11
|
-
export { default as Sky } from "./lib/Sky/Sky";
|
|
12
|
-
export { default as keyContorls } from "./lib/keyContorls";
|
|
13
|
-
export { default as Transition } from "./lib/Transition";
|
|
14
|
-
export { default as threeUtils } from "./lib/threeUtils";
|
|
15
|
-
export { default as threeLoader } from "./lib/threeLoader";
|
|
16
|
-
export { default as FPScontrol } from "./lib/FPScontrol";
|
|
17
|
-
export { default as PlaneText } from "./lib/PlaneText";
|
|
18
|
-
export { default as SpriteText } from "three-spritetext";
|
|
19
|
-
export { default as SpriteModal1 } from "./lib/spriteModal1/SpriteModal1";
|
|
20
|
-
export { default as PlaneModal1 } from "./lib/planeModal1/PlaneModal1";
|
|
21
|
-
export { default as Text3D } from "./lib/Text3D/Text3D";
|
|
22
|
-
export type { Text3DProps } from "./lib/Text3D/Text3D";
|
package/lib/type.d.ts
DELETED
|
File without changes
|
package/lib/type.js
DELETED
package/lib/type.ts
DELETED
|
File without changes
|