Skip to content

Commit

Permalink
Merge pull request #2 from MikalDev/bone-control
Browse files Browse the repository at this point in the history
Bone control
  • Loading branch information
MikalDev authored Jan 31, 2021
2 parents cc253bd + bcb4481 commit af1e1ee
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 6 deletions.
Binary file added dist/Spine-v1.32.0.c3addon
Binary file not shown.
53 changes: 53 additions & 0 deletions src/aces.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,59 @@
"initialValue" : "\"\""
}
]
},
{
"id": "set-bone-control",
"scriptName": "SetBoneControl",
"highlight": false,
"params": [
{
"id": "bone",
"type": "string",
"initialValue" : "\"\""
},
{
"id": "property",
"type": "combo",
"items": [
"x",
"y",
"rotation",
"scale-x",
"scale-y"
],
"initialValue" : "x"
},
{
"id": "value",
"type": "number",
"initialValue" : 0
}
]
},
{
"id": "remove-bone-control",
"scriptName": "RemoveBoneControl",
"highlight": false,
"params": [
{
"id": "bone",
"type": "string",
"initialValue" : "\"\""
},
{
"id": "property",
"type": "combo",
"items": [
"x",
"y",
"rotation",
"scale-x",
"scale-y"
],
"initialValue" : "x"
}
]
}
],
"expressions": [
Expand Down
3 changes: 2 additions & 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.31.1",
"version": "1.32.0",
"author": "Mikal and Igor Gritsenko",
"website": "https://gritsenko.github.io/c3_spine_plugin",
"documentation": "https://gritsenko.github.io/c3_spine_plugin",
Expand All @@ -23,6 +23,7 @@
"c3runtime/spine-webgl.js",
"c3runtime/spine-draw.js",
"c3runtime/spine-gl-cache.js",
"c3runtime/spine-bone-control.js",
"lang/en-US.json",
"aces.json",
"addon.json",
Expand Down
12 changes: 12 additions & 0 deletions src/c3runtime/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@
if (!spineBatcher) {console.warn('[Spine] SetDebugVariable, no spineBatcher',name,value);return}
spineBatcher.debugVariables[name] = value;
if (this.debug) console.info('[Spine] SetDebugVariable',name,value,spineBatcher.debugVariables);
},

SetBoneControl(bone, propertyIndex, value)
{
let properties=['x','y','rotation','scaleX','scaleY'];
this.spineBoneControl.setBoneControl(bone, properties[propertyIndex], value);
},

RemoveBoneControl(bone, propertyIndex)
{
let properties=['x','y','rotation','scaleX','scaleY'];
this.spineBoneControl.removeBoneControl(bone, properties[propertyIndex]);
}

};
Expand Down
9 changes: 6 additions & 3 deletions src/c3runtime/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
this.mvp = new spine.webgl.Matrix4();
// this.shader = spine.webgl.Shader.newTwoColoredTextured(gl);
// this.batcher = new spine.webgl.PolygonBatcher(gl);
this.mvp.ortho2d(0, 0, 0, 0); // XXX Render to texture size unknown until skeleton loaded.
this.mvp.ortho2d(0, 0, 0, 0); // Texture size unknown at this point
// this.renderer = new spine.webgl.SkeletonRenderer(gl);
// this.shapes = new spine.webgl.ShapeRenderer(gl);
this.assetManager = new spine.SharedAssetManager();
Expand Down Expand Up @@ -176,7 +176,8 @@

this.resize();

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

loadSkeleton(name, animationName, sequenceSlots) {
Expand Down Expand Up @@ -347,7 +348,6 @@
{
state.tracks[trackIndex].listener = {
complete: (trackEntry, count) => {
// XXX this.completeAnimationName = trackEntry.animation.name;
this.completeAnimationName = this.trackAnimations[trackEntry.trackIndex];
this.completeTrackIndex = trackEntry.trackIndex;
this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnimationFinished);
Expand Down Expand Up @@ -518,7 +518,10 @@
}
state.update(delta);
state.apply(active.skeleton);
// Override bones under bone control
this.spineBoneControl.applyBoneControl(active.skeleton);
active.skeleton.updateWorldTransform();

this.runtime.UpdateRender();
if (this.animateOnce > 0)
{
Expand Down
49 changes: 49 additions & 0 deletions src/c3runtime/spine-bone-control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @ts-check
"use strict";

class SpineBoneControl {
constructor(debug) {
this._bones = {}
this._debug = debug;
}

get bones() {return this._bones;}
get debug() {return this._debug;}

setBoneControl(name, property, value) {
if (!this.bones[name])
{
this.bones[name] = {};
this.bones[name][property] = value;
} else
{
this.bones[name][property] = value;
}
}

removeBoneControl(bone, property) {
if (!this.bones[bone] || !this.bones[bone][property]) {console.warn('[Spine] removeBoneConrtol, no control', bone, property);return}
delete this.bones[bone][property];
}

applyBoneControl(skeleton) {
const bones = this.bones;
for(let boneName in bones)
{
let bone = skeleton.findBone(boneName);
if (!bone) {console.warn('[Spine] applyBoneControl bone not found', boneName);continue;}
for(const property in bones[boneName])
{
bone[property] = bones[boneName][property];
}
}
}

}

// @ts-ignore
if (!globalThis.SpineBoneControl)
{
// @ts-ignore
globalThis.SpineBoneControl = SpineBoneControl;
}
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.31.2');
console.log('[Spine] SpineBatcher init, 1.32.0');
globalThis.spineBatcher = new SpineBatch();
}
52 changes: 52 additions & 0 deletions src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,58 @@
"desc": "Value of variable (string)."
}
}
},
"set-bone-control": {
"list-name": "Set bone control",
"display-text": "Set {0} {1} to {2}",
"description": "Override bone property with value.",
"params": {
"bone": {
"name": "Bone",
"desc": "Name of bone."
},
"property": {
"name": "Property",
"desc": "Property to control.",
"items": {
"x": "X",
"y": "Y",
"rotation": "Rotation",
"scale-x": "Scale X",
"scale-y": "Scale Y"
}
},
"value": {
"name": "Value",
"desc": "Value of variable (string)."
}
}
},
"remove-bone-control": {
"list-name": "Remove bone control",
"display-text": "Remove {0} control of {1}",
"description": "Override bone property with value.",
"params": {
"bone": {
"name": "Bone",
"desc": "Name of bone."
},
"property": {
"name": "Property",
"desc": "Property to control.",
"items": {
"x": "X",
"y": "Y",
"rotation": "Rotation",
"scale-x": "Scale X",
"scale-y": "Scale Y"
}
},
"value": {
"name": "Value",
"desc": "Value of variable (string)."
}
}
}
},
"expressions": {
Expand Down
7 changes: 6 additions & 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.31.2";
const PLUGIN_VERSION = "1.32.0";
const PLUGIN_CATEGORY = "general";

const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {
Expand Down Expand Up @@ -49,6 +49,11 @@
filename: "c3runtime/spine-gl-cache.js",
type: "external-runtime-script"
});

this._info.AddFileDependency({
filename: "c3runtime/spine-bone-control.js",
type: "external-runtime-script"
});
// this._info.SetDOMSideScripts(["c3runtime/spine-webgl.js"]);


Expand Down

0 comments on commit af1e1ee

Please sign in to comment.