ohzi-core 12.5.2 → 12.7.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/README.md +9 -9
- package/build/index.mjs +1 -1
- package/build/index.mjs.map +1 -1
- package/build/index.module.js +2 -0
- package/build/index.module.js.map +1 -0
- package/package.json +64 -63
- package/src/.vscode/settings.json +2 -2
- package/src/BaseApplication.js +40 -40
- package/src/Browser.js +119 -119
- package/src/CameraManager.js +37 -37
- package/src/Capabilities.js +13 -13
- package/src/CustomBezierCurve.js +58 -58
- package/src/Debug.js +359 -359
- package/src/Graphics.js +507 -507
- package/src/Initializer.js +56 -56
- package/src/KeyboardInput.js +177 -177
- package/src/OS.js +59 -59
- package/src/OScreen.js +90 -90
- package/src/OrthographicCamera.js +36 -36
- package/src/PerspectiveCamera.js +34 -34
- package/src/ReflectionPlaneContext.js +22 -22
- package/src/RenderLayers.js +30 -30
- package/src/RenderLoop.js +125 -122
- package/src/RenderOrder.js +40 -40
- package/src/ResourceContainer.js +57 -57
- package/src/SceneManager.js +55 -55
- package/src/Screen.js +71 -71
- package/src/Time.js +99 -98
- package/src/UI.js +106 -106
- package/src/action_sequencer/ActionEvent.js +22 -22
- package/src/action_sequencer/ActionInterpolator.js +39 -39
- package/src/action_sequencer/ActionSequencer.js +338 -338
- package/src/action_sequencer/NumberInterpolator.js +42 -42
- package/src/action_sequencer/VectorInterpolator.js +34 -34
- package/src/blitter_index.js +14 -14
- package/src/canvas_drawer/CanvasDrawer.js +146 -146
- package/src/canvas_drawer/MultiLineTextDrawer.js +58 -58
- package/src/canvas_drawer/SimpleTextDrawer.js +55 -55
- package/src/components/AudioClip.js +67 -67
- package/src/components/AxisHelper.js +60 -60
- package/src/components/BaseObject.js +50 -50
- package/src/components/EdgeMesh.js +172 -172
- package/src/components/GeometryEdgeVisualizer.js +57 -57
- package/src/components/Grid.js +40 -40
- package/src/components/Line.js +225 -225
- package/src/components/MultiLinePath.js +25 -25
- package/src/components/MultiLineText2D.js +75 -75
- package/src/components/ObjectAxis.js +27 -27
- package/src/components/ObjectOrientedBoundingBox.js +228 -228
- package/src/components/PlaneHelper.js +38 -38
- package/src/components/Shape2D.js +52 -52
- package/src/components/Shape3D.js +46 -46
- package/src/components/Text2D.js +49 -49
- package/src/components/UIElement.js +246 -246
- package/src/components/UpdatableMaterialMesh.js +26 -26
- package/src/components/WorldImage.js +101 -101
- package/src/components/mouse_interactors/ObjectRotator.js +64 -64
- package/src/components/sdf_text/SDFText.js +156 -156
- package/src/components/sdf_text/SDFTextBatch.js +195 -195
- package/src/components/sdf_text/TextGlyph.js +17 -17
- package/src/data_textures/CustomDataTexture.js +53 -53
- package/src/data_textures/RGBADataTexture.js +14 -14
- package/src/data_textures/RGBAFloatDataTexture.js +14 -14
- package/src/data_textures/RGBDataTexture.js +14 -14
- package/src/data_textures/RGBFloatDataTexture.js +13 -13
- package/src/editor/ManipulatorHandle.js +73 -73
- package/src/editor/ObjectEditor.js +68 -68
- package/src/editor/ObjectManipulator.js +112 -112
- package/src/editor/ObjectPicker.js +77 -77
- package/src/editor/shaders/object_picker.frag +5 -5
- package/src/editor/shaders/object_picker.vert +7 -7
- package/src/gpu_particles/GPUParticleSystem.js +111 -111
- package/src/gpu_particles/ParticleAttribute.js +89 -89
- package/src/gpu_particles/ParticlePositionAttribute.js +42 -42
- package/src/html_utilities/CSSAnimator.js +66 -66
- package/src/html_utilities/css_animator_states/Animating.js +46 -46
- package/src/html_utilities/css_animator_states/Idle.js +27 -27
- package/src/index.js +134 -134
- package/src/loaders/AsyncAbstractLoader.js +160 -160
- package/src/loaders/AsyncAudiosLoader.js +34 -34
- package/src/loaders/AsyncObjectsLoader.js +44 -44
- package/src/loaders/AsyncTexturesLoader.js +81 -70
- package/src/loaders/assets_loader/AsyncAssetsLoaderWorker.js +69 -69
- package/src/loaders/assets_loader/ResourceContainer.js +37 -37
- package/src/loaders/assets_loader/ResourceLoaderChecker.js +39 -39
- package/src/materials/AddMaterial.js +20 -20
- package/src/materials/AlphaFilterMaterial.js +23 -23
- package/src/materials/BaseShaderMaterial.js +21 -21
- package/src/materials/BlitMaterial.js +30 -30
- package/src/materials/BloomComposeMaterial.js +24 -24
- package/src/materials/BoxBlurMaterial.js +16 -16
- package/src/materials/ClearAlphaMaterial.js +15 -15
- package/src/materials/ClearColorMaterial.js +33 -33
- package/src/materials/ClearDepthNormalMaterial.js +16 -16
- package/src/materials/DeferredRendererComposeMaterial.js +35 -35
- package/src/materials/DepthNormalMaterial.js +30 -30
- package/src/materials/DisplayNormalTextureMaterial.js +18 -18
- package/src/materials/DualFilteringBlurMaterial.js +14 -14
- package/src/materials/FXAAMaterial.js +12 -12
- package/src/materials/GaussianBlurMaterial.js +40 -40
- package/src/materials/LuminosityHighPassMaterial.js +26 -26
- package/src/materials/MedianFilterMaterial.js +45 -45
- package/src/materials/NormalMaterial.js +19 -19
- package/src/materials/SDFScreenTextMaterial.js +34 -34
- package/src/materials/SDFTextMaterial.js +41 -41
- package/src/materials/SSAOComposeMaterial.js +14 -14
- package/src/materials/SSAOMaterial.js +65 -65
- package/src/materials/ScreenSpaceTextureMaterial.js +67 -67
- package/src/materials/UIElementMaterial.js +30 -30
- package/src/materials/UnrealBloomComposeMaterial.js +100 -100
- package/src/materials/UnrealBlurMaterial.js +20 -20
- package/src/materials/UnrealComposeMaterial.js +27 -27
- package/src/materials/ViewPositionMaterial.js +19 -19
- package/src/materials/deferred/DeferredPointLightMaterial.js +42 -42
- package/src/materials/gpu_particles/AttributeUpdateMaterial.js +37 -37
- package/src/materials/gpu_particles/BasicParticleMaterial.js +25 -25
- package/src/materials/gpu_particles/ParticleStorageMaterial.js +37 -37
- package/src/materials/gpu_particles/PositionStorageMaterial.js +26 -26
- package/src/object_pool/Pool.js +75 -75
- package/src/primitives/Arrow.js +62 -62
- package/src/primitives/Cube.js +24 -24
- package/src/primitives/HorizontalPlane.js +27 -27
- package/src/primitives/Sphere.js +22 -22
- package/src/primitives/VerticalPlane.js +26 -26
- package/src/raycast/GroupRaycaster.js +43 -43
- package/src/raycast/PlaneDragResolver.js +92 -92
- package/src/raycast/PlaneRaycastResolver.js +24 -24
- package/src/raycast/PlaneRaycaster.js +25 -25
- package/src/raycast/RaycastResolver.js +24 -24
- package/src/raycast/SurfaceDragResolver.js +80 -80
- package/src/raycast/states/BaseState.js +18 -18
- package/src/raycast/states/IdleState.js +19 -19
- package/src/raycast/states/OnRaycastEnter.js +17 -17
- package/src/raycast/states/OnRaycastExit.js +18 -18
- package/src/raycast/states/OnRaycastHover.js +27 -27
- package/src/render_mode/BaseRender.js +34 -34
- package/src/render_mode/BloomRender.js +63 -63
- package/src/render_mode/DebugNormalsRender.js +22 -22
- package/src/render_mode/DeferredRender.js +110 -110
- package/src/render_mode/NormalAORender.js +72 -72
- package/src/render_mode/NormalRender.js +38 -38
- package/src/render_mode/OutlineRender.js +157 -157
- package/src/render_mode/PlanarReflectionsRender.js +121 -121
- package/src/render_mode/UnrealBloomRender.js +123 -123
- package/src/render_mode/VRRender.js +71 -71
- package/src/render_utilities/Blitter.js +101 -101
- package/src/render_utilities/Blurrer.js +31 -31
- package/src/render_utilities/DepthAndNormalsRenderer.js +47 -47
- package/src/render_utilities/DualFilteringBlurrer.js +58 -58
- package/src/render_utilities/GaussianBlurrer.js +167 -167
- package/src/render_utilities/MedianFilter.js +68 -68
- package/src/render_utilities/ViewPositionRenderer.js +50 -50
- package/src/resource_loader/BasisLoader.js +51 -51
- package/src/resource_loader/FontLoader.js +48 -48
- package/src/resource_loader/JSONLoader.js +35 -35
- package/src/resource_loader/OBJLoader.js +48 -48
- package/src/resource_loader/PointArrayLoader.js +72 -72
- package/src/resource_loader/RGBETextureLoader.js +48 -48
- package/src/resource_loader/VideoLoader.js +32 -32
- package/src/scenes/AbstractScene.js +175 -175
- package/src/scenes/loading_states/CompilatorManager.js +41 -41
- package/src/scenes/loading_states/HighQualityLoadingState.js +28 -28
- package/src/scenes/loading_states/LoadingState.js +117 -117
- package/src/scenes/loading_states/RegularLoadingState.js +41 -41
- package/src/shaders/add/add.frag +27 -27
- package/src/shaders/anti_aliasing/fxaa.frag +72 -72
- package/src/shaders/basic_color/basic_color.frag +5 -5
- package/src/shaders/basic_color/basic_color.vert +9 -9
- package/src/shaders/basic_line/basic_line.frag +36 -36
- package/src/shaders/basic_line/basic_line.vert +37 -37
- package/src/shaders/basic_texture/basic_texture.frag +9 -9
- package/src/shaders/basic_texture/basic_texture.vert +16 -16
- package/src/shaders/bloom/bloom_compose_frag.glsl +22 -22
- package/src/shaders/bloom/cheap_bloom_compose_frag.glsl +13 -13
- package/src/shaders/box_blur/box_blur.frag +24 -24
- package/src/shaders/box_blur/compose.frag +31 -31
- package/src/shaders/clear/clear_depth_normal.frag +24 -24
- package/src/shaders/copy/copy.frag +6 -6
- package/src/shaders/copy/copy.vert +5 -5
- package/src/shaders/deferred/blit_copy.vert +11 -11
- package/src/shaders/deferred/deferred_compose.frag +59 -59
- package/src/shaders/deferred/point_light.frag +66 -66
- package/src/shaders/deferred/point_light.vert +13 -13
- package/src/shaders/depth_normals/debug_normals.frag +47 -47
- package/src/shaders/depth_normals/depth_normals.frag +30 -30
- package/src/shaders/depth_normals/depth_normals.vert +12 -12
- package/src/shaders/dual_filter_blur/alpha_filter.frag +14 -14
- package/src/shaders/dual_filter_blur/downsample.frag +21 -21
- package/src/shaders/dual_filter_blur/upsample.frag +24 -24
- package/src/shaders/edge_visualizer/edge_visualizer.frag +17 -17
- package/src/shaders/edge_visualizer/edge_visualizer.vert +15 -15
- package/src/shaders/edges/corners.frag +10 -10
- package/src/shaders/edges/corners.vert +30 -30
- package/src/shaders/edges/edges.frag +6 -6
- package/src/shaders/edges/edges.vert +27 -27
- package/src/shaders/gaussian_blur/gaussian_blur.frag +43 -43
- package/src/shaders/gaussian_blur/unreal_bloom_compose.frag +36 -36
- package/src/shaders/gpu_particles/common_utils.glsl +12 -12
- package/src/shaders/gpu_particles/generic_storage.frag +6 -6
- package/src/shaders/gpu_particles/store/store_position.vert +14 -14
- package/src/shaders/gpu_particles/update/basic_update.frag +20 -20
- package/src/shaders/gpu_particles/visualize/visualize.frag +10 -10
- package/src/shaders/gpu_particles/visualize/visualize.vert +12 -12
- package/src/shaders/grid/grid.frag +16 -16
- package/src/shaders/grid/grid.vert +9 -9
- package/src/shaders/luminosity_high_pass/luminosity_high_pass.frag +37 -37
- package/src/shaders/median_filter/median_filter.frag +134 -134
- package/src/shaders/normal/normal.frag +6 -6
- package/src/shaders/normal/normal.vert +6 -6
- package/src/shaders/sdf_text/sdf_screen_text.frag +51 -51
- package/src/shaders/sdf_text/sdf_screen_text.vert +41 -41
- package/src/shaders/sdf_text/sdf_text.frag +53 -53
- package/src/shaders/sdf_text/sdf_text.vert +41 -41
- package/src/shaders/ssao/hbao.frag +264 -264
- package/src/shaders/ssao/ssao.frag +95 -95
- package/src/shaders/ssao/ssao.vert +10 -10
- package/src/shaders/ssao/ssao_compose.frag +14 -14
- package/src/shaders/transparent_mix/copy.frag +6 -6
- package/src/shaders/transparent_mix/transparent_mix.frag +18 -18
- package/src/shaders/transparent_mix/transparent_mix.vert +7 -7
- package/src/shaders/ui/ss_texture.frag +10 -10
- package/src/shaders/ui/ss_texture.vert +31 -31
- package/src/shaders/ui/ws_texture.vert +38 -38
- package/src/shaders/ui_element/ui_element.frag +11 -11
- package/src/shaders/ui_element/ui_element.vert +32 -32
- package/src/shaders/unreal_blur/unreal_blur.frag +24 -24
- package/src/shaders/unreal_blur/unreal_compose.frag +23 -23
- package/src/shaders/write_view_position/write_view_position.frag +6 -6
- package/src/shaders/write_view_position/write_view_position.vert +8 -8
- package/src/static_batcher/BatchedMesh.js +56 -56
- package/src/static_batcher/GeometryBatch.js +308 -308
- package/src/static_batcher/GeometryBatcher.js +64 -64
- package/src/static_batcher/MeshBatcher.js +58 -58
- package/src/ui/ui_element_position/ScreenSpacePosition.js +16 -16
- package/src/ui/ui_element_position/WorldSpacePosition.js +23 -23
- package/src/ui/ui_element_state/OnIdle.js +24 -24
- package/src/ui/ui_element_state/OnMouseEnter.js +39 -39
- package/src/ui/ui_element_state/OnMouseExit.js +22 -22
- package/src/ui/ui_element_state/OnMouseHover.js +46 -46
- package/src/ui/ui_element_state/UIElementState.js +34 -34
- package/src/utilities/ArrayUtilities.js +57 -57
- package/src/utilities/CameraUtilities.js +283 -283
- package/src/utilities/EasingFunctions.js +231 -231
- package/src/utilities/FrustumPointFitter.js +257 -257
- package/src/utilities/GeometryUtilities.js +76 -76
- package/src/utilities/HTMLUtilities.js +76 -76
- package/src/utilities/ImageUtilities.js +28 -28
- package/src/utilities/MeshSampler.js +206 -206
- package/src/utilities/ModelUtilities.js +162 -162
- package/src/utilities/OMath.js +158 -158
- package/src/utilities/OrthographicFrustumPointFitter.js +49 -49
- package/src/utilities/PerspectiveFrustumPointFitter.js +254 -254
- package/src/utilities/StringUtilities.js +43 -43
- package/src/utilities/TimeUtilities.js +24 -24
- package/src/utilities/Validation.js +36 -36
- package/src/view_components/ApplicationView.js +73 -73
- package/src/view_components/TransitionManager.js +75 -75
- package/src/view_components/ViewComponent.js +61 -61
- package/src/view_components/ViewComponentManager.js +69 -69
- package/src/view_components/ViewManager.js +145 -145
- package/src/view_components/ViewState.js +49 -49
- package/src/view_components/transition/ActionSequencerBuilder.js +124 -124
- package/src/view_components/transition/DrawIOAnimationSheet.js +92 -92
- package/src/view_components/transition/TransitionTable.js +54 -54
- package/src/view_components/transition/ViewStateTransitionHandler.js +106 -106
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
class ArrayUtilities
|
|
2
|
-
{
|
|
3
|
-
constructor()
|
|
4
|
-
{}
|
|
5
|
-
|
|
6
|
-
static merge_from_to(source, target)
|
|
7
|
-
{
|
|
8
|
-
target.push.apply(target, source);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static expand_vec3_array(array, size)
|
|
12
|
-
{
|
|
13
|
-
const items_left_count = size - array.length;
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < items_left_count; i++)
|
|
16
|
-
{
|
|
17
|
-
array.push(array[i].clone());
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static remove_elem(array, elem)
|
|
22
|
-
{
|
|
23
|
-
const index = array.indexOf(elem);
|
|
24
|
-
if (index > -1)
|
|
25
|
-
{
|
|
26
|
-
array.splice(index, 1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static get_closest_point(points, target)
|
|
31
|
-
{
|
|
32
|
-
let closest_point = points[0];
|
|
33
|
-
let closest_distance = closest_point.distanceTo(target);
|
|
34
|
-
for (let i = 1; i < points.length; i++)
|
|
35
|
-
{
|
|
36
|
-
if (points[i].distanceTo(target) < closest_distance)
|
|
37
|
-
{
|
|
38
|
-
closest_point = points[i];
|
|
39
|
-
closest_distance = points[i].distanceTo(target);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return closest_point;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static object_values_to_array(obj)
|
|
46
|
-
{
|
|
47
|
-
const ids = Object.keys(obj);
|
|
48
|
-
const arr = [];
|
|
49
|
-
for (let i = 0; i < ids.length; i++)
|
|
50
|
-
{
|
|
51
|
-
arr.push(obj[ids[i]]);
|
|
52
|
-
}
|
|
53
|
-
return arr;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { ArrayUtilities };
|
|
1
|
+
class ArrayUtilities
|
|
2
|
+
{
|
|
3
|
+
constructor()
|
|
4
|
+
{}
|
|
5
|
+
|
|
6
|
+
static merge_from_to(source, target)
|
|
7
|
+
{
|
|
8
|
+
target.push.apply(target, source);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static expand_vec3_array(array, size)
|
|
12
|
+
{
|
|
13
|
+
const items_left_count = size - array.length;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < items_left_count; i++)
|
|
16
|
+
{
|
|
17
|
+
array.push(array[i].clone());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static remove_elem(array, elem)
|
|
22
|
+
{
|
|
23
|
+
const index = array.indexOf(elem);
|
|
24
|
+
if (index > -1)
|
|
25
|
+
{
|
|
26
|
+
array.splice(index, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static get_closest_point(points, target)
|
|
31
|
+
{
|
|
32
|
+
let closest_point = points[0];
|
|
33
|
+
let closest_distance = closest_point.distanceTo(target);
|
|
34
|
+
for (let i = 1; i < points.length; i++)
|
|
35
|
+
{
|
|
36
|
+
if (points[i].distanceTo(target) < closest_distance)
|
|
37
|
+
{
|
|
38
|
+
closest_point = points[i];
|
|
39
|
+
closest_distance = points[i].distanceTo(target);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return closest_point;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static object_values_to_array(obj)
|
|
46
|
+
{
|
|
47
|
+
const ids = Object.keys(obj);
|
|
48
|
+
const arr = [];
|
|
49
|
+
for (let i = 0; i < ids.length; i++)
|
|
50
|
+
{
|
|
51
|
+
arr.push(obj[ids[i]]);
|
|
52
|
+
}
|
|
53
|
+
return arr;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { ArrayUtilities };
|
|
@@ -1,283 +1,283 @@
|
|
|
1
|
-
import { CameraManager } from '../CameraManager';
|
|
2
|
-
import { OMath } from '../utilities/OMath';
|
|
3
|
-
import { OScreen } from '../OScreen';
|
|
4
|
-
|
|
5
|
-
import { Vector3 } from 'three';
|
|
6
|
-
import { Matrix4 } from 'three';
|
|
7
|
-
import { Plane } from 'three';
|
|
8
|
-
import { Ray } from 'three';
|
|
9
|
-
import { Sphere } from 'three';
|
|
10
|
-
import { Box3 } from 'three';
|
|
11
|
-
import { PerspectiveFrustumPointFitter } from './PerspectiveFrustumPointFitter';
|
|
12
|
-
import { OrthographicFrustumPointFitter } from './OrthographicFrustumPointFitter';
|
|
13
|
-
|
|
14
|
-
class CameraUtilities
|
|
15
|
-
{
|
|
16
|
-
init(input)
|
|
17
|
-
{
|
|
18
|
-
this.tmp_mat = new Matrix4();
|
|
19
|
-
this.plane = new Plane();
|
|
20
|
-
this.ray = new Ray();
|
|
21
|
-
|
|
22
|
-
this.tmp_size = new Vector3();
|
|
23
|
-
this.tmp_unproj = new Vector3();
|
|
24
|
-
|
|
25
|
-
this.input = input;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get_up_dir(camera)
|
|
29
|
-
{
|
|
30
|
-
camera = camera || CameraManager.current;
|
|
31
|
-
const tmp_vec = new Vector3();
|
|
32
|
-
|
|
33
|
-
tmp_vec.set(0, 1, 0);
|
|
34
|
-
tmp_vec.applyQuaternion(camera.quaternion);
|
|
35
|
-
|
|
36
|
-
return tmp_vec;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get_forward_dir(camera)
|
|
40
|
-
{
|
|
41
|
-
camera = camera || CameraManager.current;
|
|
42
|
-
const tmp_vec = new Vector3();
|
|
43
|
-
|
|
44
|
-
tmp_vec.set(0, 0, -1);
|
|
45
|
-
tmp_vec.applyQuaternion(camera.quaternion);
|
|
46
|
-
|
|
47
|
-
return tmp_vec;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get_right_dir(camera)
|
|
51
|
-
{
|
|
52
|
-
camera = camera || CameraManager.current;
|
|
53
|
-
const tmp_vec = new Vector3();
|
|
54
|
-
|
|
55
|
-
tmp_vec.set(1, 0, 0);
|
|
56
|
-
tmp_vec.applyQuaternion(camera.quaternion);
|
|
57
|
-
return tmp_vec;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
unproject_mouse_position(NDC, camera)
|
|
61
|
-
{
|
|
62
|
-
camera = camera || CameraManager.current;
|
|
63
|
-
const tmp_vec = new Vector3();
|
|
64
|
-
|
|
65
|
-
const v_fov = (camera.fov / 2) * Math.PI / 180;
|
|
66
|
-
const h_fov = (2 * Math.atan(Math.tan(v_fov) * camera.aspect)) / 2;
|
|
67
|
-
|
|
68
|
-
const distV = Math.tan(v_fov) * camera.far;
|
|
69
|
-
const distH = Math.tan(h_fov) * camera.far;
|
|
70
|
-
|
|
71
|
-
tmp_vec.set(distH * NDC.x, distV * NDC.y, -camera.far).normalize();
|
|
72
|
-
|
|
73
|
-
return tmp_vec.applyQuaternion(camera.quaternion);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get_plane_intersection(plane_position, plane_normal, NDC, camera)
|
|
77
|
-
{
|
|
78
|
-
camera = camera || CameraManager.current;
|
|
79
|
-
NDC = NDC || this.input.NDC;
|
|
80
|
-
|
|
81
|
-
const tmp_vec = new Vector3();
|
|
82
|
-
|
|
83
|
-
this.plane.setFromNormalAndCoplanarPoint(plane_normal || this.get_forward_dir(camera), plane_position);
|
|
84
|
-
if (camera.isPerspectiveCamera)
|
|
85
|
-
{
|
|
86
|
-
this.ray.set(camera.position, this.unproject_mouse_position(NDC, camera));
|
|
87
|
-
}
|
|
88
|
-
else
|
|
89
|
-
{
|
|
90
|
-
const pos = new Vector3(NDC.x * camera.right, NDC.y * camera.top, 0);
|
|
91
|
-
pos.applyQuaternion(camera.quaternion);
|
|
92
|
-
pos.add(camera.position);
|
|
93
|
-
const dir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
94
|
-
this.ray.set(pos, dir);
|
|
95
|
-
}
|
|
96
|
-
this.ray.intersectPlane(this.plane, tmp_vec);
|
|
97
|
-
|
|
98
|
-
return tmp_vec;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
fit_points_on_camera(points, zoom_scale = 1)
|
|
102
|
-
{
|
|
103
|
-
const points_sphere = new Sphere().setFromPoints(points);
|
|
104
|
-
const world_space_center = points_sphere.center;
|
|
105
|
-
const camera_forward = this.get_forward_dir(CameraManager.current).clone();
|
|
106
|
-
|
|
107
|
-
const plane = new Plane().setFromNormalAndCoplanarPoint(camera_forward, world_space_center);
|
|
108
|
-
|
|
109
|
-
const points_on_plane = OMath.project_points_on_plane(points, plane);
|
|
110
|
-
|
|
111
|
-
const projected_points_center = new Vector3();
|
|
112
|
-
let box = new Box3().setFromPoints(points_on_plane);
|
|
113
|
-
box.getCenter(projected_points_center);
|
|
114
|
-
|
|
115
|
-
const up = new Vector3(0, 1, 0).applyQuaternion(CameraManager.current.quaternion);
|
|
116
|
-
const right = up.clone().cross(camera_forward).normalize();
|
|
117
|
-
const mat = new Matrix4().set(right.x, up.x, camera_forward.x, world_space_center.x,
|
|
118
|
-
right.y, up.y, camera_forward.y, world_space_center.y,
|
|
119
|
-
right.z, up.z, camera_forward.z, world_space_center.z,
|
|
120
|
-
0, 0, 0, 1);
|
|
121
|
-
|
|
122
|
-
const inverse_mat = new Matrix4().getInverse(mat);
|
|
123
|
-
for (let i = 0; i < points_on_plane.length; i++)
|
|
124
|
-
{
|
|
125
|
-
points_on_plane[i].applyMatrix4(inverse_mat);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const size = new Vector3();
|
|
129
|
-
box = new Box3().setFromPoints(points_on_plane);
|
|
130
|
-
box.getSize(size);
|
|
131
|
-
size.multiplyScalar(zoom_scale);
|
|
132
|
-
const projected_center = new Vector3();
|
|
133
|
-
box.getCenter(projected_center);
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
position: projected_points_center,
|
|
137
|
-
zoom: this.get_zoom_to_fit_rect(size.x / 2, size.y / 2)
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get_zoom_to_fit_rect(width, height)
|
|
142
|
-
{
|
|
143
|
-
const v_fov = (CameraManager.current.fov / 2) * Math.PI / 180;
|
|
144
|
-
const h_fov = (2 * Math.atan(Math.tan(v_fov) * CameraManager.current.aspect)) / 2;
|
|
145
|
-
|
|
146
|
-
const distV = height / Math.tan(v_fov);
|
|
147
|
-
const distH = width / Math.tan(h_fov);
|
|
148
|
-
|
|
149
|
-
return Math.max(Math.abs(distH), Math.abs(distV));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get_zoom_to_fit_box(bb, camera)
|
|
153
|
-
{
|
|
154
|
-
if (camera.isOrthographicCamera)
|
|
155
|
-
{
|
|
156
|
-
bb.getSize(this.tmp_size);
|
|
157
|
-
|
|
158
|
-
const obj_x = this.tmp_size.x;
|
|
159
|
-
const obj_y = this.tmp_size.y;
|
|
160
|
-
const object_aspect = obj_x / obj_y;
|
|
161
|
-
if (OScreen.aspect_ratio / object_aspect > 1)
|
|
162
|
-
{
|
|
163
|
-
return OScreen.height / obj_y;
|
|
164
|
-
}
|
|
165
|
-
else
|
|
166
|
-
{
|
|
167
|
-
return OScreen.width / obj_x;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else
|
|
171
|
-
{
|
|
172
|
-
// return this.fit_points_on_camera([bb.min, bb.max], 1).zoom;
|
|
173
|
-
const size = new Vector3();
|
|
174
|
-
bb.getSize(size);
|
|
175
|
-
return this.get_zoom_to_fit_rect(size.x, size.y);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
get_html_screen_pos(object, camera)
|
|
180
|
-
{
|
|
181
|
-
camera = camera || CameraManager.current;
|
|
182
|
-
const tmp_vec = new Vector3();
|
|
183
|
-
|
|
184
|
-
object.getWorldPosition(tmp_vec);
|
|
185
|
-
tmp_vec.project(camera);
|
|
186
|
-
|
|
187
|
-
tmp_vec.x = (tmp_vec.x * 0.5 + 0.5) * (OScreen.width);
|
|
188
|
-
tmp_vec.y = (1 - (tmp_vec.y * 0.5 + 0.5)) * OScreen.height;
|
|
189
|
-
return tmp_vec;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
world_pos_to_screen(pos, camera)
|
|
193
|
-
{
|
|
194
|
-
camera = camera || CameraManager.current;
|
|
195
|
-
const tmp_vec = new Vector3();
|
|
196
|
-
|
|
197
|
-
tmp_vec.copy(pos);
|
|
198
|
-
tmp_vec.project(camera);
|
|
199
|
-
|
|
200
|
-
tmp_vec.x = (tmp_vec.x * 0.5 + 0.5) * (OScreen.width);
|
|
201
|
-
tmp_vec.y = (1 - (tmp_vec.y * 0.5 + 0.5)) * OScreen.height;
|
|
202
|
-
return tmp_vec;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
update_projection(camera)
|
|
206
|
-
{
|
|
207
|
-
camera.left = -OScreen.width / 2;
|
|
208
|
-
camera.right = OScreen.width / 2;
|
|
209
|
-
camera.top = OScreen.height / 2;
|
|
210
|
-
camera.bottom = -OScreen.height / 2;
|
|
211
|
-
camera.aspect = OScreen.aspect_ratio;
|
|
212
|
-
camera.updateProjectionMatrix(true);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
fit_bounding_box_points(camera, bb, scale = 1)
|
|
216
|
-
{
|
|
217
|
-
const dir = new Vector3();
|
|
218
|
-
dir.copy(bb.max).sub(bb.min);
|
|
219
|
-
|
|
220
|
-
const p1 = bb.min.clone();
|
|
221
|
-
|
|
222
|
-
const p2 = p1.clone().add(new Vector3(dir.x, 0, 0));
|
|
223
|
-
const p3 = p1.clone().add(new Vector3(0, dir.y, 0));
|
|
224
|
-
const p4 = p1.clone().add(new Vector3(0, 0, dir.z));
|
|
225
|
-
|
|
226
|
-
const p5 = p1.clone().add(new Vector3(dir.x, 0, dir.z));
|
|
227
|
-
const p6 = p1.clone().add(new Vector3(0, dir.y, dir.z));
|
|
228
|
-
const p7 = bb.max.clone();
|
|
229
|
-
const p8 = p1.clone().add(new Vector3(dir.x, dir.y, 0));
|
|
230
|
-
return this.fit_points(camera, [p1, p2, p3, p4, p5, p6, p7, p8], scale);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
fit_points(camera, points, zoom_scale = 1)
|
|
234
|
-
{
|
|
235
|
-
if (camera.isPerspectiveCamera)
|
|
236
|
-
{
|
|
237
|
-
const camera_forward_dir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
238
|
-
const camera_backward_dir = camera_forward_dir.clone().multiplyScalar(-1);
|
|
239
|
-
|
|
240
|
-
const fitter = new PerspectiveFrustumPointFitter();
|
|
241
|
-
|
|
242
|
-
const aspect_ratio = OScreen.aspect_ratio;
|
|
243
|
-
|
|
244
|
-
const camera_pos = fitter.fit_points(points, camera.quaternion, camera.fov * zoom_scale, aspect_ratio);
|
|
245
|
-
const box = new Box3().setFromPoints(points);
|
|
246
|
-
const center = new Vector3();
|
|
247
|
-
box.getCenter(center);
|
|
248
|
-
|
|
249
|
-
const reference_position_plane = new Plane().setFromNormalAndCoplanarPoint(camera_backward_dir, center);
|
|
250
|
-
|
|
251
|
-
const camera_ray = new Ray(camera_pos, camera_forward_dir);
|
|
252
|
-
|
|
253
|
-
const reference_position = new Vector3();
|
|
254
|
-
camera_ray.intersectPlane(reference_position_plane, reference_position);
|
|
255
|
-
|
|
256
|
-
const zoom = camera_pos.distanceTo(reference_position);
|
|
257
|
-
|
|
258
|
-
return {
|
|
259
|
-
zoom: zoom,
|
|
260
|
-
reference_position: reference_position,
|
|
261
|
-
camera_position: camera_pos
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
else
|
|
265
|
-
{
|
|
266
|
-
const fitter = new OrthographicFrustumPointFitter();
|
|
267
|
-
const result = fitter.fit_points(points, this.reference_rotation, camera.fov * zoom_scale, OScreen.aspect_ratio);
|
|
268
|
-
|
|
269
|
-
this.reference_position.copy(result.center);
|
|
270
|
-
this.reference_zoom = result.distance_to_center;
|
|
271
|
-
|
|
272
|
-
const forward = new Vector3(0, 0, 1).applyQuaternion(camera.quaternion);
|
|
273
|
-
return {
|
|
274
|
-
zoom: result.distance_to_center,
|
|
275
|
-
reference_position: result.center,
|
|
276
|
-
camera_position: forward.multiplyScalar(result.distance_to_center)
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const camera_utilities = new CameraUtilities();
|
|
283
|
-
export { camera_utilities as CameraUtilities };
|
|
1
|
+
import { CameraManager } from '../CameraManager';
|
|
2
|
+
import { OMath } from '../utilities/OMath';
|
|
3
|
+
import { OScreen } from '../OScreen';
|
|
4
|
+
|
|
5
|
+
import { Vector3 } from 'three';
|
|
6
|
+
import { Matrix4 } from 'three';
|
|
7
|
+
import { Plane } from 'three';
|
|
8
|
+
import { Ray } from 'three';
|
|
9
|
+
import { Sphere } from 'three';
|
|
10
|
+
import { Box3 } from 'three';
|
|
11
|
+
import { PerspectiveFrustumPointFitter } from './PerspectiveFrustumPointFitter';
|
|
12
|
+
import { OrthographicFrustumPointFitter } from './OrthographicFrustumPointFitter';
|
|
13
|
+
|
|
14
|
+
class CameraUtilities
|
|
15
|
+
{
|
|
16
|
+
init(input)
|
|
17
|
+
{
|
|
18
|
+
this.tmp_mat = new Matrix4();
|
|
19
|
+
this.plane = new Plane();
|
|
20
|
+
this.ray = new Ray();
|
|
21
|
+
|
|
22
|
+
this.tmp_size = new Vector3();
|
|
23
|
+
this.tmp_unproj = new Vector3();
|
|
24
|
+
|
|
25
|
+
this.input = input;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get_up_dir(camera)
|
|
29
|
+
{
|
|
30
|
+
camera = camera || CameraManager.current;
|
|
31
|
+
const tmp_vec = new Vector3();
|
|
32
|
+
|
|
33
|
+
tmp_vec.set(0, 1, 0);
|
|
34
|
+
tmp_vec.applyQuaternion(camera.quaternion);
|
|
35
|
+
|
|
36
|
+
return tmp_vec;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get_forward_dir(camera)
|
|
40
|
+
{
|
|
41
|
+
camera = camera || CameraManager.current;
|
|
42
|
+
const tmp_vec = new Vector3();
|
|
43
|
+
|
|
44
|
+
tmp_vec.set(0, 0, -1);
|
|
45
|
+
tmp_vec.applyQuaternion(camera.quaternion);
|
|
46
|
+
|
|
47
|
+
return tmp_vec;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get_right_dir(camera)
|
|
51
|
+
{
|
|
52
|
+
camera = camera || CameraManager.current;
|
|
53
|
+
const tmp_vec = new Vector3();
|
|
54
|
+
|
|
55
|
+
tmp_vec.set(1, 0, 0);
|
|
56
|
+
tmp_vec.applyQuaternion(camera.quaternion);
|
|
57
|
+
return tmp_vec;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
unproject_mouse_position(NDC, camera)
|
|
61
|
+
{
|
|
62
|
+
camera = camera || CameraManager.current;
|
|
63
|
+
const tmp_vec = new Vector3();
|
|
64
|
+
|
|
65
|
+
const v_fov = (camera.fov / 2) * Math.PI / 180;
|
|
66
|
+
const h_fov = (2 * Math.atan(Math.tan(v_fov) * camera.aspect)) / 2;
|
|
67
|
+
|
|
68
|
+
const distV = Math.tan(v_fov) * camera.far;
|
|
69
|
+
const distH = Math.tan(h_fov) * camera.far;
|
|
70
|
+
|
|
71
|
+
tmp_vec.set(distH * NDC.x, distV * NDC.y, -camera.far).normalize();
|
|
72
|
+
|
|
73
|
+
return tmp_vec.applyQuaternion(camera.quaternion);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get_plane_intersection(plane_position, plane_normal, NDC, camera)
|
|
77
|
+
{
|
|
78
|
+
camera = camera || CameraManager.current;
|
|
79
|
+
NDC = NDC || this.input.NDC;
|
|
80
|
+
|
|
81
|
+
const tmp_vec = new Vector3();
|
|
82
|
+
|
|
83
|
+
this.plane.setFromNormalAndCoplanarPoint(plane_normal || this.get_forward_dir(camera), plane_position);
|
|
84
|
+
if (camera.isPerspectiveCamera)
|
|
85
|
+
{
|
|
86
|
+
this.ray.set(camera.position, this.unproject_mouse_position(NDC, camera));
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
const pos = new Vector3(NDC.x * camera.right, NDC.y * camera.top, 0);
|
|
91
|
+
pos.applyQuaternion(camera.quaternion);
|
|
92
|
+
pos.add(camera.position);
|
|
93
|
+
const dir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
94
|
+
this.ray.set(pos, dir);
|
|
95
|
+
}
|
|
96
|
+
this.ray.intersectPlane(this.plane, tmp_vec);
|
|
97
|
+
|
|
98
|
+
return tmp_vec;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fit_points_on_camera(points, zoom_scale = 1)
|
|
102
|
+
{
|
|
103
|
+
const points_sphere = new Sphere().setFromPoints(points);
|
|
104
|
+
const world_space_center = points_sphere.center;
|
|
105
|
+
const camera_forward = this.get_forward_dir(CameraManager.current).clone();
|
|
106
|
+
|
|
107
|
+
const plane = new Plane().setFromNormalAndCoplanarPoint(camera_forward, world_space_center);
|
|
108
|
+
|
|
109
|
+
const points_on_plane = OMath.project_points_on_plane(points, plane);
|
|
110
|
+
|
|
111
|
+
const projected_points_center = new Vector3();
|
|
112
|
+
let box = new Box3().setFromPoints(points_on_plane);
|
|
113
|
+
box.getCenter(projected_points_center);
|
|
114
|
+
|
|
115
|
+
const up = new Vector3(0, 1, 0).applyQuaternion(CameraManager.current.quaternion);
|
|
116
|
+
const right = up.clone().cross(camera_forward).normalize();
|
|
117
|
+
const mat = new Matrix4().set(right.x, up.x, camera_forward.x, world_space_center.x,
|
|
118
|
+
right.y, up.y, camera_forward.y, world_space_center.y,
|
|
119
|
+
right.z, up.z, camera_forward.z, world_space_center.z,
|
|
120
|
+
0, 0, 0, 1);
|
|
121
|
+
|
|
122
|
+
const inverse_mat = new Matrix4().getInverse(mat);
|
|
123
|
+
for (let i = 0; i < points_on_plane.length; i++)
|
|
124
|
+
{
|
|
125
|
+
points_on_plane[i].applyMatrix4(inverse_mat);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const size = new Vector3();
|
|
129
|
+
box = new Box3().setFromPoints(points_on_plane);
|
|
130
|
+
box.getSize(size);
|
|
131
|
+
size.multiplyScalar(zoom_scale);
|
|
132
|
+
const projected_center = new Vector3();
|
|
133
|
+
box.getCenter(projected_center);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
position: projected_points_center,
|
|
137
|
+
zoom: this.get_zoom_to_fit_rect(size.x / 2, size.y / 2)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get_zoom_to_fit_rect(width, height)
|
|
142
|
+
{
|
|
143
|
+
const v_fov = (CameraManager.current.fov / 2) * Math.PI / 180;
|
|
144
|
+
const h_fov = (2 * Math.atan(Math.tan(v_fov) * CameraManager.current.aspect)) / 2;
|
|
145
|
+
|
|
146
|
+
const distV = height / Math.tan(v_fov);
|
|
147
|
+
const distH = width / Math.tan(h_fov);
|
|
148
|
+
|
|
149
|
+
return Math.max(Math.abs(distH), Math.abs(distV));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get_zoom_to_fit_box(bb, camera)
|
|
153
|
+
{
|
|
154
|
+
if (camera.isOrthographicCamera)
|
|
155
|
+
{
|
|
156
|
+
bb.getSize(this.tmp_size);
|
|
157
|
+
|
|
158
|
+
const obj_x = this.tmp_size.x;
|
|
159
|
+
const obj_y = this.tmp_size.y;
|
|
160
|
+
const object_aspect = obj_x / obj_y;
|
|
161
|
+
if (OScreen.aspect_ratio / object_aspect > 1)
|
|
162
|
+
{
|
|
163
|
+
return OScreen.height / obj_y;
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
{
|
|
167
|
+
return OScreen.width / obj_x;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else
|
|
171
|
+
{
|
|
172
|
+
// return this.fit_points_on_camera([bb.min, bb.max], 1).zoom;
|
|
173
|
+
const size = new Vector3();
|
|
174
|
+
bb.getSize(size);
|
|
175
|
+
return this.get_zoom_to_fit_rect(size.x, size.y);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
get_html_screen_pos(object, camera)
|
|
180
|
+
{
|
|
181
|
+
camera = camera || CameraManager.current;
|
|
182
|
+
const tmp_vec = new Vector3();
|
|
183
|
+
|
|
184
|
+
object.getWorldPosition(tmp_vec);
|
|
185
|
+
tmp_vec.project(camera);
|
|
186
|
+
|
|
187
|
+
tmp_vec.x = (tmp_vec.x * 0.5 + 0.5) * (OScreen.width);
|
|
188
|
+
tmp_vec.y = (1 - (tmp_vec.y * 0.5 + 0.5)) * OScreen.height;
|
|
189
|
+
return tmp_vec;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
world_pos_to_screen(pos, camera)
|
|
193
|
+
{
|
|
194
|
+
camera = camera || CameraManager.current;
|
|
195
|
+
const tmp_vec = new Vector3();
|
|
196
|
+
|
|
197
|
+
tmp_vec.copy(pos);
|
|
198
|
+
tmp_vec.project(camera);
|
|
199
|
+
|
|
200
|
+
tmp_vec.x = (tmp_vec.x * 0.5 + 0.5) * (OScreen.width);
|
|
201
|
+
tmp_vec.y = (1 - (tmp_vec.y * 0.5 + 0.5)) * OScreen.height;
|
|
202
|
+
return tmp_vec;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
update_projection(camera)
|
|
206
|
+
{
|
|
207
|
+
camera.left = -OScreen.width / 2;
|
|
208
|
+
camera.right = OScreen.width / 2;
|
|
209
|
+
camera.top = OScreen.height / 2;
|
|
210
|
+
camera.bottom = -OScreen.height / 2;
|
|
211
|
+
camera.aspect = OScreen.aspect_ratio;
|
|
212
|
+
camera.updateProjectionMatrix(true);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
fit_bounding_box_points(camera, bb, scale = 1)
|
|
216
|
+
{
|
|
217
|
+
const dir = new Vector3();
|
|
218
|
+
dir.copy(bb.max).sub(bb.min);
|
|
219
|
+
|
|
220
|
+
const p1 = bb.min.clone();
|
|
221
|
+
|
|
222
|
+
const p2 = p1.clone().add(new Vector3(dir.x, 0, 0));
|
|
223
|
+
const p3 = p1.clone().add(new Vector3(0, dir.y, 0));
|
|
224
|
+
const p4 = p1.clone().add(new Vector3(0, 0, dir.z));
|
|
225
|
+
|
|
226
|
+
const p5 = p1.clone().add(new Vector3(dir.x, 0, dir.z));
|
|
227
|
+
const p6 = p1.clone().add(new Vector3(0, dir.y, dir.z));
|
|
228
|
+
const p7 = bb.max.clone();
|
|
229
|
+
const p8 = p1.clone().add(new Vector3(dir.x, dir.y, 0));
|
|
230
|
+
return this.fit_points(camera, [p1, p2, p3, p4, p5, p6, p7, p8], scale);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
fit_points(camera, points, zoom_scale = 1)
|
|
234
|
+
{
|
|
235
|
+
if (camera.isPerspectiveCamera)
|
|
236
|
+
{
|
|
237
|
+
const camera_forward_dir = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
238
|
+
const camera_backward_dir = camera_forward_dir.clone().multiplyScalar(-1);
|
|
239
|
+
|
|
240
|
+
const fitter = new PerspectiveFrustumPointFitter();
|
|
241
|
+
|
|
242
|
+
const aspect_ratio = OScreen.aspect_ratio;
|
|
243
|
+
|
|
244
|
+
const camera_pos = fitter.fit_points(points, camera.quaternion, camera.fov * zoom_scale, aspect_ratio);
|
|
245
|
+
const box = new Box3().setFromPoints(points);
|
|
246
|
+
const center = new Vector3();
|
|
247
|
+
box.getCenter(center);
|
|
248
|
+
|
|
249
|
+
const reference_position_plane = new Plane().setFromNormalAndCoplanarPoint(camera_backward_dir, center);
|
|
250
|
+
|
|
251
|
+
const camera_ray = new Ray(camera_pos, camera_forward_dir);
|
|
252
|
+
|
|
253
|
+
const reference_position = new Vector3();
|
|
254
|
+
camera_ray.intersectPlane(reference_position_plane, reference_position);
|
|
255
|
+
|
|
256
|
+
const zoom = camera_pos.distanceTo(reference_position);
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
zoom: zoom,
|
|
260
|
+
reference_position: reference_position,
|
|
261
|
+
camera_position: camera_pos
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
{
|
|
266
|
+
const fitter = new OrthographicFrustumPointFitter();
|
|
267
|
+
const result = fitter.fit_points(points, this.reference_rotation, camera.fov * zoom_scale, OScreen.aspect_ratio);
|
|
268
|
+
|
|
269
|
+
this.reference_position.copy(result.center);
|
|
270
|
+
this.reference_zoom = result.distance_to_center;
|
|
271
|
+
|
|
272
|
+
const forward = new Vector3(0, 0, 1).applyQuaternion(camera.quaternion);
|
|
273
|
+
return {
|
|
274
|
+
zoom: result.distance_to_center,
|
|
275
|
+
reference_position: result.center,
|
|
276
|
+
camera_position: forward.multiplyScalar(result.distance_to_center)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const camera_utilities = new CameraUtilities();
|
|
283
|
+
export { camera_utilities as CameraUtilities };
|