PolGuixe
PolGuixe

Reputation: 63

Export ThreeJS Geometry to JSON

I need to export Three Geometry to JSON so I can used with xml3D.

I am trying to find the THREE.GeometryExporter() but I can't. Has it been completely deprecated? It is mentioned here

Once I have the Three JSON I should be able to use this converter to obtain the xml3D JSON.

Has anyone tried this before?

Upvotes: 3

Views: 8187

Answers (3)

Tyler Wolf
Tyler Wolf

Reputation: 106

geometry.toJSON() wasn't outputting the information in the format I needed to do something similar. My solution was the following:

cannonPoints = geometry.vertices.map(function(v) {
    return new CANNON.Vec3( v.x, v.y, v.z )
})

cannonFaces = geometry.faces.map(function(f) {
    return [f.a, f.b, f.c]
})

I shared this solution on a similar problem here: Create CANNON.RigidBody from THREE.Mesh or THREE.Geometry

Upvotes: 3

jeum
jeum

Reputation: 1094

You should try the toJSON() method :

var json = geometry.toJSON();

This method is available for geometries, materials, lights, mesh ...

Upvotes: 4

2pha
2pha

Reputation: 10165

Realease 68 seems to be the last one with GeometyExporter in the examples folder. https://github.com/mrdoob/three.js/tree/r68/examples/js/exporters

Not sure how you expect it to output to xml3D format (I've never tried it), though it should not be too hard to alter if need be.

This three.js json to xml3d converter may come in handy. https://github.com/xml3d/threejs-to-xml3d

Upvotes: 3

Related Questions