The post shows a simple way how to download the 3D Model from web page which constructed by wasm.

I assume that you have a 3D model in the scene. Now you want download the mesh from the web page to local disk.

Write a CPlusPlus interface to convert mesh to a string.

std::string UWorker::GetPolyDataStr()
{
    auto data = m_Actor->GetMapper()->GetInput();

    vSPNew( writer, vtkXMLPolyDataWriter );
    writer->SetInputData( data );
    writer->SetDataModeToAscii();
    writer->WriteToOutputStringOn();
    writer->Update();
    auto xml = writer->GetOutputString();

    Log( IInfo, "data: ", data->GetNumberOfCells() );
    //Log( IInfo, "data: ", xml );

    return xml;
}

Bind the interface for wasm in the file binding.cpp

#include <emscripten/bind.h>
#include "UWorker.h"

using namespace emscripten;

EMSCRIPTEN_BINDINGS(uWorker) {
   class_<UWorker>("UWorker")
      .constructor()
//...
      .function("GetPolyDataStr", &UWorker::GetPolyDataStr)
      ;
}

Finally, we can convert the string to blob object in html page to download. You can open it in your 3D mesh software such as Paraview.

<script>
            var data = workerObj.GetPolyDataStr();
            console.log( data );

            save( new Blob( [ data ], { type: 'text/plain' } ), "new_mesh.vtp" );
</script>

Categories: Web

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x