ohzi-core 5.16.9 → 5.16.13

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": "5.16.9",
3
+ "version": "5.16.13",
4
4
  "description": "OHZI Core Library",
5
5
  "module": "build/index.module.js",
6
6
  "source": "src/index.js",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "homepage": "https://github.com/ohzinteractive/core#readme",
42
42
  "dependencies": {
43
- "pit-js": "1.5.3",
43
+ "pit-js": "1.6.0",
44
44
  "three": "^0.128.0"
45
45
  },
46
46
  "devDependencies": {
package/src/Graphics.js CHANGED
@@ -82,6 +82,9 @@ class Graphics
82
82
  this.generateDepthNormalTexture = false;
83
83
 
84
84
  this.depth_and_normals_renderer = new DepthAndNormalsRenderer();
85
+
86
+ this.resize_observer = new ResizeObserver(this.on_resize.bind(this));
87
+ this.resize_observer.observe(this.canvas);
85
88
  }
86
89
 
87
90
  get dom_element()
@@ -105,8 +108,6 @@ class Graphics
105
108
 
106
109
  update()
107
110
  {
108
- this.check_for_resize();
109
-
110
111
  if (this.generateDepthNormalTexture)
111
112
  {
112
113
  this.depth_and_normals_renderer.render(this);
@@ -196,22 +197,13 @@ class Graphics
196
197
  !!clear_stencil);
197
198
  }
198
199
 
199
- check_for_resize()
200
+ on_resize(entries)
200
201
  {
201
- let current_width = this.canvas.clientWidth;
202
- let current_height = this.canvas.clientHeight;
203
-
204
- if (
205
- current_width !== Screen.width ||
206
- current_height !== Screen.height ||
207
- Configuration.dpr !== Screen.dpr
208
- )
202
+ for (let entry of entries)
209
203
  {
210
- let canvas_rect = this.canvas.getBoundingClientRect();
211
-
212
204
  Screen.dpr = Configuration.dpr;
213
- Screen.update_position(canvas_rect.x, canvas_rect.y);
214
- Screen.update_size(current_width, current_height);
205
+ Screen.update_position(entry.contentRect.x, entry.contentRect.y);
206
+ Screen.update_size(entry.contentRect.width, entry.contentRect.height);
215
207
 
216
208
  this.canvas.width = Screen.render_width;
217
209
  this.canvas.height = Screen.render_height;
@@ -222,11 +214,6 @@ class Graphics
222
214
  }
223
215
  }
224
216
 
225
- on_resize()
226
- {
227
- console.error('Graphics.on_resize call no longer needed.');
228
- }
229
-
230
217
  material_pass(mat, dst)
231
218
  {
232
219
  this.blitter.material_pass(mat, dst);
package/src/RenderLoop.js CHANGED
@@ -61,8 +61,6 @@ export default class RenderLoop
61
61
  {
62
62
  if (this.is_running) return; // sanity check
63
63
 
64
- this.graphics.check_for_resize();
65
-
66
64
  if (this.frames_passed === 0)
67
65
  {
68
66
  this.target_application.on_enter();
@@ -1,21 +1,35 @@
1
- import { Audio as THREEAudio } from 'three';
1
+ import { Audio as TAudio } from 'three';
2
+ import { PositionalAudio as TPositionalAudio } from 'three';
2
3
 
3
4
  export default class AudioClip
4
5
  {
5
- constructor(buffer, loop = true, volume = 1)
6
+ constructor(buffer, loop = true, volume = 1, positional = false)
6
7
  {
7
8
  this.buffer = buffer;
8
9
  this.loop = loop;
9
10
  this.volume = volume;
11
+ this.positional = positional;
10
12
 
11
13
  this.audio = undefined;
12
14
  }
13
15
 
14
16
  init(audio_listener)
15
17
  {
16
- this.audio = new THREEAudio(audio_listener);
18
+ if (this.positional)
19
+ {
20
+ this.audio = new TPositionalAudio(audio_listener);
21
+ }
22
+ else
23
+ {
24
+ this.audio = new TAudio(audio_listener);
25
+ }
26
+
17
27
  this.audio.setBuffer(this.buffer);
18
28
  this.audio.setLoop(this.loop);
29
+
30
+ // This prevents undesired volume at the beginning of playing
31
+ this.audio.gain.gain.value = 0;
32
+
19
33
  this.audio.setVolume(this.loop ? 0 : this.volume);
20
34
  }
21
35
 
@@ -1,54 +1,47 @@
1
1
  import AbstractLoader from './AbstractLoader';
2
2
 
3
3
  import AudioClip from '../components/AudioClip';
4
- import { AudioLoader as THREEAudioLoader } from 'three';
4
+
5
+ import { AudioContext } from 'three';
5
6
 
6
7
  export default class AudioLoader extends AbstractLoader
7
8
  {
8
- constructor(resource_id, url, loop = true, volume = 1, size)
9
+ constructor(resource_id, url, loop = true, volume = 0, size, positional = false)
9
10
  {
10
11
  super(resource_id, url, size);
11
- this.loader = new THREEAudioLoader();
12
12
  this.loop = loop;
13
13
  this.volume = volume;
14
+ this.positional = positional;
14
15
  }
15
16
 
16
- on_preloaded_finished(resource_container)
17
+ on_preloaded_finished(resource_container, response)
17
18
  {
18
19
  if (!window.user_interaction_for_audio)
19
20
  {
20
- setTimeout(this.on_preloaded_finished.bind(this, resource_container), 100);
21
+ setTimeout(this.on_preloaded_finished.bind(this, resource_container, response), 100);
21
22
  }
22
23
  else
23
24
  {
24
- this.load_with_three_loader(resource_container);
25
+ this.instantiate_audio(resource_container, response);
25
26
  }
26
27
  }
27
28
 
28
- load_with_three_loader(resource_container)
29
+ instantiate_audio(resource_container, response)
29
30
  {
30
- let ctx = this;
31
-
32
- this.loader.load(this.url, (buffer) =>
31
+ response.arrayBuffer().then((array_buffer) =>
33
32
  {
34
- resource_container.set_resource(ctx.resource_id, ctx.url, new AudioClip(buffer, this.loop, this.volume));
33
+ const context = AudioContext.getContext();
34
+ context.decodeAudioData(array_buffer, (audio_buffer) =>
35
+ {
36
+ resource_container.set_resource(
37
+ this.resource_id,
38
+ this.url,
39
+ new AudioClip(audio_buffer, this.loop, this.volume, this.positional)
40
+ );
35
41
 
36
- ctx.__update_downloaded_bytes(1, 1);
37
- ctx.__loading_ended();
38
- },
39
- (xhr) =>
40
- {
41
- // if (xhr)
42
- // {
43
- // let total = xhr.total || this.total_bytes;
44
-
45
- // ctx.__update_downloaded_bytes(xhr.loaded, total);
46
- // }
47
- },
48
- (error) =>
49
- {
50
- ctx.__set_error('Audio could not be loaded. Maybe wrong name or path, I don\'t know' + '¯\\_(ツ)_/¯', error);
51
- ctx.__loading_ended();
42
+ this.__update_downloaded_bytes(1, 1);
43
+ this.__loading_ended();
44
+ });
52
45
  });
53
46
  }
54
47
  }
@@ -69,9 +69,9 @@ export default class ResourceBatch
69
69
  this.resource_loaders.push(new CubemapLoader(resource_id, url, size));
70
70
  }
71
71
 
72
- add_audio(resource_id, url, loop, volume, size)
72
+ add_audio(resource_id, url, loop, volume, size, positional)
73
73
  {
74
- this.resource_loaders.push(new AudioLoader(resource_id, url, loop, volume, size));
74
+ this.resource_loaders.push(new AudioLoader(resource_id, url, loop, volume, size, positional));
75
75
  }
76
76
 
77
77
  add_video(resource_id, url, size)
@@ -19,16 +19,17 @@ export default class TextureLoader extends AbstractLoader
19
19
 
20
20
  const image = new Image();
21
21
  image.src = url;
22
+
22
23
  image.onload = () =>
23
24
  {
24
25
  texture.image = image;
25
26
  texture.needsUpdate = true;
26
- };
27
27
 
28
- resource_container.set_resource(this.resource_id, this.url, texture);
28
+ resource_container.set_resource(this.resource_id, this.url, texture);
29
29
 
30
- this.__update_downloaded_bytes(1, 1);
31
- this.__loading_ended();
30
+ this.__update_downloaded_bytes(1, 1);
31
+ this.__loading_ended();
32
+ };
32
33
  });
33
34
  }
34
35
  }
@@ -55,6 +55,10 @@ export default class ApplicationView extends ViewState
55
55
 
56
56
  set_opacity(current_state_data)
57
57
  {
58
- this.container.style.opacity = current_state_data[`${this.name}_opacity`];
58
+ if (this.container.style.opacity > current_state_data[`${this.name}_opacity`] ||
59
+ this.container.style.opacity < current_state_data[`${this.name}_opacity`])
60
+ {
61
+ this.container.style.opacity = current_state_data[`${this.name}_opacity`];
62
+ }
59
63
  }
60
64
  }
@@ -13,9 +13,9 @@ class ViewManager
13
13
 
14
14
  update()
15
15
  {
16
- this.transition_handler.update();
17
-
18
16
  this.__set_views_opacities();
17
+
18
+ this.transition_handler.update();
19
19
  }
20
20
 
21
21
  go_to_view(view_name, change_url = true, skip = false)
@@ -21,7 +21,6 @@ export class Graphics {
21
21
  static __apply_override_material(scene: any, mat: any): void;
22
22
  static readback_RT(RT: any, buffer: any): void;
23
23
  static clear(RT: any, camera: any, clear_depth: any, clear_stencil: any): void;
24
- static check_for_resize(): void;
25
24
  static on_resize(): void;
26
25
  static material_pass(mat: any, dst: any): void;
27
26
  static blit(src_RT: any, dst_RT: any, mat: any): void;