Git Product home page Git Product logo

3dlibrary's Introduction

How to build

Linux

install libraries

cd 3DLibrary/wasm-library && ./install_libraries.sh

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

building wasm library (make sure you are in /wasm-library directory)

compiling cmake file and build

./build.sh gener

after editing the main.cpp, recurrent build will be

./build.sh

check build folder for index.js and index.wasm file

How to use

<html>
<body>
 <canvas id="app"></canvas>
    <script>
    var Module = {
      onRuntimeInitialized: function() {
        window.Module = Module;
        console.log("hehe", Module)
      }
    };
    </script>
    <script src="../wasm-library/build/index.js"></script>
    <script>
    const polyMesh = new Module.PolyMesh(); //First need to create an instance of the polymesh wrapper (referenced in wasm-library/main.cpp)
    
    const mesh = BABYLON.MeshBuilder.CreateBox("mesh", {size: 2});
    const position = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
    const indices = mesh.getIndices();
    
    //populate the polyMesh with the position data from mesh to create a CGAL::Surface_mesh
    for(let i = 0; i<position.length / 3; i++){
      polyMesh.addVertex(position[i * 3], position[i * 3 + 1], position[i * 3 + 2]);
    }
    
    for(let j = 0; j < indices.length / 3; j++){
      polyMesh.addFace([indices[j * 3], indices[j * 3 + 1], indices[j * 3 + 2]])
    }
    
    //retrieve a position/indices data to update mesh
     function getMeshData(){
        let positions_buffer = polyMesh.getVertices();
        positions = Array.from(positions_buffer);
        positions_buffer = null;

        let triangles_buffer = polyMesh.getIndices();
        let indices = Array.from(triangles_buffer);
        triangles_buffer = null;

        return {positions, indices};
    }
    
    //do a simple CGAL operation like catmull smooth
    polyMesh.catmull_smooth();
    
    //update the mesh
    const dt = getMeshData()
    const vertexData = new BABYLON.VertexData()
    vertexData.positions = dt.positions
    vertexData.indices = dt.indices
    const normals = []
    BABYLON.VertexData.ComputeNormals(dt.positions, dt.indices, normals);
    vertexData.applyToMesh(mesh, true);
    
    
    </script>
</body>
</html>

3dlibrary's People

Contributors

ademola-lou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.