Skip to content

Commit 11f3555

Browse files
committed
Fix a small bug with texture loading
1 parent 727ca18 commit 11f3555

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webgl-engine",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "",
55
"main": "src/index.ts",
66
"scripts": {

src/engine.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -561,38 +561,43 @@ export class Engine<T> {
561561
/// Apply the current texture if relevant
562562
// Check if the current texture is loaded
563563
if (obj.texture && obj.texture.enabled !== false) {
564-
if (!this.loader.isLoaded(obj.texture.uri)) {
564+
if (
565+
!this.loader.isLoaded(obj.texture.uri) ||
566+
obj.texture._computed === undefined
567+
) {
565568
await this._loadTextures();
566569
}
567570

568-
const { webglTexture, square } = obj.texture._computed;
569-
gl.bindTexture(gl.TEXTURE_2D, webglTexture);
570-
571-
if (obj.texture._computed) {
572-
if (square) {
573-
gl.texParameteri(
574-
gl.TEXTURE_2D,
575-
gl.TEXTURE_WRAP_S,
576-
REPEAT_MAP[obj.texture.repeat_horizontal]
577-
);
578-
579-
gl.texParameteri(
580-
gl.TEXTURE_2D,
581-
gl.TEXTURE_WRAP_T,
582-
REPEAT_MAP[obj.texture.repeat_vertical]
583-
);
584-
} else {
585-
gl.texParameteri(
586-
gl.TEXTURE_2D,
587-
gl.TEXTURE_WRAP_S,
588-
gl.CLAMP_TO_EDGE
589-
);
590-
591-
gl.texParameteri(
592-
gl.TEXTURE_2D,
593-
gl.TEXTURE_WRAP_T,
594-
gl.CLAMP_TO_EDGE
595-
);
571+
if (obj && obj.texture) {
572+
const { webglTexture, square } = obj.texture._computed;
573+
gl.bindTexture(gl.TEXTURE_2D, webglTexture);
574+
575+
if (obj.texture._computed) {
576+
if (square) {
577+
gl.texParameteri(
578+
gl.TEXTURE_2D,
579+
gl.TEXTURE_WRAP_S,
580+
REPEAT_MAP[obj.texture.repeat_horizontal]
581+
);
582+
583+
gl.texParameteri(
584+
gl.TEXTURE_2D,
585+
gl.TEXTURE_WRAP_T,
586+
REPEAT_MAP[obj.texture.repeat_vertical]
587+
);
588+
} else {
589+
gl.texParameteri(
590+
gl.TEXTURE_2D,
591+
gl.TEXTURE_WRAP_S,
592+
gl.CLAMP_TO_EDGE
593+
);
594+
595+
gl.texParameteri(
596+
gl.TEXTURE_2D,
597+
gl.TEXTURE_WRAP_T,
598+
gl.CLAMP_TO_EDGE
599+
);
600+
}
596601
}
597602
}
598603
}

src/scene.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ export class Scene<T> {
131131
this.objects.splice(0, this.objects.length);
132132
this.vertexes = [];
133133
this.texcoords = [];
134+
this.colors = [];
134135
this.vertexMetadata = {};
135136
this.texcoordMetadata = {};
137+
this.colorMetadata = {};
136138
}
137139

138140
addObject(obj: Obj3d) {
@@ -142,8 +144,6 @@ export class Scene<T> {
142144
const obj = queue.pop();
143145
if (obj) {
144146
this.registerObject(obj);
145-
delete obj.vertexes;
146-
delete obj.texcoords;
147147
this.objects.push(obj);
148148

149149
if (obj.children) {

0 commit comments

Comments
 (0)