2013-05-02 53 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]你會看到一切正常只是增加。

我認爲這個帖子是這麼簡單的東西怎麼可以抱你了這麼長的時間的最好例子...嘆!