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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: flag non-uniform parent scales in Three.js audits (#4629)
[._.]/ Adam Eivy3fd88d13dc08
diff --git a/server/lib/threejsModelPhysicalAudit.js b/server/lib/threejsModelPhysicalAudit.jsindex 6b0d838946..6cb52d19f6 100644--- a/server/lib/threejsModelPhysicalAudit.js+++ b/server/lib/threejsModelPhysicalAudit.js@@ -6,6 +6,7 @@* 2. `buried-geometry`: Parts swallowed completely or heavily inside another part without hierarchy/attachment exemption.* 3. `coplanar-surface`: Sibling or unrelated part pairs sharing a near-coplanar surface (z-fighting).* 4. `unprovenanced-transition`: Animated parts that pop into existence in open space without emerging from a parent or ground level.+ * 5. `nonuniform-parent-scale`: A non-relief child inherits a parent's anisotropic scale and may be distorted.*/import { listSpecNames } from './threejsModel.js';@@ -14,6 +15,9 @@ const EPSILON = 1e-4;const COPLANAR_TOLERANCE = 1e-3;const TOUCH_TOLERANCE = 0.02;const MAX_AUDIT_POSES = 16;+// One percent anisotropy is small enough to ignore authoring noise while still+// catching the intentional shape-squashing that distorts a child hierarchy.+const NONUNIFORM_SCALE_TOLERANCE = 0.01;const degreesToRadians = (degrees) => (degrees * Math.PI) / 180;@@ -308,6 +312,96 @@ function collectPoseVolumes(spec, getPartState) {return volumes;}+const flattenParts = (parts) => {+ const flattened = [];+ const walk = (list) => {+ for (const part of list || []) {+ flattened.push(part);+ walk(part.children);+ }+ };+ walk(parts);+ return flattened;+};++const normalizeScale = (scale) => (+ Array.isArray(scale) && scale.length === 3 && scale.every((value) => Number.isFinite(value))+ ? scale+ : [1, 1, 1]+);++const getScaleAnisotropy = (scale) => {+ const normalized = normalizeScale(scale);+ const minimum = Math.min(...normalized);+ const maximum = Math.max(...normalized);+ const ratio = maximum / Math.max(minimum, EPSILON);+ if (ratio <= 1 + NONUNIFORM_SCALE_TOLERANCE) return null;+ return { scale: normalized, ratio };+};++const formatScale = (scale) => `[${scale.map((value) => Number(value.toFixed(4))).join(', ')}]`;++const formatNames = (names) => names.map((name) => `"${name}"`).join(', ');++const collectNonReliefDescendants = (part) => {+ const descendants = [];+ const walk = (children) => {+ for (const child of children || []) {+ if (child.explodeWithParent === true) continue;+ descendants.push({ id: child.id, name: child.name || child.id });+ walk(child.children);+ }+ };+ walk(part.children);+ return descendants;+};++const buildNonuniformParentScaleFinding = (part, scaleSamples, context = {}) => {+ const descendants = collectNonReliefDescendants(part);+ if (descendants.length === 0) return null;++ const normalizedSamples = scaleSamples.map((sample) => ({+ ...sample,+ scale: normalizeScale(sample.scale),+ anisotropy: getScaleAnisotropy(sample.scale),+ }));+ const analyzedSamples = normalizedSamples+ .filter((sample) => sample.anisotropy);+ if (analyzedSamples.length === 0) return null;++ const mostAnisotropic = analyzedSamples.reduce((best, sample) => (+ sample.anisotropy.ratio > best.anisotropy.ratio ? sample : best+ ));+ const minimumScale = [0, 1, 2].map((axis) => Math.min(...normalizedSamples.map((sample) => sample.scale[axis])));+ const maximumScale = [0, 1, 2].map((axis) => Math.max(...normalizedSamples.map((sample) => sample.scale[axis])));+ const sequenceIds = [...new Set(analyzedSamples.map((sample) => sample.sequenceId).filter(Boolean))];+ const { clipName, ...metadata } = context;+ const descendantNames = descendants.map((descendant) => descendant.name);+ const scope = clipName+ ? `In clip "${clipName}", part "${part.name || part.id}" is authored with non-uniform scale across range ${formatScale(minimumScale)} to ${formatScale(maximumScale)}`+ : `Part "${part.name || part.id}" is authored with non-uniform scale ${formatScale(mostAnisotropic.anisotropy.scale)}`;+ const sequenceSuffix = sequenceIds.length > 0 ? ` in scale sequence${sequenceIds.length === 1 ? '' : 's'} ${formatNames(sequenceIds)}` : '';++ return {+ code: 'nonuniform-parent-scale',+ severity: 'warning',+ ...metadata,+ sequenceId: sequenceIds.length > 0 ? sequenceIds.join(',') : metadata.sequenceId,+ partIds: [part.id, ...descendants.map((descendant) => descendant.id)],+ affectedDescendantNames: descendantNames,+ anisotropyRatio: mostAnisotropic.anisotropy.ratio,+ scaleRange: { min: minimumScale, max: maximumScale },+ message: `${scope} (maximum anisotropy ratio ${mostAnisotropic.anisotropy.ratio.toFixed(2)})${sequenceSuffix}, which cascades onto non-relief descendants ${formatNames(descendantNames)} and can distort them.`,+ };+};++const collectAnimatedScaleSamples = (part, sequences) => sequences+ .filter((sequence) => sequence.partId === part.id && sequence.channels?.scale)+ .flatMap((sequence) => [+ { scale: sequence.channels.scale.from, sequenceId: sequence.id },+ { scale: sequence.channels.scale.to, sequenceId: sequence.id },+ ]);+/*** @param {object|null} spec a validated Three.js scene spec* @returns {{findings: Array, errorCount: number, warningCount: number, noteCount: number,@@ -331,6 +425,7 @@ export function evaluateThreejsPhysicalAudit(spec) {const findings = [];const seenKeys = new Set();+ const parts = flattenParts(spec.parts);const addFinding = (finding) => {const key = `${finding.code}|${[...finding.partIds].sort().join(',')}|${finding.clipId || ''}|${finding.sequenceId || ''}`;@@ -344,6 +439,11 @@ export function evaluateThreejsPhysicalAudit(spec) {const evaluatedPartCount = staticVolumes.length;let evaluatedPoseCount = 1;+ for (const part of parts) {+ const finding = buildNonuniformParentScaleFinding(part, [{ scale: part.scale }]);+ if (finding) addFinding(finding);+ }+const visibleStaticVolumes = staticVolumes.filter((v) => v.visible && v.opacity > 0);// Floating check & Buried & Coplanar on resting pose@@ -445,9 +545,19 @@ export function evaluateThreejsPhysicalAudit(spec) {let remainingBudget = MAX_AUDIT_POSES - 1;for (const clip of clips) {+ const sequences = Array.isArray(clip.sequences) ? clip.sequences : [];++ for (const part of parts) {+ const scaleSamples = collectAnimatedScaleSamples(part, sequences);+ const finding = buildNonuniformParentScaleFinding(part, scaleSamples, {+ clipId: clip.id,+ clipName: clip.name || clip.id,+ });+ if (finding) addFinding(finding);+ }+if (remainingBudget <= 0) break;- const sequences = Array.isArray(clip.sequences) ? clip.sequences : [];const sampleTimes = new Set([0, clip.durationSeconds || 0]);for (const seq of sequences) {if (Number.isFinite(seq.startSeconds)) sampleTimes.add(seq.startSeconds);@@ -513,9 +623,13 @@ export function evaluateThreejsPhysicalAudit(spec) {export function buildThreejsPhysicalAuditFeedback(physicalAudit) {const actionable = (physicalAudit?.findings || []).filter((f) => f.severity === 'error' || f.severity === 'warning');if (actionable.length === 0) return '';+ const hasNonuniformParentScale = actionable.some((finding) => finding.code === 'nonuniform-parent-scale');return ['The previous pass failed physical conformance audits:',...actionable.map((finding, index) => `${index + 1}. ${finding.message}`),+ ...(hasNonuniformParentScale ? [+ 'For non-uniform parent scale findings, size each part through its own geometry dimensions (for example, box width/height/depth or sphere radius) and keep containers near-uniform instead of squashing a parent that owns other components.',+ ] : []),'Ensure every part is physically attached to a parent, sibling, or ground plane, keep geometry exposed rather than buried inside unrelated parts, avoid exact coplanar surfaces that cause flickering, and make animated parts emerge cleanly from parents or hidden containers.',].join('\n');}diff --git a/server/lib/threejsModelPhysicalAudit.test.js b/server/lib/threejsModelPhysicalAudit.test.jsindex 05b2bad55f..2ec7ae971f 100644--- a/server/lib/threejsModelPhysicalAudit.test.js+++ b/server/lib/threejsModelPhysicalAudit.test.js@@ -46,6 +46,117 @@ describe('threejsModelPhysicalAudit', () => {expect(buildThreejsPhysicalAuditFeedback(res)).toBe('');});+ it('flags non-uniform parent scale and names the affected non-relief descendants', () => {+ const spec = {+ name: 'Scaled Parent Spec',+ parts: [+ {+ id: 'torso',+ name: 'Torso',+ geometry: { type: 'box', width: 2, height: 1, depth: 1 },+ position: [0, 0.5, 0],+ scale: [3, 1, 0.2],+ children: [+ {+ id: 'head',+ name: 'Head',+ geometry: { type: 'sphere', radius: 0.5 },+ position: [0, 1, 0],+ },+ {+ id: 'panel_lines',+ name: 'Panel Lines',+ explodeWithParent: true,+ geometry: { type: 'box', width: 1, height: 0.01, depth: 0.01 },+ },+ ],+ },+ ],+ };++ const res = evaluateThreejsPhysicalAudit(spec);+ const finding = res.findings.find((item) => item.code === 'nonuniform-parent-scale');+ expect(finding).toMatchObject({+ severity: 'warning',+ partIds: ['torso', 'head'],+ affectedDescendantNames: ['Head'],+ anisotropyRatio: 15,+ scaleRange: { min: [3, 1, 0.2], max: [3, 1, 0.2] },+ });+ expect(finding.message).toContain('Torso');+ expect(finding.message).toContain('Head');+ expect(finding.message).toContain('anisotropy ratio 15.00');+ expect(buildThreejsPhysicalAuditFeedback(res)).toContain('box width/height/depth');+ });++ it('ignores relief-only children when a parent is deliberately non-uniform', () => {+ const res = evaluateThreejsPhysicalAudit({+ name: 'Relief Parent Spec',+ parts: [{+ id: 'blade',+ name: 'Blade',+ geometry: { type: 'box', width: 2, height: 0.2, depth: 1 },+ position: [0, 0.1, 0],+ scale: [4, 1, 0.5],+ children: [{+ id: 'serrations',+ name: 'Serrations',+ explodeWithParent: true,+ geometry: { type: 'box', width: 1, height: 0.1, depth: 0.1 },+ }],+ }],+ });++ expect(res.findings.filter((finding) => finding.code === 'nonuniform-parent-scale')).toHaveLength(0);+ });++ it('checks animated scale channel endpoints against nested parts', () => {+ const res = evaluateThreejsPhysicalAudit({+ name: 'Animated Scale Spec',+ parts: [{+ id: 'housing',+ name: 'Housing',+ geometry: { type: 'box', width: 2, height: 1, depth: 1 },+ position: [0, 0.5, 0],+ children: [{+ id: 'lens',+ name: 'Lens',+ geometry: { type: 'sphere', radius: 0.4 },+ position: [0, 0.8, 0],+ }],+ }],+ animation: {+ clips: [{+ id: 'deploy',+ name: 'Deploy',+ durationSeconds: 2,+ sequences: [{+ id: 'stretch-housing',+ name: 'Stretch housing',+ partId: 'housing',+ startSeconds: 0.5,+ endSeconds: 1.5,+ channels: {+ scale: { from: [1, 1, 1], to: [3, 1, 0.2] },+ },+ }],+ }],+ },+ });++ const finding = res.findings.find((item) => item.code === 'nonuniform-parent-scale');+ expect(finding).toMatchObject({+ clipId: 'deploy',+ sequenceId: 'stretch-housing',+ partIds: ['housing', 'lens'],+ affectedDescendantNames: ['Lens'],+ anisotropyRatio: 15,+ scaleRange: { min: [1, 1, 0.2], max: [3, 1, 1] },+ });+ expect(finding.message).toContain('Deploy');+ expect(finding.message).toContain('stretch-housing');+ });+it('detects floating part touching nothing', () => {const spec = {name: 'Floating Spec',diff --git a/server/services/threejsModels/prompt.js b/server/services/threejsModels/prompt.jsindex 149901f6fb..6abd4cc7fb 100644--- a/server/services/threejsModels/prompt.js+++ b/server/services/threejsModels/prompt.js@@ -104,6 +104,12 @@ at least 0.0001. Zero collapses the part to an invisible plane and a negative coreflects it; both are rejected. This format has no reflection and no hidden parts — builda mirrored counterpart as its own part with its own position and rotationDegrees, andsimply omit a part you do not want rendered.++A part's scale applies to its whole group and cascades to everything nested under it. Keep a+container part that owns other components near-uniformly scaled; author a part's proportions+through its own geometry dimensions (box width/height/depth, sphere radius, and equivalent+dimensions on other geometries) instead of using a non-uniform parent scale to shape its+children.`;const CHARACTER_FAMILY_ID = 'character';diff --git a/server/services/threejsModels/prompt.test.js b/server/services/threejsModels/prompt.test.jsindex 255f5c1cf0..1597dc7107 100644--- a/server/services/threejsModels/prompt.test.js+++ b/server/services/threejsModels/prompt.test.js@@ -19,6 +19,13 @@ describe('buildThreejsGenerationPrompt', () => {}});+ it('warns that non-uniform parent scale cascades to nested parts', () => {+ const prompt = build();+ expect(prompt).toContain("A part's scale applies to its whole group and cascades to everything nested under it");+ expect(prompt).toMatch(/Keep a\s+container part that owns other components near-uniformly scaled/);+ expect(prompt).toContain('box width/height/depth, sphere radius');+ });+it('gates on the model coming apart into readable components', () => {expect(build()).toContain('The model must come apart into readable components');});