Hi, I wondered if it is recommended (or possible at all) to load three.js geometry from a JSON file containing only that. I ask this as there’s a .toJSON
function for both Geometry and BufferGeometry, but no .fromJSON
function. I would like to minimize the size of exchanged JSON data by transferring geometry JSON instead of mesh JSON, as I plan to exchange the matrix separately (and I don’t care for materials, lights, etc.).
I would be happy if I could find something to easily load more generic Geometry JSON and BufferGeometry JSON, but I have not found a way to do this. Some things I’ve tested briefly but without results (dataParsed is the parsed JSON using the FileLoader
containing either Geometry or BufferGeometry):
var geom = dataParsed; //does not work: no center
var geom = new THREE.Geometry(); // or new THREE.BufferGeometry() depending on input
geom.setFromPoints(dataParsed.data.vertices); //does not work: faceless geometry (direct geometry)
I’ve found a way to ‘load’ a BoxGeometry and I might easily expand this for other primitives. I basically load the JSON using the THREE.FileLoader
and parse it. Then I create a new BoxGeometry based on the width/height/depth properties of the loaded JSON file, so this is more like a workaround instead of loading the geometry directly.
I’ve added two files and one snippet (below) containing different types of three.js geometry: Geometry, BufferGeometry, BoxGeometry (all derived from the same simple box).
pureGeometry.json (2.1 KB)
pureGeometryBuf.json (6.5 KB)
BoxGeometry JSON:
{
“metadata”: {
“version”: 4.5,
“type”: “Geometry”,
“generator”: “Geometry.toJSON”
},
“uuid”: “C24662A0-2E9B-4BBE-BD8E-B94C61DB2AD8”,
“type”: “BoxGeometry”,
“width”: 2,
“height”: 1,
“depth”: 1
}