pub struct SsPlayerWeb { /* private fields */ }Expand description
One character. Holds the playback tree and its placement in the scene — and no GPU resource at all, which is what makes it cheap to have many.
Implementations§
Source§impl SsPlayerWeb
impl SsPlayerWeb
Sourcepub async fn load_ssab(
&self,
bytes: Vec<u8>,
pack: Option<String>,
base_url: Option<String>,
read: Option<Function>,
) -> Result<(), JsValue>
pub async fn load_ssab( &self, bytes: Vec<u8>, pack: Option<String>, base_url: Option<String>, read: Option<Function>, ) -> Result<(), JsValue>
Register + select a .ssab, and load the textures it needs.
It loads the pack’s textures before returning and leaves setAnimation a
pure selection. Texture loading belongs to initialisation, not to
animation selection: switching motions is a frequent, synchronous
operation that must not carry a Promise, so
SsPlayerWeb::set_animation stays synchronous.
This is async because fetch and createImageBitmap are. That is the
one place the asynchrony appears.
packnames the pack for external instance references (ref_anime_pack). Passnull/undefined— the usual case — to use the name the exporter wrote into the.ssab, which is the name those references are resolved against. A name of your own overrides it, and then any external instance reference to this pack stops resolving.baseUrlis where the.ssabcame from; reference-mode atlas paths are relative to it. Defaults to the document’s URL. Embedded packs ignore it.readanswers in place offetch, as it does forSsPlayerWeb::load.
An atlas the renderer already has is left alone (“registered wins”), so
N players of one pack load it once between them. An atlas
that cannot be fetched or decoded is reported on the console and skipped,
as in _load_external_ssabs’ ERR_PRINT and PackResolver’s
console.warn: one missing image should not cost you the character.
Sourcepub async fn load(
&self,
src: &str,
read: Option<Function>,
) -> Result<(), JsValue>
pub async fn load( &self, src: &str, read: Option<Function>, ) -> Result<(), JsValue>
Fetch a .ssab and everything it needs, then select it.
The shortest form: a URL is the one input that answers both questions a pack raises — what the
bytes are, and what its sibling files resolve against. src may be
absolute or relative (resolved against the document, like any URL a page
uses), and the pack keeps the name the exporter gave it.
This is SSPlayer::load_with with the browser’s loader plugged in — the
same walk a native host’s SSPlayer::load makes. Use SsPlayerWeb::load_ssab when the bytes have
no URL at all — a bundler’s import — and pass baseUrl if that pack
still has siblings to find.
read stands in for fetch when the files are not on a server: a
dropped folder, an archive the page unpacked. It is handed each file’s
absolute URL — src resolved against the document, everything after it
resolved against src — and answers an ArrayBuffer, a Uint8Array or a
Blob, or null for a file it does not have. So a page that files a
dropped folder under URLs of its own choosing gets the whole walk:
const base = new URL('dropped/1/', location.href);
const files = new Map(dropped.map((f) => [new URL(f.path, base).href, f.file]));
await player.load(new URL('Ringo/Ringo.ssab', base).href, (url) => files.get(url));The atlases are keyed by those URLs, as fetched ones are, so a second folder needs a base of its own: under the same one, an atlas that shares a name with the first folder’s is taken as already loaded.
One load at a time per player. Starting a second before the first has
settled is rejected, because the two would otherwise race for the slot the
player was lifted out of and one of them would be lost — await the
promise, or chain the calls. Two different players load concurrently as
usual, and share whatever atlases they have in common.
Sourcepub async fn add_ssab(
&self,
bytes: Vec<u8>,
pack: Option<String>,
base_url: Option<String>,
read: Option<Function>,
) -> Result<(), JsValue>
pub async fn add_ssab( &self, bytes: Vec<u8>, pack: Option<String>, base_url: Option<String>, read: Option<Function>, ) -> Result<(), JsValue>
SsPlayerWeb::load_ssab without changing what plays: registers an
additional pack for external instance references, and loads its assets
too — a sub-animation’s cells come out of its own pack’s atlases.
Rarely needed, since SsPlayerWeb::load resolves those references
itself; it is for packs that are not URL-addressable.
Sourcepub fn animation_names(&self) -> Result<Vec<String>, JsValue>
pub fn animation_names(&self) -> Result<Vec<String>, JsValue>
The animation names in the loaded pack.
Sourcepub fn current_animation(&self) -> Result<Option<String>, JsValue>
pub fn current_animation(&self) -> Result<Option<String>, JsValue>
The animation currently set up, or undefined before the first
setAnimation and again after a load replaced the pack.
Sourcepub fn texture_refs(&self, pack: Option<String>) -> Result<Array, JsValue>
pub fn texture_refs(&self, pack: Option<String>) -> Result<Array, JsValue>
The atlases a registered pack asks for, as { key, path, embedded }[]
in pack order. pack undefined selects the main pack.
The counterpart of SsContextWeb::add_texture: only the .ssab knows where its atlases were exported to, so a page
showing a reference-mode pack fetches new URL(path, ssabUrl) for every
entry whose embedded is false and registers the pixels by key.
Embedded entries need no fetch — they arrive with the pack.
key is what the renderer is keyed by, not the slot the pack names the
atlas by. The two differ whenever two packs could name one atlas alike,
which a tool naming every project’s atlas spritemap1.png does —
registering by the slot is how a page ends up drawing another project’s
atlas, which is why the slot is not handed out here.
Sourcepub fn embedded_textures(&self, pack: Option<String>) -> Result<Array, JsValue>
pub fn embedded_textures(&self, pack: Option<String>) -> Result<Array, JsValue>
The atlases a registered pack carries, as { key, bytes }[] — the
encoded images, not pixels. Empty for a reference-mode pack.
pack undefined selects the main pack.
The embedded half of texture supply, and the counterpart of
SsPlayerWeb::texture_refs: there is nothing to fetch, but there is
still something to decode, and on this face the decoder is the browser.
Hand each entry to SsContextWeb::add_texture_from_bytes.
It is what lets this face support embedded packs without carrying an image decoder into the bundle.
Sourcepub fn missing_assets(&self) -> Result<Array, JsValue>
pub fn missing_assets(&self) -> Result<Array, JsValue>
What the last load could not get, as { kind, name, slot }[].
Empty means everything the packs asked for arrived.
load rejects only when the .ssab itself is unreadable — one missing
atlas must not cost you the character — so this is how a page tells a
complete load from one that played anyway. kind is "texture" (its
parts draw as white silhouettes) or "pack" (its parts do not appear).
Sourcepub fn replaceable_cellmap_names(
&self,
pack: Option<String>,
) -> Result<Vec<String>, JsValue>
pub fn replaceable_cellmap_names( &self, pack: Option<String>, ) -> Result<Vec<String>, JsValue>
Every replaceable name in a pack — cellmap names and TextureChange targets
both, the namespace SsPlayerWeb::set_cellmap_texture takes. pack null
selects the main pack.
Sourcepub fn set_cellmap_texture(
&self,
pack: Option<String>,
name: &str,
bitmap: &ImageBitmap,
) -> Result<(), JsValue>
pub fn set_cellmap_texture( &self, pack: Option<String>, name: &str, bitmap: &ImageBitmap, ) -> Result<(), JsValue>
Replace the texture a cellmap binds, from a premultiplied ImageBitmap the
page decoded (createImageBitmap(blob, { premultiplyAlpha: 'premultiply' })).
pack null selects the main pack. name is one of
SsPlayerWeb::replaceable_cellmap_names. The replacement should match the
original atlas’s size and cell layout — the runtime’s UVs stay in the
original cellmap’s pixel space. Rejects when the player is unbound, for a
pack or name it cannot replace, and for a bitmap the device cannot hold —
past its max_texture_dimension_2d, or closed — leaving the cellmap as it
was.
Sourcepub async fn set_cellmap_texture_from_bytes(
&self,
pack: Option<String>,
name: String,
bytes: Vec<u8>,
) -> Result<(), JsValue>
pub async fn set_cellmap_texture_from_bytes( &self, pack: Option<String>, name: String, bytes: Vec<u8>, ) -> Result<(), JsValue>
SsPlayerWeb::set_cellmap_texture from encoded image bytes (PNG); the
library runs them through createImageBitmap. Decoded before anything
changes, so a bad image leaves the cellmap as it was.
Sourcepub fn restore_cellmap_texture(
&self,
pack: Option<String>,
name: &str,
) -> Result<(), JsValue>
pub fn restore_cellmap_texture( &self, pack: Option<String>, name: &str, ) -> Result<(), JsValue>
Undo a runtime override: point the cellmap back at its original atlas and drop the replacement from the renderer. A no-op if it was not overridden; rejects a pack or name the player cannot replace.
Sourcepub fn is_cellmap_overridden(
&self,
pack: Option<String>,
name: &str,
) -> Result<bool, JsValue>
pub fn is_cellmap_overridden( &self, pack: Option<String>, name: &str, ) -> Result<bool, JsValue>
Whether a cellmap currently carries a runtime override. pack null selects
the main pack.
Sourcepub fn set_animation(&self, name: &str) -> Result<(), JsValue>
pub fn set_animation(&self, name: &str) -> Result<(), JsValue>
Select an animation: builds the instance tree, and the only call here that
allocates. Starting playback is SsPlayerWeb::play, a separate call.
Sourcepub fn play(&self) -> Result<(), JsValue>
pub fn play(&self) -> Result<(), JsValue>
Start from the head of the section, re-arming the loop count. Not a
resume: it rewinds. Use SsPlayerWeb::resume to lift a hold.
Sourcepub fn play_from(&self, start_frame: f32) -> Result<(), JsValue>
pub fn play_from(&self, start_frame: f32) -> Result<(), JsValue>
play() from startFrame rather than the head of the section.
Sourcepub fn pause(&self) -> Result<(), JsValue>
pub fn pause(&self) -> Result<(), JsValue>
Hold the current frame. Idempotent, and ignored while nothing is playing.
Sourcepub fn resume(&self) -> Result<(), JsValue>
pub fn resume(&self) -> Result<(), JsValue>
Lift a SsPlayerWeb::pause, carrying on from the same frame.
Idempotent, and a no-op on a stopped animation.
Sourcepub fn stop(&self) -> Result<(), JsValue>
pub fn stop(&self) -> Result<(), JsValue>
Stop playback. The playhead stays where it stands; nothing rewinds.
Sourcepub fn set_speed_scale(&self, speed: f32) -> Result<(), JsValue>
pub fn set_speed_scale(&self, speed: f32) -> Result<(), JsValue>
Playback rate multiplier (1.0 = as authored).
Sourcepub fn speed_scale(&self) -> Result<f32, JsValue>
pub fn speed_scale(&self) -> Result<f32, JsValue>
The speed in effect: 0 for a speed that was set to zero or below,
since that is the stop it became.
Sourcepub fn is_playing(&self) -> Result<bool, JsValue>
pub fn is_playing(&self) -> Result<bool, JsValue>
Whether this player is currently advancing.
Sourcepub fn is_pausing(&self) -> Result<bool, JsValue>
pub fn is_pausing(&self) -> Result<bool, JsValue>
Held in place rather than stopped: isPlaying stays true.
Sourcepub fn is_playing_forward(&self) -> Result<bool, JsValue>
pub fn is_playing_forward(&self) -> Result<bool, JsValue>
Which way the playhead is actually travelling — not the heading
setPlaybackDirection configured, which playbackDirection reports.
Under ping-pong the return leg runs backward while that still reads
forward. Gate audio on this: SpriteStudio has no reverse audio.
Sourcepub fn is_finished(&self) -> Result<bool, JsValue>
pub fn is_finished(&self) -> Result<bool, JsValue>
Every configured loop has played. Sticky, and never true under an infinite loop.
Sourcepub fn seek(&self, frame: f32) -> Result<(), JsValue>
pub fn seek(&self, frame: f32) -> Result<(), JsValue>
Jump to frame. Fractional values are honoured.
Sourcepub fn start_frame(&self) -> Result<i32, JsValue>
pub fn start_frame(&self) -> Result<i32, JsValue>
First frame of the range being played. Follows setAnimationSection.
Sourcepub fn total_frames(&self) -> Result<i32, JsValue>
pub fn total_frames(&self) -> Result<i32, JsValue>
Length of that range, both ends inclusive — feed it to a scrubber.
Sourcepub fn set_loop_count(&self, count: i32) -> Result<(), JsValue>
pub fn set_loop_count(&self, count: i32) -> Result<(), JsValue>
count cycles then stop; -1 (or 0) loops forever. Under ping-pong
one cycle is a full round trip.
Sourcepub fn loop_count(&self) -> Result<i32, JsValue>
pub fn loop_count(&self) -> Result<i32, JsValue>
The configured loop count — before an animation is set up, the one
setLoopCount is holding for it, or 0 when none was set.
Sourcepub fn remaining_loops(&self) -> Result<i32, JsValue>
pub fn remaining_loops(&self) -> Result<i32, JsValue>
How many cycles of the loop count are left; 0 with no animation.
Sourcepub fn set_frame_rate(&self, fps: i32) -> Result<(), JsValue>
pub fn set_frame_rate(&self, fps: i32) -> Result<(), JsValue>
Override the advance rate in fps. Prefer setSpeedScale, which scales
playback without replacing the authored rate.
Sourcepub fn frame_rate(&self) -> Result<i32, JsValue>
pub fn frame_rate(&self) -> Result<i32, JsValue>
The rate the animation advances at.
Sourcepub fn set_animation_section(&self, start: i32, end: i32) -> Result<(), JsValue>
pub fn set_animation_section(&self, start: i32, end: i32) -> Result<(), JsValue>
Restrict playback to start..=end of the current animation. Call it
after setAnimation, which rebuilds the tree and takes the section
with it. Throws, changing nothing, on an end before the start when both
are inside the animation; an end outside it is the animation’s edge.
Sourcepub fn set_playback_direction(
&self,
direction: i32,
style: i32,
) -> Result<(), JsValue>
pub fn set_playback_direction( &self, direction: i32, style: i32, ) -> Result<(), JsValue>
direction: 0 forward, 1 backward. style: 0 normal, 1 ping-pong.
Set as a pair — pass the current value for whichever you are not
changing.
Sourcepub fn playback_direction(&self) -> Result<i32, JsValue>
pub fn playback_direction(&self) -> Result<i32, JsValue>
0 forward, 1 backward.
Sourcepub fn playback_style(&self) -> Result<i32, JsValue>
pub fn playback_style(&self) -> Result<i32, JsValue>
0 normal, 1 ping-pong.
Sourcepub fn set_sub_frame_enabled(&self, enabled: bool) -> Result<(), JsValue>
pub fn set_sub_frame_enabled(&self, enabled: bool) -> Result<(), JsValue>
On (the default) draws between authored frames; off floors the frame that is drawn, pinning playback to whole ones.
The playhead keeps its fraction either way (frameNo reports it
unrounded), and so does the stepping of instance and effect children.
This affects only what is drawn.
Sourcepub fn sub_frame_enabled(&self) -> Result<bool, JsValue>
pub fn sub_frame_enabled(&self) -> Result<bool, JsValue>
See setSubFrameEnabled.
Sourcepub fn set_frame_skip_enabled(&self, skip: bool) -> Result<(), JsValue>
pub fn set_frame_skip_enabled(&self, skip: bool) -> Result<(), JsValue>
On (the default) keeps playback on the wall clock by dropping frames;
off advances exactly one frame per frame() call.
Sourcepub fn frame_skip_enabled(&self) -> Result<bool, JsValue>
pub fn frame_skip_enabled(&self) -> Result<bool, JsValue>
See setFrameSkipEnabled.
Sourcepub fn find_part_index(&self, name: &str) -> Result<i32, JsValue>
pub fn find_part_index(&self, name: &str) -> Result<i32, JsValue>
Resolve a part name to its index in the current animation, or -1 when
the name is unknown or no animation is set up.
Sourcepub fn set_part_visibility_override_by_index(
&self,
part: u32,
hide: bool,
cascade: bool,
) -> Result<(), JsValue>
pub fn set_part_visibility_override_by_index( &self, part: u32, hide: bool, cascade: bool, ) -> Result<(), JsValue>
Force-hide a part (hide = true) or revert it to the animation.
cascade propagates a force-hide to the part’s descendants — a keyframe
hide never cascades, so this is the only way to hide a sub-tree.
Sourcepub fn clear_part_visibility_override_by_index(
&self,
part: u32,
) -> Result<(), JsValue>
pub fn clear_part_visibility_override_by_index( &self, part: u32, ) -> Result<(), JsValue>
Revert a part to the animation’s own visibility.
Sourcepub fn set_part_color_override_by_index(
&self,
part: u32,
rgba: u32,
blend_op: u8,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_color_override_by_index( &self, part: u32, rgba: u32, blend_op: u8, priority: u8, ) -> Result<(), JsValue>
Override a part’s colour. blendOp: 0 mix, 1 mul, 2 add, 3 sub.
rgba is packed 0xRRGGBBAA in the authored 8-bit sRGB space — do not
pre-multiply it. priority: 0 until the next keyframe, 1 until the next
animation, 2 permanent. Normal parts only.
Sourcepub fn set_part_color_override_corners_by_index(
&self,
part: u32,
corners: &[u8],
blend_op: u8,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_color_override_corners_by_index( &self, part: u32, corners: &[u8], blend_op: u8, priority: u8, ) -> Result<(), JsValue>
Four-corner colour override, for a gradient. corners is 16 bytes in the
runtime’s order — left-top, right-top, left-bottom, right-bottom, each
[r, g, b, a]. Otherwise as setPartColorOverride.
Sourcepub fn clear_part_color_override_by_index(
&self,
part: u32,
) -> Result<(), JsValue>
pub fn clear_part_color_override_by_index( &self, part: u32, ) -> Result<(), JsValue>
Revert a part to the animation’s own colour.
Sourcepub fn set_part_cell_override_by_index(
&self,
part: u32,
cellmap_name: &str,
cell_name: &str,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_cell_override_by_index( &self, part: u32, cellmap_name: &str, cell_name: &str, priority: u8, ) -> Result<(), JsValue>
Make a part draw a different cell. cellmapName is written without the
.ssce extension. Normal and Mask parts only; throws when the cell
cannot be resolved against the loaded pack.
Sourcepub fn clear_part_cell_override_by_index(
&self,
part: u32,
) -> Result<(), JsValue>
pub fn clear_part_cell_override_by_index( &self, part: u32, ) -> Result<(), JsValue>
Revert a part to the animation’s own cell.
Sourcepub fn set_part_visibility_override(
&self,
part: &str,
hide: bool,
cascade: bool,
) -> Result<(), JsValue>
pub fn set_part_visibility_override( &self, part: &str, hide: bool, cascade: bool, ) -> Result<(), JsValue>
Force-hide a part by name, or revert it to the animation.
Sourcepub fn clear_part_visibility_override(&self, part: &str) -> Result<(), JsValue>
pub fn clear_part_visibility_override(&self, part: &str) -> Result<(), JsValue>
Revert a part to the animation’s own visibility, by name.
Sourcepub fn set_part_color_override(
&self,
part: &str,
rgba: u32,
blend_op: u8,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_color_override( &self, part: &str, rgba: u32, blend_op: u8, priority: u8, ) -> Result<(), JsValue>
Override a part’s colour by name. Arguments as setPartColorOverrideByIndex.
Sourcepub fn set_part_color_override_corners(
&self,
part: &str,
corners: &[u8],
blend_op: u8,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_color_override_corners( &self, part: &str, corners: &[u8], blend_op: u8, priority: u8, ) -> Result<(), JsValue>
Four-corner colour override by name. Arguments as the ByIndex sibling.
Sourcepub fn clear_part_color_override(&self, part: &str) -> Result<(), JsValue>
pub fn clear_part_color_override(&self, part: &str) -> Result<(), JsValue>
Revert a part to the animation’s own colour, by name.
Sourcepub fn set_part_cell_override(
&self,
part: &str,
cellmap_name: &str,
cell_name: &str,
priority: u8,
) -> Result<(), JsValue>
pub fn set_part_cell_override( &self, part: &str, cellmap_name: &str, cell_name: &str, priority: u8, ) -> Result<(), JsValue>
Make a part draw a different cell, by name.
Sourcepub fn clear_part_cell_override(&self, part: &str) -> Result<(), JsValue>
pub fn clear_part_cell_override(&self, part: &str) -> Result<(), JsValue>
Revert a part to the animation’s own cell, by name.
Sourcepub fn part_transform(&self, part: &str) -> Result<Vec<f32>, JsValue>
pub fn part_transform(&self, part: &str) -> Result<Vec<f32>, JsValue>
A part’s current-frame transform by name, as the six affine terms, or an empty array when the name is unknown.
Whether the part is hidden on the frame the last frame() built, or
undefined when the pack has no such part. An override shows from the next
frame().
The companion to partTransform, which reports where a part would be
whether or not it is drawn — a host following a part needs both.
Sourcepub fn is_part_skinned_mesh(&self, part: &str) -> Result<Option<bool>, JsValue>
pub fn is_part_skinned_mesh(&self, part: &str) -> Result<Option<bool>, JsValue>
Whether the part is a skinned mesh — one whose vertices are drawn by
bone skinning — or undefined when the pack has no such part.
A skinned mesh cannot be followed with partTransform: its node stays at
the setup position (near the character root) while the bones move the
visible vertices, so a follower would snap to the root. A picker can use
this to warn, or to steer the choice to a null / bone part. A rigid
(deform-only) mesh follows correctly and reports false.
Index form of isPartHidden, for the partIndex an event carries or a
slot in partNames; undefined when part is out of range.
Sourcepub fn is_part_skinned_mesh_by_index(
&self,
part: u32,
) -> Result<Option<bool>, JsValue>
pub fn is_part_skinned_mesh_by_index( &self, part: u32, ) -> Result<Option<bool>, JsValue>
Index form of isPartSkinnedMesh; undefined when part is out of range.
Sourcepub fn part_names(&self) -> Result<Vec<String>, JsValue>
pub fn part_names(&self) -> Result<Vec<String>, JsValue>
Every part name, in part-index order — what turns the partIndex an event
carries back into something a human reads, and what fills a part picker.
An unnamed part holds its slot as an empty string, so the array stays
index-aligned. length is the part count, and unlike partCount, which
is 0 until an animation is set up, it is there as soon as a pack is bound.
Sourcepub fn cellmap_names(&self) -> Result<Vec<String>, JsValue>
pub fn cellmap_names(&self) -> Result<Vec<String>, JsValue>
Every cellmap name in the pack, without the .ssce extension — the
namespace setPartCellOverride takes.
Sourcepub fn cell_names(&self, cellmap_name: &str) -> Result<Vec<String>, JsValue>
pub fn cell_names(&self, cellmap_name: &str) -> Result<Vec<String>, JsValue>
The cell names inside one cellmap — the other half of what
setPartCellOverride takes.
Sourcepub fn clear_all_part_overrides(&self) -> Result<(), JsValue>
pub fn clear_all_part_overrides(&self) -> Result<(), JsValue>
Drop every override on the root animation at once.
Sourcepub fn part_count(&self) -> Result<usize, JsValue>
pub fn part_count(&self) -> Result<usize, JsValue>
How many parts the root animation has; 0 before one is set up.
Sourcepub fn set_track_animation(&self, track: u32, name: &str) -> Result<(), JsValue>
pub fn set_track_animation(&self, track: u32, name: &str) -> Result<(), JsValue>
Put name on track, replacing what it was playing. Track 0 is better set
with setAnimation, which rebuilds the instance tree. On track 0 it still
makes name the current animation.
Sourcepub fn track_count(&self) -> Result<u32, JsValue>
pub fn track_count(&self) -> Result<u32, JsValue>
Number of tracks, empty ones included; 0 before an animation is set up.
Sourcepub fn clear_track(&self, track: u32) -> Result<(), JsValue>
pub fn clear_track(&self, track: u32) -> Result<(), JsValue>
Silence a track. Track 0 is refused — fade it to alpha 0 instead.
Sourcepub fn set_track_alpha(&self, track: u32, alpha: f32) -> Result<(), JsValue>
pub fn set_track_alpha(&self, track: u32, alpha: f32) -> Result<(), JsValue>
How much of track survives onto the pose below. Not clamped: above 1
extrapolates, 0 or below contributes nothing.
Sourcepub fn track_alpha(&self, track: u32) -> Result<Option<f32>, JsValue>
pub fn track_alpha(&self, track: u32) -> Result<Option<f32>, JsValue>
track’s alpha, or undefined when there is no such track.
Sourcepub fn set_track_blend(&self, track: u32, blend: u32) -> Result<(), JsValue>
pub fn set_track_blend(&self, track: u32, blend: u32) -> Result<(), JsValue>
blend: 0 = mix (lerp onto what is below), 1 = additive (offset from the setup pose).
Sourcepub fn set_track_sync(&self, track: u32, sync: u32) -> Result<(), JsValue>
pub fn set_track_sync(&self, track: u32, sync: u32) -> Result<(), JsValue>
sync: 0 = free (an animation laid on the track starts from its head),
1 = start (it starts at the phase track 0 stands at). Set it before
laying; setAnimation resets every track to free.
Sourcepub fn crossfade(
&self,
track: u32,
name: &str,
duration_ms: f32,
) -> Result<(), JsValue>
pub fn crossfade( &self, track: u32, name: &str, duration_ms: f32, ) -> Result<(), JsValue>
Fade track to name over durationMs, starting from whatever it is
playing. Advanced by frame(). On track 0, name takes over from the
call on: it is the current animation, its state is what isFinished
reports, and it plays with the speed, direction and loop count the page
set. The instance tree is not rebuilt; the instance and effect parts
belong to the pack, so the running children carry on.
Sourcepub fn fade_track(
&self,
track: u32,
target: f32,
duration_ms: f32,
) -> Result<(), JsValue>
pub fn fade_track( &self, track: u32, target: f32, duration_ms: f32, ) -> Result<(), JsValue>
Drive track’s alpha to target over durationMs. Fading track 0 to 0
settles the character onto the setup pose.
Sourcepub fn track_fade_progress(&self, track: u32) -> Result<Option<f32>, JsValue>
pub fn track_fade_progress(&self, track: u32) -> Result<Option<f32>, JsValue>
How far the fade on track has got, 0 to 1; undefined when it is not fading.
Sourcepub fn cancel_track_fade(&self, track: u32) -> Result<(), JsValue>
pub fn cancel_track_fade(&self, track: u32) -> Result<(), JsValue>
Stop the fade on track, leaving alpha and weights where they stand.
Sourcepub fn set_track_frame(&self, track: u32, frame: f32) -> Result<(), JsValue>
pub fn set_track_frame(&self, track: u32, frame: f32) -> Result<(), JsValue>
Seek track’s animation — how a continuous-control axis is driven.
Sourcepub fn track_frame(&self, track: u32) -> Result<Option<f32>, JsValue>
pub fn track_frame(&self, track: u32) -> Result<Option<f32>, JsValue>
track’s playhead, or undefined when there is no such track.
Sourcepub fn set_track_speed(&self, track: u32, speed: f32) -> Result<(), JsValue>
pub fn set_track_speed(&self, track: u32, speed: f32) -> Result<(), JsValue>
track’s own playback speed; 0 parks it, which is how a scrubbed axis
stays where setTrackFrame puts it.
Sourcepub fn track_speed(&self, track: u32) -> Result<Option<f32>, JsValue>
pub fn track_speed(&self, track: u32) -> Result<Option<f32>, JsValue>
track’s speed (see setTrackSpeed), or undefined when there is no such track.
Sourcepub fn set_track_frame_rate(&self, track: u32, fps: i32) -> Result<(), JsValue>
pub fn set_track_frame_rate(&self, track: u32, fps: i32) -> Result<(), JsValue>
setFrameRate for one track.
Sourcepub fn track_frame_rate(&self, track: u32) -> Result<Option<i32>, JsValue>
pub fn track_frame_rate(&self, track: u32) -> Result<Option<i32>, JsValue>
The rate track’s animation plays at, the override or the authored
rate; 0 for a track with neither.
Sourcepub fn set_track_frame_skip_enabled(
&self,
track: u32,
skip: bool,
) -> Result<(), JsValue>
pub fn set_track_frame_skip_enabled( &self, track: u32, skip: bool, ) -> Result<(), JsValue>
setFrameSkipEnabled for one track.
Sourcepub fn track_frame_skip_enabled(
&self,
track: u32,
) -> Result<Option<bool>, JsValue>
pub fn track_frame_skip_enabled( &self, track: u32, ) -> Result<Option<bool>, JsValue>
Whether track skips frames to keep time, or undefined when there is no such track.
Sourcepub fn set_track_playback_direction(
&self,
track: u32,
direction: i32,
style: i32,
) -> Result<(), JsValue>
pub fn set_track_playback_direction( &self, track: u32, direction: i32, style: i32, ) -> Result<(), JsValue>
setPlaybackDirection for one track, with the same 0 / 1 values.
Sourcepub fn track_playback_direction(
&self,
track: u32,
) -> Result<Option<i32>, JsValue>
pub fn track_playback_direction( &self, track: u32, ) -> Result<Option<i32>, JsValue>
0 = forward, 1 = backward.
Sourcepub fn track_playback_style(&self, track: u32) -> Result<Option<i32>, JsValue>
pub fn track_playback_style(&self, track: u32) -> Result<Option<i32>, JsValue>
0 = normal, 1 = ping-pong.
Sourcepub fn set_track_loop_count(
&self,
track: u32,
count: i32,
) -> Result<(), JsValue>
pub fn set_track_loop_count( &self, track: u32, count: i32, ) -> Result<(), JsValue>
How many times track’s animation plays before it holds its last
frame; -1 (or 0) loops forever. Set it after laying the animation:
one is laid looping forever. On track 0 this is setLoopCount, and the
player keeps the count for every animation laid there.
Sourcepub fn track_loop_count(&self, track: u32) -> Result<Option<i32>, JsValue>
pub fn track_loop_count(&self, track: u32) -> Result<Option<i32>, JsValue>
-1 for a track that loops forever; undefined for one with no animation.
Sourcepub fn is_track_finished(&self, track: u32) -> Result<bool, JsValue>
pub fn is_track_finished(&self, track: u32) -> Result<bool, JsValue>
Whether track’s animation has played its loop count out and holds its
last frame. A state, as isFinished is for track 0; there is no edge.
Sourcepub fn track_just_looped(&self, track: u32) -> Result<bool, JsValue>
pub fn track_just_looped(&self, track: u32) -> Result<bool, JsValue>
Whether the last frame() wrapped track’s animation back to its
start, as justLooped is for track 0.
Sourcepub fn set_track_outgoing_event_threshold(
&self,
track: u32,
threshold: f32,
) -> Result<(), JsValue>
pub fn set_track_outgoing_event_threshold( &self, track: u32, threshold: f32, ) -> Result<(), JsValue>
How far into a crossfade on track the outgoing animation keeps firing
events: while its share of the track, 1 - progress, is at least
threshold. The default, Infinity, silences it from the moment the
fade begins; 0.5 keeps it firing for the first half. Kept by the track.
The update that completes the fade has already released the outgoing
animation, so it fires nothing there, even at 0.
Sourcepub fn track_outgoing_event_threshold(
&self,
track: u32,
) -> Result<Option<f32>, JsValue>
pub fn track_outgoing_event_threshold( &self, track: u32, ) -> Result<Option<f32>, JsValue>
The threshold the outgoing side of a crossfade on track fires its events
at, or undefined when there is no such track.
Sourcepub fn track_main_source(&self, track: u32) -> Result<Option<u32>, JsValue>
pub fn track_main_source(&self, track: u32) -> Result<Option<u32>, JsValue>
The source carrying track’s animation; undefined when it has none.
Sourcepub fn add_track_source(
&self,
track: u32,
name: &str,
weight: f32,
) -> Result<u32, JsValue>
pub fn add_track_source( &self, track: u32, name: &str, weight: f32, ) -> Result<u32, JsValue>
Lay name on track beside what it already carries, at weight, and
return its handle. On an empty track it becomes the main source.
Sourcepub fn set_source_weight(&self, source: u32, weight: f32) -> Result<(), JsValue>
pub fn set_source_weight(&self, source: u32, weight: f32) -> Result<(), JsValue>
A source’s share within its track; weights are ratios.
Sourcepub fn source_weight(&self, source: u32) -> Result<Option<f32>, JsValue>
pub fn source_weight(&self, source: u32) -> Result<Option<f32>, JsValue>
source’s weight within its track, or undefined when there is no such source.
Sourcepub fn set_source_frame(&self, source: u32, frame: f32) -> Result<(), JsValue>
pub fn set_source_frame(&self, source: u32, frame: f32) -> Result<(), JsValue>
Seek one source — how a page keeps sources of different lengths in step.
Sourcepub fn source_frame(&self, source: u32) -> Result<Option<f32>, JsValue>
pub fn source_frame(&self, source: u32) -> Result<Option<f32>, JsValue>
source’s playhead, or undefined when there is no such source.
Sourcepub fn set_source_event_threshold(
&self,
source: u32,
threshold: f32,
) -> Result<(), JsValue>
pub fn set_source_event_threshold( &self, source: u32, threshold: f32, ) -> Result<(), JsValue>
The weight at or above which source fires its events. Only track 0’s
main source fires by default (the default threshold is Infinity); lower
this to the source’s weight or below to have it fire too.
Sourcepub fn source_event_threshold(
&self,
source: u32,
) -> Result<Option<f32>, JsValue>
pub fn source_event_threshold( &self, source: u32, ) -> Result<Option<f32>, JsValue>
The weight source must reach for its events to fire, or undefined when
there is no such source.
Sourcepub fn just_started(&self) -> Result<bool, JsValue>
pub fn just_started(&self) -> Result<bool, JsValue>
Whether the last frame() was the first to run after a play() /
playFrom() — true for exactly one call. Not raised by resume(), which
carries on rather than starting.
Sourcepub fn just_looped(&self) -> Result<bool, JsValue>
pub fn just_looped(&self) -> Result<bool, JsValue>
Whether the last frame() crossed a loop boundary. One report per call
however many cycles it crossed.
Sourcepub fn just_finished(&self) -> Result<bool, JsValue>
pub fn just_finished(&self) -> Result<bool, JsValue>
Whether the last frame() completed playback — true for exactly one
call, unlike the sticky isFinished. Never true under an infinite loop,
and not raised by stop().
Sourcepub fn events(&self) -> Result<Array, JsValue>
pub fn events(&self) -> Result<Array, JsValue>
Timeline events the last frame() crossed, as an array of plain objects
tagged by kind:
{ kind: 'userData', partIndex, integer?, rect?, point?, text? }
{ kind: 'signal', partIndex, commandId, params: [{ id, value }] }
{ kind: 'audio', partIndex, soundName, soundListNameHash, soundNameHash, loopNum }Every kind also carries frameNo (the frame the key is authored on),
partName, and source: the handle of the source on the track stack
that fired it, which tells events apart once another source has opted in
with setSourceEventThreshold.
Frames skipped over are still represented: a long tick reports every frame it stepped through, not just the one it landed on. Empty on a tick that crossed nothing, and on a culled player, which does not advance; a hidden one reports as usual.
Sourcepub fn part_transform_by_index(&self, part: u32) -> Result<Vec<f32>, JsValue>
pub fn part_transform_by_index(&self, part: u32) -> Result<Vec<f32>, JsValue>
The part’s transform on the current frame as the 2D affine
[m00, m01, m10, m11, tx, ty] — the same six numbers ssplayer-webgl’s
getPartTransform returns, in animation-local (Y-down) space, with
neither setTransform nor the canvas projection applied.
Empty when no animation is set up or part is out of range. Read it
after frame(): it describes the frame that produced. Hidden parts still
report where they would have been.
Sourcepub fn set_transform(
&self,
x: f32,
y: f32,
scale_x: f32,
scale_y: f32,
rotation: f32,
) -> Result<(), JsValue>
pub fn set_transform( &self, x: f32, y: f32, scale_x: f32, scale_y: f32, rotation: f32, ) -> Result<(), JsValue>
Place this player in the scene, in pixels from the canvas centre, with
y measured downward (as partTransform reports, and as ForWeb’s
offsetY means it). rotation is in radians.
Sourcepub fn reset_transform(&self) -> Result<(), JsValue>
pub fn reset_transform(&self) -> Result<(), JsValue>
Back to the identity placement (centred, unscaled, unrotated).
Sourcepub fn canvas_rect(&self) -> Result<JsValue, JsValue>
pub fn canvas_rect(&self) -> Result<JsValue, JsValue>
The authored canvas of the animation now playing, as
{ x, y, width, height } in player-local units — the box
SsPlayerWeb::fit_into fits when you pass no frame of your own.
undefined when no animation is set up. It is the frame the artist
composed in, placed against the origin by the animation’s pivot, not a
measured bounding box.
Sourcepub fn fit_into(
&self,
width: f32,
height: f32,
options: Option<Object>,
) -> Result<Object, JsValue>
pub fn fit_into( &self, width: f32, height: f32, options: Option<Object>, ) -> Result<Object, JsValue>
Fit the animation into a width x height box and place it there, as
setTransform would. Returns what was written, as
{ x, y, scaleX, scaleY }.
player.fitInto(canvas.width, canvas.height, { fit: 'contain', align: 'bottom' });Every field of the options object is optional:
fit—'contain'(default) |'cover'|'none'align—'center'(default),'top','bottom','left','right','top-left','top-right','bottom-left','bottom-right'frame—{ x, y, width, height }in player-local units. Supply it and nothing is read from the packoffsetX/offsetY— pixels, applied after the fitscale— a multiplier on top of the fit’s scale (default 1)flipX/flipY— mirrors; the alignment follows themrotation— radians, passed straight through
The size is in canvas pixels, so call it again on resize and after
setAnimation when the canvas differs. A collapsed box, or no animation,
places the player centred and unscaled rather than throwing. An
unrecognised fit or align does throw, naming what it accepts.
Sourcepub fn set_order(&self, order: i32) -> Result<(), JsValue>
pub fn set_order(&self, order: i32) -> Result<(), JsValue>
Draw order within the canvas; lower draws first.
Sourcepub fn set_visible(&self, visible: bool) -> Result<(), JsValue>
pub fn set_visible(&self, visible: bool) -> Result<(), JsValue>
Hide this player. A hidden player draws nothing but keeps playing: its playhead advances and its events are reported.
Sourcepub fn is_visible(&self) -> Result<bool, JsValue>
pub fn is_visible(&self) -> Result<bool, JsValue>
Whether this player draws, as setVisible set it.
Sourcepub fn set_culled(&self, culled: bool) -> Result<(), JsValue>
pub fn set_culled(&self, culled: bool) -> Result<(), JsValue>
Cull this player. A culled player is skipped by both update and draw, so it costs nothing and its playhead stops where it was.
Sourcepub fn is_culled(&self) -> Result<bool, JsValue>
pub fn is_culled(&self) -> Result<bool, JsValue>
Whether this player is culled, as setCulled set it.
Sourcepub fn set_alpha(&self, alpha: f32) -> Result<(), JsValue>
pub fn set_alpha(&self, alpha: f32) -> Result<(), JsValue>
Player-level fade in 0..1, multiplied into every part — so overlapping
parts read more opaque than alpha, unless the canvas fades each player
as one layer (SsSurfaceWeb.setGroupAlpha).
Sourcepub fn alpha(&self) -> Result<f32, JsValue>
pub fn alpha(&self) -> Result<f32, JsValue>
The player-level fade in effect, after setAlpha clamped it to 0..1.
Sourcepub fn set_tint(&self, rgb: u32) -> Result<(), JsValue>
pub fn set_tint(&self, rgb: u32) -> Result<(), JsValue>
Player-level tint as 0xRRGGBB, multiplied into every part after the
PartColor blend. 0xffffff (the default) leaves colours untouched — the
same property tint names on @spritestudio/ssplayer-webgl.
Sourcepub fn set_crowd(
&self,
placements: &[f32],
tints: Option<Vec<u32>>,
) -> Result<(), JsValue>
pub fn set_crowd( &self, placements: &[f32], tints: Option<Vec<u32>>, ) -> Result<(), JsValue>
Draw this one playhead once at each member’s placement: a crowd that costs one player’s evaluation and draw calls, however large.
placements holds six numbers a member — x, y, scaleX, scaleY, rotation, alpha, the first five in setTransform terms and composed under it, the
alpha multiplied into the player’s — and tints, when given, one
0xRRGGBB a member. An empty array draws the player once again. Throws,
leaving the crowd as it was, when placements is not a whole number of
members, tints does not match it, or there are more than 4096.
Everything else is shared: the frame, the events (reported once), the masks and the effects. Each draw is issued for every member in turn, so where two members overlap their parts interleave, and masks clip correctly only where members do not overlap.
Sourcepub fn crowd_count(&self) -> Result<usize, JsValue>
pub fn crowd_count(&self) -> Result<usize, JsValue>
How many members setCrowd last gave this player; 0 when it draws once.
Trait Implementations§
Source§impl From<SsPlayerWeb> for JsValue
impl From<SsPlayerWeb> for JsValue
Source§fn from(value: SsPlayerWeb) -> Self
fn from(value: SsPlayerWeb) -> Self
Source§impl FromWasmAbi for SsPlayerWeb
impl FromWasmAbi for SsPlayerWeb
Source§impl IntoWasmAbi for SsPlayerWeb
impl IntoWasmAbi for SsPlayerWeb
Source§impl LongRefFromWasmAbi for SsPlayerWeb
impl LongRefFromWasmAbi for SsPlayerWeb
Source§type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
RefFromWasmAbi::AbiSource§type Anchor = RcRef<SsPlayerWeb>
type Anchor = RcRef<SsPlayerWeb>
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiSource§impl NullableFromWasmAbi for SsPlayerWeb
impl NullableFromWasmAbi for SsPlayerWeb
Source§impl NullableIntoWasmAbi for SsPlayerWeb
impl NullableIntoWasmAbi for SsPlayerWeb
Source§impl OptionFromWasmAbi for SsPlayerWeb
impl OptionFromWasmAbi for SsPlayerWeb
Source§impl OptionIntoWasmAbi for SsPlayerWeb
impl OptionIntoWasmAbi for SsPlayerWeb
Source§impl RefFromWasmAbi for SsPlayerWeb
impl RefFromWasmAbi for SsPlayerWeb
Source§type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
Self are recovered from.Source§type Anchor = RcRef<SsPlayerWeb>
type Anchor = RcRef<SsPlayerWeb>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for SsPlayerWeb
impl RefMutFromWasmAbi for SsPlayerWeb
Source§type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>
RefFromWasmAbi::AbiSource§type Anchor = RcRefMut<SsPlayerWeb>
type Anchor = RcRefMut<SsPlayerWeb>
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiimpl SupportsConstructor for SsPlayerWeb
impl SupportsInstanceProperty for SsPlayerWeb
impl SupportsStaticProperty for SsPlayerWeb
Source§impl TryFromJsValue for SsPlayerWeb
impl TryFromJsValue for SsPlayerWeb
Source§fn try_from_js_value_ref(value: &JsValue) -> Option<Self>
fn try_from_js_value_ref(value: &JsValue) -> Option<Self>
Source§const NULLABLE: bool = false
const NULLABLE: bool = false
Self accepts null as a distinct value space, as
Nullable<T> does. An enclosing Option then passes null through
instead of reading it as None, so Option<T> is itself nullable
exactly when T is not. JsValue does not set this: it accepts
null as one value among all of them, not as a distinct space, and
Option<JsValue> reads it as None like the ABI does. This is the
JS-value side of NullableFromWasmAbi, which claims null at the
ABI.Source§impl VectorFromWasmAbi for SsPlayerWeb
impl VectorFromWasmAbi for SsPlayerWeb
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[SsPlayerWeb]>
Source§impl VectorIntoWasmAbi for SsPlayerWeb
impl VectorIntoWasmAbi for SsPlayerWeb
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[SsPlayerWeb]>) -> Self::Abi
Source§impl WasmDescribeVector for SsPlayerWeb
impl WasmDescribeVector for SsPlayerWeb
Auto Trait Implementations§
impl !Freeze for SsPlayerWeb
impl !RefUnwindSafe for SsPlayerWeb
impl !Send for SsPlayerWeb
impl !Sync for SsPlayerWeb
impl !UnwindSafe for SsPlayerWeb
impl Unpin for SsPlayerWeb
impl UnsafeUnpin for SsPlayerWeb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> MaybeFromWasmAbi for Twhere
T: OptionFromWasmAbi,
impl<T> MaybeFromWasmAbi for Twhere
T: OptionFromWasmAbi,
Source§type MaybeAbi = <T as FromWasmAbi>::Abi
type MaybeAbi = <T as FromWasmAbi>::Abi
Option<Self>.Source§unsafe fn from_maybe_abi(js: <T as FromWasmAbi>::Abi) -> T
unsafe fn from_maybe_abi(js: <T as FromWasmAbi>::Abi) -> T
unsafe fn try_from_maybe_abi( js: <T as FromWasmAbi>::Abi, ) -> Result<T, &'static str>
Source§impl<T> MaybeIntoWasmAbi for Twhere
T: OptionIntoWasmAbi,
impl<T> MaybeIntoWasmAbi for Twhere
T: OptionIntoWasmAbi,
Source§type MaybeAbi = <T as IntoWasmAbi>::Abi
type MaybeAbi = <T as IntoWasmAbi>::Abi
Option<Self>.Source§fn into_maybe_abi(self) -> <T as IntoWasmAbi>::Abi
fn into_maybe_abi(self) -> <T as IntoWasmAbi>::Abi
Option<Self> ABI.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.