three-base 2.0.137 → 2.0.145
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/DirectionalLight.d.ts +2 -2
- package/DirectionalLight.js +1 -1
- package/DirectionalLight.ts +70 -0
- package/EventMap.d.ts +103 -0
- package/EventMap.js +17 -0
- package/EventMap.ts +139 -0
- package/EventMesh.ts +60 -0
- package/ExtrudeMesh.js +1 -25
- package/ExtrudeMesh.ts +553 -0
- package/FPScontrol.d.ts +448 -15
- package/FPScontrol.js +1448 -266
- package/FPScontrol.ts +1855 -0
- package/Fire/Fire.d.ts +4 -4
- package/Fire/Fire.js +8 -7
- package/Fire/Fire.ts +89 -0
- package/Fire/{FireGromtry.d.ts → FireGeometry.d.ts} +2 -2
- package/Fire/{FireGromtry.js → FireGeometry.js} +1 -1
- package/Fire/FireGeometry.ts +40 -0
- package/Fire/FireMaterial.d.ts +3 -3
- package/Fire/FireMaterial.js +1 -1
- package/Fire/FireMaterial.ts +89 -0
- package/Fire/index.d.ts +1 -0
- package/Fire/index.js +1 -0
- package/Fire/index.ts +2 -0
- package/GLTFDracoLoader.d.ts +71 -0
- package/GLTFDracoLoader.js +266 -0
- package/GLTFDracoLoader.ts +430 -0
- package/Grass/Grass.d.ts +2 -2
- package/Grass/Grass.ts +38 -0
- package/Grass/index.d.ts +1 -0
- package/Grass/index.js +1 -0
- package/Grass/index.ts +2 -0
- package/Ground1/Ground1.d.ts +2 -3
- package/Ground1/Ground1.js +64 -60
- package/Ground1/Ground1.ts +114 -0
- package/Ground1/index.ts +1 -0
- package/MeshBase.d.ts +1 -0
- package/MeshBase.js +37 -13
- package/MeshBase.ts +253 -0
- package/Mirror.d.ts +3 -3
- package/Mirror.js +7 -3
- package/Mirror.ts +203 -0
- package/MktMesh/MktMesh.d.ts +301 -0
- package/MktMesh/MktMesh.js +1064 -0
- package/MktMesh/MktMesh.ts +1096 -0
- package/MktMesh/assetUrl.d.ts +59 -0
- package/MktMesh/assetUrl.js +154 -0
- package/MktMesh/assetUrl.ts +155 -0
- package/MktMesh/mktMappingShader.d.ts +12 -0
- package/MktMesh/mktMappingShader.js +139 -0
- package/MktMesh/mktMappingShader.ts +139 -0
- package/MktMesh/mktShader.d.ts +263 -0
- package/MktMesh/mktShader.js +1248 -0
- package/MktMesh/mktShader.ts +1344 -0
- package/MktMesh/panoBitmapTexture.d.ts +25 -0
- package/MktMesh/panoBitmapTexture.js +52 -0
- package/MktMesh/panoBitmapTexture.ts +54 -0
- package/MktMesh/panoSlotBind.d.ts +29 -0
- package/MktMesh/panoSlotBind.js +106 -0
- package/MktMesh/panoSlotBind.ts +153 -0
- package/MktMesh/panoSlotRoster.d.ts +22 -0
- package/MktMesh/panoSlotRoster.js +169 -0
- package/MktMesh/panoSlotRoster.ts +168 -0
- package/MktMesh/panoTileStitcher.d.ts +119 -0
- package/MktMesh/panoTileStitcher.js +533 -0
- package/MktMesh/panoTileStitcher.ts +616 -0
- package/MktMesh/types.d.ts +75 -0
- package/MktMesh/types.js +1 -0
- package/MktMesh/types.ts +87 -0
- package/MktMesh/wallCapTessellate.d.ts +33 -0
- package/MktMesh/wallCapTessellate.js +97 -0
- package/MktMesh/wallCapTessellate.ts +68 -0
- package/PipeMesh/PathGeometry.js +9 -2
- package/PipeMesh/PathGeometry.ts +343 -0
- package/PipeMesh/PathPoint.ts +36 -0
- package/PipeMesh/PathPointList.js +1 -0
- package/PipeMesh/PathPointList.ts +227 -0
- package/PipeMesh/PathTubeGeometry.ts +146 -0
- package/PipeMesh/PipeMesh.d.ts +1 -1
- package/PipeMesh/PipeMesh.js +1 -1
- package/PipeMesh/PipeMesh.ts +76 -0
- package/PipeMesh/index.ts +1 -0
- package/PlaneModal1/PlaneModal1.d.ts +16 -13
- package/PlaneModal1/PlaneModal1.js +4 -0
- package/PlaneModal1/PlaneModal1.ts +138 -0
- package/PlaneModal1/index.ts +1 -0
- package/PlaneText.d.ts +2 -14
- package/PlaneText.js +7 -2
- package/PlaneText.ts +55 -0
- package/PlaneWithHtml.d.ts +4 -2
- package/PlaneWithHtml.js +2 -1
- package/PlaneWithHtml.ts +70 -0
- package/PointLight/PointLight.d.ts +3 -4
- package/PointLight/PointLight.js +1 -7
- package/PointLight/PointLight.ts +67 -0
- package/PointLight/index.ts +1 -0
- package/README.md +110 -79
- package/Sky/Sky.ts +22 -0
- package/Sky/index.ts +1 -0
- package/SpotLight.d.ts +2 -2
- package/SpotLight.js +1 -1
- package/SpotLight.ts +74 -0
- package/SpriteModal1/SpriteModal1.d.ts +16 -13
- package/SpriteModal1/SpriteModal1.js +8 -2
- package/SpriteModal1/SpriteModal1.ts +146 -0
- package/SpriteModal1/index.ts +1 -0
- package/SpriteText.d.ts +14 -13
- package/SpriteText.js +22 -9
- package/SpriteText.ts +205 -0
- package/SpriteText2.d.ts +9 -8
- package/SpriteText2.js +57 -32
- package/SpriteText2.ts +258 -0
- package/SpriteText3.d.ts +86 -0
- package/SpriteText3.js +519 -0
- package/SpriteText3.ts +599 -0
- package/SpriteWithHtml.d.ts +4 -2
- package/SpriteWithHtml.ts +50 -0
- package/Text3D/Text3D.js +17 -21
- package/Text3D/Text3D.ts +77 -0
- package/Text3D/fontController.d.ts +10 -9
- package/Text3D/fontController.js +17 -50
- package/Text3D/fontController.ts +209 -0
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +168 -31
- package/ThreeBase.js +663 -117
- package/ThreeBase.ts +1314 -0
- package/ThreeMouse.d.ts +20 -7
- package/ThreeMouse.js +78 -32
- package/ThreeMouse.ts +472 -0
- package/Transition.d.ts +12 -7
- package/Transition.js +26 -27
- package/Transition.ts +242 -0
- package/Water/Water.js +21 -3
- package/Water/Water.ts +45 -0
- package/Water/index.d.ts +2 -0
- package/Water/index.js +2 -0
- package/Water/index.ts +2 -0
- package/WaterFlow/FloatingDuck.d.ts +88 -0
- package/WaterFlow/FloatingDuck.js +307 -0
- package/WaterFlow/FloatingDuck.ts +445 -0
- package/WaterFlow/GPUFluidSimulation.d.ts +56 -0
- package/WaterFlow/GPUFluidSimulation.js +785 -0
- package/WaterFlow/GPUFluidSimulation.ts +827 -0
- package/WaterFlow/ReservoirSystem.d.ts +106 -0
- package/WaterFlow/ReservoirSystem.js +621 -0
- package/WaterFlow/ReservoirSystem.ts +754 -0
- package/WaterFlow/SPHField.d.ts +35 -0
- package/WaterFlow/SPHField.js +204 -0
- package/WaterFlow/SPHField.ts +228 -0
- package/WaterFlow/ScreenSpaceFluidPass.d.ts +69 -0
- package/WaterFlow/ScreenSpaceFluidPass.js +736 -0
- package/WaterFlow/ScreenSpaceFluidPass.ts +789 -0
- package/WaterFlow/ShallowWaterSurface.d.ts +45 -0
- package/WaterFlow/ShallowWaterSurface.js +441 -0
- package/WaterFlow/ShallowWaterSurface.ts +510 -0
- package/WaterFlow/WaterFlow.d.ts +87 -0
- package/WaterFlow/WaterFlow.js +171 -0
- package/WaterFlow/WaterFlow.ts +219 -0
- package/WaterFlow/types.d.ts +161 -0
- package/WaterFlow/types.js +1 -0
- package/WaterFlow/types.ts +189 -0
- package/WaterFlow/waterFlowPass.d.ts +3 -0
- package/WaterFlow/waterFlowPass.js +20 -0
- package/WaterFlow/waterFlowPass.ts +40 -0
- package/collisionOBB.d.ts +42 -0
- package/collisionOBB.js +112 -0
- package/collisionOBB.ts +108 -0
- package/declare.d.ts +25 -167
- package/index.js +0 -1
- package/index.ts +1 -0
- package/instanced/InstancedBatch.d.ts +57 -0
- package/instanced/InstancedBatch.js +348 -0
- package/instanced/InstancedBatch.ts +406 -0
- package/instanced/InstancedChild.d.ts +174 -0
- package/instanced/InstancedChild.js +264 -0
- package/instanced/InstancedChild.ts +327 -0
- package/instanced/InstancedGroup.d.ts +43 -0
- package/instanced/InstancedGroup.js +126 -0
- package/instanced/InstancedGroup.ts +137 -0
- package/{InstancedMeshBase.d.ts → instanced/InstancedMeshBase.d.ts} +6 -7
- package/{InstancedMeshBase.js → instanced/InstancedMeshBase.js} +36 -47
- package/instanced/InstancedMeshBase.ts +292 -0
- package/instanced/InstancedTemplate.d.ts +46 -0
- package/instanced/InstancedTemplate.js +125 -0
- package/instanced/InstancedTemplate.ts +188 -0
- package/keyControls.d.ts +29 -0
- package/{keyContorls.js → keyControls.js} +10 -7
- package/keyControls.ts +107 -0
- package/lensflare/LensFlare.d.ts +39 -0
- package/lensflare/LensFlare.js +373 -0
- package/lensflare/LensFlare.ts +448 -0
- package/lensflare/lensflare0.png +0 -0
- package/lensflare/lensflare3.png +0 -0
- package/lensflare/lensflare_custom.png +0 -0
- package/lensflare/lensflare_hex_ghost.png +0 -0
- package/lensflare/lensflare_hex_main.png +0 -0
- package/package.json +104 -25
- package/pass/bloom_pass.d.ts +1 -1
- package/pass/bloom_pass.js +127 -40
- package/pass/bloom_pass.ts +243 -0
- package/pass/cover_pass.d.ts +1 -1
- package/pass/cover_pass.js +55 -32
- package/pass/cover_pass.ts +182 -0
- package/pass/debugDepthState.d.ts +20 -0
- package/pass/debugDepthState.js +9 -0
- package/pass/debugDepthState.ts +22 -0
- package/pass/depthTestBias.d.ts +12 -0
- package/pass/depthTestBias.js +12 -0
- package/pass/depthTestBias.ts +12 -0
- package/pass/effectUserData.d.ts +27 -0
- package/pass/effectUserData.js +1 -0
- package/pass/effectUserData.ts +46 -0
- package/pass/frosted_glass_pass.d.ts +1 -1
- package/pass/frosted_glass_pass.js +45 -64
- package/pass/frosted_glass_pass.ts +288 -0
- package/pass/fsQuad.d.ts +2 -2
- package/pass/fsQuad.ts +34 -0
- package/pass/glow_pass.d.ts +1 -1
- package/pass/glow_pass.js +288 -72
- package/pass/glow_pass.ts +654 -0
- package/pass/screen_bloom_pass.d.ts +11 -0
- package/pass/screen_bloom_pass.js +235 -0
- package/pass/screen_bloom_pass.ts +263 -0
- package/pass/ssao_pass.d.ts +78 -3
- package/pass/ssao_pass.js +642 -206
- package/pass/ssao_pass.ts +918 -0
- package/pass/stroke_pass.d.ts +1 -1
- package/pass/stroke_pass.js +187 -116
- package/pass/stroke_pass.ts +638 -0
- package/shaders/FXAAShaderMaterial.js +5 -48
- package/shaders/FXAAShaderMaterial.ts +201 -0
- package/shaders/baseDepthVisShader.d.ts +11 -0
- package/shaders/baseDepthVisShader.js +36 -0
- package/shaders/baseDepthVisShader.ts +36 -0
- package/shaders/baseTextureToRenderShader.js +46 -51
- package/shaders/baseTextureToRenderShader.ts +232 -0
- package/shaders/copyShader.js +2 -3
- package/shaders/copyShader.ts +32 -0
- package/shaders/debugDepthCompareShader.d.ts +14 -0
- package/shaders/debugDepthCompareShader.js +49 -0
- package/shaders/debugDepthCompareShader.ts +50 -0
- package/shaders/debugDepthJudgeShader.d.ts +18 -0
- package/shaders/debugDepthJudgeShader.js +52 -0
- package/shaders/debugDepthJudgeShader.ts +54 -0
- package/shaders/debugExcludedShader.d.ts +13 -0
- package/shaders/debugExcludedShader.js +46 -0
- package/shaders/debugExcludedShader.ts +48 -0
- package/spriteTextBg.d.ts +1 -0
- package/spriteTextBg.js +20 -0
- package/spriteTextBg.ts +20 -0
- package/threeLoader.d.ts +8 -7
- package/threeLoader.js +58 -67
- package/threeLoader.ts +525 -0
- package/threeUtils.d.ts +2 -1
- package/threeUtils.js +24 -25
- package/threeUtils.ts +373 -0
- package/types.d.ts +2 -0
- package/types.js +6 -0
- package/types.ts +8 -0
- package/ApngTexture.d.ts +0 -13
- package/ApngTexture.js +0 -61
- package/ApngTextureManage.d.ts +0 -18
- package/ApngTextureManage.js +0 -87
- package/KeyFrameAnimation.d.ts +0 -25
- package/KeyFrameAnimation.js +0 -78
- package/keyContorls.d.ts +0 -25
- package/lib/draco/draco_decoder.js +0 -34
- package/lib/draco/draco_decoder.wasm +0 -0
- package/lib/draco/draco_wasm_wrapper.js +0 -117
- package/pass/emissive_ao_pass.d.ts +0 -13
- package/pass/emissive_ao_pass.js +0 -370
- package/shaders.d.ts +0 -5
- package/shaders.js +0 -93
package/PointLight/PointLight.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-05-03 02:55:28
|
|
6
6
|
*/
|
|
7
|
-
import { Sprite, PointLight as THREEPointLight
|
|
7
|
+
import { Sprite, PointLight as THREEPointLight } from "three";
|
|
8
8
|
import threeLoader from "../threeLoader";
|
|
9
9
|
import threeUtils from "../threeUtils";
|
|
10
10
|
import pointLight_mapPNG from "./pointLight_map.png";
|
|
@@ -43,12 +43,6 @@ export default class PointLight extends THREEPointLight {
|
|
|
43
43
|
this.add(pointLinghtHelper);
|
|
44
44
|
return pointLinghtHelper;
|
|
45
45
|
})();
|
|
46
|
-
// 线框球体(位置标识)
|
|
47
|
-
wireframeSphere = threeUtils.isDev && (() => {
|
|
48
|
-
const sphere = new Mesh(new SphereGeometry(0.25, 12, 12), new MeshBasicMaterial({ color: this.color, wireframe: true, depthTest: false }));
|
|
49
|
-
this.add(sphere);
|
|
50
|
-
return sphere;
|
|
51
|
-
})();
|
|
52
46
|
label = threeUtils.isDev && (() => {
|
|
53
47
|
const label = new SpriteText("点光源\n\n\n");
|
|
54
48
|
label.renderOrder = Infinity;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-05-18 16:02:55
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-05-03 02:55:28
|
|
6
|
+
*/
|
|
7
|
+
import { Sprite, PointLight as THREEPointLight, Object3DEventMap } from "three";
|
|
8
|
+
import threeLoader from "../threeLoader";
|
|
9
|
+
import threeUtils from "../threeUtils";
|
|
10
|
+
import pointLight_mapPNG from "./pointLight_map.png";
|
|
11
|
+
import SpriteText from "../SpriteText";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 点光源
|
|
15
|
+
* @export
|
|
16
|
+
* @class PointLight
|
|
17
|
+
* @extends {THREEPointLight}
|
|
18
|
+
*/
|
|
19
|
+
export default class PointLight extends THREEPointLight {
|
|
20
|
+
constructor(color: string = "#fff", intensity?: number, distance?: number, decay?: number) {
|
|
21
|
+
super(color, intensity, distance, decay);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 灯光辅助器
|
|
25
|
+
pointLinghtHelper: Sprite<Object3DEventMap> | false = threeUtils.isDev && (() => {
|
|
26
|
+
const pointLinghtHelper = new Sprite();
|
|
27
|
+
pointLinghtHelper.scale.set(0.05, 0.05, 0.05);
|
|
28
|
+
pointLinghtHelper.material.alphaTest = 0.1;
|
|
29
|
+
pointLinghtHelper.material.color = this.color;
|
|
30
|
+
pointLinghtHelper.material.map = threeLoader.getTexture(pointLight_mapPNG);
|
|
31
|
+
pointLinghtHelper.material.sizeAttenuation = false;
|
|
32
|
+
pointLinghtHelper.userData = {
|
|
33
|
+
cursor: "pointer"
|
|
34
|
+
};
|
|
35
|
+
pointLinghtHelper.addEventListener("mouseenter", () => {
|
|
36
|
+
if (this.label) {
|
|
37
|
+
this.label.visible = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
pointLinghtHelper.addEventListener("mouseleave", () => {
|
|
41
|
+
if (this.label) {
|
|
42
|
+
this.label.visible = false;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.add(pointLinghtHelper);
|
|
46
|
+
return pointLinghtHelper;
|
|
47
|
+
})();
|
|
48
|
+
|
|
49
|
+
label: SpriteText | false = threeUtils.isDev && (() => {
|
|
50
|
+
const label = new SpriteText("点光源\n\n\n");
|
|
51
|
+
label.renderOrder = Infinity;
|
|
52
|
+
// label.backgroundColor = "rgba(0, 0, 0, 0.5)";
|
|
53
|
+
label.padding = 4;
|
|
54
|
+
label.strokeColor = "#333";
|
|
55
|
+
label.strokeWidth = 2;
|
|
56
|
+
// label.borderRadius = 4;
|
|
57
|
+
// label.borderWidth = 1;
|
|
58
|
+
label.position.set(0, 0, 0);
|
|
59
|
+
label.visible = false;
|
|
60
|
+
label.material.color = this.color;
|
|
61
|
+
// label.material.depthTest = false;
|
|
62
|
+
label.material.sizeAttenuation = false;
|
|
63
|
+
label.scale.multiplyScalar(0.002);
|
|
64
|
+
this.add(label);
|
|
65
|
+
return label;
|
|
66
|
+
})();
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./PointLight";
|
package/README.md
CHANGED
|
@@ -1,108 +1,139 @@
|
|
|
1
|
-
|
|
1
|
+
# three-base
|
|
2
|
+
|
|
3
|
+
一个基于 Three.js 的扩展库,提供常用的 3D 组件、动画、材质和后处理特效。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🎨 **常用 3D 组件**:MeshBase、InstancedChild(实例化网格自动合并)、Text3D、SpriteText、PlaneText 等
|
|
8
|
+
- 📦 **模型加载器**:支持 GLTF、FBX、OBJ、STL、PLY、USDZ 等格式
|
|
9
|
+
- 🎮 **交互控制**:键盘控制、FPS 控制、轨道控制
|
|
10
|
+
- ✨ **粒子特效**:火焰、水面、草地等
|
|
11
|
+
- 🌟 **后处理特效**:Bloom、发光、描边、磨砂玻璃、SSAO 等
|
|
12
|
+
- 📐 **工具类**:Transition 动画、ThreeUtils 工具函数等
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install three-base
|
|
18
|
+
```
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
|
|
20
|
+
## 使用示例
|
|
21
|
+
|
|
22
|
+
### 基础使用
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
5
25
|
import ThreeBase from "three-base";
|
|
6
|
-
import
|
|
7
|
-
|
|
26
|
+
import { Vector3 } from "three";
|
|
27
|
+
|
|
28
|
+
// 创建渲染器
|
|
29
|
+
const app = new ThreeBase();
|
|
8
30
|
|
|
9
|
-
//
|
|
10
|
-
|
|
31
|
+
// 设置容器
|
|
32
|
+
app.setContainer(document.getElementById("canvas"));
|
|
11
33
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
// 设置相机位置
|
|
35
|
+
app.resetLookAt({
|
|
36
|
+
center: new Vector3(0, 0, 0),
|
|
37
|
+
position: new Vector3(10, 10, 10)
|
|
38
|
+
});
|
|
39
|
+
```
|
|
15
40
|
|
|
16
|
-
|
|
17
|
-
ambientLight = (() => {
|
|
18
|
-
const ambientLight = new AmbientLight("#fff", 0.4);
|
|
19
|
-
this.scene.add(ambientLight);
|
|
20
|
-
return ambientLight;
|
|
21
|
-
})();
|
|
41
|
+
### 创建动画对象
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const pointLight = new PointLight("#fff", 0.4);
|
|
26
|
-
pointLight.position.set(50, 40, 50);
|
|
27
|
-
this.scene.add(pointLight);
|
|
28
|
-
return pointLight;
|
|
29
|
-
})();
|
|
43
|
+
```tsx
|
|
44
|
+
import Transition from "three-base/Transition";
|
|
30
45
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
46
|
+
// 创建动画对象
|
|
47
|
+
const transition = new Transition(
|
|
48
|
+
{ x: 0, y: 0 }, // 初始值
|
|
49
|
+
[0.8, 0, 0.2, 1], // 贝塞尔曲线
|
|
50
|
+
1000 // 过渡时间
|
|
51
|
+
);
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
// 监听变化
|
|
54
|
+
transition.onChange(({ x, y }) => {
|
|
55
|
+
mesh.position.set(x, y, 0);
|
|
56
|
+
});
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
fire.fireColor = "#ff2200";// 火焰的颜色
|
|
45
|
-
fire.fireScale = 1;// 火焰的整体缩放值
|
|
46
|
-
fire.fireRadius = 0.5;// 火焰的燃烧半径
|
|
47
|
-
fire.fireHeight = 3;// 火焰的高度
|
|
48
|
-
fire.position.set(0, 5, 0);
|
|
49
|
-
this.scene.add(fire);
|
|
50
|
-
return fire;
|
|
51
|
-
})();
|
|
58
|
+
// 修改值(自动过渡动画)
|
|
59
|
+
transition.set({ x: 10, y: 5 });
|
|
60
|
+
```
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
const geometry = new BoxGeometry(10, 10, 10);
|
|
55
|
-
const matearil = new MeshLambertMaterial({ color: 0xfff });
|
|
56
|
-
const mesh = new Mesh(geometry, matearil);
|
|
62
|
+
### 加载模型
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
```tsx
|
|
65
|
+
import MeshBase from "three-base";
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
mesh.rotation.y = rotationY;
|
|
64
|
-
});
|
|
67
|
+
// 创建模型对象
|
|
68
|
+
const model = new MeshBase("model.glb");
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
// 监听加载完成
|
|
71
|
+
model.addEventListener("loaded", () => {
|
|
72
|
+
console.log("模型加载完成!");
|
|
73
|
+
});
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
// 添加到场景
|
|
76
|
+
app.scene.add(model);
|
|
77
|
+
```
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
transition.set({ rotationY: Math.random() * 5 });
|
|
75
|
-
});
|
|
76
|
-
mesh.addEventListener("rightclick", e => { });
|
|
77
|
-
mesh.addEventListener("mouseenter", e => { });
|
|
78
|
-
mesh.addEventListener("mouseleave", e => { });
|
|
79
|
-
mesh.addEventListener("mousemove", e => { });
|
|
80
|
-
mesh.addEventListener("mousedown", e => { });
|
|
81
|
-
mesh.addEventListener("mouseup", e => { });
|
|
79
|
+
### 火焰特效
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})();
|
|
81
|
+
```tsx
|
|
82
|
+
import Fire from "three-base/Fire";
|
|
86
83
|
|
|
87
|
-
|
|
84
|
+
const fire = new Fire();
|
|
85
|
+
fire.fireColor = "#ff2200";
|
|
86
|
+
fire.fireScale = 1;
|
|
87
|
+
fire.position.set(0, 5, 0);
|
|
88
|
+
app.scene.add(fire);
|
|
89
|
+
```
|
|
88
90
|
|
|
91
|
+
## API 文档
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
### 核心类
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
- **ThreeBase**:基础渲染器类,封装了 WebGLRenderer、相机、场景等
|
|
96
|
+
- **MeshBase**:模型基类,提供模型加载、动画播放等功能
|
|
97
|
+
- **InstancedChild**:实例化网格自动合并基类(推荐),继承后框架每帧自动把同类实例合并进 InstancedMesh 批量渲染,支持内置几何 / GLB 多 submesh / GLB 骨骼动画共享姿态
|
|
98
|
+
- **InstancedMeshBase**:底层手动实例缓冲工具,供生产代码使用
|
|
99
|
+
- **Transition**:过渡动画类,提供平滑的数值过渡动画
|
|
94
100
|
|
|
101
|
+
### 组件类
|
|
95
102
|
|
|
103
|
+
- **Text3D**:3D 文字组件
|
|
104
|
+
- **SpriteText / SpriteText2**:精灵文字组件
|
|
105
|
+
- **PlaneText**:平面文字组件
|
|
106
|
+
- **SpriteWithHtml / PlaneWithHtml**:支持 HTML 内容的组件
|
|
107
|
+
- **SpriteModal1 / PlaneModal1**:弹窗组件
|
|
96
108
|
|
|
97
|
-
|
|
98
|
-
import homeRenderer form "./homeRenderer.ts";
|
|
99
|
-
homeRenderer.setContainer( document.getElementById("div") );
|
|
109
|
+
### 特效类
|
|
100
110
|
|
|
111
|
+
- **Fire**:火焰粒子特效
|
|
112
|
+
- **Water**:水面特效
|
|
113
|
+
- **Grass**:草地特效
|
|
114
|
+
- **Mirror**:镜面反射
|
|
101
115
|
|
|
116
|
+
### 后处理 Pass
|
|
102
117
|
|
|
118
|
+
- **bloom_pass**:泛光特效
|
|
119
|
+
- **glow_pass**:发光特效
|
|
120
|
+
- **stroke_pass**:描边特效
|
|
121
|
+
- **cover_pass**:颜色覆盖
|
|
122
|
+
- **frosted_glass_pass**:磨砂玻璃特效
|
|
123
|
+
- **ssao_pass**:屏幕空间环境光遮蔽
|
|
103
124
|
|
|
104
|
-
|
|
125
|
+
## 浏览器支持
|
|
126
|
+
|
|
127
|
+
- Chrome (推荐)
|
|
128
|
+
- Firefox
|
|
129
|
+
- Safari
|
|
130
|
+
- Edge
|
|
131
|
+
|
|
132
|
+
## 许可证
|
|
133
|
+
|
|
134
|
+
[MIT](./LICENSE)
|
|
105
135
|
|
|
106
|
-
|
|
136
|
+
## 相关链接
|
|
107
137
|
|
|
108
|
-
|
|
138
|
+
- 示例代码:https://gitee.com/drm/vite_react_mobx_threebase
|
|
139
|
+
- Three.js 文档:https://threejs.org/docs/
|
package/Sky/Sky.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
import { DoubleSide, Mesh, MeshBasicMaterial, SphereGeometry } from "three";
|
|
8
|
+
import threeLoader from "../threeLoader";
|
|
9
|
+
import skyMapPNG from "./skyMap.png";
|
|
10
|
+
/**
|
|
11
|
+
* 天空球
|
|
12
|
+
*/
|
|
13
|
+
export default class Sky extends Mesh {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(Sky.geometry);
|
|
16
|
+
}
|
|
17
|
+
static geometry: SphereGeometry = new SphereGeometry(5000, 100, 100);
|
|
18
|
+
material: MeshBasicMaterial = new MeshBasicMaterial({
|
|
19
|
+
side: DoubleSide,
|
|
20
|
+
map: threeLoader.getTexture(skyMapPNG),
|
|
21
|
+
});
|
|
22
|
+
}
|
package/Sky/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Sky";
|
package/SpotLight.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SpotLight as THREESpotLight } from "three";
|
|
1
|
+
import { SpotLight as THREESpotLight, Group, Object3DEventMap } from "three";
|
|
2
2
|
/** 聚光灯(dev 模式显示光锥线框 + 灯体圆柱) */
|
|
3
3
|
export default class SpotLight extends THREESpotLight {
|
|
4
4
|
constructor(color?: string, intensity?: number, distance?: number, angle?: number, penumbra?: number);
|
|
5
|
-
|
|
5
|
+
_devGroup: Group<Object3DEventMap> | false;
|
|
6
6
|
}
|
package/SpotLight.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2024-06-08 14:00:00
|
|
6
6
|
*/
|
|
7
|
-
import { SpotLight as THREESpotLight, Group, BufferGeometry, BufferAttribute, LineBasicMaterial, LineSegments, CylinderGeometry, MeshBasicMaterial, Mesh
|
|
7
|
+
import { SpotLight as THREESpotLight, Group, BufferGeometry, BufferAttribute, LineBasicMaterial, LineSegments, CylinderGeometry, MeshBasicMaterial, Mesh } from "three";
|
|
8
8
|
import threeUtils from "./threeUtils";
|
|
9
9
|
import SpriteText from "./SpriteText";
|
|
10
10
|
/** 聚光灯(dev 模式显示光锥线框 + 灯体圆柱) */
|
package/SpotLight.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-06-08 14:00:00
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-06-08 14:00:00
|
|
6
|
+
*/
|
|
7
|
+
import { SpotLight as THREESpotLight, Group, BufferGeometry, BufferAttribute, LineBasicMaterial, LineSegments, CylinderGeometry, MeshBasicMaterial, Mesh, Object3DEventMap } from "three";
|
|
8
|
+
import threeUtils from "./threeUtils";
|
|
9
|
+
import SpriteText from "./SpriteText";
|
|
10
|
+
|
|
11
|
+
/** 聚光灯(dev 模式显示光锥线框 + 灯体圆柱) */
|
|
12
|
+
export default class SpotLight extends THREESpotLight {
|
|
13
|
+
constructor(color: string = "#fff", intensity: number = 1, distance: number = 10, angle: number = Math.PI / 6, penumbra: number = 0) {
|
|
14
|
+
super(color, intensity, distance, angle, penumbra);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* ============ dev 模式可视化 ============ */
|
|
18
|
+
_devGroup: Group<Object3DEventMap> | false = threeUtils.isDev && (() => {
|
|
19
|
+
const group = new Group();
|
|
20
|
+
// ——— 灯体圆柱 ———
|
|
21
|
+
const body = new Mesh(new CylinderGeometry(0.15, 0.2, 0.6, 12), new MeshBasicMaterial({ color: this.color, depthTest: false, wireframe: true }));
|
|
22
|
+
group.add(body);
|
|
23
|
+
// ——— 光锥线框 ———
|
|
24
|
+
const coneAngle = this.angle;
|
|
25
|
+
const coneDist = Math.min(this.distance || 10, 10);
|
|
26
|
+
const topR = 0.01;
|
|
27
|
+
const bottomR = Math.tan(coneAngle) * coneDist;
|
|
28
|
+
const coneVerts: number[] = [];
|
|
29
|
+
const rings = 8;
|
|
30
|
+
const segs = 24;
|
|
31
|
+
for (let r = 0; r <= rings; r++) {
|
|
32
|
+
const t = r / rings;
|
|
33
|
+
const z = -0.3 - t * coneDist;
|
|
34
|
+
const radius = topR + (bottomR - topR) * t;
|
|
35
|
+
for (let i = 0; i < segs; i++) {
|
|
36
|
+
const a0 = (i / segs) * Math.PI * 2;
|
|
37
|
+
const a1 = ((i + 1) / segs) * Math.PI * 2;
|
|
38
|
+
const x0 = Math.cos(a0) * radius, y0 = Math.sin(a0) * radius;
|
|
39
|
+
const x1 = Math.cos(a1) * radius, y1 = Math.sin(a1) * radius;
|
|
40
|
+
coneVerts.push(x0, y0, z, x1, y1, z);
|
|
41
|
+
if (r < rings) {
|
|
42
|
+
const z2 = -0.3 - ((r + 1) / rings) * coneDist;
|
|
43
|
+
const r2 = topR + (bottomR - topR) * ((r + 1) / rings);
|
|
44
|
+
const x2 = Math.cos(a0) * r2, y2 = Math.sin(a0) * r2;
|
|
45
|
+
coneVerts.push(x0, y0, z, x2, y2, z2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const coneGeo = new BufferGeometry();
|
|
50
|
+
coneGeo.setAttribute("position", new BufferAttribute(new Float32Array(coneVerts), 3));
|
|
51
|
+
const coneLine = new LineSegments(coneGeo, new LineBasicMaterial({
|
|
52
|
+
color: this.color, depthTest: false,
|
|
53
|
+
}));
|
|
54
|
+
group.add(coneLine);
|
|
55
|
+
// ——— 标签 ———
|
|
56
|
+
const label = new SpriteText("聚光灯\n\n");
|
|
57
|
+
label.renderOrder = Infinity;
|
|
58
|
+
label.padding = 4;
|
|
59
|
+
label.strokeColor = "#333";
|
|
60
|
+
label.strokeWidth = 2;
|
|
61
|
+
label.position.set(0, -1, 0);
|
|
62
|
+
label.visible = false;
|
|
63
|
+
label.material.color = this.color;
|
|
64
|
+
label.material.sizeAttenuation = false;
|
|
65
|
+
label.scale.multiplyScalar(0.003);
|
|
66
|
+
group.add(label);
|
|
67
|
+
// ——— 交互 ———
|
|
68
|
+
group.userData = { cursor: "pointer" };
|
|
69
|
+
group.addEventListener("mouseenter", () => { label.visible = true; });
|
|
70
|
+
group.addEventListener("mouseleave", () => { label.visible = false; });
|
|
71
|
+
this.add(group);
|
|
72
|
+
return group;
|
|
73
|
+
})();
|
|
74
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Sprite, Raycaster, Intersection } from "three";
|
|
1
|
+
import { Sprite, Texture, Raycaster, Intersection } from "three";
|
|
2
2
|
export type SpritModal1Config = {
|
|
3
3
|
size?: number;
|
|
4
4
|
title?: string;
|
|
@@ -9,22 +9,25 @@ export type SpritModal1Config = {
|
|
|
9
9
|
size?: number;
|
|
10
10
|
}>;
|
|
11
11
|
};
|
|
12
|
+
type TextItem = {
|
|
13
|
+
text: string;
|
|
14
|
+
color: string;
|
|
15
|
+
size: number;
|
|
16
|
+
};
|
|
17
|
+
type ConfigType = {
|
|
18
|
+
size: number;
|
|
19
|
+
title: string;
|
|
20
|
+
titleColor: string;
|
|
21
|
+
texts: TextItem[];
|
|
22
|
+
};
|
|
12
23
|
export default class SpritModal1 extends Sprite {
|
|
13
24
|
constructor(config?: SpritModal1Config);
|
|
14
25
|
static img: HTMLImageElement;
|
|
15
26
|
canvas: HTMLCanvasElement;
|
|
16
|
-
context: CanvasRenderingContext2D;
|
|
17
|
-
texture:
|
|
18
|
-
_config:
|
|
19
|
-
size: number;
|
|
20
|
-
title: string;
|
|
21
|
-
titleColor: string;
|
|
22
|
-
texts: Array<{
|
|
23
|
-
text: string;
|
|
24
|
-
color: string;
|
|
25
|
-
size: number;
|
|
26
|
-
}>;
|
|
27
|
-
};
|
|
27
|
+
context: CanvasRenderingContext2D | null;
|
|
28
|
+
texture: Texture;
|
|
29
|
+
_config: ConfigType;
|
|
28
30
|
updata(config: SpritModal1Config): Promise<void>;
|
|
29
31
|
raycast(raycaster: Raycaster, intersects: Intersection[]): void;
|
|
30
32
|
}
|
|
33
|
+
export {};
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { Sprite, Vector2 } from "three";
|
|
8
8
|
import spriteModal1PNG from "./spriteModal1.png";
|
|
9
9
|
import threeLoader from "../threeLoader";
|
|
10
|
+
import { dispatchCustomEvent } from "../EventMap";
|
|
10
11
|
// sprit弹窗1
|
|
11
12
|
export default class SpritModal1 extends Sprite {
|
|
12
13
|
constructor(config = {}) {
|
|
@@ -16,6 +17,7 @@ export default class SpritModal1 extends Sprite {
|
|
|
16
17
|
this.material.transparent = true;
|
|
17
18
|
this.material.alphaTest = 0.01;
|
|
18
19
|
}
|
|
20
|
+
// dispatchEvent 已从 Sprite 继承,不需要重写
|
|
19
21
|
// 背景图
|
|
20
22
|
static img = (() => {
|
|
21
23
|
const img = new Image();
|
|
@@ -52,6 +54,8 @@ export default class SpritModal1 extends Sprite {
|
|
|
52
54
|
async updata(config) {
|
|
53
55
|
Object.assign(this._config, config);
|
|
54
56
|
//绘制背景
|
|
57
|
+
if (!this.context)
|
|
58
|
+
return;
|
|
55
59
|
this.context.clearRect(0, 0, 1024, 1024);
|
|
56
60
|
while (!SpritModal1.img.complete) {
|
|
57
61
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
@@ -72,6 +76,8 @@ export default class SpritModal1 extends Sprite {
|
|
|
72
76
|
let maxWidth = 530;
|
|
73
77
|
// 绘制内容
|
|
74
78
|
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
79
|
+
if (!this.context)
|
|
80
|
+
return;
|
|
75
81
|
this.context.fillStyle = color;
|
|
76
82
|
this.context.font = `${size}px serif`; // 设置字体大小
|
|
77
83
|
this.context.textAlign = "left";
|
|
@@ -96,14 +102,14 @@ export default class SpritModal1 extends Sprite {
|
|
|
96
102
|
textPos.y += size;
|
|
97
103
|
});
|
|
98
104
|
this.texture.needsUpdate = true;
|
|
99
|
-
this
|
|
105
|
+
dispatchCustomEvent(this, { type: "loaded" });
|
|
100
106
|
}
|
|
101
107
|
//鼠标拾取计算
|
|
102
108
|
raycast(raycaster, intersects) {
|
|
103
109
|
let intersect = [];
|
|
104
110
|
super.raycast(raycaster, intersect);
|
|
105
111
|
let inte = intersect[0];
|
|
106
|
-
if (inte && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
|
|
112
|
+
if (inte && inte.uv && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
|
|
107
113
|
intersects.push(inte);
|
|
108
114
|
}
|
|
109
115
|
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-03-08 00:01:34
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-03-08 02:05:25
|
|
6
|
+
*/
|
|
7
|
+
import { Sprite, Vector2, Texture, Raycaster, Intersection } from "three";
|
|
8
|
+
import spriteModal1PNG from "./spriteModal1.png";
|
|
9
|
+
import threeLoader from "../threeLoader";
|
|
10
|
+
import { dispatchCustomEvent } from "../EventMap";
|
|
11
|
+
|
|
12
|
+
export type SpritModal1Config = {
|
|
13
|
+
size?: number;
|
|
14
|
+
title?: string;
|
|
15
|
+
titleColor?: string;
|
|
16
|
+
texts?: Array<{
|
|
17
|
+
text?: string;
|
|
18
|
+
color?: string;
|
|
19
|
+
size?: number;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type TextItem = {
|
|
24
|
+
text: string;
|
|
25
|
+
color: string;
|
|
26
|
+
size: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type ConfigType = {
|
|
30
|
+
size: number;
|
|
31
|
+
title: string;
|
|
32
|
+
titleColor: string;
|
|
33
|
+
texts: TextItem[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// sprit弹窗1
|
|
37
|
+
export default class SpritModal1 extends Sprite {
|
|
38
|
+
constructor(config: SpritModal1Config = {}) {
|
|
39
|
+
super();
|
|
40
|
+
this.updata(config);
|
|
41
|
+
this.material.map = this.texture;
|
|
42
|
+
this.material.transparent = true;
|
|
43
|
+
this.material.alphaTest = 0.01;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// dispatchEvent 已从 Sprite 继承,不需要重写
|
|
47
|
+
|
|
48
|
+
// 背景图
|
|
49
|
+
static img: HTMLImageElement = (() => {
|
|
50
|
+
const img = new Image();
|
|
51
|
+
img.src = spriteModal1PNG;
|
|
52
|
+
return img;
|
|
53
|
+
})();
|
|
54
|
+
|
|
55
|
+
canvas: HTMLCanvasElement = (() => {
|
|
56
|
+
const canvas = document.createElement("canvas");
|
|
57
|
+
canvas.width = 1024;
|
|
58
|
+
canvas.height = 1024;
|
|
59
|
+
return canvas;
|
|
60
|
+
})();
|
|
61
|
+
|
|
62
|
+
context: CanvasRenderingContext2D | null = this.canvas.getContext("2d");
|
|
63
|
+
texture: Texture = threeLoader.getTexture(this.canvas);
|
|
64
|
+
|
|
65
|
+
// 配置
|
|
66
|
+
_config: ConfigType = {
|
|
67
|
+
size: 10,
|
|
68
|
+
title: "SpritModal1",
|
|
69
|
+
titleColor: "#ffffff",
|
|
70
|
+
texts: []
|
|
71
|
+
// [
|
|
72
|
+
// {
|
|
73
|
+
// text: "1",
|
|
74
|
+
// color: "#ffff00",
|
|
75
|
+
// size: 40
|
|
76
|
+
// },
|
|
77
|
+
// {
|
|
78
|
+
// text: "2",
|
|
79
|
+
// color: "#ff00ff",
|
|
80
|
+
// size: 40
|
|
81
|
+
// },
|
|
82
|
+
// ]
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
async updata(config: SpritModal1Config): Promise<void> {
|
|
86
|
+
Object.assign(this._config, config);
|
|
87
|
+
//绘制背景
|
|
88
|
+
if (!this.context) return;
|
|
89
|
+
this.context.clearRect(0, 0, 1024, 1024);
|
|
90
|
+
while (!SpritModal1.img.complete) {
|
|
91
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
92
|
+
}
|
|
93
|
+
// 设置大小
|
|
94
|
+
this.scale.set(this._config.size, this._config.size, this._config.size);
|
|
95
|
+
// this.context.fillStyle = "#00000088";
|
|
96
|
+
// this.context.fillRect(0, 0, 1024, 1024);
|
|
97
|
+
//绘制背景
|
|
98
|
+
this.context.drawImage(SpritModal1.img, 186, 0);
|
|
99
|
+
// 绘制标题
|
|
100
|
+
this.context.fillStyle = this._config.titleColor;
|
|
101
|
+
this.context.font = '40px serif'; // 设置字体大小
|
|
102
|
+
this.context.textAlign = "left";
|
|
103
|
+
this.context.textBaseline = "top";
|
|
104
|
+
this.context.fillText(this._config.title, 250, 72);
|
|
105
|
+
let textPos = new Vector2(250, 150);
|
|
106
|
+
let maxWidth = 530;
|
|
107
|
+
// 绘制内容
|
|
108
|
+
this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
|
|
109
|
+
if (!this.context) return;
|
|
110
|
+
this.context.fillStyle = color;
|
|
111
|
+
this.context.font = `${size}px serif`; // 设置字体大小
|
|
112
|
+
this.context.textAlign = "left";
|
|
113
|
+
this.context.textBaseline = "top";
|
|
114
|
+
// 字符分隔为数组
|
|
115
|
+
var arrText = text.split('');
|
|
116
|
+
var line = '';
|
|
117
|
+
// 文字自动换行计算
|
|
118
|
+
for (var n = 0; n < arrText.length; n++) {
|
|
119
|
+
var metrics = this.context.measureText(line + arrText[n]);
|
|
120
|
+
var testWidth = metrics.width;
|
|
121
|
+
if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
|
|
122
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
123
|
+
line = "";
|
|
124
|
+
textPos.y += size;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
line += arrText[n];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.context.fillText(line, textPos.x, textPos.y);
|
|
131
|
+
textPos.y += size;
|
|
132
|
+
});
|
|
133
|
+
this.texture.needsUpdate = true;
|
|
134
|
+
dispatchCustomEvent(this, { type: "loaded" });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//鼠标拾取计算
|
|
138
|
+
raycast(raycaster: Raycaster, intersects: Intersection[]): void {
|
|
139
|
+
let intersect: Intersection[] = [];
|
|
140
|
+
super.raycast(raycaster, intersect);
|
|
141
|
+
let inte = intersect[0];
|
|
142
|
+
if (inte && inte.uv && (inte.uv.x > 0.22 && inte.uv.x < 0.78) && (inte.uv.y > 0.54 && inte.uv.y < 0.94)) {
|
|
143
|
+
intersects.push(inte);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./SpriteModal1";
|