void Sprite3D::afterAsyncLoad(void* param) { Sprite3D::AsyncLoadParam* asyncParam = (Sprite3D::AsyncLoadParam*)param; autorelease(); if (asyncParam) { if (asyncParam->result) { _meshes.clear(); _meshVertexDatas.clear(); CC_SAFE_RELEASE_NULL(_skeleton); removeAllAttachNode(); //create in the main thread auto& meshdatas = asyncParam->meshdatas; auto& materialdatas = asyncParam->materialdatas; auto& nodeDatas = asyncParam->nodeDatas; if (initFrom(*nodeDatas, *meshdatas, *materialdatas)) { auto spritedata = Sprite3DCache::getInstance()->getSpriteData(asyncParam->modlePath); if (spritedata == nullptr) { //add to cache auto data = new (std::nothrow) Sprite3DCache::Sprite3DData(); data->materialdatas = materialdatas; data->nodedatas = nodeDatas; data->meshVertexDatas = _meshVertexDatas; for (const auto mesh : _meshes) { data->glProgramStates.pushBack(mesh->getGLProgramState()); } Sprite3DCache::getInstance()->addSprite3DData(asyncParam->modlePath, data); meshdatas = nullptr; materialdatas = nullptr; nodeDatas = nullptr; } } delete meshdatas; delete materialdatas; delete nodeDatas; if (asyncParam->texPath != "") { setTexture(asyncParam->texPath); } } else { CCLOG("file load failed: %s ", asyncParam->modlePath.c_str()); } asyncParam->afterLoadCallback(this, asyncParam->callbackParam); } }
bool Sprite3D::initWithFile(const std::string& path) { _aabbDirty = true; _meshes.clear(); _meshVertexDatas.clear(); CC_SAFE_RELEASE_NULL(_skeleton); removeAllAttachNode(); if (loadFromCache(path)) return true; MeshDatas* meshdatas = new (std::nothrow) MeshDatas(); MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas(); NodeDatas* nodeDatas = new (std::nothrow) NodeDatas(); if (loadFromFile(path, nodeDatas, meshdatas, materialdatas)) { if (initFrom(*nodeDatas, *meshdatas, *materialdatas)) { //add to cache auto data = new (std::nothrow) Sprite3DCache::Sprite3DData(); data->materialdatas = materialdatas; data->nodedatas = nodeDatas; data->meshVertexDatas = _meshVertexDatas; for (const auto mesh : _meshes) { data->glProgramStates.pushBack(mesh->getGLProgramState()); } Sprite3DCache::getInstance()->addSprite3DData(path, data); CC_SAFE_DELETE(meshdatas); _contentSize = getBoundingBox().size; return true; } } CC_SAFE_DELETE(meshdatas); CC_SAFE_DELETE(materialdatas); CC_SAFE_DELETE(nodeDatas); return false; }
void initFrom(const DataKeyImpl& key) { initFrom(key.getElements()); }
DataKeyImpl(const DataKeyImpl& key) { initFrom(key); }
DataKeyImpl(const std::set<DataKeyElement>& elements) { initFrom(elements); }
EastNorthCoordImpl(const EastNorthCoord& coord) { initFrom(coord); }
Block::Block(const std::shared_ptr<Block>& b){ initFrom(b->begin(), b->size()); }
Block::Block(const Block& b){ initFrom(b.begin(), b.size()); }
Block::Block(const char* str){ initFrom(str, strlen(str) + 1); }
Block::Block(const std::string& str) { initFrom(str.c_str(), str.size() + 1); }
Block::Block(const void* src, size_t sz){ initFrom(src, sz); }
TileKeyImpl(const TileKey& tileKey) { initFrom(tileKey); }
ImageBoxImpl(const ImageBox& box) { initFrom(box); }
void initFrom(const DataKeyBuilderImpl& builder) { initFrom(builder.m_elements); }
DataKeyBuilderImpl(const DataKeyBuilderImpl& builder) { initFrom(builder); }