Reputation: 16269
Having a problem loading the JSON file produced by the three.js exporter for Blender, that comes with three.js r.86.
Setup done without issues. To test this exporter, I open Blender, and I use the untitled Blender file that contains a cube:
Exporting it without any adjustments, it produces the following JSON file:
{
"metadata":{
"generator":"io_three",
"normal":36,
"position":36,
"version":3,
"type":"BufferGeometry"
},
"data":{
"index":{
"array":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],
"itemSize":1,
"type":"Uint16Array"
},
"attributes":{
"normal":{
"array":[-7.10543e-15,-1,2.98023e-08,-7.10543e-15,-1,2.98023e-08,-7.10543e-15,-1,2.98023e-08,7.10543e-15,1,-2.98023e-08,7.10543e-15,1,-2.98023e-08,7.10543e-15,1,-2.98023e-08,1,-2.38419e-07,7.10543e-15,1,-2.38419e-07,7.10543e-15,1,-2.38419e-07,7.10543e-15,-5.96046e-08,-2.98023e-07,1,-5.96046e-08,-2.98023e-07,1,-5.96046e-08,-2.98023e-07,1,-1,-1.49012e-07,-2.38419e-07,-1,-1.49012e-07,-2.38419e-07,-1,-1.49012e-07,-2.38419e-07,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,-1.77636e-15,-1,2.98023e-08,-1.77636e-15,-1,2.98023e-08,-1.77636e-15,-1,2.98023e-08,1.5099e-14,1,-2.98023e-08,1.5099e-14,1,-2.98023e-08,1.5099e-14,1,-2.98023e-08,1,3.27825e-07,5.66244e-07,1,3.27825e-07,5.66244e-07,1,3.27825e-07,5.66244e-07,-5.0664e-07,1.49012e-07,1,-5.0664e-07,1.49012e-07,1,-5.0664e-07,1.49012e-07,1,-1,-1.19209e-07,-2.08616e-07,-1,-1.19209e-07,-2.08616e-07,-1,-1.19209e-07,-2.08616e-07,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1,2.38419e-07,1.78814e-07,-1],
"itemSize":3,
"type":"Float32Array"
},
"position":{
"array":[1,-1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,0.999999,1,1,1,1,-1,1,1,-1,1,-1,1,1,-1,-1,0.999999,1,1,-1,-1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,0.999999,1,1,1,1,-1,0.999999,1,1,1,-1,1,0.999999,1,1,-1,1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1],
"itemSize":3,
"type":"Float32Array"
}
}
}
}
I have uploaded the JSON file to a server, and with a basic setup tried to load it into a scene:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My first three.js app</title>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="assets/js/three.js"></script>
<script>
/* Scene
*/
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 geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
cube.rotation.x = 2;
cube.rotation.y = 2;
renderer.render(scene, camera);
/* Load the JSON
*/
var loader = new THREE.JSONLoader();
loader.load(
'https://www.example.com/blender-cube.json',
function ( geometry, materials ) {
var material = materials[ 0 ];
var object = new THREE.Mesh( geometry, material );
scene.add( object );
}
);
</script>
</body>
</html>
With above code, I get the green cube extracted from an example page ⇗, but when reaching to the Load the JSON
portion ⇗, the following error is displayed on the browser console:
TypeError: vertices is undefined
three.js:33296.5
The mentioned error line is inside the parseModel( json, geometry )
function.
Seems to me that the three.js exporter for Blender is missing something when generating the JSON file. The function parseModel()
is expecting a vertices
property not present on the generated JSON file.
A working snippet, with a little tweak to the Load the JSON
portion, to have the JSON file in a JavaScript variable:
/* Scene
*/
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 geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
cube.rotation.x = 2;
cube.rotation.y = 2;
renderer.render(scene, camera);
/* Load the JSON
*/
var loader = new THREE.JSONLoader();
var blenderCubeObject = {
"metadata": {
"generator": "io_three",
"normal": 36,
"position": 36,
"version": 3,
"type": "BufferGeometry"
},
"data": {
"index": {
"array": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],
"itemSize": 1,
"type": "Uint16Array"
},
"attributes": {
"normal": {
"array": [-7.10543e-15, -1, 2.98023e-08, -7.10543e-15, -1, 2.98023e-08, -7.10543e-15, -1, 2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 7.10543e-15, 1, -2.98023e-08, 1, -2.38419e-07, 7.10543e-15, 1, -2.38419e-07, 7.10543e-15, 1, -2.38419e-07, 7.10543e-15, -5.96046e-08, -2.98023e-07, 1, -5.96046e-08, -2.98023e-07, 1, -5.96046e-08, -2.98023e-07, 1, -1, -1.49012e-07, -2.38419e-07, -1, -1.49012e-07, -2.38419e-07, -1, -1.49012e-07, -2.38419e-07, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, -1.77636e-15, -1, 2.98023e-08, -1.77636e-15, -1, 2.98023e-08, -1.77636e-15, -1, 2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1.5099e-14, 1, -2.98023e-08, 1, 3.27825e-07, 5.66244e-07, 1, 3.27825e-07, 5.66244e-07, 1, 3.27825e-07, 5.66244e-07, -5.0664e-07, 1.49012e-07, 1, -5.0664e-07, 1.49012e-07, 1, -5.0664e-07, 1.49012e-07, 1, -1, -1.19209e-07, -2.08616e-07, -1, -1.19209e-07, -2.08616e-07, -1, -1.19209e-07, -2.08616e-07, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1, 2.38419e-07, 1.78814e-07, -1],
"itemSize": 3,
"type": "Float32Array"
},
"position": {
"array": [1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, 0.999999, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 0.999999, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 0.999999, 1, 1, 1, 1, -1, 0.999999, 1, 1, 1, -1, 1, 0.999999, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1],
"itemSize": 3,
"type": "Float32Array"
}
}
}
};
var model = loader.parse(blenderCubeObject);
mesh = new THREE.Mesh(model.geometry, model.materials[0]);
scene.add(mesh);
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/86/three.js"></script>
Any clue to what is happening or what I'm doing wrong ?
Upvotes: 0
Views: 1086
Reputation: 28
try changing the type in apply modifier to geometry as opposed to buffergeometry and see if that helps.
Upvotes: 1