2012-11-14 159 views
0

我的HTML代碼:我的SceneJS代碼有什麼問題?

<body onload= "main()" bgcolor="white"> 
     <div> 
     <label id="3dobjects">test</label> 
     </br> 
     <canvas id="theCanvas" width="720" height="405"> 
     </canvas> 
     </br> 
     <label id="fpsout"></label> 
     </div> 
</body> 

我SceneJS腳本:

所有遺憾的
<script type="text/javascript"> 
     var N=10; 
     function average(v){ 
      var items = v.length; 
      var sum = 0.0; 
      for (i = 0; i<items; i++) 
      sum += v[i]; 
      return (sum/items); 
      } 

     function main() 
     { 


      SceneJS.createScene({ 
      type: "scene", 
      id: "theScene", 
      canvasId: "theCanvas", 
      nodes: [{ 
      type:"library", 
       id:"mylib", 
       nodes:[] 
      }, 
      // Viewing transform specifies eye position, looking at the origin by default 
      { 
       id:"lookat", 
       type: "lookAt", 
       eye : { x: 0.0, y: 1.0, z: 80.0 }, 
       up : { z: 1.0 }, 
       look:{x:0,y:0,z:0}, 
       nodes: [ 
        /* Camera describes the projection*/ 
        { 
       type: "camera", 
       optics: { 
       type: "perspective", 
       fovy : 45.0, 
       aspect : 1.78, 
       near : 0.10, 
       far : 300.0 
        }, 
       nodes: [ 
         { 
          type: "renderer", 
          clearColor: { r: 0.0, g: 0.0, b: 0.0 }, 
          clear: { 
           depth : true, 
           color : true 
         }, 

        nodes: [ 
         // Light Source 
         { 
        type: "light", 
        mode:     "point", 
        color:     { r: 1.0, g: 1.0, b: 1.0 }, 
        diffuse:    true, 
        specular:    true, 
        pos:{ x: 10.0, y: 10.0, z: 10.0 } 
        }, 

        // Tranform 
         { 
        type: "rotate", 
        id: "pitch", 
        angle: 0.0, 
        x : 1.0,  
        nodes: [ 
         { 
          type: "rotate", 
          id: "yaw", 
          angle: 0.0, 
          y : 1.0, 
          nodes: [  
           // Lights Properties 
           { 
           type: "material", 
           id:"cubeviewspace", 
           emit: 0.1, 
            baseColor:  { r: 0.8, g: 0.8, b: 0.8 }, 
            specularColor: { r: 0.8, g: 0.8, b: 0.8 }, 
            specular:  0.7, 
            shine:   10.0 
           } 
           ] 
          } 
         ] 
         } 
         ] 
         } 
         ] 
        } 
        ] 
      } 
      ] 
     }); 
     var scene = SceneJS.scene(theScene); 
     for(var i=0; i<N; i++){ 
      scene.findNode("cubeviewspace").add("node",{ 
      type:"translate", 
      id:"balltrans"+i, 
      x:(Math.random()-0.5) * scale, 
      y:(Math.random()-0.5) * scale, 
      z:(Math.random()-0.5) * scale, 
      nodes:[{ 
       type: "cube", 
      id: "ball"+i 
      }] 
      }); 
     } 
     // Printing Number Of Cubes 
     document.getElementById('3dobjects').innerHTML = "The number of Cube Objects: " +N; 
     var t0 = (new Date()).getTime(); 
     var t = 0; 

     var fpss = []; 
     scene.start({ 
     idleFunc:function(){ 
      var t1 = (new Date()).getTime(); 
      fpss.push(1000/(t1 - t0)); 
      if(fpss.length>200) 
      fpss.shift(); 
      // Printing fps 
      document.getElementById('fpsout').innerHTML = "The number of Cube Objects: " +average(fpss); 
      t0 = t1; 
      t++; 
     } 
      }); 
    } 

</script> 

首先,如果我避免了發佈這一問題的任何規則。我的意圖是得到解決問題的辦法,但沒有別的。 SceneJS API對於我的編程來說是非常新穎的,但我試圖編寫最好的代碼。我試圖在整個空間上打印立方體,並計算相應的FPS。我甚至無法在屏幕上看到畫布,但只能看到空的瀏覽器。我一直在嘗試不同的方式(幾乎完全編輯以前的版本)來解決它,但我的努力是徒勞的。我要求有人在這個問題上幫助我。我非常感謝這個人。

回答

0

你有下面的代碼

var scene = SceneJS.scene(theScene); 

改變

var scene = SceneJS.scene("theScene"); 

添加場景ID的兩側。

並添加

var scale = any_value_you_want; 

您省略了「縮放」變量。