mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
Removed skeleton from C3Renderer because it prevents GameObject to change skeleton.
This commit is contained in:
parent
89cc7670c5
commit
a641916750
@ -48,14 +48,13 @@ abstract class C3SkeletonRenderer<
|
|||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
protected renderer: Renderer,
|
protected renderer: Renderer,
|
||||||
private skeleton: Skeleton,
|
|
||||||
protected matrix: C3Matrix,
|
protected matrix: C3Matrix,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
draw (opacity = 1) {
|
draw (skeleton: Skeleton, opacity = 1) {
|
||||||
const { skeleton, matrix, inv255 } = this;
|
const { matrix, inv255 } = this;
|
||||||
|
|
||||||
let command = this.render(skeleton);
|
let command = this.render(skeleton);
|
||||||
while (command) {
|
while (command) {
|
||||||
@ -99,8 +98,8 @@ abstract class C3SkeletonRenderer<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawDebug (x: number, y: number, quad: C3Quad) {
|
drawDebug (skeleton: Skeleton, x: number, y: number, quad: C3Quad) {
|
||||||
const { skeleton, matrix } = this;
|
const { matrix } = this;
|
||||||
|
|
||||||
this.setColorFillMode();
|
this.setColorFillMode();
|
||||||
this.setBlendMode();
|
this.setBlendMode();
|
||||||
@ -342,10 +341,6 @@ abstract class C3SkeletonRenderer<
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class C3RendererRuntime extends C3SkeletonRenderer<IRenderer, C3TextureRuntime> {
|
export class C3RendererRuntime extends C3SkeletonRenderer<IRenderer, C3TextureRuntime> {
|
||||||
constructor (renderer: IRenderer, skeleton: Skeleton, matrix: C3Matrix) {
|
|
||||||
super(renderer, skeleton, matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected setColor (r: number, g: number, b: number, a: number): void {
|
protected setColor (r: number, g: number, b: number, a: number): void {
|
||||||
this.renderer.setColor([r, g, b, a]);
|
this.renderer.setColor([r, g, b, a]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,6 @@ export class C3TextureEditor extends Texture {
|
|||||||
// cannot change wraps after texture creation
|
// cannot change wraps after texture creation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dispose () {
|
dispose () {
|
||||||
this.renderer?.DeleteTexture(this.texture);
|
this.renderer?.DeleteTexture(this.texture);
|
||||||
this.renderer = undefined;
|
this.renderer = undefined;
|
||||||
|
|||||||
@ -145,9 +145,9 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
|
|||||||
const { skeleton } = this;
|
const { skeleton } = this;
|
||||||
if (!skeleton) return;
|
if (!skeleton) return;
|
||||||
|
|
||||||
this.skeletonRenderer ||= new spine.C3RendererRuntime(renderer, skeleton, this.matrix);
|
this.skeletonRenderer ||= new spine.C3RendererRuntime(renderer, this.matrix);
|
||||||
this.skeletonRenderer.draw(this.opacity);
|
this.skeletonRenderer.draw(skeleton, this.opacity);
|
||||||
if (this.propDebugSkeleton) this.skeletonRenderer.drawDebug(this.x, this.y, this.getBoundingQuad(false));
|
if (this.propDebugSkeleton) this.skeletonRenderer.drawDebug(skeleton, this.x, this.y, this.getBoundingQuad(false));
|
||||||
this.renderDragHandles();
|
this.renderDragHandles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,91 +91,6 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
|
|||||||
this.OnMakeOriginalSize();
|
this.OnMakeOriginalSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw (iRenderer: SDK.Gfx.IWebGLRenderer, iDrawParams: SDK.Gfx.IDrawParams) {
|
|
||||||
this.layoutView ||= iDrawParams.GetLayoutView();
|
|
||||||
this.renderer ||= iRenderer;
|
|
||||||
|
|
||||||
this.loadAtlas();
|
|
||||||
this.loadSkeleton();
|
|
||||||
this.initBounds();
|
|
||||||
|
|
||||||
const { _inst, skeleton } = this;
|
|
||||||
const errorsString = this.getErrorsString();
|
|
||||||
if (skeleton && this.textureAtlas && !errorsString) {
|
|
||||||
this.setAnimation();
|
|
||||||
this.setSkin();
|
|
||||||
|
|
||||||
const rectX = _inst.GetX();
|
|
||||||
const rectY = _inst.GetY();
|
|
||||||
const rectAngle = _inst.GetAngle();
|
|
||||||
let offsetX = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X) as number;
|
|
||||||
let offsetY = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_Y) as number;
|
|
||||||
let offsetAngle = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_ANGLE) as number;
|
|
||||||
|
|
||||||
if (!this.positioningBounds) {
|
|
||||||
offsetX += rectX;
|
|
||||||
offsetY += rectY;
|
|
||||||
offsetAngle += rectAngle;
|
|
||||||
|
|
||||||
const baseScaleX = _inst.GetWidth() / this.spineBounds.width;
|
|
||||||
const baseScaleY = _inst.GetHeight() / this.spineBounds.height;
|
|
||||||
skeleton.scaleX = baseScaleX;
|
|
||||||
skeleton.scaleY = baseScaleY;
|
|
||||||
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_X, baseScaleX);
|
|
||||||
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y, baseScaleY);
|
|
||||||
} else {
|
|
||||||
offsetX += this.positionModePrevX;
|
|
||||||
offsetY += this.positionModePrevY;
|
|
||||||
offsetAngle += this.positionModePrevAngle;
|
|
||||||
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X, offsetX - rectX);
|
|
||||||
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_Y, offsetY - rectY);
|
|
||||||
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_ANGLE, offsetAngle - rectAngle);
|
|
||||||
this.positionModePrevX = rectX;
|
|
||||||
this.positionModePrevY = rectY;
|
|
||||||
this.positionModePrevAngle = rectAngle;
|
|
||||||
|
|
||||||
skeleton.scaleX = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_X) as number;
|
|
||||||
skeleton.scaleY = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.update(0);
|
|
||||||
this.skeletonRenderer ||= new spine.C3RendererEditor(iRenderer, skeleton, this.matrix);
|
|
||||||
this.skeletonRenderer.draw(_inst.GetOpacity());
|
|
||||||
const quad = _inst.GetQuad();
|
|
||||||
if (_inst.GetPropertyValue(PLUGIN_CLASS.PROP_DEBUG_SKELETON) as boolean)
|
|
||||||
this.skeletonRenderer.drawDebug(rectX, rectY, quad);
|
|
||||||
this.skeletonRenderer.renderGameObjectBounds(rectX, rectY, quad);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
iRenderer.SetAlphaBlend();
|
|
||||||
|
|
||||||
const logo = (this._sdkType as SpineC3PluginType).getSpineLogo(iRenderer);
|
|
||||||
if (logo) {
|
|
||||||
iRenderer.SetColorRgba(1, 1, 1, errorsString ? 0.25 : 1);
|
|
||||||
iRenderer.SetTexture(logo);
|
|
||||||
} else {
|
|
||||||
iRenderer.SetColorFillMode();
|
|
||||||
iRenderer.SetColorRgba(0.25, 0, 0, 0.25);
|
|
||||||
}
|
|
||||||
const quad = _inst.GetQuad();
|
|
||||||
iRenderer.Quad(quad);
|
|
||||||
|
|
||||||
if (errorsString) {
|
|
||||||
const webglText = this.getErrorTextC3(iRenderer, this.layoutView);
|
|
||||||
webglText.SetSize(_inst.GetWidth(), _inst.GetHeight(), this.layoutView.GetZoomFactor());
|
|
||||||
webglText.SetText(errorsString);
|
|
||||||
|
|
||||||
const texture = webglText.GetTexture();
|
|
||||||
if (!texture) return;
|
|
||||||
|
|
||||||
iRenderer.SetColorRgba(1, 1, 1, 1);
|
|
||||||
iRenderer.SetTexture(texture);
|
|
||||||
iRenderer.Quad3(quad, webglText.GetTexRect());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async OnPropertyChanged (id: string, value: EditorPropertyValueType) {
|
async OnPropertyChanged (id: string, value: EditorPropertyValueType) {
|
||||||
if (id === PLUGIN_CLASS.PROP_ATLAS) {
|
if (id === PLUGIN_CLASS.PROP_ATLAS) {
|
||||||
this.textureAtlasSID = -1;
|
this.textureAtlasSID = -1;
|
||||||
@ -242,6 +157,91 @@ class SpineC3PluginInstance extends SDK.IWorldInstanceBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Draw (iRenderer: SDK.Gfx.IWebGLRenderer, iDrawParams: SDK.Gfx.IDrawParams) {
|
||||||
|
this.layoutView ||= iDrawParams.GetLayoutView();
|
||||||
|
this.renderer ||= iRenderer;
|
||||||
|
|
||||||
|
this.loadAtlas();
|
||||||
|
this.loadSkeleton();
|
||||||
|
this.initBounds();
|
||||||
|
|
||||||
|
const { _inst, skeleton } = this;
|
||||||
|
const errorsString = this.getErrorsString();
|
||||||
|
if (skeleton && this.textureAtlas && !errorsString) {
|
||||||
|
this.setAnimation();
|
||||||
|
this.setSkin();
|
||||||
|
|
||||||
|
const rectX = _inst.GetX();
|
||||||
|
const rectY = _inst.GetY();
|
||||||
|
const rectAngle = _inst.GetAngle();
|
||||||
|
let offsetX = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X) as number;
|
||||||
|
let offsetY = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_Y) as number;
|
||||||
|
let offsetAngle = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_ANGLE) as number;
|
||||||
|
|
||||||
|
if (!this.positioningBounds) {
|
||||||
|
offsetX += rectX;
|
||||||
|
offsetY += rectY;
|
||||||
|
offsetAngle += rectAngle;
|
||||||
|
|
||||||
|
const baseScaleX = _inst.GetWidth() / this.spineBounds.width;
|
||||||
|
const baseScaleY = _inst.GetHeight() / this.spineBounds.height;
|
||||||
|
skeleton.scaleX = baseScaleX;
|
||||||
|
skeleton.scaleY = baseScaleY;
|
||||||
|
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_X, baseScaleX);
|
||||||
|
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y, baseScaleY);
|
||||||
|
} else {
|
||||||
|
offsetX += this.positionModePrevX;
|
||||||
|
offsetY += this.positionModePrevY;
|
||||||
|
offsetAngle += this.positionModePrevAngle;
|
||||||
|
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_X, offsetX - rectX);
|
||||||
|
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_Y, offsetY - rectY);
|
||||||
|
_inst.SetPropertyValue(PLUGIN_CLASS.PROP_BOUNDS_OFFSET_ANGLE, offsetAngle - rectAngle);
|
||||||
|
this.positionModePrevX = rectX;
|
||||||
|
this.positionModePrevY = rectY;
|
||||||
|
this.positionModePrevAngle = rectAngle;
|
||||||
|
|
||||||
|
skeleton.scaleX = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_X) as number;
|
||||||
|
skeleton.scaleY = _inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.update(0);
|
||||||
|
this.skeletonRenderer ||= new spine.C3RendererEditor(iRenderer, this.matrix);
|
||||||
|
this.skeletonRenderer.draw(skeleton, _inst.GetOpacity());
|
||||||
|
const quad = _inst.GetQuad();
|
||||||
|
if (_inst.GetPropertyValue(PLUGIN_CLASS.PROP_DEBUG_SKELETON) as boolean)
|
||||||
|
this.skeletonRenderer.drawDebug(skeleton, rectX, rectY, quad);
|
||||||
|
this.skeletonRenderer.renderGameObjectBounds(rectX, rectY, quad);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
iRenderer.SetAlphaBlend();
|
||||||
|
|
||||||
|
const logo = (this._sdkType as SpineC3PluginType).getSpineLogo(iRenderer);
|
||||||
|
if (logo) {
|
||||||
|
iRenderer.SetColorRgba(1, 1, 1, errorsString ? 0.25 : 1);
|
||||||
|
iRenderer.SetTexture(logo);
|
||||||
|
} else {
|
||||||
|
iRenderer.SetColorFillMode();
|
||||||
|
iRenderer.SetColorRgba(0.25, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
const quad = _inst.GetQuad();
|
||||||
|
iRenderer.Quad(quad);
|
||||||
|
|
||||||
|
if (errorsString) {
|
||||||
|
const webglText = this.getErrorTextC3(iRenderer, this.layoutView);
|
||||||
|
webglText.SetSize(_inst.GetWidth(), _inst.GetHeight(), this.layoutView.GetZoomFactor());
|
||||||
|
webglText.SetText(errorsString);
|
||||||
|
|
||||||
|
const texture = webglText.GetTexture();
|
||||||
|
if (!texture) return;
|
||||||
|
|
||||||
|
iRenderer.SetColorRgba(1, 1, 1, 1);
|
||||||
|
iRenderer.SetTexture(texture);
|
||||||
|
iRenderer.Quad3(quad, webglText.GetTexRect());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private setAnimation () {
|
private setAnimation () {
|
||||||
const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_ANIMATION) as string;
|
const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_ANIMATION) as string;
|
||||||
this.animation = propValue === "" ? undefined : propValue;
|
this.animation = propValue === "" ? undefined : propValue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user