Skip to content

Commit

Permalink
add test for any mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Apr 5, 2024
1 parent cb73060 commit 0e2d5ab
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 6 deletions.
10 changes: 9 additions & 1 deletion demo/datas/any_mesh_settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[
{
"name": "test",
"name": "tetrahedron",
"color": "#bd0d87",
"material": "Standard",
"position": [-5.0, 0.0, 0.0],
"vertices": [0.0, 1.0, 0.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0],
"faces": [0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 1, 1, 4, 3, 3, 2, 1]
},
{
"name": "cube",
"color": "#ff0000",
"material": "Standard",
"vertices": [-3.0, -3.0, -3.0, -3.0, -3.0, 3.0, -3.0, 3.0, -3.0, -3.0, 3.0, 3.0, 3.0, -3.0, -3.0, 3.0, -3.0, 3.0, 3.0, 3.0, -3.0, 3.0, 3.0, 3.0],
"faces": [0, 1, 2, 1, 3, 2, 4, 6, 5, 6, 7, 5, 4, 5, 0, 5, 1, 0, 6, 2, 7, 2, 3, 7, 0, 2, 4, 2, 6, 4, 1, 5, 3, 5, 7, 3]
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weas",
"version": "0.1.4",
"version": "0.1.5",
"description": "WEAS (Web Environment for Atomic Structures) is a JavaScript library to visualize and manipulate the atomistic structures directly in the web browser",
"main": "src/index.js",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/AnyMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { clearObject } from "../utils.js";
import { materials } from "../tools/materials.js";

class Setting {
constructor({ name, vertices, faces, color, materialType = "Standard" }) {
constructor({ name, vertices, faces, color = "#bd0d87", position = [0, 0, 0], materialType = "Standard" }) {
/* A class to store settings */

this.name = name;
this.vertices = vertices;
this.faces = faces;
this.color = color;
this.position = position;
this.materialType = materialType;
}
}
Expand All @@ -33,9 +34,9 @@ export class AnyMesh {
}

// Modify addSetting to accept a single object parameter
addSetting({ name, vertices, faces, color, materialType }) {
addSetting({ name, vertices, faces, color, position, materialType }) {
/* Add a new setting */
const setting = new Setting({ name, vertices, faces, color, materialType });
const setting = new Setting({ name, vertices, faces, color, position, materialType });
this.settings.push(setting);
}

Expand Down Expand Up @@ -63,6 +64,8 @@ export class AnyMesh {
const faces = new Uint32Array(setting.faces);
geometry.setIndex(new THREE.BufferAttribute(faces, 1));
const object = new THREE.Mesh(geometry, material);
// set position
object.position.set(setting.position[0], setting.position[1], setting.position[2]);
this.meshes.push(object);
this.scene.add(object);
});
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/gui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ test("Instanced Primitive", async ({ page }) => {
await expect(page).toHaveScreenshot();
});

test("Any Mesh", async ({ page }) => {
await page.goto("http://127.0.0.1:8080/tests/e2e/testAnyMesh.html");
await expect(page).toHaveScreenshot();
});

test.describe("Edit", () => {
test.beforeEach(async ({ page }) => {
await page.goto("http://127.0.0.1:8080/tests/e2e/testHighlightAtoms.html");
Expand Down Expand Up @@ -280,7 +285,6 @@ test.describe("Animation", () => {
});
});


test.describe("Measurement", () => {
test.beforeEach(async ({ page }) => {
await page.goto("http://127.0.0.1:8080/tests/e2e/testMeasurement.html");
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/e2e/gui.spec.js-snapshots/VectorField-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tests/e2e/testAnyMesh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>WEAS Test</title>
</head>
<body>
<div id="viewer" style="position: relative; width: 600px; height: 400px"></div>

<script type="module">
import * as weas from "../../dist/weas.mjs";

async function fetchFile(filename) {
const response = await fetch(`../../demo/datas/${filename}`);
if (!response.ok) {
throw new Error(`Failed to load file for structure: ${filename}`);
}
return await response.text();
}

let domElement = document.getElementById("viewer");
// read atoms from file
const filename = "any_mesh_settings.json";
fetchFile(filename).then((fileContent) => {
const data = JSON.parse(fileContent);
let editor = new weas.WEAS({ domElement });
editor.anyMesh.fromSettings(data);
editor.anyMesh.drawMesh();
editor.selectionManager.selectedObjects = [editor.anyMesh.meshes[0]];
editor.render();
});
</script>
</body>
</html>

0 comments on commit 0e2d5ab

Please sign in to comment.