Add padding for indices to fix temporarily C3 bug.

This commit is contained in:
Davide Tantillo 2025-08-18 18:21:06 +02:00
parent abb14cf6ea
commit 235a96ca5c
2 changed files with 54 additions and 12 deletions

View File

@ -254,7 +254,7 @@ class DrawingInstance extends globalThis.ISDKWorldInstanceBase {
renderer.drawMesh( renderer.drawMesh(
vertices.subarray(0, numVertices * 3), vertices.subarray(0, numVertices * 3),
uvs.subarray(0, numVertices * 2), uvs.subarray(0, numVertices * 2),
indices.subarray(0, numIndices), this.padUint16ArrayForWebGPU(indices.subarray(0, numIndices)),
c3colors.subarray(0, numVertices * 4), c3colors.subarray(0, numVertices * 4),
); );
@ -263,6 +263,21 @@ class DrawingInstance extends globalThis.ISDKWorldInstanceBase {
} }
padUint16ArrayForWebGPU (originalArray: Uint16Array) {
const currentLength = originalArray.length;
const alignedLength = Math.ceil(currentLength / 6) * 6;
if (alignedLength === currentLength) {
return originalArray;
}
const paddedArray = new Uint16Array(alignedLength);
paddedArray.set(originalArray);
return paddedArray;
}
_saveToJson () { _saveToJson () {
return { return {
// data to be saved for savegames // data to be saved for savegames

View File

@ -74,7 +74,8 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
this.loadAtlas(); this.loadAtlas();
this.loadSkeleton(); this.loadSkeleton();
if (this.skeleton) { const hasErrors = this.hasErrors();
if (this.skeleton && !hasErrors) {
this.setSkin(); this.setSkin();
const rectX = this._inst.GetX(); const rectX = this._inst.GetX();
@ -110,6 +111,7 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
this.skeleton.scaleY = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number; this.skeleton.scaleY = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON_SCALE_Y) as number;
} }
const cos = Math.cos(offsetAngle); const cos = Math.cos(offsetAngle);
const sin = Math.sin(offsetAngle); const sin = Math.sin(offsetAngle);
@ -133,12 +135,15 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
iRenderer.SetAlphaBlend(); iRenderer.SetAlphaBlend();
iRenderer.SetTextureFillMode(); iRenderer.SetTextureFillMode();
iRenderer.SetTexture(command.texture.texture); iRenderer.SetTexture(command.texture.texture);
const padded = this.padUint16ArrayForWebGPU(indices.subarray(0, numIndices));
iRenderer.DrawMesh( iRenderer.DrawMesh(
vertices.subarray(0, numVertices * 3), vertices.subarray(0, numVertices * 3),
uvs.subarray(0, numVertices * 2), uvs.subarray(0, numVertices * 2),
indices.subarray(0, numIndices), this.padUint16ArrayForWebGPU(indices.subarray(0, numIndices)),
); );
command = command.next; command = command.next;
} }
@ -148,11 +153,11 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
iRenderer.LineQuad(this._inst.GetQuad()); iRenderer.LineQuad(this._inst.GetQuad());
iRenderer.Line(rectX, rectY, offsetX, offsetY); iRenderer.Line(rectX, rectY, offsetX, offsetY);
if (this.hasErrors()) { // if (this.hasErrors()) {
iRenderer.SetColorFillMode(); // iRenderer.SetColorFillMode();
iRenderer.SetColorRgba(1, 0, 0, .5); // iRenderer.SetColorRgba(1, 0, 0, .5);
iRenderer.Quad(this._inst.GetQuad()); // iRenderer.Quad(this._inst.GetQuad());
} // }
} else { } else {
const sdkType = (this._sdkType as any); const sdkType = (this._sdkType as any);
@ -163,6 +168,9 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
iRenderer.ResetColor(); iRenderer.ResetColor();
iRenderer.SetAlphaBlend(); iRenderer.SetAlphaBlend();
iRenderer.SetTexture(logo); iRenderer.SetTexture(logo);
if (hasErrors) {
iRenderer.SetColorRgba(1, 0, 0, 1);
}
iRenderer.Quad(this._inst.GetQuad()); iRenderer.Quad(this._inst.GetQuad());
} else { } else {
iRenderer.SetAlphaBlend(); iRenderer.SetAlphaBlend();
@ -180,6 +188,21 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
} }
} }
padUint16ArrayForWebGPU (originalArray: Uint16Array) {
const currentLength = originalArray.length;
const alignedLength = Math.ceil(currentLength / 6) * 6;
if (alignedLength === currentLength) {
return originalArray;
}
const paddedArray = new Uint16Array(alignedLength);
paddedArray.set(originalArray);
return paddedArray;
}
async OnPropertyChanged (id: string, value: EditorPropertyValueType) { async OnPropertyChanged (id: string, value: EditorPropertyValueType) {
console.log(`Prop change - Name: ${id} - Value: ${value}`); console.log(`Prop change - Name: ${id} - Value: ${value}`);
@ -208,6 +231,7 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
if (id === PLUGIN_CLASS.PROP_SKIN) { if (id === PLUGIN_CLASS.PROP_SKIN) {
this.skins = []; this.skins = [];
this.setSkin(); this.setSkin();
this.resetBounds();
this.layoutView?.Refresh(); this.layoutView?.Refresh();
return; return;
} }
@ -286,8 +310,10 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON) as number; const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_SKELETON) as number;
const loaderScale = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_LOADER_SCALE) as number; const loaderScale = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_LOADER_SCALE) as number;
const skeletonData = await this.assetLoader.loadSkeletonEditor(propValue, this.textureAtlas, loaderScale, this._inst); const skeletonData = await this.assetLoader.loadSkeletonEditor(propValue, this.textureAtlas, loaderScale, this._inst)
console.log(skeletonData); .catch((error) => {
console.log("ATLAS AND SKELETON NOT CORRESPONDING", error);
});
if (!skeletonData) return; if (!skeletonData) return;
this.skeleton = new spine.Skeleton(skeletonData); this.skeleton = new spine.Skeleton(skeletonData);
@ -307,11 +333,12 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
if (!this.renderer) return; if (!this.renderer) return;
const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_ATLAS) as number; const propValue = this._inst.GetPropertyValue(PLUGIN_CLASS.PROP_ATLAS) as number;
console.log("Loading atlas");
if (this.currentAtlasFileSID === propValue) return; if (this.currentAtlasFileSID === propValue) return;
this.currentAtlasFileSID = propValue; this.currentAtlasFileSID = propValue;
console.log("Loading atlas");
const textureAtlas = await this.assetLoader.loadAtlasEditor(propValue, this._inst, this.renderer); const textureAtlas = await this.assetLoader.loadAtlasEditor(propValue, this._inst, this.renderer);
if (!textureAtlas) return; if (!textureAtlas) return;
@ -407,7 +434,7 @@ class MyDrawingInstance extends SDK.IWorldInstanceBase {
this.setError( this.setError(
"boundsNoDimension", "boundsNoDimension",
width <= 0 || height <= 0, width <= 0 || height <= 0,
"A bounds cannot have negative dimension" "A bounds cannot have negative dimensions. This might happen when the setup pose is empty. Try to set a skin and the Animation/Skin bounds provider."
); );
return Object.keys(errors).length > 0; return Object.keys(errors).length > 0;