perf(editor): stabilize 3D opening-guide rendering, remove per-tick GPU churn
Reuse one THREE.Line + preallocated position buffer per guide slot, mutating endpoints in place each drag tick instead of rebuilding the geometry, line, and two Vector3s and re-uploading the GPU buffer every frame. Key guides by a stable semantic id (sill / head / gap:side / vertical / spacing:i) so a slot that persists keeps its React element and drei <Html> pill mounted as the guide set churns, rather than remounting under shifting index keys. Also: make useOpeningGuides.clear() a no-op when already empty so the common no-guide hover frame doesn't push a fresh [] and re-render to the same nothing; dispose the move-tool cursor EdgesGeometry on unmount; and memoize the placement-tool cursor EdgesGeometry (static fallback dims) so it isn't reallocated and orphaned on every render during placement. Reviewed by Codex (peer + adversarial): no correctness, hook-order, or GPU-leak regressions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
86e9b3c8bf
commit
69aa272004
@@ -105,10 +105,14 @@ export function publishOpeningGuides3D(args: {
|
||||
|
||||
const out: OpeningGuide3D[] = []
|
||||
|
||||
// Stable `id`s keyed on the guide's semantic role (not list position) so the
|
||||
// 3D layer can keep a persisting slot's element + `<Html>` pill mounted as the
|
||||
// set churns each tick — see `OpeningGuide3D`.
|
||||
if (guides.sillHead) {
|
||||
if (guides.sillHead.sill > MIN_DIMENSION_M) {
|
||||
out.push({
|
||||
kind: 'dimension',
|
||||
id: 'sill',
|
||||
from: toWorld(centerS, 0),
|
||||
to: toWorld(centerS, guides.sillHead.bottomY),
|
||||
value: guides.sillHead.sill,
|
||||
@@ -117,6 +121,7 @@ export function publishOpeningGuides3D(args: {
|
||||
if (guides.sillHead.head > MIN_DIMENSION_M) {
|
||||
out.push({
|
||||
kind: 'dimension',
|
||||
id: 'head',
|
||||
from: toWorld(centerS, guides.sillHead.topY),
|
||||
to: toWorld(centerS, wallHeight),
|
||||
value: guides.sillHead.head,
|
||||
@@ -127,6 +132,7 @@ export function publishOpeningGuides3D(args: {
|
||||
for (const gap of guides.gaps) {
|
||||
out.push({
|
||||
kind: 'dimension',
|
||||
id: `gap:${gap.side}`,
|
||||
from: toWorld(gap.fromS, centerY),
|
||||
to: toWorld(gap.toS, centerY),
|
||||
value: gap.distance,
|
||||
@@ -140,6 +146,7 @@ export function publishOpeningGuides3D(args: {
|
||||
const hi = Math.max(centerS + width / 2, target.centerS + target.width / 2)
|
||||
out.push({
|
||||
kind: 'align-line',
|
||||
id: 'vertical',
|
||||
from: toWorld(lo, guides.vertical.y),
|
||||
to: toWorld(hi, guides.vertical.y),
|
||||
})
|
||||
@@ -147,13 +154,15 @@ export function publishOpeningGuides3D(args: {
|
||||
}
|
||||
|
||||
if (guides.equalSpacing) {
|
||||
for (const seg of guides.equalSpacing.segments) {
|
||||
const { gap, segments } = guides.equalSpacing
|
||||
segments.forEach((seg, i) => {
|
||||
out.push({
|
||||
kind: 'badge',
|
||||
id: `spacing:${i}`,
|
||||
at: toWorld((seg.fromS + seg.toS) / 2, centerY),
|
||||
value: guides.equalSpacing.gap,
|
||||
value: gap,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
useOpeningGuides.getState().set(out)
|
||||
|
||||
Reference in New Issue
Block a user