randyp

I'm working in Cocos Creator, trying to figure out how to dynamically create and attach attachments to an anim. I've created an AttachmentLoader with the functions for creating the attachment (primarily concerned with RegionAttachments here). Everything seems to execute fine until we get to rendering and then I get errors about undefined textures or materials. It appears that working attachments not being created programatically have textures of type "sp_SkeletonTexture" (yes, underscore), but I can't find a definition for this class anywhere. I'm creating a "sp.spine.FakeTexture" as it's the only class I can find that also inherits from the abstract "sp.spine.Texture". Any ideas what I'm missing?

Here is my code creating the attachment currently. It's just taking a sprite input and attempting to create a RegionAttachment.
newRegionAttachment(skin: sp.spine.Skin, name: string, path: string): sp.spine.RegionAttachment {
var attachment = new sp.spine.RegionAttachment(name);
var tex = this._sprite.getTexture();
var id : string = this._sprite.name + "_" + tex.name;

var texRect: cc.Rect = this._sprite.getRect();

// //normalize rect to UV space of packed atlas
// texRect.x = this.inverseLerp(0, tex.width, texRect.x);
// texRect.y = this.inverseLerp(0, tex.height, texRect.y);
// texRect.width = this.inverseLerp(0, tex.width, texRect.width);
// texRect.height = this.inverseLerp(0, tex.height, texRect.height);

var region = this._atlasTable.get(id);

if(region === null || region === undefined){
region = new sp.spine.TextureAtlasRegion();
region.width = texRect.width;
region.height = texRect.height;
var img = tex.getHtmlElementObj();
//console.log(img);
region.texture = new sp.spine.FakeTexture(img);
console.log(region.texture);
var page = new sp.spine.TextureAtlasPage();

region.page = page;
this._atlasTable.set(id, region);
}

attachment.uvs = [texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin];
attachment.width = texRect.width;
attachment.height = texRect.height;


attachment.setRegion(region);
attachment.rendererObject = region;
// attachment.scaleX = 1;
// attachment.scaleY = 1;

return attachment;
}
randyp
  • Beiträge: 2

Mario

I'm afraid we don't maintain the Cocos Creator integration, but let's see if we can figure this out. Could you post the concrete error message you get? Your code, apart from using a FakeTexture, looks fine to me.
Benutzeravatar
Mario

Mario
  • Beiträge: 2303

randyp

Here is the error callstack
spine-assembler.js:111 Uncaught TypeError: Cannot read property 'getId' of undefined
at _getSlotMaterial (spine-assembler.js:111)
at SpineAssembler.realTimeTraverse (spine-assembler.js:367)
at SpineAssembler.fillBuffers (spine-assembler.js:672)
at RenderFlow.321._proto._render (render-flow.js:82)
at RenderFlow.321._proto._color (render-flow.js:68)
at RenderFlow.321._proto._opacity (render-flow.js:57)
at RenderFlow.321._proto._updateRenderData (render-flow.js:75)
at RenderFlow.321._proto._worldTransform (render-flow.js:49)
at RenderFlow.321._proto._localTransform (render-flow.js:32)
at RenderFlow.init [as _func] (render-flow.js:187)
This is the first line of the callstack - the property "tex" is undefined
Annotation 2020-07-10 104109.jpg


This is the second line in the callstack where the above function gets called.
Annotation 2020-07-10 103927.jpg


Here the "attachment.region.texture._texture" is the undefined argument being passed in. The "._texture" property doesn't even exist on abstract "sp.spine.Texture" class or the "sp.spine.FakeTexture" inheriting. The appears to need to be a "sp_SkeletonTexture" when I examine a working attachment, but I can't find any definition or reference of this class.
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
randyp
  • Beiträge: 2

Mario

Hm, it seems this is an entirely custom implementation of the renderer that I'm not familiar with. Could you maybe ask the Cocos Creator maintainers how to achieve this? I'm afraid I don't quite understand their setup.
Benutzeravatar
Mario

Mario
  • Beiträge: 2303


Zurück zu Runtimes