mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-19 00:06:42 +08:00
Add expressions to get bone-x, bone-y- bone-rotation.
This commit is contained in:
parent
c626d59b0e
commit
0c189465c7
@ -343,6 +343,42 @@
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "bone-x",
|
||||
"expressionName": "BoneX",
|
||||
"highlight": false,
|
||||
"returnType": "number",
|
||||
"params": [
|
||||
{
|
||||
"id": "bone-name",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "bone-y",
|
||||
"expressionName": "BoneY",
|
||||
"highlight": false,
|
||||
"returnType": "number",
|
||||
"params": [
|
||||
{
|
||||
"id": "bone-name",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "bone-rotation",
|
||||
"expressionName": "BoneRotation",
|
||||
"highlight": false,
|
||||
"returnType": "number",
|
||||
"params": [
|
||||
{
|
||||
"id": "bone-name",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -8,12 +8,25 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Exps =
|
||||
Double (this: SDKInstanceClass, num: number) {
|
||||
return num * 2;
|
||||
},
|
||||
|
||||
SlotAttachment (this: SDKInstanceClass, slotName: string) {
|
||||
if (!this.skeleton) return "";
|
||||
const slot = this.skeleton.findSlot(slotName);
|
||||
if (!slot) return "";
|
||||
const attachment = slot.pose.getAttachment();
|
||||
return attachment ? attachment.name : "";
|
||||
},
|
||||
|
||||
BoneX (this: SDKInstanceClass, boneName: string) {
|
||||
return this.getBoneX(boneName);
|
||||
},
|
||||
|
||||
BoneY (this: SDKInstanceClass, boneName: string) {
|
||||
return this.getBoneY(boneName);
|
||||
},
|
||||
|
||||
BoneRotation (this: SDKInstanceClass, boneName: string) {
|
||||
return this.getBoneRotation(boneName);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -355,6 +355,77 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
|
||||
}
|
||||
}
|
||||
|
||||
public getBoneX (boneName: string): number {
|
||||
const { skeleton } = this;
|
||||
if (!skeleton) {
|
||||
console.warn('[Spine] getBoneX: no skeleton');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bone = skeleton.findBone(boneName);
|
||||
if (!bone) {
|
||||
console.warn(`[Spine] getBoneX: bone not found: ${boneName}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const x = bone.applied.worldX;
|
||||
const y = bone.applied.worldY;
|
||||
const offsetX = this.x + this.propOffsetX;
|
||||
const offsetAngle = this.angle + this.propOffsetAngle;
|
||||
|
||||
if (offsetAngle) {
|
||||
const cos = Math.cos(offsetAngle);
|
||||
const sin = Math.sin(offsetAngle);
|
||||
return x * cos - y * sin + offsetX;
|
||||
}
|
||||
return x + offsetX;
|
||||
}
|
||||
|
||||
public getBoneY (boneName: string): number {
|
||||
const { skeleton } = this;
|
||||
if (!skeleton) {
|
||||
console.warn('[Spine] getBoneY: no skeleton');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bone = skeleton.findBone(boneName);
|
||||
if (!bone) {
|
||||
console.warn(`[Spine] getBoneY: bone not found: ${boneName}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const x = bone.applied.worldX;
|
||||
const y = bone.applied.worldY;
|
||||
const offsetY = this.y + this.propOffsetY;
|
||||
const offsetAngle = this.angle + this.propOffsetAngle;
|
||||
|
||||
if (offsetAngle) {
|
||||
const cos = Math.cos(offsetAngle);
|
||||
const sin = Math.sin(offsetAngle);
|
||||
return x * sin + y * cos + offsetY;
|
||||
}
|
||||
return y + offsetY;
|
||||
}
|
||||
|
||||
public getBoneRotation (boneName: string): number {
|
||||
const { skeleton } = this;
|
||||
if (!skeleton) {
|
||||
console.warn('[Spine] getBoneRotation: no skeleton');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bone = skeleton.findBone(boneName);
|
||||
if (!bone) {
|
||||
console.warn(`[Spine] getBoneRotation: bone not found: ${boneName}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const boneRotation = bone.applied.getWorldRotationX();
|
||||
const offsetAngle = this.angle + this.propOffsetAngle;
|
||||
|
||||
return boneRotation + (offsetAngle * 180 / Math.PI);
|
||||
}
|
||||
|
||||
private _setSkin () {
|
||||
const { skeleton } = this;
|
||||
if (!skeleton) return;
|
||||
|
||||
@ -426,6 +426,36 @@
|
||||
"desc": "Name of the slot"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-x": {
|
||||
"description": "Get the world X position of a bone.",
|
||||
"translated-name": "BoneX",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "Bone name",
|
||||
"desc": "Name of the bone"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-y": {
|
||||
"description": "Get the world Y position of a bone.",
|
||||
"translated-name": "BoneY",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "Bone name",
|
||||
"desc": "Name of the bone"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-rotation": {
|
||||
"description": "Get the world rotation of a bone.",
|
||||
"translated-name": "BoneRotation",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "Bone name",
|
||||
"desc": "Name of the bone"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,6 +426,36 @@
|
||||
"desc": "插槽的名称"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-x": {
|
||||
"description": "获取骨骼的世界X位置。",
|
||||
"translated-name": "BoneX",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "骨骼名称",
|
||||
"desc": "骨骼的名称"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-y": {
|
||||
"description": "获取骨骼的世界Y位置。",
|
||||
"translated-name": "BoneY",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "骨骼名称",
|
||||
"desc": "骨骼的名称"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bone-rotation": {
|
||||
"description": "获取骨骼的世界旋转角度。",
|
||||
"translated-name": "BoneRotation",
|
||||
"params": {
|
||||
"bone-name": {
|
||||
"name": "骨骼名称",
|
||||
"desc": "骨骼的名称"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user