ohzi-core 6.11.0 → 6.13.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": "6.11.0",
3
+ "version": "6.13.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.8.6",
39
+ "pit-js": "1.9.0",
40
40
  "three": "^0.137.0"
41
41
  },
42
42
  "devDependencies": {
package/src/Input.js CHANGED
@@ -7,8 +7,9 @@ class Input extends InputController
7
7
  {
8
8
  super();
9
9
 
10
- this.left_mouse_button_clicked = false;
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.left_mouse_button_clicked = false;
60
+ this.clicked = false;
35
61
 
36
62
  this.keyboard.clear();
37
63
  }
@@ -5,7 +5,8 @@ export default class KeyboardInput
5
5
  this.ctrlz_pressed = false;
6
6
  this.ctrlz_fired = false;
7
7
 
8
- this.keys = [];
8
+ this.keys = {};
9
+ this.keys_keys = [];
9
10
  this.container = container;
10
11
 
11
12
  this.container.addEventListener('keydown', this.on_key_down.bind(this), false);
@@ -33,16 +34,17 @@ export default class KeyboardInput
33
34
  clear()
34
35
  {
35
36
  this.ctrlz_pressed = false;
36
- for (let i = 0; i < this.keys.length; i++)
37
+
38
+ for (let i = 0; i < this.keys_keys.length; i++)
37
39
  {
38
- this.keys[i].pressed = false;
39
- this.keys[i].released = false;
40
+ this.keys[this.keys_keys[i]].pressed = false;
41
+ this.keys[this.keys_keys[i]].released = false;
40
42
  }
41
43
  }
42
44
 
43
45
  release_key(key_name)
44
46
  {
45
- const key = this.keys.find(key => key.key_name === key_name);
47
+ const key = this.keys[key_name];
46
48
  if (key)
47
49
  {
48
50
  key.fired = false;
@@ -55,16 +57,16 @@ export default class KeyboardInput
55
57
  {
56
58
  this.ctrlz_fired = false;
57
59
 
58
- for (let i = 0; i < this.keys.length; i++)
60
+ for (let i = 0; i < this.keys_keys.length; i++)
59
61
  {
60
- this.keys[i].fired = false;
61
- this.keys[i].down = false;
62
+ this.keys[this.keys_keys[i]].fired = false;
63
+ this.keys[this.keys_keys[i]].down = false;
62
64
  }
63
65
  }
64
66
 
65
67
  press_key(key_name)
66
68
  {
67
- const key = this.keys.find(key => key.key_name === key_name);
69
+ const key = this.keys[key_name];
68
70
  if (key)
69
71
  {
70
72
  if (key.down === false)
@@ -78,7 +80,7 @@ export default class KeyboardInput
78
80
 
79
81
  is_key_pressed(key_name)
80
82
  {
81
- const key = this.keys.find(key => key.key_name === key_name);
83
+ const key = this.keys[key_name];
82
84
  if (key)
83
85
  {
84
86
  return key.pressed;
@@ -88,7 +90,7 @@ export default class KeyboardInput
88
90
 
89
91
  is_key_down(key_name)
90
92
  {
91
- const key = this.keys.find(key => key.key_name === key_name);
93
+ const key = this.keys[key_name];
92
94
  if (key)
93
95
  {
94
96
  return key.down;
@@ -98,7 +100,7 @@ export default class KeyboardInput
98
100
 
99
101
  is_key_released(key_name)
100
102
  {
101
- const key = this.keys.find(key => key.key_name === key_name);
103
+ const key = this.keys[key_name];
102
104
  if (key)
103
105
  {
104
106
  return key.released;
@@ -109,31 +111,20 @@ export default class KeyboardInput
109
111
 
110
112
  register_key(key)
111
113
  {
112
- this.keys.push(
114
+ this.keys[key] =
113
115
  {
114
116
  key_name: key,
115
117
  pressed: false,
116
118
  down: false,
117
119
  fired: false
118
- });
120
+ };
121
+
122
+ this.keys_keys = Object.keys(this.keys);
119
123
  }
120
124
 
121
125
  unregister_key(key_name)
122
126
  {
123
- let key = undefined;
124
- for (let i = 0; i < this.keys.length; i++)
125
- {
126
- if (this.keys[i].key_name === key_name)
127
- {
128
- key = this.keys[i];
129
- }
130
- }
131
-
132
- const index = this.keys.indexOf(key);
133
- if (index > -1)
134
- {
135
- this.keys.splice(index, 1);
136
- }
127
+ delete this.keys[key_name];
137
128
  }
138
129
 
139
130
  dispose()
package/src/RenderLoop.js CHANGED
@@ -33,6 +33,8 @@ export default class RenderLoop
33
33
  this.target_application.on_post_start();
34
34
  }
35
35
 
36
+ Input.update();
37
+
36
38
  this.target_application.update();
37
39
  ViewManager.update();
38
40
  ViewComponentManager.update();
package/src/index.js CHANGED
@@ -48,6 +48,7 @@ import CameraUtilities from './utilities/CameraUtilities';
48
48
  import EasingFunctions from './utilities/EasingFunctions';
49
49
  import FrustumPointFitter from './utilities/FrustumPointFitter';
50
50
  import GeometryUtilities from './utilities/GeometryUtilities';
51
+ import HTMLUtilities from './utilities/HTMLUtilities';
51
52
  import ImageUtilities from './utilities/ImageUtilities';
52
53
  import OMath from './utilities/OMath';
53
54
  import MeshSampler from './utilities/MeshSampler';
@@ -146,6 +147,7 @@ export {
146
147
  EasingFunctions,
147
148
  FrustumPointFitter,
148
149
  GeometryUtilities,
150
+ HTMLUtilities,
149
151
  ImageUtilities,
150
152
  OMath,
151
153
  MeshSampler,
@@ -0,0 +1,44 @@
1
+ export default class HTMLUtilities
2
+ {
3
+ static load_images(container)
4
+ {
5
+ const images = container.querySelectorAll('img');
6
+
7
+ for (let i = 0; i < images.length; i++)
8
+ {
9
+ const image = images[i];
10
+
11
+ if (image.dataset.src)
12
+ {
13
+ image.src = image.dataset.src;
14
+ }
15
+ }
16
+
17
+ const image_objects = container.querySelectorAll('object');
18
+
19
+ for (let i = 0; i < image_objects.length; i++)
20
+ {
21
+ const image_object = image_objects[i];
22
+
23
+ if (image_object.dataset.src)
24
+ {
25
+ image_object.data = image_object.dataset.src;
26
+ }
27
+ }
28
+ }
29
+
30
+ static load_videos(container)
31
+ {
32
+ const videos = container.querySelectorAll('video');
33
+
34
+ for (let i = 0; i < videos.length; i++)
35
+ {
36
+ const video = videos[i];
37
+
38
+ if (video.dataset.src)
39
+ {
40
+ video.src = video.dataset.src;
41
+ }
42
+ }
43
+ }
44
+ }
@@ -1,9 +1,34 @@
1
1
  export default class ObjectUtilities
2
2
  {
3
- constructor()
4
- {}
3
+ static is_object(item)
4
+ {
5
+ return (item && typeof item === 'object' && !Array.isArray(item));
6
+ }
7
+
8
+ static merge_deep(target, ...sources)
9
+ {
10
+ if (!sources.length) return target;
11
+ const source = sources.shift();
12
+
13
+ if (ObjectUtilities.is_object(target) && ObjectUtilities.is_object(source))
14
+ {
15
+ for (const key in source)
16
+ {
17
+ if (ObjectUtilities.is_object(source[key]))
18
+ {
19
+ if (!target[key]) Object.assign(target, { [key]: {} });
20
+ ObjectUtilities.merge_deep(target[key], source[key]);
21
+ }
22
+ else
23
+ {
24
+ Object.assign(target, { [key]: source[key] });
25
+ }
26
+ }
27
+ }
28
+
29
+ return ObjectUtilities.merge_deep(target, ...sources);
30
+ }
5
31
 
6
- // Changes XML to JSON
7
32
  static xml_to_json(xml)
8
33
  {
9
34
  // Create the return object
@@ -1,4 +1,5 @@
1
1
  import ResourceContainer from '../ResourceContainer';
2
+ import HTMLUtilities from '../utilities/HTMLUtilities';
2
3
  import ViewManager from './ViewManager';
3
4
  import ViewState from './ViewState';
4
5
 
@@ -59,32 +60,12 @@ export default class ApplicationView extends ViewState
59
60
 
60
61
  load_html_images()
61
62
  {
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
- }
63
+ HTMLUtilities.load_images(this.container);
73
64
  }
74
65
 
75
66
  load_html_videos()
76
67
  {
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
- }
68
+ HTMLUtilities.load_videos(this.container);
88
69
  }
89
70
 
90
71
  set_opacity(current_state_data)
@@ -1,3 +1,4 @@
1
+ import HTMLUtilities from '../utilities/HTMLUtilities';
1
2
  import ViewComponentManager from './ViewComponentManager';
2
3
 
3
4
  export default class ViewComponent
@@ -58,4 +59,14 @@ export default class ViewComponent
58
59
  }
59
60
  }
60
61
  }
62
+
63
+ load_html_images()
64
+ {
65
+ HTMLUtilities.load_images(this.container);
66
+ }
67
+
68
+ load_html_videos()
69
+ {
70
+ HTMLUtilities.load_videos(this.container);
71
+ }
61
72
  }
package/types/Input.d.ts CHANGED
@@ -1,8 +1,170 @@
1
+ import { Vector2 } from "three";
2
+
1
3
  export class Input {
2
- static left_mouse_button_clicked: boolean;
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 when left click is pressed.
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
  }
@@ -0,0 +1,10 @@
1
+ export class HTMLUtilities {
2
+ /**
3
+ * Load Images defined in data-src.
4
+ */
5
+ static load_images(container: HTMLElement): void;
6
+ /**
7
+ * Load Videos defined in data-src.
8
+ */
9
+ static load_videos(container: HTMLElement): void;
10
+ }
@@ -1,5 +1,16 @@
1
1
  export class ObjectUtilities {
2
- static xml_to_json(xml: any): {
3
- '@attributes': {};
4
- };
2
+ /**
3
+ * Simple object check.
4
+ */
5
+ static is_object(item: any): boolean;
6
+
7
+ /**
8
+ * Deep merge two objects.
9
+ */
10
+ static merge_deep(target: any, ...sources: any): void;
11
+
12
+ /**
13
+ * Convert XML to JSON
14
+ */
15
+ static xml_to_json(xml: any): object;
5
16
  }
@@ -6,6 +6,15 @@ export class ApplicationView extends ViewState {
6
6
  });
7
7
  container: any;
8
8
  url: any;
9
+ start(): void;
10
+ show(): void;
11
+ before_enter(): void;
12
+ on_enter(): void;
13
+ before_exit(): void;
14
+ on_exit(): void;
15
+ update(): void;
9
16
  set_opacity(opacity: any): void;
17
+ load_html_images(): void;
18
+ load_html_videos(): void;
10
19
  }
11
20
  import ViewState from "./ViewState";
@@ -10,4 +10,6 @@ export class ViewComponent {
10
10
  update(): void;
11
11
  on_exit(): void;
12
12
  set_opacity(opacity: any): void;
13
+ load_html_images(): void;
14
+ load_html_videos(): void;
13
15
  }