第一,我已經讀過this question沒有幫助ThreeJS無法加載JSON檔案
如何我做的:首先,我從C4D導出模型.ojb。然後我導入OBJ到www.trheejs /編輯
我填補所有空白
然後從樹我選擇我的對象,並將其導出到Threejs對象,它保存一個以.json文件
我的代碼
<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);
var kiss = new THREE.Object3D(), loader = new THREE.JSONLoader(true);
loader.load("brikk2.json", function (geometry, materials) {
var mesh = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({ color: 0xff0000, ambient: 0xff0000 }));
scene.add(mesh);
});
var render = function() {
requestAnimationFrame(render);
renderer.render(scene, camera);
};
render();
</script>
當我運行有論文的錯誤消息
THREE.WebGLRenderer 67 three.js:20806
THREE.WebGLRenderer: elementindex as unsigned integer not supported. three.js:26942
XHR finished loading: "http://xxxxxx.xx/tst/mrdoob-three2/brikk2.json". three.js:12018
THREE.JSONLoader.loadAjaxJSON three.js:12018
THREE.JSONLoader.load three.js:11942
load test.html:23
(anonymous function) test.html:28
Uncaught TypeError: Cannot read property 'length' of undefined three.js:12087
parseModel three.js:12087
THREE.JSONLoader.parse three.js:12028
xhr.onreadystatechange three.js:11969
JSON的我加載JSON文件的
{
"metadata": {
"version": 4.3,
"type": "Object",
"generator": "ObjectExporter"
},
"geometries": [
{
"uuid": "213E28EF-E388-46FE-AED3-54695667E086",
"name": "brikkG",
"type": "Geometry",
"data": {
"vertices": [0.036304,-0.016031,-0.027174,0.036304,0.......
........ 232,1228,1139,1141,1140,1]
}
}],
"materials": [
{
"uuid": "F74C77E4-8371-41BC-85CA-31FC96916CC6",
"name": "lego",
"type": "MeshPhongMaterial",
"color": 16721408,
"ambient": 16777215,
"emissive": 0,
"specular": 16777215,
"shininess": 30,
"opacity": 1,
"transparent": false,
"wireframe": false
}],
"object": {
"uuid": "3BAAB8CA-1EB7-464A-8C6D-FC4BBB3C63C6",
"name": "BrikkM",
"type": "Mesh",
"geometry": "213E28EF-E388-46FE-AED3-54695667E086",
"material": "F74C77E4-8371-41BC-85CA-31FC96916CC6",
"matrix": [1000,0,0,0,0,1000,0,0,0,0,1000,0,0,0,0,1]
}
}
結構
基本上我已經嘗試了所有我已閱讀有關導入原生JSON到ThreeJS,我試圖文件從treejs/editor或clara.io仍然有相同的錯誤信息,我不知道了,我花了3天試圖解決這個問題。
如果我嘗試創建幾何形狀像CubeGeometry它使沒有問題,但一旦我嘗試用本地JSON,沒有什麼工作了
有人能幫忙嗎?
這是有幫助的。你能發佈你的html嗎? –