three-base 2.0.137 → 2.0.142
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 +6 -6
- package/DirectionalLight.js +68 -68
- package/DirectionalLight.ts +70 -0
- package/EventMap.d.ts +103 -0
- package/EventMap.js +17 -0
- package/EventMap.ts +139 -0
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/EventMesh.ts +60 -0
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +342 -366
- package/ExtrudeMesh.ts +553 -0
- package/FPScontrol.d.ts +511 -78
- package/FPScontrol.js +1799 -617
- package/FPScontrol.ts +1855 -0
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +80 -79
- package/Fire/Fire.ts +89 -0
- package/Fire/{FireGromtry.d.ts → FireGeometry.d.ts} +9 -9
- package/Fire/{FireGromtry.js → FireGeometry.js} +40 -40
- package/Fire/FireGeometry.ts +40 -0
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/FireMaterial.ts +89 -0
- package/Fire/index.d.ts +2 -1
- package/Fire/index.js +2 -1
- 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 +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/Grass.ts +38 -0
- package/Grass/index.d.ts +2 -1
- package/Grass/index.js +2 -1
- package/Grass/index.ts +2 -0
- package/Ground1/Ground1.d.ts +10 -11
- package/Ground1/Ground1.js +95 -91
- package/Ground1/Ground1.ts +114 -0
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/Ground1/index.ts +1 -0
- package/MeshBase.d.ts +36 -35
- package/MeshBase.js +247 -223
- package/MeshBase.ts +253 -0
- package/Mirror.d.ts +25 -25
- package/Mirror.js +143 -139
- package/Mirror.ts +203 -0
- package/MktMesh/MktMesh.d.ts +291 -0
- package/MktMesh/MktMesh.js +1045 -0
- package/MktMesh/MktMesh.ts +1075 -0
- package/MktMesh/assetUrl.d.ts +35 -0
- package/MktMesh/assetUrl.js +69 -0
- package/MktMesh/assetUrl.ts +69 -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.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +307 -300
- package/PipeMesh/PathGeometry.ts +343 -0
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPoint.ts +36 -0
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +209 -208
- package/PipeMesh/PathPointList.ts +227 -0
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PathTubeGeometry.ts +146 -0
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/PipeMesh.ts +76 -0
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PipeMesh/index.ts +1 -0
- package/PlaneModal1/PlaneModal1.d.ts +34 -31
- package/PlaneModal1/PlaneModal1.js +109 -105
- package/PlaneModal1/PlaneModal1.ts +138 -0
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneModal1/index.ts +1 -0
- package/PlaneText.d.ts +27 -39
- package/PlaneText.js +35 -30
- package/PlaneText.ts +55 -0
- package/PlaneWithHtml.d.ts +13 -11
- package/PlaneWithHtml.js +64 -63
- package/PlaneWithHtml.ts +70 -0
- package/PointLight/PointLight.d.ts +13 -14
- package/PointLight/PointLight.js +64 -70
- package/PointLight/PointLight.ts +67 -0
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/PointLight/index.ts +1 -0
- package/README.md +110 -79
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/Sky.ts +22 -0
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/Sky/index.ts +1 -0
- package/SpotLight.d.ts +6 -6
- package/SpotLight.js +72 -72
- package/SpotLight.ts +74 -0
- package/SpriteModal1/SpriteModal1.d.ts +33 -30
- package/SpriteModal1/SpriteModal1.js +116 -110
- package/SpriteModal1/SpriteModal1.ts +146 -0
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteModal1/index.ts +1 -0
- package/SpriteText.d.ts +46 -45
- package/SpriteText.js +176 -163
- package/SpriteText.ts +205 -0
- package/SpriteText2.d.ts +48 -47
- package/SpriteText2.js +223 -198
- 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 +9 -7
- package/SpriteWithHtml.js +44 -44
- package/SpriteWithHtml.ts +50 -0
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +58 -62
- package/Text3D/Text3D.ts +77 -0
- package/Text3D/fontController.d.ts +60 -59
- package/Text3D/fontController.js +166 -199
- package/Text3D/fontController.ts +209 -0
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +248 -111
- package/ThreeBase.js +1202 -656
- package/ThreeBase.ts +1314 -0
- package/ThreeMouse.d.ts +54 -40
- package/ThreeMouse.js +453 -407
- package/ThreeMouse.ts +472 -0
- package/Transition.d.ts +45 -40
- package/Transition.js +209 -210
- package/Transition.ts +242 -0
- package/Water/Water.d.ts +5 -5
- package/Water/Water.js +44 -26
- 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 +23 -165
- package/index.d.ts +1 -1
- package/index.js +1 -2
- 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} +38 -39
- package/{InstancedMeshBase.js → instanced/InstancedMeshBase.js} +282 -293
- 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 +30 -0
- package/{keyContorls.js → keyControls.js} +101 -98
- 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 +99 -25
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +188 -101
- package/pass/bloom_pass.ts +243 -0
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +122 -99
- 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 +2 -2
- package/pass/frosted_glass_pass.js +167 -186
- package/pass/frosted_glass_pass.ts +288 -0
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/fsQuad.ts +34 -0
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +449 -233
- 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 +88 -13
- package/pass/ssao_pass.js +802 -366
- package/pass/ssao_pass.ts +918 -0
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +329 -258
- package/pass/stroke_pass.ts +638 -0
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +23 -66
- 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.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +55 -60
- package/shaders/baseTextureToRenderShader.ts +232 -0
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +13 -14
- 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 +35 -34
- package/threeLoader.js +518 -527
- package/threeLoader.ts +525 -0
- package/threeUtils.d.ts +53 -52
- package/threeUtils.js +329 -330
- 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/threeUtils.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2022-02-24 22:49:42
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2023-05-03 00:36:18
|
|
6
|
+
*/
|
|
7
|
+
import { Box3, BufferGeometry, Clock, EventDispatcher, Material, Mesh, MeshBasicMaterial, MeshLambertMaterial, Object3D, Vector3 } from "three";
|
|
8
|
+
import { MathUtils } from "three";
|
|
9
|
+
const { generateUUID } = MathUtils;
|
|
10
|
+
import { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter";
|
|
11
|
+
import type { ThreeUtilsEventTypeMap } from "./EventMap";
|
|
12
|
+
|
|
13
|
+
interface KeepZoomDom {
|
|
14
|
+
dom: HTMLElement;
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class ThreeUtils extends EventDispatcher<ThreeUtilsEventTypeMap> {
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.requestAnimationFrame();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isProd: boolean = typeof process !== 'undefined' && process.env?.NODE_ENV === "production";
|
|
26
|
+
|
|
27
|
+
isDev: boolean = typeof process !== 'undefined' && process.env?.NODE_ENV === "development";
|
|
28
|
+
|
|
29
|
+
_timeTemp: number = performance.now();
|
|
30
|
+
|
|
31
|
+
_accumulate: number = 0; // 事件分发次数
|
|
32
|
+
|
|
33
|
+
_box3: Box3 = new Box3();
|
|
34
|
+
|
|
35
|
+
_size: Vector3 = new Vector3();
|
|
36
|
+
|
|
37
|
+
_center: Vector3 = new Vector3();
|
|
38
|
+
|
|
39
|
+
_clock: Clock = new Clock();
|
|
40
|
+
|
|
41
|
+
requestAnimationFrame(): void {
|
|
42
|
+
this._accumulate += 1;
|
|
43
|
+
const timeTemp = (this._timeTemp = performance.now());
|
|
44
|
+
this.dispatchEvent({
|
|
45
|
+
type: "requestAnimationFrame",
|
|
46
|
+
timeTemp,
|
|
47
|
+
accumulate: this._accumulate,
|
|
48
|
+
});
|
|
49
|
+
this._computerDomZoom();
|
|
50
|
+
//执行一个计划任务
|
|
51
|
+
let work = this.workList.splice(0, 1)[0];
|
|
52
|
+
work && work();
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
this.requestAnimationFrame();
|
|
55
|
+
}, 30 - this._clock.getDelta());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 需要保持宽高比的元素列表
|
|
59
|
+
private _keepZoomDoms: KeepZoomDom[] = [];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*计算需要保持比例的元素
|
|
63
|
+
*/
|
|
64
|
+
private _computerDomZoom(): void {
|
|
65
|
+
//1. 踢除没有出现在页面上的 dom 元素
|
|
66
|
+
this._keepZoomDoms = this._keepZoomDoms.filter((l) => this.inDocument(l.dom));
|
|
67
|
+
//2.设置dom的缩放值样式
|
|
68
|
+
this._keepZoomDoms.map((item, i) => {
|
|
69
|
+
let parentDom = item.dom.parentNode as HTMLElement;
|
|
70
|
+
let scale = Math.min(parentDom.clientWidth / item.width, parentDom.clientHeight / item.height);
|
|
71
|
+
Object.assign(item.dom.style, {
|
|
72
|
+
position: "absolute",
|
|
73
|
+
top: "50%",
|
|
74
|
+
left: "50%",
|
|
75
|
+
transform: `translate(-50%, -50%) scale(${scale})`,
|
|
76
|
+
width: `${item.width}px`,
|
|
77
|
+
height: `${item.height}px`,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* dom元素保持比例
|
|
84
|
+
*/
|
|
85
|
+
keepZoom(dom: HTMLElement | null, width: number = 1920, height: number = 1080): void {
|
|
86
|
+
if (dom) {
|
|
87
|
+
// 去掉相同的dom存储的信息
|
|
88
|
+
this._keepZoomDoms = this._keepZoomDoms.filter((l) => l.dom !== dom);
|
|
89
|
+
// 把配置加入到列表中
|
|
90
|
+
this._keepZoomDoms.push({ dom, width, height });
|
|
91
|
+
dom.dataset.a = "这个元素缩放比例由 threeUtils.keepZoom 方法设置";
|
|
92
|
+
this._computerDomZoom();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
workList: Array<() => void> = [];
|
|
97
|
+
|
|
98
|
+
// 时钟对象
|
|
99
|
+
clock: Clock = new Clock();
|
|
100
|
+
|
|
101
|
+
// 按照任务队列依次执行计划任务 性能优化
|
|
102
|
+
/**
|
|
103
|
+
* @param {() => void} [callback]
|
|
104
|
+
* @param {boolean} [first=true] 需要优先执行
|
|
105
|
+
*/
|
|
106
|
+
addWork(work?: () => void, first: boolean = false): void {
|
|
107
|
+
// 加入任务队列
|
|
108
|
+
if (work && !this.workList.includes(work)) {
|
|
109
|
+
if (first) {
|
|
110
|
+
this.workList.splice(1, 0, work); // 优先执行的任务回调
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.workList.push(work);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
*判断一个元素是否在页面上
|
|
120
|
+
*/
|
|
121
|
+
inDocument(dom: ParentNode | null): boolean {
|
|
122
|
+
if (dom === null) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
else if (dom.parentNode === null) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
else if (dom.parentNode === document) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return this.inDocument(dom.parentNode);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 获取中心点
|
|
137
|
+
getCenter(object3d: Object3D | BufferGeometry): Vector3 {
|
|
138
|
+
if (object3d instanceof Object3D) {
|
|
139
|
+
this._box3.setFromObject(object3d);
|
|
140
|
+
this._box3.getCenter(this._center);
|
|
141
|
+
}
|
|
142
|
+
else if (object3d instanceof BufferGeometry) {
|
|
143
|
+
object3d.computeBoundingBox();
|
|
144
|
+
object3d.boundingBox!.getCenter(this._center);
|
|
145
|
+
}
|
|
146
|
+
return this._center.clone();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 获取模型大小
|
|
150
|
+
getSize(object3d: Object3D | BufferGeometry): Vector3 {
|
|
151
|
+
if (object3d instanceof Object3D) {
|
|
152
|
+
this._box3.setFromObject(object3d);
|
|
153
|
+
this._box3.getSize(this._size);
|
|
154
|
+
}
|
|
155
|
+
else if (object3d instanceof BufferGeometry) {
|
|
156
|
+
object3d.computeBoundingBox();
|
|
157
|
+
object3d.boundingBox!.getSize(this._size);
|
|
158
|
+
}
|
|
159
|
+
return this._size.clone();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 模型对齐底面
|
|
163
|
+
alignBottom(object3d: Object3D | BufferGeometry, y: number = 0): void {
|
|
164
|
+
if (object3d instanceof Object3D) {
|
|
165
|
+
this._box3.setFromObject(object3d);
|
|
166
|
+
this._box3.getCenter(this._center);
|
|
167
|
+
this._box3.getSize(this._size);
|
|
168
|
+
object3d.position.y -= this._center.y - this._size.y * 0.5;
|
|
169
|
+
object3d.position.y += y;
|
|
170
|
+
object3d.updateMatrixWorld(true);
|
|
171
|
+
}
|
|
172
|
+
else if (object3d instanceof BufferGeometry) {
|
|
173
|
+
object3d.computeBoundingBox();
|
|
174
|
+
object3d.translate(0, -object3d.boundingBox!.min.y + y, 0);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 居中对象
|
|
179
|
+
centerObject3D(object3d: Object3D | BufferGeometry): void {
|
|
180
|
+
if (object3d instanceof Object3D) {
|
|
181
|
+
this._box3.setFromObject(object3d);
|
|
182
|
+
this._box3.getCenter(this._center);
|
|
183
|
+
object3d.position.sub(this._center);
|
|
184
|
+
object3d.updateMatrixWorld(true);
|
|
185
|
+
}
|
|
186
|
+
else if (object3d instanceof BufferGeometry) {
|
|
187
|
+
object3d.center();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//居中对象
|
|
192
|
+
center(object3d: Object3D | BufferGeometry): void {
|
|
193
|
+
this.centerObject3D(object3d);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 使用指定的维度(xyz)计算, 缩放至指定大小;
|
|
197
|
+
scaleTo(object3d: Object3D | BufferGeometry, size: number = 1, key: Array<"x" | "y" | "z"> = ["x", "y", "z"]): void {
|
|
198
|
+
const originSize = this.getSize(object3d);
|
|
199
|
+
const scale = size / Math.max(...key.map((k) => originSize[k]));
|
|
200
|
+
if ((object3d as Object3D).isObject3D) {
|
|
201
|
+
(object3d as Object3D).scale.multiplyScalar(scale);
|
|
202
|
+
(object3d as Object3D).updateMatrixWorld(true);
|
|
203
|
+
}
|
|
204
|
+
else if ((object3d as BufferGeometry).isBufferGeometry) {
|
|
205
|
+
(object3d as BufferGeometry).scale(scale, scale, scale);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 应用全部变化
|
|
210
|
+
applyAllTranstion(object3d: Object3D): void {
|
|
211
|
+
object3d.updateMatrixWorld(true);
|
|
212
|
+
// 应用全部变换
|
|
213
|
+
object3d.traverse((obj) => {
|
|
214
|
+
obj.position.set(0, 0, 0);
|
|
215
|
+
obj.rotation.set(0, 0, 0);
|
|
216
|
+
obj.scale.set(1, 1, 1);
|
|
217
|
+
if (obj instanceof Mesh) {
|
|
218
|
+
obj.geometry.applyMatrix4(obj.matrixWorld);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 导出 glb
|
|
224
|
+
exportGLB(input: Object3D, fileName: string = "threeUtils.exportGLB", maxTextureSize: number = 4096): void {
|
|
225
|
+
const gltfExporter = new GLTFExporter();
|
|
226
|
+
gltfExporter.parse(input, (result) => {
|
|
227
|
+
if (result instanceof ArrayBuffer) {
|
|
228
|
+
const link = document.createElement("a");
|
|
229
|
+
link.style.display = "none";
|
|
230
|
+
document.body.appendChild(link); // Firefox workaround, see #6594
|
|
231
|
+
link.href = URL.createObjectURL(new Blob([result], { type: "application/octet-stream" }));
|
|
232
|
+
link.download = `${fileName}.glb`;
|
|
233
|
+
link.click();
|
|
234
|
+
}
|
|
235
|
+
}, (error) => { }, {
|
|
236
|
+
trs: true,
|
|
237
|
+
onlyVisible: true, // 只导出可见的
|
|
238
|
+
binary: true, // glb
|
|
239
|
+
maxTextureSize: maxTextureSize,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//导出usdz
|
|
244
|
+
exportUsdz(): void { }
|
|
245
|
+
|
|
246
|
+
// 计算网格的体积
|
|
247
|
+
getVolume(geometry: BufferGeometry): number {
|
|
248
|
+
if (!geometry.index)
|
|
249
|
+
return 0;
|
|
250
|
+
if (!geometry.isBufferGeometry) {
|
|
251
|
+
console.warn("'geometry' must be an indexed or non-indexed buffer geometry");
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
const isIndexed = geometry.index !== null;
|
|
255
|
+
const position = geometry.attributes.position;
|
|
256
|
+
let sum = 0;
|
|
257
|
+
const p1 = new Vector3(), p2 = new Vector3(), p3 = new Vector3();
|
|
258
|
+
if (!isIndexed) {
|
|
259
|
+
const faces = position.count / 3;
|
|
260
|
+
for (let i = 0; i < faces; i++) {
|
|
261
|
+
p1.fromBufferAttribute(position, i * 3 + 0);
|
|
262
|
+
p2.fromBufferAttribute(position, i * 3 + 1);
|
|
263
|
+
p3.fromBufferAttribute(position, i * 3 + 2);
|
|
264
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const index = geometry.index;
|
|
269
|
+
const faces = index.count / 3;
|
|
270
|
+
for (let i = 0; i < faces; i++) {
|
|
271
|
+
p1.fromBufferAttribute(position, index.array[i * 3 + 0]);
|
|
272
|
+
p2.fromBufferAttribute(position, index.array[i * 3 + 1]);
|
|
273
|
+
p3.fromBufferAttribute(position, index.array[i * 3 + 2]);
|
|
274
|
+
sum += this.signedVolumeOfTriangle(p1, p2, p3);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return sum > 0 ? sum : 0;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
signedVolumeOfTriangle(p1: Vector3, p2: Vector3, p3: Vector3): number {
|
|
281
|
+
return p1.dot(p2.cross(p3)) / 6.0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
//清理对象的网格和材质的缓存
|
|
285
|
+
dipose(object3d: Object3D): void {
|
|
286
|
+
object3d.traverse((obj) => {
|
|
287
|
+
if (obj instanceof Mesh) {
|
|
288
|
+
obj.geometry.dispose();
|
|
289
|
+
if (obj.material instanceof Material) {
|
|
290
|
+
obj.material.dispose();
|
|
291
|
+
}
|
|
292
|
+
else if (obj.material instanceof Array) {
|
|
293
|
+
obj.material.map((m: Material) => {
|
|
294
|
+
m.dispose();
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 获取文件名的后缀
|
|
302
|
+
getSuffix(filename: string): string {
|
|
303
|
+
const match = filename.match(/([^\.]+)$/);
|
|
304
|
+
return match ? match[1].toLowerCase() : "";
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// 从url 中提取文件名
|
|
308
|
+
getFilename(url: string): string {
|
|
309
|
+
// 移除URL的查询字符串和哈希部分
|
|
310
|
+
const path = url.split("?")[0].split("#")[0];
|
|
311
|
+
// 使用lastIndexOf和substring从路径中提取文件名
|
|
312
|
+
const filename = path.substring(path.lastIndexOf("/") + 1);
|
|
313
|
+
return filename;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
//文件转blob
|
|
317
|
+
fileToBloburl(file: File): Promise<string> {
|
|
318
|
+
return new Promise((resolve, reject) => {
|
|
319
|
+
const reader = new FileReader();
|
|
320
|
+
reader.onload = function (event) {
|
|
321
|
+
const arrayBuffer = event.target!.result;
|
|
322
|
+
const blob = new Blob([arrayBuffer]);
|
|
323
|
+
const bloburl = URL.createObjectURL(blob);
|
|
324
|
+
resolve(bloburl);
|
|
325
|
+
};
|
|
326
|
+
reader.onerror = function (error) {
|
|
327
|
+
throw new Error(`文件转blbo 失败,${file.name}`);
|
|
328
|
+
};
|
|
329
|
+
reader.readAsArrayBuffer(file);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
//材质转为基础材质
|
|
334
|
+
toMeshBasicMaterial<P extends Material | Material[]>(material: P): P {
|
|
335
|
+
if (material instanceof Array) {
|
|
336
|
+
return material.map((m) => this.toMeshBasicMaterial(m)) as P;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
const meshBasicMaterial = new MeshBasicMaterial();
|
|
340
|
+
for (let i in meshBasicMaterial) {
|
|
341
|
+
if (!["type"].includes(i) &&
|
|
342
|
+
meshBasicMaterial.hasOwnProperty(i) &&
|
|
343
|
+
(material as unknown as { [key: string]: unknown }).hasOwnProperty(i)) {
|
|
344
|
+
(meshBasicMaterial as unknown as { [key: string]: unknown })[i] = (material as unknown as { [key: string]: unknown })[i];
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return meshBasicMaterial as unknown as P;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
toMeshLambertMaterial<P extends Material | Material[]>(material: P): P {
|
|
352
|
+
if (material instanceof Array) {
|
|
353
|
+
return material.map((m) => this.toMeshLambertMaterial(m)) as P;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const meshLambertMaterial = new MeshLambertMaterial();
|
|
357
|
+
for (let i in meshLambertMaterial) {
|
|
358
|
+
if (!["type"].includes(i) &&
|
|
359
|
+
meshLambertMaterial.hasOwnProperty(i) &&
|
|
360
|
+
(material as unknown as { [key: string]: unknown }).hasOwnProperty(i)) {
|
|
361
|
+
(meshLambertMaterial as unknown as { [key: string]: unknown })[i] = (material as unknown as { [key: string]: unknown })[i];
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return meshLambertMaterial as unknown as P;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const threeUtils: ThreeUtils = new ThreeUtils();
|
|
370
|
+
|
|
371
|
+
(window as unknown as Record<string, unknown>).threeUtils = threeUtils;
|
|
372
|
+
|
|
373
|
+
export default threeUtils;
|
package/types.d.ts
ADDED
package/types.js
ADDED
package/types.ts
ADDED
package/ApngTexture.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { APNG } from "apng-js";
|
|
2
|
-
import Player from "apng-js/types/library/player";
|
|
3
|
-
import { CanvasTexture } from "three";
|
|
4
|
-
export default class ApngTexture extends CanvasTexture {
|
|
5
|
-
constructor(url: string);
|
|
6
|
-
static TimeTemp: number;
|
|
7
|
-
preUpdate: number;
|
|
8
|
-
player?: Player;
|
|
9
|
-
apng?: APNG;
|
|
10
|
-
onUpdate: () => void;
|
|
11
|
-
getUuid(): number | "";
|
|
12
|
-
loadApng(url: string): Promise<void>;
|
|
13
|
-
}
|
package/ApngTexture.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import parseAPNG from "apng-js";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { CanvasTexture } from "three";
|
|
4
|
-
import threeUtils from "./threeUtils";
|
|
5
|
-
export default class ApngTexture extends CanvasTexture {
|
|
6
|
-
constructor(url) {
|
|
7
|
-
super(document.createElement("canvas"));
|
|
8
|
-
this.loadApng(url);
|
|
9
|
-
}
|
|
10
|
-
// 获取时间戳
|
|
11
|
-
static TimeTemp = performance.now();
|
|
12
|
-
// 上一次更新时间
|
|
13
|
-
preUpdate = 0;
|
|
14
|
-
player;
|
|
15
|
-
// apng 对象
|
|
16
|
-
apng;
|
|
17
|
-
// 更新纹理
|
|
18
|
-
onUpdate = () => {
|
|
19
|
-
if (this.preUpdate === ApngTexture.TimeTemp) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
this.preUpdate = ApngTexture.TimeTemp;
|
|
23
|
-
if (this.player) {
|
|
24
|
-
this.player.renderNextFrame();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
// 获取当前帧id
|
|
28
|
-
getUuid() {
|
|
29
|
-
if (this.apng) {
|
|
30
|
-
let currentTime = ApngTexture.TimeTemp % this.apng.playTime;
|
|
31
|
-
let i = 0;
|
|
32
|
-
while (this.apng.frames[i] && currentTime > this.apng.frames[i].delay) {
|
|
33
|
-
currentTime -= this.apng.frames[i].delay;
|
|
34
|
-
i++;
|
|
35
|
-
}
|
|
36
|
-
return this.apng.frames[i].delay;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// 加载apng图片
|
|
43
|
-
async loadApng(url) {
|
|
44
|
-
const res = await axios.get(url, { method: "post", responseType: "blob" });
|
|
45
|
-
const blob = new Blob([res.data]);
|
|
46
|
-
const reader = new FileReader();
|
|
47
|
-
await new Promise((resolve) => {
|
|
48
|
-
reader.onload = () => resolve();
|
|
49
|
-
reader.readAsArrayBuffer(blob);
|
|
50
|
-
});
|
|
51
|
-
const apng = parseAPNG(reader.result);
|
|
52
|
-
this.dispose();
|
|
53
|
-
this.image.width = apng.width;
|
|
54
|
-
this.image.height = apng.height;
|
|
55
|
-
this.player = await apng.getPlayer(this.image.getContext("2d"));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// 定时更新时间戳
|
|
59
|
-
threeUtils.addEventListener("requestAnimationFrame", (e) => {
|
|
60
|
-
ApngTexture.TimeTemp = e.timeTemp;
|
|
61
|
-
});
|
package/ApngTextureManage.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Texture, TextureLoader } from "three";
|
|
2
|
-
/**
|
|
3
|
-
* apng 纹理管理对象
|
|
4
|
-
*/
|
|
5
|
-
declare class apngTextureManage {
|
|
6
|
-
constructor();
|
|
7
|
-
static TextureLoader: TextureLoader;
|
|
8
|
-
static isInit: boolean;
|
|
9
|
-
static TimeTemp: number;
|
|
10
|
-
playTimes: Map<any, any>;
|
|
11
|
-
anpgTextList: {
|
|
12
|
-
[key: string]: Texture[];
|
|
13
|
-
};
|
|
14
|
-
getTexture(path: string): Texture;
|
|
15
|
-
loadApng(url: string): Promise<void>;
|
|
16
|
-
}
|
|
17
|
-
declare const ApngTextureManage: apngTextureManage;
|
|
18
|
-
export default ApngTextureManage;
|
package/ApngTextureManage.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import parseAPNG from "apng-js";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import { isEmpty } from "lodash";
|
|
4
|
-
import { MirroredRepeatWrapping, TextureLoader } from "three";
|
|
5
|
-
import threeUtils from "./threeUtils";
|
|
6
|
-
/**
|
|
7
|
-
* apng 纹理管理对象
|
|
8
|
-
*/
|
|
9
|
-
class apngTextureManage {
|
|
10
|
-
constructor() {
|
|
11
|
-
// 初始化定时更新时间戳
|
|
12
|
-
if (apngTextureManage.isInit) {
|
|
13
|
-
apngTextureManage.isInit = false;
|
|
14
|
-
threeUtils.addEventListener("requestAnimationFrame5000", (e) => {
|
|
15
|
-
apngTextureManage.TimeTemp = e.timeTemp;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
static TextureLoader = new TextureLoader();
|
|
20
|
-
static isInit = true;
|
|
21
|
-
// 获取时间戳
|
|
22
|
-
static TimeTemp = performance.now();
|
|
23
|
-
// 每个动态纹理的播放总时长
|
|
24
|
-
playTimes = new Map();
|
|
25
|
-
// 保存所有的动态纹理
|
|
26
|
-
anpgTextList = {};
|
|
27
|
-
// 获取动态纹理 需要每帧都获取一下
|
|
28
|
-
getTexture(path) {
|
|
29
|
-
// 如果 没有这个纹理就返回空同时开始加载这个纹理
|
|
30
|
-
if (!this.anpgTextList[path]) {
|
|
31
|
-
this.anpgTextList[path] = [];
|
|
32
|
-
this.loadApng(path);
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
else if (isEmpty(this.anpgTextList[path])) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const playTime = this.playTimes.get(path);
|
|
40
|
-
let currentTime = apngTextureManage.TimeTemp % playTime;
|
|
41
|
-
let i = 0;
|
|
42
|
-
while (this.anpgTextList[path][i] && currentTime > Number(this.anpgTextList[path][i].name)) {
|
|
43
|
-
currentTime -= Number(this.anpgTextList[path][i].name);
|
|
44
|
-
i++;
|
|
45
|
-
}
|
|
46
|
-
this.anpgTextList[path][i].needsUpdate = true;
|
|
47
|
-
return this.anpgTextList[path][i];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// 加载apng图片
|
|
51
|
-
async loadApng(url) {
|
|
52
|
-
const res = await axios.get(url, { method: "post", responseType: "blob" });
|
|
53
|
-
const blob = new Blob([res.data]);
|
|
54
|
-
const reader = new FileReader();
|
|
55
|
-
await new Promise((resolve) => {
|
|
56
|
-
reader.onload = () => resolve();
|
|
57
|
-
reader.readAsArrayBuffer(blob);
|
|
58
|
-
});
|
|
59
|
-
const apng = parseAPNG(reader.result);
|
|
60
|
-
// 存储播放时长
|
|
61
|
-
this.playTimes.set(url, apng.playTime);
|
|
62
|
-
// for (let i = 0; i < apng.frames.length; i++) {
|
|
63
|
-
// const frame = apng.frames[i];
|
|
64
|
-
// frame.createImage();
|
|
65
|
-
// await new Promise(resolve => frame.imageElement!.onload = resolve);
|
|
66
|
-
// }
|
|
67
|
-
for (let i = 0; i < apng.frames.length; i++) {
|
|
68
|
-
const frame = apng.frames[i];
|
|
69
|
-
var blobUrl = URL.createObjectURL(frame.imageData);
|
|
70
|
-
const texture = apngTextureManage.TextureLoader.load(blobUrl);
|
|
71
|
-
texture.anisotropy = 16;
|
|
72
|
-
texture.wrapS = texture.wrapT = MirroredRepeatWrapping;
|
|
73
|
-
// export const RepeatWrapping: Wrapping;
|
|
74
|
-
// export const ClampToEdgeWrapping: Wrapping;
|
|
75
|
-
// export const MirroredRepeatWrapping: Wrapping;
|
|
76
|
-
// magFilter: TextureFilter;
|
|
77
|
-
// minFilter: TextureFilter;
|
|
78
|
-
texture.name = String(frame.delay);
|
|
79
|
-
texture.center.set(0.5, 0.5);
|
|
80
|
-
texture.repeat.set(apng.width / frame.width, apng.height / frame.height);
|
|
81
|
-
// texture.needsUpdate = true;
|
|
82
|
-
this.anpgTextList[url].push(texture);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const ApngTextureManage = new apngTextureManage();
|
|
87
|
-
export default ApngTextureManage;
|
package/KeyFrameAnimation.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Euler, Line, LineBasicMaterial, Object3D, Vector3 } from "three";
|
|
2
|
-
export type Keyframe = {
|
|
3
|
-
position: Vector3;
|
|
4
|
-
scale: Vector3;
|
|
5
|
-
rotation: Euler;
|
|
6
|
-
timeTemp: number;
|
|
7
|
-
};
|
|
8
|
-
export type KeyframeAnimationProps = {
|
|
9
|
-
speedScale?: number;
|
|
10
|
-
object3d: Object3D;
|
|
11
|
-
keyframes: Array<Keyframe>;
|
|
12
|
-
};
|
|
13
|
-
export default class KeyframeAnimation extends Object3D {
|
|
14
|
-
constructor(props: KeyframeAnimationProps);
|
|
15
|
-
speedScale: number;
|
|
16
|
-
object3d: Object3D;
|
|
17
|
-
halperLine: Line<any, LineBasicMaterial, import("three").Object3DEventMap>;
|
|
18
|
-
keyframes: Array<Keyframe>;
|
|
19
|
-
setObject3D(object3d: Object3D): void;
|
|
20
|
-
getKeyframe(i: number): Keyframe;
|
|
21
|
-
setKeyframe(i: number, keyframe: Keyframe): void;
|
|
22
|
-
setKeyframes(keyframes: Array<Keyframe>): void;
|
|
23
|
-
update(): void;
|
|
24
|
-
updateMatrix(): void;
|
|
25
|
-
}
|
package/KeyFrameAnimation.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-02-16 00:22:31
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-02-16 19:08:55
|
|
6
|
-
*/
|
|
7
|
-
import { last } from "lodash";
|
|
8
|
-
import { BufferAttribute, Line, LineBasicMaterial, Object3D } from "three";
|
|
9
|
-
import threeUtils from "./threeUtils";
|
|
10
|
-
// 关键帧动画对象
|
|
11
|
-
export default class KeyframeAnimation extends Object3D {
|
|
12
|
-
constructor(props) {
|
|
13
|
-
super();
|
|
14
|
-
// 速度调整
|
|
15
|
-
this.speedScale = props.speedScale || 1;
|
|
16
|
-
// 设置关键帧对象数组
|
|
17
|
-
this.setKeyframes(props.keyframes);
|
|
18
|
-
// 设置对象
|
|
19
|
-
this.setObject3D(props.object3d);
|
|
20
|
-
}
|
|
21
|
-
// 速度调整
|
|
22
|
-
speedScale = 1;
|
|
23
|
-
// 需要需要移动的对象
|
|
24
|
-
object3d;
|
|
25
|
-
//路径辅助线
|
|
26
|
-
halperLine = new Line(undefined, new LineBasicMaterial({ color: "#f00" }));
|
|
27
|
-
// 关键帧数组
|
|
28
|
-
keyframes = [];
|
|
29
|
-
// 设置需要移动的对象
|
|
30
|
-
setObject3D(object3d) {
|
|
31
|
-
this.object3d = object3d;
|
|
32
|
-
if (threeUtils.isDev) {
|
|
33
|
-
this.children = [object3d, this.halperLine];
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.children = [object3d];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// 获取单个关键帧
|
|
40
|
-
getKeyframe(i) {
|
|
41
|
-
return this.keyframes[i];
|
|
42
|
-
}
|
|
43
|
-
// 设置单个关键帧
|
|
44
|
-
setKeyframe(i, keyframe) {
|
|
45
|
-
this.keyframes[i] = keyframe;
|
|
46
|
-
this.setKeyframes(this.keyframes);
|
|
47
|
-
}
|
|
48
|
-
//设置全部关键帧
|
|
49
|
-
setKeyframes(keyframes) {
|
|
50
|
-
this.keyframes = keyframes;
|
|
51
|
-
const position = [];
|
|
52
|
-
keyframes.map(k => {
|
|
53
|
-
position.push(k.position.x);
|
|
54
|
-
position.push(k.position.y);
|
|
55
|
-
position.push(k.position.z);
|
|
56
|
-
});
|
|
57
|
-
this.halperLine.geometry.setAttribute("position", new BufferAttribute(new Float32Array(position), 3, false));
|
|
58
|
-
}
|
|
59
|
-
// 更具关键帧的信息更新 对象的位置
|
|
60
|
-
update() {
|
|
61
|
-
const { _timeTemp } = threeUtils;
|
|
62
|
-
const maxtimetemp = last(this.keyframes).timeTemp;
|
|
63
|
-
const currentTime = _timeTemp % maxtimetemp;
|
|
64
|
-
const currentKeyframeIndex = this.keyframes.findIndex(k => currentTime < k.timeTemp);
|
|
65
|
-
const startKeyframe = this.keyframes[currentKeyframeIndex - 1];
|
|
66
|
-
const endKeyframe = this.keyframes[currentKeyframeIndex];
|
|
67
|
-
const progress = (currentTime - startKeyframe.timeTemp) / (endKeyframe.timeTemp - startKeyframe.timeTemp);
|
|
68
|
-
this.object3d.position.copy(endKeyframe.position).sub(startKeyframe.position).multiplyScalar(progress).add(startKeyframe.position);
|
|
69
|
-
this.object3d.scale.copy(endKeyframe.scale).sub(startKeyframe.scale).multiplyScalar(progress).add(startKeyframe.scale);
|
|
70
|
-
this.object3d.rotation.set((endKeyframe.rotation.x - startKeyframe.rotation.x) * progress + startKeyframe.rotation.x, (endKeyframe.rotation.y - startKeyframe.rotation.y) * progress + startKeyframe.rotation.y, (endKeyframe.rotation.z - startKeyframe.rotation.z) * progress + startKeyframe.rotation.z);
|
|
71
|
-
this.dispatchEvent({ type: "update" });
|
|
72
|
-
}
|
|
73
|
-
//更新关键帧的实例矩阵
|
|
74
|
-
updateMatrix() {
|
|
75
|
-
this.update();
|
|
76
|
-
super.updateMatrix();
|
|
77
|
-
}
|
|
78
|
-
}
|