ohzi-core 11.2.4 → 12.0.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.mjs +2 -0
- package/build/index.mjs.map +1 -0
- package/package.json +10 -8
- package/src/BaseApplication.js +0 -3
- package/src/Browser.js +4 -4
- package/src/Initializer.js +5 -1
- package/src/OS.js +2 -2
- package/src/RenderLoop.js +9 -9
- package/src/ResourceContainer.js +0 -1
- package/src/Screen.js +55 -0
- package/src/Time.js +2 -14
- package/src/action_sequencer/ActionSequencer.js +7 -3
- package/src/gpu_particles/ParticleAttribute.js +2 -2
- package/src/index.js +18 -12
- package/src/loaders/AsyncAbstractLoader.js +144 -0
- package/src/loaders/AsyncAudiosLoader.js +34 -0
- package/src/loaders/AsyncObjectsLoader.js +38 -0
- package/src/loaders/AsyncTexturesLoader.js +70 -0
- package/src/loaders/assets_loader/AbstractLoader.js +129 -0
- package/src/loaders/assets_loader/AssetLoader.js +24 -0
- package/src/loaders/assets_loader/AsyncAssetsLoaderWorker.js +69 -0
- package/src/loaders/assets_loader/ResourceBatch.js +86 -0
- package/src/loaders/assets_loader/ResourceContainer.js +37 -0
- package/src/loaders/assets_loader/ResourceLoaderChecker.js +39 -0
- package/src/render_mode/NormalAORender.js +2 -2
- package/src/resource_loader/AsyncTextureLoader.js +1 -3
- package/src/resource_loader/BasisLoader.js +4 -0
- package/src/scenes/AbstractScene.js +166 -0
- package/src/scenes/loading_states/CompilatorManager.js +41 -0
- package/src/scenes/loading_states/HighQualityLoadingState.js +28 -0
- package/src/scenes/loading_states/LoadingState.js +106 -0
- package/src/scenes/loading_states/RegularLoadingState.js +41 -0
- package/src/utilities/OMath.js +2 -0
- package/src/view_components/ApplicationView.js +26 -3
- package/src/view_components/TransitionManager.js +15 -0
- package/src/view_components/ViewComponent.js +26 -12
- package/src/view_components/ViewComponentManager.js +10 -0
- package/src/view_components/ViewManager.js +52 -14
- package/src/view_components/ViewState.js +7 -7
- package/src/view_components/transition/ActionSequencerBuilder.js +3 -3
- package/src/view_components/transition/TransitionTable.js +2 -9
- package/types/BaseApplication.d.ts +0 -1
- package/types/Browser.d.ts +1 -1
- package/types/CameraManager.d.ts +4 -2
- package/types/Graphics.d.ts +3 -8
- package/types/Initializer.d.ts +1 -1
- package/types/RenderLoop.d.ts +2 -1
- package/types/SceneManager.d.ts +3 -1
- package/types/Time.d.ts +0 -5
- package/types/action_sequencer/ActionSequencer.d.ts +2 -2
- package/types/canvas_drawer/SimpleTextDrawer.d.ts +1 -0
- package/types/index.d.ts +122 -105
- package/types/loaders/AsyncAbstractLoader.d.ts +27 -0
- package/types/loaders/AsyncAudiosLoader.d.ts +5 -0
- package/types/loaders/AsyncObjectsLoader.d.ts +6 -0
- package/types/loaders/AsyncTexturesLoader.d.ts +8 -0
- package/types/render_mode/NormalAORender.d.ts +0 -1
- package/types/resource_loader/AsyncTextureLoader.d.ts +1 -1
- package/types/resource_loader/AudioLoader.d.ts +1 -0
- package/types/resource_loader/BasisLoader.d.ts +1 -0
- package/types/resource_loader/CubemapLoader.d.ts +1 -0
- package/types/resource_loader/DAELoader.d.ts +1 -0
- package/types/resource_loader/FileLoader.d.ts +1 -0
- package/types/resource_loader/FontLoader.d.ts +1 -0
- package/types/resource_loader/GLTFDRACOLoader.d.ts +1 -0
- package/types/resource_loader/GLTFLoader.d.ts +1 -0
- package/types/resource_loader/HDRCubeTextureLoader.d.ts +1 -0
- package/types/resource_loader/OBJLoader.d.ts +1 -0
- package/types/resource_loader/PointArrayLoader.d.ts +1 -0
- package/types/resource_loader/RGBETextureLoader.d.ts +1 -0
- package/types/resource_loader/TextLoader.d.ts +1 -0
- package/types/scenes/AbstractScene.d.ts +31 -0
- package/types/scenes/loading_states/CompilatorManager.d.ts +8 -0
- package/types/scenes/loading_states/HighQualityLoadingState.d.ts +3 -0
- package/types/scenes/loading_states/LoadingState.d.ts +28 -0
- package/types/scenes/loading_states/RegularLoadingState.d.ts +5 -0
- package/types/utilities/FrustumPointFitter.d.ts +3 -1
- package/types/utilities/OMath.d.ts +9 -9
- package/types/view_components/ApplicationView.d.ts +3 -1
- package/types/view_components/ViewComponent.d.ts +5 -1
- package/types/view_components/ViewComponentManager.d.ts +1 -0
- package/types/view_components/ViewManager.d.ts +22 -4
- package/types/view_components/ViewState.d.ts +3 -0
- package/types/view_components/transition/ActionSequencerBuilder.d.ts +1 -1
- package/types/view_components/transition/TransitionTable.d.ts +0 -2
- package/build/index.module.js +0 -2
- package/build/index.module.js.map +0 -1
- package/src/view_components/ApplicationViewController.js +0 -85
- package/src/view_components/VCManager.js +0 -9
- package/src/view_components/ViewComponentController.js +0 -73
- package/src/view_components/ViewComponentControllerManager.js +0 -59
- package/src/view_components/ViewControllerManager.js +0 -91
- package/src/view_components/WorkerToMain.js +0 -25
- package/types/blitter_index.d.ts +0 -6
- package/types/render_mode/TransparencyMixRender.d.ts +0 -21
- package/types/view_components/ApplicationViewController.d.ts +0 -11
- package/types/view_components/VCManager.d.ts +0 -5
- package/types/view_components/ViewComponentController.d.ts +0 -14
- package/types/view_components/ViewComponentControllerManager.d.ts +0 -12
- package/types/view_components/ViewControllerManager.d.ts +0 -12
- package/types/view_components/WorkerToMain.d.ts +0 -8
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
|
|
2
|
+
class AbstractLoader
|
|
3
|
+
{
|
|
4
|
+
constructor(resource_id, url, size = 1)
|
|
5
|
+
{
|
|
6
|
+
this.resource_id = resource_id;
|
|
7
|
+
this.url = url;
|
|
8
|
+
this.loaded_bytes = 0;
|
|
9
|
+
this.total_bytes = size;
|
|
10
|
+
|
|
11
|
+
this.has_finished = false;
|
|
12
|
+
this.has_error = false;
|
|
13
|
+
this.error_message = 'none';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
is_int(n)
|
|
17
|
+
{
|
|
18
|
+
return Number(n) === n && n % 1 === 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
is_float(n)
|
|
22
|
+
{
|
|
23
|
+
return Number(n) === n && n % 1 !== 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
is_number(n)
|
|
27
|
+
{
|
|
28
|
+
return this.is_int(n) || this.is_float(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
__update_downloaded_bytes(loaded, total)
|
|
32
|
+
{
|
|
33
|
+
loaded = this.is_number(loaded) ? loaded : 1;
|
|
34
|
+
total = this.is_number(total) ? total : 1;
|
|
35
|
+
|
|
36
|
+
this.loaded_bytes = loaded;
|
|
37
|
+
|
|
38
|
+
if (total > 0)
|
|
39
|
+
{
|
|
40
|
+
this.total_bytes = total;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (this.loaded_bytes > this.total_bytes)
|
|
44
|
+
{
|
|
45
|
+
console.warn('Total bytes is smaller than loaded ones. Please set total bytes by hand to:', this.url);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
__loading_ended()
|
|
50
|
+
{
|
|
51
|
+
this.has_finished = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
__set_error(message)
|
|
55
|
+
{
|
|
56
|
+
this.has_error = true;
|
|
57
|
+
this.error_message = message;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
print_error()
|
|
61
|
+
{
|
|
62
|
+
console.error('Error while loading ' + this.resource_id + '\n\t path: ' + this.url + '\n\t\t' + this.error_message);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
load(resource_container)
|
|
66
|
+
{
|
|
67
|
+
if (resource_container.resources_by_url[this.url] === undefined)
|
|
68
|
+
{
|
|
69
|
+
const cache = 'no-cache';
|
|
70
|
+
|
|
71
|
+
fetch(this.url, {
|
|
72
|
+
method: 'GET', // *GET, POST, PUT, DELETE, etc.
|
|
73
|
+
mode: 'cors', // no-cors, *cors, same-origin
|
|
74
|
+
cache: cache, // *default, no-cache, reload, force-cache, only-if-cached
|
|
75
|
+
credentials: 'same-origin', // include, *same-origin, omit
|
|
76
|
+
redirect: 'follow' // manual, *follow, error
|
|
77
|
+
})
|
|
78
|
+
.then(this.on_progress.bind(this, resource_container))
|
|
79
|
+
.catch(this.__on_error.bind(this));
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
resource_container.set_resource(this.resource_id, this.url, resource_container.resources_by_url[this.url]);
|
|
84
|
+
|
|
85
|
+
this.__update_downloaded_bytes(1, 1);
|
|
86
|
+
this.__loading_ended();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async on_progress(resource_container, response)
|
|
91
|
+
{
|
|
92
|
+
const response_clone = response.clone();
|
|
93
|
+
const reader = response.body.getReader();
|
|
94
|
+
|
|
95
|
+
// Step 2: get total length
|
|
96
|
+
const contentLength = +response.headers.get('Content-Length');
|
|
97
|
+
|
|
98
|
+
// Step 3: read the data
|
|
99
|
+
let receivedLength = 0; // received that many bytes at the moment
|
|
100
|
+
|
|
101
|
+
while (true)
|
|
102
|
+
{
|
|
103
|
+
const { done, value } = await reader.read();
|
|
104
|
+
|
|
105
|
+
if (done)
|
|
106
|
+
{
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
receivedLength += value.length;
|
|
111
|
+
|
|
112
|
+
this.__update_downloaded_bytes(receivedLength, contentLength);
|
|
113
|
+
// console.log(`Received ${receivedLength} of ${contentLength}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.on_preloaded_finished(resource_container, response_clone);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
on_preloaded_finished(resource_container, response)
|
|
120
|
+
{
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
__on_error(data)
|
|
124
|
+
{
|
|
125
|
+
console.error(data);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { AbstractLoader };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractLoader } from './AbstractLoader';
|
|
2
|
+
|
|
3
|
+
class AssetLoader extends AbstractLoader
|
|
4
|
+
{
|
|
5
|
+
constructor(resource_id, url, size)
|
|
6
|
+
{
|
|
7
|
+
super(resource_id, url, size);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
on_preloaded_finished(resource_container, response)
|
|
11
|
+
{
|
|
12
|
+
response.blob().then((blob) =>
|
|
13
|
+
{
|
|
14
|
+
const url = URL.createObjectURL(blob);
|
|
15
|
+
|
|
16
|
+
resource_container.set_resource(this.resource_id, this.url, url);
|
|
17
|
+
|
|
18
|
+
this.__update_downloaded_bytes(1, 1);
|
|
19
|
+
this.__loading_ended();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { AssetLoader };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// We use custom ResourceBatch, ResourceContainer and AbstractLoader to reduce build size
|
|
2
|
+
import { ResourceBatch } from './ResourceBatch';
|
|
3
|
+
import { ResourceContainer } from './ResourceContainer';
|
|
4
|
+
import { AssetLoader } from './AssetLoader';
|
|
5
|
+
import { ResourceLoaderChecker } from './ResourceLoaderChecker';
|
|
6
|
+
|
|
7
|
+
class AsyncAssetsLoaderWorker
|
|
8
|
+
{
|
|
9
|
+
run()
|
|
10
|
+
{
|
|
11
|
+
this.assets = {};
|
|
12
|
+
this.resource_batches = {};
|
|
13
|
+
this.resource_container = new ResourceContainer('worker');
|
|
14
|
+
this.resource_loader_checkers = {};
|
|
15
|
+
|
|
16
|
+
this.__bind_messages();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
__bind_messages()
|
|
20
|
+
{
|
|
21
|
+
self.addEventListener('message', (e) =>
|
|
22
|
+
{
|
|
23
|
+
const message = e.data;
|
|
24
|
+
|
|
25
|
+
switch (message.type)
|
|
26
|
+
{
|
|
27
|
+
case 'assets':
|
|
28
|
+
this.assets[message.loader_name] = this.assets[message.loader_name] ? this.assets[message.loader_name] : [];
|
|
29
|
+
this.assets[message.loader_name] = this.assets[message.loader_name].concat(message.data);
|
|
30
|
+
|
|
31
|
+
break;
|
|
32
|
+
case 'load':
|
|
33
|
+
this.__setup_batch(message.loader_name);
|
|
34
|
+
|
|
35
|
+
this.resource_batches[message.loader_name].load();
|
|
36
|
+
this.resource_loader_checkers[message.loader_name].setup(this.on_assets_ready.bind(this, message.loader_name), 10);
|
|
37
|
+
this.resource_loader_checkers[message.loader_name].check();
|
|
38
|
+
|
|
39
|
+
break;
|
|
40
|
+
case 'reset':
|
|
41
|
+
// TODO: maybe not necessary anymore
|
|
42
|
+
this.assets[message.loader_name] = [];
|
|
43
|
+
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
on_assets_ready(loader_name)
|
|
50
|
+
{
|
|
51
|
+
postMessage({ type: `asset_loaded_${loader_name}`, data: this.resource_container.resources });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
__setup_batch(loader_name)
|
|
55
|
+
{
|
|
56
|
+
// this.resource_containers[loader_name] = new ResourceContainer(loader_name);
|
|
57
|
+
this.resource_batches[loader_name] = new ResourceBatch(loader_name, this.resource_container);
|
|
58
|
+
this.resource_loader_checkers[loader_name] = new ResourceLoaderChecker(this.resource_batches[loader_name]);
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < this.assets[loader_name].length; i++)
|
|
61
|
+
{
|
|
62
|
+
const asset = this.assets[loader_name][i];
|
|
63
|
+
|
|
64
|
+
this.resource_batches[loader_name].add_loader(new AssetLoader(asset.name, asset.url, asset.size));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
new AsyncAssetsLoaderWorker().run();
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
class ResourceBatch
|
|
3
|
+
{
|
|
4
|
+
constructor(batch_name, resource_container)
|
|
5
|
+
{
|
|
6
|
+
this.resource_loaders = [];
|
|
7
|
+
this.batch_name = batch_name || 'unnamed batch';
|
|
8
|
+
this.resource_container = resource_container;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
add_loader(loader)
|
|
12
|
+
{
|
|
13
|
+
this.resource_loaders.push(loader);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
load()
|
|
17
|
+
{
|
|
18
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
19
|
+
{
|
|
20
|
+
this.resource_loaders[i].load(this.resource_container);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get loading_finished()
|
|
25
|
+
{
|
|
26
|
+
let finished = true;
|
|
27
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
28
|
+
{
|
|
29
|
+
finished = finished && this.resource_loaders[i].has_finished;
|
|
30
|
+
}
|
|
31
|
+
return finished;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get has_errors()
|
|
35
|
+
{
|
|
36
|
+
let has_error = false;
|
|
37
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
38
|
+
{
|
|
39
|
+
has_error = has_error || this.resource_loaders[i].has_error;
|
|
40
|
+
}
|
|
41
|
+
return has_error;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
print_errors()
|
|
45
|
+
{
|
|
46
|
+
console.error('Batch <' + this.batch_name + '> could not load successfully');
|
|
47
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
48
|
+
{
|
|
49
|
+
if (this.resource_loaders[i].has_error)
|
|
50
|
+
{
|
|
51
|
+
this.resource_loaders[i].print_error();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get_progress()
|
|
57
|
+
{
|
|
58
|
+
return this.get_loaded_bytes() / this.get_total_bytes();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get_loaded_bytes()
|
|
62
|
+
{
|
|
63
|
+
let loaded_bytes = 1;
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
66
|
+
{
|
|
67
|
+
loaded_bytes += this.resource_loaders[i].loaded_bytes;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return loaded_bytes;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get_total_bytes()
|
|
74
|
+
{
|
|
75
|
+
let total_bytes = 1;
|
|
76
|
+
|
|
77
|
+
for (let i = 0; i < this.resource_loaders.length; i++)
|
|
78
|
+
{
|
|
79
|
+
total_bytes += this.resource_loaders[i].total_bytes;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return total_bytes;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { ResourceBatch };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
class ResourceContainer
|
|
3
|
+
{
|
|
4
|
+
constructor(name)
|
|
5
|
+
{
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.resources = {};
|
|
8
|
+
this.resources_by_url = {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
set_resource(name, url, resource)
|
|
12
|
+
{
|
|
13
|
+
const urls = Object.keys(this.resources_by_url);
|
|
14
|
+
|
|
15
|
+
if (urls.includes(url))
|
|
16
|
+
{
|
|
17
|
+
this.resources[name] = this.resources_by_url[url];
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
{
|
|
21
|
+
this.resources[name] = resource;
|
|
22
|
+
this.resources_by_url[url] = resource;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get_resource(name)
|
|
27
|
+
{
|
|
28
|
+
return this.resources[name];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get(name)
|
|
32
|
+
{
|
|
33
|
+
return this.resources[name];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { ResourceContainer };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class ResourceLoaderChecker
|
|
2
|
+
{
|
|
3
|
+
constructor(batch)
|
|
4
|
+
{
|
|
5
|
+
this.batch = batch;
|
|
6
|
+
this.on_resources_loaded = undefined;
|
|
7
|
+
this.timeout = 10;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
setup(on_resources_loaded, timeout = 10)
|
|
11
|
+
{
|
|
12
|
+
this.on_resources_loaded = on_resources_loaded;
|
|
13
|
+
this.timeout = timeout;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
check()
|
|
17
|
+
{
|
|
18
|
+
if (this.batch.loading_finished)
|
|
19
|
+
{
|
|
20
|
+
if (this.batch.has_errors)
|
|
21
|
+
{
|
|
22
|
+
this.batch.print_errors();
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
{
|
|
26
|
+
this.on_resources_loaded();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
{
|
|
31
|
+
setTimeout(function()
|
|
32
|
+
{
|
|
33
|
+
this.check(this.batch, this.on_resources_loaded);
|
|
34
|
+
}.bind(this), this.timeout);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { ResourceLoaderChecker };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CameraManager } from '../CameraManager';
|
|
2
2
|
import { Graphics } from '../Graphics';
|
|
3
|
-
import { OScreen } from '../OScreen';
|
|
4
|
-
import { SceneManager } from '../SceneManager';
|
|
5
3
|
import { DisplayNormalTextureMaterial } from '../materials/DisplayNormalTextureMaterial';
|
|
6
4
|
import { SSAOComposeMaterial } from '../materials/SSAOComposeMaterial';
|
|
7
5
|
import { SSAOMaterial } from '../materials/SSAOMaterial';
|
|
6
|
+
import { OScreen } from '../OScreen';
|
|
8
7
|
import { BaseRender } from '../render_mode/BaseRender';
|
|
9
8
|
import { Blurrer } from '../render_utilities/Blurrer';
|
|
9
|
+
import { SceneManager } from '../SceneManager';
|
|
10
10
|
|
|
11
11
|
import { WebGLRenderTarget } from 'three';
|
|
12
12
|
|
|
@@ -3,7 +3,7 @@ import { AbstractLoader } from './AbstractLoader';
|
|
|
3
3
|
|
|
4
4
|
import { NoColorSpace, SRGBColorSpace, Texture } from 'three';
|
|
5
5
|
|
|
6
|
-
class AsyncTextureLoader extends AbstractLoader
|
|
6
|
+
export class AsyncTextureLoader extends AbstractLoader
|
|
7
7
|
{
|
|
8
8
|
constructor(resource_id, url, size, flipY = true, premultiplyAlpha = false, colorSpaceConversion = true)
|
|
9
9
|
{
|
|
@@ -109,5 +109,3 @@ class AsyncTextureLoader extends AbstractLoader
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
export { AsyncTextureLoader };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AbstractLoader } from './AbstractLoader';
|
|
2
2
|
|
|
3
|
+
// import { sRGBEncoding } from 'three';
|
|
4
|
+
|
|
3
5
|
class BasisLoader extends AbstractLoader
|
|
4
6
|
{
|
|
5
7
|
constructor(resource_id, url, loader, size)
|
|
@@ -15,6 +17,8 @@ class BasisLoader extends AbstractLoader
|
|
|
15
17
|
{
|
|
16
18
|
this.loader.load(this.url, (basis) =>
|
|
17
19
|
{
|
|
20
|
+
// basis.encoding = sRGBEncoding;
|
|
21
|
+
|
|
18
22
|
resource_container.set_resource(this.resource_id, this.url, basis);
|
|
19
23
|
|
|
20
24
|
this.__update_downloaded_bytes(1, 1);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Scene } from 'three';
|
|
2
|
+
// import { AvatarSystem } from '../../components/avatar/AvatarSystem';
|
|
3
|
+
|
|
4
|
+
import { HighQualityLoadingState } from './loading_states/HighQualityLoadingState';
|
|
5
|
+
import { LoadingState } from './loading_states/LoadingState';
|
|
6
|
+
import { RegularLoadingState } from './loading_states/RegularLoadingState';
|
|
7
|
+
|
|
8
|
+
class AbstractScene extends Scene
|
|
9
|
+
{
|
|
10
|
+
constructor({ name, compilators })
|
|
11
|
+
{
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
this.name = name;
|
|
15
|
+
|
|
16
|
+
this.is_loaded = false;
|
|
17
|
+
this.is_high_loaded = false;
|
|
18
|
+
|
|
19
|
+
this.loading_states = {
|
|
20
|
+
regular: new RegularLoadingState(this, compilators),
|
|
21
|
+
high: new HighQualityLoadingState(this, compilators)
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.current_loading_state = new LoadingState(this, compilators);
|
|
25
|
+
// this.set_loading_state(this.loading_states.regular);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get loading_progress()
|
|
29
|
+
{
|
|
30
|
+
return this.current_loading_state.loading_progress;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init()
|
|
34
|
+
{
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
load()
|
|
38
|
+
{
|
|
39
|
+
this.init();
|
|
40
|
+
|
|
41
|
+
this.set_loading_state(this.loading_states.regular);
|
|
42
|
+
this.current_loading_state.load();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get_objects()
|
|
46
|
+
{
|
|
47
|
+
const objects = [];
|
|
48
|
+
|
|
49
|
+
this.traverse(child =>
|
|
50
|
+
{
|
|
51
|
+
if (child.geometry)
|
|
52
|
+
{
|
|
53
|
+
objects.push(child);
|
|
54
|
+
|
|
55
|
+
// if (child.name === 'pitch_floor')
|
|
56
|
+
// {
|
|
57
|
+
// objects.push(child);
|
|
58
|
+
// }
|
|
59
|
+
// else
|
|
60
|
+
// {
|
|
61
|
+
// child.visible = false;
|
|
62
|
+
// }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return objects;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
dispose_cpu()
|
|
70
|
+
{
|
|
71
|
+
this.traverse(child =>
|
|
72
|
+
{
|
|
73
|
+
if (child.geometry)
|
|
74
|
+
{
|
|
75
|
+
child.geometry.attributes.position.array = new Float32Array(3);
|
|
76
|
+
if (child.geometry.attributes.normal)
|
|
77
|
+
{
|
|
78
|
+
child.geometry.attributes.normal.array = new Float32Array(3);
|
|
79
|
+
}
|
|
80
|
+
if (child.geometry.attributes.uv)
|
|
81
|
+
{
|
|
82
|
+
child.geometry.attributes.uv.array = new Float32Array(2);
|
|
83
|
+
}
|
|
84
|
+
if (child.material.map)
|
|
85
|
+
{
|
|
86
|
+
for (let i = 0; i < child.material.map.mipmaps.length; i++)
|
|
87
|
+
{
|
|
88
|
+
child.material.map.mipmaps[i] = new Uint8Array(4);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// AvatarSystem.component_container.component_instancer.data_texture.data = new Float32Array(4);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
dispose()
|
|
98
|
+
{
|
|
99
|
+
this.traverse(child =>
|
|
100
|
+
{
|
|
101
|
+
if (child.material)
|
|
102
|
+
{
|
|
103
|
+
if (child.material.map)
|
|
104
|
+
{
|
|
105
|
+
child.material.map.dispose();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
child.material.dispose();
|
|
109
|
+
child.geometry.dispose();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
// AvatarSystem.component_container.component_instancer.data_texture.data = new Float32Array(4);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
set_assets(scene_objects, scene_textures, scene_sounds)
|
|
116
|
+
{
|
|
117
|
+
this.loading_states.regular.set_assets(scene_objects, scene_textures, scene_sounds);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
set_high_assets(scene_objects, scene_textures, scene_sounds)
|
|
121
|
+
{
|
|
122
|
+
this.loading_states.high.set_assets(scene_objects, scene_textures, scene_sounds);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
set_loading_state(state)
|
|
126
|
+
{
|
|
127
|
+
this.current_loading_state.on_exit();
|
|
128
|
+
this.current_loading_state = state;
|
|
129
|
+
this.current_loading_state.on_enter();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Called from transition
|
|
133
|
+
update_loading_state()
|
|
134
|
+
{
|
|
135
|
+
if (!this.is_high_loaded)
|
|
136
|
+
{
|
|
137
|
+
this.current_loading_state.update();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
update()
|
|
142
|
+
{
|
|
143
|
+
this.update_loading_state();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
on_assets_ready()
|
|
147
|
+
{
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
on_assets_compiled()
|
|
152
|
+
{
|
|
153
|
+
this.is_loaded = true;
|
|
154
|
+
|
|
155
|
+
// Load high quality assets
|
|
156
|
+
this.set_loading_state(this.loading_states.high);
|
|
157
|
+
this.current_loading_state.load();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
on_high_quality_assets_ready()
|
|
161
|
+
{
|
|
162
|
+
this.is_high_loaded = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { AbstractScene };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class CompilatorManager
|
|
2
|
+
{
|
|
3
|
+
constructor(compilators)
|
|
4
|
+
{
|
|
5
|
+
this.compilators = compilators;
|
|
6
|
+
this.first_update = true;
|
|
7
|
+
|
|
8
|
+
this.index = 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
update()
|
|
12
|
+
{
|
|
13
|
+
if (!this.is_finished())
|
|
14
|
+
{
|
|
15
|
+
if (this.compilators[this.index].finished)
|
|
16
|
+
{
|
|
17
|
+
this.index++;
|
|
18
|
+
this.first_update = true;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
{
|
|
22
|
+
if (this.first_update)
|
|
23
|
+
{
|
|
24
|
+
this.compilators[this.index].start();
|
|
25
|
+
this.first_update = false;
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
{
|
|
29
|
+
this.compilators[this.index].update();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
is_finished()
|
|
36
|
+
{
|
|
37
|
+
return this.index === this.compilators.length;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { CompilatorManager };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { LoadingState } from './LoadingState';
|
|
2
|
+
|
|
3
|
+
export class HighQualityLoadingState extends LoadingState
|
|
4
|
+
{
|
|
5
|
+
on_enter()
|
|
6
|
+
{
|
|
7
|
+
super.on_enter();
|
|
8
|
+
// this.setup_loader();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
on_exit()
|
|
12
|
+
{
|
|
13
|
+
super.on_exit();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
update()
|
|
17
|
+
{
|
|
18
|
+
super.update();
|
|
19
|
+
|
|
20
|
+
if (this.is_loaded())
|
|
21
|
+
{
|
|
22
|
+
// if (this.is_compiled())
|
|
23
|
+
// {
|
|
24
|
+
this.scene.on_high_quality_assets_ready();
|
|
25
|
+
// }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|