@@ -850,6 +850,14 @@ namespace gdjs {
850850 const angleCosValue = Math . cos ( angle ) ;
851851 const angleSinValue = Math . sin ( angle ) ;
852852
853+ // Determine if this layer will actually render in 3D mode.
854+ // A layer configured for 3D (has _threeCamera and _threePlaneMesh) but with no
855+ // 3D objects will be rendered directly in 2D mode, so it should use 2D-style
856+ // pixi container setup to avoid a zoom mismatch.
857+ // See also: `layerHas3DObjectsToRender` in `runtimescene-pixi-renderer.ts`.
858+ const willRenderIn3DMode =
859+ this . _threeCamera && this . _threePlaneMesh && this . has3DObjects ( ) ;
860+
853861 // Update the 2D plane in the 3D world position, size and rotation,
854862 // and update the 2D Pixi container position, size and rotation.
855863 if ( this . _threeCamera && this . _threePlaneMesh ) {
@@ -869,31 +877,36 @@ namespace gdjs {
869877 this . _threePlaneMesh . position . set ( cx , - cy , 0 ) ;
870878 this . _threePlaneMesh . rotation . set ( 0 , 0 , - angle ) ;
871879
872- // Update the 2D Pixi container size and rotation to match the "zoom" (which comes from the 2D plane size)
873- // rotation and position.
874- effectivePixiZoom = this . _layer . getWidth ( ) / boxW ; // == height/boxH
875- this . _pixiContainer . scale . set ( effectivePixiZoom , effectivePixiZoom ) ;
876- this . _pixiContainer . rotation = angle ;
877-
878- const followX = cx ;
879- const followY = - cy ;
880- const centerX2d =
881- followX * effectivePixiZoom * angleCosValue -
882- followY * effectivePixiZoom * angleSinValue ;
883- const centerY2d =
884- followX * effectivePixiZoom * angleSinValue +
885- followY * effectivePixiZoom * angleCosValue ;
886- this . _pixiContainer . position . x =
887- this . _layer . getWidth ( ) / 2 - centerX2d ;
888- this . _pixiContainer . position . y =
889- this . _layer . getHeight ( ) / 2 - centerY2d ;
880+ if ( willRenderIn3DMode ) {
881+ // Update the 2D Pixi container size and rotation to match the "zoom" (which comes from the 2D plane size)
882+ // rotation and position.
883+ effectivePixiZoom = this . _layer . getWidth ( ) / boxW ; // == height/boxH
884+ this . _pixiContainer . scale . set ( effectivePixiZoom , effectivePixiZoom ) ;
885+ this . _pixiContainer . rotation = angle ;
886+
887+ const followX = cx ;
888+ const followY = - cy ;
889+ const centerX2d =
890+ followX * effectivePixiZoom * angleCosValue -
891+ followY * effectivePixiZoom * angleSinValue ;
892+ const centerY2d =
893+ followX * effectivePixiZoom * angleSinValue +
894+ followY * effectivePixiZoom * angleCosValue ;
895+ this . _pixiContainer . position . x =
896+ this . _layer . getWidth ( ) / 2 - centerX2d ;
897+ this . _pixiContainer . position . y =
898+ this . _layer . getHeight ( ) / 2 - centerY2d ;
899+ }
890900 }
891901 }
892902
893903 // 2D only (no 3D rendering and so no 2D plane in the 3D world):
894904 // Update the 2D Pixi container position, size and rotation.
895- if ( ! this . _threeCamera || ! this . _threePlaneMesh ) {
905+ // This also applies to layers configured for 3D but with no 3D objects,
906+ // since they will be rendered directly in 2D mode.
907+ if ( ! willRenderIn3DMode ) {
896908 effectivePixiZoom = this . _layer . getCameraZoom ( ) ;
909+
897910 this . _pixiContainer . rotation = angle ;
898911 this . _pixiContainer . scale . x = effectivePixiZoom ;
899912 this . _pixiContainer . scale . y = effectivePixiZoom ;
0 commit comments