THREE.js - Can't load texture locally

后端 未结 4 1852
一向
一向 2020-12-04 00:06

I have a local file in which I try to load texture like this:

var texture = THREE.ImageUtils.loadTexture( \'image.jpg\' );
var cubeGeo = new THREE.CubeGeomet         


        
4条回答
  •  心在旅途
    2020-12-04 00:25

    If you need to use textures in your project, you can convert images to base64 strings and then just assign them to your variables

    Here is the sample: https://codepen.io/tamlyn/pen/RNrQVq

    var texture = new THREE.Texture();
    texture.image = image;
    image.onload = function() {
    texture.needsUpdate = true;
    };
    

    Where image was read from the base64 string

    So you can create res.js and just write there all the textures :) it's not very good, because if you change some images, you have to reconvert them to base64, but it works in any browser (even Ms edge)

提交回复
热议问题