mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
Sprite Editor Origin Fixes (#3648)
- PreviewSprite and SpriteEditor.Preview no longer improperly offsets the image by the origin when the aspect ratio of the sprite isn't 1:1 https://files.facepunch.com/CarsonKompon/2025/December/19_08-28-ScrawnyHoopoe.mp4
This commit is contained in:
@@ -45,8 +45,19 @@ class PreviewSprite : AssetPreview
|
|||||||
|
|
||||||
public override void UpdateScene( float cycle, float timeStep )
|
public override void UpdateScene( float cycle, float timeStep )
|
||||||
{
|
{
|
||||||
|
var texture = spriteRenderer.Texture;
|
||||||
|
if ( texture.Width == 0 || texture.Height == 0 )
|
||||||
|
return;
|
||||||
|
var ratio = (float)texture.Width / texture.Height;
|
||||||
var pivotOffset = new Vector2( 0.5f, 0.5f ) - (CurrentAnimation?.Origin ?? new Vector2( 0.5f, 0.5f ));
|
var pivotOffset = new Vector2( 0.5f, 0.5f ) - (CurrentAnimation?.Origin ?? new Vector2( 0.5f, 0.5f ));
|
||||||
PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x, pivotOffset.y ) * 16;
|
if ( ratio > 1 )
|
||||||
|
{
|
||||||
|
PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x, pivotOffset.y / ratio ) * 16;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PrimaryObject.WorldPosition = new Vector3( 0, pivotOffset.x * ratio, pivotOffset.y ) * 16;
|
||||||
|
}
|
||||||
|
|
||||||
spriteRenderer.TextureFilter = FilterMode;
|
spriteRenderer.TextureFilter = FilterMode;
|
||||||
|
|
||||||
|
|||||||
@@ -94,10 +94,23 @@ public class Preview : Widget
|
|||||||
|
|
||||||
private void ScenePreFrame()
|
private void ScenePreFrame()
|
||||||
{
|
{
|
||||||
var originOffset = new Vector2( 0.5f, 0.5f ) - (SpriteEditor?.SelectedAnimation?.Origin ?? new Vector2( 0.5f, 0.5f ));
|
var texture = Renderer.Texture;
|
||||||
Renderer.WorldPosition = Renderer.WorldPosition
|
if ( texture.Width == 0 || texture.Height == 0 )
|
||||||
.WithY( originOffset.x * 100 )
|
return;
|
||||||
.WithZ( originOffset.y * 100 );
|
var ratio = (float)texture.Width / texture.Height;
|
||||||
|
var pivotOffset = new Vector2( 0.5f, 0.5f ) - (SpriteEditor?.SelectedAnimation?.Origin ?? new Vector2( 0.5f, 0.5f ));
|
||||||
|
if ( ratio > 1 )
|
||||||
|
{
|
||||||
|
Renderer.WorldPosition = Renderer.WorldPosition
|
||||||
|
.WithY( pivotOffset.x * 100 )
|
||||||
|
.WithZ( pivotOffset.y * 100 / ratio );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Renderer.WorldPosition = Renderer.WorldPosition
|
||||||
|
.WithY( pivotOffset.x * 100 * ratio )
|
||||||
|
.WithZ( pivotOffset.y * 100 );
|
||||||
|
}
|
||||||
|
|
||||||
switch ( SpriteEditor?.Antialiasing )
|
switch ( SpriteEditor?.Antialiasing )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user