diff --git a/CHANGELOG-next.md b/CHANGELOG-next.md index 8d901d4..a2d84a0 100644 --- a/CHANGELOG-next.md +++ b/CHANGELOG-next.md @@ -1,3 +1,17 @@ +## Additional354 candidate: aquatic foreground occlusion + +- Fish Tank (including Saltwater Coral Reef), Physics Aquarium and Ocean reef now suppress the complete underwater scene on current foreground outlines, with ring holes kept open. Fish Tank movement avoids those silhouettes instead of swimming across them. +- Source-bound authored-photo depth, only when the existing receipt and coordinate checks pass, adjusts underwater lighting. No raw depth file is used by these three effects. +- This is outline occlusion and relative depth lighting, NOT metric 3D fish placement. It cannot remove light from objects whose outlines are missing or wrong. No physical-room acceptance claimed until a native run verifies it. + +## 0.98.354-experimental1: current-outline library pictures + +- Library assignment pictures and effect-browser pictures use an immutable snapshot of current authored outlines, not the fixed sample shelf/frame/cabinet room. +- Thumbnail keys include all serialized surface fields and authoring dimensions, so edits, additions, removals and metadata changes cannot reuse an old room picture. +- Selected idea scenes build against that same private outline snapshot. Rendering is isolated from the live player's physics, camera, audio and calibrated projector transforms. +- These pictures are photo-coordinate illustrations, not measured projector output. They do not prove a fix for a separate projector-output stale-outline case. Native Windows/UI/projector execution not tested here. +- Dual-camera first-pattern timeout remains unresolved. No measured calibration or depth binding rewritten.353 is the rollback target after publication. + # Next candidate after experimental 315 - Removed the repeating unfinished moving-light effects dialog at startup. Its caveat is in What's new and these release notes instead. diff --git a/aquatic_room354.go b/aquatic_room354.go new file mode 100644 index 0000000..e8667f1 --- /dev/null +++ b/aquatic_room354.go @@ -0,0 +1,115 @@ +package main + +import "math" + +// Aquatic effects live in authored-photo coordinates. Foreground outlines are +// conservative occluders, not invented metric volumes. Bound photo depth may +// change underwater lighting; virtual fish z is never compared to room metres. +type aquaticRoomField354 struct { + w, h int + dom [4]float64 + blocked []bool + gain []float32 + head *plan + depth *depthMap +} + +func aquaticRoomID354(id string) bool { + return id == fishTankID || id == "phys:aquarium" || id == "phys:ocean" +} +func buildAquaticRoomField354(outlines []physOutline, dom [4]float64, w, h int, dm *depthMap) *aquaticRoomField354 { + if w < 1 || h < 1 || w > 2048 || h > 2048 { + return nil + } + f := &aquaticRoomField354{w: w, h: h, dom: dom, blocked: make([]bool, w*h), gain: make([]float32, w*h), depth: dm} + // Raster only each outline's bounds. Cost is bounded by covered areas, + // not every room pixel multiplied by every outline. + outlines = modelRingOutlines(outlines) + dw, dh := dom[2]-dom[0], dom[3]-dom[1] + if dw <= 0 || dh <= 0 { + return nil + } + for _, o := range outlines { + if len(o.poly) < 3 { + continue + } + bb := physPolyBox(o.poly) + x0, x1 := clampi(int(math.Floor((bb[0]-dom[0])/dw*float64(w))), 0, w), clampi(int(math.Ceil((bb[2]-dom[0])/dw*float64(w))), 0, w) + y0, y1 := clampi(int(math.Floor((bb[1]-dom[1])/dh*float64(h))), 0, h), clampi(int(math.Ceil((bb[3]-dom[1])/dh*float64(h))), 0, h) + for y := y0; y < y1; y++ { + sy := dom[1] + (float64(y)+.5)/float64(h)*dh + for x := x0; x < x1; x++ { + sx := dom[0] + (float64(x)+.5)/float64(w)*dw + if modelOutlineContains(o, sx, sy) { + f.blocked[y*w+x] = true + } + } + } + } + for y := 0; y < h; y++ { + sy := dom[1] + (float64(y)+.5)/float64(h)*dh + for x := 0; x < w; x++ { + sx := dom[0] + (float64(x)+.5)/float64(w)*dw + i := y*w + x + f.gain[i] = 1 + if dm != nil && !f.blocked[i] { + _, nx, ny, nz, ok := dm.NormalAtOK(sx, sy) + if ok && !math.IsNaN(nx+ny+nz) && !math.IsInf(nx+ny+nz, 0) { + f.gain[i] = float32(.72 + .28*math.Max(0, math.Min(1, -nx*.35-ny*.35+nz*.8))) + } + } + } + } + return f +} +func (f *aquaticRoomField354) at(sx, sy float64) (bool, float32) { + if f == nil || f.w < 1 || f.h < 1 || f.dom[2] <= f.dom[0] || f.dom[3] <= f.dom[1] { + return false, 1 + } + u, v := (sx-f.dom[0])/(f.dom[2]-f.dom[0]), (sy-f.dom[1])/(f.dom[3]-f.dom[1]) + if math.IsNaN(u+v) || math.IsInf(u+v, 0) || u < 0 || v < 0 || u >= 1 || v >= 1 { + return false, 1 + } + i := int(v*float64(f.h))*f.w + int(u*float64(f.w)) + return f.blocked[i], f.gain[i] +} +func (f *aquaticRoomField354) apply(out []float32) { + if f == nil || len(out) != f.w*f.h*4 { + return + } + for i, blocked := range f.blocked { + o := i * 4 + if blocked { + out[o], out[o+1], out[o+2], out[o+3] = 0, 0, 0, 0 + } else { + g := f.gain[i] + out[o] *= g + out[o+1] *= g + out[o+2] *= g + } + } +} +func (e *physEngine) aquaticBind354(plans []*plan, dm *depthMap) { + if !aquaticRoomID354(e.kind.id) || len(plans) == 0 { + return + } + if f := e.aquaticRoom354; f != nil && f.head == plans[0] && f.w == e.fw && f.h == e.fh && f.depth == dm { + return + } + outlines := physOutlinesOf(plans, nil) + f := buildAquaticRoomField354(outlines, [4]float64{e.g.dx0, e.g.dy0, e.g.dx1, e.g.dy1}, e.fw, e.fh, dm) + if f != nil { + f.head = plans[0] + } + e.aquaticRoom354 = f + e.dirty = true +} +func (s *fishTank) roomBlocked354(u, v float64) bool { + if s.room354 == nil { + return false + } + x := s.tankW[0] + u*(s.tankW[2]-s.tankW[0]) + y := s.tankW[1] + v*(s.tankW[3]-s.tankW[1]) + b, _ := s.room354.at(x, y) + return b +} diff --git a/aquatic_room354_test.go b/aquatic_room354_test.go new file mode 100644 index 0000000..c6eed15 --- /dev/null +++ b/aquatic_room354_test.go @@ -0,0 +1,85 @@ +package main + +import ( + "math" + "testing" +) + +func aquaticL354() physOutline { + return physOutline{id: "piano", cls: "piano", poly: [][2]float64{{.1, .1}, {.4, .1}, {.4, .5}, {.8, .5}, {.8, .8}, {.1, .8}}} +} +func Test354AquaticExactContourAndBlack(t *testing.T) { + f := buildAquaticRoomField354([]physOutline{aquaticL354()}, [4]float64{0, 0, 1, 1}, 100, 100, nil) + for _, v := range []struct { + x, y float64 + want bool + }{{.2, .2, true}, {.6, .2, false}, {.6, .6, true}, {.9, .9, false}} { + got, g := f.at(v.x, v.y) + if got != v.want || g != 1 { + t.Fatal(v, got, g) + } + } + out := make([]float32, 100*100*4) + for i := range out { + out[i] = .5 + } + f.apply(out) + if out[(20*100+20)*4] != 0 || out[(20*100+20)*4+3] != 0 || out[(20*100+60)*4] != .5 { + t.Fatal("foreground wash or bbox cut") + } + black := make([]float32, len(out)) + f.apply(black) + for _, x := range black { + if x != 0 { + t.Fatal("black was lifted") + } + } +} +func Test354AquaticRingsAndMovedOutlines(t *testing.T) { + o := physOutline{id: "art", poly: [][2]float64{{.1, .1}, {.9, .1}, {.9, .9}, {.1, .9}}, rings: []MaskRing{{Outer: [][2]float64{{.1, .1}, {.9, .1}, {.9, .9}, {.1, .9}}, Holes: [][][2]float64{{{.4, .4}, {.6, .4}, {.6, .6}, {.4, .6}}}}}} + a := buildAquaticRoomField354([]physOutline{o}, [4]float64{0, 0, 1, 1}, 100, 100, nil) + if b, _ := a.at(.5, .5); b { + t.Fatal("hole filled") + } + if b, _ := a.at(.2, .2); !b { + t.Fatal("ring missing") + } + b := buildAquaticRoomField354(nil, [4]float64{0, 0, 1, 1}, 100, 100, nil) + if b.blocked[20*100+20] { + t.Fatal("removed outline persists") + } + if b, g := a.at(math.NaN(), .5); b || g != 1 { + t.Fatal("invalid coordinate") + } +} +func Test354AquaticDepthNeutralityAndPhotoCoordinates(t *testing.T) { + dm := &depthMap{W: 4, H: 4, V: make([]float32, 16), Valid: make([]bool, 16)} + for i := range dm.V { + dm.V[i] = .4 + } // invalid values abstain + f := buildAquaticRoomField354(nil, [4]float64{.4, .2, .8, .6}, 40, 40, dm) + for _, g := range f.gain { + if g != 1 { + t.Fatal("missing depth changed output") + } + } + o := physOutline{poly: [][2]float64{{.5, .3}, {.6, .3}, {.6, .4}, {.5, .4}}} + f = buildAquaticRoomField354([]physOutline{o}, [4]float64{.4, .2, .8, .6}, 40, 40, nil) + if b, _ := f.at(.55, .35); !b { + t.Fatal("domain treated as full frame") + } + s := &fishTank{room354: f, tankW: [4]float64{.4, .2, .8, .6}} + if !s.roomBlocked354(.375, .375) || s.roomBlocked354(.9, .9) { + t.Fatal("tank to photo coordinate binding") + } +} +func Test354AquaticScope(t *testing.T) { + for _, id := range []string{fishTankID, "phys:aquarium", "phys:ocean"} { + if !aquaticRoomID354(id) { + t.Fatal(id) + } + } + if aquaticRoomID354("phys:water") || aquaticRoomID354("m-fire") { + t.Fatal("unrelated effect altered") + } +} diff --git a/common.go b/common.go index 721eb6e..9142223 100644 --- a/common.go +++ b/common.go @@ -11,7 +11,7 @@ import ( "time" ) -const version = "0.98.353-experimental1" +const version = "0.98.354-experimental1" const appDisplayName = "Projection Mapper - Built by Instinct" diff --git a/effect_browser_windows.go b/effect_browser_windows.go index d56b59d..e0d4acd 100644 --- a/effect_browser_windows.go +++ b/effect_browser_windows.go @@ -6,7 +6,6 @@ import ( "strings" "sync" "syscall" - "time" "unsafe" ) @@ -280,7 +279,11 @@ var browserThumbSlots = make(chan struct{}, 1) func (a *app) browserThumb(id string) *Frame { if a==nil||a.pl==nil||a.pl.R==nil||pickerFavorite331(id){return nil} - key := id + a.pl.mu.Lock() + snap,geometryKey:=libraryOutlineSnapshotFor354(a.pl.P) + a.pl.mu.Unlock() + if geometryKey==""{return nil} + key:=geometryKey+"|"+id if strings.HasPrefix(id, "video:") { key = a.pl.R.ContentDir + "|" + id } @@ -316,7 +319,7 @@ func (a *app) browserThumb(id string) *Frame { } pInvalidateRect.Call(hwnd, 0, 0) }() - f := renderBrowserThumb(renderer, id) + f := renderBrowserOutlineThumb354(renderer,snap,id) browserThumbCache.Lock() if len(browserThumbCache.frames) >= 192 { browserThumbCache.frames = map[string]*Frame{} @@ -326,51 +329,14 @@ func (a *app) browserThumb(id string) *Frame { }() return nil } -func renderBrowserThumb(renderer *Renderer, id string) *Frame { +func renderBrowserOutlineThumb354(renderer *Renderer,snap libraryOutlineSnapshot354,id string)*Frame { if pickerFavorite331(id){return nil} - var f *Frame - if it,_,ok:=(&app{}).presetLookup326(id);ok {if as,ok:=presetAssign326(it);ok{return renderLibraryAssignSample(as)}} - if strings.HasPrefix(id, "idea:") { - p, sc, ok := ideaSampleScene(id) - if !ok { - return nil - } - r := newRenderer(p, "") - r.exportVirtual = true - f = newFrame(160, 90) - for j := 0; j <= 12; j++ { - r.RenderScene(&sc, float64(j)*.1, f, 1, time.Time{}) - } - } - - if f != nil { - } else if strings.HasPrefix(id, "video:") { - f = renderer.vidThumb(strings.TrimPrefix(id, "video:"), 160, 90) - if f == nil { - return nil - } - } else if kind, ok := physKindOf(id); ok { - cfg := physResolve(kind, nil, rgb{1, 1, 1}, rgb{}, 1) - outlines := []physOutline{{id: "sample-shelf", poly: [][2]float64{{.25, .5}, {.65, .5}, {.65, .55}, {.25, .55}}}, {id: "sample-frame", poly: [][2]float64{{.1, .18}, {.3, .18}, {.3, .4}, {.1, .4}}}, {id: "sample-cabinet", poly: [][2]float64{{.7, .65}, {.95, .65}, {.95, .95}, {.7, .95}}}} - g := physBuildGrid(outlines, [4]float64{0, 0, 1, 1}, 16.0/9, 96, cfg.boxes, nil, "", nil) - e := newPhysEngine(kind, cfg, g) - defer physStopSim(e.sim) - e.exportMode = true - e.stepN(90) - e.render() - f = newFrame(160, 90) - for y := 0; y < 90; y++ { - for x := 0; x < 160; x++ { - c, alpha := e.sample((float64(x)+.5)/160, (float64(y)+.5)/90) - i := (y*160 + x) * 4 - f.Pix[i], f.Pix[i+1], f.Pix[i+2], f.Pix[i+3] = to8(c.b*alpha), to8(c.g*alpha), to8(c.r*alpha), 255 - } - } - } - if f == nil { - f = fxThumb(id, "#ffffff", 160, 90) - } - return f + if strings.HasPrefix(id,"video:"){return renderer.vidThumb(strings.TrimPrefix(id,"video:"),160,90)} + if it,_,ok:=(&app{}).presetLookup326(id);ok{if as,ok:=presetAssign326(it);ok{return renderLibraryOutlineAssign354(snap,as)}} + if strings.HasPrefix(id,"idea:"){ + p,sc,ok:=ideaSceneOnProject354(id,snap.project());if !ok{return nil};return renderLibraryOutlineScene354(p,sc) + } + return renderLibraryOutlineAssign354(snap,Assign{Type:"fx",ID:id,C1:"#ffffff",C2:"#000000",Scale:1,Speed:1,Inten:1,Phys:&PhysParams{Shared:true}}) } func (a *app) favoriteStep(d int) { diff --git a/fishtank.go b/fishtank.go index 8c8bc87..8e1f44e 100644 --- a/fishtank.go +++ b/fishtank.go @@ -337,6 +337,7 @@ type ftFlake struct{ x, y, vx, vy, life float64 } type ftBubble struct{ x, y, r, ph, vy float64 } type fishTank struct { + room354 *aquaticRoomField354 live hxLiveQ set fishTankSettings specs []ftSpec @@ -376,7 +377,8 @@ func (s *fishTank) reset(e *physEngine) { if g.w > 0 && g.h > 0 && g.dx1 > g.dx0 && g.dy1 > g.dy0 { aspect = float64(g.w) / float64(g.h) * (g.dy1 - g.dy0) / (g.dx1 - g.dx0) } - s.tankW, _ = fishTankLayout(g.src, aspect, s.set) + s.room354=e.aquaticRoom354 + s.tankW, _ = fishTankLayout(g.src, aspect, s.set) if s.tankW == [4]float64{} { s.tw = 0 s.th = 0 @@ -619,6 +621,11 @@ func (s *fishTank) stepFish(dt float64) { } } } + // Geometry may have changed after spawning. Rehome a fish trapped in a + // newly authored foreground outline into observed open water, bounded tries. + if s.roomBlocked354(f.x,f.y){ + for trial:=0;trial<24;trial++{x,y:=s.rnd.rng(.06,.94),s.rnd.rng(sp.yMin,sp.yMax);if !s.roomBlocked354(x,y){f.x,f.y=x,y;break}} + } // Depth band + walls: soft springs, hard stop at the glass. if f.y < sp.yMin { ay += (sp.yMin - f.y) * 3 @@ -645,8 +652,12 @@ func (s *fishTank) stepFish(dt float64) { if sp2 < speed*0.3 && f.pause <= 0 { f.vx += f.dir * speed * 0.3 * dt * 4 } - f.x += f.vx * dt - f.y += f.vy * dt + nx,ny:=f.x+f.vx*dt,f.y+f.vy*dt + if s.roomBlocked354(nx,ny){ + // Slide round foreground silhouettes rather than drawing over them. + if !s.roomBlocked354(nx,f.y){f.x=nx;f.vy=-f.vy}else if !s.roomBlocked354(f.x,ny){f.y=ny;f.vx=-f.vx}else{f.vx=-f.vx;f.vy=-f.vy} + f.wx,f.wy=s.rnd.rng(.06,.94),s.rnd.rng(sp.yMin,sp.yMax) + }else{f.x,f.y=nx,ny} f.x = math.Max(0.01, math.Min(0.99, f.x)) f.y = math.Max(ftSurface+0.02, math.Min(0.92, f.y)) f.z += math.Sin(s.t*0.1+float64(i)) * dt * 0.01 diff --git a/fishtank_ui_win.go b/fishtank_ui_win.go index 9138b90..38d752c 100644 --- a/fishtank_ui_win.go +++ b/fishtank_ui_win.go @@ -165,7 +165,7 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { Title: "Fish Tank", Subtitle: "Realistic 3D-lit aquarium with sub-frame swimming, Beer-Lambert depth absorption, overhead caustics, and swaying plants.", SubtitleH: 42, - Sensing: "ObjectIQ Furniture Placement + Wall Aspect", + Sensing: "Current Outline Occlusion + Furniture Placement + Source-Bound Depth Lighting", Selected: tankName, Status: status, }) @@ -198,7 +198,7 @@ func (a *app) fishTankLayout(add func(widget) int, rx, rw, y, bh, pad int) { } add(widget{kind: kBtn, id: idFtLight, text: light, l: x0, t: by, r: rx + rw - sc(16), b: by + bh, enabled: true}) by += bh + sc(8) - txt := "Tank width is a share of the wall; height keeps a real 2:1 tank shape. Automatic and left/right placement stand it on the widest supported outline, including couches. Seating-only never substitutes a table or other object. This uses mapped outline geometry, not measured physical depth." + txt := "Tank width is a share of the wall; height keeps a real 2:1 tank shape. Automatic and left/right placement stand it on the widest supported outline, including couches. Seating-only never substitutes a table or other object. Current foreground outlines stay dark and fish avoid their silhouettes. Verified source-bound room depth can shade the water; fish z remains virtual tank depth, not metric room placement." if status != "" { txt += " • " + status } diff --git a/fxphys.go b/fxphys.go index f46a9cd..795a7f6 100644 --- a/fxphys.go +++ b/fxphys.go @@ -214,6 +214,7 @@ func (r *physRand) f() float64 { return float64(r.next()>>11) / (1 << 53) } func (r *physRand) rng(a, b float64) float64 { return a + (b-a)*r.f() } type physEngine struct { + aquaticRoom354 *aquaticRoomField354 materialFrame PBRFrameBuffer materialRGB [][3]float32 mu sync.Mutex @@ -325,6 +326,7 @@ func (e *physEngine) render() { e.dirty = false clear(e.back) e.sim.shade(e) + if e.aquaticRoom354!=nil{e.aquaticRoom354.apply(e.back)} if e.cfg.cpuMaterial { e.applyCPUMaterial() } @@ -332,6 +334,7 @@ func (e *physEngine) render() { } func (e *physEngine) sample(sx, sy float64) (rgb, float32) { + if e.aquaticRoom354!=nil{if b,_:=e.aquaticRoom354.at(sx,sy);b{return rgb{},0}} g := e.g fx := (sx-g.dx0)/(g.dx1-g.dx0)*float64(e.fw) - 0.5 fy := (sy-g.dy0)/(g.dy1-g.dy0)*float64(e.fh) - 0.5 @@ -729,7 +732,7 @@ func (r *Renderer) physFieldFor(sc *Scene, pl *plan, as Assign, plans []*plan, t e.layout = hark10LayoutFor(pl, plans, fw, fh) if strings.HasPrefix(kind.id,"phys:ag-") { e.layout = agAuthoredLayout323(r.P,pl,shared) } } - if r.P != nil && r.P.Depth != nil && r.P.Depth.File != "" { + if !aquaticRoomID354(kind.id) && r.P != nil && r.P.Depth != nil && r.P.Depth.File != "" { if dm, err := getDepthMap(r.P.Depth.File); err == nil { e.depth = dm // measured room depth (normalized 0..1); sims that use it must document unit handling } diff --git a/idea_favorites_windows.go b/idea_favorites_windows.go index eb03f9e..d9e7539 100644 --- a/idea_favorites_windows.go +++ b/idea_favorites_windows.go @@ -143,6 +143,9 @@ func ideaSampleScene(key string) (*Project, Scene, bool) { p.Surfaces = append(p.Surfaces, Surface{ID: cls, Name: cls, Cls: cls, Poly: [][2]float64{{x, y}, {x + .19, y}, {x + .19, y + .32}, {x, y + .32}}}) } p.Scene.W, p.Scene.H = 160, 90 + return ideaSceneOnProject354(key,p) +} +func ideaSceneOnProject354(key string,p *Project)(*Project,Scene,bool){ for _, it := range favoriteIdeas() { if it.key != key { continue diff --git a/library_outline354.go b/library_outline354.go new file mode 100644 index 0000000..9dfd159 --- /dev/null +++ b/library_outline354.go @@ -0,0 +1,84 @@ +package main + +import ( + "crypto/sha256" + "encoding/hex" + "encoding/json" + "time" +) + +// This is a private photo-coordinate illustration of the current authored +// outlines, never a calibrated projector frame. No live player or sensor is used. +type libraryOutlineSnapshot354 struct { + Surfaces []Surface `json:"surfaces"` + Scene [2]int `json:"scene"` +} + +func libraryOutlineSnapshotFor354(p *Project) (libraryOutlineSnapshot354, string) { + if p == nil { + return libraryOutlineSnapshot354{}, "" + } + raw, err := json.Marshal(libraryOutlineSnapshot354{Surfaces: p.Surfaces, Scene: [2]int{p.Scene.W, p.Scene.H}}) + if err != nil { + return libraryOutlineSnapshot354{}, "" + } + var snap libraryOutlineSnapshot354 + if json.Unmarshal(raw, &snap) != nil { + return libraryOutlineSnapshot354{}, "" + } + digest := sha256.Sum256(raw) + return snap, hex.EncodeToString(digest[:]) +} +func (s libraryOutlineSnapshot354) project() *Project { + p := &Project{Surfaces: append([]Surface(nil), s.Surfaces...), Map: MapCfg{Mode: "identity", ProjRes: [2]int{320, 180}}, Output: Output{Brightness: 1, Gamma: 1}} + p.Scene.W, p.Scene.H = s.Scene[0], s.Scene[1] + if p.Scene.W < 1 || p.Scene.H < 1 { + p.Scene.W, p.Scene.H = 320, 180 + } + // Only the private copy loses projector transforms. Keeping them here would + // draw a measured-projector LUT in the photo-coordinate thumbnail. + for i := range p.Surfaces { + sf := &p.Surfaces[i] + sf.Cal = nil + sf.SceneCorr = nil + sf.T3 = nil + sf.T3GLB = nil + sf.Mapping = "" + sf.T3Relief = "" + sf.T3Even = false + } + return p +} +func libraryOutlineAssignScene354(p *Project, as Assign) Scene { + sc := Scene{ID: "local-current-outlines354", Duration: 3600, Assign: map[string]Assign{}} + for _, sf := range p.Surfaces { + if sf.visible() && !sf.Occluder { + sc.Assign[sf.ID] = as + } + } + return sc +} +func renderLibraryOutlineScene354(p *Project, sc Scene) *Frame { + if p == nil || len(sc.Assign) == 0 { + return nil + } + sc.FadeIn, sc.FadeOut = 0, 0 + r := newRenderer(p, "") + r.exportVirtual = true + r.directorIsolatedHub = &physHub{owner: r, eng: map[string]*physEngine{}} + defer func() { + for _, e := range r.directorIsolatedHub.eng { + physStopSim(e.sim) + } + r.closeVideoResources() + }() + f := newFrame(320, 180) + for i := 0; i <= 12; i++ { + r.RenderScene(&sc, float64(i)*.275, f, 1, time.Time{}) + } + return f +} +func renderLibraryOutlineAssign354(s libraryOutlineSnapshot354, as Assign) *Frame { + p := s.project() + return renderLibraryOutlineScene354(p, libraryOutlineAssignScene354(p, as)) +} diff --git a/library_outline354_test.go b/library_outline354_test.go new file mode 100644 index 0000000..bd2b5c1 --- /dev/null +++ b/library_outline354_test.go @@ -0,0 +1,102 @@ +package main + +import ( + "bytes" + "encoding/json" + "math" + "testing" +) + +func outlineFixture354() *Project { + p := &Project{Surfaces: []Surface{{ID: "new-shape", Cls: "shelf", Poly: [][2]float64{{.1, .1}, {.4, .1}, {.4, .5}, {.1, .5}}, Quad: [][2]float64{{.1, .1}, {.4, .1}, {.4, .5}, {.1, .5}}, Read: &ObjRead{Material: "wood"}}}} + p.Scene.W, p.Scene.H = 640, 480 + return p +} +func Test354OutlineSnapshotTracksGeometryAndMetadata(t *testing.T) { + p := outlineFixture354() + s, k := libraryOutlineSnapshotFor354(p) + if k == "" || len(s.Surfaces) != 1 { + t.Fatal("missing snapshot") + } + p.Surfaces[0].Poly[0][0] = .7 + _, changed := libraryOutlineSnapshotFor354(p) + if changed == k || s.Surfaces[0].Poly[0][0] != .1 { + t.Fatal("stale key or live polygon alias") + } + p.Surfaces[0].Read.Material = "glass" + if s.Surfaces[0].Read.Material != "wood" { + t.Fatal("nested live alias") + } + _, metadata := libraryOutlineSnapshotFor354(p) + if metadata == changed { + t.Fatal("metadata not keyed") + } + p.Surfaces = append(p.Surfaces, Surface{ID: "added"}) + _, added := libraryOutlineSnapshotFor354(p) + if added == metadata { + t.Fatal("added surface not keyed") + } + p.Scene.W++ + _, aspect := libraryOutlineSnapshotFor354(p) + if aspect == added { + t.Fatal("authoring dimensions not keyed") + } +} +func Test354OutlineSnapshotFailsClosed(t *testing.T) { + if _, key := libraryOutlineSnapshotFor354(nil); key != "" { + t.Fatal("nil accepted") + } + p := outlineFixture354() + p.Surfaces[0].Poly[0][0] = math.NaN() + if _, key := libraryOutlineSnapshotFor354(p); key != "" { + t.Fatal("invalid geometry accepted") + } +} +func Test354OutlineSceneUsesCurrentMembership(t *testing.T) { + p := outlineFixture354() + no := false + p.Surfaces = append(p.Surfaces, Surface{ID: "cut", Occluder: true}, Surface{ID: "hidden", Visible: &no}, Surface{ID: "latest"}) + before, _ := json.Marshal(p) + snap, _ := libraryOutlineSnapshotFor354(p) + own := snap.project() + sc := libraryOutlineAssignScene354(own, Assign{Type: "fx", ID: "m-fire", Scale: 1, Speed: 1, Inten: 1}) + if len(sc.Assign) != 2 || sc.Assign["latest"].ID != "m-fire" { + t.Fatal("current membership lost") + } + if _, ok := sc.Assign["sample-shelf"]; ok { + t.Fatal("synthetic room leaked") + } + after, _ := json.Marshal(p) + if !bytes.Equal(before, after) { + t.Fatal("live project changed") + } + if own.Map.Mode != "identity" || own.Scene.W != 640 || own.Scene.H != 480 { + t.Fatal("photo coordinate source lost") + } +} + +// Runs only with the complete native application test suite. Portable extracted +// tests do not replace this pixel regression or native projector acceptance. +func Test354ActualOutlinePixelsMoveWithCurrentShape(t *testing.T) { + p := outlineFixture354() + snap, _ := libraryOutlineSnapshotFor354(p) + as := Assign{Type: "fx", ID: "m-fire", C1: "#ff8800", C2: "#000000", Scale: 1, Speed: 1, Inten: 1} + a := renderLibraryOutlineAssign354(snap, as) + for j := range p.Surfaces[0].Poly { + p.Surfaces[0].Poly[j][0] += .45 + p.Surfaces[0].Quad[j][0] += .45 + } + next, _ := libraryOutlineSnapshotFor354(p) + b := renderLibraryOutlineAssign354(next, as) + if a == nil || b == nil || bytes.Equal(a.Pix, b.Pix) { + t.Fatal("actual pixels ignored moved outlines") + } + for y := 25; y < 80; y++ { + for x := 36; x < 95; x++ { + i := (y*b.W + x) * 4 + if b.Pix[i]|b.Pix[i+1]|b.Pix[i+2] != 0 { + t.Fatal("old outline still lit", x, y) + } + } + } +} diff --git a/library_preview_windows.go b/library_preview_windows.go index db4ea43..3b2dca8 100644 --- a/library_preview_windows.go +++ b/library_preview_windows.go @@ -177,20 +177,20 @@ func (a *app) librarySample() (string, string, *Frame) { as := agAssign(es[clampi(agUI.sel, 0, len(es)-1)]) name := es[clampi(agUI.sel, 0, len(es)-1)].Name agUI.mu.Unlock() - return name, "Selected settings on a sample room. No measured depth or physical fit.", a.libraryAssignSample(as) + return name, "Current outlines in photo coordinates. Not calibrated projector output.", a.libraryAssignSample(as) } agUI.mu.Unlock() case bugsimPageIdx: as := a.bugsimHooks().assign() - return a.bugsimHooks().name(), "Selected settings on a sample room. Real projector fit is unverified.", a.libraryAssignSample(as) + return a.bugsimHooks().name(), "Current outlines in photo coordinates. Not calibrated projector output.", a.libraryAssignSample(as) case carbonPageIdx: - as:=carbonAssignCurrent();return effectName(as.ID),"Selected settings on a sample room. No measured depth or physical fit.",a.libraryAssignSample(as) + as:=carbonAssignCurrent();return effectName(as.ID),"Current outlines in photo coordinates. Not calibrated projector output.",a.libraryAssignSample(as) case ag100PageIdx: - ag100UI.mu.Lock();i:=clampi(ag100UI.sel,0,len(AG100Effects)-1);ag100UI.mu.Unlock();ef:=AG100Effects[i];return ef.Name,ef.Desc,a.libraryAssignSample(ag100AssignNow()) + ag100UI.mu.Lock();i:=clampi(ag100UI.sel,0,len(AG100Effects)-1);ag100UI.mu.Unlock();ef:=AG100Effects[i];return ef.Name,"Current outlines in photo coordinates. "+ef.Desc,a.libraryAssignSample(ag100AssignNow()) case botanicalPageIdx: return botanicalSelected().Name,"Authored synthetic silhouette illustration only, not your body or a live camera frame. Actual projector output is black until fresh real segmentation is explicitly started.",botanicalIllustration() case chimeraPageIdx: - name,desc,as:=a.chimeraSampleInfo();return name,desc,a.libraryAssignSample(as) + name,desc,as:=a.chimeraSampleInfo();return name,"Current outlines in photo coordinates. "+desc,a.libraryAssignSample(as) case physPageIdx: return "Physics selection", "Local mapped selection, not measured projector output.", a.physPreviewFrame() case hxPageIdx: @@ -202,29 +202,29 @@ func (a *app) librarySample() (string, string, *Frame) { case ofxPageIdx: id = a.ofxSel().ID case fishTankPageIdx: - return "Fish Tank selection", "Selected settings on a sample room. Real placement may differ.", a.libraryAssignSample(fishTankAssignNow(a.st.SafeMode)) + return "Fish Tank selection", "Current outlines in photo coordinates. Real placement may differ.", a.libraryAssignSample(fishTankAssignNow(a.st.SafeMode)) case restylePageIdx: name, _ := restyleLabel(restyleSel) - return name, "Selected style on a sample room. Some unfinished choices may be almost blank.", a.libraryAssignSample(restyleAssign()) + return name, "Current outlines in photo coordinates. Some unfinished choices may be almost blank.", a.libraryAssignSample(restyleAssign()) case roomFiltersPageIdx: roomFiltersUI.mu.Lock() i := clampi(roomFiltersUI.sel, 0, len(roomFilterSpecs)-1) roomFiltersUI.mu.Unlock() sp := roomFilterSpecs[i] - return sp.Name, sp.Desc, a.libraryAssignSample(roomFilterAssignNow()) + return sp.Name, "Current outlines in photo coordinates. "+sp.Desc, a.libraryAssignSample(roomFilterAssignNow()) case xmasPageIdx: effects := GetXmasEffects() i := clampi(activeXmasEffectIdx, 0, len(effects)-1) ef := effects[i] - return ef.Name, ef.Description, a.libraryAssignSample(Assign{Type: "fx", ID: ef.ID, C1: "#ff2a2a", C2: "#18d860", Scale: 1, Speed: 1, Inten: 1, Fit: "fill"}) + return ef.Name, "Current outlines in photo coordinates. "+ef.Description, a.libraryAssignSample(Assign{Type: "fx", ID: ef.ID, C1: "#ff2a2a", C2: "#18d860", Scale: 1, Speed: 1, Inten: 1, Fit: "fill"}) case antidemoPageIdx: antidemoUI.mu.Lock() i := clampi(antidemoUI.sel, 0, len(antidemoSpecs)-1) antidemoUI.mu.Unlock() sp := antidemoSpecs[i] - return sp.Name, sp.Desc, a.libraryAssignSample(antidemoAssignNow()) + return sp.Name, "Current outlines in photo coordinates. "+sp.Desc, a.libraryAssignSample(antidemoAssignNow()) case antiRustPageIdx: - i:=antiCuratedSelected340();sp:=antiCurated340[i];return sp.Name,"Synthetic sample. Original saved playback preserved.",a.libraryAssignSample(antiCuratedAssign340(i)) + i:=antiCuratedSelected340();sp:=antiCurated340[i];return sp.Name,"Current outlines in photo coordinates. Original saved playback preserved.",a.libraryAssignSample(antiCuratedAssign340(i)) case antiWGSLPageIdx, antiCUDAPageIdx, antiGLSLPageIdx, antiJuliaPageIdx: engIdx := 0 switch U.page { @@ -259,7 +259,7 @@ func (a *app) librarySample() (string, string, *Frame) { pixelUI.Lock() as := pixelUIAssignLocked() pixelUI.Unlock() - return effectName(as.ID), "Selected settings on a sample room. Real projector fit is unverified.", a.libraryAssignSample(as) + return effectName(as.ID), "Current outlines in photo coordinates. Not calibrated projector output.", a.libraryAssignSample(as) case qPageIdx: return "3d characters selection", "Local selection sample; projector fit is unverified.", a.qPreviewFrame(320, 180) case ttPageIdx: @@ -272,7 +272,7 @@ func (a *app) librarySample() (string, string, *Frame) { case hmPageIdx: return "HeavyM composition", "Composition canvas. Not measured projector output.", a.hmCanvasFrame(320, 180) case themesPageIdx: - return "Auto Themes selection", "Selected theme renderer on synthetic sample geometry, not your room or measured projector output.", a.themePreviewFrame(320, 180) + return "Auto Themes selection", "Selected theme on current outlines in photo coordinates, not calibrated projector output.", a.themePreviewFrame(320, 180) case musePageIdx: museUI.mu.Lock() i := museUI.sel @@ -302,7 +302,7 @@ func (a *app) librarySample() (string, string, *Frame) { } } if id != "" && a.pl != nil && a.pl.R != nil { - return effectName(id), "Selected effect sample, default settings. Preview tests your mapped selection.", a.browserThumb(id) + return effectName(id), "Current outlines, default settings, photo coordinates. Preview tests calibrated projector output.", a.browserThumb(id) } if U.page == 8 { return "No saved picture selected", "Select a saved picture on the right. No image generation or sending starts here.", nil diff --git a/library_sample_windows.go b/library_sample_windows.go index bb3ec54..4bfba7b 100644 --- a/library_sample_windows.go +++ b/library_sample_windows.go @@ -16,8 +16,13 @@ var librarySampleCache = struct { // Params are serialized before leaving the UI thread. One bounded worker uses // only this private simulator, never the player's show, calibration or audio. func (a *app) libraryAssignSample(as Assign) *Frame { - raw, _ := json.Marshal(as) - key := string(raw) + if a==nil||a.pl==nil{return nil} + a.pl.mu.Lock() + snap,geometryKey:=libraryOutlineSnapshotFor354(a.pl.P) + a.pl.mu.Unlock() + if geometryKey==""{return nil} + raw,err:=json.Marshal(as);if err!=nil{return nil} + key:=geometryKey+"|"+string(raw) librarySampleCache.Lock() if f, ok := librarySampleCache.frames[key]; ok { librarySampleCache.Unlock() @@ -44,7 +49,7 @@ func (a *app) libraryAssignSample(as Assign) *Frame { }() var own Assign json.Unmarshal(raw, &own) - f := renderLibraryAssignSample(own) + f := renderLibraryOutlineAssign354(snap,own) librarySampleCache.Lock() if len(librarySampleCache.frames) >= 48 { librarySampleCache.frames = map[string]*Frame{} diff --git a/render.go b/render.go index b8ae8bf..76e9ff7 100644 --- a/render.go +++ b/render.go @@ -1991,6 +1991,19 @@ func (r *Renderer) RenderScene(sc *Scene, t float64, f *Frame, fade float64, clk livingCached.update(as.ID, livingShapeCtx, t*speed, c1, inten) } phys := r.physFieldFor(sc, pl, as, plans, t, clk, speed, inten, c1, c2, f.W, f.H) + if phys!=nil&&aquaticRoomID354(as.ID){ + // frameDepth passed the exact source/authoring receipt above. Physics uses + // photo UV directly, not local effect UV, and abstains for unbound plans. + var aquaticDepth *depthMap + if as.Angle==0&&r.P.Depth!=nil { + eligible:=true + for _,ap:=range plans{if ap==nil||!ap.photoScene||ap.t3!=nil||ap.depthAuthoring!=r.P.Depth.AuthoringSHA256{eligible=false;break}} + if eligible{aquaticDepth=frameDepth} + } + phys.e.mu.Lock();phys.e.aquaticBind354(plans,aquaticDepth) + if tank,ok:=phys.e.sim.(*fishTank);ok{tank.room354=phys.e.aquaticRoom354} + phys.e.render();phys.e.mu.Unlock() + } physPlan := isPhysFx(as.ID) prow := proof.beginPlan(pi, pl, as, inten) var demoOffsets []int32 diff --git a/themes_20_ui_win.go b/themes_20_ui_win.go index 149cba1..1f7e3cb 100644 --- a/themes_20_ui_win.go +++ b/themes_20_ui_win.go @@ -57,9 +57,9 @@ func (a *app) themesLayout(add func(widget) int, rx, rw, y, bh, pad int) { pw := rw - 2*sc(16) ph := sc(160) - add(widget{kind: kThumb, id: idThemeCanvas, l: rx + sc(16), t: y, r: rx + rw - sc(16), b: y + ph, img: a.themePreviewFrame(pw, ph), text: fmt.Sprintf("Synthetic renderer sample: %s [%s]", th.Name, th.Category), enabled: false}) + add(widget{kind: kThumb, id: idThemeCanvas, l: rx + sc(16), t: y, r: rx + rw - sc(16), b: y + ph, img: a.themePreviewFrame(pw, ph), text: fmt.Sprintf("Current outline illustration: %s [%s]", th.Name, th.Category), enabled: false}) y += ph + pad - row("Still from the selected theme renderer on synthetic sample geometry, not your mapped room or measured depth.",36) + row("Selected theme on current outlines in photo coordinates, not calibrated projector output or measured depth.",36) y = a.fxStdHeaderLayout(add, rx, rw, y, pad, fxStdHeaderOpts{ Title: "Auto Themes",