three-base 2.0.130 → 2.0.134

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.
Files changed (123) hide show
  1. package/ApngTexture.d.ts +13 -13
  2. package/ApngTexture.js +61 -61
  3. package/ApngTextureManage.d.ts +18 -18
  4. package/ApngTextureManage.js +87 -87
  5. package/DirectionalLight.d.ts +6 -0
  6. package/DirectionalLight.js +68 -0
  7. package/EventMesh.d.ts +18 -18
  8. package/EventMesh.js +59 -59
  9. package/ExtrudeMesh.d.ts +112 -112
  10. package/ExtrudeMesh.js +366 -366
  11. package/FPScontrol.d.ts +71 -50
  12. package/FPScontrol.js +505 -232
  13. package/Fire/Fire.d.ts +28 -28
  14. package/Fire/Fire.js +79 -79
  15. package/Fire/FireGromtry.d.ts +9 -9
  16. package/Fire/FireGromtry.js +40 -40
  17. package/Fire/FireMaterial.d.ts +28 -28
  18. package/Fire/FireMaterial.js +32 -32
  19. package/Fire/index.d.ts +1 -1
  20. package/Fire/index.js +1 -1
  21. package/Grass/Grass.d.ts +8 -8
  22. package/Grass/Grass.js +38 -38
  23. package/Grass/index.d.ts +1 -1
  24. package/Grass/index.js +1 -1
  25. package/Ground1/Ground1.d.ts +11 -11
  26. package/Ground1/Ground1.js +54 -54
  27. package/Ground1/index.d.ts +1 -1
  28. package/Ground1/index.js +1 -1
  29. package/InstancedMeshBase.d.ts +39 -39
  30. package/InstancedMeshBase.js +293 -293
  31. package/KeyFrameAnimation.d.ts +25 -25
  32. package/KeyFrameAnimation.js +78 -78
  33. package/MeshBase.d.ts +35 -35
  34. package/MeshBase.js +223 -223
  35. package/Mirror.d.ts +25 -25
  36. package/Mirror.js +139 -139
  37. package/PipeMesh/PathGeometry.d.ts +44 -44
  38. package/PipeMesh/PathGeometry.js +300 -300
  39. package/PipeMesh/PathPoint.d.ts +17 -17
  40. package/PipeMesh/PathPoint.js +31 -31
  41. package/PipeMesh/PathPointList.d.ts +31 -31
  42. package/PipeMesh/PathPointList.js +208 -208
  43. package/PipeMesh/PathTubeGeometry.d.ts +25 -25
  44. package/PipeMesh/PathTubeGeometry.js +130 -130
  45. package/PipeMesh/PipeMesh.d.ts +25 -25
  46. package/PipeMesh/PipeMesh.js +63 -63
  47. package/PipeMesh/index.d.ts +1 -1
  48. package/PipeMesh/index.js +1 -1
  49. package/PlaneModal1/PlaneModal1.d.ts +31 -31
  50. package/PlaneModal1/PlaneModal1.js +105 -105
  51. package/PlaneModal1/index.d.ts +1 -1
  52. package/PlaneModal1/index.js +1 -1
  53. package/PlaneText.d.ts +39 -39
  54. package/PlaneText.js +30 -30
  55. package/PlaneWithHtml.d.ts +11 -11
  56. package/PlaneWithHtml.js +63 -68
  57. package/PointLight/PointLight.d.ts +14 -13
  58. package/PointLight/PointLight.js +70 -64
  59. package/PointLight/index.d.ts +1 -1
  60. package/PointLight/index.js +1 -1
  61. package/Sky/Sky.d.ts +9 -9
  62. package/Sky/Sky.js +22 -22
  63. package/Sky/index.d.ts +1 -1
  64. package/Sky/index.js +1 -1
  65. package/SpotLight.d.ts +6 -0
  66. package/SpotLight.js +72 -0
  67. package/SpriteModal1/SpriteModal1.d.ts +30 -30
  68. package/SpriteModal1/SpriteModal1.js +110 -110
  69. package/SpriteModal1/index.d.ts +1 -1
  70. package/SpriteModal1/index.js +1 -1
  71. package/SpriteText.d.ts +45 -45
  72. package/SpriteText.js +163 -163
  73. package/SpriteText2.d.ts +47 -47
  74. package/SpriteText2.js +198 -198
  75. package/SpriteWithHtml.d.ts +7 -7
  76. package/SpriteWithHtml.js +44 -49
  77. package/Text3D/Text3D.d.ts +20 -20
  78. package/Text3D/Text3D.js +62 -62
  79. package/Text3D/fontController.d.ts +59 -59
  80. package/Text3D/fontController.js +199 -199
  81. package/Text3D/index.d.ts +1 -1
  82. package/Text3D/index.js +1 -1
  83. package/ThreeBase.d.ts +97 -81
  84. package/ThreeBase.js +613 -560
  85. package/ThreeMouse.d.ts +40 -40
  86. package/ThreeMouse.js +407 -407
  87. package/Transition.d.ts +40 -40
  88. package/Transition.js +210 -210
  89. package/Water/Water.d.ts +5 -0
  90. package/Water/Water.js +26 -0
  91. package/Water/waternormals.jpg +0 -0
  92. package/declare.d.ts +167 -0
  93. package/index.d.ts +1 -1
  94. package/index.js +2 -2
  95. package/keyContorls.d.ts +25 -25
  96. package/keyContorls.js +98 -98
  97. package/package.json +1 -1
  98. package/pass/bloom_pass.d.ts +2 -2
  99. package/pass/bloom_pass.js +99 -99
  100. package/pass/cover_pass.d.ts +2 -2
  101. package/pass/cover_pass.js +95 -95
  102. package/pass/frosted_glass_pass.d.ts +2 -0
  103. package/pass/frosted_glass_pass.js +275 -0
  104. package/pass/fsQuad.d.ts +9 -9
  105. package/pass/fsQuad.js +28 -28
  106. package/pass/glow_pass.d.ts +2 -2
  107. package/pass/glow_pass.js +310 -254
  108. package/pass/ssao_pass.d.ts +11 -0
  109. package/pass/ssao_pass.js +294 -0
  110. package/pass/stroke_pass.d.ts +2 -2
  111. package/pass/stroke_pass.js +199 -199
  112. package/shaders/FXAAShaderMaterial.d.ts +3 -3
  113. package/shaders/FXAAShaderMaterial.js +21 -21
  114. package/shaders/baseTextureToRenderShader.d.ts +2 -2
  115. package/shaders/baseTextureToRenderShader.js +14 -14
  116. package/shaders/copyShader.d.ts +3 -3
  117. package/shaders/copyShader.js +14 -14
  118. package/shaders.d.ts +5 -5
  119. package/shaders.js +42 -42
  120. package/threeLoader.d.ts +34 -34
  121. package/threeLoader.js +527 -527
  122. package/threeUtils.d.ts +52 -52
  123. package/threeUtils.js +330 -330
@@ -1,300 +1,300 @@
1
- import { DynamicDrawUsage, StaticDrawUsage } from 'three/src/constants.js';
2
- import { PathPoint } from './PathPoint.js';
3
- import { BufferGeometry } from 'three/src/core/BufferGeometry.js';
4
- import { BufferAttribute } from 'three/src/core/BufferAttribute.js';
5
- import { Vector3 } from 'three/src/math/Vector3.js';
6
- /**
7
- * PathGeometry
8
- */
9
- class PathGeometry extends BufferGeometry {
10
- /**
11
- * @param {Object|Number} initData - If initData is number, geometry init by empty data and set it as the max vertex. If initData is Object, it contains pathPointList and options.
12
- * @param {Boolean} [generateUv2=false]
13
- */
14
- constructor(initData, generateUv2 = false) {
15
- super();
16
- this._initByData(initData.pathPointList, initData.options, initData.usage, generateUv2);
17
- }
18
- _initByMaxVertex(maxVertex, generateUv2) {
19
- this.setAttribute('position', new BufferAttribute(new Float32Array(maxVertex * 3), 3).setUsage(DynamicDrawUsage));
20
- this.setAttribute('normal', new BufferAttribute(new Float32Array(maxVertex * 3), 3).setUsage(DynamicDrawUsage));
21
- this.setAttribute('uv', new BufferAttribute(new Float32Array(maxVertex * 2), 2).setUsage(DynamicDrawUsage));
22
- if (generateUv2) {
23
- this.setAttribute('uv2', new BufferAttribute(new Float32Array(maxVertex * 2), 2).setUsage(DynamicDrawUsage));
24
- }
25
- this.drawRange.start = 0;
26
- this.drawRange.count = 0;
27
- this.setIndex(new Array(maxVertex * 3));
28
- }
29
- _initByData(pathPointList, options, usage, generateUv2) {
30
- const vertexData = generatePathVertexData(pathPointList, options, generateUv2);
31
- if (vertexData && vertexData.count !== 0) {
32
- this.setAttribute('position', new BufferAttribute(new Float32Array(vertexData.position), 3).setUsage(usage || StaticDrawUsage));
33
- this.setAttribute('normal', new BufferAttribute(new Float32Array(vertexData.normal), 3).setUsage(usage || StaticDrawUsage));
34
- this.setAttribute('uv', new BufferAttribute(new Float32Array(vertexData.uv), 2).setUsage(usage || StaticDrawUsage));
35
- if (generateUv2) {
36
- this.setAttribute('uv2', new BufferAttribute(new Float32Array(vertexData.uv2), 2).setUsage(usage || StaticDrawUsage));
37
- }
38
- this.setIndex(vertexData.indices);
39
- }
40
- else {
41
- this._initByMaxVertex(2, generateUv2);
42
- }
43
- }
44
- /**
45
- * Update geometry by PathPointList instance
46
- * @param {PathPointList} pathPointList
47
- * @param {Object} options
48
- * @param {Number} [options.width=0.1]
49
- * @param {Number} [options.progress=1]
50
- * @param {Boolean} [options.arrow=true]
51
- * @param {String} [options.side='both'] - "left"/"right"/"both"
52
- */
53
- update(pathPointList, options) {
54
- const generateUv2 = !!this.getAttribute('uv2');
55
- const vertexData = generatePathVertexData(pathPointList, options, generateUv2);
56
- if (vertexData) {
57
- this._updateAttributes(vertexData.position, vertexData.normal, vertexData.uv, generateUv2 ? vertexData.uv2 : null, vertexData.indices);
58
- this.drawRange.count = vertexData.count;
59
- }
60
- else {
61
- this.drawRange.count = 0;
62
- }
63
- }
64
- _resizeAttribute(name, len) {
65
- let attribute = this.getAttribute(name);
66
- while (attribute.array.length < len) {
67
- const oldLength = attribute.array.length;
68
- const newAttribute = new BufferAttribute(new Float32Array(oldLength * 2), attribute.itemSize, attribute.normalized);
69
- newAttribute.name = attribute.name;
70
- newAttribute.usage = attribute.usage;
71
- this.setAttribute(name, newAttribute);
72
- attribute = newAttribute;
73
- }
74
- }
75
- _resizeIndex(len) {
76
- let index = this.getIndex();
77
- while (index.array.length < len) {
78
- const oldLength = index.array.length;
79
- const newIndex = new BufferAttribute(oldLength * 2 > 65535 ? new Uint32Array(oldLength * 2) : new Uint16Array(oldLength * 2), 1);
80
- newIndex.name = index.name;
81
- newIndex.usage = index.usage;
82
- this.setIndex(newIndex);
83
- index = newIndex;
84
- }
85
- }
86
- _updateAttributes(position, normal, uv, uv2, indices) {
87
- this._resizeAttribute('position', position.length);
88
- const positionAttribute = this.getAttribute('position');
89
- positionAttribute.array.set(position, 0);
90
- positionAttribute.updateRange.count = position.length;
91
- positionAttribute.needsUpdate = true;
92
- this._resizeAttribute('normal', normal.length);
93
- const normalAttribute = this.getAttribute('normal');
94
- normalAttribute.array.set(normal, 0);
95
- normalAttribute.updateRange.count = normal.length;
96
- normalAttribute.needsUpdate = true;
97
- this._resizeAttribute('uv', uv.length);
98
- const uvAttribute = this.getAttribute('uv');
99
- uvAttribute.array.set(uv, 0);
100
- uvAttribute.updateRange.count = uv.length;
101
- uvAttribute.needsUpdate = true;
102
- if (uv2) {
103
- this._resizeAttribute('uv2', uv2.length);
104
- const uv2Attribute = this.getAttribute('uv2');
105
- uv2Attribute.array.set(uv2, 0);
106
- uv2Attribute.updateRange.count = uv2.length;
107
- uv2Attribute.needsUpdate = true;
108
- }
109
- this._resizeIndex(indices.length);
110
- const indexAttribute = this.getIndex();
111
- indexAttribute.set(indices, 0);
112
- indexAttribute.updateRange.count = indices.length;
113
- indexAttribute.needsUpdate = true;
114
- }
115
- }
116
- export { PathGeometry };
117
- // Vertex Data Generate Functions
118
- function generatePathVertexData(pathPointList, options, generateUv2 = false) {
119
- const width = options.width || 0.1;
120
- const progress = options.progress !== undefined ? options.progress : 1;
121
- const arrow = options.arrow !== undefined ? options.arrow : true;
122
- const side = options.side !== undefined ? options.side : 'both';
123
- const halfWidth = width / 2;
124
- const sideWidth = side !== 'both' ? width / 2 : width;
125
- const totalDistance = pathPointList.distance();
126
- const progressDistance = progress * totalDistance;
127
- if (totalDistance == 0) {
128
- return null;
129
- }
130
- const sharpUvOffset = halfWidth / sideWidth;
131
- const sharpUvOffset2 = halfWidth / totalDistance;
132
- let count = 0;
133
- // modify data
134
- const position = [];
135
- const normal = [];
136
- const uv = [];
137
- const uv2 = [];
138
- const indices = [];
139
- let verticesCount = 0;
140
- const right = new Vector3();
141
- const left = new Vector3();
142
- // for sharp corners
143
- const leftOffset = new Vector3();
144
- const rightOffset = new Vector3();
145
- const tempPoint1 = new Vector3();
146
- const tempPoint2 = new Vector3();
147
- function addVertices(pathPoint) {
148
- const first = position.length === 0;
149
- const sharpCorner = pathPoint.sharp && !first;
150
- const uvDist = pathPoint.dist / sideWidth;
151
- const uvDist2 = pathPoint.dist / totalDistance;
152
- const dir = pathPoint.dir;
153
- const up = pathPoint.up;
154
- const _right = pathPoint.right;
155
- if (side !== 'left') {
156
- right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
157
- }
158
- else {
159
- right.set(0, 0, 0);
160
- }
161
- if (side !== 'right') {
162
- left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
163
- }
164
- else {
165
- left.set(0, 0, 0);
166
- }
167
- right.add(pathPoint.pos);
168
- left.add(pathPoint.pos);
169
- if (sharpCorner) {
170
- leftOffset.fromArray(position, position.length - 6).sub(left);
171
- rightOffset.fromArray(position, position.length - 3).sub(right);
172
- const leftDist = leftOffset.length();
173
- const rightDist = rightOffset.length();
174
- const sideOffset = leftDist - rightDist;
175
- let longerOffset, longEdge;
176
- if (sideOffset > 0) {
177
- longerOffset = leftOffset;
178
- longEdge = left;
179
- }
180
- else {
181
- longerOffset = rightOffset;
182
- longEdge = right;
183
- }
184
- tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge);
185
- let _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir);
186
- let _len = tempPoint2.copy(longEdge).sub(tempPoint1).length();
187
- let _dist = _cos * _len * 2;
188
- tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
189
- if (sideOffset > 0) {
190
- position.push(tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
191
- right.x, right.y, right.z, // 5
192
- left.x, left.y, left.z, // 4
193
- right.x, right.y, right.z, // 3
194
- tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
195
- right.x, right.y, right.z // 1
196
- );
197
- verticesCount += 6;
198
- indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 4, verticesCount - 6, verticesCount - 5, verticesCount - 2, verticesCount - 4, verticesCount - 1);
199
- count += 12;
200
- }
201
- else {
202
- position.push(left.x, left.y, left.z, // 6
203
- tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
204
- left.x, left.y, left.z, // 4
205
- right.x, right.y, right.z, // 3
206
- left.x, left.y, left.z, // 2
207
- tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
208
- );
209
- verticesCount += 6;
210
- indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 6, verticesCount - 5, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
211
- count += 12;
212
- }
213
- normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
214
- uv.push(uvDist - sharpUvOffset, 0, uvDist - sharpUvOffset, 1, uvDist, 0, uvDist, 1, uvDist + sharpUvOffset, 0, uvDist + sharpUvOffset, 1);
215
- if (generateUv2) {
216
- uv2.push(uvDist2 - sharpUvOffset2, 0, uvDist2 - sharpUvOffset2, 1, uvDist2, 0, uvDist2, 1, uvDist2 + sharpUvOffset2, 0, uvDist2 + sharpUvOffset2, 1);
217
- }
218
- }
219
- else {
220
- position.push(left.x, left.y, left.z, right.x, right.y, right.z);
221
- normal.push(up.x, up.y, up.z, up.x, up.y, up.z);
222
- uv.push(uvDist, 0, uvDist, 1);
223
- if (generateUv2) {
224
- uv2.push(uvDist2, 0, uvDist2, 1);
225
- }
226
- verticesCount += 2;
227
- if (!first) {
228
- indices.push(verticesCount - 2, verticesCount - 4, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
229
- count += 6;
230
- }
231
- }
232
- }
233
- const sharp = new Vector3();
234
- function addStart(pathPoint) {
235
- const dir = pathPoint.dir;
236
- const up = pathPoint.up;
237
- const _right = pathPoint.right;
238
- const uvDist = pathPoint.dist / sideWidth;
239
- const uvDist2 = pathPoint.dist / totalDistance;
240
- if (side !== 'left') {
241
- right.copy(_right).multiplyScalar(halfWidth * 2);
242
- }
243
- else {
244
- right.set(0, 0, 0);
245
- }
246
- if (side !== 'right') {
247
- left.copy(_right).multiplyScalar(-halfWidth * 2);
248
- }
249
- else {
250
- left.set(0, 0, 0);
251
- }
252
- sharp.copy(dir).setLength(halfWidth * 3);
253
- right.add(pathPoint.pos);
254
- left.add(pathPoint.pos);
255
- sharp.add(pathPoint.pos);
256
- position.push(left.x, left.y, left.z, right.x, right.y, right.z, sharp.x, sharp.y, sharp.z);
257
- normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
258
- uv.push(uvDist, side !== 'both' ? (side !== 'right' ? -2 : 0) : -0.5, uvDist, side !== 'both' ? (side !== 'left' ? 2 : 0) : 1.5, uvDist + 1.5, side !== 'both' ? 0 : 0.5);
259
- if (generateUv2) {
260
- uv2.push(uvDist2, side !== 'both' ? (side !== 'right' ? -2 : 0) : -0.5, uvDist2, side !== 'both' ? (side !== 'left' ? 2 : 0) : 1.5, uvDist2 + (1.5 * width) / totalDistance, side !== 'both' ? 0 : 0.5);
261
- }
262
- verticesCount += 3;
263
- indices.push(verticesCount - 1, verticesCount - 3, verticesCount - 2);
264
- count += 3;
265
- }
266
- let lastPoint;
267
- if (progressDistance > 0) {
268
- for (let i = 0; i < pathPointList.count; i++) {
269
- const pathPoint = pathPointList.array[i];
270
- if (pathPoint.dist > progressDistance) {
271
- const prevPoint = pathPointList.array[i - 1];
272
- lastPoint = new PathPoint();
273
- // linear lerp for progress
274
- const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
275
- lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
276
- addVertices(lastPoint);
277
- break;
278
- }
279
- else {
280
- addVertices(pathPoint);
281
- }
282
- }
283
- }
284
- else {
285
- lastPoint = pathPointList.array[0];
286
- }
287
- // build arrow geometry
288
- if (arrow) {
289
- lastPoint = lastPoint || pathPointList.array[pathPointList.count - 1];
290
- addStart(lastPoint);
291
- }
292
- return {
293
- position,
294
- normal,
295
- uv,
296
- uv2,
297
- indices,
298
- count,
299
- };
300
- }
1
+ import { DynamicDrawUsage, StaticDrawUsage } from 'three/src/constants.js';
2
+ import { PathPoint } from './PathPoint.js';
3
+ import { BufferGeometry } from 'three/src/core/BufferGeometry.js';
4
+ import { BufferAttribute } from 'three/src/core/BufferAttribute.js';
5
+ import { Vector3 } from 'three/src/math/Vector3.js';
6
+ /**
7
+ * PathGeometry
8
+ */
9
+ class PathGeometry extends BufferGeometry {
10
+ /**
11
+ * @param {Object|Number} initData - If initData is number, geometry init by empty data and set it as the max vertex. If initData is Object, it contains pathPointList and options.
12
+ * @param {Boolean} [generateUv2=false]
13
+ */
14
+ constructor(initData, generateUv2 = false) {
15
+ super();
16
+ this._initByData(initData.pathPointList, initData.options, initData.usage, generateUv2);
17
+ }
18
+ _initByMaxVertex(maxVertex, generateUv2) {
19
+ this.setAttribute('position', new BufferAttribute(new Float32Array(maxVertex * 3), 3).setUsage(DynamicDrawUsage));
20
+ this.setAttribute('normal', new BufferAttribute(new Float32Array(maxVertex * 3), 3).setUsage(DynamicDrawUsage));
21
+ this.setAttribute('uv', new BufferAttribute(new Float32Array(maxVertex * 2), 2).setUsage(DynamicDrawUsage));
22
+ if (generateUv2) {
23
+ this.setAttribute('uv2', new BufferAttribute(new Float32Array(maxVertex * 2), 2).setUsage(DynamicDrawUsage));
24
+ }
25
+ this.drawRange.start = 0;
26
+ this.drawRange.count = 0;
27
+ this.setIndex(new Array(maxVertex * 3));
28
+ }
29
+ _initByData(pathPointList, options, usage, generateUv2) {
30
+ const vertexData = generatePathVertexData(pathPointList, options, generateUv2);
31
+ if (vertexData && vertexData.count !== 0) {
32
+ this.setAttribute('position', new BufferAttribute(new Float32Array(vertexData.position), 3).setUsage(usage || StaticDrawUsage));
33
+ this.setAttribute('normal', new BufferAttribute(new Float32Array(vertexData.normal), 3).setUsage(usage || StaticDrawUsage));
34
+ this.setAttribute('uv', new BufferAttribute(new Float32Array(vertexData.uv), 2).setUsage(usage || StaticDrawUsage));
35
+ if (generateUv2) {
36
+ this.setAttribute('uv2', new BufferAttribute(new Float32Array(vertexData.uv2), 2).setUsage(usage || StaticDrawUsage));
37
+ }
38
+ this.setIndex(vertexData.indices);
39
+ }
40
+ else {
41
+ this._initByMaxVertex(2, generateUv2);
42
+ }
43
+ }
44
+ /**
45
+ * Update geometry by PathPointList instance
46
+ * @param {PathPointList} pathPointList
47
+ * @param {Object} options
48
+ * @param {Number} [options.width=0.1]
49
+ * @param {Number} [options.progress=1]
50
+ * @param {Boolean} [options.arrow=true]
51
+ * @param {String} [options.side='both'] - "left"/"right"/"both"
52
+ */
53
+ update(pathPointList, options) {
54
+ const generateUv2 = !!this.getAttribute('uv2');
55
+ const vertexData = generatePathVertexData(pathPointList, options, generateUv2);
56
+ if (vertexData) {
57
+ this._updateAttributes(vertexData.position, vertexData.normal, vertexData.uv, generateUv2 ? vertexData.uv2 : null, vertexData.indices);
58
+ this.drawRange.count = vertexData.count;
59
+ }
60
+ else {
61
+ this.drawRange.count = 0;
62
+ }
63
+ }
64
+ _resizeAttribute(name, len) {
65
+ let attribute = this.getAttribute(name);
66
+ while (attribute.array.length < len) {
67
+ const oldLength = attribute.array.length;
68
+ const newAttribute = new BufferAttribute(new Float32Array(oldLength * 2), attribute.itemSize, attribute.normalized);
69
+ newAttribute.name = attribute.name;
70
+ newAttribute.usage = attribute.usage;
71
+ this.setAttribute(name, newAttribute);
72
+ attribute = newAttribute;
73
+ }
74
+ }
75
+ _resizeIndex(len) {
76
+ let index = this.getIndex();
77
+ while (index.array.length < len) {
78
+ const oldLength = index.array.length;
79
+ const newIndex = new BufferAttribute(oldLength * 2 > 65535 ? new Uint32Array(oldLength * 2) : new Uint16Array(oldLength * 2), 1);
80
+ newIndex.name = index.name;
81
+ newIndex.usage = index.usage;
82
+ this.setIndex(newIndex);
83
+ index = newIndex;
84
+ }
85
+ }
86
+ _updateAttributes(position, normal, uv, uv2, indices) {
87
+ this._resizeAttribute('position', position.length);
88
+ const positionAttribute = this.getAttribute('position');
89
+ positionAttribute.array.set(position, 0);
90
+ positionAttribute.updateRange.count = position.length;
91
+ positionAttribute.needsUpdate = true;
92
+ this._resizeAttribute('normal', normal.length);
93
+ const normalAttribute = this.getAttribute('normal');
94
+ normalAttribute.array.set(normal, 0);
95
+ normalAttribute.updateRange.count = normal.length;
96
+ normalAttribute.needsUpdate = true;
97
+ this._resizeAttribute('uv', uv.length);
98
+ const uvAttribute = this.getAttribute('uv');
99
+ uvAttribute.array.set(uv, 0);
100
+ uvAttribute.updateRange.count = uv.length;
101
+ uvAttribute.needsUpdate = true;
102
+ if (uv2) {
103
+ this._resizeAttribute('uv2', uv2.length);
104
+ const uv2Attribute = this.getAttribute('uv2');
105
+ uv2Attribute.array.set(uv2, 0);
106
+ uv2Attribute.updateRange.count = uv2.length;
107
+ uv2Attribute.needsUpdate = true;
108
+ }
109
+ this._resizeIndex(indices.length);
110
+ const indexAttribute = this.getIndex();
111
+ indexAttribute.set(indices, 0);
112
+ indexAttribute.updateRange.count = indices.length;
113
+ indexAttribute.needsUpdate = true;
114
+ }
115
+ }
116
+ export { PathGeometry };
117
+ // Vertex Data Generate Functions
118
+ function generatePathVertexData(pathPointList, options, generateUv2 = false) {
119
+ const width = options.width || 0.1;
120
+ const progress = options.progress !== undefined ? options.progress : 1;
121
+ const arrow = options.arrow !== undefined ? options.arrow : true;
122
+ const side = options.side !== undefined ? options.side : 'both';
123
+ const halfWidth = width / 2;
124
+ const sideWidth = side !== 'both' ? width / 2 : width;
125
+ const totalDistance = pathPointList.distance();
126
+ const progressDistance = progress * totalDistance;
127
+ if (totalDistance == 0) {
128
+ return null;
129
+ }
130
+ const sharpUvOffset = halfWidth / sideWidth;
131
+ const sharpUvOffset2 = halfWidth / totalDistance;
132
+ let count = 0;
133
+ // modify data
134
+ const position = [];
135
+ const normal = [];
136
+ const uv = [];
137
+ const uv2 = [];
138
+ const indices = [];
139
+ let verticesCount = 0;
140
+ const right = new Vector3();
141
+ const left = new Vector3();
142
+ // for sharp corners
143
+ const leftOffset = new Vector3();
144
+ const rightOffset = new Vector3();
145
+ const tempPoint1 = new Vector3();
146
+ const tempPoint2 = new Vector3();
147
+ function addVertices(pathPoint) {
148
+ const first = position.length === 0;
149
+ const sharpCorner = pathPoint.sharp && !first;
150
+ const uvDist = pathPoint.dist / sideWidth;
151
+ const uvDist2 = pathPoint.dist / totalDistance;
152
+ const dir = pathPoint.dir;
153
+ const up = pathPoint.up;
154
+ const _right = pathPoint.right;
155
+ if (side !== 'left') {
156
+ right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
157
+ }
158
+ else {
159
+ right.set(0, 0, 0);
160
+ }
161
+ if (side !== 'right') {
162
+ left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
163
+ }
164
+ else {
165
+ left.set(0, 0, 0);
166
+ }
167
+ right.add(pathPoint.pos);
168
+ left.add(pathPoint.pos);
169
+ if (sharpCorner) {
170
+ leftOffset.fromArray(position, position.length - 6).sub(left);
171
+ rightOffset.fromArray(position, position.length - 3).sub(right);
172
+ const leftDist = leftOffset.length();
173
+ const rightDist = rightOffset.length();
174
+ const sideOffset = leftDist - rightDist;
175
+ let longerOffset, longEdge;
176
+ if (sideOffset > 0) {
177
+ longerOffset = leftOffset;
178
+ longEdge = left;
179
+ }
180
+ else {
181
+ longerOffset = rightOffset;
182
+ longEdge = right;
183
+ }
184
+ tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge);
185
+ let _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir);
186
+ let _len = tempPoint2.copy(longEdge).sub(tempPoint1).length();
187
+ let _dist = _cos * _len * 2;
188
+ tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
189
+ if (sideOffset > 0) {
190
+ position.push(tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
191
+ right.x, right.y, right.z, // 5
192
+ left.x, left.y, left.z, // 4
193
+ right.x, right.y, right.z, // 3
194
+ tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
195
+ right.x, right.y, right.z // 1
196
+ );
197
+ verticesCount += 6;
198
+ indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 4, verticesCount - 6, verticesCount - 5, verticesCount - 2, verticesCount - 4, verticesCount - 1);
199
+ count += 12;
200
+ }
201
+ else {
202
+ position.push(left.x, left.y, left.z, // 6
203
+ tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
204
+ left.x, left.y, left.z, // 4
205
+ right.x, right.y, right.z, // 3
206
+ left.x, left.y, left.z, // 2
207
+ tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
208
+ );
209
+ verticesCount += 6;
210
+ indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 6, verticesCount - 5, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
211
+ count += 12;
212
+ }
213
+ normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
214
+ uv.push(uvDist - sharpUvOffset, 0, uvDist - sharpUvOffset, 1, uvDist, 0, uvDist, 1, uvDist + sharpUvOffset, 0, uvDist + sharpUvOffset, 1);
215
+ if (generateUv2) {
216
+ uv2.push(uvDist2 - sharpUvOffset2, 0, uvDist2 - sharpUvOffset2, 1, uvDist2, 0, uvDist2, 1, uvDist2 + sharpUvOffset2, 0, uvDist2 + sharpUvOffset2, 1);
217
+ }
218
+ }
219
+ else {
220
+ position.push(left.x, left.y, left.z, right.x, right.y, right.z);
221
+ normal.push(up.x, up.y, up.z, up.x, up.y, up.z);
222
+ uv.push(uvDist, 0, uvDist, 1);
223
+ if (generateUv2) {
224
+ uv2.push(uvDist2, 0, uvDist2, 1);
225
+ }
226
+ verticesCount += 2;
227
+ if (!first) {
228
+ indices.push(verticesCount - 2, verticesCount - 4, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
229
+ count += 6;
230
+ }
231
+ }
232
+ }
233
+ const sharp = new Vector3();
234
+ function addStart(pathPoint) {
235
+ const dir = pathPoint.dir;
236
+ const up = pathPoint.up;
237
+ const _right = pathPoint.right;
238
+ const uvDist = pathPoint.dist / sideWidth;
239
+ const uvDist2 = pathPoint.dist / totalDistance;
240
+ if (side !== 'left') {
241
+ right.copy(_right).multiplyScalar(halfWidth * 2);
242
+ }
243
+ else {
244
+ right.set(0, 0, 0);
245
+ }
246
+ if (side !== 'right') {
247
+ left.copy(_right).multiplyScalar(-halfWidth * 2);
248
+ }
249
+ else {
250
+ left.set(0, 0, 0);
251
+ }
252
+ sharp.copy(dir).setLength(halfWidth * 3);
253
+ right.add(pathPoint.pos);
254
+ left.add(pathPoint.pos);
255
+ sharp.add(pathPoint.pos);
256
+ position.push(left.x, left.y, left.z, right.x, right.y, right.z, sharp.x, sharp.y, sharp.z);
257
+ normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
258
+ uv.push(uvDist, side !== 'both' ? (side !== 'right' ? -2 : 0) : -0.5, uvDist, side !== 'both' ? (side !== 'left' ? 2 : 0) : 1.5, uvDist + 1.5, side !== 'both' ? 0 : 0.5);
259
+ if (generateUv2) {
260
+ uv2.push(uvDist2, side !== 'both' ? (side !== 'right' ? -2 : 0) : -0.5, uvDist2, side !== 'both' ? (side !== 'left' ? 2 : 0) : 1.5, uvDist2 + (1.5 * width) / totalDistance, side !== 'both' ? 0 : 0.5);
261
+ }
262
+ verticesCount += 3;
263
+ indices.push(verticesCount - 1, verticesCount - 3, verticesCount - 2);
264
+ count += 3;
265
+ }
266
+ let lastPoint;
267
+ if (progressDistance > 0) {
268
+ for (let i = 0; i < pathPointList.count; i++) {
269
+ const pathPoint = pathPointList.array[i];
270
+ if (pathPoint.dist > progressDistance) {
271
+ const prevPoint = pathPointList.array[i - 1];
272
+ lastPoint = new PathPoint();
273
+ // linear lerp for progress
274
+ const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
275
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
276
+ addVertices(lastPoint);
277
+ break;
278
+ }
279
+ else {
280
+ addVertices(pathPoint);
281
+ }
282
+ }
283
+ }
284
+ else {
285
+ lastPoint = pathPointList.array[0];
286
+ }
287
+ // build arrow geometry
288
+ if (arrow) {
289
+ lastPoint = lastPoint || pathPointList.array[pathPointList.count - 1];
290
+ addStart(lastPoint);
291
+ }
292
+ return {
293
+ position,
294
+ normal,
295
+ uv,
296
+ uv2,
297
+ indices,
298
+ count,
299
+ };
300
+ }
@@ -1,17 +1,17 @@
1
- import { Vector3 } from 'three/src/math/Vector3';
2
- /**
3
- * PathPoint
4
- */
5
- declare class PathPoint {
6
- pos: Vector3;
7
- dir: Vector3;
8
- right: Vector3;
9
- up: Vector3;
10
- dist: number;
11
- widthScale: number;
12
- sharp: boolean;
13
- constructor();
14
- lerpPathPoints(p1: PathPoint, p2: PathPoint, alpha: number): void;
15
- copy(source: PathPoint): void;
16
- }
17
- export { PathPoint };
1
+ import { Vector3 } from 'three/src/math/Vector3';
2
+ /**
3
+ * PathPoint
4
+ */
5
+ declare class PathPoint {
6
+ pos: Vector3;
7
+ dir: Vector3;
8
+ right: Vector3;
9
+ up: Vector3;
10
+ dist: number;
11
+ widthScale: number;
12
+ sharp: boolean;
13
+ constructor();
14
+ lerpPathPoints(p1: PathPoint, p2: PathPoint, alpha: number): void;
15
+ copy(source: PathPoint): void;
16
+ }
17
+ export { PathPoint };