@@ -236,10 +236,10 @@ export default function ThreeDControls({ swatches, onChange, persisted }: ThreeD
236236 // Map geometry height to slicer layer index using slicer's first layer height.
237237 // We report the layer whose top is at or above this height, matching slicer UI labels.
238238 const effFirst = Math . max ( 0 , slicerFirstLayerHeight || 0 ) ;
239- let layerNum = 2 ;
239+ let layerNum = 1 ;
240240 if ( layerHeight > 0 ) {
241241 const delta = Math . max ( 0 , heightAt - effFirst ) ;
242- layerNum = 2 + Math . ceil ( delta / layerHeight ) ;
242+ layerNum = 1 + Math . ceil ( delta / layerHeight ) ;
243243 }
244244 swapPlan . push ( {
245245 type : 'swap' ,
@@ -327,6 +327,21 @@ export default function ThreeDControls({ swatches, onChange, persisted }: ThreeD
327327 const displayOrder =
328328 colorOrder . length === filtered . length ? colorOrder : filtered . map ( ( _ , i ) => i ) ;
329329
330+ // Ensure the currently-first color in display order cannot be below the slicer first layer height
331+ useEffect ( ( ) => {
332+ if ( displayOrder . length === 0 ) return ;
333+ const firstFi = displayOrder [ 0 ] ;
334+ const current = colorSliceHeights [ firstFi ] ;
335+ const minFirst = Math . max ( layerHeight , slicerFirstLayerHeight ) ;
336+ if ( typeof current === 'number' && isFinite ( current ) && current < minFirst ) {
337+ setColorSliceHeights ( ( prev ) => {
338+ const next = prev . slice ( ) ;
339+ next [ firstFi ] = minFirst ;
340+ return next ;
341+ } ) ;
342+ }
343+ } , [ displayOrder , colorSliceHeights , layerHeight , slicerFirstLayerHeight ] ) ;
344+
330345 return (
331346 < div className = "space-y-4" >
332347 { /* Apply button */ }
@@ -450,16 +465,21 @@ export default function ThreeDControls({ swatches, onChange, persisted }: ThreeD
450465 >
451466 < SortableContent asChild >
452467 < div className = "space-y-2" >
453- { displayOrder . map ( ( fi ) => {
468+ { displayOrder . map ( ( fi , idx ) => {
454469 const s = filtered [ fi ] ;
455470 const val = colorSliceHeights [ fi ] ?? layerHeight ;
471+ const isFirst = idx === 0 ;
472+ const minForRow = isFirst
473+ ? Math . max ( layerHeight , slicerFirstLayerHeight )
474+ : layerHeight ;
456475 return (
457476 < ThreeDColorRow
458477 key = { `${ s . hex } -${ fi } ` }
459478 fi = { fi }
460479 hex = { s . hex }
461480 value = { val }
462481 layerHeight = { layerHeight }
482+ minHeight = { minForRow }
463483 onChange = { onRowChange }
464484 />
465485 ) ;
0 commit comments