Skip to content

armgit / SOMA

Public Imported from GitHub
0

Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice

App: deckende Referenzen mit Tiefe zeichnen, Tests für Schraubbahn, Warnungen und alpha

Kai-Jungsthoefel3696f1345b17
diff --git a/app/src/renderer/viewer.ts b/app/src/renderer/viewer.ts
index 8551608..01bec22 100644
--- a/app/src/renderer/viewer.ts
+++ b/app/src/renderer/viewer.ts
@@ -297,7 +297,9 @@ export class Viewer {
mat.polygonOffset = true; mat.polygonOffsetFactor = 1; mat.polygonOffsetUnits = 1;
mat.userData.baseOpacity = mat.opacity;
mat.userData.baseTransparent = mat.transparent;
- if (meta.role === 'reference') { mat.depthWrite = false; m.renderOrder = 1; }
+ // Durchsichtige Referenzen ohne Tiefe, damit man dahinter sieht. Eine deckende (alpha=1, etwa ein Boden) wie ein Bauteil
+ mat.userData.seeThrough = meta.role === 'reference' && mat.opacity < 1;
+ if (mat.userData.seeThrough) { mat.depthWrite = false; m.renderOrder = 1; }
}
fresh.set(meta.partId, { group: o, meta, meshes, lines, base: o.position.clone(), offset: new THREE.Vector3() });
});
@@ -482,8 +484,9 @@ export class Viewer {
// Einzeln transparent: deutlich durchsichtiger und ohne Tiefe, damit man sieht, was dahinter liegt
mat.opacity = own ? Math.min(base, 0.18) : this.ghost ? Math.min(base, 0.35) : base;
mat.transparent = own || this.ghost || (mat.userData.baseTransparent as boolean);
- mat.depthWrite = !own && p.meta.role !== 'reference';
- m.renderOrder = own ? 2 : p.meta.role === 'reference' ? 1 : 0;
+ const seeThrough = mat.userData.seeThrough as boolean;
+ mat.depthWrite = !own && !seeThrough;
+ m.renderOrder = own ? 2 : seeThrough ? 1 : 0;
mat.needsUpdate = true;
}
}
diff --git a/app/test/animation.mjs b/app/test/animation.mjs
index 642fc86..d2fc493 100644
--- a/app/test/animation.mjs
+++ b/app/test/animation.mjs
@@ -65,6 +65,30 @@ a = Animation("Deckel falsch")
lid = a.hinge("Lid", (0, 0, 26), (1, 0, 26))
a.play(lid.to(60), run_time=1)
`;
+// Konsole schwenkt mit to() um 90° um die senkrechte Achse durch (-50, 0): Schraubbahn statt geradem Weg des Ursprungs.
+// Dazu je ein Fall für die Bewegungsprüfung: Sprung (run_time=0), zu schnelle Drehung, am Ende versteckt
+const BEWEGUNG = `import cadquery as cq
+from soma.anim import Animation
+
+a = Animation("Bewegung")
+konsole = a.part("Konsole")
+stift = a.hinge("Stift", (50, 0, 0), (50, 0, 1))
+lasche = a.part("Lasche")
+a.play(konsole.to(cq.Location(cq.Vector(-50, 50, 0), cq.Vector(0, 0, 1), 90)), run_time=1, ease="linear")
+a.play(stift.by(1800), run_time=1)
+a.play(lasche.translate((0, -30, 0)), run_time=0)
+a.wait(0.5)
+a.hide("Störer")
+a.wait(0.5)
+`;
+// Abstand eines Punkts der Konsole (10 mm neben der Achse) von der Achse nach der halben Drehung
+const POSE = `from soma import animrun
+import numpy as np
+_p, res = animrun.load(".")
+a = next(x for _f, r in res if isinstance(r, list) for x in r if x.name == "Bewegung")
+p = a.poses(0.5)["Konsole"] @ np.array([-60.0, 0, 5, 1])
+print(round(float(np.hypot(p[0] + 50, p[1])), 4))
+`;
const KAPUTT = `from soma.anim import Animation
a = Animation("Kaputt")
a.hinge("Gibtsnicht", (0, 0, 0), (1, 0, 0))
@@ -140,6 +164,26 @@ try {
await waitFor('Fehler weg', () => window.soma.anim.list().then((x) => x.errors.length === 0), 20000).catch(() => {});
check('Gelöschte Datei: Ihr Fehler verschwindet aus der Liste', (await list()).errors.length === 0);
+ // 3b) Schraubbahn bei to() und Bewegungsprüfung (Sprung, Eiern, am Ende versteckt)
+ r = soma(['anim', 'info', 'Deckel öffnen']);
+ check('Ruhige Animation: keine Warnungen zur Bewegung', r.stdout.includes('Motion: no jumps, wobble or parts hidden at the end'), r.stdout.slice(-400));
+ fs.writeFileSync(path.join(dir, 'animations', 'bewegung.py'), BEWEGUNG);
+ // Erst den Watcher bauen lassen, sonst bauen App und soma gleichzeitig
+ await waitFor('Animation Bewegung gebaut', () => window.soma.anim.list().then((x) => x.animations.length === 3 && !x.building), 90000);
+ r = soma(['anim', 'build', 'animations/bewegung.py']);
+ check('soma anim build meldet Eiern (Stift), Sprung (Lasche) und am Ende versteckt (Störer)', r.status === 0
+ && /Stift: turns up to [\d.]+ deg per frame[^\n]*\(wobble\)/.test(r.stdout) && /Lasche: jumps 30 mm within one frame/.test(r.stdout)
+ && r.stdout.includes('still hidden at the end: Störer') && !r.stdout.includes('Konsole:'), r.stdout + r.stderr);
+ r = spawnSync(PY, ['-c', POSE], { cwd: dir, env, encoding: 'utf8', timeout: 5 * 60 * 1000 });
+ check('to() mit Drehung um eine Achse fern vom Ursprung: Schraubbahn, der Punkt bleibt 10 mm neben der Achse', near(Number(r.stdout.trim()), 10, 1e-3),
+ r.stdout + r.stderr);
+ r = soma(['anim', 'info', 'Bewegung']);
+ check('soma anim info zeigt die Warnungen', r.stdout.includes('Motion warnings:') && r.stdout.includes('Lasche: jumps'), r.stdout.slice(-600));
+ fs.rmSync(path.join(dir, 'animations', 'bewegung.py'));
+ // Der Index verliert gelöschte Dateien erst beim nächsten Bauen
+ soma(['anim', 'build']);
+ await waitFor('Animation Bewegung wieder weg', () => window.soma.anim.list().then((x) => x.animations.length === 2 && !x.building), 90000);
+
// 4) Abspielen im Viewer. Animationen und Analysen stehen in eigenen Reitern (E82): Der Reiter zeigt die Liste, erst ein Klick
// darin spielt eine ab. `showAnim` wählt wie ein Klick in der Liste
await ev(() => window.__t.refreshViewLists());
diff --git a/app/test/groups.mjs b/app/test/groups.mjs
index ccf3844..a323c36 100644
--- a/app/test/groups.mjs
+++ b/app/test/groups.mjs
@@ -240,6 +240,17 @@ walk(a)`);
check('output/model.step: Gehaeuse › Schrauben › Schraube und Reference › Platine › Stecker › USB_C', lines.includes(' Gehaeuse') && lines.includes(' Schrauben') && lines.includes(' Schraube')
&& lines.includes(' Reference') && lines.includes(' Platine') && lines.includes(' Stecker') && lines.includes(' USB_C'), lines.join(' | ').slice(0, 120));
+ // 8) Referenz mit alpha=1 (Boden, Logo für eine Animation): deckend mit Tiefe, trotzdem nicht in export --all
+ fs.writeFileSync(path.join(proj.dir, 'model.py'), MODEL + 'add_part("Tisch", cq.Workplane().box(100, 80, 2).translate((0, 0, -12)), role="reference", alpha=1, color=(0.3, 0.3, 0.3))\n');
+ await waitFor('Modell mit deckender Referenz gebaut', () => window.__t.status().state === 'ok' && window.__t.partCount() === 7, 90000).catch(() => {});
+ const ids7 = await ev(() => Object.fromEntries(window.__t.parts().map((p) => [p.name, p.id])));
+ const tisch = await ev((id) => window.__t.viewer.partLook(id), ids7.Tisch);
+ const platine = await ev((id) => window.__t.viewer.partLook(id), ids7.Leiterplatte);
+ check('Referenz mit alpha=1 deckend und mit Tiefe, die übrigen Referenzen bleiben durchsichtig', tisch?.opacity === 1 && tisch.depthWrite
+ && platine?.opacity < 1 && !platine.depthWrite, JSON.stringify({ tisch, platine }));
+ const exp = spawnSync(PY, ['-m', 'soma', 'export', '--all', '--format', 'step', '--out', path.join(proj.dir, 'renders'), '--project', proj.dir], { encoding: 'utf8', env: { ...process.env, PYTHONUTF8: '1' } });
+ check('soma export --all lässt auch die deckende Referenz aus', exp.status === 0 && !exp.stdout.includes('Tisch') && /not exported: \d+ reference/.test(exp.stdout), exp.stdout + exp.stderr);
+
const relevant = page.errors.filter((e) => !/favicon/i.test(e));
check('Keine Konsolenfehler im Renderer', relevant.length === 0, relevant.slice(0, 2).join(' | ').slice(0, 100));
} catch (e) {