Show Mesh Tessellation

HOOPS Communicator does not have a built-in render mode to show mesh tessellation, however it is very easy to extract and show that information. See the function below that provides this functionality. Make sure to pass in the nodeid of a body node.

For a live demo see here:
https://3dsandbox.techsoft3d.com/?snippet=3YgjHRQW8Kadi9VNrHLOik&autorun=true

async function showNodeTessellation(nodeid) {
    const mdata = new Communicator.MeshData();
    let matrix = hwv.model.getNodeMatrix(nodeid);

    let data = await hwv.model.getNodeMeshData(nodeid);
    let lines = [];
    for (let i = 0; i < data.faces.elementCount; i++) {
        let face = data.faces.element(i);
        let pp = face.iterate();
        for (let j = 0; j < face.vertexCount; j += 3) {
            let tp = [];
            for (let k = 0; k < 3; k++) {
                let rawpoint = pp.next();
                let p = new Communicator.Point3(rawpoint.position[0], rawpoint.position[1], rawpoint.position[2]);
                p = matrix.transform(p);
                tp.push(p.x,p.y,p.z);
            }
            tp.push(tp[0],tp[1],tp[2]);
            mdata.addPolyline(tp);
        }
    }
    mdata.addPolyline(lines);
    const mid = await hwv.model.createMesh(mdata);
    let meshInstanceData = new Communicator.MeshInstanceData(mid);
    let node = hwv.model.createNode(hwv.model.getNodeParent(nodeid), "meshnode");
    const resnode = await hwv.model.createMeshInstance(meshInstanceData, node);
    hwv.model.setNodesLineColor([node], Communicator.Color.black());
    return resnode;
}
2 Likes