Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pmndrs/drei
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v9.87.0
Choose a base ref
...
head repository: pmndrs/drei
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v9.87.1
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Oct 9, 2023

  1. fix: support for variable sized sprites (#1678)

    * feat: added optional Sprite or Plane geometry for SpriteAnimator
    
    * fix: support for variable sized sprites
    
    * fix: added extra checks to change frames with variable size
    Michael Dobekidis authored Oct 9, 2023
    1

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bc12fe0 View commit details
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/core/SpriteAnimator.tsx
12 changes: 10 additions & 2 deletions src/core/SpriteAnimator.tsx
Original file line number Diff line number Diff line change
@@ -86,7 +86,9 @@ export const SpriteAnimator: React.FC<SpriteAnimatorProps> = (

const calculateAspectRatio = (width: number, height: number): Vector3 => {
const aspectRatio = height / width
spriteRef.current.scale.set(1, aspectRatio, 1)
if (spriteRef.current) {
spriteRef.current.scale.set(1, aspectRatio, 1)
}
return [1, aspectRatio, 1]
}

@@ -125,6 +127,12 @@ export const SpriteAnimator: React.FC<SpriteAnimatorProps> = (
currentFrame.current = 0
currentFrameName.current = frameName
hasEnded.current = false
modifySpritePosition()
if (spriteData.current) {
const { w, h } = getFirstItem(spriteData.current.frames).sourceSize
const _aspect = calculateAspectRatio(w, h)
setAspect(_aspect)
}
}
}, [frameName])

@@ -326,7 +334,7 @@ export const SpriteAnimator: React.FC<SpriteAnimatorProps> = (
return param[0]
} else if (typeof param === 'object' && param !== null) {
const keys = Object.keys(param)
return param[keys[0]][0]
return frameName ? param[frameName][0] : param[keys[0]][0]
} else {
return { w: 0, h: 0 }
}