Skip to content

Commit f33fe2f

Browse files
authored
Merge pull request #1832 from Lurenyiabc/Master3.0
fix:spine bug.
2 parents 17a0bca + f09a944 commit f33fe2f

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

src/layaAir/laya/spine/Spine2DRenderNode.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,15 @@ export class Spine2DRenderNode extends BaseRenderNode2D {
574574
if (null == this._skeleton) return;
575575
let skins = this._externalSkins;
576576
if (skins) {
577-
let normal = false;
577+
let normal = false;//todo 需要修改顶点构成?
578578
for (let i = skins.length - 1; i >= 0; i--) {
579579
skins[i].flush();
580-
normal = skins[i].normal || normal;
580+
// normal = skins[i].normal || normal;
581581
}
582582

583-
if (normal) {
583+
// if (normal) {
584584
this.useFastRender = false;
585-
}
585+
// }
586586
}
587587
}
588588
/**
@@ -653,6 +653,7 @@ export class Spine2DRenderNode extends BaseRenderNode2D {
653653
this._clearUpdate();
654654
//this.timer.clear(this, this._update);
655655
this._state.update(-this._currentPlayTime);
656+
// this._skeleton.setToSetupPose();
656657
// this._state.clearTrack(this.trackIndex);
657658
this._currentPlayTime = 0;
658659
this.event(Event.STOPPED);

src/layaAir/laya/spine/normal/SpineSkeletonRenderer.ts

+37-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ export class SpineSkeletonRenderer extends SpineNormalRenderBase implements ISpi
402402
attachmentColor = mesh.color;
403403
} else if (attachment instanceof window.spine.ClippingAttachment) {
404404
let clip = <spine.ClippingAttachment>(attachment);
405-
clipper.clipStart(slot, clip);
405+
// clipper.clipStart(slot, clip);
406+
this.clipStart(this.clipper , slot , clip , -skeleton.x, -skeleton.y);
406407
continue;
407408
} else {
408409
clipper.clipEndWithSlot(slot);
@@ -480,6 +481,40 @@ export class SpineSkeletonRenderer extends SpineNormalRenderBase implements ISpi
480481
virtualMesh && virtualMesh.draw();
481482
}
482483

484+
/**
485+
* @link spine-ts/.../SkeletonClipping.ts
486+
* @param clipper
487+
* @param slot
488+
* @param clip
489+
* @param ofx
490+
* @param ofy
491+
* @returns
492+
*/
493+
clipStart(clipper:spine.SkeletonClipping , slot : spine.Slot, clip:spine.VertexAttachment ,ofx: number, ofy: number) {
494+
//@ts-ignore
495+
if (clipper.clipAttachment)
496+
return 0;
497+
//@ts-ignore
498+
clipper.clipAttachment = clip;
499+
let n = clip.worldVerticesLength;
500+
//@ts-ignore
501+
let vertices:spine.NumberArrayLike = spine.Utils.setArraySize(clipper.clippingPolygon, n);
502+
// clip.computeWorldVertices(slot, 0, n, vertices, 0, 2);
503+
this.computeWorldVertices_MeshAttachment(clip , slot , 0 , n , vertices , 0 , 2 , ofx , ofy);
504+
//@ts-ignore
505+
let clippingPolygon = clipper.clippingPolygon;
506+
spine.SkeletonClipping.makeClockwise(clippingPolygon);
507+
//@ts-ignore
508+
let clippingPolygons = clipper.clippingPolygons = clipper.triangulator.decompose(clippingPolygon, clipper.triangulator.triangulate(clippingPolygon));
509+
for (let i = 0, n = clippingPolygons.length; i < n; i++) {
510+
let polygon = clippingPolygons[i];
511+
spine.SkeletonClipping.makeClockwise(polygon);
512+
polygon.push(polygon[0]);
513+
polygon.push(polygon[1]);
514+
}
515+
return clippingPolygons.length;
516+
}
517+
483518
/**
484519
* @link spine-ts/.../RegionAttachment.ts
485520
* @param attachment
@@ -537,7 +572,7 @@ export class SpineSkeletonRenderer extends SpineNormalRenderBase implements ISpi
537572
* @param ofy
538573
* @returns
539574
*/
540-
private computeWorldVertices_MeshAttachment(attachment: spine.MeshAttachment, slot: spine.Slot, start: number, count: number, worldVertices: spine.NumberArrayLike, offset: number, stride: number, ofx: number, ofy: number) {
575+
private computeWorldVertices_MeshAttachment(attachment: spine.VertexAttachment, slot: spine.Slot, start: number, count: number, worldVertices: spine.NumberArrayLike, offset: number, stride: number, ofx: number, ofy: number) {
541576
count = offset + (count >> 1) * stride;
542577
let skeleton = slot.bone.skeleton;
543578
let deformArray = slot.deform;

src/layaAir/laya/spine/optimize/SpineNormalRender.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class SpineNormalRender implements ISpineOptimizeRender {
4242
_skeleton: spine.Skeleton;
4343
/**@internal */
4444
_spineColor: Color
45-
45+
/** @internal */
46+
_skinIndex: number = 0;
4647
/**
4748
* @en Initializes the renderer.
4849
* @param skeleton The spine skeleton.
@@ -91,7 +92,7 @@ export class SpineNormalRender implements ISpineOptimizeRender {
9192
* @param index 要设置的皮肤索引。
9293
*/
9394
setSkinIndex(index: number): void {
94-
//throw new NotImplementedError();
95+
this._skinIndex = index;
9596
}
9697

9798

@@ -103,6 +104,9 @@ export class SpineNormalRender implements ISpineOptimizeRender {
103104
*/
104105
changeSkeleton(skeleton: spine.Skeleton) {
105106
this._skeleton = skeleton;
107+
//@ts-ignore
108+
skeleton.showSkinByIndex(this._skinIndex);
109+
this._skeleton.setSlotsToSetupPose();
106110
}
107111

108112
/**

src/layaAir/laya/spine/optimize/SpineOptimizeRender.ts

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export class SpineOptimizeRender implements ISpineOptimizeRender {
169169
this.renderProxyMap.forEach(render=>{
170170
render.changeSkeleton(skeleton);
171171
});
172+
//@ts-ignore
173+
skeleton.showSkinByIndex(this._skinIndex);
174+
this._skeleton.setSlotsToSetupPose();
172175
}
173176

174177
/**

0 commit comments

Comments
 (0)