javascript - ThreeJS DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext' - S

I recently started working withlearning ThreeJS, and I've been having trouble loading a texture o

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.

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.

Share Improve this question asked Feb 6, 2016 at 7:08 Alex HickelAlex Hickel 211 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745151721a4613899.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信