0

I have seen plenty of examples on how to export a mesh or a whole scene from ThreeJS to an OBJ file. Starting from MrDoob example here:https://threejs.org/examples/#misc_exporter_obj

But since a marching cube like this : https://threejs.org/examples/webgl_marchingcubes.html is not an instance of THREE.Mesh, what would be the workaround to export its current geometry into an Obj file? And by extension its material into an mtl file as explained in this question : Export a three js textured model to a .OBJ with .MTL file

EDIT

As far as I understand, it is possible to export a copy of the current state of the metaballs by using the generateGeometry() function provided by marching cubes. Below is an example using filesaver.js and JSZip.js to export the geometry and material as two files in a zip. THREE.OBJExporter comes from the modified version of the original obj exporter of threeJS done as mentionned above (Export a three js textured model to a .OBJ with .MTL file):

function exportToObj(the_object){
                var zip = new JSZip();
                var the_exporter = new THREE.OBJExporter();
                var result = the_exporter.parse(the_object);
                zip.file("Blob.obj", result.obj);
                zip.file("Blob.mtl", result.mtl);
                zip.generateAsync({type:"blob"}).then(function (blob) {
                    saveAs(blob, "Blob.zip");
                });
}
$(document).on('keyup',function(e) {
    if (e.which == 13){ // enter key to export to OBJ
            var TempMesh = new THREE.Mesh(effect.generateGeometry(),effect.material);
            //effect is of the type: new THREE.MarchingCubes()
            exportToObj(TempMesh);
    }
});

In that way, if a color is provided to the material, it will be exported in the .mtl file. But the last missing piece is probably how to properly convert a shaderMaterial for example? Save it as a texture maybe?

compmonks
  • 647
  • 10
  • 24

0 Answers0