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;
}