Giter Site home page Giter Site logo

playcanvas-spine's Introduction

PlayCanvas Spine

A Spine plugin for the PlayCanvas Engine.

CI

Examples such as the Hero above can be found in the examples folder. To run them, start a local web server and go to http://localhost/path/to/examples/hero.html (the path will depend on your file serving root directory).

Usage

Versions

The following plugins are available:

Spine Editor PlayCanvas Engine
3.6 Up to 1.65
3.8 Up to 1.65
4.0 1.27 and later
4.1 1.27 and later

Each plugin provides both a Component System to PlayCanvas Engine and the corresponding spine-core runtime to your scripts as global variable called spine. This allows developers to leverage the full spine library.

Editor

Add the plugin matching the Spine version used to export the animations, i.e build/playcanvas-spine.X.X.min.js and the PlayCanvas script build/spine.js to your project.

Create an entity with a script component and add the script spine to it. Upload your exported spine resources (atlas, skeleton json file, textures) and attach them to the spine script on your entity.

Ensure the plugin file is listed before the PlayCanvas script in the Scripts Loading Order.

Engine-only

Load the required library script, i.e. build/playcanvas-spine.X.X.min.js. Then, add spine components to your entities as follows:

var entity = new pc.Entity();
entity.addComponent("spine", {
    atlasAsset: atlas,       // atlas text asset id
    textureAssets: textures, // array of texture asset ids
    skeletonAsset: skeleton  // skeleton json asset id
});

Building

Prebuilt versions of the PlayCanvas Spine library can be found in the lib folder. However, to build them yourself, first install the NPM package dependencies:

npm install

Then, to build do:

npm run build

playcanvas-spine's People

Contributors

daredevildave avatar dependabot[bot] avatar e-strokov avatar epreston avatar maksims avatar mvaligursky avatar slimbuck avatar steveny-sc avatar vkalpias avatar willeastcott avatar yaustar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playcanvas-spine's Issues

Runtime Error in Internet Explorer 11

Launch
https://launch.playcanvas.com/581347
in Internet Explorer 11

Observe
Error: Object doesn't support property or method 'map'
File: playcanvas-spine.min.js, Line: 3, Column: 17925

Notes
This is a minimal example project with the most current version of the playcanvas-spine library, which works in Chrome and Edge. But i think the issue is that IE 11 has a different implementation of Float32Array and uses a object type instead of a float type.

Memory leak: Spine component not fully removed on destroy (Fix included)

Description

I noticed a performance issue after creating and deleting a large number of spine entities and using chrome memory snapshot tool realized that a lot of spine related data remained in memory after deleting all spines. (Spine, SpineComponent, SpineComponentData, SineTextureWrapper)

Investigating the code I noticed that the SpineComponentSystem overwrite the removeComponent function without calling the original breaking the component deletion flow.

Fix

This issue can be fixed by adding a call to the base removeComponent
pc.ComponentSystem.prototype.removeComponent.call(entity.spine.system, entity);
or a cleaner fix would be to register for the "beforeremove" event and move the spine removeComponent code into the callback.

this.on('beforeremove', this.onBeforeRemove, this);

...

onBeforeRemove: function(entity, component) {
        var data = entity.spine.data;
        if (data.spine) {
            data.spine.destroy();
        }

        entity.spine.removeComponent();
    },

Test project:

https://playcanvas.com/project/780176/overview/spine-leak

Steps to reproduce:

  1. launch application.
  2. Press load to load assets.
  3. Take memory snapshot with chrome developer tools ans search for spine objects.
  4. Press spawn to create a new spine entity.
  5. Pres delete to delete it.
  6. Wait a few second, take another memory snapshot and search for spine objects again.
  7. Notice the issue.
    If you uncomment one of the two fixed in playcanvas-spine.3.8.js around lines 7740 to 8870 all the extra spine data will be removed from memory.

Allow optional material configuration for the plugin

Hey team,

while using the Spine plugin on one of our projects we've noticed that the Spine animations were white. We discovered that that was due to the ambient light that was set to white. We fixed that issue by patching the plugin and inside createMaterial method we disabled the diffuse color

material.diffuse = new pc.Color(0, 0, 0, 0); // include diffuse component, this allows lights contribution

I think this is kind of "hacky" on our part and was wondering if there could be a way of setting this as an option on the SpineComponent?

Thanks!

Unable to disable or destroy entity in the complete callback

When trying to disable or destroy an entity at the end of an animation. I either throws an error saying the skeleton cannot be null or keeps rendering the last frame of the animation.

SpineAnim.prototype.LoadSpine = function(entityName)
{
        this.entity.spine.spine.skeleton.setSkinByName("default");
        this.entity.spine.spine.skeleton.setSlotsToSetupPose();
        
        this.entity.spine.states[1] = new spine.AnimationState(this.entity.spine.spine.stateData);

        this.delegateObj = {
            complete: this.onComplete.bind(this),
            interrupt: this.onComplete.bind(this)
        };

        this.entity.spine.state.addListener(this.delegateObj);
            this.entity.spine.state.defaultMix = 0.2;
           this.entity.spine.state.addAnimation(0, "Idle", false);
};

SpineAnim.prototype.onComplete = function(track){

//this.entity.enabled = false <- doesnt work.  continues to render last frame.
//this.entity.destroy();  <- throws an error saying skeleton cannot be null.

  setTimeout(function(){this.entity.enabled = false;}.bind(this), 10); // <- works because it is outside of the on complete function.
        
};

Meshinstance memory leak in render

Repo project: https://playcanvas.com/project/704630/overview/spine-test

https://github.com/playcanvas/playcanvas-spine/blob/master/src/spine.js#L453

meshinstances are removed in the render loop but the materials that they referenced still have a reference to the meshinstance.

A temp fix that was used:

Spine.prototype.render = function () {
    // FIX: clear materials before dropping mesh instances:
    this._meshInstances.forEach(function(instance) {
        instance.material = null;
    });
    // END FIX
    this.removeFromLayers();
    this._meshes = [];
    this._meshInstances.length = 0;
  etc...

Spine clipping mask problem

Awesome!!!

Do you have a version of Super SpineBoy for mobile? (safari and mobile chrome)

Your version apparently only works on desktop browsers.

Regards

ES6 Compatibility

Current implementation modifies the global "pc" variable to store its data. In the more modern and performant builds of pc engine, this does not work.

The current implementation of spine needs to store data and make features available to every app instance that the global "pc" instance might create. It needs to persist it even when those app instances, scenes, or root nodes are destroyed. At the time, a clever and graceful solution was to tuck things neatly into the "pc" variable to make sure its available no matter what happens.

While the chances for conflict are low, modern language features have been introduced to solve conflicts between vendor libraries. Unfortunately, the current approach is what a conflicting vendor library would do. If the spine plugin implementation took a different approach to meet those goals, this issue goes away.

It seems a small refactor is required.

This issue was first raised on the engine project here:
playcanvas/engine#5399

Support modification of material properties

Currently this plugin just creates a material with properties defined by the plugin. It is useful to choose some of these properties. For example:

  • should the texture be the diffusemap or emissivemap
  • if emissive, diffuse color should be (0,0,0)
  • user may wish to disable lighting/fog/tonemapping on material.

Data export from Spine 3.8.xx

Hello,

I use spine 3.8.xx version.. When I export data from spine to playcanvas it's not working because of version. In contrib/spine-ts there is a warning: Spine-ts works with data exported from Spine 3.6.xx.
What can I do to upgrade to 3.8.xx version(how can I create a compatible playcanvas-spine.js) or do you have a plan to create a new playcanvas-spine.min.js for 3.8.xx?

Thank you

Attaching listeners to AnimationState

Hi, I'm not sure where to ask questions regarding the PC runtime for Spine so I'm asking here.

Can you provide an example of how to use addListener()? The Spine User Guide wasn't able to help me in this regard.

Mention required "Power Of Two" export option.

This took a fair bit of head-scratching, so I'll post it here to avoid that problem in the future.
Since PlayCanvas resizes the textures to nearest power of two by default, this "Power of two" Spine export option has to be used.
image
(otherwise, image resizing has to be disabled in PlayCanvas Asset Task settings)

Spine Layer is set to UI Layer

The layer for spine rendering gets set to UI layer with this code in spine.js:

this._layers = [pc.LAYERID_UI];

Since one also wants to have UI rendererd over the spine characters, please consider to make this changeable via attributes.

Best,
Rene

Memory Leaks

I noticed that spine entities don't get freed in the memory. I used this project to reproduce this issue by having two scenes with one spine object each and you can switch between them. After each scene change, the previous spine entity can't get fully deleted. You can check this out by using the Memory Allocation Timeline of the chrome debugging tools. I explain it in further detail in this forum post.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.