@@ -146,6 +146,20 @@ export interface IBlueprintFormatJSON {
146146 collections ?: ICollectionJSON [ ]
147147}
148148
149+ export function fixCubeRotation ( cube : Cube ) {
150+ const maxRotation = Math . max ( ...cube . rotation )
151+ const minRotation = Math . min ( ...cube . rotation )
152+ if ( maxRotation <= 45 && minRotation >= - 45 ) return
153+ // Use the rotation with the largest absolute value
154+ const rotation = Math . abs ( maxRotation ) >= Math . abs ( minRotation ) ? maxRotation : minRotation
155+ const axis = cube . rotation . indexOf ( rotation )
156+
157+ const previousSelected = Project ! . selected_elements
158+ Project ! . selected_elements = [ cube ]
159+ rotateOnAxis ( ( ) => rotation , axis , true )
160+ Project ! . selected_elements = previousSelected
161+ }
162+
149163//region > Convert
150164export function convertToBlueprint ( ) {
151165 // Convert the current project to a Blueprint
@@ -156,13 +170,19 @@ export function convertToBlueprint() {
156170 group . createUniqueName ( Group . all . filter ( g => g !== group ) )
157171 group . sanitizeName ( )
158172 }
173+
159174 for ( const animation of Blockbench . Animation . all ) {
160175 animation . createUniqueName ( Blockbench . Animation . all . filter ( a => a !== animation ) )
161176 animation . name = sanitizeStorageKey ( animation . name )
162177 }
178+
163179 for ( const cube of Cube . all ) {
164180 cube . setUVMode ( false )
181+
182+ fixCubeRotation ( cube )
165183 }
184+
185+ Canvas . updateAll ( )
166186}
167187
168188export function getDefaultProjectSettings ( ) {
@@ -278,6 +298,13 @@ export const BLUEPRINT_FORMAT = registerModelFormat(
278298 component : ProjectTitleSvelte ,
279299 props : { pluginMode : project . pluginMode } ,
280300 } )
301+
302+ for ( const cube of Cube . all ) {
303+ cube . setUVMode ( false )
304+ fixCubeRotation ( cube )
305+ }
306+
307+ Canvas . updateAll ( )
281308 } )
282309 } ,
283310
@@ -353,14 +380,8 @@ export function projectTargetVersionIsAtLeast(version: string): boolean {
353380 return ! compareVersions ( version , Project ! . animated_java . target_minecraft_version )
354381}
355382
356- export function shouldEnableRotationLock ( ) : boolean {
357- if ( ! activeProjectIsBlueprintFormat ( ) ) return false
358-
359- if ( projectTargetVersionIsAtLeast ( '1.21.6' ) ) {
360- return false
361- }
362-
363- return ! (
383+ export function hasNonElementSelection ( ) : boolean {
384+ return (
364385 ! ! Group . first_selected ||
365386 ! ! AnimatedJava . TextDisplay . selected . length ||
366387 ! ! AnimatedJava . VanillaItemDisplay . selected . length ||
@@ -376,20 +397,20 @@ export function shouldEnableRotationLock(): boolean {
376397 )
377398}
378399
379- export function updateRotationLock ( ) {
380- if ( ! activeProjectIsBlueprintFormat ( ) ) return
381- const format = BLUEPRINT_FORMAT . get ( ) !
382- // If any of these node types are selected, we disable rotation lock.
383- format . rotation_limit = shouldEnableRotationLock ( )
384- format . rotation_snap = format . rotation_limit
385- }
386-
387- export function disableRotationLock ( ) {
400+ export function updateRotationConstraints ( ) {
388401 if ( ! activeProjectIsBlueprintFormat ( ) ) return
389402 const format = BLUEPRINT_FORMAT . get ( ) !
403+ if ( ! format ) {
404+ console . error ( 'Animated Java Blueprint format is not registered!' )
405+ return
406+ }
390407
391- format . rotation_limit = false
392- format . rotation_snap = false
408+ // Rotation is always limited when selecting an element
409+ format . rotation_limit = ! hasNonElementSelection ( )
410+ if ( ! projectTargetVersionIsAtLeast ( '1.21.6' ) /* < 1.21.6 */ ) {
411+ // But only snaps to 22.5 degree increments on versions before 1.21.6
412+ format . rotation_snap = format . rotation_limit
413+ }
393414}
394415
395416EVENTS . SELECT_PROJECT . subscribe ( project => {
@@ -402,13 +423,12 @@ EVENTS.UNSELECT_PROJECT.subscribe(project => {
402423 EVENTS . UNSELECT_AJ_PROJECT . publish ( project )
403424 }
404425} )
405- EVENTS . UPDATE_SELECTION . subscribe ( updateRotationLock )
426+ EVENTS . UPDATE_SELECTION . subscribe ( updateRotationConstraints )
406427EVENTS . SELECT_AJ_PROJECT . subscribe ( ( ) => {
407428 requestAnimationFrame ( ( ) => {
408- updateRotationLock ( )
429+ updateRotationConstraints ( )
409430 } )
410431} )
411432EVENTS . UNSELECT_AJ_PROJECT . subscribe ( project => {
412433 if ( project . visualBoundingBox ) scene . remove ( project . visualBoundingBox )
413- disableRotationLock ( )
414434} )
0 commit comments