Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust spine basic API #111

Merged
merged 85 commits into from
Oct 29, 2024
Merged

Adjust spine basic API #111

merged 85 commits into from
Oct 29, 2024

Conversation

johanzhu
Copy link
Collaborator

@johanzhu johanzhu commented Oct 28, 2024

What does this PR do?
Adjust spine basic API.

Changes

  • Deprecated resource getter and setter
  • Refractor SkeletonResource. Change name to spineResource, add an another animationData create from previous skeletonData.
    Additionally create and store animationData, which is generated based on the original skeletonData. Add a skeletonData cache to manage resource reference counting relationships based on skeletonData.
  • Add createSpineResource API and export it.
  • Delete addSeparateSlot API
  • Modify the renderer initialization method to initialize directly by setting Skeleton and State.
  • Add static methods createWithEntity and attachToEntity to facilitate manual creation of Spine animations for users.
  • Remove the setting variable and move the rendering parameters zSpacing and useClipping to the outermost level of the renderer.

Impact:
After deprecating the resource API, the recommended way for users to create Spine animations will change."

old:

const spineResource = (await engine.resourceManager.load({
  ...resource,
  type: 'spine'
})) as SpineResource;
const spineEntity = new Entity(engine, 'spine-entity');
const spineAnimation = spineEntity.addComponent(SpineAnimationRenderer);
pineAnimation.resource = spineResource;
root.addChild(spineEntity);

new:

const spineResource = (await engine.resourceManager.load({
  ...resource,
  type: 'spine'
})) as SpineResource;

// create with entity
const spineAnimation = SpineAnimationRenderer.createWithEntity(spineResource);
root.addChild(spineAnimation.entity);

// or  attach to entity
const spineEntity = scene.findEntityByName('spine');
const spineAnimation = SpineRendererAnimation.attachToEntity(spineEntity, spineResource);

// or  create with skeleton and state
// In this case, use should create new skeleton and AnimationState with source data in spineResource
const spineEntity = new Entity(engine, 'spine-entity');
const spineAnimation = spineEntity.addComponent(SpineAnimationRenderer);
const { skeletonData, animationData } = spineResource;
const skeleton = new Skeleton(skeletonData);
const state = new AnimationState(animationData);
spineAnimation.skeleton = skeleton;
spineAnimation.state = state;
root.addChild(spineEntity);

Additional Context
Related to issue: #109

Please review the changes and provide feedback on the caching logic and implementation details.

@GuoLei1990 GuoLei1990 changed the title Adjust spine basic API. Adjust spine basic API Oct 29, 2024
@GuoLei1990 GuoLei1990 added the engineering Engineering problems label Oct 29, 2024
src/loader/SpineResource.ts Outdated Show resolved Hide resolved
src/loader/SpineResource.ts Show resolved Hide resolved
src/loader/SpineResource.ts Outdated Show resolved Hide resolved
src/loader/SpineResource.ts Show resolved Hide resolved
@GuoLei1990 GuoLei1990 merged commit 901110f into galacean:4.2 Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engineering Engineering problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants