Skip to content

Commit

Permalink
Add AsyncTextureLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
fedegratti committed May 7, 2022
1 parent 6bf8a14 commit 6f48087
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.8.0
v6.9.0
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": "6.8.0",
"version": "6.9.0",
"description": "OHZI Core Library",
"source": "src/index.js",
"module": "build/index.module.js",
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import OBJLoader from './resource_loader/OBJLoader';
import PointArrayLoader from './resource_loader/PointArrayLoader';
import RGBETextureLoader from './resource_loader/RGBETextureLoader';
import TextLoader from './resource_loader/TextLoader';
import AsyncTextureLoader from './resource_loader/AsyncTextureLoader';
import TextureLoader from './resource_loader/TextureLoader';
import VideoLoader from './resource_loader/VideoLoader';

Expand Down Expand Up @@ -205,6 +206,7 @@ export {
PointArrayLoader,
RGBETextureLoader,
TextLoader,
AsyncTextureLoader,
TextureLoader,
VideoLoader,

Expand Down
35 changes: 35 additions & 0 deletions src/resource_loader/AsyncTextureLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import AbstractLoader from './AbstractLoader';

import { Texture } from 'three';

export default class AsyncTextureLoader extends AbstractLoader
{
constructor(resource_id, url, size)
{
super(resource_id, url, size);
}

on_preloaded_finished(resource_container)
{
const texture = new Texture();
const image = new Image();

image.src = this.url;

image.onload = () =>
{
texture.image = image;
texture.needsUpdate = true;

resource_container.set_resource(this.resource_id, this.url, texture);

this.__update_downloaded_bytes(1, 1);
this.__loading_ended();
};

image.onerror = () =>
{
console.error('Error loading texture. Maybe the resource is not an image?', this.url);
};
}
}
6 changes: 6 additions & 0 deletions types/resource_loader/AsyncTextureLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AbstractLoader } from "./AbstractLoader";

export class AsyncTextureLoader extends AbstractLoader {
constructor(resource_id: any, url: any, size: any);
loader: any;
}
2 changes: 1 addition & 1 deletion types/resource_loader/BasisLoader.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractLoader } from "./AbstractLoader";

export class BasisLoader extends AbstractLoader {
constructor(resource_id: any, url: any, renderer: any, loader: any, size: any);
constructor(resource_id: any, url: any, loader: any, size: any);
loader: any;
}

0 comments on commit 6f48087

Please sign in to comment.