Skip to content

Commit

Permalink
Added custom loaders to scenes. Fixed JSONLoader. Updated types.
Browse files Browse the repository at this point in the history
  • Loading branch information
fedegratti committed Aug 6, 2024
1 parent a2c5d03 commit 235ba6e
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 169 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ohzi-core",
"version": "12.0.3",
"version": "12.1.0",
"description": "OHZI Interactive Core Library",
"source": "src/index.js",
"module": "build/index.mjs",
Expand Down
13 changes: 8 additions & 5 deletions src/resource_loader/JSONLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ class JSONLoader extends AbstractLoader
super(resource_id, url, size);
}

on_preloaded_finished(resource_container, response)
on_preloaded_finished(resource_container)
{
if (resource_container.resources_by_url[this.url] === undefined)
{
response.json().then((json) =>
fetch(this.url).then((response) =>
{
resource_container.set_resource(this.resource_id, this.url, json);
response.json().then((json) =>
{
resource_container.set_resource(this.resource_id, this.url, json);

this.__update_downloaded_bytes(1, 1);
this.__loading_ended();
this.__update_downloaded_bytes(1, 1);
this.__loading_ended();
});
});
}
else
Expand Down
8 changes: 4 additions & 4 deletions src/scenes/AbstractScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ class AbstractScene extends Scene
// AvatarSystem.component_container.component_instancer.data_texture.data = new Float32Array(4);
}

set_assets(scene_objects, scene_textures, scene_sounds)
set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data)
{
this.loading_states.regular.set_assets(scene_objects, scene_textures, scene_sounds);
this.loading_states.regular.set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data);
}

set_high_assets(scene_objects, scene_textures, scene_sounds)
set_high_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data)
{
this.loading_states.high.set_assets(scene_objects, scene_textures, scene_sounds);
this.loading_states.high.set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data);
}

set_loading_state(state)
Expand Down
13 changes: 12 additions & 1 deletion src/scenes/loading_states/LoadingState.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ export class LoadingState
this.callback_called = false;
}

set_assets(scene_objects, scene_textures, scene_sounds)
set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders = [], custom_compilators = [], custom_data = [])
{
this.scene_objects = scene_objects;
this.scene_textures = scene_textures;
this.scene_sounds = scene_sounds;

this.custom_loaders = custom_loaders;
this.custom_compilators = custom_compilators;
this.custom_data = custom_data;
}

get loading_progress()
Expand Down Expand Up @@ -81,6 +85,13 @@ export class LoadingState
this.loaders.push(audios_loader);
compilators.push(new this.AudiosCompilator(audios_loader.get_assets_names()));

for (let i = 0; i < this.custom_loaders.length; i++)
{
const loader = new this.custom_loaders[i](this.scene.name, this.custom_data[i], assets_worker);
this.loaders.push(loader);
compilators.push(new this.custom_compilators[i](loader.get_assets_names()));
}

this.compilator_manager = new CompilatorManager(compilators);
}

Expand Down
6 changes: 2 additions & 4 deletions types/Browser.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
export { browser as Browser };
declare const browser: Browser;
declare class Browser {
init(): void;
init(): Promise<void>;
browser_name: string;
agent: string;
vr_browser_keywords: string[];
vr_browser_name: string;
has_web_xr_support: boolean;
is_vr: any;
version: number;
get name(): string;
get is_safari(): boolean;
get is_chrome(): boolean;
get is_edge(): boolean;
get is_edge_chromium(): boolean;
get is_vr(): boolean;
get has_webm(): boolean;
get has_hvec(): boolean;
get preferred_video_extension(): "webm" | "hvec.mp4" | "mp4";
Expand Down
13 changes: 10 additions & 3 deletions types/Graphics.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export { graphics as Graphics };
declare const graphics: Graphics;
declare class Graphics {
init(canvas: any, core_attributes: any, context_attributes: any, threejs_attributes: any): void;
init({ canvas, core_attributes, context_attributes, threejs_attributes, dpr }: {
canvas: any;
core_attributes: any;
context_attributes: any;
threejs_attributes: any;
dpr: any;
}): void;
_renderer: any;
blitter: Blitter;
canvas: any;
Expand Down Expand Up @@ -29,18 +35,19 @@ declare class Graphics {
threejs_attributes: {
logarithmicDepthBuffer: boolean;
};
resize_observer: ResizeObserver;
get dom_element(): any;
get depth_normals_RT(): any;
set_state(new_state: any): void;
update(): void;
__update_current_camera(): void;
render(scene: any, camera: any, RT: any, override_mat: any): void;
compile(scene: any, camera: any, RT: any, override_mat: any): void;
compile_async(scene: any, camera: any, RT: any, override_mat: any, target_scene: any): Promise<any>;
render_scene(scene: any): void;
__apply_override_material(scene: any, mat: any): void;
readback_RT(RT: any, buffer: any): void;
clear(RT: any, camera: any, clear_depth: any, clear_stencil: any): void;
on_resize(entries: any): void;
on_resize(entries: any, dpr: any): void;
material_pass(mat: any, dst: any): void;
blit(src_RT: any, dst_RT: any, mat: any): void;
blit_clear_with_material(dst_RT: any, mat: any): void;
Expand Down
6 changes: 6 additions & 0 deletions types/blitter_index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { MedianFilter } from "./render_utilities/MedianFilter";
import { GaussianBlurrer } from "./render_utilities/GaussianBlurrer";
import { Blurrer } from "./render_utilities/Blurrer";
import { Blitter } from "./render_utilities/Blitter";
import { DualFilteringBlurMaterial } from "./materials/DualFilteringBlurMaterial";
export { MedianFilter, GaussianBlurrer, Blurrer, Blitter, DualFilteringBlurMaterial };
Loading

0 comments on commit 235ba6e

Please sign in to comment.