Hi.
Thank you for response. I wrote my own attachment loader. It's easy. I dont use mashes or FFD and dont now if my loader will work correct for it. For simple quad attachment it works well.
First of all I move attachment creating from AtlasAttachmentLoader to my loader, and create rendererObject from cocos2d::Sprite:
spAttachment* _NativeAttachmentLoader_createAttachment (spAttachmentLoader* loader, spSkin* skin, spAttachmentType type,
const char* name, const char* path) {
switch (type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* attachment;
//Get name in atlas
std::string spritePath = path;
spritePath += ".png";
//Creating some sprite to save information
Sprite* region = Sprite::createWithSpriteFrameName(spritePath);
if (!region) {
_spAttachmentLoader_setError(loader, "Region not found: ", path);
return 0;
}
// Now cocos can't delete sprite
region->retain();
//Seting values from sprite
const cocos2d::Size& regionSize = region->getContentSize();
const V3F_C4B_T2F_Quad spriteQuad = region->getQuad();
attachment = spRegionAttachment_create(name);
attachment->rendererObject = region;
spRegionAttachment_setUVs(attachment,
spriteQuad.bl.texCoords.u,
spriteQuad.bl.texCoords.v,
spriteQuad.tr.texCoords.u,
spriteQuad.tr.texCoords.v,
0);
attachment->regionOffsetX = 0;
attachment->regionOffsetY = 0;
attachment->regionWidth = regionSize.width;
attachment->regionHeight = regionSize.height;
attachment->regionOriginalWidth = regionSize.width;
attachment->regionOriginalHeight = regionSize.height;
return SUPER(attachment);
}
...
}
After that I change a little function that config attachment:
void _NativeAttachmentLoader_configureAttachment (spAttachmentLoader* loader, spAttachment* attachment) {
attachment->attachmentLoader = loader;
switch (attachment->type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* regionAttachment = SUB_CAST(spRegionAttachment, attachment);
//Getting region from sprite
Sprite* region = (Sprite*)regionAttachment->rendererObject;
// Create vertex aatachment from sprite texture
AttachmentVertices* attachmentVertices = new AttachmentVertices(region->getTexture(), 4, quadTriangles, 6);
V3F_C4B_T2F* vertices = attachmentVertices->_triangles->verts;
// Create uv's from sprite quad
const V3F_C4B_T2F_Quad& spriteQuad = region->getQuad();
vertices[1].texCoords = spriteQuad.tl.texCoords;
vertices[2].texCoords = spriteQuad.tr.texCoords;
vertices[3].texCoords = spriteQuad.br.texCoords;
vertices[0].texCoords = spriteQuad.bl.texCoords;
//Sefty delete sprite
region->release();
regionAttachment->rendererObject = attachmentVertices;
break;
}
...
}
And set in the default value of spAtlass in loader constructor to nullptr, because when I removing it the runtime is crash
NativeAttachmentLoader* NativeAttachmentLoader_create (spAtlas* atlas = nullptr);
But now I try to include polygon sprites and it don't work correct. I read all TriangleCommand from sprite.
void _NativeAttachmentLoader_configureAttachment (spAttachmentLoader* loader, spAttachment* attachment) {
attachment->attachmentLoader = loader;
switch (attachment->type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* regionAttachment = SUB_CAST(spRegionAttachment, attachment);
//Getting region from sprite
Sprite* region = (Sprite*)regionAttachment->rendererObject;
//Get frame of sprite
SpriteFrame* regionFrame = region->getSpriteFrame();
//Get info about triangles in sprite
const PolygonInfo& regionPolygonInfo = regionFrame->getPolygonInfo();
//Get all triangles
const TrianglesCommand::Triangles& regionTriangles = regionPolygonInfo.triangles;
uint triangleCount = regionTriangles.vertCount / 2;
// Create vertex aatachment from sprite texture
AttachmentVertices* attachmentVertices = new AttachmentVertices(region->getTexture(), triangleCount, regionTriangles.indices, regionTriangles.indexCount);
V3F_C4B_T2F* vertices = attachmentVertices->_triangles->verts;
// Texture cords in atlas
V3F_C4B_T2F* regionVertices = regionTriangles.verts;
for(uint i = 0; i < triangleCount; ++i)
{
vertices[i].texCoords.u = regionVertices[i].texCoords.u;
vertices[i].texCoords.v = regionVertices[i].texCoords.v;
}
//Sefty delete sprite
region->release();
regionAttachment->rendererObject = attachmentVertices;
break;
}
...
Maybe you can help me or show me where I was wrong. I tried change indices and clone TriangleCommand object, but it didn't help.
Result should be:
Loading Image
and I have something like this
Loading Image
Image I'm posted from Ubuntu, on my working Mac I have more psychedelic results.
Thank you.