Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Fix Difference Engine gear phasing and carry clearances
Yuechen Lic77e1b67bcf8
diff --git a/demos/Aetheris.DifferenceEngine.Showcase/PresentationManifest.cs b/demos/Aetheris.DifferenceEngine.Showcase/PresentationManifest.csindex e2555473..82528b1e 100644--- a/demos/Aetheris.DifferenceEngine.Showcase/PresentationManifest.cs+++ b/demos/Aetheris.DifferenceEngine.Showcase/PresentationManifest.cs@@ -7,7 +7,7 @@ using Aetheris.Kernel.Firmament.FirmamentV2;namespace Aetheris.DifferenceEngine.Showcase;public sealed record PresentationBinding(string OccurrenceId,string Kind,double[] Pivot,double Ratio,int Register,int Digit,string Role);-public sealed record PresentationGearLink(string A,string B,double Ratio,int TeethA,int TeethB,double CenterDistanceMm,string Interface);+public sealed record PresentationGearLink(string A,string B,double Ratio,int TeethA,int TeethB,double CenterDistanceMm,string Interface,double PhaseADegrees,double PhaseBDegrees);public sealed record ExplosionBinding(string OccurrenceId,double[] Offset);public sealed record DemonstrationState(int Result,int FirstDifference,int SecondDifference);public sealed record DemonstrationProgram(string Id,string Name,IReadOnlyList<DemonstrationState> States);@@ -27,7 +27,8 @@ public static class PresentationManifeststring Resolve(string id)=>localRoot is null?id:"assembly-instance:"+occurrencePath+id[("assembly-instance:"+localRoot).Length..];var a=Resolve(g.A.OccurrenceIdentity);var b=Resolve(g.B.OccurrenceIdentity);if(!byId.ContainsKey(a)||!byId.ContainsKey(b))throw new InvalidOperationException("presentation-gear-endpoint-missing");- links.Add(new(a,b,ratio*g.RotationSign,g.A.Teeth!.Value,g.B.Teeth!.Value,g.ActualCenterDistanceMm,mate.Name));+ double WorldPhase(string id,double phase) => phase+Math.Atan2(byId[id].Transform[1],byId[id].Transform[0])*180/Math.PI;+ links.Add(new(a,b,ratio*g.RotationSign,g.A.Teeth!.Value,g.B.Teeth!.Value,g.ActualCenterDistanceMm,mate.Name,WorldPhase(a,g.A.PhaseDegrees),WorldPhase(b,g.B.PhaseDegrees)));}foreach(var mate in ir.Mates)Add(mate);foreach(var definition in ir.AssemblyDefinitions!)foreach(var occurrence in ir.Instances.Where(i=>i.DefinitionIdentity==definition.DefinitionIdentity))diff --git a/demos/Aetheris.DifferenceEngine.Showcase/ShowcaseDesign.cs b/demos/Aetheris.DifferenceEngine.Showcase/ShowcaseDesign.csindex aed54cf8..b9e02c8e 100644--- a/demos/Aetheris.DifferenceEngine.Showcase/ShowcaseDesign.cs+++ b/demos/Aetheris.DifferenceEngine.Showcase/ShowcaseDesign.cs@@ -55,8 +55,8 @@ public sealed record ShowcaseDesign(double DigitPitch = 80)var pivotX=34-8*.24*double.Cos(double.Pi/12);var pivotY=-8*.24*double.Sin(double.Pi/12);var carry = Part("Pawl","CarryPawl",x:34,z:36,angle:double.Pi)+ Part("Pivot",Rod(2,33,44),pivotX,pivotY) + Part("PivotCollar",Ring(4,2.2,40,42),pivotX,pivotY)- + Part("Pedestal",StockAt(46,0,8,8,10,25))- + Part("Tongue",Box(22,10,3),39,0,33)+ + Part("Pedestal",StockAt(46,12,8,8,10,25))+ + Part("Tongue",Box(22,34,3),39,0,33)+ Part("Lever",Box(7,50,4),pivotX,20,42) + Part("LinkPin",Rod(2,44,59),pivotX,40)+ Part("ResetLink",Box(7,7,17),pivotX,40,59);Write("CarryVisualModule.firmament",stock+Module("CarryVisualModule",carry,"Pedestal.Joint","","Semantic Mount = Pedestal.Joint;"));@@ -71,15 +71,20 @@ public sealed record ShowcaseDesign(double DigitPitch = 80)digit += Part(name+"Tie",Rod(2.5,-20,62),0,y)+Part(name+"Cap",Ring(4.5,2.5,60,63),0,y);}var revolute="Interface<Revolute> DriveJournal { A: DigitModule.DriveGear.Joint; B: DigitModule.Bearing.Joint; }";+ // The middle register follows an odd number of external meshes. Phase only+ // its drive gears; supports, decimal wheels and carry parts retain their frames.+ var phasedDigit=digit.Replace(Part("DriveGear","RegisterDrive"),Part("DriveGear","RegisterDrivePhased"),StringComparison.Ordinal);Write("DigitModule.firmament","Include \"DigitWheel.firmament\";\nInclude \"CarryVisualModule.firmament\";\n"- +Module("DigitModule",digit,"Bearing.Joint",revolute,"Semantic Mount = Bearing.Joint; Gear Drive = DriveGear;"));+ +Module("DigitModule",digit,"Bearing.Joint",revolute,"Semantic Mount = Bearing.Joint; Gear Drive = DriveGear;")+ +Module("DigitModulePhased",phasedDigit,"Bearing.Joint",revolute.Replace("DigitModule.","DigitModulePhased.",StringComparison.Ordinal).Replace("DriveJournal {","DriveJournalPhased {",StringComparison.Ordinal),"Semantic Mount = Bearing.Joint; Gear Drive = DriveGear;"));var register = Part("Shaft",Rod(4,-20,ShaftTop-FirstLevel));var expose="Semantic Mount = Shaft.Joint;\n";for(var i=0;i<Digits;i++) {register+=Child("Digit"+i,"DigitModule",z:i*DigitPitch); expose+=$"Gear Drive{i} = Digit{i}.Drive;\n";}register+=Part("Crown",Ring(14,4,Top-FirstLevel-8,Top-FirstLevel))+Part("Foot",Ring(14,4,-20,-12))+Part("TopRetainer",Ring(8,4,GantryBottom+GantryThickness-FirstLevel,ShaftTop-FirstLevel));- Write("Register.firmament","Include \"DigitModule.firmament\";\n"+Module("Register",register,"Shaft.Joint","",expose));+ Write("Register.firmament","Include \"DigitModule.firmament\";\n"+Module("Register",register,"Shaft.Joint","",expose)+ +Module("RegisterPhased",register.Replace(" = DigitModule>"," = DigitModulePhased>",StringComparison.Ordinal),"Shaft.Joint","",expose));var transfer="";foreach(var (name,x) in new[]{("Input",44d),("Output",84d)}) {@@ -87,12 +92,20 @@ public sealed record ShowcaseDesign(double DigitPitch = 80)+Part(name+"Bearing",Ring(7,3.2,-12,-5),x)+Part(name+"Collar",Ring(6,3.2,8,11),x);}transfer+=Part("Bridge","DoubleBearingBridge<W: 56mm>")+Part("RearSupport",Box(12,60,6),64,30,-24);- Write("TransferModule.firmament",stock+Module("TransferModule",transfer,"Bridge.Joint",+ // TransferIdler's shared body has a 9-degree authored phase. Rotate one+ // occurrence another half tooth (9 degrees), giving alternating tooth/gap alignment.+ var transfer0=transfer.Replace(Part("OutputGear","TransferIdler",84),Part("OutputGear","TransferIdler",84,angle:double.Pi/20),StringComparison.Ordinal);+ var transfer1=transfer.Replace(Part("InputGear","TransferIdler",44),Part("InputGear","TransferIdler",44,angle:double.Pi/20),StringComparison.Ordinal);+ Write("TransferModule.firmament",stock+Module("TransferModule",transfer0,"Bridge.Joint","Interface<Gear> IdlerMesh { A: TransferModule.InputGear; B: TransferModule.OutputGear; }",+ "Semantic Mount = Bridge.Joint; Gear Input = InputGear; Gear Output = OutputGear;")+ +Module("TransferModulePhased",transfer1,"Bridge.Joint",+ "Interface<Gear> IdlerMeshPhased { A: TransferModulePhased.InputGear; B: TransferModulePhased.OutputGear; }","Semantic Mount = Bridge.Joint; Gear Input = InputGear; Gear Output = OutputGear;"));var bank="";var ports="";for(var i=0;i<Digits;i++){bank+=Child("Level"+i,"TransferModule",z:i*DigitPitch);ports+=$"Gear Input{i} = Level{i}.Input; Gear Output{i} = Level{i}.Output;\n";}- Write("TransferBank.firmament","Include \"TransferModule.firmament\";\n"+Module("TransferBank",bank,"Level0.Mount","",ports));+ Write("TransferBank.firmament","Include \"TransferModule.firmament\";\n"+Module("TransferBank",bank,"Level0.Mount","",ports)+ +Module("TransferBankPhased",bank.Replace(" = TransferModule>"," = TransferModulePhased>",StringComparison.Ordinal),"Level0.Mount","",ports));var gantrySeats=string.Join("\n",Enumerable.Range(0,3).Select(r=>$"Semantic GantrySeat{r} {{ DatumFrame Frame = [{N(r*RegisterPitch)},0,{N(GantryBottom)}] x [1,0,0] y [0,1,0] z [0,0,1]; }}"));var frame=Part("Plinth",StockAt(96,14,-36,484,188,16),semantics:gantrySeats)+Part("BaseDeck",Box(464,168,8),96,14,-20);@@ -123,8 +136,8 @@ public sealed record ShowcaseDesign(double DigitPitch = 80)var root=new StringBuilder("Units: mm\nInclude \"modules/Register.firmament\";\nInclude \"modules/TransferBank.firmament\";\nInclude \"modules/Frame.firmament\";\nInclude \"modules/CrankDrive.firmament\";\nAssembly DifferenceEngine {\n<Assembly DifferenceEngine>\n");root.Append(Child("Frame","FrameBay")); root.Append(Child("MainCrank","CrankDrive"));var names=new[]{"ResultRegister","FirstDifferenceRegister","SecondDifferenceRegister"};- for(var r=0;r<Registers;r++)root.Append(Child(names[r],"Register",r*RegisterPitch,0,FirstLevel));- for(var b=0;b<2;b++)root.Append(Child("Transfer"+b,"TransferBank",b*RegisterPitch,0,FirstLevel));+ for(var r=0;r<Registers;r++)root.Append(Child(names[r],r==1?"RegisterPhased":"Register",r*RegisterPitch,0,FirstLevel));+ for(var b=0;b<2;b++)root.Append(Child("Transfer"+b,b==1?"TransferBankPhased":"TransferBank",b*RegisterPitch,0,FirstLevel));root.AppendLine("</Assembly>\nAnchor: DifferenceEngine.Frame.Mount;");root.AppendLine("Interface<Gear> CrankInput { A: DifferenceEngine.MainCrank.Output; B: DifferenceEngine.ResultRegister.Drive0; }");for(var b=0;b<2;b++)for(var d=0;d<Digits;d++){diff --git a/demos/Aetheris.DifferenceEngine.Showcase/verify.mjs b/demos/Aetheris.DifferenceEngine.Showcase/verify.mjsindex 328f62de..3340b550 100644--- a/demos/Aetheris.DifferenceEngine.Showcase/verify.mjs+++ b/demos/Aetheris.DifferenceEngine.Showcase/verify.mjs@@ -20,9 +20,33 @@ const pulses=[0,1].map(d=>Array.from({length:1001},(_,i)=>({t:i/1000,p:evaluate(assert.ok(pulses[0]<pulses[1],'Units carry must precede tens carry');assert.deepEqual(evaluate(carry,0,1).values,[100,1,0]);const bindings=new Map(manifest.bindings.map(b=>[b.occurrenceId,b]));+const occurrences=new Map(mesh.occurrences.map(o=>[o.id,o]));for(const link of manifest.gearLinks){assert.ok(Math.abs(link.ratio+link.teethA/link.teethB)<1e-10);assert.ok(Math.abs(bindings.get(link.b).ratio-bindings.get(link.a).ratio*link.ratio)<1e-10);+ const a=occurrences.get(link.a).transform,b=occurrences.get(link.b).transform;+ const direction=Math.atan2(b[13]-a[13],b[12]-a[12])/(2*Math.PI);+ for(let sample=0;sample<=100;sample++){+ const turn=sample/100;+ const contact=(direction-link.phaseADegrees/360-turn*bindings.get(link.a).ratio)*link.teethA+ +(direction+.5-link.phaseBDegrees/360-turn*bindings.get(link.b).ratio)*link.teethB;+ assert.ok(Math.abs(contact-Math.floor(contact)-.5)<1e-6,'Tooth-to-gap phase: '+link.a+' / '+link.b);+ }+}+const definitions=new Map(mesh.definitions.map(d=>[d.id,d]));+function yBounds(path){+ const o=mesh.occurrences.find(o=>o.path===path),m=o.transform,p=definitions.get(o.definitionId).positions;+ let min=Infinity,max=-Infinity;+ for(let i=0;i<p.length;i+=3){const y=m[1]*p[i]+m[5]*p[i+1]+m[9]*p[i+2]+m[13];min=Math.min(min,y);max=Math.max(max,y);}+ return [min,max];+}+const collarClearances=[];+for(let bank=0;bank<2;bank++)for(let digit=0;digit<4;digit++){+ const register=['ResultRegister','FirstDifferenceRegister'][bank];+ const support=yBounds(`DifferenceEngine.${register}.Digit${digit}.Carry.Pedestal`);+ const collar=yBounds(`DifferenceEngine.Transfer${bank}.Level${digit}.InputCollar`);+ const gap=support[0]-collar[1];+ assert.ok(gap>=1-1e-8,'Carry support must clear the complete collar mesh');collarClearances.push(gap);}const offsets=hierarchyOffsets(mesh.occurrences,manifest.explosions);assert.deepEqual(offsets.get('assembly-instance:DifferenceEngine.ResultRegister.Digit0.Wheel.Drum'),[-90,0,-30]);@@ -40,4 +64,4 @@ for(const definition of mesh.definitions){}assert.ok(volume>0,'Positive oriented display volume: '+definition.identity);}-console.log(JSON.stringify({passed:true,transitions,gearLinks:manifest.gearLinks.length,carryPulseTimes:pulses,occurrences:bindings.size,gantryClearances:receipts.gantryClearances.map(c=>c.clearanceMm)}));+console.log(JSON.stringify({passed:true,transitions,gearLinks:manifest.gearLinks.length,gearPhaseSamples:101,collarClearances,carryPulseTimes:pulses,occurrences:bindings.size,gantryClearances:receipts.gantryClearances.map(c=>c.clearanceMm)}));diff --git a/docs/public/demos/difference-engine-showcase.md b/docs/public/demos/difference-engine-showcase.mdindex 44abc84a..6f05b790 100644--- a/docs/public/demos/difference-engine-showcase.md+++ b/docs/public/demos/difference-engine-showcase.md@@ -14,10 +14,12 @@ Presentation arithmetic is deliberately prescribed. Future contact, clutch, torq## Production assets-`Run.ps1 -NoServe` creates an ignored `dist/` with relative URLs, local Three.js dependencies and its license, complete STEP, shared meshes and presentation manifest. Serve that directory with `serve.py` for the local production test. The checked-in `wrangler.jsonc` names the static asset directory for a future Cloudflare Workers deployment; deployment requires a separate explicit request. No worker backend, account registration or deployment is performed.+`Run.ps1 -NoServe` creates an ignored `dist/` with relative URLs, local Three.js dependencies and its license, complete STEP, shared meshes and presentation manifest. Serve that directory with `serve.py` for the local production test. The checked-in `wrangler.jsonc` names the static asset directory for the [public Cloudflare showcase](https://aetheris-difference-engine-showcase.yuechenli.workers.dev/). Generation itself does not deploy or create a backend.The hero preview is captured from the real browser into `dist/preview.png` during visual review. On later regeneration `Prepare-Viewer.ps1` reuses `review/assembly-hero.png` if present; regenerate that capture when the design changes. Do not substitute synthetic machine geometry or an AI image.## Authoring findings+The transfer train alternates tooth-to-gap phases across all three registers: 20-tooth idlers differ by 9 degrees, and the middle register uses a 7.5-degree phased 24-tooth drive definition. Phasing belongs to the exported CAD rest assembly, so playback and STEP agree. The carry pedestals are offset 12 mm sideways with extended connecting plates, leaving 1 mm between each affected support and its idler collar. `verify.mjs` checks all 26 gear pairs at 101 rotation samples and all eight collar clearances against exported mesh bounds. These checks address the visible clashes, not full mechanism/contact qualification.+Nested reusable assemblies must retain parent-relative local transforms. Reapplying definition-root transforms at each nested level doubles offsets; the canonical nested-occurrence witness covers a translated and rotated hierarchy and checks mesh/STEP realization. Anchor-owner parts should be authored at the module origin; a semantic datum alone does not relocate the solver's anchor owner. Positioned stock templates keep offset geometry explicit while the anchor occurrence remains at zero. Extrusion bounds use explicit `Zlow`/`Zhigh` parameters in this bounded author.diff --git a/fixtures/DifferenceEngine/parts/Showcase.firmament b/fixtures/DifferenceEngine/parts/Showcase.firmamentindex d9f5412c..f5ec8152 100644--- a/fixtures/DifferenceEngine/parts/Showcase.firmament+++ b/fixtures/DifferenceEngine/parts/Showcase.firmament@@ -33,6 +33,7 @@ Template < W: Length > Struct DoubleBearingBridge {}}SpurGear RegisterDrive { Module: 2mm Teeth: 24 PressureAngle: 20deg FaceWidth: 7mm BoreDiameter: 8.8mm Backlash: 0.15mm Phase: 0deg }+SpurGear RegisterDrivePhased { Module: 2mm Teeth: 24 PressureAngle: 20deg FaceWidth: 7mm BoreDiameter: 8.8mm Backlash: 0.15mm Phase: 7.5deg }SpurGear TransferIdler { Module: 2mm Teeth: 20 PressureAngle: 20deg FaceWidth: 7mm BoreDiameter: 6.6mm Backlash: 0.15mm Phase: 9deg }RatchetGear DecimalRatchet { Teeth: 20 OutsideDiameter: 52mm FaceWidth: 5mm BoreDiameter: 8.8mm DriveFaceAngle: 0deg Phase: 0deg }Pawl CarryPawl { Width: 8mm Length: 22mm Thickness: 4mm PivotDiameter: 4.4mm NoseLength: 4mm EngagementAngle: 15deg }