Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: support double-sided open-shell materials (#4632)

Adam Eivy847e7b83488e
diff --git a/client/src/lib/threejsSculpt.js b/client/src/lib/threejsSculpt.js
index dea57c5414..82db900cc2 100644
--- a/client/src/lib/threejsSculpt.js
+++ b/client/src/lib/threejsSculpt.js
@@ -71,11 +71,13 @@ export function createSculptBufferGeometry(definition) {
* render profile — the two must move together.
*/
export function sculptMaterialProps(definition, envMapIntensity = 1) {
+ const doubleSided = definition.side === 'double' ? { side: THREE.DoubleSide } : {};
const unlit = {
color: definition.color,
opacity: definition.opacity,
transparent: definition.transparent,
wireframe: definition.wireframe,
+ ...doubleSided,
};
if (definition.type === 'basic') return unlit;
const lit = {
diff --git a/client/src/lib/threejsSculpt.test.js b/client/src/lib/threejsSculpt.test.js
index d7797a7c9a..8072e95f6d 100644
--- a/client/src/lib/threejsSculpt.test.js
+++ b/client/src/lib/threejsSculpt.test.js
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest';
+import * as THREE from 'three';
import { createSculptBufferGeometry, needsSculptBufferGeometry, sculptMaterialProps } from './threejsSculpt.js';
const extrudeDefinition = (overrides = {}) => ({
@@ -131,5 +132,12 @@ describe('sculptMaterialProps', () => {
// never `undefined` — three reads that as "leave the material's own".
expect(sculptMaterialProps(definition).envMapIntensity).toBe(1);
});
+
+ it('forwards double-sided rendering to every material type', () => {
+ for (const type of ['standard', 'physical', 'basic']) {
+ expect(sculptMaterialProps({ ...definition, type, side: 'double' }).side).toBe(THREE.DoubleSide);
+ }
+ expect(sculptMaterialProps({ ...definition, side: 'front' })).not.toHaveProperty('side');
+ });
});
// @vitest-environment node
diff --git a/client/src/pages/ThreejsModelDetail.jsx b/client/src/pages/ThreejsModelDetail.jsx
index 65a764d744..0f4f2de299 100644
--- a/client/src/pages/ThreejsModelDetail.jsx
+++ b/client/src/pages/ThreejsModelDetail.jsx
@@ -405,6 +405,7 @@ export default function ThreejsModelDetail() {
// the same as passing it — the panel is omitted rather than shown clean.
const coverageFindings = Array.isArray(record.coverage?.findings) ? record.coverage.findings : null;
const flatnessFindings = Array.isArray(record.flatness?.findings) ? record.flatness.findings : null;
+ const flatnessHasWarnings = flatnessFindings?.some((finding) => finding.severity === 'warning');
const penetrationFindings = Array.isArray(record.penetration?.findings) ? record.penetration.findings : null;
const physicalAuditFindings = Array.isArray(record.physicalAudit?.findings)
? record.physicalAudit.findings
@@ -614,7 +615,7 @@ export default function ThreejsModelDetail() {
findings={flatnessFindings}
cleanLabel="Identity parts carry real depth"
footer={`A model can match its reference head-on and still be a stack of cardboard cut-outs, so this check counts how many identity-defining features are built only from flat parts.${
- flatnessFindings.length > 0 ? ' Refining without your own feedback will also ask for real depth.' : ''
+ flatnessHasWarnings ? ' Refining without your own feedback will also ask for real depth.' : ''
}`}
/>
)}
diff --git a/client/src/pages/ThreejsModelDetail.test.jsx b/client/src/pages/ThreejsModelDetail.test.jsx
index 4fcfb225e7..408c4524cd 100644
--- a/client/src/pages/ThreejsModelDetail.test.jsx
+++ b/client/src/pages/ThreejsModelDetail.test.jsx
@@ -167,6 +167,32 @@ describe('ThreejsModelDetail cross-section gate', () => {
expect(screen.queryByText(/will also ask for real depth/)).not.toBeInTheDocument();
});
+ it('shows an intentional membrane note without promising depth feedback', async () => {
+ getThreejsModel.mockResolvedValue({
+ ...baseRecord,
+ flatness: {
+ errorCount: 0,
+ warningCount: 0,
+ noteCount: 1,
+ identityDetailCount: 1,
+ flatIdentityDetailCount: 1,
+ flatRatio: 1,
+ slabPartIds: ['fin'],
+ findings: [{
+ code: 'flat-identity-parts',
+ severity: 'note',
+ message: '1 of 1 identity-defining features are intentional membrane surfaces (Fin).',
+ }],
+ },
+ });
+ renderDetail();
+
+ await waitFor(() => expect(screen.getByText('Cross-section')).toBeInTheDocument());
+ expect(screen.getByText(/intentional membrane surfaces/)).toBeInTheDocument();
+ expect(screen.getByText('0 error · 0 warning · 1 note')).toBeInTheDocument();
+ expect(screen.queryByText(/will also ask for real depth/)).not.toBeInTheDocument();
+ });
+
it('hides the section for a record generated before the gate existed', async () => {
getThreejsModel.mockResolvedValue({ ...baseRecord, flatness: null });
renderDetail();
diff --git a/server/lib/threejsModel.js b/server/lib/threejsModel.js
index 03995a72df..99af7f460d 100644
--- a/server/lib/threejsModel.js
+++ b/server/lib/threejsModel.js
@@ -265,6 +265,7 @@ export const threejsGeometrySchema = z.discriminatedUnion('type', [
export const threejsMaterialSchema = z.object({
type: z.enum(['standard', 'physical', 'basic']).default('standard'),
+ side: z.enum(['front', 'double']).default('front'),
color: colorSchema,
metalness: z.number().finite().min(0).max(1).default(0),
roughness: z.number().finite().min(0).max(1).default(0.65),
@@ -844,6 +845,8 @@ export function evaluateThreejsFlatness(spec) {
const details = Array.isArray(spec?.detailInventory) ? spec.detailInventory : [];
const slabPartIds = new Set();
const flatFeatures = [];
+ const intentionalMembraneFeatures = [];
+ const intentionalMembranePartIds = new Set();
let evaluated = 0;
for (const detail of details) {
@@ -865,6 +868,11 @@ export function evaluateThreejsFlatness(spec) {
if (!implementing.every((mesh) => isSlabGeometry(mesh.geometry))) continue;
flatFeatures.push(detail.feature);
for (const mesh of implementing) slabPartIds.add(mesh.id);
+ const isIntentionalMembrane = implementing.every((mesh) => spec?.materials?.[mesh.material]?.side === 'double');
+ if (isIntentionalMembrane) {
+ intentionalMembraneFeatures.push(detail.feature);
+ for (const mesh of implementing) intentionalMembranePartIds.add(mesh.id);
+ }
}
// `null`, not 0: a spec with no buildable identity feature was not measured
@@ -872,21 +880,41 @@ export function evaluateThreejsFlatness(spec) {
const flatRatio = evaluated === 0 ? null : flatFeatures.length / evaluated;
const findings = [];
if (flatRatio !== null && flatRatio > FLAT_IDENTITY_RATIO_THRESHOLD) {
- const offenders = [...slabPartIds];
- findings.push({
- code: 'flat-identity-parts',
- severity: 'warning',
- partIds: offenders,
- features: flatFeatures,
- message: `${flatFeatures.length} of ${evaluated} identity-defining features are built only from flat parts (${listSpecNames(offenders.map((id) => byId.get(id)?.name || id))}). The model will read as a projection the moment it is orbited — give the parts the subject's identity rides on a real cross-section instead of stacking unbevelled extrusions and planar triangle fans.`,
- });
+ const intentionalFeatureNames = new Set(intentionalMembraneFeatures);
+ const unintentionalFeatures = flatFeatures.filter((feature) => !intentionalFeatureNames.has(feature));
+ const nonMembraneFeatureCount = evaluated - intentionalMembraneFeatures.length;
+ const nonMembraneFlatRatio = nonMembraneFeatureCount === 0
+ ? 0
+ : unintentionalFeatures.length / nonMembraneFeatureCount;
+ if (intentionalMembraneFeatures.length > 0) {
+ findings.push({
+ code: 'flat-identity-parts',
+ severity: 'note',
+ partIds: [...intentionalMembranePartIds],
+ features: intentionalMembraneFeatures,
+ message: `${intentionalMembraneFeatures.length} of ${evaluated} identity-defining features are intentional membrane surfaces (zero-thickness open shells: ${listSpecNames(intentionalMembraneFeatures)}). Their materials are double-sided (side "double"), so they remain visible from both sides.`,
+ });
+ }
+ if (nonMembraneFlatRatio > FLAT_IDENTITY_RATIO_THRESHOLD) {
+ const offenders = [...slabPartIds].filter((id) => !intentionalMembranePartIds.has(id));
+ findings.push({
+ code: 'flat-identity-parts',
+ severity: 'warning',
+ partIds: offenders,
+ features: unintentionalFeatures,
+ message: `${unintentionalFeatures.length} of ${nonMembraneFeatureCount} identity-defining features are built only from flat parts (${listSpecNames(offenders.map((id) => byId.get(id)?.name || id))}). The model will read as a projection the moment it is orbited — give the parts the subject's identity rides on a real cross-section instead of stacking unbevelled extrusions and planar triangle fans. If a part is genuinely a zero-thickness membrane, make its material double-sided (side "double") instead; do not use that declaration to avoid giving a solid part real depth.`,
+ });
+ }
}
+ const warningCount = findings.filter((finding) => finding.severity === 'warning').length;
+ const noteCount = findings.filter((finding) => finding.severity === 'note').length;
+
return {
findings,
errorCount: 0,
- warningCount: findings.length,
- noteCount: 0,
+ warningCount,
+ noteCount,
identityDetailCount: evaluated,
flatIdentityDetailCount: flatFeatures.length,
flatRatio,
@@ -905,7 +933,7 @@ export function buildThreejsFlatnessFeedback(flatness) {
return [
'The previous pass failed the cross-section check — it reads as a flat projection rather than a solid:',
...warnings.map((finding, index) => `${index + 1}. ${finding.message}`),
- 'Rebuild those parts with genuine depth: compose them from primitives, or give an extrude a bevel, so the model holds up from any orbit angle.',
+ 'Rebuild those parts with genuine depth: compose them from primitives, or give an extrude a bevel, so the model holds up from any orbit angle. If a part is genuinely a zero-thickness membrane — such as a cape, leaf, fin, or wing — make its material double-sided (side "double") instead, but never use that declaration to avoid giving a solid part real depth.',
].join('\n');
}
@@ -1261,11 +1289,13 @@ function createGeometry(definition) {
}
function createMaterial(definition) {
+ const doubleSided = definition.side === 'double' ? { side: THREE.DoubleSide } : {};
const unlit = {
color: definition.color,
opacity: definition.opacity,
transparent: definition.transparent,
wireframe: definition.wireframe,
+ ...doubleSided,
};
if (definition.type === 'basic') {
return new THREE.MeshBasicMaterial(unlit);
diff --git a/server/lib/threejsModel.test.js b/server/lib/threejsModel.test.js
index 413ddd72ee..4a0b80dd19 100644
--- a/server/lib/threejsModel.test.js
+++ b/server/lib/threejsModel.test.js
@@ -72,6 +72,7 @@ describe('threejsSculptSpecSchema', () => {
it('accepts a bounded hierarchy and fills material/part defaults', () => {
const parsed = threejsSculptSpecSchema.parse(validSpec());
expect(parsed.materials.body.emissive).toBe('#000000');
+ expect(parsed.materials.body.side).toBe('front');
expect(parsed.parts[0].castShadow).toBe(true);
expect(parsed.parts[0].children[0].id).toBe('frontTrim');
});
@@ -348,6 +349,14 @@ describe('buildThreejsFactorySource', () => {
expect(source).toContain('"explodeWithParent": true');
});
+ it('emits the declared double-sided material option for the standalone factory', () => {
+ const spec = validSpec();
+ spec.materials.body.side = 'double';
+ const source = buildThreejsFactorySource(spec);
+ expect(source).toContain('"side": "double"');
+ expect(source).toContain('const doubleSided = definition.side === \'double\' ? { side: THREE.DoubleSide } : {};');
+ });
+
it('emits extrude, tube, and physical-channel construction', () => {
const spec = validSpec();
spec.parts[0].geometry = validExtrude();
@@ -589,6 +598,26 @@ describe('evaluateThreejsFlatness', () => {
it('returns a clean result for a missing spec', () => {
expect(evaluateThreejsFlatness(null)).toMatchObject({ findings: [], flatRatio: null });
});
+
+ it('notes a flat identity part as an intentional membrane when its material is double-sided', () => {
+ const spec = flatnessSpec([geometryPart('membrane', flatFanGeometry())]);
+ spec.materials.body.side = 'double';
+ const flatness = evaluateThreejsFlatness(spec);
+ expect(flatness).toMatchObject({
+ warningCount: 0,
+ noteCount: 1,
+ flatIdentityDetailCount: 1,
+ flatRatio: 1,
+ });
+ expect(flatness.findings[0]).toMatchObject({
+ code: 'flat-identity-parts',
+ severity: 'note',
+ partIds: ['membrane'],
+ features: ['membrane part silhouette'],
+ });
+ expect(flatness.findings[0].message).toContain('intentional membrane surfaces');
+ expect(buildThreejsFlatnessFeedback(flatness)).toBe('');
+ });
});
describe('buildThreejsFlatnessFeedback', () => {
diff --git a/server/services/threejsModels/prompt.js b/server/services/threejsModels/prompt.js
index 03ccd772fc..149901f6fb 100644
--- a/server/services/threejsModels/prompt.js
+++ b/server/services/threejsModels/prompt.js
@@ -30,6 +30,10 @@ Choosing between them:
- lathe — profiles that are rotationally symmetric about the Y axis.
- custom triangles — a last resort, only after none of the above can express the silhouette.
+A genuinely zero-thickness two-sided surface — such as a wing membrane, cape, leaf, or fin —
+needs a material with "side":"double" or it disappears from behind. Use that declaration only
+for an intentional open shell; it must not be used to dodge giving a solid part a real cross-section.
+
When extrude is the WRONG answer: an unbevelled extrude has exactly two depth planes, so it is
a slab. A body with a real cross-section — a torso, a limb, a head, a housing, a grip, a shell
that swells or tapers through its thickness — must not be one. Build it from primitives, a
@@ -53,6 +57,7 @@ Return one raw JSON object and nothing else. It must have exactly this top-level
"materials": {
"materialId": {
"type":"standard" | "physical" | "basic",
+ "side":"front" | "double",
"color":"#RRGGBB","metalness":0..1,"roughness":0..1,
"emissive":"#RRGGBB","emissiveIntensity":0..20,
"opacity":0..1,"transparent":false,"wireframe":false,