ohzi-core 6.9.0 → 6.12.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/build/index.module.js +1 -1
- package/build/index.module.js.map +1 -1
- package/package.json +2 -2
- package/src/Graphics.js +9 -2
- package/src/Input.js +28 -2
- package/src/RenderLoop.js +5 -5
- package/src/view_components/ApplicationView.js +30 -0
- package/types/Input.d.ts +163 -1
- package/types/RenderLoop.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ohzi-core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"description": "OHZI Core Library",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"module": "build/index.module.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/ohzinteractive/core",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"pit-js": "1.
|
|
39
|
+
"pit-js": "1.9.0",
|
|
40
40
|
"three": "^0.137.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
package/src/Graphics.js
CHANGED
|
@@ -34,12 +34,14 @@ class Graphics
|
|
|
34
34
|
premultipliedAlpha: true,
|
|
35
35
|
preserveDrawingBuffer: true,
|
|
36
36
|
powerPreference: 'high-performance',
|
|
37
|
-
logarithmicDepthBuffer: false
|
|
37
|
+
logarithmicDepthBuffer: false,
|
|
38
|
+
force_webgl2: true,
|
|
39
|
+
xr_enabled: false
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
Object.assign(this.context_attributes, context_attributes);
|
|
41
43
|
|
|
42
|
-
if (context_attributes.force_webgl2)
|
|
44
|
+
if (this.context_attributes.force_webgl2)
|
|
43
45
|
{
|
|
44
46
|
this.canvas_context = canvas.getContext('webgl2', this.context_attributes) ||
|
|
45
47
|
canvas.getContext('webgl', this.context_attributes) ||
|
|
@@ -60,6 +62,11 @@ class Graphics
|
|
|
60
62
|
context: this.canvas_context
|
|
61
63
|
});
|
|
62
64
|
|
|
65
|
+
if (this.context_attributes.xr_enabled)
|
|
66
|
+
{
|
|
67
|
+
this._renderer.xr.enabled = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
this._renderer.autoClear = false;
|
|
64
71
|
|
|
65
72
|
this._renderer.setPixelRatio(1);
|
package/src/Input.js
CHANGED
|
@@ -7,8 +7,9 @@ class Input extends InputController
|
|
|
7
7
|
{
|
|
8
8
|
super();
|
|
9
9
|
|
|
10
|
-
this.
|
|
10
|
+
this.clicked = false;
|
|
11
11
|
this.captured_NDC = { x: 0, y: 0 };
|
|
12
|
+
this.current_NDC_delta = { x: 0, y: 0 };
|
|
12
13
|
|
|
13
14
|
this.keyboard = new KeyboardInput();
|
|
14
15
|
}
|
|
@@ -27,11 +28,36 @@ class Input extends InputController
|
|
|
27
28
|
this.keyboard.dispose();
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
update()
|
|
32
|
+
{
|
|
33
|
+
if (this.left_mouse_button_pressed)
|
|
34
|
+
{
|
|
35
|
+
this.captured_NDC.x = this.NDC.x;
|
|
36
|
+
this.captured_NDC.y = this.NDC.y;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (this.left_mouse_button_down)
|
|
40
|
+
{
|
|
41
|
+
this.current_NDC_delta.x += Math.abs(this.NDC_delta.x);
|
|
42
|
+
this.current_NDC_delta.y += Math.abs(this.NDC_delta.y);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.left_mouse_button_released)
|
|
46
|
+
{
|
|
47
|
+
if (this.current_NDC_delta.x < 0.001 || this.current_NDC_delta.y < 0.001)
|
|
48
|
+
{
|
|
49
|
+
this.clicked = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.current_NDC_delta = { x: 0, y: 0 };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
30
56
|
clear()
|
|
31
57
|
{
|
|
32
58
|
super.clear();
|
|
33
59
|
|
|
34
|
-
this.
|
|
60
|
+
this.clicked = false;
|
|
35
61
|
|
|
36
62
|
this.keyboard.clear();
|
|
37
63
|
}
|
package/src/RenderLoop.js
CHANGED
|
@@ -12,8 +12,6 @@ export default class RenderLoop
|
|
|
12
12
|
{
|
|
13
13
|
target_application = target_application || new BaseApplication();
|
|
14
14
|
|
|
15
|
-
this._frame_id = -1;
|
|
16
|
-
|
|
17
15
|
this.target_application = target_application;
|
|
18
16
|
this.graphics = graphics;
|
|
19
17
|
|
|
@@ -35,6 +33,8 @@ export default class RenderLoop
|
|
|
35
33
|
this.target_application.on_post_start();
|
|
36
34
|
}
|
|
37
35
|
|
|
36
|
+
Input.update();
|
|
37
|
+
|
|
38
38
|
this.target_application.update();
|
|
39
39
|
ViewManager.update();
|
|
40
40
|
ViewComponentManager.update();
|
|
@@ -50,7 +50,6 @@ export default class RenderLoop
|
|
|
50
50
|
|
|
51
51
|
// ###### END CYCLE #######
|
|
52
52
|
|
|
53
|
-
this._frame_id = requestAnimationFrame(this.update.bind(this));
|
|
54
53
|
this.target_application.on_frame_end();
|
|
55
54
|
this.frames_passed++;
|
|
56
55
|
|
|
@@ -69,7 +68,8 @@ export default class RenderLoop
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
this.is_running = true;
|
|
72
|
-
|
|
71
|
+
|
|
72
|
+
this.graphics._renderer.setAnimationLoop(this.update.bind(this));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
stop()
|
|
@@ -79,7 +79,7 @@ export default class RenderLoop
|
|
|
79
79
|
this.is_running = false;
|
|
80
80
|
this.target_application.on_exit();
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
this.graphics._renderer.setAnimationLoop(null);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
set_state(new_state)
|
|
@@ -57,6 +57,36 @@ export default class ApplicationView extends ViewState
|
|
|
57
57
|
this.container.classList.remove('before_exit');
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
load_html_images()
|
|
61
|
+
{
|
|
62
|
+
const images = this.container.querySelectorAll('img');
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < images.length; i++)
|
|
65
|
+
{
|
|
66
|
+
const image = images[i];
|
|
67
|
+
|
|
68
|
+
if (image.dataset.src)
|
|
69
|
+
{
|
|
70
|
+
image.src = image.dataset.src;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
load_html_videos()
|
|
76
|
+
{
|
|
77
|
+
const videos = this.container.querySelectorAll('video');
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < videos.length; i++)
|
|
80
|
+
{
|
|
81
|
+
const video = videos[i];
|
|
82
|
+
|
|
83
|
+
if (video.dataset.src)
|
|
84
|
+
{
|
|
85
|
+
video.src = video.dataset.src;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
60
90
|
set_opacity(current_state_data)
|
|
61
91
|
{
|
|
62
92
|
this.container.style.opacity = current_state_data[`${this.name}_opacity`];
|
package/types/Input.d.ts
CHANGED
|
@@ -1,8 +1,170 @@
|
|
|
1
|
+
import { Vector2 } from "three";
|
|
2
|
+
|
|
1
3
|
export class Input {
|
|
2
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Works for left mouse button or first touch on the screen (primary touch).
|
|
6
|
+
*/
|
|
7
|
+
static left_mouse_button_pressed: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Works for left mouse button or first touch on the screen (primary touch).
|
|
10
|
+
*/
|
|
11
|
+
static left_mouse_button_down: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Works for left mouse button or first touch on the screen (primary touch).
|
|
14
|
+
*/
|
|
15
|
+
static left_mouse_button_released: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Mouse only.
|
|
19
|
+
*/
|
|
20
|
+
static middle_mouse_button_pressed: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Mouse only.
|
|
23
|
+
*/
|
|
24
|
+
static middle_mouse_button_down: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Mouse only.
|
|
27
|
+
*/
|
|
28
|
+
static middle_mouse_button_released: boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Mouse only.
|
|
32
|
+
*/
|
|
33
|
+
static right_mouse_button_pressed: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Mouse only.
|
|
36
|
+
*/
|
|
37
|
+
static right_mouse_button_down: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Mouse only.
|
|
40
|
+
*/
|
|
41
|
+
static right_mouse_button_released: boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Mouse and primary touch.
|
|
45
|
+
*/
|
|
46
|
+
static clicked: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Screen coordinates of the mouse (or primary touch) position.
|
|
50
|
+
*/
|
|
51
|
+
static pointer_pos: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Difference between previous position and current position.
|
|
58
|
+
*/
|
|
59
|
+
static pointer_pos_delta: {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Screen coordinates of the mouse (or primary touch) position, where the origin is in the upper left corner (browser coordinates).
|
|
66
|
+
*/
|
|
67
|
+
static html_pointer_pos: {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The center of all active touches. If using mouse, this is the same as pointer_pos.
|
|
74
|
+
*/
|
|
75
|
+
static pointer_center: {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The center of all active touches. If using mouse, this is the same as pointer_pos.
|
|
82
|
+
*/
|
|
83
|
+
static pointer_center_delta: {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* [-1..1] the center of all active touches. If using mouse, this is the same as pointer_pos.
|
|
90
|
+
*/
|
|
91
|
+
static pointer_center_NDC: {
|
|
92
|
+
x: number;
|
|
93
|
+
y: number;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* [-1..1] difference between previous normalized center and current one.
|
|
98
|
+
*/
|
|
99
|
+
static pointer_center_NDC_delta: {
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Normalized [-1..1] device coordinates for mouse or primary touch.
|
|
106
|
+
*/
|
|
107
|
+
static NDC: {
|
|
108
|
+
x: number;
|
|
109
|
+
y: number;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* [-1..1] difference between previous normalized position and current normalized position.
|
|
114
|
+
*/
|
|
115
|
+
static NDC_delta: {
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Normalized [-1..1] device coordinates for mouse or primary touch, but in browser space (upper left corner maps to <-1,-1>).
|
|
122
|
+
*/
|
|
123
|
+
static html_NDC: {
|
|
124
|
+
x: number;
|
|
125
|
+
y: number;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Normalized [-1..1] device coordinates for mouse or primary touch (captured then left click is pressed), but in browser space (upper left corner maps to <-1,-1>).
|
|
130
|
+
*/
|
|
3
131
|
static captured_NDC: {
|
|
4
132
|
x: number;
|
|
5
133
|
y: number;
|
|
6
134
|
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* This is equivalent to the mouse wheel (-1, 0, 1) or dragging with one finger [-x..x] measured in pixels.
|
|
138
|
+
*/
|
|
139
|
+
static scroll_delta: float;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* This is equivalent to the mouse wheel (-1, 0, 1) or pinching with two fingers [-x..x] measured in pixels.
|
|
143
|
+
*/
|
|
144
|
+
static zoom_delta: float;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns 1 if any mouse button is down, or return the amount of active touches.
|
|
148
|
+
*/
|
|
149
|
+
static pointer_count: integer;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* True if the mouse or primary touch is contained within the bounds of the subregion
|
|
153
|
+
*/
|
|
154
|
+
static pointer_is_within_bounds: boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* True if the pointer is over an html element
|
|
158
|
+
*/
|
|
159
|
+
static pointer_is_over_element(html_element: any): boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Call this at the beginning of the current frame.
|
|
163
|
+
*/
|
|
164
|
+
static update(): void;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Call this at the end of the current frame.
|
|
168
|
+
*/
|
|
7
169
|
static clear(): void;
|
|
8
170
|
}
|