ohzi-core 10.7.0 → 10.7.2

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.7.0",
3
+ "version": "10.7.2",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
@@ -43,18 +43,19 @@
43
43
  "registry": "https://registry.npmjs.org/"
44
44
  },
45
45
  "dependencies": {
46
- "three": "0.148.0"
46
+ "three": "0.161.0"
47
47
  },
48
48
  "standardx": {
49
49
  "ignore": [
50
- "rollup.config.mjs"
50
+ "rollup.config.js"
51
51
  ]
52
52
  },
53
53
  "devDependencies": {
54
- "@rollup/plugin-terser": "^0.4.4",
55
- "rollup": "4.1.4",
56
- "rollup-plugin-glslify": "^1.3.1",
54
+ "rollup": "^2.44.0",
55
+ "rollup-plugin-glslify": "^1.2.0",
56
+ "rollup-plugin-sourcemaps": "^0.6.3",
57
+ "rollup-plugin-terser": "^7.0.2",
57
58
  "standardx": "^7.0.0",
58
- "typescript": "4.4.4"
59
+ "typescript": "^4.4.3"
59
60
  }
60
61
  }
package/src/Browser.js CHANGED
@@ -1,22 +1,16 @@
1
1
 
2
2
  class Browser
3
3
  {
4
- init()
4
+ async init()
5
5
  {
6
6
  this.browser_name = '';
7
7
  this.agent = window.navigator.userAgent.toLowerCase();
8
8
 
9
- // vr specific
10
- this.vr_browser_keywords = ['oculusbrowser', 'oculus', 'vive', 'rift', 'windowsmr', 'cardboard', 'daydream', 'wolvic'];
11
- this.vr_browser_name = this.vr_browser_keywords.find(keyword => this.agent.includes(keyword));
12
- // Check for WebXR support (indicating VR capabilities)
13
9
  this.has_web_xr_support = 'xr' in navigator;
10
+ this.is_vr = this.has_web_xr_support && await navigator.xr.isSessionSupported('immersive-vr');
14
11
 
15
12
  switch (true)
16
13
  {
17
- case this.vr_browser_name !== undefined && this.has_web_xr_support:
18
- this.browser_name = this.vr_browser_name;
19
- break;
20
14
  case this.agent.indexOf('edge') > -1:
21
15
  this.browser_name = 'edge_ie';
22
16
  break;
@@ -71,11 +65,6 @@ class Browser
71
65
  return this.browser_name === 'edge_chromium';
72
66
  }
73
67
 
74
- get is_vr()
75
- {
76
- return this.vr_browser_keywords.includes(this.browser_name);
77
- }
78
-
79
68
  get has_webm()
80
69
  {
81
70
  return !!(this.is_chrome || this.is_firefox || this.is_edge_chromium);
package/src/Graphics.js CHANGED
@@ -1,21 +1,22 @@
1
+ import { CameraManager } from './CameraManager';
2
+ import { Capabilities } from './Capabilities';
1
3
  import { Configuration } from './Configuration';
2
- import { BaseRender } from './render_mode/BaseRender';
3
4
  import { OScreen } from './OScreen';
4
- import { CameraManager } from './CameraManager';
5
5
  import { SceneManager } from './SceneManager';
6
- import { Capabilities } from './Capabilities';
7
- import { DepthAndNormalsRenderer } from './render_utilities/DepthAndNormalsRenderer';
6
+
7
+ import { BaseRender } from './render_mode/BaseRender';
8
8
  import { Blitter } from './render_utilities/Blitter';
9
+ import { DepthAndNormalsRenderer } from './render_utilities/DepthAndNormalsRenderer';
9
10
 
10
11
  import {
12
+ AlwaysDepth,
13
+ FloatType,
11
14
  NearestFilter,
15
+ NoBlending,
16
+ NoColorSpace,
12
17
  RGBAFormat,
13
- LinearEncoding,
14
- FloatType,
15
- WebGLRenderTarget,
16
18
  ShaderMaterial,
17
- NoBlending,
18
- AlwaysDepth
19
+ WebGLRenderTarget
19
20
  } from 'three';
20
21
 
21
22
  import { WebGLRenderer } from 'three';
@@ -179,6 +180,30 @@ class Graphics
179
180
  this.__apply_override_material(scene, undefined);
180
181
  }
181
182
 
183
+ compile(scene, camera, RT, override_mat)
184
+ {
185
+ this.__apply_override_material(scene, override_mat);
186
+
187
+ this._renderer.setRenderTarget(RT === undefined ? null : RT);
188
+ this._renderer.compile(scene || SceneManager.current,
189
+ camera || CameraManager.current);
190
+
191
+ this.__apply_override_material(scene, undefined);
192
+ }
193
+
194
+ async compile_async(scene, camera, RT, override_mat, target_scene)
195
+ {
196
+ this.__apply_override_material(scene, override_mat);
197
+
198
+ this._renderer.setRenderTarget(RT === undefined ? null : RT);
199
+ const promise = this._renderer.compileAsync(scene || SceneManager.current,
200
+ camera || CameraManager.current, target_scene);
201
+
202
+ this.__apply_override_material(scene, undefined);
203
+
204
+ return promise;
205
+ }
206
+
182
207
  render_scene(scene)
183
208
  {
184
209
  if (scene.on_pre_render)
@@ -363,7 +388,7 @@ class Graphics
363
388
  minFilter: NearestFilter,
364
389
  magFilter: NearestFilter,
365
390
  format: RGBAFormat,
366
- encoding: LinearEncoding,
391
+ colorSpace: NoColorSpace,
367
392
  type: FloatType,
368
393
  stencilBuffer: false,
369
394
  depthBuffer: false
@@ -1,20 +1,11 @@
1
- import edge_line_vert from '../shaders/edges/edges.vert';
2
- import edge_line_frag from '../shaders/edges/edges.frag';
3
- import corners_vert from '../shaders/edges/corners.vert';
4
1
  import corners_frag from '../shaders/edges/corners.frag';
2
+ import corners_vert from '../shaders/edges/corners.vert';
3
+ import edge_line_frag from '../shaders/edges/edges.frag';
4
+ import edge_line_vert from '../shaders/edges/edges.vert';
5
5
 
6
6
  import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
7
7
 
8
- import { Object3D } from 'three';
9
- import { ShaderMaterial } from 'three';
10
- import { Color } from 'three';
11
- import { Mesh } from 'three';
12
- import { EdgesGeometry } from 'three';
13
- import { LineSegments } from 'three';
14
- import { LineBasicMaterial } from 'three';
15
- import { Vector3 } from 'three';
16
- import { PlaneGeometry } from 'three';
17
- import { BufferAttribute } from 'three';
8
+ import { BufferAttribute, Color, EdgesGeometry, LineBasicMaterial, LineSegments, Mesh, Object3D, PlaneGeometry, ShaderMaterial, Vector3 } from 'three';
18
9
 
19
10
  class EdgeMesh extends Object3D
20
11
  {
@@ -114,7 +105,7 @@ class EdgeMesh extends Object3D
114
105
  buffer_geometries.push(geometry);
115
106
  }
116
107
 
117
- return BufferGeometryUtils.mergeBufferGeometries(buffer_geometries);
108
+ return BufferGeometryUtils.mergeGeometries(buffer_geometries);
118
109
  }
119
110
 
120
111
  __get_corners_geometry(geometry_vertices)
@@ -135,7 +126,7 @@ class EdgeMesh extends Object3D
135
126
  plane_geometry.setAttribute('w_pos', new BufferAttribute(pos_array, 3));
136
127
  circle_buffer_geometries.push(plane_geometry);
137
128
  }
138
- return BufferGeometryUtils.mergeBufferGeometries(circle_buffer_geometries);
129
+ return BufferGeometryUtils.mergeGeometries(circle_buffer_geometries);
139
130
  }
140
131
 
141
132
  set_visible(boolean)
@@ -1,12 +1,12 @@
1
+ import { RGBAFormat } from 'three';
1
2
  import { CustomDataTexture } from './CustomDataTexture';
2
- import { RGBFormat } from 'three';
3
3
 
4
4
  class RGBDataTexture extends CustomDataTexture
5
5
  {
6
6
  constructor(width, height)
7
7
  {
8
8
  const data = new Uint8Array(width * height * 3);
9
- super(data, width, height, RGBFormat);
9
+ super(data, width, height, RGBAFormat);
10
10
  this.multiplier = 255;
11
11
  }
12
12
  }
@@ -1,13 +1,12 @@
1
+ import { FloatType, RGBAFormat } from 'three';
1
2
  import { CustomDataTexture } from './CustomDataTexture';
2
- import { FloatType } from 'three';
3
- import { RGBFormat } from 'three';
4
3
 
5
4
  class RGBFloatDataTexture extends CustomDataTexture
6
5
  {
7
6
  constructor(width, height)
8
7
  {
9
8
  const data = new Float32Array(width * height * 3);
10
- super(data, width, height, RGBFormat, FloatType);
9
+ super(data, width, height, RGBAFormat, FloatType);
11
10
  }
12
11
  }
13
12
 
@@ -1,11 +1,6 @@
1
1
  import { Graphics } from '../Graphics';
2
2
 
3
- import { NearestFilter } from 'three';
4
- import { RGBAFormat } from 'three';
5
- import { LinearEncoding } from 'three';
6
- import { HalfFloatType } from 'three';
7
- import { FloatType } from 'three';
8
- import { WebGLRenderTarget } from 'three';
3
+ import { FloatType, HalfFloatType, NearestFilter, NoColorSpace, RGBAFormat, WebGLRenderTarget } from 'three';
9
4
  import { Capabilities } from '../Capabilities';
10
5
 
11
6
  class ParticleAttribute
@@ -37,7 +32,7 @@ class ParticleAttribute
37
32
  minFilter: NearestFilter,
38
33
  magFilter: NearestFilter,
39
34
  format: RGBAFormat,
40
- encoding: LinearEncoding,
35
+ colorScape: NoColorSpace,
41
36
  type: Capabilities.fp_textures_available ? FloatType : HalfFloatType,
42
37
  stencilBuffer: false,
43
38
  depthBuffer: false
@@ -3,11 +3,7 @@ import { BlitMaterial } from '../materials/BlitMaterial';
3
3
  import frag from '../shaders/ssao/ssao.frag';
4
4
  import vert from '../shaders/ssao/ssao.vert';
5
5
 
6
- import { Matrix4 } from 'three';
7
- import { Vector3 } from 'three';
8
- import { DataTexture } from 'three';
9
- import { RGBFormat } from 'three';
10
- import { RepeatWrapping } from 'three';
6
+ import { DataTexture, Matrix4, RGBAFormat, RepeatWrapping, Vector3 } from 'three';
11
7
 
12
8
  import { OMath } from '../utilities/OMath';
13
9
  class SSAOMaterial extends BlitMaterial
@@ -57,7 +53,7 @@ class SSAOMaterial extends BlitMaterial
57
53
  rotation_kernel[i * 3 + 3] = 0;
58
54
  }
59
55
 
60
- const rotation_texture = new DataTexture(rotation_kernel, 4, 4, RGBFormat);
56
+ const rotation_texture = new DataTexture(rotation_kernel, 4, 4, RGBAFormat);
61
57
  rotation_texture.wrapS = RepeatWrapping;
62
58
  rotation_texture.wrapT = RepeatWrapping;
63
59
 
@@ -1,7 +1,4 @@
1
- import { CylinderBufferGeometry } from 'three';
2
- import { ConeBufferGeometry } from 'three';
3
- import { MeshBasicMaterial } from 'three';
4
- import { Vector3, Mesh } from 'three';
1
+ import { ConeGeometry, CylinderGeometry, Mesh, MeshBasicMaterial, Vector3 } from 'three';
5
2
 
6
3
  import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
7
4
 
@@ -14,13 +11,13 @@ class Arrow extends Mesh
14
11
 
15
12
  const cone_height = 0.4;
16
13
  const cylinder_height = length - cone_height;
17
- const cylinder_geo = new CylinderBufferGeometry(0.01, 0.01, cylinder_height, 32);
14
+ const cylinder_geo = new CylinderGeometry(0.01, 0.01, cylinder_height, 32);
18
15
  cylinder_geo.translate(0, cylinder_height / 2, 0);
19
16
 
20
- const cone_geometry = new ConeBufferGeometry(0.1, cone_height, 32);
17
+ const cone_geometry = new ConeGeometry(0.1, cone_height, 32);
21
18
  cone_geometry.translate(0, cylinder_height + cone_height / 2, 0);
22
19
 
23
- const buffer_geometry = BufferGeometryUtils.mergeBufferGeometries([cylinder_geo, cone_geometry]);
20
+ const buffer_geometry = BufferGeometryUtils.mergeGeometries([cylinder_geo, cone_geometry]);
24
21
  buffer_geometry.rotateX(3.14 / 2);
25
22
 
26
23
  const material = new MeshBasicMaterial({ color: color });
@@ -1,6 +1,4 @@
1
- import { Mesh } from 'three';
2
- import { SphereBufferGeometry } from 'three';
3
- import { MeshBasicMaterial } from 'three';
1
+ import { Mesh, MeshBasicMaterial, SphereGeometry } from 'three';
4
2
 
5
3
  class Sphere extends Mesh
6
4
  {
@@ -8,7 +6,7 @@ class Sphere extends Mesh
8
6
  {
9
7
  color = color || '#FF0000';
10
8
  radius = radius || 1;
11
- const geometry = new SphereBufferGeometry(radius, 64, 64);
9
+ const geometry = new SphereGeometry(radius, 64, 64);
12
10
  const material = new MeshBasicMaterial({ color: color });
13
11
  super(geometry, material);
14
12
  }
@@ -1,16 +1,12 @@
1
1
  import { CameraManager } from '../CameraManager';
2
- import { SceneManager } from '../SceneManager';
2
+ import { Graphics } from '../Graphics';
3
3
  import { OScreen } from '../OScreen';
4
- import { BaseRender } from '../render_mode/BaseRender';
4
+ import { SceneManager } from '../SceneManager';
5
5
  import { DeferredRendererComposeMaterial } from '../materials/DeferredRendererComposeMaterial';
6
- import { Graphics } from '../Graphics';
7
6
  import { DeferredPointLightMaterial } from '../materials/deferred/DeferredPointLightMaterial';
7
+ import { BaseRender } from '../render_mode/BaseRender';
8
8
 
9
- import { WebGLRenderTarget } from 'three';
10
- import { Scene } from 'three';
11
- import { Mesh } from 'three';
12
- import { SphereBufferGeometry } from 'three';
13
- import { Matrix4 } from 'three';
9
+ import { Matrix4, Mesh, Scene, SphereGeometry, WebGLRenderTarget } from 'three';
14
10
 
15
11
  class DeferredRender extends BaseRender
16
12
  {
@@ -29,7 +25,7 @@ class DeferredRender extends BaseRender
29
25
  const light_intensity = 1;
30
26
  const light_brightest_component = 1;
31
27
  const radius_needed_for_intensity = Math.sqrt(4 * light_intensity * (light_brightest_component * (256.0 / 5.0))) / (2 * light_intensity);
32
- const sphere = new Mesh(new SphereBufferGeometry(radius_needed_for_intensity), new DeferredPointLightMaterial(light_intensity));
28
+ const sphere = new Mesh(new SphereGeometry(radius_needed_for_intensity), new DeferredPointLightMaterial(light_intensity));
33
29
  // sphere.position.y = 2;
34
30
  // this.scene_lights.add(sphere);
35
31
 
@@ -1,43 +1,49 @@
1
1
  import { AbstractLoader } from './AbstractLoader';
2
2
 
3
3
  import { HDRCubeTextureLoader as THDRCubeTextureLoader } from 'three/examples/jsm/loaders/HDRCubeTextureLoader.js';
4
- import { UnsignedByteType } from 'three';
5
4
 
6
5
  class HDRCubeTextureLoader extends AbstractLoader
7
6
  {
8
- constructor(resource_id, url, size)
7
+ constructor(resource_id, url, extension, size)
9
8
  {
10
9
  super(resource_id, url, size);
11
10
  this.loader = new THDRCubeTextureLoader();
12
- this.url_suffix = ['/px.hdr', '/nx.hdr', '/py.hdr', '/ny.hdr', '/pz.hdr', '/nz.hdr'];
11
+ this.loader.setPath(url + '/');
12
+ // this.loader.setDataType(UnsignedByteType);
13
+ this.urls = [
14
+ `px.${extension}`,
15
+ `nx.${extension}`,
16
+ `py.${extension}`,
17
+ `ny.${extension}`,
18
+ `pz.${extension}`,
19
+ `nz.${extension}`
20
+ ];
13
21
  }
14
22
 
15
23
  on_preloaded_finished(resource_container)
16
24
  {
17
25
  if (resource_container.resources_by_url[this.url] === undefined)
18
26
  {
19
- this.loader.setPath(this.url)
20
- .setDataType(UnsignedByteType)
21
- .load(this.url_suffix, (hdr) =>
22
- {
23
- resource_container.set_resource(this.resource_id, this.url, hdr);
27
+ this.loader.load(this.urls, (hdr) =>
28
+ {
29
+ resource_container.set_resource(this.resource_id, this.url, hdr);
24
30
 
25
- this.__update_downloaded_bytes(1, 1);
26
- this.__loading_ended();
27
- },
28
- (xhr) =>
29
- {
31
+ this.__update_downloaded_bytes(1, 1);
32
+ this.__loading_ended();
33
+ },
34
+ (xhr) =>
35
+ {
30
36
  // if (xhr)
31
37
  // {
32
38
  // let total = xhr.total || this.total_bytes;
33
39
  // this.__update_downloaded_bytes(xhr.loaded, total);
34
40
  // }
35
- },
36
- (msg) =>
37
- {
38
- this.__set_error(msg + '\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource');
39
- this.__loading_ended();
40
- });
41
+ },
42
+ (msg) =>
43
+ {
44
+ this.__set_error(msg + '\n\n\t If the error says something about unexpected token < in JSON then the probably the problem is related to the file not being found. Check the name and path of the resource');
45
+ this.__loading_ended();
46
+ });
41
47
  }
42
48
  else
43
49
  {
@@ -1,10 +1,4 @@
1
- import { Vector2 } from 'three';
2
- import { ShaderMaterial } from 'three';
3
- import { Mesh } from 'three';
4
- import { DataTexture } from 'three';
5
- import { RGBAFormat } from 'three';
6
- import { RGBFormat } from 'three';
7
- import { FloatType } from 'three';
1
+ import { DataTexture, FloatType, Mesh, RGBAFormat, ShaderMaterial, Vector2 } from 'three';
8
2
 
9
3
  class GeometryBatch
10
4
  {
@@ -242,7 +236,7 @@ class GeometryBatch
242
236
  __create_rgb_texture(width)
243
237
  {
244
238
  const data = new Uint8Array(3 * width * width);
245
- return new DataTexture(data, width, width, RGBFormat);
239
+ return new DataTexture(data, width, width, RGBAFormat);
246
240
  }
247
241
 
248
242
  __create_rgba_texture(width)
@@ -36,7 +36,7 @@ class GeometryBatcher
36
36
  }
37
37
 
38
38
  const buffer_attribute = new BufferAttribute(new Float32Array(attr_accessor_uvs), 2);
39
- const buffer_geometry = BufferGeometryUtils.mergeBufferGeometries(buffer_geometries);
39
+ const buffer_geometry = BufferGeometryUtils.mergeGeometries(buffer_geometries);
40
40
  buffer_geometry.setAttribute('attr_accessor_uv', buffer_attribute);
41
41
 
42
42
  this.batches.push(new GeometryBatch(buffer_geometry, texture_width));
@@ -41,7 +41,7 @@ class MeshBatcher
41
41
  }
42
42
  }
43
43
 
44
- const buffer_geometry = BufferGeometryUtils.mergeBufferGeometries(geometries);
44
+ const buffer_geometry = BufferGeometryUtils.mergeGeometries(geometries);
45
45
 
46
46
  const buffer_attribute = new BufferAttribute(new Float32Array(attr_mesh_id), 1);
47
47
  buffer_geometry.setAttribute('mesh_id', buffer_attribute);