3

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?

PolGuixe
  • 63
  • 1
  • 7

3 Answers3

4

You should try the toJSON() method :

var json = geometry.toJSON();

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

jeum
  • 1,048
  • 3
  • 13
  • 29
  • 1
    Explains why it was removed :) – 2pha Jun 21 '15 at 08:52
  • I think (not sure) that THREE.GeometryExporter() has been replaced by toJSON() – jeum Jun 21 '15 at 09:00
  • I'n not sure too, never used it. Worth a go though. – 2pha Jun 21 '15 at 09:01
  • For geometries it works and exports vertices, faces, normals,etc. But if it is a BoxGeometry type it doesn't export vertices, faces, normals, etc. I need to find a way to work around. – PolGuixe Jun 23 '15 at 21:22
  • 1
    It seems that you need to convert BoxGeometries : have a look at [this thread](http://stackoverflow.com/questions/26438566/what-is-the-correct-way-to-edit-the-vertices-of-a-box-geometry?answertab=active#tab-top) and [this one](https://github.com/mrdoob/three.js/issues/5483) – jeum Jun 24 '15 at 09:46
3

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

2pha
  • 9,798
  • 2
  • 29
  • 43
  • That converter will definitely help, but needs to be modified. And for xml3d v5 the JSON format will be changed as far as I know. – PolGuixe Jun 23 '15 at 21:20
3

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

Community
  • 1
  • 1
Tyler Wolf
  • 106
  • 4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/13987655) – Mark Rotteveel Oct 17 '16 at 08:49
  • Updated per your suggestion – Tyler Wolf Oct 17 '16 at 13:29