std::vector<std::string>* findAndGetTextureInfoByProperty(FbxProperty fbxTextureProperty, int midx) {
	std::vector<std::string>* textureFileNames = new std::vector<std::string>();

	if( fbxTextureProperty.IsValid() )
	{
		int numTextures = fbxTextureProperty.GetSrcObjectCount<FbxTexture>();

		for (int j = 0; j < numTextures; ++j) {

			// Here we have to check if it's layeredtextures, or just textures:
			FbxLayeredTexture *fbxLayeredTexture = fbxTextureProperty.GetSrcObject<FbxLayeredTexture>(j);
			if (fbxLayeredTexture) {

				int numLayeredTextures = fbxLayeredTexture->GetSrcObjectCount<FbxTexture>();
				for (int k = 0; k < numLayeredTextures; ++k) {

					FbxTexture* fbxTexture = fbxLayeredTexture->GetSrcObject<FbxTexture>(k);
					if (fbxTexture) {

						// NOTE the blend mode is ALWAYS on the LayeredTexture and NOT the one on the texture.
						// Why is that?  because one texture can be shared on different layered textures and might
						// have different blend modes.

						FbxLayeredTexture::EBlendMode lBlendMode;
						fbxLayeredTexture->GetTextureBlendMode(k, lBlendMode);
						std::string textureFileName = getTextureFileName(fbxTexture);
						textureFileNames->push_back(textureFileName);
					}
				}
			}
			else {
				// No layered texture simply get on the property
				FbxTexture* fbxTexture = fbxTextureProperty.GetSrcObject<FbxTexture>(j);
				if (fbxTexture) {
					// Display connected Material header only at the first time

					std::string textureFileName = getTextureFileName(fbxTexture);
					textureFileNames->push_back(textureFileName);
				}
			}
		}
	}

	return textureFileNames;
}
Example #2
0
void LLTextureCache::removeFromCache(const LLUUID& id)
{
	//llwarns << "Removing texture from cache: " << id << llendl;
	if (!mReadOnly)
	{
		removeHeaderCacheEntry(id);
		ll_apr_file_remove(getTextureFileName(id), NULL);
	}
}
Example #3
0
void LLTextureCache::removeFromCacheLocked(const LLUUID& id)
{
	//llwarns << "Removing texture from cache: " << id << llendl;
	if (!mReadOnly)
	{
		removeHeaderCacheEntry(id);
		LLAPRFile::remove(getTextureFileName(id));
	}
}
Example #4
0
void ATOM_Decal::assign (ATOM_Node *other) const
{
	ATOM_Node::assign (other);
	ATOM_Decal *decal = dynamic_cast<ATOM_Decal*>(other);
	if (decal)
	{
		decal->setTextureFileName (getTextureFileName ());
		if (!decal->getTexture ())
		{
			decal->setTexture (getTexture());
		}
	}
}
Example #5
0
	void CSObject::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options)
	{
		out->addInt(		"Id",				getId());
		out->addString(		"Name",				getName().c_str());
		out->addBool(		"Dead",				getDead());
		out->addBool(		"DebugObject",		getDebugObject());
		out->addVector3d(	"Position",			getRelativePosition());
		out->addVector3d(	"PositionOffset",	getPositionOffset());
		out->addVector3d(	"Rotation",			getRelativeRotation());
		out->addVector3d(	"RotationOffset",	getRotationOffset());
		out->addVector3d(	"Scale",			getRelativeScale());
		out->addVector3d(	"ScaleOffset",		getScaleOffset());
		out->addVector3d(	"BBOffset",			getBBOffset());
		out->addBool(		"Shadow",			getShadow());
		out->addString(		"ActorFileName",	getActorFileName().c_str());
		out->addString(		"TextureFileName",	getTextureFileName().c_str());
	}
Example #6
0
void LLTextureCache::purgeTextures(bool validate)
{
	if (mReadOnly)
	{
		return;
	}

	// *FIX:Mani - watchdog off.
	LLAppViewer::instance()->pauseMainloopTimeout();

	LLMutexLock lock(&mHeaderMutex);
	
	S32 filesize = ll_apr_file_size(mTexturesDirEntriesFileName, NULL);
	S32 num_entries = filesize / sizeof(Entry);
	if (num_entries * (S32)sizeof(Entry) != filesize)
	{
		LL_WARNS("TextureCache") << "Bad cache file: " << mTexturesDirEntriesFileName << " Purging." << LL_ENDL;
		purgeAllTextures(false);
		return;
	}
	if (num_entries == 0)
	{
		return; // nothing to do
	}
	
	Entry* entries = new Entry[num_entries];
	S32 bytes_read = ll_apr_file_read_ex(mTexturesDirEntriesFileName, NULL,
										 (U8*)entries, 0, num_entries*sizeof(Entry));
	if (bytes_read != filesize)
	{
		LL_WARNS("TextureCache") << "Bad cache file (2): " << mTexturesDirEntriesFileName << " Purging." << LL_ENDL;
		purgeAllTextures(false);
		return;
	}
	
	LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Reading " << num_entries << " Entries from " << mTexturesDirEntriesFileName << LL_ENDL;
	
	std::map<LLUUID, S32> entry_idx_map;
	S64 total_size = 0;
	for (S32 idx=0; idx<num_entries; idx++)
	{
		const LLUUID& id = entries[idx].mID;
 		LL_DEBUGS("TextureCache") << "Entry: " << id << " Size: " << entries[idx].mSize << " Time: " << entries[idx].mTime << LL_ENDL;
		std::map<LLUUID, S32>::iterator iter = entry_idx_map.find(id);
		if (iter != entry_idx_map.end())
		{
			// Newer entry replacing older entry
			S32 pidx = iter->second;
			total_size -= entries[pidx].mSize;
			entries[pidx].mSize = 0; // flag: skip older entry
		}
		entry_idx_map[id] = idx;
		total_size += entries[idx].mSize;
	}

	U32 validate_idx = 0;
	if (validate)
	{
		validate_idx = gSavedSettings.getU32("CacheValidateCounter");
		U32 next_idx = (++validate_idx) % 256;
		gSavedSettings.setU32("CacheValidateCounter", next_idx);
		LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Validating: " << validate_idx << LL_ENDL;
	}
	
	S64 min_cache_size = sCacheMaxTexturesSize / 100 * 95;
	S32 purge_count = 0;
	S32 next_idx = 0;
	for (S32 idx=0; idx<num_entries; idx++)
	{
		if (entries[idx].mSize == 0)
		{
			continue;
		}
		bool purge_entry = false;
		std::string filename = getTextureFileName(entries[idx].mID);
		if (total_size >= min_cache_size)
		{
			purge_entry = true;
		}
		else if (validate)
		{
			// make sure file exists and is the correct size
			S32 uuididx = entries[idx].mID.mData[0];
			if (uuididx == validate_idx)
			{
 				LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mSize << LL_ENDL;
				S32 bodysize = ll_apr_file_size(filename, NULL);
				if (bodysize != entries[idx].mSize)
				{
					LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mSize
							<< filename << LL_ENDL;
					purge_entry = true;
				}
			}
		}
		if (purge_entry)
		{
			purge_count++;
			LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL;
			mFilesToDelete.push_back(filename);
			total_size -= entries[idx].mSize;
			entries[idx].mSize = 0;
		}
		else
		{
			if (next_idx != idx)
			{
				entries[next_idx] = entries[idx];
			}
			++next_idx;
		}
	}
	num_entries = next_idx;

	mTimeLastFileDelete.reset();

	LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Writing Entries: " 
		<< num_entries << " (" << num_entries*sizeof(Entry)/1024 << "KB)"
		<< LL_ENDL;
	
	ll_apr_file_remove(mTexturesDirEntriesFileName, NULL);
	ll_apr_file_write_ex(mTexturesDirEntriesFileName, NULL,
						 (U8*)&entries[0], 0, num_entries*sizeof(Entry));
	
	mTexturesSizeTotal = 0;
	mTexturesSizeMap.clear();
	for (S32 idx=0; idx<num_entries; idx++)
	{
		mTexturesSizeMap[entries[idx].mID] = entries[idx].mSize;
		mTexturesSizeTotal += entries[idx].mSize;
	}
	llassert(mTexturesSizeTotal == total_size);
	
	delete[] entries;

	// *FIX:Mani - watchdog back on.
	LLAppViewer::instance()->resumeMainloopTimeout();
	
	LL_INFOS("TextureCache") << "TEXTURE CACHE:"
			<< " PURGED: " << purge_count
			<< " ENTRIES: " << num_entries
			<< " CACHE SIZE: " << total_size/1024/1024 << " MB"
			<< llendl;
}
Example #7
0
//------------------------------------------------------------------------------
// Write the BMP file
//------------------------------------------------------------------------------
bool BmpTexture::writeFile()
{
   return writeFileBMP(getTextureFileName(), getTexturePath());
    }
Example #8
0
//------------------------------------------------------------------------------
// Read the BMP file
//------------------------------------------------------------------------------
bool BmpTexture::readFile()
{
   return readFileBMP(getTextureFileName(), getTexturePath());
}
Example #9
0
void LLTextureCache::purgeTextures(bool validate)
{
	if (mReadOnly)
	{
		return;
	}

	if (!mThreaded)
	{
		// *FIX:Mani - watchdog off.
		LLAppViewer::instance()->pauseMainloopTimeout();
	}
	
	LLMutexLock lock(&mHeaderMutex);

	llinfos << "TEXTURE CACHE: Purging." << llendl;

	// Read the entries list
	std::vector<Entry> entries;
	U32 num_entries = openAndReadEntries(entries);
	if (!num_entries)
	{
		writeEntriesAndClose(entries);
		return; // nothing to purge
	}
	
	// Use mTexturesSizeMap to collect UUIDs of textures with bodies
	typedef std::set<std::pair<U32,S32> > time_idx_set_t;
	std::set<std::pair<U32,S32> > time_idx_set;
	for (size_map_t::iterator iter1 = mTexturesSizeMap.begin();
		 iter1 != mTexturesSizeMap.end(); ++iter1)
	{
		if (iter1->second > 0)
		{
			id_map_t::iterator iter2 = mHeaderIDMap.find(iter1->first);
			if (iter2 != mHeaderIDMap.end())
			{
				S32 idx = iter2->second;
				time_idx_set.insert(std::make_pair(entries[idx].mTime, idx));
// 				llinfos << "TIME: " << entries[idx].mTime << " TEX: " << entries[idx].mID << " IDX: " << idx << " Size: " << entries[idx].mImageSize << llendl;
			}
		}
	}
	
	// Validate 1/256th of the files on startup
	U32 validate_idx = 0;
	if (validate)
	{
		validate_idx = gSavedSettings.getU32("CacheValidateCounter");
		U32 next_idx = (validate_idx + 1) % 256;
		gSavedSettings.setU32("CacheValidateCounter", next_idx);
		LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Validating: " << validate_idx << LL_ENDL;
	}

	S64 cache_size = mTexturesSizeTotal;
	S64 purged_cache_size = (sCacheMaxTexturesSize * (S64)((1.f-TEXTURE_CACHE_PURGE_AMOUNT)*100)) / 100;
	S32 purge_count = 0;
	for (time_idx_set_t::iterator iter = time_idx_set.begin();
		 iter != time_idx_set.end(); ++iter)
	{
		S32 idx = iter->second;
		bool purge_entry = false;
		std::string filename = getTextureFileName(entries[idx].mID);
		if (cache_size >= purged_cache_size)
		{
			purge_entry = true;
		}
		else if (validate)
		{
			// make sure file exists and is the correct size
			S32 uuididx = entries[idx].mID.mData[0];
			if (uuididx == validate_idx)
			{
 				LL_DEBUGS("TextureCache") << "Validating: " << filename << "Size: " << entries[idx].mBodySize << LL_ENDL;
				S32 bodysize = LLAPRFile::size(filename);
				if (bodysize != entries[idx].mBodySize)
				{
					LL_WARNS("TextureCache") << "TEXTURE CACHE BODY HAS BAD SIZE: " << bodysize << " != " << entries[idx].mBodySize
							<< filename << LL_ENDL;
					purge_entry = true;
				}
			}
		}
		else
		{
			break;
		}
		
		if (purge_entry)
		{
			purge_count++;
	 		LL_DEBUGS("TextureCache") << "PURGING: " << filename << LL_ENDL;
			if (entries[idx].mBodySize > 0)
			{
				LLAPRFile::remove(filename);
			}
			else if (LLAPRFile::isExist(filename))	// Sanity check. Shouldn't exist.
			{
				LL_WARNS("TextureCache") << "Entry has zero body size but existing " << filename << ". Deleting file too..." << LL_ENDL;
				LLAPRFile::remove(filename);
			}
			cache_size -= entries[idx].mBodySize;
			mTexturesSizeTotal -= entries[idx].mBodySize;
			entries[idx].mBodySize = 0;
			mTexturesSizeMap.erase(entries[idx].mID);
		}
	}

	LL_DEBUGS("TextureCache") << "TEXTURE CACHE: Writing Entries: " << num_entries << LL_ENDL;

	writeEntriesAndClose(entries);
	
	if (!mThreaded)
	{
		// *FIX:Mani - watchdog back on.
		LLAppViewer::instance()->resumeMainloopTimeout();
	}
	
	LL_INFOS("TextureCache") << "TEXTURE CACHE:"
			<< " PURGED: " << purge_count
			<< " ENTRIES: " << num_entries
			<< " CACHE SIZE: " << mTexturesSizeTotal / 1024*1024 << " MB"
			<< llendl;
}
Example #10
0
void ParticleEditor::SaveConfigFile(QString filename)
{
	FILE* sFile;
	sFile = fopen(filename.toLocal8Bit().data(), "wb");
	if (!sFile){
		addConsoleInfo("保存失败");
		return;
	}
	QVariantMap document;
	QVariantList resList;
	QVariantMap particleData;

	//导出资源
	QStringList imageList = resourceView->getImageList();
	for (int i = 0; i < imageList.size(); i++){
		QVariant res = imageList.at(i);
		resList.append(res);
	}

	//导出粒子
	auto layer = dynamic_cast<C3DLayer*>(g_Layer);
	auto particleSystem = layer->getParticleSystem();
	particleData.insert("texture", particleSystem->getTextureFileName().c_str());
	particleData.insert("count", particleSystem->getParticleCount());
	particleData.insert("particle_type", particleSystem->getParticleType());
	particleData.insert("blendfunc_src", particleSystem->getBlendFunc().src);
	particleData.insert("blendfunc_dst", particleSystem->getBlendFunc().dst);
	auto data = particleSystem->getParticleData();
	particleData.insert("velocity_min_x", data.m_Velocity_Min.x);
	particleData.insert("velocity_min_y", data.m_Velocity_Min.y);
	particleData.insert("velocity_min_z", data.m_Velocity_Min.z);
	particleData.insert("velocity_max_x", data.m_Velocity_Max.x);
	particleData.insert("velocity_max_y", data.m_Velocity_Max.y);
	particleData.insert("velocity_max_z", data.m_Velocity_Max.z);
	particleData.insert("accleration_min_x", data.m_Acceleration_Min.x);
	particleData.insert("accleration_min_y", data.m_Acceleration_Min.y);
	particleData.insert("accleration_min_z", data.m_Acceleration_Min.z);
	particleData.insert("accleration_max_x", data.m_Acceleration_Max.x);
	particleData.insert("accleration_max_y", data.m_Acceleration_Max.y);
	particleData.insert("accleration_max_z", data.m_Acceleration_Max.z);
	particleData.insert("size_min_x", data.m_Size_Min.x);
	particleData.insert("size_min_y", data.m_Size_Min.y);
	particleData.insert("size_min_z", data.m_Size_Min.z);
	particleData.insert("size_max_x", data.m_Size_Max.x);
	particleData.insert("size_max_y", data.m_Size_Max.y);
	particleData.insert("size_max_z", data.m_Size_Max.z);
	particleData.insert("size_velocity_x", data.m_Size_Velocity.x);
	particleData.insert("size_velocity_y", data.m_Size_Velocity.y);
	particleData.insert("size_velocity_z", data.m_Size_Velocity.z);
	particleData.insert("color_min_x", data.m_Color_Min.x);
	particleData.insert("color_min_y", data.m_Color_Min.y);
	particleData.insert("color_min_z", data.m_Color_Min.z);
	particleData.insert("color_max_x", data.m_Color_Max.x);
	particleData.insert("color_max_y", data.m_Color_Max.y);
	particleData.insert("color_max_z", data.m_Color_Max.z);
	particleData.insert("color_velocity_x", data.m_Color_Velocity.x);
	particleData.insert("color_velocity_y", data.m_Color_Velocity.y);
	particleData.insert("color_velocity_z", data.m_Color_Velocity.z);
	particleData.insert("life_min", data.m_Life_Min);
	particleData.insert("life_max", data.m_Life_Max);
	particleData.insert("life_velocity", data.m_Life_Velocity);
	particleData.insert("m_color_r", particleSystem->getColor()[0]);
	particleData.insert("m_color_g", particleSystem->getColor()[1]);
	particleData.insert("m_color_b", particleSystem->getColor()[2]);
	particleData.insert("m_color_a", particleSystem->getColor()[3]);
	document.insert("resList", resList);
	document.insert("particleData", particleData);
	QJsonDocument jsonDocument = QJsonDocument::fromVariant(document);
	QByteArray array = jsonDocument.toJson(QJsonDocument::Compact);
	unsigned int count = array.size();
	const char* data__ = (const char*)array.data();
	fwrite(data__, count, 1, sFile);
	fclose(sFile);
}