ohzi-core 10.0.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -8,6 +8,8 @@ import { Plane } from 'three';
|
|
|
8
8
|
import { Ray } from 'three';
|
|
9
9
|
import { Sphere } from 'three';
|
|
10
10
|
import { Box3 } from 'three';
|
|
11
|
+
import { PerspectiveFrustumPointFitter } from './PerspectiveFrustumPointFitter';
|
|
12
|
+
import { OrthographicFrustumPointFitter } from './OrthographicFrustumPointFitter';
|
|
11
13
|
|
|
12
14
|
class CameraUtilities
|
|
13
15
|
{
|
|
@@ -206,6 +208,72 @@ class CameraUtilities
|
|
|
206
208
|
camera.aspect = OScreen.aspect_ratio;
|
|
207
209
|
camera.updateProjectionMatrix(true);
|
|
208
210
|
}
|
|
211
|
+
|
|
212
|
+
fit_bounding_box_points(camera, bb, scale = 1)
|
|
213
|
+
{
|
|
214
|
+
const dir = new Vector3();
|
|
215
|
+
dir.copy(bb.max).sub(bb.min);
|
|
216
|
+
|
|
217
|
+
const p1 = bb.min.clone();
|
|
218
|
+
|
|
219
|
+
const p2 = p1.clone().add(new Vector3(dir.x, 0, 0));
|
|
220
|
+
const p3 = p1.clone().add(new Vector3(0, dir.y, 0));
|
|
221
|
+
const p4 = p1.clone().add(new Vector3(0, 0, dir.z));
|
|
222
|
+
|
|
223
|
+
const p5 = p1.clone().add(new Vector3(dir.x, 0, dir.z));
|
|
224
|
+
const p6 = p1.clone().add(new Vector3(0, dir.y, dir.z));
|
|
225
|
+
const p7 = bb.max.clone();
|
|
226
|
+
const p8 = p1.clone().add(new Vector3(dir.x, dir.y, 0));
|
|
227
|
+
return this.fit_points(camera, [p1, p2, p3, p4, p5, p6, p7, p8], scale);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fit_points(camera, points, zoom_scale = 1)
|
|
231
|
+
{
|
|
232
|
+
if (camera.isPerspectiveCamera)
|
|
233
|
+
{
|
|
234
|
+
const camera_forward_dir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
235
|
+
const camera_backward_dir = camera_forward_dir.clone().multiplyScalar(-1);
|
|
236
|
+
|
|
237
|
+
const fitter = new PerspectiveFrustumPointFitter();
|
|
238
|
+
|
|
239
|
+
const aspect_ratio = OScreen.aspect_ratio;
|
|
240
|
+
|
|
241
|
+
const camera_pos = fitter.fit_points(points, camera.quaternion, camera.fov * zoom_scale, aspect_ratio);
|
|
242
|
+
const box = new Box3().setFromPoints(points);
|
|
243
|
+
const center = new Vector3();
|
|
244
|
+
box.getCenter(center);
|
|
245
|
+
|
|
246
|
+
const reference_position_plane = new Plane().setFromNormalAndCoplanarPoint(camera_backward_dir, center);
|
|
247
|
+
|
|
248
|
+
const camera_ray = new Ray(camera_pos, camera_forward_dir);
|
|
249
|
+
|
|
250
|
+
const reference_position = new Vector3();
|
|
251
|
+
camera_ray.intersectPlane(reference_position_plane, reference_position);
|
|
252
|
+
|
|
253
|
+
const zoom = camera_pos.distanceTo(reference_position);
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
zoom: zoom,
|
|
257
|
+
reference_position: reference_position,
|
|
258
|
+
camera_position: camera_pos
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
{
|
|
263
|
+
const fitter = new OrthographicFrustumPointFitter();
|
|
264
|
+
const result = fitter.fit_points(points, this.reference_rotation, camera.fov * zoom_scale, OScreen.aspect_ratio);
|
|
265
|
+
|
|
266
|
+
this.reference_position.copy(result.center);
|
|
267
|
+
this.reference_zoom = result.distance_to_center;
|
|
268
|
+
|
|
269
|
+
const forward = new Vector3(0, 0, 1).applyQuaternion(camera.quaternion);
|
|
270
|
+
return {
|
|
271
|
+
zoom: result.distance_to_center,
|
|
272
|
+
reference_position: result.center,
|
|
273
|
+
camera_position: forward.multiplyScalar(result.distance_to_center)
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
209
277
|
}
|
|
210
278
|
|
|
211
279
|
const camera_utilities = new CameraUtilities();
|
|
@@ -36,12 +36,7 @@ class StringUtilities
|
|
|
36
36
|
|
|
37
37
|
static snake_to_camelcase(string)
|
|
38
38
|
{
|
|
39
|
-
return string.replace(
|
|
40
|
-
/([-_][a-z])/g,
|
|
41
|
-
(group) => group.toUpperCase()
|
|
42
|
-
.replace('-', '')
|
|
43
|
-
.replace('_', '')
|
|
44
|
-
);
|
|
39
|
+
return string.toLowerCase().replace(/[-_][a-z0-9]/g, (group) => group.slice(-1).toUpperCase());
|
|
45
40
|
}
|
|
46
41
|
}
|
|
47
42
|
|