Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from MikalDev/master
Browse files Browse the repository at this point in the history
Add link to Bone Control project, add warnings on init if atlasURI blank
  • Loading branch information
MikalDev authored Feb 11, 2021
2 parents 7859c35 + a9ff506 commit 932695c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Add-on based on **Mikal's** sample from this [thread](https://www.construct.net/

[BoundingBoxMesh project](https://github.com/gritsenko/c3_spine_plugin/releases/download/1.18.0/SpineBBoxMesh.c3p)

[AimBoneControl project](https://github.com/gritsenko/c3_spine_plugin/releases/download/1.36.1/SpineboyAimBoneControl.c3p)

## LIVE DEMO
[Live Demo](https://gritsenko.github.io/c3_spine_plugin/docs/LiveDemo/index.html)

Expand Down
Binary file added dist/Spine-v1.36.2.c3addon
Binary file not shown.
2 changes: 1 addition & 1 deletion src/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "plugin",
"name": "Spine",
"id": "Gritsenko_Spine",
"version": "1.36.1",
"version": "1.36.2",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
82 changes: 45 additions & 37 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
this.trackAnimations = {};
this.skinNames = [];
this.delayedTrackListeners = [];
this.sdkType = this.GetSdkType();

this.atlasPath = "";

Expand Down Expand Up @@ -92,12 +93,12 @@
}

async initTexturesBatcher() {
this._sdkType._texturesBatcherInitializing = true;
this.sdkType._texturesBatcherInitializing = true;
// Init spineBatcher (only initializes once)
spineBatcher.init(this.canvas, this.runtime);
await this.loadSkeletonTextures();
this._sdkType._texturesBatcherInitialized = true;
this._sdkType._texturesBatcherInitializing = false;
this.sdkType._texturesBatcherInitialized = true;
this.sdkType._texturesBatcherInitializing = false;
}

resize() {
Expand All @@ -118,10 +119,10 @@

async loadSkeletonTextures()
{
this._sdkType._assetManager = new spine.SharedAssetManager();
this._sdkType._assetTag = this.uid;
const assetManager = this._sdkType._assetManager;
const assetTag = this._sdkType._assetTag;
this.sdkType._assetManager = new spine.SharedAssetManager();
this.sdkType._assetTag = this.uid;
const assetManager = this.sdkType._assetManager;
const assetTag = this.sdkType._assetTag;
const gl = this.gl;

if (this.debug) console.info(this.GetInstance().GetUID(),'[Spine] Loading skeleton, textures, json, atlas');
Expand All @@ -131,11 +132,11 @@

// Path translation for json and atlast (1:1)
this.atlasURI = await this.runtime._assetManager.GetProjectFileUrl(this.atlasPath);
this._sdkType._assetPaths[this.atlasURI] = this.atlasURI;
this._sdkType._assetPaths[this.atlasPath] = this.atlasURI;
this.sdkType._assetPaths[this.atlasURI] = this.atlasURI;
this.sdkType._assetPaths[this.atlasPath] = this.atlasURI;
this.jsonURI = await this.runtime._assetManager.GetProjectFileUrl(this.jsonPath);
this._sdkType._assetPaths[this.jsonURI] = this.jsonURI;
this._sdkType._assetPaths[this.jsonPath] = this.jsonURI;
this.sdkType._assetPaths[this.jsonURI] = this.jsonURI;
this.sdkType._assetPaths[this.jsonPath] = this.jsonURI;

assetManager.loadJson(assetTag, this.jsonURI);

Expand All @@ -146,7 +147,7 @@
for(let i=0;i<assetPaths.length;i++)
{
this.pngURI = await this.runtime._assetManager.GetProjectFileUrl(assetPaths[i]);
this._sdkType._assetPaths[assetPaths[i]] = this.pngURI;
this.sdkType._assetPaths[assetPaths[i]] = this.pngURI;
assetManager.loadTexture(assetTag, textureLoader, this.pngURI);
}

Expand All @@ -155,29 +156,35 @@

loadSkeletonData()
{
const assetManager = this._sdkType._assetManager;;
const assetTag = this._sdkType._assetTag;
const assetManager = this.sdkType._assetManager;;
const assetTag = this.sdkType._assetTag;
const self = this;

const atlasURI = assetManager.get(assetTag, this.atlasURI);
this._sdkType._atlas = new spine.TextureAtlas(atlasURI, function(path) {
return assetManager.get(self._sdkType._assetTag, self._sdkType._assetPaths[path]);

// Sentry error reported
if (atlasURI === undefined || atlasURI === null)
{
console.warn('[Spine] loadSkeletonData, atlasURI not set', atlasURI, assetTag, this.atlasURI, assetManager.isLoadingComplete(assetTag), this.atlasPath);
}
this.sdkType._atlas = new spine.TextureAtlas(atlasURI, function(path) {
return assetManager.get(self.sdkType._assetTag, self.sdkType._assetPaths[path]);
});
this._sdkType._atlasLoader = new spine.AtlasAttachmentLoader(this._sdkType._atlas);
this.sdkType._atlasLoader = new spine.AtlasAttachmentLoader(this.sdkType._atlas);

this._sdkType._skeletonJson = new spine.SkeletonJson(this._sdkType._atlasLoader);
this._sdkType._skeletonJson.scale = this.skeletonRenderQuality;
this.sdkType._skeletonJson = new spine.SkeletonJson(this.sdkType._atlasLoader);
this.sdkType._skeletonJson.scale = this.skeletonRenderQuality;
// JSON file with one skeleton, no name
this._sdkType._jsonURI = this.jsonURI;
this.sdkType._jsonURI = this.jsonURI;
if (this.skeletonName == "")
{
this._sdkType._skeletonData = this._sdkType._skeletonJson.readSkeletonData(assetManager.get(assetTag, this.jsonURI));
this.sdkType._skeletonData = this.sdkType._skeletonJson.readSkeletonData(assetManager.get(assetTag, this.jsonURI));
} else
{
this._sdkType._skeletonData = this._sdkType._skeletonJson.readSkeletonData(assetManager.get(assetTag, this.jsonURI) [this.skeletonName] );
this.sdkType._skeletonData = this.sdkType._skeletonJson.readSkeletonData(assetManager.get(assetTag, this.jsonURI) [this.skeletonName] );
}
this._sdkType._skeletonDataInitialized = true;
this._sdkType._skeletonDataInitializing = false;
this.sdkType._skeletonDataInitialized = true;
this.sdkType._skeletonDataInitializing = false;
}

loadSkeletons() {
Expand All @@ -203,15 +210,15 @@
if (this.debug) console.info("[Spine] Reading skeleton data:", this.uid, name, animationName);
// If skeletonData not initialized, create it and stop other instances from creating it

let skeleton = new spine.Skeleton(this._sdkType._skeletonData);
let skeleton = new spine.Skeleton(this.sdkType._skeletonData);
let subskin = skeleton.data.findSkin(this.skinName);
if (subskin === undefined) {
subskin = skeleton.data.skins[0];
}

skeleton.setSkin(subskin);

let stateData = new spine.AnimationStateData(this._sdkType._skeletonData);
let stateData = new spine.AnimationStateData(this.sdkType._skeletonData);
stateData.defaultMix = this.defaultMix;

var state = new spine.AnimationState(stateData);
Expand Down Expand Up @@ -247,15 +254,15 @@
}

return {
atlas: this._sdkType._atlas,
atlas: this.sdkType._atlas,
skeleton: skeleton,
state: state,
playTime: 0,
bounds: {
offset: offset,
size: size
},
atlasLoader : this._sdkType._atlasLoader,
atlasLoader : this.sdkType._atlasLoader,
skeletonBounds: skeletonBounds,
stateData: stateData
};
Expand Down Expand Up @@ -418,9 +425,6 @@
}

IsSpineReady() {
const assetManager = this._sdkType._assetManager;
const assetTag = this._sdkType._assetTag;

if (this.isSkeletonLoaded) {
return true;
}
Expand All @@ -432,28 +436,31 @@
}

// Once per object, load texture assets, init spinebatcher
if (!this._sdkType._texturesBatcherInitialized)
if (!this.sdkType._texturesBatcherInitialized)
{
if(!this._sdkType._texturesBatcherInitializing)
if(!this.sdkType._texturesBatcherInitializing)
{
this._sdkType._texturesBatcherInitializing = true;
this.sdkType._texturesBatcherInitializing = true;
this.initTexturesBatcher();
}
return false;
}

const assetManager = this.sdkType._assetManager;
const assetTag = this.sdkType._assetTag;

// Once per object, wait for assets to complete loading
if (!assetManager.isLoadingComplete(assetTag))
{
return false;
}

// Once per object, load skeletonData, load assets
if (!this._sdkType._skeletonDataInitialized)
if (!this.sdkType._skeletonDataInitialized)
{
if(!this._sdkType._skeletonDataInitializing)
if(!this.sdkType._skeletonDataInitializing)
{
this._sdkType._skeletonDataInitializing = true;
this.sdkType._skeletonDataInitializing = true;
this.loadSkeletonData();
}
return false;
Expand Down Expand Up @@ -516,6 +523,7 @@
this.slotColors = null;
this.slotDarkColors = null;
this.spineBoneControl = null;
this.sdkType = null;
}

Tick() {
Expand Down
2 changes: 1 addition & 1 deletion src/c3runtime/spine-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ class SpineBatch {

if (!globalThis.spineBatcher)
{
console.log('[Spine] SpineBatcher init, 1.36.1');
console.log('[Spine] SpineBatcher init, 1.36.2');
globalThis.spineBatcher = new SpineBatch();
}
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const C3 = self.C3;

const PLUGIN_ID = "Gritsenko_Spine";
const PLUGIN_VERSION = "1.36.1";
const PLUGIN_VERSION = "1.36.2";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down

0 comments on commit 932695c

Please sign in to comment.