Three.js and loading a cross-domain image

后端 未结 4 1572
梦谈多话
梦谈多话 2020-11-30 02:16

I know this has been asked before, and I\'ve read ever question and answer I\'ve been able to find, but nothing works.

I\'m running this on a local server (IIS). I\'

4条回答
  •  独厮守ぢ
    2020-11-30 02:59

    UPDATE: Deprecated method

    I came across this problem and applied solution from the answer to find it not working due to the deprecated method in newer releases of the THREE.js. I'm posting this answer in case anyone get the same issue. Despite deprecation, information provided by gman in original answer are most helpful and I recommend reading it.

    THREE.ImageUtils.loadTexture()
    

    method became deprecated since the original question and answer.

    Current way to load the texture:

    // instantiate a loader
    var loader = new THREE.TextureLoader();
    
    //allow cross origin loading
    loader.crossOrigin = '';
    
    // load a resource
    loader.load('textures/land_ocean_ice_cloud_2048.jpg',
        // Function when resource is loaded
        function ( texture ) {},
        // Function called when download progresses
        function ( xhr ) {},
        // Function called when download errors
        function ( xhr ) {}
    );
    

提交回复
热议问题