8000 Add gl-matrix to editor by elalish · Pull Request #332 · elalish/manifold · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add gl-matrix to editor #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bindings/wasm/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ Manifold Revolve(std::vector<std::vector<glm::vec2>>& polygons,
return Manifold::Revolve(ToPolygon(polygons), circularSegments);
}

Manifold Transform(Manifold& manifold, std::vector<float>& mat) {
Manifold Transform(Manifold& manifold, const val& mat) {
std::vector<float> array = convertJSArrayToNumberVector<float>(mat);
glm::mat4x3 matrix;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 3; j++) matrix[i][j] = mat[i * 3 + j];
for (const int col : {0, 1, 2, 3})
for (const int row : {0, 1, 2}) matrix[col][row] = array[col * 4 + row];
return manifold.Transform(matrix);
}

Expand Down
30 changes: 8 additions & 22 deletions bindings/wasm/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,6 @@ Module.setup = function() {
return out;
};

// note that the matrix is using column major (same as glm)
Module.Manifold.prototype.transform = function(mat) {
const vec = new Module.Vector_f32();
if (mat.length == 16) {
// assuming glMatrix format (column major)
// skip the last row
for (let i = 0; i < 16; i++)
if (i % 4 != 3)
vec.push_back(mat[i]);
} else {
console.assert(mat.length == 4, 'expects a 3x4 matrix');
for (let col of mat) {
console.assert(col.length == 3, 'expects a 3x4 matrix');
for (let x of col) vec.push_back(x);
}
}
const result = this._Transform(vec);
vec.delete();
return result;
};

Module.Manifold.prototype.translate = function(...vec) {
return this._Translate(vararg2vec(vec));
};
Expand Down Expand Up @@ -184,7 +163,14 @@ Module.setup = function() {
}

transform(run) {
return this.runTransform.subarray(12 * run, 12 * (run + 1));
const mat4 = new Array(16);
for (const col of [0, 1, 2, 3]) {
for (const row of [0, 1, 2]) {
mat4[4 * col + row] = this.runTransform[12 * run + 3 * col + row];
}
}
mat4[15] = 1;
return mat4;
}
}

Expand Down
Loading
0