三个Js Texture不会出现

ThreeJs Texture wont appear

我想在 ThreeJs 中给一个盒子添加一个纹理。 我看不出我做错了什么,在 chrome 和 internet exp 中它不起作用。

<script src="three.min.js"></script>
    <script src="OrbitControls.js"></script>
    <script>
    //Scene aanmaken
    var scene = new THREE.Scene();
    //Camera 
    var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); 
    //Render instellen
    var renderer = new THREE.WebGLRenderer(); 
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0x000000);
    document.body.appendChild(renderer.domElement)
    //Camera positie
    camera.position.z = 30; 
    camera.position.y = 10;
    //Orbit control aanroepen, voor rond te kijken in de scene
    var controls = new THREE.OrbitControls(camera, renderer.domElement);


    var tafelGeometry = new THREE.BoxGeometry(20,1,40);
    //Texture       
    var tableMaterials = new THREE.MeshBasicMaterial( {map: THREE.ImageUtils.loadTexture( "laken.jpg" ),side: THREE.DoubleSide} );

    var tafel = new THREE.Mesh(tafelGeometry,tableMaterials);
    scene.add(tafel);


    function render()
    {
    requestAnimationFrame(render);
    renderer.render(scene,camera);
    controls.update();
    }
    render();

希望有人能帮助我。 亲切的问候帕特里克

我认为您在加载纹理时遇到了问题。确保纹理加载完美并且没有出现以下错误:

XMLHttpRequest cannot load file:/Desktop/Three.js/abc.jpg. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

如果您遇到上述问题,请使用 web-editor(即 visual studio)创建网站进行检查。

Chrome 出于安全原因阻止加载纹理。 尝试打开 chrome(在 Windows 中):

.\chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

(但不要用它访问其他网站)