
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
msh-parser
Advanced tools
Finite element .msh format loader and parser, works on binary and ascii .msh files – unit tested and written in TypeScript.
Live demo: apps.amandaghassaei.com/msh-parser/demo/
The MSH file format is used for storing 3D finite element mesh information for simulation purposes. This library does not generate or render .msh files, but it will allow you to parse them in a browser or Nodejs environment. You can generate tetrahedral .msh files from boundary meshes (.stl, .obj) using TetWild. You can view .msh files with Gmsh or by dragging them into the demo app. Example .msh files can be found in test/msh/.
npm install msh-parser
and import into your project:
import { parseMSH, loadMSH, loadMSHAsync } from 'msh-parser';
Import bundle/msh-parser.min.js directly into your html:
<html>
<head>
<script src="msh-parser.min.js"></script>
</head>
<body>
</body>
</html>
MSHParserLib
will be accessible globally:
const { parseMSH, loadMSH, loadMSHAsync } = MSHParserLib;
Full API documentation in docs.
// Load and parse the .msh file using the specified file path.
loadMSH('./bunny.msh', (mesh) => {
const {
nodes,
elementIndices,
edgesIndices,
exteriorEdgesIndices,
exteriorFacesIndices,
elementVolumes,
nodalVolumes,
isTetMesh,
numExteriorNodes,
boundingBox,
} = mesh;
});
// Also try:
// const mesh = loadMSHAsync('./bunny.msh');
// Or parse synchronously from file buffer.
const mesh = parseMSH(fs.readFileSync('./bunny.msh'));
nodes
is a Float32Array or Float64Array of length 3 * numNodes containing a flat list of node positions in the following order [x0, y0, z0, x1, y1, z1, ...]
.elementIndices
is a 2 dimensional array of node indices corresponding to the finite elements of the mesh. For a tetrahedral mesh, all elements will contain four node indices, but element length may vary for other types of meshes. elementIndices
has the following structure:[
[e0a, e0b, e0c, e0d], // Element 0
[e1a, e1b, e1c, e1d], // Element 1
...
]
edgesIndices
(tet-meshes only for now) is a Uint32Array containing all pairs of edgesIndices in the mesh. Node indices are in the form: [e01, e02, e11, e12, ...]
. edgesIndices
is calculated when queried and then cached.exteriorEdgesIndices
(tet-meshes only for now) is a Uint32Array containing all pairs of exterior edgesIndices in the mesh. Node indices are in the form: [e01, e02, e11, e12, ...]
. exteriorEdgesIndices
is calculated when queried and then cached.exteriorFacesIndices
(tet-meshes only for now) is a 2 dimensional array of node indices corresponding to the exterior faces of the mesh. For a tetrahedral mesh, all exterior faces will be triangles, but face shape may vary for other types of meshes. Triangular exterior faces have CC winding order. exteriorFacesArray
has the following structure:[
[f0a, f0b, f0c], // Face 0
[f1a, f1b, f1c], // Face 1
...
]
elementVolumes
(tet-meshes only for now) is a Float32Array containing the volume of all elements in the mesh. elementVolumes
is calculated when queried and then cached.nodalVolumes
(tet-meshes only for now) is a Float32Array containing the approximate volume of all nodes in the mesh. This is calculated by evenly distributing element volume across adjacent nodes. nodalVolumes
is calculated when queried and then cached.isTetMesh
is a boolean that indicates all mesh elements are tetrahedra.numExteriorNodes
(tet-meshes only for now) is the number of nodes that lie on the exterior of the mesh. nodes
has been ordered so that the nodes in the range [0, numExteriorNodes - 1] correspond to the nodes referenced by exteriorFacesIndices
.boundingBox
is the min and max of the mesh's bounding box in the form: { min: [x, y, z], max: [x, y, z] }
. boundingBox
is calculated when queried and then cached.The mesh object returned by parseMSH
, loadMSH
, and loadMSHAsync
also exposes methods for modifying its geometry:
mesh.scaleNodesToUnitBoundingBox();
MSHMesh.scaleNodesToUnitBoundingBox()
scales the nodes
values (in place) to fit inside a unit box and centered around the origin.This library imports fs
in Nodejs environments to load files from a url string. This code is never hit in the browser environment (the browser uses a XMLHttpRequest instead), but you may see build warnings due to the import('fs')
statement in the code. (I'm wondering if there is a better way to handle this that is compatible for both Nodejs and browser environments, please let me know if you have ideas.)
To fix this warning, you need to set fs
as an external dependency in your build settings:
// rollup.config.js
export default {
...
external: ['fs'],
};
// vite.config.js
export default {
build: {
rollupOptions: {
external: ['fs'],
},
}
...
}
This work is licensed under an MIT License. It depends on the following:
I don't have any plans to continue developing this package, but I'm happy to review pull requests if you would like to add a new feature.
To install dev dependencies:
npm install
To compile src
to dist
:
npm run build
To run tests:
npm run test
FAQs
Finite element .msh format parser, written in TypeScript.
The npm package msh-parser receives a total of 2 weekly downloads. As such, msh-parser popularity was classified as not popular.
We found that msh-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.