ohzi-core 6.16.1 → 7.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohzi-core",
3
- "version": "6.16.1",
3
+ "version": "7.0.1",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
@@ -37,7 +37,7 @@
37
37
  "homepage": "https://github.com/ohzinteractive/core",
38
38
  "dependencies": {
39
39
  "pit-js": "1.9.1",
40
- "three": "^0.137.0"
40
+ "three": "0.146.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "cross-var": "^1.1.0",
package/src/Debug.js CHANGED
@@ -11,7 +11,7 @@ import { Vector3 } from 'three';
11
11
  import { LineBasicMaterial } from 'three';
12
12
  import { BufferGeometry } from 'three';
13
13
  import { Line } from 'three';
14
- import { PlaneBufferGeometry } from 'three';
14
+ import { PlaneGeometry } from 'three';
15
15
  import { ShaderMaterial } from 'three';
16
16
  import { Vector4 } from 'three';
17
17
  import { Mesh } from 'three';
@@ -136,7 +136,7 @@ class Debug
136
136
 
137
137
  draw_plane(width, height, color)
138
138
  {
139
- const geometry = new PlaneBufferGeometry(width, height);
139
+ const geometry = new PlaneGeometry(width, height);
140
140
  const material = new ShaderMaterial({
141
141
  uniforms: {
142
142
  _Color: { value: new Vector4(0, 1, 0, 0.2) }
@@ -236,7 +236,7 @@ class Debug
236
236
 
237
237
  draw_texture(tex, w, h)
238
238
  {
239
- const mesh = new Mesh(new PlaneBufferGeometry(1, 1), new ScreenSpaceTextureMaterial());
239
+ const mesh = new Mesh(new PlaneGeometry(1, 1), new ScreenSpaceTextureMaterial());
240
240
  this.display_texture_meshes.push(mesh);
241
241
  this.scene.add(mesh);
242
242
 
package/src/UI.js CHANGED
@@ -13,11 +13,11 @@ class UI
13
13
  this.ui_elements = [];
14
14
  this._tmp_normalized_pos = new Vector2();
15
15
  this.ss_scene = new Scene();
16
- this.ss_scene.autoUpdate = false;
16
+ this.ss_scene.matrixWorldAutoUpdate = false;
17
17
  this.ss_scene.frustumCulled = false;
18
18
 
19
19
  this.ws_scene = new Scene();
20
- this.ws_scene.autoUpdate = false;
20
+ this.ws_scene.matrixWorldAutoUpdate = false;
21
21
  this.ws_scene.frustumCulled = false;
22
22
 
23
23
  this.ss_camera = new OrthographicCamera(-1, 1, 1, -1, -100, 100);
@@ -1,5 +1,4 @@
1
1
 
2
- import { Math as TMath } from 'three';
3
2
  import OMath from '../utilities/OMath';
4
3
 
5
4
  export default class ActionSequencer
@@ -61,19 +60,19 @@ export default class ActionSequencer
61
60
 
62
61
  set_progress(time)
63
62
  {
64
- this.elapsed_time = TMath.clamp(time, 0, this.duration);
63
+ this.elapsed_time = OMath.clamp(time, 0, this.duration);
65
64
  this.__play_clips(this.elapsed_time, this.elapsed_time);
66
65
  }
67
66
 
68
67
  set_normalized_progress(t)
69
68
  {
70
- this.elapsed_time = TMath.clamp(t, 0, 1) * this.duration;
69
+ this.elapsed_time = OMath.clamp(t, 0, 1) * this.duration;
71
70
  this.__play_clips(this.elapsed_time, this.elapsed_time);
72
71
  }
73
72
 
74
73
  get_progress()
75
74
  {
76
- return TMath.clamp(this.elapsed_time / this.get_duration(), 0, 1);
75
+ return OMath.clamp(this.elapsed_time / this.get_duration(), 0, 1);
77
76
  }
78
77
 
79
78
  is_finished()
@@ -180,7 +179,7 @@ export default class ActionSequencer
180
179
  {
181
180
  this.tmp_t = this.__linear_map_01(time, keyframe.from, keyframe.to);
182
181
 
183
- return keyframe.interpolator.evaluate(TMath.clamp(this.tmp_t, 0, 1));
182
+ return keyframe.interpolator.evaluate(OMath.clamp(this.tmp_t, 0, 1));
184
183
  }
185
184
 
186
185
  get_keyframes(channel_name)
@@ -1,5 +1,5 @@
1
1
  import ActionInterpolator from './ActionInterpolator';
2
- import { Math as TMath } from 'three';
2
+ import OMath from '../utilities/OMath';
3
3
 
4
4
  export default class NumberInterpolator extends ActionInterpolator
5
5
  {
@@ -15,11 +15,11 @@ export default class NumberInterpolator extends ActionInterpolator
15
15
 
16
16
  update(context, t)
17
17
  {
18
- context[this.attribute_name] = TMath.lerp(this.from, this.to, this.easing_function(t));
18
+ context[this.attribute_name] = OMath.lerp(this.from, this.to, this.easing_function(t));
19
19
  }
20
20
 
21
21
  evaluate(t)
22
22
  {
23
- return TMath.lerp(this.from, this.to, this.easing_function(t));
23
+ return OMath.lerp(this.from, this.to, this.easing_function(t));
24
24
  }
25
25
  }
@@ -13,7 +13,7 @@ import { EdgesGeometry } from 'three';
13
13
  import { LineSegments } from 'three';
14
14
  import { LineBasicMaterial } from 'three';
15
15
  import { Vector3 } from 'three';
16
- import { PlaneBufferGeometry } from 'three';
16
+ import { PlaneGeometry } from 'three';
17
17
  import { BufferAttribute } from 'three';
18
18
 
19
19
  export default class EdgeMesh extends Object3D
@@ -82,7 +82,7 @@ export default class EdgeMesh extends Object3D
82
82
  for (let i = 0; i < points.length; i += 2)
83
83
  {
84
84
  const dir = points[i + 1].clone().sub(points[i]).normalize();
85
- const geometry = new PlaneBufferGeometry(1, 1);
85
+ const geometry = new PlaneGeometry(1, 1);
86
86
  const vertices = geometry.getAttribute('position');
87
87
  // top right
88
88
  vertices.array[0] = points[i].x;
@@ -122,7 +122,7 @@ export default class EdgeMesh extends Object3D
122
122
  const circle_buffer_geometries = [];
123
123
  for (let i = 0; i < geometry_vertices.count; i++)
124
124
  {
125
- const plane_geometry = new PlaneBufferGeometry(1, 1);
125
+ const plane_geometry = new PlaneGeometry(1, 1);
126
126
  const plane_vertices = plane_geometry.getAttribute('position');
127
127
  const w_pos = [];
128
128
  for (let d = 0; d < plane_vertices.count; d++)
@@ -5,7 +5,7 @@ import GeometryUtilities from '../utilities/GeometryUtilities';
5
5
  import { Mesh } from 'three';
6
6
  import { ShaderMaterial } from 'three';
7
7
  import { Color } from 'three';
8
- import { PlaneBufferGeometry } from 'three';
8
+ import { PlaneGeometry } from 'three';
9
9
 
10
10
  export default class Grid extends Mesh
11
11
  {
@@ -22,7 +22,7 @@ export default class Grid extends Mesh
22
22
  depthWrite: false
23
23
  });
24
24
 
25
- const plane_geometry = new PlaneBufferGeometry(100, 100, 100, 100);
25
+ const plane_geometry = new PlaneGeometry(100, 100, 100, 100);
26
26
 
27
27
  const non_indexed_geometry = GeometryUtilities.convert_to_non_indexed_geometry(plane_geometry);
28
28
 
@@ -3,7 +3,7 @@ import SDFTextMaterial from '../../materials/SDFTextMaterial';
3
3
  import ArrayUtilities from '../../utilities/ArrayUtilities';
4
4
 
5
5
  import {
6
- PlaneBufferGeometry,
6
+ PlaneGeometry,
7
7
  Mesh,
8
8
  Vector2,
9
9
  InstancedBufferGeometry,
@@ -21,7 +21,7 @@ export default class SDFTextBatch extends Mesh
21
21
  const instanced_geometry = new InstancedBufferGeometry();
22
22
  instanced_geometry.instanceCount = 0;
23
23
 
24
- const geometry = new PlaneBufferGeometry(1, 1);
24
+ const geometry = new PlaneGeometry(1, 1);
25
25
  geometry.translate(0.5, 0.5, 0);
26
26
  instanced_geometry.setAttribute('position', new Float32BufferAttribute(geometry.getAttribute('position').array, 3));
27
27
  instanced_geometry.setAttribute('uv', new Float32BufferAttribute(geometry.getAttribute('uv').array, 2));
@@ -9,7 +9,7 @@ import { BoxGeometry } from 'three';
9
9
  import { MeshBasicMaterial } from 'three';
10
10
  import { Mesh } from 'three';
11
11
  import { Raycaster } from 'three';
12
- import { Math as TMath } from 'three';
12
+ import OMath from '../utilities/OMath';
13
13
 
14
14
  export default class ManipulatorHandle extends Object3D
15
15
  {
@@ -22,9 +22,9 @@ export default class ManipulatorHandle extends Object3D
22
22
  this.add(this.arrow_helper);
23
23
 
24
24
  const collider_size = new Vector3();
25
- collider_size.x = TMath.clamp(direction.x * length, 1, 30);
26
- collider_size.y = TMath.clamp(direction.y * length, 1, 30);
27
- collider_size.z = TMath.clamp(direction.z * length, 1, 30);
25
+ collider_size.x = OMath.clamp(direction.x * length, 1, 30);
26
+ collider_size.y = OMath.clamp(direction.y * length, 1, 30);
27
+ collider_size.z = OMath.clamp(direction.z * length, 1, 30);
28
28
 
29
29
  const geometry = new BoxGeometry(collider_size.x, collider_size.y, collider_size.z);
30
30
  const material = new MeshBasicMaterial({ color: color, depthTest: false, depthWrite: false });
@@ -47,8 +47,8 @@ export default class ObjectPicker
47
47
 
48
48
  this.camera_layers = this.camera.layers.mask;
49
49
  this.camera.layers.set(RenderLayers.selectable);
50
- this.tmp_scene_auto_update = this.scene.autoUpdate;
51
- this.scene.autoUpdate = false;
50
+ this.tmp_scene_auto_update = this.scene.matrixWorldAutoUpdate;
51
+ this.scene.matrixWorldAutoUpdate = false;
52
52
  }
53
53
 
54
54
  __restore_scene(objects)
@@ -59,7 +59,7 @@ export default class ObjectPicker
59
59
  objects[i].restore_layer_state();
60
60
  }
61
61
  this.camera.layers.mask = this.camera_layers;
62
- this.scene.autoUpdate = this.tmp_scene_auto_update;
62
+ this.scene.matrixWorldAutoUpdate = this.tmp_scene_auto_update;
63
63
  }
64
64
 
65
65
  __readback_id(mouse_NDC)
@@ -1,8 +1,7 @@
1
1
  import Time from '../../Time';
2
2
  import Idle from './Idle';
3
3
 
4
- import { Math as TMath } from 'three';
5
-
4
+ import OMath from '../../utilities/OMath';
6
5
  export default class Animating
7
6
  {
8
7
  constructor()
@@ -25,9 +24,9 @@ export default class Animating
25
24
  this.t += Time.delta_time / animator.duration;
26
25
 
27
26
  this.easing_function_t = animator.easing_function(this.t);
28
- this.easing_function_t = TMath.clamp(this.easing_function_t, 0, 1);
27
+ this.easing_function_t = OMath.clamp(this.easing_function_t, 0, 1);
29
28
 
30
- animator.set_property_value(TMath.lerp(animator.from, animator.to, this.easing_function_t));
29
+ animator.set_property_value(OMath.lerp(animator.from, animator.to, this.easing_function_t));
31
30
 
32
31
  if (this.easing_function_t >= 0.9999)
33
32
  {
@@ -2,7 +2,8 @@ import BaseShaderMaterial from './BaseShaderMaterial';
2
2
  import frag from '../shaders/sdf_text/sdf_text.frag';
3
3
  import vert from '../shaders/sdf_text/sdf_text.vert';
4
4
 
5
- import { Vector2, DoubleSide, LinearFilter, Math as TMath } from 'three';
5
+ import { Vector2, DoubleSide, LinearFilter } from 'three';
6
+ import OMath from '../utilities/OMath';
6
7
 
7
8
  export default class SDFTextMaterial extends BaseShaderMaterial
8
9
  {
@@ -32,6 +33,6 @@ export default class SDFTextMaterial extends BaseShaderMaterial
32
33
 
33
34
  set_boldness(value)
34
35
  {
35
- this.uniforms._Boldness.value = TMath.lerp(0.5, 0.2, value);
36
+ this.uniforms._Boldness.value = OMath.lerp(0.5, 0.2, value);
36
37
  }
37
38
  }
@@ -3,12 +3,11 @@ import frag from '../shaders/ssao/ssao.frag';
3
3
  import vert from '../shaders/ssao/ssao.vert';
4
4
 
5
5
  import { Matrix4 } from 'three';
6
- import { Math as TMath } from 'three';
7
6
  import { Vector3 } from 'three';
8
7
  import { DataTexture } from 'three';
9
8
  import { RGBFormat } from 'three';
10
9
  import { RepeatWrapping } from 'three';
11
-
10
+ import OMath from '../utilities/OMath';
12
11
  export default class SSAOMaterial extends BlitMaterial
13
12
  {
14
13
  constructor()
@@ -38,7 +37,7 @@ export default class SSAOMaterial extends BlitMaterial
38
37
  Math.random());
39
38
  dir.normalize();
40
39
  let scale = i / kernel_size;
41
- scale = TMath.lerp(0.1, 1.0, scale * scale);
40
+ scale = OMath.lerp(0.1, 1.0, scale * scale);
42
41
  dir.multiplyScalar(scale);
43
42
 
44
43
  sample_kernel.push(dir);
@@ -1,6 +1,6 @@
1
1
  import { Mesh } from 'three';
2
2
  import { MeshBasicMaterial } from 'three';
3
- import { PlaneBufferGeometry } from 'three';
3
+ import { PlaneGeometry } from 'three';
4
4
 
5
5
  export default class HorizontalPlane extends Mesh
6
6
  {
@@ -11,7 +11,7 @@ export default class HorizontalPlane extends Mesh
11
11
  color = color || '#FF0000';
12
12
  material = material || new MeshBasicMaterial({ color: color });
13
13
 
14
- const geometry = new PlaneBufferGeometry(width, height);
14
+ const geometry = new PlaneGeometry(width, height);
15
15
  geometry.rotateX(-3.14 / 2);
16
16
  super(geometry, material);
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { Mesh } from 'three';
2
- import { PlaneBufferGeometry } from 'three';
2
+ import { PlaneGeometry } from 'three';
3
3
  import { MeshBasicMaterial } from 'three';
4
4
 
5
5
  export default class VerticalPlane extends Mesh
@@ -11,7 +11,7 @@ export default class VerticalPlane extends Mesh
11
11
  color = color || '#FF0000';
12
12
  material = material || new MeshBasicMaterial({ color: color });
13
13
 
14
- const geometry = new PlaneBufferGeometry(width, height);
14
+ const geometry = new PlaneGeometry(width, height);
15
15
  super(geometry, material);
16
16
  }
17
17
  }
@@ -2,7 +2,7 @@ import BlitMaterial from '../materials/BlitMaterial';
2
2
 
3
3
  import { Scene } from 'three';
4
4
  import { Mesh } from 'three';
5
- import { PlaneBufferGeometry } from 'three';
5
+ import { PlaneGeometry } from 'three';
6
6
  import { OrthographicCamera } from 'three';
7
7
 
8
8
  export default class Blitter
@@ -13,7 +13,7 @@ export default class Blitter
13
13
  this._blit_scene = new Scene();
14
14
  this._blit_material = new BlitMaterial();
15
15
  this._blit_quad = new Mesh(
16
- new PlaneBufferGeometry(1, 1), this._blit_material);
16
+ new PlaneGeometry(1, 1), this._blit_material);
17
17
  this._blit_scene.add(this._blit_quad);
18
18
  this._blit_camera = new OrthographicCamera(-1, 1, 1, -1, -10000, 10000);
19
19
  }
@@ -2,8 +2,8 @@ import GeometryBatch from './GeometryBatch';
2
2
 
3
3
  import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
4
4
 
5
- import { Math as TMath } from 'three';
6
5
  import { BufferAttribute } from 'three';
6
+ import OMath from '../utilities/OMath';
7
7
 
8
8
  class GeometryBatcher
9
9
  {
@@ -15,7 +15,7 @@ class GeometryBatcher
15
15
  batch(buffer_geometries)
16
16
  {
17
17
  const attr_accessor_uvs = [];
18
- const texture_width = TMath.ceilPowerOfTwo(Math.sqrt(buffer_geometries.length));
18
+ const texture_width = OMath.ceilPowerOfTwo(Math.sqrt(buffer_geometries.length));
19
19
  // console.log("Store count: " + buffer_geometries.length + ", Texture size: " +texture_width);
20
20
 
21
21
  this.__init_uv_array(attr_accessor_uvs, texture_width);
@@ -1,5 +1,4 @@
1
1
  import { Vector3 } from 'three';
2
- import { Math as TMath } from 'three';
3
2
 
4
3
  export default class OMath
5
4
  {
@@ -64,7 +63,7 @@ export default class OMath
64
63
  {
65
64
  for (let i = 0; i < 16; i++)
66
65
  {
67
- target.elements[i] = TMath.lerp(from.elements[i], to.elements[i], t);
66
+ target.elements[i] = this.lerp(from.elements[i], to.elements[i], t);
68
67
  }
69
68
  }
70
69
 
@@ -1,4 +1,5 @@
1
- import { Vector3, Plane, Quaternion, Sphere, Math as TMath, Line3 } from 'three';
1
+ import { Vector3, Plane, Quaternion, Sphere, Line3 } from 'three';
2
+ import OMath from './OMath';
2
3
  export default class PerspectiveFrustumPointFitter
3
4
  {
4
5
  constructor()
@@ -10,7 +11,7 @@ export default class PerspectiveFrustumPointFitter
10
11
  {
11
12
  this.sphere.setFromPoints(points);
12
13
 
13
- const v_fov = TMath.degToRad(vertical_fov / 2);
14
+ const v_fov = OMath.degToRad(vertical_fov / 2);
14
15
  const h_fov = (2 * Math.atan(Math.tan(v_fov) * aspect)) / 2;
15
16
 
16
17
  const up_plane_normal = this.get_up_plane_normal(camera_quaternion, v_fov);
@@ -16,7 +16,7 @@ export default class ActionSequencerBuilder
16
16
  const tracks = animation_data.animation_tracks;
17
17
  const triggers = animation_data.triggers;
18
18
 
19
- const initial_tracks = this.state_to_tracks(this.initial_state_data);
19
+ const initial_tracks = this.state_to_tracks(this.initial_state_data, this.get_longest_time(animation_data.animation_tracks));
20
20
 
21
21
  for (let i = 0; i < initial_tracks.length; i++)
22
22
  {
@@ -52,7 +52,7 @@ export default class ActionSequencerBuilder
52
52
  return sequencer;
53
53
  }
54
54
 
55
- state_to_tracks(state)
55
+ state_to_tracks(state, longest_time)
56
56
  {
57
57
  const tracks = [];
58
58
 
@@ -63,7 +63,7 @@ export default class ActionSequencerBuilder
63
63
  tracks.push({
64
64
  attribute_name: keys[i],
65
65
  from_time: 0,
66
- to_time: 1,
66
+ to_time: longest_time < 1 ? longest_time : 1,
67
67
  to_value: state[keys[i]],
68
68
  initial: true,
69
69
  easing_function: 'ease_in_out_cubic'
@@ -103,4 +103,20 @@ export default class ActionSequencerBuilder
103
103
 
104
104
  return sequencer;
105
105
  }
106
+
107
+ get_longest_time(tracks)
108
+ {
109
+ let longest_time = -1;
110
+
111
+ for (let i = 0; i < tracks.length; i++)
112
+ {
113
+ const track = tracks[i];
114
+
115
+ const track_time = track.to_time;
116
+
117
+ longest_time = track_time > longest_time ? track_time : longest_time;
118
+ }
119
+
120
+ return longest_time;
121
+ }
106
122
  }