ohzi-core 10.4.2 → 10.6.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohzi-core",
3
- "version": "10.4.2",
3
+ "version": "10.6.0",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
@@ -12,6 +12,9 @@ class BaseApplication
12
12
  update()
13
13
  {}
14
14
 
15
+ fixed_update()
16
+ {}
17
+
15
18
  on_post_render()
16
19
  {}
17
20
 
package/src/Browser.js CHANGED
@@ -6,6 +6,12 @@ class Browser
6
6
  this.browser_name = '';
7
7
  this.agent = window.navigator.userAgent.toLowerCase();
8
8
 
9
+ // vr specific
10
+ this.vrBrowserKeywords = ['OculusBrowser', 'oculus', 'vive', 'rift', 'windowsmr', 'cardboard', 'daydream'];
11
+ this.vrBrowser = this.vrBrowserKeywords.find(keyword => this.agent.includes(keyword));
12
+ // Check for WebXR support (indicating VR capabilities)
13
+ this.hasWebXRSupport = 'xr' in navigator;
14
+
9
15
  switch (true)
10
16
  {
11
17
  case this.agent.indexOf('edge') > -1:
@@ -29,6 +35,9 @@ class Browser
29
35
  case this.agent.indexOf('safari') > -1:
30
36
  this.browser_name = 'safari';
31
37
  break;
38
+ case this.vrBrowser && this.hasWebXRSupport:
39
+ this.browser_name = this.vrBrowser;
40
+ break;
32
41
  default:
33
42
  this.browser_name = 'other';
34
43
  break;
@@ -62,6 +71,11 @@ class Browser
62
71
  return this.browser_name === 'edge_chromium';
63
72
  }
64
73
 
74
+ get is_vr()
75
+ {
76
+ return this.vrBrowserKeywords.includes(this.browser_name);
77
+ }
78
+
65
79
  get has_webm()
66
80
  {
67
81
  return !!(this.is_chrome || this.is_firefox || this.is_edge_chromium);
package/src/Debug.js CHANGED
@@ -25,6 +25,7 @@ import { MeshBasicMaterial } from 'three';
25
25
 
26
26
  import basic_color_vert from './shaders/basic_color/basic_color.vert';
27
27
  import basic_color_frag from './shaders/basic_color/basic_color.frag';
28
+ import { CameraManager } from './CameraManager';
28
29
 
29
30
  class Debug
30
31
  {
@@ -38,22 +39,22 @@ class Debug
38
39
 
39
40
  this.ctx = undefined;
40
41
  this.scene = new Scene();
41
- this.camera = new PerspectiveCamera();
42
- // this.camera.clear_alpha = 0;
42
+ this.camera = new PerspectiveCamera(60, OScreen.aspect_ratio, 0.1, 1000);
43
+ this.camera.clear_alpha = 0;
43
44
  }
44
45
 
45
46
  draw_arrow(origin, dir, color = 0xff0000)
46
47
  {
47
48
  const arrow = new Arrow(color, dir.length(), dir.clone().normalize());
48
49
  arrow.position.copy(origin);
49
- SceneManager.current.add(arrow);
50
+ this.scene.add(arrow);
50
51
  return arrow;
51
52
  }
52
53
 
53
54
  draw_axis()
54
55
  {
55
56
  const axis = new AxisHelper();
56
- SceneManager.current.add(axis);
57
+ this.scene.add(axis);
57
58
  return axis;
58
59
  }
59
60
 
@@ -99,7 +100,7 @@ class Debug
99
100
 
100
101
  const line = new Line(geometry, material);
101
102
  line.frustumCulled = false;
102
- SceneManager.current.add(line);
103
+ this.scene.add(line);
103
104
  return line;
104
105
  }
105
106
 
@@ -111,7 +112,7 @@ class Debug
111
112
 
112
113
  const cube = new Cube(new Vector3(size, size, size), undefined, color);
113
114
  cube.position.copy(pos);
114
- SceneManager.current.add(cube);
115
+ this.scene.add(cube);
115
116
  return cube;
116
117
  }
117
118
 
@@ -133,7 +134,7 @@ class Debug
133
134
  // cube.quaternion.setFromRotationMatrix(new Matrix4().makeBasis(right,up,forward));
134
135
  cube.quaternion.setFromUnitVectors(new Vector3(0, 0, -1), forward_dir);
135
136
 
136
- SceneManager.current.add(cube);
137
+ this.scene.add(cube);
137
138
  return cube;
138
139
  }
139
140
 
@@ -152,7 +153,7 @@ class Debug
152
153
 
153
154
  const plane = new Mesh(geometry, material);
154
155
  plane.renderOrder = -10000;
155
- SceneManager.current.add(plane);
156
+ this.scene.add(plane);
156
157
  return plane;
157
158
  }
158
159
 
@@ -175,7 +176,7 @@ class Debug
175
176
 
176
177
  const sphere = new Sphere(size, color);
177
178
  sphere.position.copy(pos);
178
- SceneManager.current.add(sphere);
179
+ this.scene.add(sphere);
179
180
  return sphere;
180
181
  }
181
182
 
@@ -255,7 +256,7 @@ class Debug
255
256
  }
256
257
  if (this.scene.children.length > 0)
257
258
  {
258
- graphics.render(this.scene, this.camera);
259
+ graphics.render(this.scene, CameraManager.current);
259
260
  }
260
261
  }
261
262
  }
package/src/RenderLoop.js CHANGED
@@ -17,6 +17,8 @@ class RenderLoop
17
17
 
18
18
  this.is_running = false;
19
19
  this.frames_passed = 0;
20
+
21
+ this.time_accumulator = 0;
20
22
  }
21
23
 
22
24
  update()
@@ -35,7 +37,17 @@ class RenderLoop
35
37
 
36
38
  this.input.update();
37
39
 
40
+ this.time_accumulator += Time.delta_time;
41
+
42
+ while (this.time_accumulator > Time.fixed_delta_time)
43
+ {
44
+ this.target_application.fixed_update();
45
+ this.time_accumulator -= Time.fixed_delta_time;
46
+ }
47
+ Time.__set_frame_interpolation(this.time_accumulator / Time.fixed_delta_time);
48
+
38
49
  this.target_application.update();
50
+
39
51
  ViewManager.update();
40
52
  ViewComponentManager.update();
41
53
 
package/src/Time.js CHANGED
@@ -5,17 +5,18 @@ class Time
5
5
  {
6
6
  constructor()
7
7
  {
8
- this.delta_buffer = [0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016];
8
+ this.__delta_buffer = [0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016, 0.016];
9
9
  }
10
10
 
11
11
  init()
12
12
  {
13
13
  this.___time = new Clock();
14
- this.__raw_delta_time = 0;
14
+ this.__delta_time = 0;
15
+ this.__smooth_delta_time = 0;
15
16
  this.__elapsed_time = 0;
16
17
  this.__allocated_time = new Vector2(0, 0);
17
-
18
- this.delta_time = 0.016;
18
+ this.__frame_interpolation_t = 0;
19
+ this.fixed_delta_time = 1 / 30;
19
20
  }
20
21
 
21
22
  get elapsed_time()
@@ -23,6 +24,16 @@ class Time
23
24
  return this.__elapsed_time;
24
25
  }
25
26
 
27
+ get delta_time()
28
+ {
29
+ return this.__delta_time;
30
+ }
31
+
32
+ get smooth_delta_time()
33
+ {
34
+ return this.__smooth_delta_time;
35
+ }
36
+
26
37
  get shader_time()
27
38
  {
28
39
  this.__allocated_time.x = this.delta_time;
@@ -30,27 +41,52 @@ class Time
30
41
  return this.__allocated_time;
31
42
  }
32
43
 
44
+ get frame_interpolation()
45
+ {
46
+ return this.__frame_interpolation_t;
47
+ }
48
+
49
+ get fdt()
50
+ {
51
+ return this.fixed_delta_time;
52
+ }
53
+
54
+ get dt()
55
+ {
56
+ return this.delta_time;
57
+ }
58
+
59
+ get sdt()
60
+ {
61
+ return this.smooth_delta_time;
62
+ }
63
+
64
+ __set_frame_interpolation(value)
65
+ {
66
+ this.__frame_interpolation_t = value;
67
+ }
68
+
33
69
  __update()
34
70
  {
35
- this.__raw_delta_time = this.___time.getDelta();
71
+ this.__delta_time = this.___time.getDelta();
36
72
  this.__elapsed_time = this.___time.getElapsedTime();
37
73
 
38
- this.delta_buffer.shift();
39
- this.delta_buffer.push(this.__raw_delta_time < 0.32 ? this.__raw_delta_time : 0.032);
74
+ this.__delta_buffer.shift();
75
+ this.__delta_buffer.push(this.delta_time < 0.32 ? this.delta_time : 0.032);
40
76
 
41
- this.__calculate_delta_time();
77
+ this.__calculate_smooth_delta_time();
42
78
  }
43
79
 
44
- __calculate_delta_time()
80
+ __calculate_smooth_delta_time()
45
81
  {
46
- this.delta_time = 0;
82
+ this.__smooth_delta_time = 0;
47
83
 
48
- for (let i = 0; i < this.delta_buffer.length; i++)
84
+ for (let i = 0; i < this.__delta_buffer.length; i++)
49
85
  {
50
- this.delta_time += this.delta_buffer[i];
86
+ this.__smooth_delta_time += this.__delta_buffer[i];
51
87
  }
52
88
 
53
- this.delta_time = this.delta_time / this.delta_buffer.length;
89
+ this.__smooth_delta_time = this.__smooth_delta_time / this.__delta_buffer.length;
54
90
  }
55
91
  }
56
92
 
@@ -3,11 +3,12 @@ import { OMath } from '../utilities/OMath';
3
3
 
4
4
  class ActionSequencer
5
5
  {
6
- constructor(context)
6
+ constructor(context = {})
7
7
  {
8
+ this.previous_elapsed_time = -0.00001;
8
9
  this.elapsed_time = -0.00001;
9
10
  this.playback_speed = this.__get_playback_speed();
10
- this.playing = false;
11
+ this.playing = true;
11
12
 
12
13
  this.action_events = [];
13
14
  this.context = context;
@@ -53,19 +54,22 @@ class ActionSequencer
53
54
  {
54
55
  if (this.playing)
55
56
  {
56
- this.__play_clips(this.elapsed_time, this.elapsed_time + delta_time * this.playback_speed);
57
- this.elapsed_time = this.elapsed_time + delta_time * this.playback_speed;
57
+ this.previous_elapsed_time = this.elapsed_time;
58
+ this.elapsed_time += delta_time * this.playback_speed;
59
+ this.__play_clips(this.previous_elapsed_time, this.elapsed_time);
58
60
  }
59
61
  }
60
62
 
61
63
  set_progress(time)
62
64
  {
65
+ this.previous_elapsed_time = this.elapsed_time;
63
66
  this.elapsed_time = OMath.clamp(time, 0, this.duration);
64
67
  this.__play_clips(this.elapsed_time, this.elapsed_time);
65
68
  }
66
69
 
67
70
  set_normalized_progress(t)
68
71
  {
72
+ this.previous_elapsed_time = this.elapsed_time;
69
73
  this.elapsed_time = OMath.clamp(t, 0, 1) * this.duration;
70
74
  this.__play_clips(this.elapsed_time, this.elapsed_time);
71
75
  }
@@ -155,14 +159,9 @@ class ActionSequencer
155
159
 
156
160
  __play_clips(from, to)
157
161
  {
158
- for (let i = 0; i < this.action_events.length; i++)
162
+ if (this.elapsed_time > this.previous_elapsed_time)
159
163
  {
160
- if (this.action_events[i].trigger_time > from - Number.EPSILON &&
161
- this.action_events[i].trigger_time < to + Number.EPSILON)
162
- {
163
- // console.log("Play event: " + this.action_events[i].action.constructor.name + " at "+ this.action_events[i].trigger_time);
164
- this.action_events[i].action.trigger();
165
- }
164
+ this.__play_events(this.previous_elapsed_time, this.elapsed_time);
166
165
  }
167
166
  const channel_names = Object.keys(this.initial_context);
168
167
 
@@ -175,6 +174,19 @@ class ActionSequencer
175
174
  }
176
175
  }
177
176
 
177
+ __play_events(from, to)
178
+ {
179
+ for (let i = 0; i < this.action_events.length; i++)
180
+ {
181
+ const trigger_time = this.action_events[i].trigger_time;
182
+ if (OMath.between(trigger_time, from, to))
183
+ {
184
+ console.log('Play event: ' + this.action_events[i].action.constructor.name + ' at ' + this.action_events[i].trigger_time);
185
+ this.action_events[i].action.trigger();
186
+ }
187
+ }
188
+ }
189
+
178
190
  evaluate_keyframe(keyframe, time)
179
191
  {
180
192
  this.tmp_t = this.__linear_map_01(time, keyframe.from, keyframe.to);