2013-05-02 27 views
0

的基本问题是,我不能让我的例子对象文本工作 - 我没有在控制台中看到任何错误,所以我不reayll知道为什么它不希望跑。WebGL的对象文本不工作

我知道代码工作,如果我只是使用一些正常功能,不,也许我在什么地方搞砸范围或者我应该使用对象构造对象的文字符号?

我有大约一看,看不出任何问题与使用对象文本内的WebGL所以假设我有一些狡猾的编码回事。

我已经提交的jsfiddle为您检查 - 请忽略纹理的跨域问题。

http://jsfiddle.net/j6RMD/

 var MyCube = { 

      container : null, 
      renderer : null, 
      scene  : null, 
      camera : null, 
      cube  : null, 
      animating : null, 
      light  : null, 
      mapUrl : null, 
      map  : null, 
      material : null, 
      geometry : null, 
      animating : false, 

      onLoad : function(){ 
       this.container = $("#container"); 

       this.renderer = new THREE.WebGLRenderer({ antialias: true }); 

       this.renderer.setSize(this.container.offsetWidth, this.container.offsetHeight); 
       $(this.container).append(this.renderer.domElement); 

       this.scene = new THREE.Scene(); 

       this.camera = new THREE.PerspectiveCamera(45, 
       this.container.offsetWidth/this.container.offsetHeight, 1, 4000); 
       this.camera.position.set(0, 0, 3); 

       this.light = new THREE.DirectionalLight(0xffffff, 1.5); 
       this.light.position.set(0, 0, 1); 
       this.scene.add(this.light); 

       this.mapUrl = "molumen_small_funny_angry_monster-999px.png"; 
       this.map = THREE.ImageUtils.loadTexture(this.mapUrl); 

       this.material = new THREE.MeshPhongMaterial({ map: this.map }); 

       this.geometry = new THREE.CubeGeometry(1, 1, 1); 

       this.cube = new THREE.Mesh(this.geometry, this.material); 

       this.cube.rotation.x = Math.PI/5; 
       this.cube.rotation.y = Math.PI/5; 

       this.scene.add(this.cube); 

       this.myrun(); 
      }, 

      myrun : function(){ 
       MyCube.renderer.render(MyCube.scene,MyCube.camera); 

       if(MyCube.animating) 
       { 
        MyCube.cube.rotation.y -= 0.11; 
        MyCube.cube.rotation.x -= 0.10; 
       } 
       requestAnimationFrame(MyCube.myrun); 
      } 

     } 

     MyCube.onLoad(); 

     $('#container').click(function(){ 
      MyCube.animating = !MyCube.animating; 
      return false; 
     }); 
+0

终于解决 - 谢谢你没有Stackoverflow !!!!!!! – user1806692 2013-05-06 23:59:46

回答

0

我所要做的就是添加[0]到jQuery选择的div容器像这样结束......

this.container = $("#container")[0];

,而不是

this.container = $("#container");

我没有意识到(愚蠢)是没有[0]我是返回一个jQuery对象,而不是一个HTML DOM元素。考虑到这里的知识丰富,我很惊讶没有人在我面前发现这一点。

如果你回到我的jsfiddle例子,(从纹理分开)在[0]你会看到一切正常只是增加。

我认为这个帖子是这么简单的东西怎么可以抱你了这么长的时间的最好例子...叹!