简体   繁体   中英

ThreeJS DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext'

I recently started working with/learning ThreeJS, and I've been having trouble loading a texture onto a planeMesh. This is what I have right now for the plane:

var characterTexture = new THREE.ImageUtils.loadTexture( 'images/hunter_1.png' );
    var geometry = new THREE.PlaneGeometry( 100, 100, 32);
    var material = new THREE.MeshLambertMaterial( { map: characterTexture, side : THREE.DoubleSide} );
    character = new THREE.Mesh( geometry, material );

Whenever I run this though, I am given this error:

DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at file:///C:/Users/ name /Desktop/images/hunter_1.png may not be loaded.(…)

I have seen quite a few answers to similar questions, but they have all been Uncaught SecurityErrors instead of DOMExceptions and I'm not clear on if the two are similar. If anyone has any ideas of what I've done wrong, please tell! Thanks.

For security reasons it's not possible to run this from your localhost, simply upload it to a web server and your issue should be resolved.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM