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 #52 from MikalDev/master
Browse files Browse the repository at this point in the history
Init fixes
  • Loading branch information
MikalDev authored Feb 14, 2021
2 parents 932695c + 0f7c31a commit d1ff3d4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 18 deletions.
Binary file added dist/Spine-v1.36.3.c3addon
Binary file not shown.
Binary file added dist/Spine-v1.36.4.c3addon
Binary file not shown.
Binary file added dist/Spine-v1.36.5.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.2",
"version": "1.36.5",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand Down
10 changes: 10 additions & 0 deletions src/c3runtime/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@
for(slotName in this.slotColors)
{
let slot = skeleton.findSlot(slotName);
if (slot === null)
{
console.warn("[Spine] ApplySlotColors, slot not found: ",slotName,this.uid,this.runtime.GetTickCount());
continue;
}
let color = this.slotColors[slotName];
slot.color.set(
spineBatcher.getRValue(color),
Expand All @@ -259,6 +264,11 @@
for(slotName in this.slotDarkColors)
{
let slot = skeleton.findSlot(slotName);
if (slot === null)
{
console.warn("[Spine] ApplySlotColors dark color, slot not found: ",slotName,this.uid,this.runtime.GetTickCount());
continue;
}
// Set only if dark Color is available, (Tint Black must be applied to the slot in the project.)
if (slot.darkColor)
{
Expand Down
43 changes: 29 additions & 14 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
this.isPlaying = true;
this.instance = inst;

this.isSkeletonLoaded = false;
this.skeletonInfo = null;
this.renderer = null;
this.gl = null;
Expand All @@ -30,6 +29,7 @@
this.sdkType = this.GetSdkType();

this.atlasPath = "";
this.objectName = this.GetInstance().GetObjectClass().GetName();

if (properties) {
this.jsonPath = properties[0];
Expand All @@ -48,7 +48,6 @@
}

this.isMirrored = false;
this._elementId = "";

this._elementTexture = null

Expand Down Expand Up @@ -83,7 +82,6 @@
initInstance()
{
this.initSpineInProgress = true;
this._elementId = 1; // XXX remove when possible
// Init Spine elements
this.mvp = new spine.webgl.Matrix4();
this.mvp.ortho2d(0, 0, 0, 0); // Texture size unknown at this point
Expand Down Expand Up @@ -165,8 +163,15 @@
// Sentry error reported
if (atlasURI === undefined || atlasURI === null)
{
console.warn('[Spine] loadSkeletonData, atlasURI not set', atlasURI, assetTag, this.atlasURI, assetManager.isLoadingComplete(assetTag), this.atlasPath);
console.warn('[Spine] loadSkeletonData, atlasURI not set', atlasURI, assetTag, this.atlasURI, assetManager.isLoadingComplete(assetTag), this.atlasPath, this.runtime.GetTickCount());
console.warn('[Spine] objectclass',this.objectName, this.sdkType, this.runtime.GetTickCount());
if (globalThis.Sentry)
{
globalThis.Sentry.captureException('[Spine] loadSkeletonData, atlasURI not set, object:'+this.objectName);
}
return;
}

this.sdkType._atlas = new spine.TextureAtlas(atlasURI, function(path) {
return assetManager.get(self.sdkType._assetTag, self.sdkType._assetPaths[path]);
});
Expand Down Expand Up @@ -198,16 +203,14 @@
const animations = this.skeletonInfo.skeleton.data.animations;
this.animationNames = animations.map(x => x.name);

this.isSkeletonLoaded = true;

this.resize();

spineBatcher.addInstance(this.skeletonInfo, this.skeletonScale, this.GetInstance().GetUID());
this.spineBoneControl = new SpineBoneControl(this.debug);
}

loadSkeleton(name, animationName, sequenceSlots) {
if (this.debug) console.info("[Spine] Reading skeleton data:", this.uid, name, animationName);
if (this.debug) console.info("[Spine] Reading skeleton data:", this.uid, this.sdkType.GetObjectClass().GetName(), animationName);
// If skeletonData not initialized, create it and stop other instances from creating it

let skeleton = new spine.Skeleton(this.sdkType._skeletonData);
Expand Down Expand Up @@ -424,8 +427,19 @@
this.isPlaying = false;
}

IsSpineReady() {
if (this.isSkeletonLoaded) {
async IsSpineReady() {
// Guard for case where sdkType does not exist (deleted on release)
if (this.sdkType === null || this.sdkType === undefined)
{
if (this.debug) console.warn('[Spine] IsSpineReady, sdkType not defined', this.sdkType);
if (globalThis.Sentry)
{
globalThis.Sentry.captureException('[Spine] IsSpineReady, sdkType not defined:'+this.sdkType);
}
return false;
}

if (this.isLoaded) {
return true;
}

Expand All @@ -441,7 +455,7 @@
if(!this.sdkType._texturesBatcherInitializing)
{
this.sdkType._texturesBatcherInitializing = true;
this.initTexturesBatcher();
await this.initTexturesBatcher();
}
return false;
}
Expand Down Expand Up @@ -485,7 +499,6 @@
this.canvas = null;
this.bgColor = null;
this.isPlaying = null;
this.isSkeletonLoaded = null;
this.skeletonInfo = null;
this.renderer = null;
this.gl = null;
Expand All @@ -501,7 +514,6 @@
this.collisionsEnabled = null;
this.defaultMix = null;
this.isMirrored = null;
this._elementId = null;
this._elementTexture = null
this.pngURI = null;
this.atlasURI = null;
Expand All @@ -527,7 +539,10 @@
}

Tick() {
if (!this.IsSpineReady()) {
// Async function, set this.isLoaded on completion
this.IsSpineReady();

if (!this.isLoaded) {
return;
}

Expand Down Expand Up @@ -609,7 +624,7 @@

var gl = renderer._gl

if (this._elementId == "" || !this.isSkeletonLoaded) return; // elementID not set, can't draw the element
if (!this.isLoaded) return; // Spine instance not loaded, can't draw

var myCanvas = this.canvas;

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.2');
console.log('[Spine] SpineBatcher init, 1.36.5');
globalThis.spineBatcher = new SpineBatch();
}
2 changes: 2 additions & 0 deletions src/c3runtime/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

Release()
{
console.warn('[Spine] type.Release', this.GetObjectClass().GetName(), this._runtime.GetTickCount())
super.Release();
}

OnCreate()
{
console.info('[Spine] type.OnCreate', this.GetObjectClass().GetName(), this._runtime.GetTickCount())
this.GetImageInfo().LoadAsset(this._runtime);
this._skeletonDataInitialized = false;
this._skeletonDataInitializing = false;
Expand Down
4 changes: 2 additions & 2 deletions 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.2";
const PLUGIN_VERSION = "1.36.5";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand All @@ -23,7 +23,7 @@
this._info.SetIsRotatable(true); // allow to be rotated
this._info.SetHasImage(true);
this._info.SetSupportsEffects(true); // allow effects
this._info.SetMustPreDraw(true);
this._info.SetMustPreDraw(false);
this._info.AddCommonPositionACEs();
this._info.AddCommonAngleACEs();
this._info.AddCommonAppearanceACEs();
Expand Down

0 comments on commit d1ff3d4

Please sign in to comment.