Export ThreeJS Geometry to JSON

我怕爱的太早我们不能终老 提交于 2019-12-24 03:07:54

问题


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?


回答1:


You should try the toJSON() method :

var json = geometry.toJSON();

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




回答2:


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




回答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



来源:https://stackoverflow.com/questions/30959385/export-threejs-geometry-to-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!