diff options
Diffstat (limited to 'indra')
| -rw-r--r-- | indra/llprimitive/llmodel.cpp | 77 | ||||
| -rw-r--r-- | indra/llprimitive/llmodel.h | 7 | ||||
| -rwxr-xr-x | indra/newview/llfloatermodelpreview.cpp | 132 | ||||
| -rw-r--r-- | indra/newview/llfloatermodelpreview.h | 5 | ||||
| -rwxr-xr-x | indra/newview/llmeshrepository.cpp | 54 | ||||
| -rwxr-xr-x | indra/newview/llmeshrepository.h | 5 | 
6 files changed, 170 insertions, 110 deletions
| diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index d3f42c63d5..986bde0581 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1378,6 +1378,14 @@ LLSD LLModel::writeModel(  		}  	} +	if (as_slm) +	{ //save material list names +		for (U32 i = 0; i < high->mMaterialList.size(); ++i) +		{ +			mdl["material_list"][i] = high->mMaterialList[i]; +		} +	} +  	for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx)  	{  		if (model[idx] && model[idx]->getNumVolumeFaces() > 0) @@ -1565,10 +1573,10 @@ LLSD LLModel::writeModel(  		}  	} -	return writeModelToStream(ostr, mdl, nowrite); +	return writeModelToStream(ostr, mdl, nowrite, as_slm);  } -LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite) +LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite, BOOL as_slm)  {  	U32 bytes = 0; @@ -1576,6 +1584,11 @@ LLSD LLModel::writeModelToStream(std::ostream& ostr, LLSD& mdl, BOOL nowrite)  	LLSD header; +	if (as_slm && mdl.has("material_list")) +	{ //save material binding names to header +		header["material_list"] = mdl["material_list"]; +	} +  	std::string skin;  	if (mdl.has("skin")) @@ -1769,6 +1782,15 @@ bool LLModel::loadModel(std::istream& is)  		}  	} +	if (header.has("material_list")) +	{ //load material list names +		mMaterialList.clear(); +		for (U32 i = 0; i < header["material_list"].size(); ++i) +		{ +			mMaterialList.push_back(header["material_list"][i].asString()); +		} +	} +  	std::string nm[] =   	{  		"lowest_lod", @@ -1855,6 +1877,57 @@ bool LLModel::loadModel(std::istream& is)  } +void LLModel::matchMaterialOrder(LLModel* ref) +{ +	llassert(ref->mMaterialList.size() == mMaterialList.size()); + +	std::map<std::string, U32> index_map; +	 +	//build a map of material slot names to face indexes +	bool reorder = false; +	std::set<std::string> base_mat; +	std::set<std::string> cur_mat; + +	for (U32 i = 0; i < mMaterialList.size(); i++) +	{ +		index_map[ref->mMaterialList[i]] = i; +		if (!reorder) +		{ //if any material name does not match reference, we need to reorder +			reorder = ref->mMaterialList[i] != mMaterialList[i]; +		} +		base_mat.insert(ref->mMaterialList[i]); +		cur_mat.insert(mMaterialList[i]); +	} + + +	if (reorder &&  +		base_mat == cur_mat) //don't reorder if material name sets don't match +	{ +		std::vector<LLVolumeFace> new_face_list; +		new_face_list.resize(mVolumeFaces.size()); + +		std::vector<std::string> new_material_list; +		new_material_list.resize(mVolumeFaces.size()); + +		//rebuild face list so materials have the same order  +		//as the reference model +		for (U32 i = 0; i < mMaterialList.size(); ++i) +		{  +			U32 ref_idx = index_map[mMaterialList[i]]; +			new_face_list[ref_idx] = mVolumeFaces[i]; + +			new_material_list[ref_idx] = mMaterialList[i]; +		} + +		llassert(new_material_list == ref->mMaterialList); +		 +		mVolumeFaces = new_face_list; +	} + +	//override material list with reference model ordering +	mMaterialList = ref->mMaterialList; +} +  bool LLModel::loadSkinInfo(LLSD& header, std::istream &is)  { diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h index 1ece877f0f..3f58eba07d 100644 --- a/indra/llprimitive/llmodel.h +++ b/indra/llprimitive/llmodel.h @@ -143,7 +143,7 @@ public:  	static LLSD writeModelToStream(  		std::ostream& ostr,  		LLSD& mdl, -		BOOL nowrite = FALSE); +		BOOL nowrite = FALSE, BOOL as_slm = FALSE);  	static LLModel* loadModelFromDomMesh(domMesh* mesh);  	static std::string getElementLabel(daeElement* element); @@ -172,6 +172,11 @@ public:  	void optimizeVolumeFaces();  	void offsetMesh( const LLVector3& pivotPoint );  	void getNormalizedScaleTranslation(LLVector3& scale_out, LLVector3& translation_out); +	 +	//reorder face list based on mMaterialList in this and reference so  +	//order matches that of reference (material ordering touchup) +	void matchMaterialOrder(LLModel* reference); +  	std::vector<std::string> mMaterialList;  	//data used for skin weights diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index ab370a221f..6c6b124b39 100755 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -103,6 +103,9 @@  #include "llanimationstates.h"  #include "glod/glod.h" + +const S32 SLM_SUPPORTED_VERSION = 2; +  //static  S32 LLFloaterModelPreview::sUploadAmount = 10;  LLFloaterModelPreview* LLFloaterModelPreview::sInstance = NULL; @@ -410,8 +413,6 @@ BOOL LLFloaterModelPreview::postBuild()  	childSetAction("reset_btn", onReset, this); -	childSetAction("clear_materials", onClearMaterials, this); -  	childSetCommitCallback("preview_lod_combo", onPreviewLODCommit, this);  	childSetCommitCallback("upload_skin", onUploadSkinCommit, this); @@ -1941,8 +1942,11 @@ bool LLModelLoader::doLoadModel()  								mesh_scale *= transformation;  								transformation = mesh_scale; -								std::vector<LLImportMaterial> materials; -								materials.resize(model->getNumVolumeFaces()); +								std::map<std::string, LLImportMaterial> materials; +								for (U32 i = 0; i < model->mMaterialList.size(); ++i) +								{ +									materials[model->mMaterialList[i]] = LLImportMaterial(); +								}  								mScene[transformation].push_back(LLModelInstance(model, model->mLabel, transformation, materials));  								stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);  							} @@ -2004,6 +2008,11 @@ bool LLModelLoader::loadFromSLM(const std::string& filename)  	//build model list for each LoD  	model_list model[LLModel::NUM_LODS]; +	if (data["version"].asInteger() != SLM_SUPPORTED_VERSION) +	{  //unsupported version +		return false; +	} +  	LLSD& mesh = data["mesh"];  	LLVolumeParams volume_params; @@ -2321,14 +2330,17 @@ void LLModelLoader::loadTextures()  	{  		for(U32 i = 0 ; i < iter->second.size(); i++)  		{ -			for(U32 j = 0 ; j < iter->second[i].mMaterial.size() ; j++) +			for(std::map<std::string, LLImportMaterial>::iterator j = iter->second[i].mMaterial.begin(); +				j != iter->second[i].mMaterial.end(); ++j)  			{ -				if(!iter->second[i].mMaterial[j].mDiffuseMapFilename.empty()) +				LLImportMaterial& material = j->second; + +				if(!material.mDiffuseMapFilename.empty())  				{ -					iter->second[i].mMaterial[j].mDiffuseMap =  -						LLViewerTextureManager::getFetchedTextureFromUrl("file://" + iter->second[i].mMaterial[j].mDiffuseMapFilename, TRUE, LLViewerTexture::BOOST_PREVIEW); -					iter->second[i].mMaterial[j].mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, mPreview, NULL, FALSE); -					iter->second[i].mMaterial[j].mDiffuseMap->forceToSaveRawImage(0, F32_MAX); +					material.mDiffuseMap =  +						LLViewerTextureManager::getFetchedTextureFromUrl("file://" + material.mDiffuseMapFilename, TRUE, LLViewerTexture::BOOST_PREVIEW); +					material.mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, mPreview, NULL, FALSE); +					material.mDiffuseMap->forceToSaveRawImage(0, F32_MAX);  					mNumOfFetchingTextures++ ;  				}  			} @@ -2628,7 +2640,7 @@ void LLModelLoader::processElement( daeElement* element, bool& badElement )  				{  					LLMatrix4 transformation = mTransform; -					std::vector<LLImportMaterial> materials = getMaterials(model, instance_geo); +					std::map<std::string, LLImportMaterial> materials = getMaterials(model, instance_geo);  					// adjust the transformation to compensate for mesh normalization  					LLVector3 mesh_scale_vector; @@ -2684,9 +2696,9 @@ void LLModelLoader::processElement( daeElement* element, bool& badElement )  	}  } -std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domInstance_geometry* instance_geo) +std::map<std::string, LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domInstance_geometry* instance_geo)  { -	std::vector<LLImportMaterial> materials; +	std::map<std::string, LLImportMaterial> materials;  	for (int i = 0; i < model->mMaterialList.size(); i++)  	{  		LLImportMaterial import_material; @@ -2733,7 +2745,8 @@ std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domIns  			}  		} -		materials.push_back(import_material); +		import_material.mBinding = model->mMaterialList[i]; +		materials[model->mMaterialList[i]] = import_material;  	}  	return materials; @@ -3118,6 +3131,19 @@ void LLModelPreview::rebuildUploadData()  		mFMP->childEnable("ok_btn");  	} +	//reorder materials to match mBaseModel +	for (U32 i = 0; i < LLModel::NUM_LODS; i++) +	{ +		if (mBaseModel.size() == mModel[i].size()) +		{ +			for (U32 j = 0; j < mBaseModel.size(); ++j) +			{ +				mModel[i][j]->matchMaterialOrder(mBaseModel[j]); +				llassert(mModel[i][j]->mMaterialList == mBaseModel[j]->mMaterialList); +			} +		} +	} +  	for (LLModelLoader::scene::iterator iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter)  	{ //for each transform in scene  		LLMatrix4 mat = iter->first; @@ -3216,6 +3242,8 @@ void LLModelPreview::saveUploadData(const std::string& filename, bool save_skinw  	LLSD data; +	data["version"] = SLM_SUPPORTED_VERSION; +  	S32 mesh_id = 0;  	//build list of unique models and initialize local id @@ -3591,43 +3619,6 @@ void LLModelPreview::generateNormals()  	updateStatusMessages();  } -void LLModelPreview::clearMaterials() -{ -	for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) -	{ //for each transform in current scene -		for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter) -		{ //for each instance with that transform -			LLModelInstance& source_instance = *model_iter; -			LLModel* source = source_instance.mModel; - -			for (S32 i = 0; i < source->getNumVolumeFaces(); ++i) -			{ //for each face in instance -				LLImportMaterial& source_material = source_instance.mMaterial[i]; - -				//clear material info -				source_material.mDiffuseColor = LLColor4(1,1,1,1); -				source_material.mDiffuseMap = NULL; -				source_material.mDiffuseMapFilename.clear(); -				source_material.mDiffuseMapLabel.clear(); -				source_material.mFullbright = false; -			} -		} -	} - -	mVertexBuffer[mPreviewLOD].clear(); - -	if (mPreviewLOD == LLModel::LOD_HIGH) -	{ -		mBaseScene = mScene[mPreviewLOD]; -		mBaseModel = mModel[mPreviewLOD]; -		clearGLODGroup(); -		mVertexBuffer[5].clear(); -	} - -	mResourceCost = calcResourceCost(); -	refresh(); -} -  void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_limit)  {  	if (mBaseModel.empty()) @@ -4897,6 +4888,19 @@ BOOL LLModelPreview::render()  			}  		} +		//DEBUG -- make sure material lists all match +		for (U32 i = 0; i < LLModel::NUM_LODS; i++) +		{ +			if (mBaseModel.size() == mModel[i].size()) +			{ +				for (U32 j = 0; j < mBaseModel.size(); ++j) +				{ +					mModel[i][j]->matchMaterialOrder(mBaseModel[j]); +					llassert(mModel[i][j]->mMaterialList == mBaseModel[j]->mMaterialList); +				} +			} +		} +  		if (regen)  		{  			genBuffers(mPreviewLOD, skin_weight); @@ -4928,13 +4932,18 @@ BOOL LLModelPreview::render()  					if (textures)  					{ -						glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); -						if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull()) +						const std::string& binding = instance.mModel->mMaterialList[i]; +						const LLImportMaterial& material = instance.mMaterial[binding]; + +						llassert(binding == model->mMaterialList[i]); +						 +						glColor4fv(material.mDiffuseColor.mV); +						if (material.mDiffuseMap.notNull())  						{ -							if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1) +							if (material.mDiffuseMap->getDiscardLevel() > -1)  							{ -								gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true); -								mTextureSet.insert(instance.mMaterial[i].mDiffuseMap.get()); +								gGL.getTexUnit(0)->bind(material.mDiffuseMap, true); +								mTextureSet.insert(material.mDiffuseMap.get());  							}  						}  					} @@ -5234,8 +5243,10 @@ BOOL LLModelPreview::render()  								position[j] = v;  							} +							const std::string& binding = instance.mModel->mMaterialList[i]; +							const LLImportMaterial& material = instance.mMaterial[binding];  							buffer->setBuffer(type_mask & buffer->getTypeMask()); -							glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); +							glColor4fv(material.mDiffuseColor.mV);  							gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);  							buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);  							glColor3f(0.4f, 0.4f, 0.4f); @@ -5384,13 +5395,6 @@ void LLFloaterModelPreview::onUpload(void* user_data)  //static -void LLFloaterModelPreview::onClearMaterials(void* user_data) -{ -	LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; -	mp->mModelPreview->clearMaterials(); -} - -//static  void LLFloaterModelPreview::refresh(LLUICtrl* ctrl, void* user_data)  {  	sInstance->toggleCalculateButton(true); diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h index 56098c6250..e252c9a677 100644 --- a/indra/newview/llfloatermodelpreview.h +++ b/indra/newview/llfloatermodelpreview.h @@ -109,7 +109,7 @@ public:  	void loadTextures() ; //called in the main thread.  	void processElement(daeElement* element, bool& badElement); -	std::vector<LLImportMaterial> getMaterials(LLModel* model, domInstance_geometry* instance_geo); +	std::map<std::string, LLImportMaterial> getMaterials(LLModel* model, domInstance_geometry* instance_geo);  	LLImportMaterial profileToMaterial(domProfile_COMMON* material);  	std::string getElementLabel(daeElement *element);  	LLColor4 getDaeColor(daeElement* element); @@ -182,8 +182,6 @@ public:  	static void onUpload(void* data); -	static void onClearMaterials(void* data); -	  	static void refresh(LLUICtrl* ctrl, void* data);  	void updateResourceCost(); @@ -330,7 +328,6 @@ public:  	void loadModelCallback(S32 lod);  	void genLODs(S32 which_lod = -1, U32 decimation = 3, bool enforce_tri_limit = false);  	void generateNormals(); -	void clearMaterials();  	U32 calcResourceCost();  	void rebuildUploadData();  	void saveUploadData(bool save_skinweights, bool save_joint_poisitions); diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index a06422a177..9e4b749ea1 100755 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -36,7 +36,6 @@  #include "llbufferstream.h"  #include "llcurl.h"  #include "lldatapacker.h" -#include "llfasttimer.h"  #include "llfloatermodelpreview.h"  #include "llfloaterperms.h"  #include "lleconomy.h" @@ -72,9 +71,6 @@  #include <queue> -LLFastTimer::DeclareTimer FTM_MESH_UPDATE("Mesh Update"); -LLFastTimer::DeclareTimer FTM_LOAD_MESH("Load Mesh"); -  LLMeshRepository gMeshRepo;  const U32 MAX_MESH_REQUESTS_PER_SECOND = 100; @@ -1410,12 +1406,7 @@ void LLMeshUploadThread::wholeModelToLLSD(LLSD& dest, bool include_textures)  			for (S32 face_num = 0; face_num < data.mBaseModel->getNumVolumeFaces(); face_num++)  			{ -				if(face_num >= instance.mMaterial.size()) -				{ -					break ; -				} - -				LLImportMaterial& material = instance.mMaterial[face_num]; +				LLImportMaterial& material = instance.mMaterial[data.mBaseModel->mMaterialList[face_num]];  				LLSD face_entry = LLSD::emptyMap();  				LLViewerFetchedTexture *texture = material.mDiffuseMap.get(); @@ -1580,9 +1571,6 @@ void LLMeshUploadThread::requestWholeModelFee()  	mFinished = true;  } -static LLFastTimer::DeclareTimer FTM_NOTIFY_MESH_LOADED("Notify Loaded"); -static LLFastTimer::DeclareTimer FTM_NOTIFY_MESH_UNAVAILABLE("Notify Unavailable"); -  void LLMeshRepoThread::notifyLoadedMeshes()  {  	while (!mLoadedQ.empty()) @@ -2146,8 +2134,6 @@ S32 LLMeshRepository::loadMesh(LLVOVolume* vobj, const LLVolumeParams& mesh_para  		return detail;  	} -	LLFastTimer t(FTM_LOAD_MESH);  -  	{  		LLMutexLock lock(mMeshMutex);  		//add volume to list of loading meshes @@ -2223,11 +2209,6 @@ S32 LLMeshRepository::loadMesh(LLVOVolume* vobj, const LLVolumeParams& mesh_para  	return detail;  } -static LLFastTimer::DeclareTimer FTM_START_MESH_THREAD("Start Thread"); -static LLFastTimer::DeclareTimer FTM_LOAD_MESH_LOD("Load LOD"); -static LLFastTimer::DeclareTimer FTM_MESH_LOCK1("Lock 1"); -static LLFastTimer::DeclareTimer FTM_MESH_LOCK2("Lock 2"); -  void LLMeshRepository::notifyLoadedMeshes()  { //called from main thread @@ -2293,18 +2274,9 @@ void LLMeshRepository::notifyLoadedMeshes()  		}  	} -	LLFastTimer t(FTM_MESH_UPDATE); - -	{ -		LLFastTimer t(FTM_MESH_LOCK1); -		mMeshMutex->lock();	 -	} - -	{ -		LLFastTimer t(FTM_MESH_LOCK2); -		mThread->mMutex->lock(); -	} -	 +	mMeshMutex->lock();	 +	mThread->mMutex->lock(); +		  	//popup queued error messages from background threads  	while (!mUploadErrorQ.empty())  	{ @@ -2356,7 +2328,6 @@ void LLMeshRepository::notifyLoadedMeshes()  		while (!mPendingRequests.empty() && push_count > 0)  		{ -			LLFastTimer t(FTM_LOAD_MESH_LOD);  			LLMeshRepoThread::LODRequest& request = mPendingRequests.front();  			mThread->loadMeshLOD(request.mMeshParams, request.mLOD);  			mPendingRequests.erase(mPendingRequests.begin()); @@ -2757,6 +2728,11 @@ bool LLImportMaterial::operator<(const LLImportMaterial &rhs) const  		return mDiffuseColor < rhs.mDiffuseColor;  	} +	if (mBinding != rhs.mBinding) +	{ +		return mBinding < rhs.mBinding; +	} +  	return mFullbright < rhs.mFullbright;  } @@ -3391,7 +3367,8 @@ LLModelInstance::LLModelInstance(LLSD& data)  	for (U32 i = 0; i < data["material"].size(); ++i)  	{ -		mMaterial.push_back(LLImportMaterial(data["material"][i])); +		LLImportMaterial mat(data["material"][i]); +		mMaterial[mat.mBinding] = mat;  	}  } @@ -3404,9 +3381,10 @@ LLSD LLModelInstance::asLLSD()  	ret["label"] = mLabel;  	ret["transform"] = mTransform.getValue(); -	for (U32 i = 0; i < mMaterial.size(); ++i) +	U32 i = 0; +	for (std::map<std::string, LLImportMaterial>::iterator iter = mMaterial.begin(); iter != mMaterial.end(); ++iter)  	{ -		ret["material"][i] = mMaterial[i].asLLSD(); +		ret["material"][i++] = iter->second.asLLSD();  	}  	return ret; @@ -3418,6 +3396,7 @@ LLImportMaterial::LLImportMaterial(LLSD& data)  	mDiffuseMapLabel = data["diffuse"]["label"].asString();  	mDiffuseColor.setValue(data["diffuse"]["color"]);  	mFullbright = data["fullbright"].asBoolean(); +	mBinding = data["binding"].asString();  } @@ -3429,7 +3408,8 @@ LLSD LLImportMaterial::asLLSD()  	ret["diffuse"]["label"] = mDiffuseMapLabel;  	ret["diffuse"]["color"] = mDiffuseColor.getValue();  	ret["fullbright"] = mFullbright; -	 +	ret["binding"] = mBinding; +  	return ret;  } diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h index 74a08a998f..d775e8f74a 100755 --- a/indra/newview/llmeshrepository.h +++ b/indra/newview/llmeshrepository.h @@ -92,6 +92,7 @@ public:  	LLPointer<LLViewerFetchedTexture> mDiffuseMap;  	std::string mDiffuseMapFilename;  	std::string mDiffuseMapLabel; +	std::string mBinding;  	LLColor4 mDiffuseColor;  	bool mFullbright; @@ -120,9 +121,9 @@ public:  	S32 mLocalMeshID;  	LLMatrix4 mTransform; -	std::vector<LLImportMaterial> mMaterial; +	std::map<std::string, LLImportMaterial> mMaterial; -	LLModelInstance(LLModel* model, const std::string& label, LLMatrix4& transform, std::vector<LLImportMaterial>& materials) +	LLModelInstance(LLModel* model, const std::string& label, LLMatrix4& transform, std::map<std::string, LLImportMaterial>& materials)  		: mModel(model), mLabel(label), mTransform(transform), mMaterial(materials)  	{  		mLocalMeshID = -1; | 
