Using textures in THREE.js

前端 未结 6 1882
遇见更好的自我
遇见更好的自我 2020-11-27 03:16

I am starting with THREE.js, and I am trying to draw a rectangle with a texture on it, lit by a single source of light. I think this is as simple as it gets (HTML omitted fo

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 03:36

    Andrea solution is absolutely right, I will just write another implementation based on the same idea. If you took a look at the THREE.ImageUtils.loadTexture() source you will find it uses the javascript Image object. The $(window).load event is fired after all Images are loaded ! so at that event we can render our scene with the textures already loaded...

    • CoffeeScript

      $(document).ready ->
      
          material = new THREE.MeshLambertMaterial(map: THREE.ImageUtils.loadTexture("crate.gif"))
      
          sphere   = new THREE.Mesh(new THREE.SphereGeometry(radius, segments, rings), material)
      
          $(window).load ->
              renderer.render scene, camera
      
    • JavaScript

      $(document).ready(function() {
      
          material = new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture("crate.gif") });
      
          sphere = new THREE.Mesh(new THREE.SphereGeometry(radius, segments, rings), material);
      
          $(window).load(function() {
              renderer.render(scene, camera);
          });
      });
      

    Thanks...

提交回复
热议问题