ohzi-core 8.0.2 → 8.1.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": "8.0.2",
3
+ "version": "8.1.0",
4
4
  "description": "OHZI Core Library",
5
5
  "source": "src/index.js",
6
6
  "module": "build/index.module.js",
@@ -3,6 +3,8 @@ class CameraManager
3
3
  init()
4
4
  {
5
5
  this._current = undefined;
6
+ // VR Spectator
7
+ this._spectator = undefined;
6
8
  }
7
9
 
8
10
  set current(camera)
@@ -14,6 +16,16 @@ class CameraManager
14
16
  {
15
17
  return this._current;
16
18
  }
19
+
20
+ set spectator(camera)
21
+ {
22
+ this._spectator = camera;
23
+ }
24
+
25
+ get spectator()
26
+ {
27
+ return this._spectator;
28
+ }
17
29
  }
18
30
 
19
31
  export default new CameraManager();
package/src/Graphics.js CHANGED
@@ -77,8 +77,10 @@ class Graphics
77
77
  {
78
78
  this._renderer.xr.enabled = true;
79
79
  }
80
-
81
- this._renderer.autoClear = false;
80
+ else
81
+ {
82
+ this._renderer.autoClear = false;
83
+ }
82
84
 
83
85
  this._renderer.setPixelRatio(1);
84
86
 
package/src/index.js CHANGED
@@ -20,6 +20,7 @@ import Input from './Input';
20
20
  import Initializer from './Initializer';
21
21
  import NormalAORender from './render_mode/NormalAORender';
22
22
  import NormalRender from './render_mode/NormalRender';
23
+ import VRRender from './render_mode/VRRender';
23
24
  import UnrealBloomRender from './render_mode/UnrealBloomRender';
24
25
  import OrthographicCamera from './OrthographicCamera';
25
26
  import OS from './OS';
@@ -131,6 +132,7 @@ export {
131
132
  Initializer,
132
133
  NormalAORender,
133
134
  NormalRender,
135
+ VRRender,
134
136
  UnrealBloomRender,
135
137
  OrthographicCamera,
136
138
  OS,
@@ -0,0 +1,69 @@
1
+ import CameraManager from '../CameraManager';
2
+ import SceneManager from '../SceneManager';
3
+ import BaseRender from '../render_mode/BaseRender';
4
+ import Graphics from '../Graphics';
5
+
6
+ export default class VRRender extends BaseRender
7
+ {
8
+ constructor()
9
+ {
10
+ super();
11
+ }
12
+
13
+ render()
14
+ {
15
+ // Graphics.clear(undefined, CameraManager.current, true, true);
16
+
17
+ if (SceneManager.current.on_pre_render)
18
+ {
19
+ SceneManager.current.on_pre_render();
20
+ }
21
+
22
+ if (SceneManager.current.render)
23
+ {
24
+ SceneManager.current.render();
25
+ }
26
+ else
27
+ {
28
+ Graphics.render(SceneManager.current, CameraManager.current, Graphics._renderer.getRenderTarget());
29
+ }
30
+
31
+ this.render_spectator_camera();
32
+
33
+ if (SceneManager.current.on_post_render)
34
+ {
35
+ SceneManager.current.on_post_render();
36
+ }
37
+ }
38
+
39
+ render_spectator_camera()
40
+ {
41
+ const spectator_camera = CameraManager.spectator;
42
+
43
+ if (spectator_camera && Graphics._renderer.xr.isPresenting)
44
+ {
45
+ // Copy the XR Camera's position and rotation, but use your
46
+ // main camera's projection matrix
47
+ const xrCam = Graphics._renderer.xr.getCamera(CameraManager.current);
48
+
49
+ spectator_camera.projectionMatrix.copy(CameraManager.current.projectionMatrix);
50
+
51
+ spectator_camera.position.copy(xrCam.position);
52
+ spectator_camera.quaternion.copy(xrCam.quaternion);
53
+
54
+ // we'll restore this later
55
+ const currentRenderTarget = Graphics._renderer.getRenderTarget();
56
+
57
+ // turn off the WebXR rendering
58
+ Graphics._renderer.xr.isPresenting = false;
59
+
60
+ // render to the canvas on our main display
61
+ Graphics._renderer.setRenderTarget(null);
62
+ Graphics._renderer.render(SceneManager.current, spectator_camera);
63
+
64
+ // reset back to enable WebXR
65
+ Graphics._renderer.setRenderTarget(currentRenderTarget);
66
+ Graphics._renderer.xr.isPresenting = true;
67
+ }
68
+ }
69
+ }