@threlte/extras
<AnimatedSpriteMaterial>
Provides animation tools for spritesheets.
<script lang="ts">
import { Canvas } from '@threlte/core'
import Scene from './Scene.svelte'
</script>
<div class="h-full">
<Canvas>
<Scene />
</Canvas>
</div>
<style>
div {
background-color: black;
height: 100%;
}
</style>This material is most easily used by passing it a spritesheet URL and a JSON metadata file URL.
Currently, JSON metadata using Aseprite’s hash export format is supported.
Animation names from tags can be used to transition to specific animations in the spritesheet.
<T.Sprite>
<AnimatedSpriteMaterial
animation="Idle"
textureUrl="./player.png"
dataUrl="./player.json"
/>
</T.Sprite>If no metadata file is provided, additional props must be passed to run an animation:
totalFrames, if the spritesheet is only a single row.totalFrames,rows, andcolumns, otherwise.
<T.Sprite>
<AnimatedSpriteMaterial
textureUrl="./fire.png"
totalFrames={14}
rows={4}
columns={4}
/>
</T.Sprite>Additionally, if a sheet with no JSON supplied has multiple animations, start and end frames must be passed to run an animation within the sheet.
<T.Sprite>
<AnimatedSpriteMaterial
textureUrl="./fire.png"
totalFrames={14}
rows={4}
columns={4}
startFrame={4}
endFrame={8}
/>
</T.Sprite><AnimatedSpriteMaterial> can be attached to a <T.Sprite> as well as a <T.Mesh>.
<script lang="ts">
import { Canvas, T } from '@threlte/core'
import Scene from './Scene.svelte'
</script>
<div>
<Canvas>
<Scene />
<T.DirectionalLight
intensity={2}
castShadow
position={[1, 1, 1]}
/>
</Canvas>
</div>
<style>
div {
height: 100%;
}
</style>In the case of a Mesh parent a MeshBasicMaterial will be used by default, instead of a SpriteMaterial when attached to a Sprite. A custom depth material will be attached when parented to a mesh to support shadows.
Any other material type can be used as well.
<T.Mesh>
<AnimatedSpriteMaterial
is={THREE.MeshStandardMaterial}
textureUrl="./fire.png"
totalFrames={14}
/>
</T.Mesh>