Export three.js tag as OBJ or STL

I would like to create an export as an OBJ or STL link for a tr.js mesh parametric object. Also as an export option at http://www.3dtin.com

Any advice would be appreciated.

+8
canvas webgl
source share
4 answers

To get the grid in .obj format, I use this simple function:

THREE.saveGeometryToObj = function (geometry) { var s = ''; for (i = 0; i < geometry.vertices.length; i++) { s+= 'v '+(geometry.vertices[i].x) + ' ' + geometry.vertices[i].y + ' '+ geometry.vertices[i].z + '\n'; } for (i = 0; i < geometry.faces.length; i++) { s+= 'f '+ (geometry.faces[i].a+1) + ' ' + (geometry.faces[i].b+1) + ' '+ (geometry.faces[i].c+1); if (geometry.faces[i].d !== undefined) { s+= ' '+ (geometry.faces[i].d+1); } s+= '\n'; } return s; } 
+7
source share

Writing the text of OBJExporter should be fairly simple. Just use OBJLoader as a reference. In a few weeks, I will probably write it myself if no one has done this by then.

+3
source share

I would first consider python OBJ -> tr.js converter.

If you do not agree with this, I do not think that you will find any libraries previously created for this. I would ask 3DTin if they used the library, or if they developed it on their own.

+1
source share

I slightly modified the above code to allow arrays of objects that were duplicated and translated into the scene. I am currently using document.writeln and then manually copy and paste into the document.

 var l = parent.length; var j = 0; while (l--) { var numVerts = parent[l].children[0].geometry.vertices.length; document.writeln(THREE.saveGeometryToObj(parent[l].children[0],j*(numVerts))); j++; } THREE.saveGeometryToObj = function (geo,nums) { geo.updateMatrixWorld(); var num = parseInt(nums); var s = ''; for (i = 0; i < geo.geometry.vertices.length; i++) { var vector = new THREE.Vector3( geo.geometry.vertices[i].x, geo.geometry.vertices[i].y, geo.geometry.vertices[i].z ); geo.matrixWorld.multiplyVector3( vector ); s+= 'v '+(vector.x) + ' ' + vector.y + ' '+ vector.z + '</br>'; } for (i = 0; i < geo.geometry.faces.length; i++) { s+= 'f '+ (geo.geometry.faces[i].a+1+num) + ' ' + (geo.geometry.faces[i].b+1+num) + ' '+ (geo.geometry.faces[i].c+1+num); if (geo.geometry.faces[i].d!==undefined) { s+= ' '+ (geo.geometry.faces[i].d+1+num); } s+= '</br>'; } return s; 

}

0
source share

All Articles