I am in the process of creating a dynamic scene that can be saved and then loaded at a later time.
When saving the scene, I serialize all objects along with their data. The process for meshes is quite straightforward:
var json = {};
json.objectsInScene = [];
for (var i = 0; i < collectionOfObjects.length; i++)
{
json.objectsInScene.push(collectionOfObjects[i].toJSON();
}
Upon loading the scene back in, this is how it is approached:
var jsonObject = JSON.parse(json);
for (var i = 0; i < jsonObject.objectsInScene.length;i++){
var loader = new THREE.JSONLoader();
var geometry = loader.parse(jsonObject.objectsInScene[i]);
var mesh = new THREE.Mesh(geometry.geometry, new THREE.MeshBasicMaterial());
this.scene.add(mesh);
}
An error occurs when executing the code:
Error: Cannot read property 'length' of undefined
Located at Line 14990 of three.js.
The problematic line is identified as follows:
zLength = vertices.length;
Further investigation reveals that vertices.length is indeed undefined
. It appears the assignment takes place a few lines earlier:
var vertices = json.vertices;
However, the json object only consists of the following properties:
geometries: Array[15]
materials: Array[15]
metadata: Object
object: Object
What could be the issue here? Where does the problem arise, and what steps can be taken to resolve it?
R73