mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts][threejs] SkeletonMesh now takes an option SkeletonMeshMaterialParametersCustomizer function that allows you to modify the ShaderMaterialParameters before the material is finalized. Use it to modify things like THREEJS' Material.depthTest etc. See #1590.
This commit is contained in:
parent
a659b70f18
commit
e60a60ccd5
10
spine-ts/build/spine-all.d.ts
vendored
10
spine-ts/build/spine-all.d.ts
vendored
@ -1811,7 +1811,7 @@ declare module spine.threejs {
|
|||||||
private verticesLength;
|
private verticesLength;
|
||||||
private indices;
|
private indices;
|
||||||
private indicesLength;
|
private indicesLength;
|
||||||
constructor(maxVertices?: number);
|
constructor(maxVertices?: number, materialCustomizer?: SkeletonMeshMaterialParametersCustomizer);
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
clear(): void;
|
clear(): void;
|
||||||
begin(): void;
|
begin(): void;
|
||||||
@ -1821,8 +1821,11 @@ declare module spine.threejs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module spine.threejs {
|
declare module spine.threejs {
|
||||||
|
interface SkeletonMeshMaterialParametersCustomizer {
|
||||||
|
(materialParameters: THREE.ShaderMaterialParameters): void;
|
||||||
|
}
|
||||||
class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
||||||
constructor();
|
constructor(customizer: SkeletonMeshMaterialParametersCustomizer);
|
||||||
}
|
}
|
||||||
class SkeletonMesh extends THREE.Object3D {
|
class SkeletonMesh extends THREE.Object3D {
|
||||||
tempPos: Vector2;
|
tempPos: Vector2;
|
||||||
@ -1840,7 +1843,8 @@ declare module spine.threejs {
|
|||||||
static VERTEX_SIZE: number;
|
static VERTEX_SIZE: number;
|
||||||
private vertices;
|
private vertices;
|
||||||
private tempColor;
|
private tempColor;
|
||||||
constructor(skeletonData: SkeletonData);
|
private materialCustomizer;
|
||||||
|
constructor(skeletonData: SkeletonData, materialCustomizer?: SkeletonMeshMaterialParametersCustomizer);
|
||||||
update(deltaTime: number): void;
|
update(deltaTime: number): void;
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
private clearBatches;
|
private clearBatches;
|
||||||
|
|||||||
@ -2819,10 +2819,25 @@ var spine;
|
|||||||
if (!bone.appliedValid)
|
if (!bone.appliedValid)
|
||||||
bone.updateAppliedTransform();
|
bone.updateAppliedTransform();
|
||||||
var p = bone.parent;
|
var p = bone.parent;
|
||||||
var id = 1 / (p.a * p.d - p.b * p.c);
|
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
|
var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.OnlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case spine.TransformMode.NoRotationOrReflection:
|
||||||
|
rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
|
||||||
|
var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
default:
|
||||||
var x = targetX - p.worldX, y = targetY - p.worldY;
|
var x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
var d = pa * pd - pb * pc;
|
||||||
var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
|
||||||
if (bone.ascaleX < 0)
|
if (bone.ascaleX < 0)
|
||||||
rotationIK += 180;
|
rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
@ -2831,6 +2846,12 @@ var spine;
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
var sx = bone.ascaleX, sy = bone.ascaleY;
|
var sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.NoScale:
|
||||||
|
case spine.TransformMode.NoScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s = (dd / b - 1) * alpha + 1;
|
var s = (dd / b - 1) * alpha + 1;
|
||||||
@ -4060,6 +4081,8 @@ var spine;
|
|||||||
var input = new BinaryInput(binary);
|
var input = new BinaryInput(binary);
|
||||||
skeletonData.hash = input.readString();
|
skeletonData.hash = input.readString();
|
||||||
skeletonData.version = input.readString();
|
skeletonData.version = input.readString();
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = input.readFloat();
|
skeletonData.x = input.readFloat();
|
||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
@ -5470,6 +5493,8 @@ var spine;
|
|||||||
if (skeletonMap != null) {
|
if (skeletonMap != null) {
|
||||||
skeletonData.hash = skeletonMap.hash;
|
skeletonData.hash = skeletonMap.hash;
|
||||||
skeletonData.version = skeletonMap.spine;
|
skeletonData.version = skeletonMap.spine;
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = skeletonMap.x;
|
skeletonData.x = skeletonMap.x;
|
||||||
skeletonData.y = skeletonMap.y;
|
skeletonData.y = skeletonMap.y;
|
||||||
skeletonData.width = skeletonMap.width;
|
skeletonData.width = skeletonMap.width;
|
||||||
@ -11043,8 +11068,9 @@ var spine;
|
|||||||
(function (threejs) {
|
(function (threejs) {
|
||||||
var MeshBatcher = (function (_super) {
|
var MeshBatcher = (function (_super) {
|
||||||
__extends(MeshBatcher, _super);
|
__extends(MeshBatcher, _super);
|
||||||
function MeshBatcher(maxVertices) {
|
function MeshBatcher(maxVertices, materialCustomizer) {
|
||||||
if (maxVertices === void 0) { maxVertices = 10920; }
|
if (maxVertices === void 0) { maxVertices = 10920; }
|
||||||
|
if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.verticesLength = 0;
|
_this.verticesLength = 0;
|
||||||
_this.indicesLength = 0;
|
_this.indicesLength = 0;
|
||||||
@ -11064,7 +11090,7 @@ var spine;
|
|||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = 0;
|
geo.drawRange.count = 0;
|
||||||
_this.geometry = geo;
|
_this.geometry = geo;
|
||||||
_this.material = new threejs.SkeletonMeshMaterial();
|
_this.material = new threejs.SkeletonMeshMaterial(materialCustomizer);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
MeshBatcher.prototype.dispose = function () {
|
MeshBatcher.prototype.dispose = function () {
|
||||||
@ -11142,7 +11168,7 @@ var spine;
|
|||||||
(function (threejs) {
|
(function (threejs) {
|
||||||
var SkeletonMeshMaterial = (function (_super) {
|
var SkeletonMeshMaterial = (function (_super) {
|
||||||
__extends(SkeletonMeshMaterial, _super);
|
__extends(SkeletonMeshMaterial, _super);
|
||||||
function SkeletonMeshMaterial() {
|
function SkeletonMeshMaterial(customizer) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var vertexShader = "\n\t\t\t\tattribute vec4 color;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tvColor = color;\n\t\t\t\t\tgl_Position = projectionMatrix*modelViewMatrix*vec4(position,1.0);\n\t\t\t\t}\n\t\t\t";
|
var vertexShader = "\n\t\t\t\tattribute vec4 color;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tvColor = color;\n\t\t\t\t\tgl_Position = projectionMatrix*modelViewMatrix*vec4(position,1.0);\n\t\t\t\t}\n\t\t\t";
|
||||||
var fragmentShader = "\n\t\t\t\tuniform sampler2D map;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main(void) {\n\t\t\t\t\tgl_FragColor = texture2D(map, vUv)*vColor;\n\t\t\t\t}\n\t\t\t";
|
var fragmentShader = "\n\t\t\t\tuniform sampler2D map;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main(void) {\n\t\t\t\t\tgl_FragColor = texture2D(map, vUv)*vColor;\n\t\t\t\t}\n\t\t\t";
|
||||||
@ -11156,6 +11182,7 @@ var spine;
|
|||||||
transparent: true,
|
transparent: true,
|
||||||
alphaTest: 0.5
|
alphaTest: 0.5
|
||||||
};
|
};
|
||||||
|
customizer(parameters);
|
||||||
_this = _super.call(this, parameters) || this;
|
_this = _super.call(this, parameters) || this;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@ -11165,7 +11192,8 @@ var spine;
|
|||||||
threejs.SkeletonMeshMaterial = SkeletonMeshMaterial;
|
threejs.SkeletonMeshMaterial = SkeletonMeshMaterial;
|
||||||
var SkeletonMesh = (function (_super) {
|
var SkeletonMesh = (function (_super) {
|
||||||
__extends(SkeletonMesh, _super);
|
__extends(SkeletonMesh, _super);
|
||||||
function SkeletonMesh(skeletonData) {
|
function SkeletonMesh(skeletonData, materialCustomizer) {
|
||||||
|
if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.tempPos = new spine.Vector2();
|
_this.tempPos = new spine.Vector2();
|
||||||
_this.tempUv = new spine.Vector2();
|
_this.tempUv = new spine.Vector2();
|
||||||
@ -11177,6 +11205,7 @@ var spine;
|
|||||||
_this.clipper = new spine.SkeletonClipping();
|
_this.clipper = new spine.SkeletonClipping();
|
||||||
_this.vertices = spine.Utils.newFloatArray(1024);
|
_this.vertices = spine.Utils.newFloatArray(1024);
|
||||||
_this.tempColor = new spine.Color();
|
_this.tempColor = new spine.Color();
|
||||||
|
_this.materialCustomizer = materialCustomizer;
|
||||||
_this.skeleton = new spine.Skeleton(skeletonData);
|
_this.skeleton = new spine.Skeleton(skeletonData);
|
||||||
var animData = new spine.AnimationStateData(skeletonData);
|
var animData = new spine.AnimationStateData(skeletonData);
|
||||||
_this.state = new spine.AnimationState(animData);
|
_this.state = new spine.AnimationState(animData);
|
||||||
@ -11204,7 +11233,7 @@ var spine;
|
|||||||
};
|
};
|
||||||
SkeletonMesh.prototype.nextBatch = function () {
|
SkeletonMesh.prototype.nextBatch = function () {
|
||||||
if (this.batches.length == this.nextBatchIndex) {
|
if (this.batches.length == this.nextBatchIndex) {
|
||||||
var batch_1 = new threejs.MeshBatcher();
|
var batch_1 = new threejs.MeshBatcher(10920, this.materialCustomizer);
|
||||||
this.add(batch_1);
|
this.add(batch_1);
|
||||||
this.batches.push(batch_1);
|
this.batches.push(batch_1);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2819,10 +2819,25 @@ var spine;
|
|||||||
if (!bone.appliedValid)
|
if (!bone.appliedValid)
|
||||||
bone.updateAppliedTransform();
|
bone.updateAppliedTransform();
|
||||||
var p = bone.parent;
|
var p = bone.parent;
|
||||||
var id = 1 / (p.a * p.d - p.b * p.c);
|
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
|
var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.OnlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case spine.TransformMode.NoRotationOrReflection:
|
||||||
|
rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
|
||||||
|
var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
default:
|
||||||
var x = targetX - p.worldX, y = targetY - p.worldY;
|
var x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
var d = pa * pd - pb * pc;
|
||||||
var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
|
||||||
if (bone.ascaleX < 0)
|
if (bone.ascaleX < 0)
|
||||||
rotationIK += 180;
|
rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
@ -2831,6 +2846,12 @@ var spine;
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
var sx = bone.ascaleX, sy = bone.ascaleY;
|
var sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.NoScale:
|
||||||
|
case spine.TransformMode.NoScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s = (dd / b - 1) * alpha + 1;
|
var s = (dd / b - 1) * alpha + 1;
|
||||||
@ -4060,6 +4081,8 @@ var spine;
|
|||||||
var input = new BinaryInput(binary);
|
var input = new BinaryInput(binary);
|
||||||
skeletonData.hash = input.readString();
|
skeletonData.hash = input.readString();
|
||||||
skeletonData.version = input.readString();
|
skeletonData.version = input.readString();
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = input.readFloat();
|
skeletonData.x = input.readFloat();
|
||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
@ -5470,6 +5493,8 @@ var spine;
|
|||||||
if (skeletonMap != null) {
|
if (skeletonMap != null) {
|
||||||
skeletonData.hash = skeletonMap.hash;
|
skeletonData.hash = skeletonMap.hash;
|
||||||
skeletonData.version = skeletonMap.spine;
|
skeletonData.version = skeletonMap.spine;
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = skeletonMap.x;
|
skeletonData.x = skeletonMap.x;
|
||||||
skeletonData.y = skeletonMap.y;
|
skeletonData.y = skeletonMap.y;
|
||||||
skeletonData.width = skeletonMap.width;
|
skeletonData.width = skeletonMap.width;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2819,10 +2819,25 @@ var spine;
|
|||||||
if (!bone.appliedValid)
|
if (!bone.appliedValid)
|
||||||
bone.updateAppliedTransform();
|
bone.updateAppliedTransform();
|
||||||
var p = bone.parent;
|
var p = bone.parent;
|
||||||
var id = 1 / (p.a * p.d - p.b * p.c);
|
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
|
var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.OnlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case spine.TransformMode.NoRotationOrReflection:
|
||||||
|
rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
|
||||||
|
var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
default:
|
||||||
var x = targetX - p.worldX, y = targetY - p.worldY;
|
var x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
var d = pa * pd - pb * pc;
|
||||||
var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
|
||||||
if (bone.ascaleX < 0)
|
if (bone.ascaleX < 0)
|
||||||
rotationIK += 180;
|
rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
@ -2831,6 +2846,12 @@ var spine;
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
var sx = bone.ascaleX, sy = bone.ascaleY;
|
var sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.NoScale:
|
||||||
|
case spine.TransformMode.NoScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s = (dd / b - 1) * alpha + 1;
|
var s = (dd / b - 1) * alpha + 1;
|
||||||
@ -4060,6 +4081,8 @@ var spine;
|
|||||||
var input = new BinaryInput(binary);
|
var input = new BinaryInput(binary);
|
||||||
skeletonData.hash = input.readString();
|
skeletonData.hash = input.readString();
|
||||||
skeletonData.version = input.readString();
|
skeletonData.version = input.readString();
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = input.readFloat();
|
skeletonData.x = input.readFloat();
|
||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
@ -5470,6 +5493,8 @@ var spine;
|
|||||||
if (skeletonMap != null) {
|
if (skeletonMap != null) {
|
||||||
skeletonData.hash = skeletonMap.hash;
|
skeletonData.hash = skeletonMap.hash;
|
||||||
skeletonData.version = skeletonMap.spine;
|
skeletonData.version = skeletonMap.spine;
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = skeletonMap.x;
|
skeletonData.x = skeletonMap.x;
|
||||||
skeletonData.y = skeletonMap.y;
|
skeletonData.y = skeletonMap.y;
|
||||||
skeletonData.width = skeletonMap.width;
|
skeletonData.width = skeletonMap.width;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2819,10 +2819,25 @@ var spine;
|
|||||||
if (!bone.appliedValid)
|
if (!bone.appliedValid)
|
||||||
bone.updateAppliedTransform();
|
bone.updateAppliedTransform();
|
||||||
var p = bone.parent;
|
var p = bone.parent;
|
||||||
var id = 1 / (p.a * p.d - p.b * p.c);
|
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
|
var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.OnlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case spine.TransformMode.NoRotationOrReflection:
|
||||||
|
rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
|
||||||
|
var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
default:
|
||||||
var x = targetX - p.worldX, y = targetY - p.worldY;
|
var x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
var d = pa * pd - pb * pc;
|
||||||
var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
|
||||||
if (bone.ascaleX < 0)
|
if (bone.ascaleX < 0)
|
||||||
rotationIK += 180;
|
rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
@ -2831,6 +2846,12 @@ var spine;
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
var sx = bone.ascaleX, sy = bone.ascaleY;
|
var sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.NoScale:
|
||||||
|
case spine.TransformMode.NoScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s = (dd / b - 1) * alpha + 1;
|
var s = (dd / b - 1) * alpha + 1;
|
||||||
@ -4060,6 +4081,8 @@ var spine;
|
|||||||
var input = new BinaryInput(binary);
|
var input = new BinaryInput(binary);
|
||||||
skeletonData.hash = input.readString();
|
skeletonData.hash = input.readString();
|
||||||
skeletonData.version = input.readString();
|
skeletonData.version = input.readString();
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = input.readFloat();
|
skeletonData.x = input.readFloat();
|
||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
@ -5470,6 +5493,8 @@ var spine;
|
|||||||
if (skeletonMap != null) {
|
if (skeletonMap != null) {
|
||||||
skeletonData.hash = skeletonMap.hash;
|
skeletonData.hash = skeletonMap.hash;
|
||||||
skeletonData.version = skeletonMap.spine;
|
skeletonData.version = skeletonMap.spine;
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = skeletonMap.x;
|
skeletonData.x = skeletonMap.x;
|
||||||
skeletonData.y = skeletonMap.y;
|
skeletonData.y = skeletonMap.y;
|
||||||
skeletonData.width = skeletonMap.width;
|
skeletonData.width = skeletonMap.width;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
10
spine-ts/build/spine-threejs.d.ts
vendored
10
spine-ts/build/spine-threejs.d.ts
vendored
@ -1343,7 +1343,7 @@ declare module spine.threejs {
|
|||||||
private verticesLength;
|
private verticesLength;
|
||||||
private indices;
|
private indices;
|
||||||
private indicesLength;
|
private indicesLength;
|
||||||
constructor(maxVertices?: number);
|
constructor(maxVertices?: number, materialCustomizer?: SkeletonMeshMaterialParametersCustomizer);
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
clear(): void;
|
clear(): void;
|
||||||
begin(): void;
|
begin(): void;
|
||||||
@ -1353,8 +1353,11 @@ declare module spine.threejs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module spine.threejs {
|
declare module spine.threejs {
|
||||||
|
interface SkeletonMeshMaterialParametersCustomizer {
|
||||||
|
(materialParameters: THREE.ShaderMaterialParameters): void;
|
||||||
|
}
|
||||||
class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
||||||
constructor();
|
constructor(customizer: SkeletonMeshMaterialParametersCustomizer);
|
||||||
}
|
}
|
||||||
class SkeletonMesh extends THREE.Object3D {
|
class SkeletonMesh extends THREE.Object3D {
|
||||||
tempPos: Vector2;
|
tempPos: Vector2;
|
||||||
@ -1372,7 +1375,8 @@ declare module spine.threejs {
|
|||||||
static VERTEX_SIZE: number;
|
static VERTEX_SIZE: number;
|
||||||
private vertices;
|
private vertices;
|
||||||
private tempColor;
|
private tempColor;
|
||||||
constructor(skeletonData: SkeletonData);
|
private materialCustomizer;
|
||||||
|
constructor(skeletonData: SkeletonData, materialCustomizer?: SkeletonMeshMaterialParametersCustomizer);
|
||||||
update(deltaTime: number): void;
|
update(deltaTime: number): void;
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
private clearBatches;
|
private clearBatches;
|
||||||
|
|||||||
@ -8171,8 +8171,9 @@ var spine;
|
|||||||
(function (threejs) {
|
(function (threejs) {
|
||||||
var MeshBatcher = (function (_super) {
|
var MeshBatcher = (function (_super) {
|
||||||
__extends(MeshBatcher, _super);
|
__extends(MeshBatcher, _super);
|
||||||
function MeshBatcher(maxVertices) {
|
function MeshBatcher(maxVertices, materialCustomizer) {
|
||||||
if (maxVertices === void 0) { maxVertices = 10920; }
|
if (maxVertices === void 0) { maxVertices = 10920; }
|
||||||
|
if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.verticesLength = 0;
|
_this.verticesLength = 0;
|
||||||
_this.indicesLength = 0;
|
_this.indicesLength = 0;
|
||||||
@ -8192,7 +8193,7 @@ var spine;
|
|||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = 0;
|
geo.drawRange.count = 0;
|
||||||
_this.geometry = geo;
|
_this.geometry = geo;
|
||||||
_this.material = new threejs.SkeletonMeshMaterial();
|
_this.material = new threejs.SkeletonMeshMaterial(materialCustomizer);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
MeshBatcher.prototype.dispose = function () {
|
MeshBatcher.prototype.dispose = function () {
|
||||||
@ -8270,7 +8271,7 @@ var spine;
|
|||||||
(function (threejs) {
|
(function (threejs) {
|
||||||
var SkeletonMeshMaterial = (function (_super) {
|
var SkeletonMeshMaterial = (function (_super) {
|
||||||
__extends(SkeletonMeshMaterial, _super);
|
__extends(SkeletonMeshMaterial, _super);
|
||||||
function SkeletonMeshMaterial() {
|
function SkeletonMeshMaterial(customizer) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var vertexShader = "\n\t\t\t\tattribute vec4 color;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tvColor = color;\n\t\t\t\t\tgl_Position = projectionMatrix*modelViewMatrix*vec4(position,1.0);\n\t\t\t\t}\n\t\t\t";
|
var vertexShader = "\n\t\t\t\tattribute vec4 color;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main() {\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tvColor = color;\n\t\t\t\t\tgl_Position = projectionMatrix*modelViewMatrix*vec4(position,1.0);\n\t\t\t\t}\n\t\t\t";
|
||||||
var fragmentShader = "\n\t\t\t\tuniform sampler2D map;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main(void) {\n\t\t\t\t\tgl_FragColor = texture2D(map, vUv)*vColor;\n\t\t\t\t}\n\t\t\t";
|
var fragmentShader = "\n\t\t\t\tuniform sampler2D map;\n\t\t\t\tvarying vec2 vUv;\n\t\t\t\tvarying vec4 vColor;\n\t\t\t\tvoid main(void) {\n\t\t\t\t\tgl_FragColor = texture2D(map, vUv)*vColor;\n\t\t\t\t}\n\t\t\t";
|
||||||
@ -8284,6 +8285,7 @@ var spine;
|
|||||||
transparent: true,
|
transparent: true,
|
||||||
alphaTest: 0.5
|
alphaTest: 0.5
|
||||||
};
|
};
|
||||||
|
customizer(parameters);
|
||||||
_this = _super.call(this, parameters) || this;
|
_this = _super.call(this, parameters) || this;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@ -8293,7 +8295,8 @@ var spine;
|
|||||||
threejs.SkeletonMeshMaterial = SkeletonMeshMaterial;
|
threejs.SkeletonMeshMaterial = SkeletonMeshMaterial;
|
||||||
var SkeletonMesh = (function (_super) {
|
var SkeletonMesh = (function (_super) {
|
||||||
__extends(SkeletonMesh, _super);
|
__extends(SkeletonMesh, _super);
|
||||||
function SkeletonMesh(skeletonData) {
|
function SkeletonMesh(skeletonData, materialCustomizer) {
|
||||||
|
if (materialCustomizer === void 0) { materialCustomizer = function (parameters) { }; }
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.tempPos = new spine.Vector2();
|
_this.tempPos = new spine.Vector2();
|
||||||
_this.tempUv = new spine.Vector2();
|
_this.tempUv = new spine.Vector2();
|
||||||
@ -8305,6 +8308,7 @@ var spine;
|
|||||||
_this.clipper = new spine.SkeletonClipping();
|
_this.clipper = new spine.SkeletonClipping();
|
||||||
_this.vertices = spine.Utils.newFloatArray(1024);
|
_this.vertices = spine.Utils.newFloatArray(1024);
|
||||||
_this.tempColor = new spine.Color();
|
_this.tempColor = new spine.Color();
|
||||||
|
_this.materialCustomizer = materialCustomizer;
|
||||||
_this.skeleton = new spine.Skeleton(skeletonData);
|
_this.skeleton = new spine.Skeleton(skeletonData);
|
||||||
var animData = new spine.AnimationStateData(skeletonData);
|
var animData = new spine.AnimationStateData(skeletonData);
|
||||||
_this.state = new spine.AnimationState(animData);
|
_this.state = new spine.AnimationState(animData);
|
||||||
@ -8332,7 +8336,7 @@ var spine;
|
|||||||
};
|
};
|
||||||
SkeletonMesh.prototype.nextBatch = function () {
|
SkeletonMesh.prototype.nextBatch = function () {
|
||||||
if (this.batches.length == this.nextBatchIndex) {
|
if (this.batches.length == this.nextBatchIndex) {
|
||||||
var batch_1 = new threejs.MeshBatcher();
|
var batch_1 = new threejs.MeshBatcher(10920, this.materialCustomizer);
|
||||||
this.add(batch_1);
|
this.add(batch_1);
|
||||||
this.batches.push(batch_1);
|
this.batches.push(batch_1);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -2819,10 +2819,25 @@ var spine;
|
|||||||
if (!bone.appliedValid)
|
if (!bone.appliedValid)
|
||||||
bone.updateAppliedTransform();
|
bone.updateAppliedTransform();
|
||||||
var p = bone.parent;
|
var p = bone.parent;
|
||||||
var id = 1 / (p.a * p.d - p.b * p.c);
|
var pa = p.a, pb = p.b, pc = p.c, pd = p.d;
|
||||||
|
var rotationIK = -bone.ashearX - bone.arotation, tx = 0, ty = 0;
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.OnlyTranslation:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
break;
|
||||||
|
case spine.TransformMode.NoRotationOrReflection:
|
||||||
|
rotationIK += Math.atan2(pc, pa) * spine.MathUtils.radDeg;
|
||||||
|
var ps = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
||||||
|
pb = -pc * ps;
|
||||||
|
pd = pa * ps;
|
||||||
|
default:
|
||||||
var x = targetX - p.worldX, y = targetY - p.worldY;
|
var x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
var tx = (x * p.d - y * p.b) * id - bone.ax, ty = (y * p.a - x * p.c) * id - bone.ay;
|
var d = pa * pd - pb * pc;
|
||||||
var rotationIK = Math.atan2(ty, tx) * spine.MathUtils.radDeg - bone.ashearX - bone.arotation;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
|
}
|
||||||
|
rotationIK += Math.atan2(ty, tx) * spine.MathUtils.radDeg;
|
||||||
if (bone.ascaleX < 0)
|
if (bone.ascaleX < 0)
|
||||||
rotationIK += 180;
|
rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
@ -2831,6 +2846,12 @@ var spine;
|
|||||||
rotationIK += 360;
|
rotationIK += 360;
|
||||||
var sx = bone.ascaleX, sy = bone.ascaleY;
|
var sx = bone.ascaleX, sy = bone.ascaleY;
|
||||||
if (compress || stretch) {
|
if (compress || stretch) {
|
||||||
|
switch (bone.data.transformMode) {
|
||||||
|
case spine.TransformMode.NoScale:
|
||||||
|
case spine.TransformMode.NoScaleOrReflection:
|
||||||
|
tx = targetX - bone.worldX;
|
||||||
|
ty = targetY - bone.worldY;
|
||||||
|
}
|
||||||
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
var b = bone.data.length * sx, dd = Math.sqrt(tx * tx + ty * ty);
|
||||||
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001) {
|
||||||
var s = (dd / b - 1) * alpha + 1;
|
var s = (dd / b - 1) * alpha + 1;
|
||||||
@ -4060,6 +4081,8 @@ var spine;
|
|||||||
var input = new BinaryInput(binary);
|
var input = new BinaryInput(binary);
|
||||||
skeletonData.hash = input.readString();
|
skeletonData.hash = input.readString();
|
||||||
skeletonData.version = input.readString();
|
skeletonData.version = input.readString();
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = input.readFloat();
|
skeletonData.x = input.readFloat();
|
||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
@ -5470,6 +5493,8 @@ var spine;
|
|||||||
if (skeletonMap != null) {
|
if (skeletonMap != null) {
|
||||||
skeletonData.hash = skeletonMap.hash;
|
skeletonData.hash = skeletonMap.hash;
|
||||||
skeletonData.version = skeletonMap.spine;
|
skeletonData.version = skeletonMap.spine;
|
||||||
|
if ("3.8.75" == skeletonData.version)
|
||||||
|
throw new Error("Unsupported skeleton data, please export with a newer version of Spine.");
|
||||||
skeletonData.x = skeletonMap.x;
|
skeletonData.x = skeletonMap.x;
|
||||||
skeletonData.y = skeletonMap.y;
|
skeletonData.y = skeletonMap.y;
|
||||||
skeletonData.width = skeletonMap.width;
|
skeletonData.width = skeletonMap.width;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -67,7 +67,9 @@ function load (name, scale) {
|
|||||||
var skeletonData = skeletonJson.readSkeletonData(assetManager.get(skeletonFile));
|
var skeletonData = skeletonJson.readSkeletonData(assetManager.get(skeletonFile));
|
||||||
|
|
||||||
// Create a SkeletonMesh from the data and attach it to the scene
|
// Create a SkeletonMesh from the data and attach it to the scene
|
||||||
skeletonMesh = new spine.threejs.SkeletonMesh(skeletonData);
|
skeletonMesh = new spine.threejs.SkeletonMesh(skeletonData, function(parameters) {
|
||||||
|
parameters.depthTest = false;
|
||||||
|
});
|
||||||
skeletonMesh.state.setAnimation(0, animation, true);
|
skeletonMesh.state.setAnimation(0, animation, true);
|
||||||
mesh.add(skeletonMesh);
|
mesh.add(skeletonMesh);
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ module spine.threejs {
|
|||||||
private indices: Uint16Array;
|
private indices: Uint16Array;
|
||||||
private indicesLength = 0;
|
private indicesLength = 0;
|
||||||
|
|
||||||
constructor (maxVertices: number = 10920) {
|
constructor (maxVertices: number = 10920, materialCustomizer: SkeletonMeshMaterialParametersCustomizer = (parameters) => { }) {
|
||||||
super();
|
super();
|
||||||
if (maxVertices > 10920) throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
|
if (maxVertices > 10920) throw new Error("Can't have more than 10920 triangles per batch: " + maxVertices);
|
||||||
let vertices = this.vertices = new Float32Array(maxVertices * MeshBatcher.VERTEX_SIZE);
|
let vertices = this.vertices = new Float32Array(maxVertices * MeshBatcher.VERTEX_SIZE);
|
||||||
@ -52,7 +52,7 @@ module spine.threejs {
|
|||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = 0;
|
geo.drawRange.count = 0;
|
||||||
this.geometry = geo;
|
this.geometry = geo;
|
||||||
this.material = new SkeletonMeshMaterial();
|
this.material = new SkeletonMeshMaterial(materialCustomizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose () {
|
dispose () {
|
||||||
|
|||||||
@ -28,8 +28,12 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
module spine.threejs {
|
module spine.threejs {
|
||||||
|
export interface SkeletonMeshMaterialParametersCustomizer {
|
||||||
|
(materialParameters: THREE.ShaderMaterialParameters): void;
|
||||||
|
}
|
||||||
|
|
||||||
export class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
export class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
||||||
constructor () {
|
constructor (customizer: SkeletonMeshMaterialParametersCustomizer) {
|
||||||
let vertexShader = `
|
let vertexShader = `
|
||||||
attribute vec4 color;
|
attribute vec4 color;
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
@ -59,6 +63,7 @@ module spine.threejs {
|
|||||||
transparent: true,
|
transparent: true,
|
||||||
alphaTest: 0.5
|
alphaTest: 0.5
|
||||||
};
|
};
|
||||||
|
customizer(parameters);
|
||||||
super(parameters);
|
super(parameters);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -82,10 +87,11 @@ module spine.threejs {
|
|||||||
|
|
||||||
private vertices = Utils.newFloatArray(1024);
|
private vertices = Utils.newFloatArray(1024);
|
||||||
private tempColor = new Color();
|
private tempColor = new Color();
|
||||||
|
private materialCustomizer: SkeletonMeshMaterialParametersCustomizer;
|
||||||
|
|
||||||
constructor (skeletonData: SkeletonData) {
|
constructor (skeletonData: SkeletonData, materialCustomizer: SkeletonMeshMaterialParametersCustomizer = (parameters) => { }) {
|
||||||
super();
|
super();
|
||||||
|
this.materialCustomizer = materialCustomizer;
|
||||||
this.skeleton = new Skeleton(skeletonData);
|
this.skeleton = new Skeleton(skeletonData);
|
||||||
let animData = new AnimationStateData(skeletonData);
|
let animData = new AnimationStateData(skeletonData);
|
||||||
this.state = new AnimationState(animData);
|
this.state = new AnimationState(animData);
|
||||||
@ -118,7 +124,7 @@ module spine.threejs {
|
|||||||
|
|
||||||
private nextBatch () {
|
private nextBatch () {
|
||||||
if (this.batches.length == this.nextBatchIndex) {
|
if (this.batches.length == this.nextBatchIndex) {
|
||||||
let batch = new MeshBatcher();
|
let batch = new MeshBatcher(10920, this.materialCustomizer);
|
||||||
this.add(batch);
|
this.add(batch);
|
||||||
this.batches.push(batch);
|
this.batches.push(batch);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user