ohzi-core 9.3.1 → 9.4.1
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 +1 -1
- package/src/Browser.js +27 -1
- package/src/resource_loader/AsyncTextureLoader.js +50 -0
- package/src/resource_loader/CubemapLoader.js +7 -7
- package/types/Browser.d.ts +2 -0
- package/types/resource_loader/AsyncTextureLoader.d.ts +2 -0
- package/types/resource_loader/CubemapLoader.d.ts +1 -1
package/package.json
CHANGED
package/src/Browser.js
CHANGED
|
@@ -33,6 +33,8 @@ class Browser
|
|
|
33
33
|
this.browser_name = 'other';
|
|
34
34
|
break;
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
this.version = this.get_version();
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
get name()
|
|
@@ -62,7 +64,7 @@ class Browser
|
|
|
62
64
|
|
|
63
65
|
get has_webm()
|
|
64
66
|
{
|
|
65
|
-
return this.is_chrome || this.is_firefox || this.is_edge_chromium;
|
|
67
|
+
return !!(this.is_chrome || this.is_firefox || this.is_edge_chromium);
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
get has_hvec()
|
|
@@ -74,6 +76,30 @@ class Browser
|
|
|
74
76
|
{
|
|
75
77
|
return this.has_webm ? 'webm' : this.has_hvec ? 'hvec.mp4' : 'mp4';
|
|
76
78
|
}
|
|
79
|
+
|
|
80
|
+
get_version()
|
|
81
|
+
{
|
|
82
|
+
const ua = navigator.userAgent;
|
|
83
|
+
let tem = '';
|
|
84
|
+
let version = 0;
|
|
85
|
+
|
|
86
|
+
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
87
|
+
if (/trident/i.test(M[1]))
|
|
88
|
+
{
|
|
89
|
+
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
|
|
90
|
+
version = 'IE ' + (tem[1] || '');
|
|
91
|
+
}
|
|
92
|
+
if (M[1] === 'Chrome')
|
|
93
|
+
{
|
|
94
|
+
tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
|
|
95
|
+
if (tem != null) version = tem.slice(1).join(' ').replace('OPR', 'Opera');
|
|
96
|
+
}
|
|
97
|
+
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
98
|
+
if ((tem = ua.match(/version\/(\d+)/i)) != null) M.splice(1, 1, tem[1]);
|
|
99
|
+
version = M.join(' ');
|
|
100
|
+
|
|
101
|
+
return Number(version.split(' ')[1]);
|
|
102
|
+
}
|
|
77
103
|
}
|
|
78
104
|
|
|
79
105
|
const browser = new Browser();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AbstractLoader } from './AbstractLoader';
|
|
2
2
|
|
|
3
3
|
import { Texture } from 'three';
|
|
4
|
+
import { Browser } from '../Browser';
|
|
4
5
|
|
|
5
6
|
class AsyncTextureLoader extends AbstractLoader
|
|
6
7
|
{
|
|
@@ -10,6 +11,18 @@ class AsyncTextureLoader extends AbstractLoader
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
on_preloaded_finished(resource_container)
|
|
14
|
+
{
|
|
15
|
+
if (Browser.is_safari && Browser.version < 15)
|
|
16
|
+
{
|
|
17
|
+
this.load_with_old_method(resource_container);
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
{
|
|
21
|
+
this.load_with_new_method(resource_container);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
load_with_old_method(resource_container)
|
|
13
26
|
{
|
|
14
27
|
if (resource_container.resources_by_url[this.url] === undefined)
|
|
15
28
|
{
|
|
@@ -42,6 +55,43 @@ class AsyncTextureLoader extends AbstractLoader
|
|
|
42
55
|
this.__loading_ended();
|
|
43
56
|
}
|
|
44
57
|
}
|
|
58
|
+
|
|
59
|
+
load_with_new_method(resource_container)
|
|
60
|
+
{
|
|
61
|
+
if (resource_container.resources_by_url[this.url] === undefined)
|
|
62
|
+
{
|
|
63
|
+
const fetchOptions = {};
|
|
64
|
+
fetchOptions.credentials = 'same-origin';
|
|
65
|
+
// fetchOptions.headers = this.requestHeader;
|
|
66
|
+
|
|
67
|
+
fetch(this.url, fetchOptions).then((res) =>
|
|
68
|
+
{
|
|
69
|
+
return res.blob();
|
|
70
|
+
}).then((blob) =>
|
|
71
|
+
{
|
|
72
|
+
return createImageBitmap(blob, { colorSpaceConversion: 'none' });
|
|
73
|
+
}).then((imageBitmap) =>
|
|
74
|
+
{
|
|
75
|
+
const texture = new Texture(imageBitmap);
|
|
76
|
+
texture.needsUpdate = true;
|
|
77
|
+
|
|
78
|
+
resource_container.set_resource(this.resource_id, this.url, texture);
|
|
79
|
+
|
|
80
|
+
this.__update_downloaded_bytes(1, 1);
|
|
81
|
+
this.__loading_ended();
|
|
82
|
+
}).catch(function(e)
|
|
83
|
+
{
|
|
84
|
+
console.error(e);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
{
|
|
89
|
+
resource_container.set_resource(this.resource_id, this.url, resource_container.resources_by_url[this.url]);
|
|
90
|
+
|
|
91
|
+
this.__update_downloaded_bytes(1, 1);
|
|
92
|
+
this.__loading_ended();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
45
95
|
}
|
|
46
96
|
|
|
47
97
|
export { AsyncTextureLoader };
|
|
@@ -4,18 +4,18 @@ import { CubeTextureLoader } from 'three';
|
|
|
4
4
|
|
|
5
5
|
class CubemapLoader extends AbstractLoader
|
|
6
6
|
{
|
|
7
|
-
constructor(resource_id, url, size)
|
|
7
|
+
constructor(resource_id, url, extension, size)
|
|
8
8
|
{
|
|
9
9
|
super(resource_id, url, size);
|
|
10
10
|
this.loader = new CubeTextureLoader();
|
|
11
11
|
this.loader.setPath(url + '/');
|
|
12
12
|
this.urls = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
`px.${extension}`,
|
|
14
|
+
`nx.${extension}`,
|
|
15
|
+
`py.${extension}`,
|
|
16
|
+
`ny.${extension}`,
|
|
17
|
+
`pz.${extension}`,
|
|
18
|
+
`nz.${extension}`
|
|
19
19
|
];
|
|
20
20
|
}
|
|
21
21
|
|
package/types/Browser.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare class Browser {
|
|
|
4
4
|
init(): void;
|
|
5
5
|
browser_name: string;
|
|
6
6
|
agent: string;
|
|
7
|
+
version: number;
|
|
7
8
|
get name(): string;
|
|
8
9
|
get is_safari(): boolean;
|
|
9
10
|
get is_chrome(): boolean;
|
|
@@ -12,4 +13,5 @@ declare class Browser {
|
|
|
12
13
|
get has_webm(): boolean;
|
|
13
14
|
get has_hvec(): boolean;
|
|
14
15
|
get preferred_video_extension(): "webm" | "hvec.mp4" | "mp4";
|
|
16
|
+
get_version(): number;
|
|
15
17
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export class AsyncTextureLoader extends AbstractLoader {
|
|
2
2
|
constructor(resource_id: any, url: any, size: any);
|
|
3
3
|
on_preloaded_finished(resource_container: any): void;
|
|
4
|
+
load_with_old_method(resource_container: any): void;
|
|
5
|
+
load_with_new_method(resource_container: any): void;
|
|
4
6
|
}
|
|
5
7
|
import { AbstractLoader } from "./AbstractLoader";
|