viral-viewer-2 6.3.0 → 6.3.1

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 (143) hide show
  1. package/dist/index.mjs +1611 -1615
  2. package/dist/threejs-addon/n8ao/post-processing.d.ts +109 -109
  3. package/package.json +1 -1
  4. package/dist/components/animation/viral-animation.js +0 -71
  5. package/dist/components/animation/viral-animation.js.map +0 -1
  6. package/dist/components/bvh/viral-bvh.js +0 -19
  7. package/dist/components/bvh/viral-bvh.js.map +0 -1
  8. package/dist/components/camera/viral-camera.js +0 -207
  9. package/dist/components/camera/viral-camera.js.map +0 -1
  10. package/dist/components/compress/viral-compress.processor.js +0 -13
  11. package/dist/components/compress/viral-compress.processor.js.map +0 -1
  12. package/dist/components/custom-objects/index.js +0 -6
  13. package/dist/components/custom-objects/index.js.map +0 -1
  14. package/dist/components/custom-objects/viral-instanced-mesh.js +0 -203
  15. package/dist/components/custom-objects/viral-instanced-mesh.js.map +0 -1
  16. package/dist/components/custom-objects/viral-mesh.js +0 -25
  17. package/dist/components/custom-objects/viral-mesh.js.map +0 -1
  18. package/dist/components/data-manager/viral-data-manager.js +0 -35
  19. package/dist/components/data-manager/viral-data-manager.js.map +0 -1
  20. package/dist/components/event-handler/base/event-dispatcher.js +0 -35
  21. package/dist/components/event-handler/base/event-dispatcher.js.map +0 -1
  22. package/dist/components/event-handler/keyboard/viral-keyboard.js +0 -78
  23. package/dist/components/event-handler/keyboard/viral-keyboard.js.map +0 -1
  24. package/dist/components/event-handler/mouse/viral-mouse.js +0 -239
  25. package/dist/components/event-handler/mouse/viral-mouse.js.map +0 -1
  26. package/dist/components/event-handler/viral-centralized-event-handler.js +0 -186
  27. package/dist/components/event-handler/viral-centralized-event-handler.js.map +0 -1
  28. package/dist/components/event-handler/viral-lifecycle-event-handler.js +0 -55
  29. package/dist/components/event-handler/viral-lifecycle-event-handler.js.map +0 -1
  30. package/dist/components/loader/viral-point-cloud.loader.js +0 -33
  31. package/dist/components/loader/viral-point-cloud.loader.js.map +0 -1
  32. package/dist/components/loader/viral-revit.loader.js +0 -344
  33. package/dist/components/loader/viral-revit.loader.js.map +0 -1
  34. package/dist/components/loader/viral-three.loader.js +0 -20
  35. package/dist/components/loader/viral-three.loader.js.map +0 -1
  36. package/dist/components/loader/viral.loader.js +0 -16
  37. package/dist/components/loader/viral.loader.js.map +0 -1
  38. package/dist/components/material/viral-material-manager.js +0 -60
  39. package/dist/components/material/viral-material-manager.js.map +0 -1
  40. package/dist/components/post-processing/post-processing-renderer.js +0 -46
  41. package/dist/components/post-processing/post-processing-renderer.js.map +0 -1
  42. package/dist/components/renderer/viral-renderer.js +0 -55
  43. package/dist/components/renderer/viral-renderer.js.map +0 -1
  44. package/dist/components/scene/viral-scene.js +0 -131
  45. package/dist/components/scene/viral-scene.js.map +0 -1
  46. package/dist/components/stats/viral-stats.js +0 -17
  47. package/dist/components/stats/viral-stats.js.map +0 -1
  48. package/dist/components/visibility-manager/viral-visibility-manager.js +0 -175
  49. package/dist/components/visibility-manager/viral-visibility-manager.js.map +0 -1
  50. package/dist/components/worker/base/worker-pool.js +0 -68
  51. package/dist/components/worker/base/worker-pool.js.map +0 -1
  52. package/dist/components/worker/base/worker-thread.js +0 -35
  53. package/dist/components/worker/base/worker-thread.js.map +0 -1
  54. package/dist/components/worker/fetch-data.worker.js +0 -31
  55. package/dist/components/worker/fetch-data.worker.js.map +0 -1
  56. package/dist/components/worker/load-element-by-material-v2.worker.js +0 -80
  57. package/dist/components/worker/load-element-by-material-v2.worker.js.map +0 -1
  58. package/dist/components/worker/load-element-by-material.worker.js +0 -59
  59. package/dist/components/worker/load-element-by-material.worker.js.map +0 -1
  60. package/dist/components/worker/load-element-standalone.worker.js +0 -109
  61. package/dist/components/worker/load-element-standalone.worker.js.map +0 -1
  62. package/dist/components/worker/viral-viewer-2.worker.js +0 -127
  63. package/dist/components/worker/viral-viewer-2.worker.js.map +0 -1
  64. package/dist/components/worker/viral-viewer-3.worker.js +0 -82
  65. package/dist/components/worker/viral-viewer-3.worker.js.map +0 -1
  66. package/dist/components/worker/viral-viewer.worker.js +0 -107
  67. package/dist/components/worker/viral-viewer.worker.js.map +0 -1
  68. package/dist/components/worker-script/fetch-data-worker.script.js +0 -56
  69. package/dist/components/worker-script/fetch-data-worker.script.js.map +0 -1
  70. package/dist/components/worker-script/load-element-by-material.script.js +0 -131
  71. package/dist/components/worker-script/load-element-by-material.script.js.map +0 -1
  72. package/dist/components/worker-script/load-element-standalone.script.js +0 -34172
  73. package/dist/components/worker-script/load-element-standalone.script.js.map +0 -1
  74. package/dist/components/worker-script/load-model-worker-2.script.js +0 -2704
  75. package/dist/components/worker-script/load-model-worker-2.script.js.map +0 -1
  76. package/dist/components/worker-script/load-model-worker.script.js +0 -148
  77. package/dist/components/worker-script/load-model-worker.script.js.map +0 -1
  78. package/dist/components/worker-script/material-aproach/load-element-by-material-instanced-mesh.script.js +0 -34152
  79. package/dist/components/worker-script/material-aproach/load-element-by-material-instanced-mesh.script.js.map +0 -1
  80. package/dist/components/worker-script/material-aproach/load-element-by-material-mesh.script.js +0 -127
  81. package/dist/components/worker-script/material-aproach/load-element-by-material-mesh.script.js.map +0 -1
  82. package/dist/components/worker-script/threejs.types.js +0 -34162
  83. package/dist/components/worker-script/threejs.types.js.map +0 -1
  84. package/dist/const/colors.js +0 -39
  85. package/dist/const/colors.js.map +0 -1
  86. package/dist/const/fonts.js +0 -17
  87. package/dist/const/fonts.js.map +0 -1
  88. package/dist/const/icons.js +0 -11
  89. package/dist/const/icons.js.map +0 -1
  90. package/dist/gui/context-menu/viral-context-menu.js +0 -78
  91. package/dist/gui/context-menu/viral-context-menu.js.map +0 -1
  92. package/dist/gui/draggable-modal/viral-draggable-modal.js +0 -167
  93. package/dist/gui/draggable-modal/viral-draggable-modal.js.map +0 -1
  94. package/dist/gui/fonts/fonts.js +0 -20
  95. package/dist/gui/fonts/fonts.js.map +0 -1
  96. package/dist/gui/navigation-cube/components/cube-camera.js +0 -74
  97. package/dist/gui/navigation-cube/components/cube-camera.js.map +0 -1
  98. package/dist/gui/navigation-cube/components/cube-renderer.js +0 -31
  99. package/dist/gui/navigation-cube/components/cube-renderer.js.map +0 -1
  100. package/dist/gui/navigation-cube/components/cube-scene.js +0 -546
  101. package/dist/gui/navigation-cube/components/cube-scene.js.map +0 -1
  102. package/dist/gui/navigation-cube/components/cube.mouse.js +0 -109
  103. package/dist/gui/navigation-cube/components/cube.mouse.js.map +0 -1
  104. package/dist/gui/navigation-cube/viral-navigation-cube.js +0 -50
  105. package/dist/gui/navigation-cube/viral-navigation-cube.js.map +0 -1
  106. package/dist/gui/spinner/viral-spinner.js +0 -102
  107. package/dist/gui/spinner/viral-spinner.js.map +0 -1
  108. package/dist/gui/tools/tools/viral-tool-ambient-occlusion.js +0 -25
  109. package/dist/gui/tools/tools/viral-tool-ambient-occlusion.js.map +0 -1
  110. package/dist/gui/tools/tools/viral-tool-dark-mode.js +0 -21
  111. package/dist/gui/tools/tools/viral-tool-dark-mode.js.map +0 -1
  112. package/dist/gui/tools/tools/viral-tool-elevation.js +0 -30
  113. package/dist/gui/tools/tools/viral-tool-elevation.js.map +0 -1
  114. package/dist/gui/tools/tools/viral-tool-export-scene.js +0 -36
  115. package/dist/gui/tools/tools/viral-tool-export-scene.js.map +0 -1
  116. package/dist/gui/tools/tools/viral-tool-measure.js +0 -243
  117. package/dist/gui/tools/tools/viral-tool-measure.js.map +0 -1
  118. package/dist/gui/tools/tools/viral-tool-sunlight.js +0 -46
  119. package/dist/gui/tools/tools/viral-tool-sunlight.js.map +0 -1
  120. package/dist/gui/tools/viral-tools.js +0 -213
  121. package/dist/gui/tools/viral-tools.js.map +0 -1
  122. package/dist/index.js +0 -21
  123. package/dist/index.js.map +0 -1
  124. package/dist/services/local-storage.service.js +0 -57
  125. package/dist/services/local-storage.service.js.map +0 -1
  126. package/dist/threejs-addon/n8ao/n8ao.js +0 -1952
  127. package/dist/threejs-addon/n8ao/n8ao.js.map +0 -1
  128. package/dist/threejs-addon/n8ao/post-processing.js +0 -15145
  129. package/dist/threejs-addon/n8ao/post-processing.js.map +0 -1
  130. package/dist/threejs-addon/stats.js +0 -102
  131. package/dist/threejs-addon/stats.js.map +0 -1
  132. package/dist/types.js +0 -173
  133. package/dist/types.js.map +0 -1
  134. package/dist/utils/html.js +0 -12
  135. package/dist/utils/html.js.map +0 -1
  136. package/dist/utils/index.js +0 -10
  137. package/dist/utils/index.js.map +0 -1
  138. package/dist/utils/log.js +0 -14
  139. package/dist/utils/log.js.map +0 -1
  140. package/dist/utils/threejs.js +0 -44
  141. package/dist/utils/threejs.js.map +0 -1
  142. package/dist/viral-viewer-api.js +0 -76
  143. package/dist/viral-viewer-api.js.map +0 -1
@@ -1,2704 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.workerCode = void 0;
4
- function workerFunction() {
5
- function addMesh(indices, vertices, transform = null, callback = (buffer) => { }) {
6
- let verticePoints = [];
7
- if (transform == null) {
8
- for (let i = 0; i < indices.length; i++) {
9
- const index = indices[i];
10
- const point = vertices[index];
11
- verticePoints.push(-point.X);
12
- verticePoints.push(point.Z);
13
- verticePoints.push(point.Y);
14
- }
15
- const buffer = new Float32Array(verticePoints);
16
- callback(buffer);
17
- return;
18
- }
19
- let numbers = [
20
- transform.BasisX.X,
21
- -transform.BasisX.Z,
22
- -transform.BasisX.Y,
23
- 0,
24
- -transform.BasisZ.X,
25
- transform.BasisZ.Z,
26
- transform.BasisZ.Y,
27
- 0,
28
- -transform.BasisY.X,
29
- transform.BasisY.Z,
30
- transform.BasisY.Y,
31
- 0,
32
- -transform.Offset.X,
33
- transform.Offset.Z,
34
- transform.Offset.Y,
35
- 1,
36
- ];
37
- //transform first
38
- let matrix4 = new Matrix4();
39
- matrix4.fromArray(numbers);
40
- let newVertices = [];
41
- for (let i = 0; i < vertices.length; i++) {
42
- const point = vertices[i];
43
- const point2 = new Vector3(-point.X, point.Z, point.Y);
44
- point2.applyMatrix4(matrix4);
45
- newVertices.push(point2);
46
- }
47
- for (let i = 0; i < indices.length; i++) {
48
- const index = indices[i];
49
- const point = newVertices[index];
50
- verticePoints.push(point.x);
51
- verticePoints.push(point.y);
52
- verticePoints.push(point.z);
53
- }
54
- const buffer = new Float32Array(verticePoints);
55
- callback(buffer);
56
- }
57
- function progressGeometries(json, callback = (buffer) => { }) {
58
- addMesh(json.Indices, json.Vertices, json.Transform, (buffer) => {
59
- callback(buffer);
60
- });
61
- }
62
- self.addEventListener("message", (event) => {
63
- progressGeometries(event.data, (buffer) => {
64
- self.postMessage({
65
- buffer: buffer
66
- });
67
- });
68
- }, false);
69
- //#region Threejs Types
70
- const StaticDrawUsage = 35044;
71
- class EventDispatcher {
72
- constructor() {
73
- this._listeners = {};
74
- }
75
- addEventListener(type, listener) {
76
- if (this._listeners[type] === undefined)
77
- this._listeners[type] = [];
78
- const listeners = this._listeners[type];
79
- if (listeners.indexOf(listener) === -1) {
80
- listeners.push(listener);
81
- }
82
- }
83
- hasEventListener(type, listener) {
84
- if (this._listeners[type] === undefined)
85
- return false;
86
- const listeners = this._listeners[type];
87
- return listeners !== undefined && listeners.indexOf(listener) !== -1;
88
- }
89
- removeEventListener(type, listener) {
90
- if (this._listeners[type] === undefined)
91
- return;
92
- const listeners = this._listeners[type];
93
- if (listeners !== undefined) {
94
- const index = listeners.indexOf(listener);
95
- if (index !== -1) {
96
- listeners.splice(index, 1);
97
- }
98
- }
99
- }
100
- dispatchEvent(event) {
101
- if (this._listeners[event.type] === undefined)
102
- return;
103
- const listeners = this._listeners[event.type];
104
- if (listeners !== undefined) {
105
- event.target = this;
106
- // Make a copy, in case listeners are removed while iterating.
107
- const array = listeners.slice(0);
108
- for (let i = 0, l = array.length; i < l; i++) {
109
- array[i].call(this, event);
110
- }
111
- event.target = undefined;
112
- }
113
- }
114
- }
115
- const _lut = [];
116
- for (let i = 0; i < 256; i++) {
117
- _lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
118
- }
119
- const DEG2RAD = Math.PI / 180;
120
- const RAD2DEG = 180 / Math.PI;
121
- const generateUUID = () => {
122
- const d0 = Math.random() * 0xffffffff | 0;
123
- const d1 = Math.random() * 0xffffffff | 0;
124
- const d2 = Math.random() * 0xffffffff | 0;
125
- const d3 = Math.random() * 0xffffffff | 0;
126
- const uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' +
127
- _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' +
128
- _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] +
129
- _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff];
130
- // .toUpperCase() here flattens concatenated strings to save heap memory space.
131
- return uuid.toUpperCase();
132
- };
133
- function clamp(value, min, max) {
134
- return Math.max(min, Math.min(max, value));
135
- }
136
- // Compute euclidean modulo of n % m
137
- // https://en.wikipedia.org/wiki/Modulo_operation
138
- function euclideanModulo(n, m) {
139
- return ((n % m) + m) % m;
140
- }
141
- // https://en.wikipedia.org/wiki/Linear_interpolation
142
- function lerp(x, y, t) {
143
- return (1 - t) * x + t * y;
144
- }
145
- function isPowerOfTwo(value) {
146
- return (value & (value - 1)) === 0 && value !== 0;
147
- }
148
- function floorPowerOfTwo(value) {
149
- return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
150
- }
151
- //#region Color
152
- const _colorKeywords = {
153
- 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
154
- 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
155
- 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
156
- 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
157
- 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
158
- 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
159
- 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
160
- 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
161
- 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
162
- 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
163
- 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
164
- 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
165
- 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
166
- 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
167
- 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
168
- 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
169
- 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
170
- 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
171
- 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
172
- 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
173
- 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
174
- 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
175
- 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
176
- 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32
177
- };
178
- const _hslA = { h: 0, s: 0, l: 0 };
179
- const _hslB = { h: 0, s: 0, l: 0 };
180
- function hue2rgb(p, q, t) {
181
- if (t < 0)
182
- t += 1;
183
- if (t > 1)
184
- t -= 1;
185
- if (t < 1 / 6)
186
- return p + (q - p) * 6 * t;
187
- if (t < 1 / 2)
188
- return q;
189
- if (t < 2 / 3)
190
- return p + (q - p) * 6 * (2 / 3 - t);
191
- return p;
192
- }
193
- function SRGBToLinear(c) {
194
- return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
195
- }
196
- function LinearToSRGB(c) {
197
- return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
198
- }
199
- class Color {
200
- constructor(r, g, b) {
201
- this.r = 0;
202
- this.g = 0;
203
- this.b = 0;
204
- if (g === undefined && b === undefined) {
205
- // r is THREE.Color, hex, or string
206
- return this.set(r);
207
- }
208
- return this.setRGB(r, g, b);
209
- }
210
- set(value) {
211
- if (value && value.isColor) {
212
- this.copy(value);
213
- }
214
- else if (typeof value === 'number') {
215
- this.setHex(value);
216
- }
217
- else if (typeof value === 'string') {
218
- this.setStyle(value);
219
- }
220
- return this;
221
- }
222
- setScalar(scalar) {
223
- this.r = scalar;
224
- this.g = scalar;
225
- this.b = scalar;
226
- return this;
227
- }
228
- setHex(hex) {
229
- hex = Math.floor(hex);
230
- this.r = ((hex >> 16) & 255) / 255;
231
- this.g = ((hex >> 8) & 255) / 255;
232
- this.b = (hex & 255) / 255;
233
- return this;
234
- }
235
- setRGB(r, g, b) {
236
- this.r = r;
237
- this.g = g;
238
- this.b = b;
239
- return this;
240
- }
241
- setHSL(h, s, l) {
242
- // h, s, l ranges are in 0.0 - 1.0
243
- h = euclideanModulo(h, 1);
244
- s = clamp(s, 0, 1);
245
- l = clamp(l, 0, 1);
246
- if (s === 0) {
247
- this.r = this.g = this.b = l;
248
- }
249
- else {
250
- const p = l <= 0.5 ? l * (1 + s) : l + s - (l * s);
251
- const q = 2 * l - p;
252
- this.r = hue2rgb(q, p, h + 1 / 3);
253
- this.g = hue2rgb(q, p, h);
254
- this.b = hue2rgb(q, p, h - 1 / 3);
255
- }
256
- return this;
257
- }
258
- setStyle(style) {
259
- function handleAlpha(string) {
260
- if (string === undefined)
261
- return;
262
- if (parseFloat(string) < 1) {
263
- console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
264
- }
265
- }
266
- let m;
267
- if ((m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style))) {
268
- // rgb / hsl
269
- let color;
270
- const name = m[1];
271
- const components = m[2];
272
- switch (name) {
273
- case 'rgb':
274
- case 'rgba':
275
- if ((color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
276
- // rgb(255,0,0) rgba(255,0,0,0.5)
277
- this.r = Math.min(255, parseInt(color[1], 10)) / 255;
278
- this.g = Math.min(255, parseInt(color[2], 10)) / 255;
279
- this.b = Math.min(255, parseInt(color[3], 10)) / 255;
280
- handleAlpha(color[4]);
281
- return this;
282
- }
283
- if ((color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
284
- // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
285
- this.r = Math.min(100, parseInt(color[1], 10)) / 100;
286
- this.g = Math.min(100, parseInt(color[2], 10)) / 100;
287
- this.b = Math.min(100, parseInt(color[3], 10)) / 100;
288
- handleAlpha(color[4]);
289
- return this;
290
- }
291
- break;
292
- case 'hsl':
293
- case 'hsla':
294
- if ((color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
295
- // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
296
- const h = parseFloat(color[1]) / 360;
297
- const s = parseInt(color[2], 10) / 100;
298
- const l = parseInt(color[3], 10) / 100;
299
- handleAlpha(color[4]);
300
- return this.setHSL(h, s, l);
301
- }
302
- break;
303
- }
304
- }
305
- else if ((m = /^\#([A-Fa-f\d]+)$/.exec(style))) {
306
- // hex color
307
- const hex = m[1];
308
- const size = hex.length;
309
- if (size === 3) {
310
- // #ff0
311
- this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
312
- this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
313
- this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
314
- return this;
315
- }
316
- else if (size === 6) {
317
- // #ff0000
318
- this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
319
- this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
320
- this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
321
- return this;
322
- }
323
- }
324
- if (style && style.length > 0) {
325
- return this.setColorName(style);
326
- }
327
- return this;
328
- }
329
- setColorName(style) {
330
- // color keywords
331
- let key = style.toLowerCase();
332
- const hex = _colorKeywords[key];
333
- if (hex !== undefined) {
334
- // red
335
- this.setHex(hex);
336
- }
337
- else {
338
- // unknown color
339
- console.warn('THREE.Color: Unknown color ' + style);
340
- }
341
- return this;
342
- }
343
- clone() {
344
- return new Color(this.r, this.g, this.b);
345
- }
346
- copy(color) {
347
- this.r = color.r;
348
- this.g = color.g;
349
- this.b = color.b;
350
- return this;
351
- }
352
- copyGammaToLinear(color, gammaFactor = 2.0) {
353
- this.r = Math.pow(color.r, gammaFactor);
354
- this.g = Math.pow(color.g, gammaFactor);
355
- this.b = Math.pow(color.b, gammaFactor);
356
- return this;
357
- }
358
- copyLinearToGamma(color, gammaFactor = 2.0) {
359
- const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
360
- this.r = Math.pow(color.r, safeInverse);
361
- this.g = Math.pow(color.g, safeInverse);
362
- this.b = Math.pow(color.b, safeInverse);
363
- return this;
364
- }
365
- convertGammaToLinear(gammaFactor) {
366
- this.copyGammaToLinear(this, gammaFactor);
367
- return this;
368
- }
369
- convertLinearToGamma(gammaFactor) {
370
- this.copyLinearToGamma(this, gammaFactor);
371
- return this;
372
- }
373
- copySRGBToLinear(color) {
374
- this.r = SRGBToLinear(color.r);
375
- this.g = SRGBToLinear(color.g);
376
- this.b = SRGBToLinear(color.b);
377
- return this;
378
- }
379
- copyLinearToSRGB(color) {
380
- this.r = LinearToSRGB(color.r);
381
- this.g = LinearToSRGB(color.g);
382
- this.b = LinearToSRGB(color.b);
383
- return this;
384
- }
385
- convertSRGBToLinear() {
386
- this.copySRGBToLinear(this);
387
- return this;
388
- }
389
- convertLinearToSRGB() {
390
- this.copyLinearToSRGB(this);
391
- return this;
392
- }
393
- getHex() {
394
- return (this.r * 255) << 16 ^ (this.g * 255) << 8 ^ (this.b * 255) << 0;
395
- }
396
- getHexString() {
397
- return ('000000' + this.getHex().toString(16)).slice(-6);
398
- }
399
- getHSL(target) {
400
- const r = this.r, g = this.g, b = this.b;
401
- const max = Math.max(r, g, b);
402
- const min = Math.min(r, g, b);
403
- let hue = 0, saturation = 0;
404
- const lightness = (min + max) / 2.0;
405
- if (min === max) {
406
- hue = 0;
407
- saturation = 0;
408
- }
409
- else {
410
- const delta = max - min;
411
- saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
412
- switch (max) {
413
- case r:
414
- hue = (g - b) / delta + (g < b ? 6 : 0);
415
- break;
416
- case g:
417
- hue = (b - r) / delta + 2;
418
- break;
419
- case b:
420
- hue = (r - g) / delta + 4;
421
- break;
422
- }
423
- hue /= 6;
424
- }
425
- target.h = hue;
426
- target.s = saturation;
427
- target.l = lightness;
428
- return target;
429
- }
430
- getStyle() {
431
- return 'rgb(' + (this.r * 255) + ',' + (this.g * 255) + ',' + (this.b * 255) + ')';
432
- }
433
- offsetHSL(h, s, l) {
434
- this.getHSL(_hslA);
435
- _hslA.h += h;
436
- _hslA.s += s;
437
- _hslA.l += l;
438
- this.setHSL(_hslA.h, _hslA.s, _hslA.l);
439
- return this;
440
- }
441
- add(color) {
442
- this.r += color.r;
443
- this.g += color.g;
444
- this.b += color.b;
445
- return this;
446
- }
447
- addColors(color1, color2) {
448
- this.r = color1.r + color2.r;
449
- this.g = color1.g + color2.g;
450
- this.b = color1.b + color2.b;
451
- return this;
452
- }
453
- addScalar(s) {
454
- this.r += s;
455
- this.g += s;
456
- this.b += s;
457
- return this;
458
- }
459
- sub(color) {
460
- this.r = Math.max(0, this.r - color.r);
461
- this.g = Math.max(0, this.g - color.g);
462
- this.b = Math.max(0, this.b - color.b);
463
- return this;
464
- }
465
- multiply(color) {
466
- this.r *= color.r;
467
- this.g *= color.g;
468
- this.b *= color.b;
469
- return this;
470
- }
471
- multiplyScalar(s) {
472
- this.r *= s;
473
- this.g *= s;
474
- this.b *= s;
475
- return this;
476
- }
477
- lerp(color, alpha) {
478
- this.r += (color.r - this.r) * alpha;
479
- this.g += (color.g - this.g) * alpha;
480
- this.b += (color.b - this.b) * alpha;
481
- return this;
482
- }
483
- lerpColors(color1, color2, alpha) {
484
- this.r = color1.r + (color2.r - color1.r) * alpha;
485
- this.g = color1.g + (color2.g - color1.g) * alpha;
486
- this.b = color1.b + (color2.b - color1.b) * alpha;
487
- return this;
488
- }
489
- lerpHSL(color, alpha) {
490
- this.getHSL(_hslA);
491
- color.getHSL(_hslB);
492
- const h = lerp(_hslA.h, _hslB.h, alpha);
493
- const s = lerp(_hslA.s, _hslB.s, alpha);
494
- const l = lerp(_hslA.l, _hslB.l, alpha);
495
- this.setHSL(h, s, l);
496
- return this;
497
- }
498
- equals(c) {
499
- return c.r === this.r && c.g === this.g && c.b === this.b;
500
- }
501
- fromArray(array, offset = 0) {
502
- this.r = array[offset];
503
- this.g = array[offset + 1];
504
- this.b = array[offset + 2];
505
- return this;
506
- }
507
- toArray(array = [], offset = 0) {
508
- array[offset] = this.r;
509
- array[offset + 1] = this.g;
510
- array[offset + 2] = this.b;
511
- return array;
512
- }
513
- fromBufferAttribute(attribute, index) {
514
- this.r = attribute.getX(index);
515
- this.g = attribute.getY(index);
516
- this.b = attribute.getZ(index);
517
- if (attribute.normalized === true) {
518
- // assuming Uint8Array
519
- this.r /= 255;
520
- this.g /= 255;
521
- this.b /= 255;
522
- }
523
- return this;
524
- }
525
- toJSON() {
526
- return this.getHex();
527
- }
528
- }
529
- //#endregion
530
- //#region Base Unit
531
- class Vector2 {
532
- constructor(x = 0, y = 0) {
533
- this.x = x;
534
- this.y = y;
535
- }
536
- get width() {
537
- return this.x;
538
- }
539
- set width(value) {
540
- this.x = value;
541
- }
542
- get height() {
543
- return this.y;
544
- }
545
- set height(value) {
546
- this.y = value;
547
- }
548
- set(x, y) {
549
- this.x = x;
550
- this.y = y;
551
- return this;
552
- }
553
- setScalar(scalar) {
554
- this.x = scalar;
555
- this.y = scalar;
556
- return this;
557
- }
558
- setX(x) {
559
- this.x = x;
560
- return this;
561
- }
562
- setY(y) {
563
- this.y = y;
564
- return this;
565
- }
566
- setComponent(index, value) {
567
- switch (index) {
568
- case 0:
569
- this.x = value;
570
- break;
571
- case 1:
572
- this.y = value;
573
- break;
574
- default:
575
- throw new Error('index is out of range: ' + index);
576
- }
577
- return this;
578
- }
579
- getComponent(index) {
580
- switch (index) {
581
- case 0:
582
- return this.x;
583
- case 1:
584
- return this.y;
585
- default:
586
- throw new Error('index is out of range: ' + index);
587
- }
588
- }
589
- clone() {
590
- return new this.constructor(this.x, this.y);
591
- }
592
- copy(v) {
593
- this.x = v.x;
594
- this.y = v.y;
595
- return this;
596
- }
597
- add(v, w) {
598
- if (w !== undefined) {
599
- console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
600
- return this.addVectors(v, w);
601
- }
602
- this.x += v.x;
603
- this.y += v.y;
604
- return this;
605
- }
606
- addScalar(s) {
607
- this.x += s;
608
- this.y += s;
609
- return this;
610
- }
611
- addVectors(a, b) {
612
- this.x = a.x + b.x;
613
- this.y = a.y + b.y;
614
- return this;
615
- }
616
- addScaledVector(v, s) {
617
- this.x += v.x * s;
618
- this.y += v.y * s;
619
- return this;
620
- }
621
- sub(v, w) {
622
- if (w !== undefined) {
623
- console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
624
- return this.subVectors(v, w);
625
- }
626
- this.x -= v.x;
627
- this.y -= v.y;
628
- return this;
629
- }
630
- subScalar(s) {
631
- this.x -= s;
632
- this.y -= s;
633
- return this;
634
- }
635
- subVectors(a, b) {
636
- this.x = a.x - b.x;
637
- this.y = a.y - b.y;
638
- return this;
639
- }
640
- multiply(v) {
641
- this.x *= v.x;
642
- this.y *= v.y;
643
- return this;
644
- }
645
- multiplyScalar(scalar) {
646
- this.x *= scalar;
647
- this.y *= scalar;
648
- return this;
649
- }
650
- divide(v) {
651
- this.x /= v.x;
652
- this.y /= v.y;
653
- return this;
654
- }
655
- divideScalar(scalar) {
656
- return this.multiplyScalar(1 / scalar);
657
- }
658
- applyMatrix3(m) {
659
- const x = this.x, y = this.y;
660
- const e = m.elements;
661
- this.x = e[0] * x + e[3] * y + e[6];
662
- this.y = e[1] * x + e[4] * y + e[7];
663
- return this;
664
- }
665
- min(v) {
666
- this.x = Math.min(this.x, v.x);
667
- this.y = Math.min(this.y, v.y);
668
- return this;
669
- }
670
- max(v) {
671
- this.x = Math.max(this.x, v.x);
672
- this.y = Math.max(this.y, v.y);
673
- return this;
674
- }
675
- clamp(min, max) {
676
- // assumes min < max, componentwise
677
- this.x = Math.max(min.x, Math.min(max.x, this.x));
678
- this.y = Math.max(min.y, Math.min(max.y, this.y));
679
- return this;
680
- }
681
- clampScalar(minVal, maxVal) {
682
- this.x = Math.max(minVal, Math.min(maxVal, this.x));
683
- this.y = Math.max(minVal, Math.min(maxVal, this.y));
684
- return this;
685
- }
686
- clampLength(min, max) {
687
- const length = this.length();
688
- return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
689
- }
690
- floor() {
691
- this.x = Math.floor(this.x);
692
- this.y = Math.floor(this.y);
693
- return this;
694
- }
695
- ceil() {
696
- this.x = Math.ceil(this.x);
697
- this.y = Math.ceil(this.y);
698
- return this;
699
- }
700
- round() {
701
- this.x = Math.round(this.x);
702
- this.y = Math.round(this.y);
703
- return this;
704
- }
705
- roundToZero() {
706
- this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
707
- this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
708
- return this;
709
- }
710
- negate() {
711
- this.x = -this.x;
712
- this.y = -this.y;
713
- return this;
714
- }
715
- dot(v) {
716
- return this.x * v.x + this.y * v.y;
717
- }
718
- cross(v) {
719
- return this.x * v.y - this.y * v.x;
720
- }
721
- lengthSq() {
722
- return this.x * this.x + this.y * this.y;
723
- }
724
- length() {
725
- return Math.sqrt(this.x * this.x + this.y * this.y);
726
- }
727
- manhattanLength() {
728
- return Math.abs(this.x) + Math.abs(this.y);
729
- }
730
- normalize() {
731
- return this.divideScalar(this.length() || 1);
732
- }
733
- angle() {
734
- // computes the angle in radians with respect to the positive x-axis
735
- const angle = Math.atan2(-this.y, -this.x) + Math.PI;
736
- return angle;
737
- }
738
- distanceTo(v) {
739
- return Math.sqrt(this.distanceToSquared(v));
740
- }
741
- distanceToSquared(v) {
742
- const dx = this.x - v.x, dy = this.y - v.y;
743
- return dx * dx + dy * dy;
744
- }
745
- manhattanDistanceTo(v) {
746
- return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
747
- }
748
- setLength(length) {
749
- return this.normalize().multiplyScalar(length);
750
- }
751
- lerp(v, alpha) {
752
- this.x += (v.x - this.x) * alpha;
753
- this.y += (v.y - this.y) * alpha;
754
- return this;
755
- }
756
- lerpVectors(v1, v2, alpha) {
757
- this.x = v1.x + (v2.x - v1.x) * alpha;
758
- this.y = v1.y + (v2.y - v1.y) * alpha;
759
- return this;
760
- }
761
- equals(v) {
762
- return v.x === this.x && v.y === this.y;
763
- }
764
- fromArray(array, offset = 0) {
765
- this.x = array[offset];
766
- this.y = array[offset + 1];
767
- return this;
768
- }
769
- toArray(array = [], offset = 0) {
770
- array[offset] = this.x;
771
- array[offset + 1] = this.y;
772
- return array;
773
- }
774
- fromBufferAttribute(attribute, index, offset) {
775
- if (offset !== undefined) {
776
- console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
777
- }
778
- this.x = attribute.getX(index);
779
- this.y = attribute.getY(index);
780
- return this;
781
- }
782
- rotateAround(center, angle) {
783
- const c = Math.cos(angle), s = Math.sin(angle);
784
- const x = this.x - center.x;
785
- const y = this.y - center.y;
786
- this.x = x * c - y * s + center.x;
787
- this.y = x * s + y * c + center.y;
788
- return this;
789
- }
790
- random() {
791
- this.x = Math.random();
792
- this.y = Math.random();
793
- return this;
794
- }
795
- *[Symbol.iterator]() {
796
- yield this.x;
797
- yield this.y;
798
- }
799
- }
800
- class Vector3 {
801
- constructor(x = 0, y = 0, z = 0) {
802
- this.x = x;
803
- this.y = y;
804
- this.z = z;
805
- }
806
- set(x, y, z) {
807
- if (z === undefined)
808
- z = this.z; // sprite.scale.set(x, y)
809
- this.x = x;
810
- this.y = y;
811
- this.z = z;
812
- return this;
813
- }
814
- setScalar(scalar) {
815
- this.x = scalar;
816
- this.y = scalar;
817
- this.z = scalar;
818
- return this;
819
- }
820
- setX(x) {
821
- this.x = x;
822
- return this;
823
- }
824
- setY(y) {
825
- this.y = y;
826
- return this;
827
- }
828
- setZ(z) {
829
- this.z = z;
830
- return this;
831
- }
832
- setComponent(index, value) {
833
- switch (index) {
834
- case 0:
835
- this.x = value;
836
- break;
837
- case 1:
838
- this.y = value;
839
- break;
840
- case 2:
841
- this.z = value;
842
- break;
843
- default:
844
- throw new Error('index is out of range: ' + index);
845
- }
846
- return this;
847
- }
848
- getComponent(index) {
849
- switch (index) {
850
- case 0:
851
- return this.x;
852
- case 1:
853
- return this.y;
854
- case 2:
855
- return this.z;
856
- default:
857
- throw new Error('index is out of range: ' + index);
858
- }
859
- }
860
- clone() {
861
- return new Vector3(this.x, this.y, this.z);
862
- }
863
- copy(v) {
864
- this.x = v.x;
865
- this.y = v.y;
866
- this.z = v.z;
867
- return this;
868
- }
869
- add(v, w) {
870
- if (w !== undefined) {
871
- console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
872
- return this.addVectors(v, w);
873
- }
874
- this.x += v.x;
875
- this.y += v.y;
876
- this.z += v.z;
877
- return this;
878
- }
879
- addScalar(s) {
880
- this.x += s;
881
- this.y += s;
882
- this.z += s;
883
- return this;
884
- }
885
- addVectors(a, b) {
886
- this.x = a.x + b.x;
887
- this.y = a.y + b.y;
888
- this.z = a.z + b.z;
889
- return this;
890
- }
891
- addScaledVector(v, s) {
892
- this.x += v.x * s;
893
- this.y += v.y * s;
894
- this.z += v.z * s;
895
- return this;
896
- }
897
- sub(v, w) {
898
- if (w !== undefined) {
899
- console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
900
- return this.subVectors(v, w);
901
- }
902
- this.x -= v.x;
903
- this.y -= v.y;
904
- this.z -= v.z;
905
- return this;
906
- }
907
- subScalar(s) {
908
- this.x -= s;
909
- this.y -= s;
910
- this.z -= s;
911
- return this;
912
- }
913
- subVectors(a, b) {
914
- this.x = a.x - b.x;
915
- this.y = a.y - b.y;
916
- this.z = a.z - b.z;
917
- return this;
918
- }
919
- multiply(v, w) {
920
- if (w !== undefined) {
921
- console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
922
- return this.multiplyVectors(v, w);
923
- }
924
- this.x *= v.x;
925
- this.y *= v.y;
926
- this.z *= v.z;
927
- return this;
928
- }
929
- multiplyScalar(scalar) {
930
- this.x *= scalar;
931
- this.y *= scalar;
932
- this.z *= scalar;
933
- return this;
934
- }
935
- multiplyVectors(a, b) {
936
- this.x = a.x * b.x;
937
- this.y = a.y * b.y;
938
- this.z = a.z * b.z;
939
- return this;
940
- }
941
- applyMatrix3(m) {
942
- const x = this.x, y = this.y;
943
- const e = m.elements;
944
- this.x = e[0] * x + e[3] * y + e[6];
945
- this.y = e[1] * x + e[4] * y + e[7];
946
- return this;
947
- }
948
- applyMatrix4(m) {
949
- const x = this.x;
950
- const y = this.y;
951
- const z = this.z;
952
- const e = m.elements;
953
- const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
954
- this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
955
- this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
956
- this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
957
- return this;
958
- }
959
- setFromMatrix3Column(m, index) {
960
- return this.fromArray(m.elements, index * 3);
961
- }
962
- fromArray(array, offset = 0) {
963
- this.x = array[offset];
964
- this.y = array[offset + 1];
965
- this.z = array[offset + 2];
966
- return this;
967
- }
968
- toArray(array = [], offset = 0) {
969
- array[offset] = this.x;
970
- array[offset + 1] = this.y;
971
- array[offset + 2] = this.z;
972
- return array;
973
- }
974
- fromBufferAttribute(attribute, index, offset) {
975
- if (offset !== undefined) {
976
- console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
977
- }
978
- this.x = attribute.getX(index);
979
- this.y = attribute.getY(index);
980
- this.z = attribute.getZ(index);
981
- return this;
982
- }
983
- applyNormalMatrix(m) {
984
- this.applyMatrix3(m);
985
- this.normalize();
986
- return this;
987
- }
988
- normalize() {
989
- const length = this.length() || 1;
990
- return this.divideScalar(length);
991
- }
992
- length() {
993
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
994
- }
995
- divideScalar(scalar) {
996
- return this.multiplyScalar(1 / scalar);
997
- }
998
- transformDirection(m) {
999
- const x = this.x, y = this.y, z = this.z;
1000
- const e = m.elements;
1001
- this.x = e[0] * x + e[4] * y + e[8] * z;
1002
- this.y = e[1] * x + e[5] * y + e[9] * z;
1003
- this.z = e[2] * x + e[6] * y + e[10] * z;
1004
- return this.normalize();
1005
- }
1006
- min(v) {
1007
- this.x = Math.min(this.x, v.x);
1008
- this.y = Math.min(this.y, v.y);
1009
- this.z = Math.min(this.z, v.z);
1010
- return this;
1011
- }
1012
- max(v) {
1013
- this.x = Math.max(this.x, v.x);
1014
- this.y = Math.max(this.y, v.y);
1015
- this.z = Math.max(this.z, v.z);
1016
- return this;
1017
- }
1018
- dot(v) {
1019
- return this.x * v.x + this.y * v.y + this.z * v.z;
1020
- }
1021
- distanceToSquared(v) {
1022
- const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1023
- return dx * dx + dy * dy + dz * dz;
1024
- }
1025
- distanceTo(v) {
1026
- return Math.sqrt(this.distanceToSquared(v));
1027
- }
1028
- lengthSq() {
1029
- return this.x * this.x + this.y * this.y + this.z * this.z;
1030
- }
1031
- equals(v) {
1032
- return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z));
1033
- }
1034
- negate() {
1035
- this.x = -this.x;
1036
- this.y = -this.y;
1037
- this.z = -this.z;
1038
- return this;
1039
- }
1040
- cross(v, w) {
1041
- if (w !== undefined) {
1042
- console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
1043
- return this.crossVectors(v, w);
1044
- }
1045
- return this.crossVectors(this, v);
1046
- }
1047
- crossVectors(a, b) {
1048
- const ax = a.x, ay = a.y, az = a.z;
1049
- const bx = b.x, by = b.y, bz = b.z;
1050
- this.x = ay * bz - az * by;
1051
- this.y = az * bx - ax * bz;
1052
- this.z = ax * by - ay * bx;
1053
- return this;
1054
- }
1055
- clamp(min, max) {
1056
- // assumes min < max, componentwise
1057
- this.x = Math.max(min.x, Math.min(max.x, this.x));
1058
- this.y = Math.max(min.y, Math.min(max.y, this.y));
1059
- this.z = Math.max(min.z, Math.min(max.z, this.z));
1060
- return this;
1061
- }
1062
- }
1063
- class Vector4 {
1064
- constructor(x = 0, y = 0, z = 0, w = 1) {
1065
- this.x = x;
1066
- this.y = y;
1067
- this.z = z;
1068
- this.w = w;
1069
- }
1070
- get width() {
1071
- return this.z;
1072
- }
1073
- set width(value) {
1074
- this.z = value;
1075
- }
1076
- get height() {
1077
- return this.w;
1078
- }
1079
- set height(value) {
1080
- this.w = value;
1081
- }
1082
- set(x, y, z, w) {
1083
- this.x = x;
1084
- this.y = y;
1085
- this.z = z;
1086
- this.w = w;
1087
- return this;
1088
- }
1089
- setScalar(scalar) {
1090
- this.x = scalar;
1091
- this.y = scalar;
1092
- this.z = scalar;
1093
- this.w = scalar;
1094
- return this;
1095
- }
1096
- setX(x) {
1097
- this.x = x;
1098
- return this;
1099
- }
1100
- setY(y) {
1101
- this.y = y;
1102
- return this;
1103
- }
1104
- setZ(z) {
1105
- this.z = z;
1106
- return this;
1107
- }
1108
- setW(w) {
1109
- this.w = w;
1110
- return this;
1111
- }
1112
- setComponent(index, value) {
1113
- switch (index) {
1114
- case 0:
1115
- this.x = value;
1116
- break;
1117
- case 1:
1118
- this.y = value;
1119
- break;
1120
- case 2:
1121
- this.z = value;
1122
- break;
1123
- case 3:
1124
- this.w = value;
1125
- break;
1126
- default:
1127
- throw new Error('index is out of range: ' + index);
1128
- }
1129
- return this;
1130
- }
1131
- getComponent(index) {
1132
- switch (index) {
1133
- case 0:
1134
- return this.x;
1135
- case 1:
1136
- return this.y;
1137
- case 2:
1138
- return this.z;
1139
- case 3:
1140
- return this.w;
1141
- default:
1142
- throw new Error('index is out of range: ' + index);
1143
- }
1144
- }
1145
- clone() {
1146
- return new this.constructor(this.x, this.y, this.z, this.w);
1147
- }
1148
- copy(v) {
1149
- this.x = v.x;
1150
- this.y = v.y;
1151
- this.z = v.z;
1152
- this.w = v.w !== undefined ? v.w : 1;
1153
- return this;
1154
- }
1155
- add(v, w) {
1156
- if (w !== undefined) {
1157
- console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
1158
- return this.addVectors(v, w);
1159
- }
1160
- this.x += v.x;
1161
- this.y += v.y;
1162
- this.z += v.z;
1163
- this.w += v.w;
1164
- return this;
1165
- }
1166
- addScalar(s) {
1167
- this.x += s;
1168
- this.y += s;
1169
- this.z += s;
1170
- this.w += s;
1171
- return this;
1172
- }
1173
- addVectors(a, b) {
1174
- this.x = a.x + b.x;
1175
- this.y = a.y + b.y;
1176
- this.z = a.z + b.z;
1177
- this.w = a.w + b.w;
1178
- return this;
1179
- }
1180
- addScaledVector(v, s) {
1181
- this.x += v.x * s;
1182
- this.y += v.y * s;
1183
- this.z += v.z * s;
1184
- this.w += v.w * s;
1185
- return this;
1186
- }
1187
- sub(v, w) {
1188
- if (w !== undefined) {
1189
- console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
1190
- return this.subVectors(v, w);
1191
- }
1192
- this.x -= v.x;
1193
- this.y -= v.y;
1194
- this.z -= v.z;
1195
- this.w -= v.w;
1196
- return this;
1197
- }
1198
- subScalar(s) {
1199
- this.x -= s;
1200
- this.y -= s;
1201
- this.z -= s;
1202
- this.w -= s;
1203
- return this;
1204
- }
1205
- subVectors(a, b) {
1206
- this.x = a.x - b.x;
1207
- this.y = a.y - b.y;
1208
- this.z = a.z - b.z;
1209
- this.w = a.w - b.w;
1210
- return this;
1211
- }
1212
- multiply(v) {
1213
- this.x *= v.x;
1214
- this.y *= v.y;
1215
- this.z *= v.z;
1216
- this.w *= v.w;
1217
- return this;
1218
- }
1219
- multiplyScalar(scalar) {
1220
- this.x *= scalar;
1221
- this.y *= scalar;
1222
- this.z *= scalar;
1223
- this.w *= scalar;
1224
- return this;
1225
- }
1226
- applyMatrix4(m) {
1227
- const x = this.x, y = this.y, z = this.z, w = this.w;
1228
- const e = m.elements;
1229
- this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
1230
- this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
1231
- this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
1232
- this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
1233
- return this;
1234
- }
1235
- divideScalar(scalar) {
1236
- return this.multiplyScalar(1 / scalar);
1237
- }
1238
- setAxisAngleFromQuaternion(q) {
1239
- this.w = 2 * Math.acos(q.w);
1240
- const s = Math.sqrt(1 - q.w * q.w);
1241
- if (s < 0.0001) {
1242
- this.x = 1;
1243
- this.y = 0;
1244
- this.z = 0;
1245
- }
1246
- else {
1247
- this.x = q.x / s;
1248
- this.y = q.y / s;
1249
- this.z = q.z / s;
1250
- }
1251
- return this;
1252
- }
1253
- setAxisAngleFromRotationMatrix(m) {
1254
- const epsilon = 0.01;
1255
- const epsilon2 = 0.1;
1256
- const te = m.elements;
1257
- const m11 = te[0], m12 = te[4], m13 = te[8];
1258
- const m21 = te[1], m22 = te[5], m23 = te[9];
1259
- const m31 = te[2], m32 = te[6], m33 = te[10];
1260
- if (Math.abs(m12 - m21) < epsilon &&
1261
- Math.abs(m13 - m31) < epsilon &&
1262
- Math.abs(m23 - m32) < epsilon) {
1263
- if (Math.abs(m12 + m21) < epsilon2 &&
1264
- Math.abs(m13 + m31) < epsilon2 &&
1265
- Math.abs(m23 + m32) < epsilon2 &&
1266
- Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
1267
- this.set(1, 0, 0, 0);
1268
- return this;
1269
- }
1270
- this.set(0, 0.707106781, 0.707106781, Math.PI);
1271
- return this;
1272
- }
1273
- let s = Math.sqrt((m32 - m23) * (m32 - m23) +
1274
- (m13 - m31) * (m13 - m31) +
1275
- (m21 - m12) * (m21 - m12));
1276
- if (Math.abs(s) < 0.001)
1277
- s = 1;
1278
- this.x = (m32 - m23) / s;
1279
- this.y = (m13 - m31) / s;
1280
- this.z = (m21 - m12) / s;
1281
- this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
1282
- return this;
1283
- }
1284
- min(v) {
1285
- this.x = Math.min(this.x, v.x);
1286
- this.y = Math.min(this.y, v.y);
1287
- this.z = Math.min(this.z, v.z);
1288
- this.w = Math.min(this.w, v.w);
1289
- return this;
1290
- }
1291
- max(v) {
1292
- this.x = Math.max(this.x, v.x);
1293
- this.y = Math.max(this.y, v.y);
1294
- this.z = Math.max(this.z, v.z);
1295
- this.w = Math.max(this.w, v.w);
1296
- return this;
1297
- }
1298
- clamp(min, max) {
1299
- this.x = Math.max(min.x, Math.min(max.x, this.x));
1300
- this.y = Math.max(min.y, Math.min(max.y, this.y));
1301
- this.z = Math.max(min.z, Math.min(max.z, this.z));
1302
- this.w = Math.max(min.w, Math.min(max.w, this.w));
1303
- return this;
1304
- }
1305
- clampScalar(minVal, maxVal) {
1306
- this.x = Math.max(minVal, Math.min(maxVal, this.x));
1307
- this.y = Math.max(minVal, Math.min(maxVal, this.y));
1308
- this.z = Math.max(minVal, Math.min(maxVal, this.z));
1309
- this.w = Math.max(minVal, Math.min(maxVal, this.w));
1310
- return this;
1311
- }
1312
- clampLength(min, max) {
1313
- const length = this.length();
1314
- return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1315
- }
1316
- floor() {
1317
- this.x = Math.floor(this.x);
1318
- this.y = Math.floor(this.y);
1319
- this.z = Math.floor(this.z);
1320
- this.w = Math.floor(this.w);
1321
- return this;
1322
- }
1323
- ceil() {
1324
- this.x = Math.ceil(this.x);
1325
- this.y = Math.ceil(this.y);
1326
- this.z = Math.ceil(this.z);
1327
- this.w = Math.ceil(this.w);
1328
- return this;
1329
- }
1330
- round() {
1331
- this.x = Math.round(this.x);
1332
- this.y = Math.round(this.y);
1333
- this.z = Math.round(this.z);
1334
- this.w = Math.round(this.w);
1335
- return this;
1336
- }
1337
- roundToZero() {
1338
- this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
1339
- this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
1340
- this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
1341
- this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
1342
- return this;
1343
- }
1344
- negate() {
1345
- this.x = -this.x;
1346
- this.y = -this.y;
1347
- this.z = -this.z;
1348
- this.w = -this.w;
1349
- return this;
1350
- }
1351
- dot(v) {
1352
- return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
1353
- }
1354
- lengthSq() {
1355
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
1356
- }
1357
- length() {
1358
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
1359
- }
1360
- manhattanLength() {
1361
- return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
1362
- }
1363
- normalize() {
1364
- return this.divideScalar(this.length() || 1);
1365
- }
1366
- setLength(length) {
1367
- return this.normalize().multiplyScalar(length);
1368
- }
1369
- lerp(v, alpha) {
1370
- this.x += (v.x - this.x) * alpha;
1371
- this.y += (v.y - this.y) * alpha;
1372
- this.z += (v.z - this.z) * alpha;
1373
- this.w += (v.w - this.w) * alpha;
1374
- return this;
1375
- }
1376
- lerpVectors(v1, v2, alpha) {
1377
- this.x = v1.x + (v2.x - v1.x) * alpha;
1378
- this.y = v1.y + (v2.y - v1.y) * alpha;
1379
- this.z = v1.z + (v2.z - v1.z) * alpha;
1380
- this.w = v1.w + (v2.w - v1.w) * alpha;
1381
- return this;
1382
- }
1383
- equals(v) {
1384
- return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
1385
- }
1386
- fromArray(array, offset = 0) {
1387
- this.x = array[offset];
1388
- this.y = array[offset + 1];
1389
- this.z = array[offset + 2];
1390
- this.w = array[offset + 3];
1391
- return this;
1392
- }
1393
- toArray(array = [], offset = 0) {
1394
- array[offset] = this.x;
1395
- array[offset + 1] = this.y;
1396
- array[offset + 2] = this.z;
1397
- array[offset + 3] = this.w;
1398
- return array;
1399
- }
1400
- fromBufferAttribute(attribute, index, offset) {
1401
- if (offset !== undefined) {
1402
- console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
1403
- }
1404
- this.x = attribute.getX(index);
1405
- this.y = attribute.getY(index);
1406
- this.z = attribute.getZ(index);
1407
- this.w = attribute.getW(index);
1408
- return this;
1409
- }
1410
- random() {
1411
- this.x = Math.random();
1412
- this.y = Math.random();
1413
- this.z = Math.random();
1414
- this.w = Math.random();
1415
- return this;
1416
- }
1417
- *[Symbol.iterator]() {
1418
- yield this.x;
1419
- yield this.y;
1420
- yield this.z;
1421
- yield this.w;
1422
- }
1423
- }
1424
- class Matrix3 {
1425
- constructor() {
1426
- this.elements = [
1427
- 1, 0, 0,
1428
- 0, 1, 0,
1429
- 0, 0, 1
1430
- ];
1431
- if (arguments.length > 0) {
1432
- console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
1433
- }
1434
- }
1435
- set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
1436
- const te = this.elements;
1437
- te[0] = n11;
1438
- te[1] = n21;
1439
- te[2] = n31;
1440
- te[3] = n12;
1441
- te[4] = n22;
1442
- te[5] = n32;
1443
- te[6] = n13;
1444
- te[7] = n23;
1445
- te[8] = n33;
1446
- return this;
1447
- }
1448
- identity() {
1449
- this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
1450
- return this;
1451
- }
1452
- copy(m) {
1453
- const te = this.elements;
1454
- const me = m.elements;
1455
- te[0] = me[0];
1456
- te[1] = me[1];
1457
- te[2] = me[2];
1458
- te[3] = me[3];
1459
- te[4] = me[4];
1460
- te[5] = me[5];
1461
- te[6] = me[6];
1462
- te[7] = me[7];
1463
- te[8] = me[8];
1464
- return this;
1465
- }
1466
- extractBasis(xAxis, yAxis, zAxis) {
1467
- xAxis.setFromMatrix3Column(this, 0);
1468
- yAxis.setFromMatrix3Column(this, 1);
1469
- zAxis.setFromMatrix3Column(this, 2);
1470
- return this;
1471
- }
1472
- setFromMatrix4(m) {
1473
- const me = m.elements;
1474
- this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
1475
- return this;
1476
- }
1477
- multiply(m) {
1478
- return this.multiplyMatrices(this, m);
1479
- }
1480
- premultiply(m) {
1481
- return this.multiplyMatrices(m, this);
1482
- }
1483
- multiplyMatrices(a, b) {
1484
- const ae = a.elements;
1485
- const be = b.elements;
1486
- const te = this.elements;
1487
- const a11 = ae[0], a12 = ae[3], a13 = ae[6];
1488
- const a21 = ae[1], a22 = ae[4], a23 = ae[7];
1489
- const a31 = ae[2], a32 = ae[5], a33 = ae[8];
1490
- const b11 = be[0], b12 = be[3], b13 = be[6];
1491
- const b21 = be[1], b22 = be[4], b23 = be[7];
1492
- const b31 = be[2], b32 = be[5], b33 = be[8];
1493
- te[0] = a11 * b11 + a12 * b21 + a13 * b31;
1494
- te[3] = a11 * b12 + a12 * b22 + a13 * b32;
1495
- te[6] = a11 * b13 + a12 * b23 + a13 * b33;
1496
- te[1] = a21 * b11 + a22 * b21 + a23 * b31;
1497
- te[4] = a21 * b12 + a22 * b22 + a23 * b32;
1498
- te[7] = a21 * b13 + a22 * b23 + a23 * b33;
1499
- te[2] = a31 * b11 + a32 * b21 + a33 * b31;
1500
- te[5] = a31 * b12 + a32 * b22 + a33 * b32;
1501
- te[8] = a31 * b13 + a32 * b23 + a33 * b33;
1502
- return this;
1503
- }
1504
- multiplyScalar(s) {
1505
- const te = this.elements;
1506
- te[0] *= s;
1507
- te[3] *= s;
1508
- te[6] *= s;
1509
- te[1] *= s;
1510
- te[4] *= s;
1511
- te[7] *= s;
1512
- te[2] *= s;
1513
- te[5] *= s;
1514
- te[8] *= s;
1515
- return this;
1516
- }
1517
- determinant() {
1518
- const te = this.elements;
1519
- const a = te[0], b = te[1], c = te[2], d = te[3], e = te[4], f = te[5], g = te[6], h = te[7], i = te[8];
1520
- return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
1521
- }
1522
- invert() {
1523
- const te = this.elements;
1524
- const n11 = te[0], n21 = te[1], n31 = te[2], n12 = te[3], n22 = te[4], n32 = te[5], n13 = te[6], n23 = te[7], n33 = te[8], t11 = n33 * n22 - n32 * n23, t12 = n32 * n13 - n33 * n12, t13 = n23 * n12 - n22 * n13, det = n11 * t11 + n21 * t12 + n31 * t13;
1525
- if (det === 0)
1526
- return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
1527
- const detInv = 1 / det;
1528
- te[0] = t11 * detInv;
1529
- te[1] = (n31 * n23 - n33 * n21) * detInv;
1530
- te[2] = (n32 * n21 - n31 * n22) * detInv;
1531
- te[3] = t12 * detInv;
1532
- te[4] = (n33 * n11 - n31 * n13) * detInv;
1533
- te[5] = (n31 * n12 - n32 * n11) * detInv;
1534
- te[6] = t13 * detInv;
1535
- te[7] = (n21 * n13 - n23 * n11) * detInv;
1536
- te[8] = (n22 * n11 - n21 * n12) * detInv;
1537
- return this;
1538
- }
1539
- transpose() {
1540
- let tmp;
1541
- const m = this.elements;
1542
- tmp = m[1];
1543
- m[1] = m[3];
1544
- m[3] = tmp;
1545
- tmp = m[2];
1546
- m[2] = m[6];
1547
- m[6] = tmp;
1548
- tmp = m[5];
1549
- m[5] = m[7];
1550
- m[7] = tmp;
1551
- return this;
1552
- }
1553
- getNormalMatrix(matrix4) {
1554
- return this.setFromMatrix4(matrix4).invert().transpose();
1555
- }
1556
- transposeIntoArray(r) {
1557
- const m = this.elements;
1558
- r[0] = m[0];
1559
- r[1] = m[3];
1560
- r[2] = m[6];
1561
- r[3] = m[1];
1562
- r[4] = m[4];
1563
- r[5] = m[7];
1564
- r[6] = m[2];
1565
- r[7] = m[5];
1566
- r[8] = m[8];
1567
- return this;
1568
- }
1569
- setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
1570
- const c = Math.cos(rotation);
1571
- const s = Math.sin(rotation);
1572
- this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
1573
- return this;
1574
- }
1575
- scale(sx, sy) {
1576
- const te = this.elements;
1577
- te[0] *= sx;
1578
- te[3] *= sx;
1579
- te[6] *= sx;
1580
- te[1] *= sy;
1581
- te[4] *= sy;
1582
- te[7] *= sy;
1583
- return this;
1584
- }
1585
- rotate(theta) {
1586
- const c = Math.cos(theta);
1587
- const s = Math.sin(theta);
1588
- const te = this.elements;
1589
- const a11 = te[0], a12 = te[3], a13 = te[6];
1590
- const a21 = te[1], a22 = te[4], a23 = te[7];
1591
- te[0] = c * a11 + s * a21;
1592
- te[3] = c * a12 + s * a22;
1593
- te[6] = c * a13 + s * a23;
1594
- te[1] = -s * a11 + c * a21;
1595
- te[4] = -s * a12 + c * a22;
1596
- te[7] = -s * a13 + c * a23;
1597
- return this;
1598
- }
1599
- translate(tx, ty) {
1600
- const te = this.elements;
1601
- te[0] += tx * te[2];
1602
- te[3] += tx * te[5];
1603
- te[6] += tx * te[8];
1604
- te[1] += ty * te[2];
1605
- te[4] += ty * te[5];
1606
- te[7] += ty * te[8];
1607
- return this;
1608
- }
1609
- equals(matrix) {
1610
- const te = this.elements;
1611
- const me = matrix.elements;
1612
- for (let i = 0; i < 9; i++) {
1613
- if (te[i] !== me[i])
1614
- return false;
1615
- }
1616
- return true;
1617
- }
1618
- fromArray(array, offset = 0) {
1619
- for (let i = 0; i < 9; i++) {
1620
- this.elements[i] = array[i + offset];
1621
- }
1622
- return this;
1623
- }
1624
- toArray(array = [], offset = 0) {
1625
- const te = this.elements;
1626
- array[offset] = te[0];
1627
- array[offset + 1] = te[1];
1628
- array[offset + 2] = te[2];
1629
- array[offset + 3] = te[3];
1630
- array[offset + 4] = te[4];
1631
- array[offset + 5] = te[5];
1632
- array[offset + 6] = te[6];
1633
- array[offset + 7] = te[7];
1634
- array[offset + 8] = te[8];
1635
- return array;
1636
- }
1637
- clone() {
1638
- return new Matrix3().fromArray(this.elements);
1639
- }
1640
- }
1641
- class Matrix4 {
1642
- constructor() {
1643
- this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
1644
- }
1645
- fromArray(array, offset = 0) {
1646
- for (let i = 0; i < 16; i++) {
1647
- this.elements[i] = array[i + offset];
1648
- }
1649
- return this;
1650
- }
1651
- getMaxScaleOnAxis() {
1652
- const te = this.elements;
1653
- const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
1654
- const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
1655
- const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
1656
- return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
1657
- }
1658
- }
1659
- class Box3 {
1660
- constructor(min = new Vector3(+Infinity, +Infinity, +Infinity), max = new Vector3(-Infinity, -Infinity, -Infinity)) {
1661
- this.min = min;
1662
- this.max = max;
1663
- }
1664
- set(min, max) {
1665
- this.min.copy(min);
1666
- this.max.copy(max);
1667
- return this;
1668
- }
1669
- setFromArray(array) {
1670
- let minX = +Infinity;
1671
- let minY = +Infinity;
1672
- let minZ = +Infinity;
1673
- let maxX = -Infinity;
1674
- let maxY = -Infinity;
1675
- let maxZ = -Infinity;
1676
- for (let i = 0, l = array.length; i < l; i += 3) {
1677
- const x = array[i];
1678
- const y = array[i + 1];
1679
- const z = array[i + 2];
1680
- if (x < minX)
1681
- minX = x;
1682
- if (y < minY)
1683
- minY = y;
1684
- if (z < minZ)
1685
- minZ = z;
1686
- if (x > maxX)
1687
- maxX = x;
1688
- if (y > maxY)
1689
- maxY = y;
1690
- if (z > maxZ)
1691
- maxZ = z;
1692
- }
1693
- this.min.set(minX, minY, minZ);
1694
- this.max.set(maxX, maxY, maxZ);
1695
- return this;
1696
- }
1697
- setFromBufferAttribute(attribute) {
1698
- let minX = +Infinity;
1699
- let minY = +Infinity;
1700
- let minZ = +Infinity;
1701
- let maxX = -Infinity;
1702
- let maxY = -Infinity;
1703
- let maxZ = -Infinity;
1704
- for (let i = 0, l = attribute.count; i < l; i++) {
1705
- const x = attribute.getX(i);
1706
- const y = attribute.getY(i);
1707
- const z = attribute.getZ(i);
1708
- if (x < minX)
1709
- minX = x;
1710
- if (y < minY)
1711
- minY = y;
1712
- if (z < minZ)
1713
- minZ = z;
1714
- if (x > maxX)
1715
- maxX = x;
1716
- if (y > maxY)
1717
- maxY = y;
1718
- if (z > maxZ)
1719
- maxZ = z;
1720
- }
1721
- this.min.set(minX, minY, minZ);
1722
- this.max.set(maxX, maxY, maxZ);
1723
- return this;
1724
- }
1725
- setFromPoints(points) {
1726
- this.makeEmpty();
1727
- for (let i = 0, il = points.length; i < il; i++) {
1728
- this.expandByPoint(points[i]);
1729
- }
1730
- return this;
1731
- }
1732
- setFromCenterAndSize(center, size) {
1733
- const halfSize = new Vector3().copy(size).multiplyScalar(0.5);
1734
- this.min.copy(center).sub(halfSize);
1735
- this.max.copy(center).add(halfSize);
1736
- return this;
1737
- }
1738
- setFromObject(object) {
1739
- this.makeEmpty();
1740
- return this.expandByObject(object);
1741
- }
1742
- clone() {
1743
- return new Box3().copy(this);
1744
- }
1745
- copy(box) {
1746
- this.min.copy(box.min);
1747
- this.max.copy(box.max);
1748
- return this;
1749
- }
1750
- makeEmpty() {
1751
- this.min.x = this.min.y = this.min.z = +Infinity;
1752
- this.max.x = this.max.y = this.max.z = -Infinity;
1753
- return this;
1754
- }
1755
- isEmpty() {
1756
- return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
1757
- }
1758
- getCenter(target) {
1759
- return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
1760
- }
1761
- getSize(target) {
1762
- return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
1763
- }
1764
- expandByPoint(point) {
1765
- this.min.min(point);
1766
- this.max.max(point);
1767
- return this;
1768
- }
1769
- expandByVector(vector) {
1770
- this.min.sub(vector);
1771
- this.max.add(vector);
1772
- return this;
1773
- }
1774
- expandByScalar(scalar) {
1775
- this.min.addScalar(-scalar);
1776
- this.max.addScalar(scalar);
1777
- return this;
1778
- }
1779
- expandByObject(object) {
1780
- object.updateWorldMatrix(false, false);
1781
- const geometry = object.geometry;
1782
- if (geometry !== undefined) {
1783
- if (geometry.boundingBox === null) {
1784
- geometry.computeBoundingBox();
1785
- }
1786
- const box = new Box3().copy(geometry.boundingBox);
1787
- box.applyMatrix4(object.matrixWorld);
1788
- this.union(box);
1789
- }
1790
- const children = object.children;
1791
- for (let i = 0, l = children.length; i < l; i++) {
1792
- this.expandByObject(children[i]);
1793
- }
1794
- return this;
1795
- }
1796
- containsPoint(point) {
1797
- return point.x < this.min.x || point.x > this.max.x ||
1798
- point.y < this.min.y || point.y > this.max.y ||
1799
- point.z < this.min.z || point.z > this.max.z ? false : true;
1800
- }
1801
- containsBox(box) {
1802
- return this.min.x <= box.min.x && box.max.x <= this.max.x &&
1803
- this.min.y <= box.min.y && box.max.y <= this.max.y &&
1804
- this.min.z <= box.min.z && box.max.z <= this.max.z;
1805
- }
1806
- getParameter(point, target) {
1807
- return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
1808
- }
1809
- intersectsBox(box) {
1810
- return box.max.x < this.min.x || box.min.x > this.max.x ||
1811
- box.max.y < this.min.y || box.min.y > this.max.y ||
1812
- box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
1813
- }
1814
- intersectsSphere(sphere) {
1815
- this.clampPoint(sphere.center, _vector$b);
1816
- return _vector$b.distanceToSquared(sphere.center) <= (sphere.radius * sphere.radius);
1817
- }
1818
- intersectsPlane(plane) {
1819
- let min, max;
1820
- if (plane.normal.x > 0) {
1821
- min = plane.normal.x * this.min.x;
1822
- max = plane.normal.x * this.max.x;
1823
- }
1824
- else {
1825
- min = plane.normal.x * this.max.x;
1826
- max = plane.normal.x * this.min.x;
1827
- }
1828
- if (plane.normal.y > 0) {
1829
- min += plane.normal.y * this.min.y;
1830
- max += plane.normal.y * this.max.y;
1831
- }
1832
- else {
1833
- min += plane.normal.y * this.max.y;
1834
- max += plane.normal.y * this.min.y;
1835
- }
1836
- if (plane.normal.z > 0) {
1837
- min += plane.normal.z * this.min.z;
1838
- max += plane.normal.z * this.max.z;
1839
- }
1840
- else {
1841
- min += plane.normal.z * this.max.z;
1842
- max += plane.normal.z * this.min.z;
1843
- }
1844
- return (min <= -plane.constant && max >= -plane.constant);
1845
- }
1846
- intersectsTriangle(triangle) {
1847
- if (this.isEmpty()) {
1848
- return false;
1849
- }
1850
- this.getCenter(_center);
1851
- _extents.subVectors(this.max, _center);
1852
- _v0$2.subVectors(triangle.a, _center);
1853
- _v1$7.subVectors(triangle.b, _center);
1854
- _v2$3.subVectors(triangle.c, _center);
1855
- _f0.subVectors(_v1$7, _v0$2);
1856
- _f1.subVectors(_v2$3, _v1$7);
1857
- _f2.subVectors(_v0$2, _v2$3);
1858
- let axes = [
1859
- 0, -_f0.z, _f0.y,
1860
- 0, -_f1.z, _f1.y,
1861
- 0, -_f2.z, _f2.y,
1862
- _f0.z, 0, -_f0.x,
1863
- _f1.z, 0, -_f1.x,
1864
- _f2.z, 0, -_f2.x,
1865
- -_f0.y, _f0.x, 0,
1866
- -_f1.y, _f1.x, 0,
1867
- -_f2.y, _f2.x, 0
1868
- ];
1869
- if (!satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents)) {
1870
- return false;
1871
- }
1872
- axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
1873
- if (!satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents)) {
1874
- return false;
1875
- }
1876
- _triangleNormal.crossVectors(_f0, _f1);
1877
- axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
1878
- return satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents);
1879
- }
1880
- clampPoint(point, target) {
1881
- return target.copy(point).clamp(this.min, this.max);
1882
- }
1883
- distanceToPoint(point) {
1884
- const clampedPoint = _vector$b.copy(point).clamp(this.min, this.max);
1885
- return clampedPoint.sub(point).length();
1886
- }
1887
- getBoundingSphere(target) {
1888
- this.getCenter(target.center);
1889
- target.radius = this.getSize(_vector$b).length() * 0.5;
1890
- return target;
1891
- }
1892
- intersect(box) {
1893
- this.min.max(box.min);
1894
- this.max.min(box.max);
1895
- if (this.isEmpty()) {
1896
- this.makeEmpty();
1897
- }
1898
- return this;
1899
- }
1900
- union(box) {
1901
- this.min.min(box.min);
1902
- this.max.max(box.max);
1903
- return this;
1904
- }
1905
- applyMatrix4(matrix) {
1906
- if (this.isEmpty()) {
1907
- return this;
1908
- }
1909
- _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
1910
- _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
1911
- _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
1912
- _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
1913
- _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
1914
- _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
1915
- _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
1916
- _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
1917
- this.setFromPoints(_points);
1918
- return this;
1919
- }
1920
- translate(offset) {
1921
- this.min.add(offset);
1922
- this.max.add(offset);
1923
- return this;
1924
- }
1925
- equals(box) {
1926
- return box.min.equals(this.min) && box.max.equals(this.max);
1927
- }
1928
- }
1929
- const _points = [
1930
- /*@__PURE__*/ new Vector3(),
1931
- /*@__PURE__*/ new Vector3(),
1932
- /*@__PURE__*/ new Vector3(),
1933
- /*@__PURE__*/ new Vector3(),
1934
- /*@__PURE__*/ new Vector3(),
1935
- /*@__PURE__*/ new Vector3(),
1936
- /*@__PURE__*/ new Vector3(),
1937
- /*@__PURE__*/ new Vector3()
1938
- ];
1939
- const _vector$b = /*@__PURE__*/ new Vector3();
1940
- const _box$3 = /*@__PURE__*/ new Box3();
1941
- // triangle centered vertices
1942
- const _v0$2 = /*@__PURE__*/ new Vector3();
1943
- const _v1$7 = /*@__PURE__*/ new Vector3();
1944
- const _v2$3 = /*@__PURE__*/ new Vector3();
1945
- // triangle edge vectors
1946
- const _f0 = /*@__PURE__*/ new Vector3();
1947
- const _f1 = /*@__PURE__*/ new Vector3();
1948
- const _f2 = /*@__PURE__*/ new Vector3();
1949
- const _center = /*@__PURE__*/ new Vector3();
1950
- const _extents = /*@__PURE__*/ new Vector3();
1951
- const _triangleNormal = /*@__PURE__*/ new Vector3();
1952
- const _testAxis = /*@__PURE__*/ new Vector3();
1953
- function satForAxes(axes, v0, v1, v2, extents) {
1954
- for (let i = 0, j = axes.length - 3; i <= j; i += 3) {
1955
- const _testAxis = new Vector3().fromArray(axes, i);
1956
- // Project the AABB onto the separating axis
1957
- const r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z);
1958
- // Project all 3 vertices of the triangle onto the separating axis
1959
- const p0 = v0.dot(_testAxis);
1960
- const p1 = v1.dot(_testAxis);
1961
- const p2 = v2.dot(_testAxis);
1962
- // Actual test, basically see if either of the most extreme of the triangle points intersects r
1963
- if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
1964
- // Points of the projected triangle are outside the projected half-length of the AABB
1965
- // The axis is separating, and we can exit
1966
- return false;
1967
- }
1968
- }
1969
- return true;
1970
- }
1971
- const _box$2 = /*@__PURE__*/ new Box3();
1972
- const _v1$6 = /*@__PURE__*/ new Vector3();
1973
- const _toFarthestPoint = /*@__PURE__*/ new Vector3();
1974
- const _toPoint = /*@__PURE__*/ new Vector3();
1975
- class Sphere {
1976
- constructor(center = new Vector3(), radius = -1) {
1977
- this.center = center;
1978
- this.radius = radius;
1979
- }
1980
- set(center, radius) {
1981
- this.center.copy(center);
1982
- this.radius = radius;
1983
- return this;
1984
- }
1985
- setFromPoints(points, optionalCenter) {
1986
- const center = this.center;
1987
- if (optionalCenter !== undefined) {
1988
- center.copy(optionalCenter);
1989
- }
1990
- else {
1991
- const box = new Box3();
1992
- box.setFromPoints(points);
1993
- box.getCenter(center);
1994
- }
1995
- let maxRadiusSq = 0;
1996
- for (let i = 0, il = points.length; i < il; i++) {
1997
- maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
1998
- }
1999
- this.radius = Math.sqrt(maxRadiusSq);
2000
- return this;
2001
- }
2002
- copy(sphere) {
2003
- this.center.copy(sphere.center);
2004
- this.radius = sphere.radius;
2005
- return this;
2006
- }
2007
- isEmpty() {
2008
- return this.radius < 0;
2009
- }
2010
- makeEmpty() {
2011
- this.center.set(0, 0, 0);
2012
- this.radius = -1;
2013
- return this;
2014
- }
2015
- containsPoint(point) {
2016
- return point.distanceToSquared(this.center) <= this.radius * this.radius;
2017
- }
2018
- distanceToPoint(point) {
2019
- return point.distanceTo(this.center) - this.radius;
2020
- }
2021
- intersectsSphere(sphere) {
2022
- const radiusSum = this.radius + sphere.radius;
2023
- return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
2024
- }
2025
- intersectsBox(box) {
2026
- return box.intersectsSphere(this);
2027
- }
2028
- intersectsPlane(plane) {
2029
- return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
2030
- }
2031
- clampPoint(point, target) {
2032
- const deltaLengthSq = this.center.distanceToSquared(point);
2033
- target.copy(point);
2034
- if (deltaLengthSq > this.radius * this.radius) {
2035
- target.sub(this.center).normalize().multiplyScalar(this.radius).add(this.center);
2036
- }
2037
- return target;
2038
- }
2039
- getBoundingBox(target) {
2040
- if (this.isEmpty()) {
2041
- target.makeEmpty();
2042
- return target;
2043
- }
2044
- target.set(this.center, this.center);
2045
- target.expandByScalar(this.radius);
2046
- return target;
2047
- }
2048
- applyMatrix4(matrix) {
2049
- this.center.applyMatrix4(matrix);
2050
- this.radius *= matrix.getMaxScaleOnAxis();
2051
- return this;
2052
- }
2053
- translate(offset) {
2054
- this.center.add(offset);
2055
- return this;
2056
- }
2057
- expandByPoint(point) {
2058
- _toPoint.subVectors(point, this.center);
2059
- const lengthSq = _toPoint.lengthSq();
2060
- if (lengthSq > this.radius * this.radius) {
2061
- const length = Math.sqrt(lengthSq);
2062
- const missingRadiusHalf = (length - this.radius) * 0.5;
2063
- this.center.add(_toPoint.multiplyScalar(missingRadiusHalf / length));
2064
- this.radius += missingRadiusHalf;
2065
- }
2066
- return this;
2067
- }
2068
- union(sphere) {
2069
- _toFarthestPoint.subVectors(sphere.center, this.center).normalize().multiplyScalar(sphere.radius);
2070
- this.expandByPoint(_v1$6.copy(sphere.center).add(_toFarthestPoint));
2071
- this.expandByPoint(_v1$6.copy(sphere.center).sub(_toFarthestPoint));
2072
- return this;
2073
- }
2074
- equals(sphere) {
2075
- return sphere.center.equals(this.center) && sphere.radius === this.radius;
2076
- }
2077
- clone() {
2078
- return new Sphere().copy(this);
2079
- }
2080
- }
2081
- class Plane {
2082
- constructor(normal = new Vector3(1, 0, 0), constant = 0) {
2083
- // normal is assumed to be normalized
2084
- this.normal = normal;
2085
- this.constant = constant;
2086
- }
2087
- set(normal, constant) {
2088
- this.normal.copy(normal);
2089
- this.constant = constant;
2090
- return this;
2091
- }
2092
- setComponents(x, y, z, w) {
2093
- this.normal.set(x, y, z);
2094
- this.constant = w;
2095
- return this;
2096
- }
2097
- setFromNormalAndCoplanarPoint(normal, point) {
2098
- this.normal.copy(normal);
2099
- this.constant = -point.dot(this.normal);
2100
- return this;
2101
- }
2102
- setFromCoplanarPoints(a, b, c) {
2103
- const normal = new Vector3().subVectors(c, b).cross(new Vector3().subVectors(a, b)).normalize();
2104
- this.setFromNormalAndCoplanarPoint(normal, a);
2105
- return this;
2106
- }
2107
- copy(plane) {
2108
- this.normal.copy(plane.normal);
2109
- this.constant = plane.constant;
2110
- return this;
2111
- }
2112
- normalize() {
2113
- // Note: will lead to a divide by zero if the plane is invalid.
2114
- const inverseNormalLength = 1.0 / this.normal.length();
2115
- this.normal.multiplyScalar(inverseNormalLength);
2116
- this.constant *= inverseNormalLength;
2117
- return this;
2118
- }
2119
- negate() {
2120
- this.constant *= -1;
2121
- this.normal.negate();
2122
- return this;
2123
- }
2124
- distanceToPoint(point) {
2125
- return this.normal.dot(point) + this.constant;
2126
- }
2127
- distanceToSphere(sphere) {
2128
- return this.distanceToPoint(sphere.center) - sphere.radius;
2129
- }
2130
- projectPoint(point, target) {
2131
- return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
2132
- }
2133
- intersectLine(line, target) {
2134
- const direction = line.delta(new Vector3());
2135
- const denominator = this.normal.dot(direction);
2136
- if (denominator === 0) {
2137
- // Line is coplanar, return origin
2138
- if (this.distanceToPoint(line.start) === 0) {
2139
- return target.copy(line.start);
2140
- }
2141
- // Unsure if this is the correct method to handle this case.
2142
- return null;
2143
- }
2144
- const t = -(line.start.dot(this.normal) + this.constant) / denominator;
2145
- if (t < 0 || t > 1) {
2146
- return null;
2147
- }
2148
- return target.copy(direction).multiplyScalar(t).add(line.start);
2149
- }
2150
- intersectsLine(line) {
2151
- // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
2152
- const startSign = this.distanceToPoint(line.start);
2153
- const endSign = this.distanceToPoint(line.end);
2154
- return (startSign < 0 && endSign > 0) || (endSign < 0 && startSign > 0);
2155
- }
2156
- intersectsBox(box) {
2157
- return box.intersectsPlane(this);
2158
- }
2159
- intersectsSphere(sphere) {
2160
- return sphere.intersectsPlane(this);
2161
- }
2162
- coplanarPoint(target) {
2163
- return target.copy(this.normal).multiplyScalar(-this.constant);
2164
- }
2165
- applyMatrix4(matrix, optionalNormalMatrix) {
2166
- const normalMatrix = optionalNormalMatrix || new Matrix3().getNormalMatrix(matrix);
2167
- const referencePoint = this.coplanarPoint(new Vector3()).applyMatrix4(matrix);
2168
- const normal = this.normal.applyMatrix3(normalMatrix).normalize();
2169
- this.constant = -referencePoint.dot(normal);
2170
- return this;
2171
- }
2172
- translate(offset) {
2173
- this.constant -= offset.dot(this.normal);
2174
- return this;
2175
- }
2176
- equals(plane) {
2177
- return plane.normal.equals(this.normal) && plane.constant === this.constant;
2178
- }
2179
- clone() {
2180
- return new Plane().copy(this);
2181
- }
2182
- }
2183
- const _v0$1 = /*@__PURE__*/ new Vector3();
2184
- const _v1$3 = /*@__PURE__*/ new Vector3();
2185
- const _v2$2 = /*@__PURE__*/ new Vector3();
2186
- const _v3$1 = /*@__PURE__*/ new Vector3();
2187
- const _vab = /*@__PURE__*/ new Vector3();
2188
- const _vac = /*@__PURE__*/ new Vector3();
2189
- const _vbc = /*@__PURE__*/ new Vector3();
2190
- const _vap = /*@__PURE__*/ new Vector3();
2191
- const _vbp = /*@__PURE__*/ new Vector3();
2192
- const _vcp = /*@__PURE__*/ new Vector3();
2193
- class Triangle {
2194
- constructor(a = new Vector3(), b = new Vector3(), c = new Vector3()) {
2195
- this.a = a;
2196
- this.b = b;
2197
- this.c = c;
2198
- }
2199
- static getNormal(a, b, c, target) {
2200
- target.subVectors(c, b);
2201
- _v0$1.subVectors(a, b);
2202
- target.cross(_v0$1);
2203
- const targetLengthSq = target.lengthSq();
2204
- if (targetLengthSq > 0) {
2205
- return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
2206
- }
2207
- return target.set(0, 0, 0);
2208
- }
2209
- // static/instance method to calculate barycentric coordinates
2210
- // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
2211
- static getBarycoord(point, a, b, c, target) {
2212
- _v0$1.subVectors(c, a);
2213
- _v1$3.subVectors(b, a);
2214
- _v2$2.subVectors(point, a);
2215
- const dot00 = _v0$1.dot(_v0$1);
2216
- const dot01 = _v0$1.dot(_v1$3);
2217
- const dot02 = _v0$1.dot(_v2$2);
2218
- const dot11 = _v1$3.dot(_v1$3);
2219
- const dot12 = _v1$3.dot(_v2$2);
2220
- const denom = (dot00 * dot11 - dot01 * dot01);
2221
- // collinear or singular triangle
2222
- if (denom === 0) {
2223
- // arbitrary location outside of triangle?
2224
- // not sure if this is the best idea, maybe should be returning undefined
2225
- return target.set(-2, -1, -1);
2226
- }
2227
- const invDenom = 1 / denom;
2228
- const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
2229
- const v = (dot00 * dot12 - dot01 * dot02) * invDenom;
2230
- // barycentric coordinates must always sum to 1
2231
- return target.set(1 - u - v, v, u);
2232
- }
2233
- static containsPoint(point, a, b, c) {
2234
- this.getBarycoord(point, a, b, c, _v3$1);
2235
- return (_v3$1.x >= 0) && (_v3$1.y >= 0) && ((_v3$1.x + _v3$1.y) <= 1);
2236
- }
2237
- static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
2238
- this.getBarycoord(point, p1, p2, p3, _v3$1);
2239
- target.set(0, 0, undefined);
2240
- target.addScaledVector(uv1, _v3$1.x);
2241
- target.addScaledVector(uv2, _v3$1.y);
2242
- target.addScaledVector(uv3, _v3$1.z);
2243
- return target;
2244
- }
2245
- static isFrontFacing(a, b, c, direction) {
2246
- _v0$1.subVectors(c, b);
2247
- _v1$3.subVectors(a, b);
2248
- // strictly front facing
2249
- return (_v0$1.cross(_v1$3).dot(direction) < 0) ? true : false;
2250
- }
2251
- set(a, b, c) {
2252
- this.a.copy(a);
2253
- this.b.copy(b);
2254
- this.c.copy(c);
2255
- return this;
2256
- }
2257
- setFromPointsAndIndices(points, i0, i1, i2) {
2258
- this.a.copy(points[i0]);
2259
- this.b.copy(points[i1]);
2260
- this.c.copy(points[i2]);
2261
- return this;
2262
- }
2263
- setFromAttributeAndIndices(attribute, i0, i1, i2) {
2264
- this.a.fromBufferAttribute(attribute, i0);
2265
- this.b.fromBufferAttribute(attribute, i1);
2266
- this.c.fromBufferAttribute(attribute, i2);
2267
- return this;
2268
- }
2269
- clone() {
2270
- return new Triangle().copy(this);
2271
- }
2272
- copy(triangle) {
2273
- this.a.copy(triangle.a);
2274
- this.b.copy(triangle.b);
2275
- this.c.copy(triangle.c);
2276
- return this;
2277
- }
2278
- getArea() {
2279
- _v0$1.subVectors(this.c, this.b);
2280
- _v1$3.subVectors(this.a, this.b);
2281
- return _v0$1.cross(_v1$3).length() * 0.5;
2282
- }
2283
- getMidpoint(target) {
2284
- return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
2285
- }
2286
- getNormal(target) {
2287
- return Triangle.getNormal(this.a, this.b, this.c, target);
2288
- }
2289
- getPlane(target) {
2290
- return target.setFromCoplanarPoints(this.a, this.b, this.c);
2291
- }
2292
- getBarycoord(point, target) {
2293
- return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
2294
- }
2295
- getUV(point, uv1, uv2, uv3, target) {
2296
- return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
2297
- }
2298
- containsPoint(point) {
2299
- return Triangle.containsPoint(point, this.a, this.b, this.c);
2300
- }
2301
- isFrontFacing(direction) {
2302
- return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
2303
- }
2304
- intersectsBox(box) {
2305
- return box.intersectsTriangle(this);
2306
- }
2307
- closestPointToPoint(p, target) {
2308
- const a = this.a, b = this.b, c = this.c;
2309
- let v, w;
2310
- // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
2311
- // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
2312
- // under the accompanying license; see chapter 5.1.5 for detailed explanation.
2313
- // basically, we're distinguishing which of the voronoi regions of the triangle
2314
- // the point lies in with the minimum amount of redundant computation.
2315
- _vab.subVectors(b, a);
2316
- _vac.subVectors(c, a);
2317
- _vap.subVectors(p, a);
2318
- const d1 = _vab.dot(_vap);
2319
- const d2 = _vac.dot(_vap);
2320
- if (d1 <= 0 && d2 <= 0) {
2321
- // vertex region of A; barycentric coords (1, 0, 0)
2322
- return target.copy(a);
2323
- }
2324
- _vbp.subVectors(p, b);
2325
- const d3 = _vab.dot(_vbp);
2326
- const d4 = _vac.dot(_vbp);
2327
- if (d3 >= 0 && d4 <= d3) {
2328
- // vertex region of B; barycentric coords (0, 1, 0)
2329
- return target.copy(b);
2330
- }
2331
- const vc = d1 * d4 - d3 * d2;
2332
- if (vc <= 0 && d1 >= 0 && d3 <= 0) {
2333
- v = d1 / (d1 - d3);
2334
- // edge region of AB; barycentric coords (1-v, v, 0)
2335
- return target.copy(a).addScaledVector(_vab, v);
2336
- }
2337
- _vcp.subVectors(p, c);
2338
- const d5 = _vab.dot(_vcp);
2339
- const d6 = _vac.dot(_vcp);
2340
- if (d6 >= 0 && d5 <= d6) {
2341
- // vertex region of C; barycentric coords (0, 0, 1)
2342
- return target.copy(c);
2343
- }
2344
- const vb = d5 * d2 - d1 * d6;
2345
- if (vb <= 0 && d2 >= 0 && d6 <= 0) {
2346
- w = d2 / (d2 - d6);
2347
- // edge region of AC; barycentric coords (1-w, 0, w)
2348
- return target.copy(a).addScaledVector(_vac, w);
2349
- }
2350
- const va = d3 * d6 - d5 * d4;
2351
- if (va <= 0 && (d4 - d3) >= 0 && (d5 - d6) >= 0) {
2352
- _vbc.subVectors(c, b);
2353
- w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
2354
- // edge region of BC; barycentric coords (0, 1-w, w)
2355
- return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
2356
- }
2357
- // face region
2358
- const denom = 1 / (va + vb + vc);
2359
- // u = va * denom
2360
- v = vb * denom;
2361
- w = vc * denom;
2362
- return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
2363
- }
2364
- equals(triangle) {
2365
- return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
2366
- }
2367
- }
2368
- //#endregion
2369
- const _vector$9 = /*@__PURE__*/ new Vector3(0, 0, 0);
2370
- const _vector2$1 = /*@__PURE__*/ new Vector2();
2371
- class BufferAttribute {
2372
- constructor(array, itemSize, normalized = true) {
2373
- this.name = '';
2374
- if (Array.isArray(array)) {
2375
- throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
2376
- }
2377
- this.array = array;
2378
- this.itemSize = itemSize;
2379
- this.count = array !== undefined ? array.length / itemSize : 0;
2380
- this.normalized = normalized === true;
2381
- this.usage = StaticDrawUsage;
2382
- this.updateRange = { offset: 0, count: -1 };
2383
- this.version = 0;
2384
- }
2385
- onUploadCallback() { }
2386
- set needsUpdate(value) {
2387
- if (value === true)
2388
- this.version++;
2389
- }
2390
- setUsage(value) {
2391
- this.usage = value;
2392
- return this;
2393
- }
2394
- copy(source) {
2395
- this.name = source.name;
2396
- this.array = source.array;
2397
- this.itemSize = source.itemSize;
2398
- this.count = source.count;
2399
- this.normalized = source.normalized;
2400
- this.usage = source.usage;
2401
- return this;
2402
- }
2403
- copyAt(index1, attribute, index2) {
2404
- index1 *= this.itemSize;
2405
- index2 *= attribute.itemSize;
2406
- for (let i = 0, l = this.itemSize; i < l; i++) {
2407
- this.array[index1 + i] = attribute.array[index2 + i];
2408
- }
2409
- return this;
2410
- }
2411
- copyArray(array) {
2412
- this.array.set(array);
2413
- return this;
2414
- }
2415
- copyColorsArray(colors) {
2416
- const array = this.array;
2417
- let offset = 0;
2418
- for (let i = 0, l = colors.length; i < l; i++) {
2419
- let color = colors[i];
2420
- if (color === undefined) {
2421
- console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
2422
- color = new Color(255, 255, 255);
2423
- }
2424
- array[offset++] = color.r;
2425
- array[offset++] = color.g;
2426
- array[offset++] = color.b;
2427
- }
2428
- return this;
2429
- }
2430
- copyVector2sArray(vectors) {
2431
- const array = this.array;
2432
- let offset = 0;
2433
- for (let i = 0, l = vectors.length; i < l; i++) {
2434
- let vector = vectors[i];
2435
- if (vector === undefined) {
2436
- console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
2437
- vector = new Vector2();
2438
- }
2439
- array[offset++] = vector.x;
2440
- array[offset++] = vector.y;
2441
- }
2442
- return this;
2443
- }
2444
- copyVector3sArray(vectors) {
2445
- const array = this.array;
2446
- let offset = 0;
2447
- for (let i = 0, l = vectors.length; i < l; i++) {
2448
- let vector = vectors[i];
2449
- if (vector === undefined) {
2450
- console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
2451
- vector = new Vector3(0, 0, 0);
2452
- }
2453
- array[offset++] = vector.x;
2454
- array[offset++] = vector.y;
2455
- array[offset++] = vector.z;
2456
- }
2457
- return this;
2458
- }
2459
- copyVector4sArray(vectors) {
2460
- const array = this.array;
2461
- let offset = 0;
2462
- for (let i = 0, l = vectors.length; i < l; i++) {
2463
- let vector = vectors[i];
2464
- if (vector === undefined) {
2465
- console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
2466
- vector = new Vector4();
2467
- }
2468
- array[offset++] = vector.x;
2469
- array[offset++] = vector.y;
2470
- array[offset++] = vector.z;
2471
- array[offset++] = vector.w;
2472
- }
2473
- return this;
2474
- }
2475
- applyMatrix3(m) {
2476
- if (this.itemSize === 2) {
2477
- for (let i = 0, l = this.count; i < l; i++) {
2478
- _vector2$1.fromBufferAttribute(this, i);
2479
- _vector2$1.applyMatrix3(m);
2480
- this.setXY(i, _vector2$1.x, _vector2$1.y);
2481
- }
2482
- }
2483
- else if (this.itemSize === 3) {
2484
- for (let i = 0, l = this.count; i < l; i++) {
2485
- _vector$9.fromBufferAttribute(this, i);
2486
- _vector$9.applyMatrix3(m);
2487
- this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2488
- }
2489
- }
2490
- return this;
2491
- }
2492
- applyMatrix4(m) {
2493
- for (let i = 0, l = this.count; i < l; i++) {
2494
- _vector$9.x = this.getX(i);
2495
- _vector$9.y = this.getY(i);
2496
- _vector$9.z = this.getZ(i);
2497
- _vector$9.applyMatrix4(m);
2498
- this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2499
- }
2500
- return this;
2501
- }
2502
- applyNormalMatrix(m) {
2503
- for (let i = 0, l = this.count; i < l; i++) {
2504
- _vector$9.x = this.getX(i);
2505
- _vector$9.y = this.getY(i);
2506
- _vector$9.z = this.getZ(i);
2507
- _vector$9.applyNormalMatrix(m);
2508
- this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2509
- }
2510
- return this;
2511
- }
2512
- transformDirection(m) {
2513
- for (let i = 0, l = this.count; i < l; i++) {
2514
- _vector$9.x = this.getX(i);
2515
- _vector$9.y = this.getY(i);
2516
- _vector$9.z = this.getZ(i);
2517
- _vector$9.transformDirection(m);
2518
- this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z);
2519
- }
2520
- return this;
2521
- }
2522
- set(value, offset = 0) {
2523
- this.array.set(value, offset);
2524
- return this;
2525
- }
2526
- getX(index) {
2527
- return this.array[index * this.itemSize];
2528
- }
2529
- setX(index, x) {
2530
- this.array[index * this.itemSize] = x;
2531
- return this;
2532
- }
2533
- getY(index) {
2534
- return this.array[index * this.itemSize + 1];
2535
- }
2536
- setY(index, y) {
2537
- this.array[index * this.itemSize + 1] = y;
2538
- return this;
2539
- }
2540
- getZ(index) {
2541
- return this.array[index * this.itemSize + 2];
2542
- }
2543
- setZ(index, z) {
2544
- this.array[index * this.itemSize + 2] = z;
2545
- return this;
2546
- }
2547
- getW(index) {
2548
- return this.array[index * this.itemSize + 3];
2549
- }
2550
- setW(index, w) {
2551
- this.array[index * this.itemSize + 3] = w;
2552
- return this;
2553
- }
2554
- setXY(index, x, y) {
2555
- index *= this.itemSize;
2556
- this.array[index + 0] = x;
2557
- this.array[index + 1] = y;
2558
- return this;
2559
- }
2560
- setXYZ(index, x, y, z) {
2561
- index *= this.itemSize;
2562
- this.array[index + 0] = x;
2563
- this.array[index + 1] = y;
2564
- this.array[index + 2] = z;
2565
- return this;
2566
- }
2567
- setXYZW(index, x, y, z, w) {
2568
- index *= this.itemSize;
2569
- this.array[index + 0] = x;
2570
- this.array[index + 1] = y;
2571
- this.array[index + 2] = z;
2572
- this.array[index + 3] = w;
2573
- return this;
2574
- }
2575
- onUpload(callback) {
2576
- this.onUploadCallback = callback;
2577
- return this;
2578
- }
2579
- clone() {
2580
- return new this.constructor(this.array, this.itemSize).copy(this);
2581
- }
2582
- toJSON() {
2583
- const data = {
2584
- itemSize: this.itemSize,
2585
- type: this.array.constructor.name,
2586
- array: Array.prototype.slice.call(this.array),
2587
- normalized: this.normalized,
2588
- name: '',
2589
- usage: 0,
2590
- updateRange: {
2591
- offset: 0,
2592
- count: 0
2593
- }
2594
- };
2595
- if (this.name !== '')
2596
- data.name = this.name;
2597
- if (this.usage !== StaticDrawUsage)
2598
- data.usage = this.usage;
2599
- if (this.updateRange.offset !== 0 || this.updateRange.count !== -1)
2600
- data.updateRange = this.updateRange;
2601
- return data;
2602
- }
2603
- }
2604
- let _id = 0;
2605
- const _vector$8 = /*@__PURE__*/ new Vector3();
2606
- class BufferGeometry extends EventDispatcher {
2607
- constructor() {
2608
- super();
2609
- Object.defineProperty(this, 'id', { value: _id++ });
2610
- this.uuid = generateUUID();
2611
- this.name = '';
2612
- this.type = 'BufferGeometry';
2613
- this.index = null;
2614
- this.attributes = {};
2615
- this.morphAttributes = {};
2616
- this.morphTargetsRelative = false;
2617
- this.groups = [];
2618
- this.boundingBox = null;
2619
- this.boundingSphere = null;
2620
- this.drawRange = { start: 0, count: Infinity };
2621
- this.userData = {};
2622
- }
2623
- getIndex() {
2624
- return this.index;
2625
- }
2626
- setAttribute(name, attribute) {
2627
- this.attributes[name] = attribute;
2628
- return this;
2629
- }
2630
- getAttribute(name) {
2631
- return this.attributes[name];
2632
- }
2633
- computeVertexNormals() {
2634
- const index = this.index;
2635
- const positionAttribute = this.getAttribute('position');
2636
- if (positionAttribute !== undefined) {
2637
- let normalAttribute = this.getAttribute('normal');
2638
- if (normalAttribute === undefined) {
2639
- normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
2640
- this.setAttribute('normal', normalAttribute);
2641
- }
2642
- else {
2643
- // reset existing normals to zero
2644
- for (let i = 0, il = normalAttribute.count; i < il; i++) {
2645
- normalAttribute.setXYZ(i, 0, 0, 0);
2646
- }
2647
- }
2648
- const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
2649
- const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
2650
- const cb = new Vector3(), ab = new Vector3();
2651
- // indexed elements
2652
- if (index) {
2653
- for (let i = 0, il = index.count; i < il; i += 3) {
2654
- const vA = index.getX(i + 0);
2655
- const vB = index.getX(i + 1);
2656
- const vC = index.getX(i + 2);
2657
- pA.fromBufferAttribute(positionAttribute, vA);
2658
- pB.fromBufferAttribute(positionAttribute, vB);
2659
- pC.fromBufferAttribute(positionAttribute, vC);
2660
- cb.subVectors(pC, pB);
2661
- ab.subVectors(pA, pB);
2662
- cb.cross(ab);
2663
- nA.fromBufferAttribute(normalAttribute, vA);
2664
- nB.fromBufferAttribute(normalAttribute, vB);
2665
- nC.fromBufferAttribute(normalAttribute, vC);
2666
- nA.add(cb);
2667
- nB.add(cb);
2668
- nC.add(cb);
2669
- normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
2670
- normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
2671
- normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
2672
- }
2673
- }
2674
- else {
2675
- // non-indexed elements (unconnected triangle soup)
2676
- for (let i = 0, il = positionAttribute.count; i < il; i += 3) {
2677
- pA.fromBufferAttribute(positionAttribute, i + 0);
2678
- pB.fromBufferAttribute(positionAttribute, i + 1);
2679
- pC.fromBufferAttribute(positionAttribute, i + 2);
2680
- cb.subVectors(pC, pB);
2681
- ab.subVectors(pA, pB);
2682
- cb.cross(ab);
2683
- normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z);
2684
- normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z);
2685
- normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z);
2686
- }
2687
- }
2688
- this.normalizeNormals();
2689
- normalAttribute.needsUpdate = true;
2690
- }
2691
- }
2692
- normalizeNormals() {
2693
- const normals = this.attributes.normal;
2694
- for (let i = 0, il = normals.count; i < il; i++) {
2695
- _vector$8.fromBufferAttribute(normals, i);
2696
- _vector$8.normalize();
2697
- normals.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z);
2698
- }
2699
- }
2700
- }
2701
- //#endregion
2702
- }
2703
- exports.workerCode = workerFunction;
2704
- //# sourceMappingURL=load-model-worker-2.script.js.map