2013-04-16 86 views
0
<html> 
    <head> 
     <title>My first Three.js app</title> 
     <style>canvas { width: 100%; height: 100% }</style> 
    </head> 
    <body> 
     <script src="https://raw.github.com/mrdoob/three.js/master/build/three.js"></script> 
     <!--<script src="C:/Users/danr/Desktop/ThreeJS/three.js-master/build/three.js"></script>--> 
     <script> 
      var scene = new THREE.Scene(); 
      var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000); 

      var renderer = new THREE.WebGLRenderer(); 
      renderer.setSize(window.innerWidth, window.innerHeight); 
      document.body.appendChild(renderer.domElement); 

      camera.position.z = 5; 

      var pointLight = new THREE.PointLight(0xFFFFFF); 
      pointLight.position.x = 2; 
      pointLight.position.y = 5; 
      pointLight.position.z = 10; 
      scene.add(pointLight); 

      loader = new THREE.JSONLoader(); 
      loader.load("./X738.js", function(geometry) 
      { 
       mesh = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial()); 
       mesh.scale.set(1, 1, 1); 
       mesh.position.y = 0; 
       mesh.position.x = 0; 
       scene.add(mesh); 
      }); 

      function render() { 
       requestAnimationFrame(render); 


       renderer.render(scene, camera); 
      } 
      render(); 
     </script> 
    </body> 
</html> 

這是我所有的代碼。我正在使用Apache2.2服務器,並使用python將我的模型從FBX轉換爲Json。這裏是我得到的錯誤消息:嘗試使用JSONLoader加載幾何體時發生奇怪的錯誤()

THREE.WebGLRenderer 57 three.js:18058 
Uncaught SyntaxError: Unexpected token , three.js:9764 
xhr.onreadystatechange three.js:9764 

    xhr.onreadystatechange = function() { 

       if (xhr.readyState === xhr.DONE) { 

        if (xhr.status === 200 || xhr.status === 0) { 

         if (xhr.responseText) { 

          var json = JSON.parse(xhr.responseText);//*Uncaught SyntaxError: Unexpected token* 
          var result = context.parse(json, texturePath); 
          callback(result.geometry, result.materials); 

任何建議與什麼可能是錯誤的?我嘗試了許多不同的解決方案,但似乎沒有任何工作,我感到非常失落。

謝謝!

編輯:這是一個什麼樣的pyhton FBX至JSON轉換器給我回一個樣本:

{ 
    "metadata": { 
     "formatVersion" : 3.2, 
     "type"  : "scene", 
     "generatedBy" : "convert-to-threejs.py", 
     "objects"  : 1, 
     "geometries" : 1, 
     "materials"  : 1, 
     "textures"  : 1 
    }, 


    "urlBaseType": "relativeToScene", 

    "objects" : 
    { 
     "Tire_Front" : { 
      "geometry" : "Geometry_40_Tire_Front", 
      "material" : "Material #3319", 
      "position" : [ 0, -423.113, 451.225 ], 
      "rotation" : [ -1.5708, 0.000987928, 6.04932e-20 ], 
      "scale" : [ 1, 1, 1 ], 
      "visible" : true 
     } 
    }, 

    "geometries" : 
    { 
     "Geometry_40_Tire_Front" : { 
      "type" : "embedded", 
      "id" : "Embed_40_Tire_Front" 
     } 
    }, 
+0

你看過回來的回覆嗎?它有效的JSON? – epascarello

+0

如何檢查JSON是否有效? – user2287949

+0

將它與其他JSON示例進行比較時,它看起來像是有效的JSON。我將發佈我在主帖的編輯中回覆的內容。 – user2287949

回答

0

我認定「未捕獲的SyntaxError:意外的標記」的一些消息來源在以.json文件。注意語法,包括括號「{」或「[」。

{ 
    "metadata": { 
     "formatVersion" : 3.2, 
     "type"  : "scene", 
     "generatedBy" : "convert-to-threejs.py", 
     "objects"  : 1, 
     "geometries" : 1, 
     "materials"  : 1, 
     "textures"  : 1 
    }, 


    "urlBaseType": "relativeToScene", 

    "objects" : 
    { 
     "Tire_Front" : { 
      "geometry" : "Geometry_40_Tire_Front", 
      "material" : "Material #3319", 
      "position" : [ 0, -423.113, 451.225 ], 
      "rotation" : [ -1.5708, 0.000987928, 6.04932e-20 ], 
      "scale" : [ 1, 1, 1 ], 
      "visible" : true 
     } 
    }, 

    "geometries" : 
    { 
     "Geometry_40_Tire_Front" : { 
      "type" : "embedded", 
      "id" : "Embed_40_Tire_Front" 
     } 
    } 

}

使用 「OBJLoader」 而不是 「JSONLoader」 加載的對象也有幫助。

相關問題