xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.15k stars 264 forks source link

When ctx.json.images[textureInfo.source].uri is undefined, glTF model can't load. #269

Closed horsefaced closed 6 years ago

horsefaced commented 6 years ago

When ctx.json.images[textureInfo.source].uri is undefined, glTF model can't load.

The 860 line in loadTexture function in glTFModel.js

        function loadTexture(ctx, textureInfo) {
            var texture = new xeogl.Texture(ctx.scene, {
                src: ctx.basePath + ctx.json.images[textureInfo.source].uri,
                flipY: !!textureInfo.flipY
            });
            ctx.model._addComponent(texture);
            textureInfo._texture = texture;
        }

This function load texture image from image file. But when the gltf model's texture is in buffers block embed in gltf file, the textures block hasn't uri property, so that code will cost 404 not found error.

I modify this code to

        function loadTexture(ctx, textureInfo) {
            var texture = new xeogl.Texture(ctx.scene, {
                src: ctx.json.images[textureInfo.source].uri ? ctx.basePath + ctx.json.images[textureInfo.source].uri : undefined,
                flipY: !!textureInfo.flipY
            });
            ctx.model._addComponent(texture);
            textureInfo._texture = texture;
        }
xeolabs commented 6 years ago

Looks good - would you like to put this fix in a pull request? Then you can get credit for the contribution ;)

horsefaced commented 6 years ago

OK