@@ -336,7 +336,7 @@ function renderElement (world: World, cursor: Vec3, element: BlockElement, doAO:
336336 let localShift = null as any
337337
338338 if ( element . rotation && ! needTiles ) {
339- // todo do we support rescale?
339+ // Rescale support for block model rotations
340340 localMatrix = buildRotationMatrix (
341341 element . rotation . axis ,
342342 element . rotation . angle
@@ -349,6 +349,37 @@ function renderElement (world: World, cursor: Vec3, element: BlockElement, doAO:
349349 element . rotation . origin
350350 )
351351 )
352+
353+ // Apply rescale if specified
354+ if ( element . rotation . rescale ) {
355+ const FIT_TO_BLOCK_SCALE_MULTIPLIER = 2 - Math . sqrt ( 2 )
356+ const angleRad = element . rotation . angle * Math . PI / 180
357+ const scale = Math . abs ( Math . sin ( angleRad ) ) * FIT_TO_BLOCK_SCALE_MULTIPLIER
358+
359+ // Get axis vector components (1 for the rotation axis, 0 for others)
360+ const axisX = element . rotation . axis === 'x' ? 1 : 0
361+ const axisY = element . rotation . axis === 'y' ? 1 : 0
362+ const axisZ = element . rotation . axis === 'z' ? 1 : 0
363+
364+ // Create scale matrix: scale = (1 - axisComponent) * scaleFactor + 1
365+ const scaleMatrix = [
366+ [ ( 1 - axisX ) * scale + 1 , 0 , 0 ] ,
367+ [ 0 , ( 1 - axisY ) * scale + 1 , 0 ] ,
368+ [ 0 , 0 , ( 1 - axisZ ) * scale + 1 ]
369+ ]
370+
371+ // Apply scaling to the transformation matrix
372+ localMatrix = matmulmat3 ( localMatrix , scaleMatrix )
373+
374+ // Recalculate shift with the new matrix
375+ localShift = vecsub3 (
376+ element . rotation . origin ,
377+ matmul3 (
378+ localMatrix ,
379+ element . rotation . origin
380+ )
381+ )
382+ }
352383 }
353384
354385 const aos : number [ ] = [ ]
0 commit comments