summaryrefslogtreecommitdiff
path: root/indra/newview/llfloatermodelpreview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llfloatermodelpreview.cpp')
-rwxr-xr-xindra/newview/llfloatermodelpreview.cpp226
1 files changed, 138 insertions, 88 deletions
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 7448f2bb2a..19cec55837 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -290,6 +290,22 @@ bool ll_is_degenerate(const LLVector4a& a, const LLVector4a& b, const LLVector4a
bool validate_face(const LLVolumeFace& face)
{
+
+ for (U32 v = 0; v < face.mNumVertices; v++)
+ {
+ if(face.mPositions && !face.mPositions[v].isFinite3())
+ {
+ llwarns << "NaN position data in face found!" << llendl;
+ return false;
+ }
+
+ if(face.mNormals && !face.mNormals[v].isFinite3())
+ {
+ llwarns << "NaN normal data in face found!" << llendl;
+ return false;
+ }
+ }
+
for (U32 i = 0; i < face.mNumIndices; ++i)
{
if (face.mIndices[i] >= face.mNumVertices)
@@ -305,8 +321,10 @@ bool validate_face(const LLVolumeFace& face)
return false;
}
+
/*const LLVector4a scale(0.5f);
+
for (U32 i = 0; i < face.mNumIndices; i+=3)
{
U16 idx1 = face.mIndices[i];
@@ -323,7 +341,6 @@ bool validate_face(const LLVolumeFace& face)
return false;
}
}*/
-
return true;
}
@@ -396,7 +413,6 @@ mCalculateBtn(NULL)
sInstance = this;
mLastMouseX = 0;
mLastMouseY = 0;
- mGLName = 0;
mStatusLock = new LLMutex(NULL);
mModelPreview = NULL;
@@ -498,7 +514,7 @@ BOOL LLFloaterModelPreview::postBuild()
text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i));
}
}
- std::string current_grid = LLGridManager::getInstance()->getGridLabel();
+ std::string current_grid = LLGridManager::getInstance()->getGridId();
std::transform(current_grid.begin(),current_grid.end(),current_grid.begin(),::tolower);
std::string validate_url;
if (current_grid == "agni")
@@ -538,11 +554,6 @@ LLFloaterModelPreview::~LLFloaterModelPreview()
delete mModelPreview;
}
- if (mGLName)
- {
- LLImageGL::deleteTextures(1, &mGLName );
- }
-
delete mStatusLock;
mStatusLock = NULL;
}
@@ -743,6 +754,20 @@ void LLFloaterModelPreview::onAutoFillCommit(LLUICtrl* ctrl, void* userdata)
void LLFloaterModelPreview::onLODParamCommit(S32 lod, bool enforce_tri_limit)
{
mModelPreview->onLODParamCommit(lod, enforce_tri_limit);
+
+ //refresh LoDs that reference this one
+ for (S32 i = lod - 1; i >= 0; --i)
+ {
+ LLComboBox* lod_source_combo = getChild<LLComboBox>("lod_source_" + lod_name[i]);
+ if (lod_source_combo->getCurrentIndex() == LLModelPreview::USE_LOD_ABOVE)
+ {
+ onLoDSourceCommit(i);
+ }
+ else
+ {
+ break;
+ }
+ }
}
@@ -752,7 +777,6 @@ void LLFloaterModelPreview::onLODParamCommit(S32 lod, bool enforce_tri_limit)
void LLFloaterModelPreview::draw()
{
LLFloater::draw();
- LLRect r = getRect();
mModelPreview->update();
@@ -1676,7 +1700,6 @@ bool LLModelLoader::doLoadModel()
//If no skeleton, do a breadth-first search to get at specific joints
bool rootNode = false;
- bool skeletonWithNoRootNode = false;
//Need to test for a skeleton that does not have a root node
//This occurs when your instance controller does not have an associated scene
@@ -1687,10 +1710,6 @@ bool LLModelLoader::doLoadModel()
{
rootNode = true;
}
- else
- {
- skeletonWithNoRootNode = true;
- }
}
if ( !pSkeleton || !rootNode )
@@ -2494,7 +2513,7 @@ void LLModelLoader::loadTextures()
if(!material.mDiffuseMapFilename.empty())
{
material.mDiffuseMap =
- LLViewerTextureManager::getFetchedTextureFromUrl("file://" + material.mDiffuseMapFilename, TRUE, LLViewerTexture::BOOST_PREVIEW);
+ LLViewerTextureManager::getFetchedTextureFromUrl("file://" + material.mDiffuseMapFilename, FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_PREVIEW);
material.mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, mPreview, NULL, FALSE);
material.mDiffuseMap->forceToSaveRawImage(0, F32_MAX);
mNumOfFetchingTextures++ ;
@@ -3876,15 +3895,30 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_lim
U32 triangle_count = 0;
- for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
+ U32 instanced_triangle_count = 0;
+
+ //get the triangle count for the whole scene
+ for (LLModelLoader::scene::iterator iter = mBaseScene.begin(), endIter = mBaseScene.end(); iter != endIter; ++iter)
{
- LLModel* mdl = *iter;
- for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
+ for (LLModelLoader::model_instance_list::iterator instance = iter->second.begin(), end_instance = iter->second.end(); instance != end_instance; ++instance)
{
- triangle_count += mdl->getVolumeFace(i).mNumIndices/3;
+ LLModel* mdl = instance->mModel;
+ if (mdl)
+ {
+ instanced_triangle_count += mdl->getNumTriangles();
+ }
}
}
+ //get the triangle count for the non-instanced set of models
+ for (U32 i = 0; i < mBaseModel.size(); ++i)
+ {
+ triangle_count += mBaseModel[i]->getNumTriangles();
+ }
+
+ //get ratio of uninstanced triangles to instanced triangles
+ F32 triangle_ratio = (F32) triangle_count / (F32) instanced_triangle_count;
+
U32 base_triangle_count = triangle_count;
U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
@@ -3918,6 +3952,8 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_lim
if (which_lod > -1 && which_lod < NUM_LOD)
{
limit = mFMP->childGetValue("lod_triangle_limit_" + lod_name[which_lod]).asInteger();
+ //convert from "scene wide" to "non-instanced" triangle limit
+ limit = (S32) ( (F32) limit*triangle_ratio );
}
}
else
@@ -4023,7 +4059,7 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation, bool enforce_tri_lim
U32 actual_verts = 0;
U32 submeshes = 0;
- mRequestedTriangleCount[lod] = triangle_count;
+ mRequestedTriangleCount[lod] = (S32) ( (F32) triangle_count / triangle_ratio );
mRequestedErrorThreshold[lod] = lod_error_threshold;
glodGroupParameteri(mGroup, GLOD_ADAPT_MODE, lod_mode);
@@ -4205,28 +4241,36 @@ void LLModelPreview::updateStatusMessages()
//initialize total for this lod to 0
total_tris[lod] = total_verts[lod] = total_submeshes[lod] = 0;
- for (U32 i = 0; i < mModel[lod].size(); ++i)
- { //for each model in the lod
- S32 cur_tris = 0;
- S32 cur_verts = 0;
- S32 cur_submeshes = mModel[lod][i]->getNumVolumeFaces();
-
- for (S32 j = 0; j < cur_submeshes; ++j)
- { //for each submesh (face), add triangles and vertices to current total
- const LLVolumeFace& face = mModel[lod][i]->getVolumeFace(j);
- cur_tris += face.mNumIndices/3;
- cur_verts += face.mNumVertices;
- }
+ for (LLModelLoader::scene::iterator iter = mScene[lod].begin(), endIter = mScene[lod].end(); iter != endIter; ++iter)
+ {
+ for (LLModelLoader::model_instance_list::iterator instance = iter->second.begin(), end_instance = iter->second.end(); instance != end_instance; ++instance)
+ {
+ LLModel* model = instance->mModel;
+ if (model)
+ {
+ //for each model in the lod
+ S32 cur_tris = 0;
+ S32 cur_verts = 0;
+ S32 cur_submeshes = model->getNumVolumeFaces();
+
+ for (S32 j = 0; j < cur_submeshes; ++j)
+ { //for each submesh (face), add triangles and vertices to current total
+ const LLVolumeFace& face = model->getVolumeFace(j);
+ cur_tris += face.mNumIndices/3;
+ cur_verts += face.mNumVertices;
+ }
- //add this model to the lod total
- total_tris[lod] += cur_tris;
- total_verts[lod] += cur_verts;
- total_submeshes[lod] += cur_submeshes;
+ //add this model to the lod total
+ total_tris[lod] += cur_tris;
+ total_verts[lod] += cur_verts;
+ total_submeshes[lod] += cur_submeshes;
- //store this model's counts to asset data
- tris[lod].push_back(cur_tris);
- verts[lod].push_back(cur_verts);
- submeshes[lod].push_back(cur_submeshes);
+ //store this model's counts to asset data
+ tris[lod].push_back(cur_tris);
+ verts[lod].push_back(cur_verts);
+ submeshes[lod].push_back(cur_submeshes);
+ }
+ }
}
}
@@ -4403,34 +4447,38 @@ void LLModelPreview::updateStatusMessages()
}
//add up physics triangles etc
- S32 start = 0;
- S32 end = mModel[LLModel::LOD_PHYSICS].size();
-
S32 phys_tris = 0;
S32 phys_hulls = 0;
S32 phys_points = 0;
- for (S32 i = start; i < end; ++i)
- { //add up hulls and points and triangles for selected mesh(es)
- LLModel* model = mModel[LLModel::LOD_PHYSICS][i];
- S32 cur_submeshes = model->getNumVolumeFaces();
-
- LLModel::convex_hull_decomposition& decomp = model->mPhysics.mHull;
-
- if (!decomp.empty())
+ //get the triangle count for the whole scene
+ for (LLModelLoader::scene::iterator iter = mScene[LLModel::LOD_PHYSICS].begin(), endIter = mScene[LLModel::LOD_PHYSICS].end(); iter != endIter; ++iter)
+ {
+ for (LLModelLoader::model_instance_list::iterator instance = iter->second.begin(), end_instance = iter->second.end(); instance != end_instance; ++instance)
{
- phys_hulls += decomp.size();
- for (U32 i = 0; i < decomp.size(); ++i)
+ LLModel* model = instance->mModel;
+ if (model)
{
- phys_points += decomp[i].size();
- }
- }
- else
- { //choose physics shape OR decomposition, can't use both
- for (S32 j = 0; j < cur_submeshes; ++j)
- { //for each submesh (face), add triangles and vertices to current total
- const LLVolumeFace& face = model->getVolumeFace(j);
- phys_tris += face.mNumIndices/3;
+ S32 cur_submeshes = model->getNumVolumeFaces();
+
+ LLModel::convex_hull_decomposition& decomp = model->mPhysics.mHull;
+
+ if (!decomp.empty())
+ {
+ phys_hulls += decomp.size();
+ for (U32 i = 0; i < decomp.size(); ++i)
+ {
+ phys_points += decomp[i].size();
+ }
+ }
+ else
+ { //choose physics shape OR decomposition, can't use both
+ for (S32 j = 0; j < cur_submeshes; ++j)
+ { //for each submesh (face), add triangles and vertices to current total
+ const LLVolumeFace& face = model->getVolumeFace(j);
+ phys_tris += face.mNumIndices/3;
+ }
+ }
}
}
}
@@ -4594,7 +4642,7 @@ void LLModelPreview::updateLodControls(S32 lod)
if (!lod_combo) return;
S32 lod_mode = lod_combo->getCurrentIndex();
- if (lod_mode == 0) // LoD from file
+ if (lod_mode == LOD_FROM_FILE) // LoD from file
{
fmp->mLODMode[lod] = 0;
for (U32 i = 0; i < num_file_controls; ++i)
@@ -4607,7 +4655,7 @@ void LLModelPreview::updateLodControls(S32 lod)
mFMP->childHide(lod_controls[i] + lod_name[lod]);
}
}
- else if (lod_mode == 2) // use LoD above
+ else if (lod_mode == USE_LOD_ABOVE) // use LoD above
{
fmp->mLODMode[lod] = 2;
for (U32 i = 0; i < num_file_controls; ++i)
@@ -4780,7 +4828,8 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
if (vf.mTexCoords)
{
vb->getTexCoord0Strider(tc_strider);
- LLVector4a::memcpyNonAliased16((F32*) tc_strider.get(), (F32*) vf.mTexCoords, num_vertices*2*sizeof(F32));
+ S32 tex_size = (num_vertices*2*sizeof(F32)+0xF) & ~0xF;
+ LLVector4a::memcpyNonAliased16((F32*) tc_strider.get(), (F32*) vf.mTexCoords, tex_size);
}
if (vf.mNormals)
@@ -4982,16 +5031,9 @@ BOOL LLModelPreview::render()
bool upload_skin = mFMP->childGetValue("upload_skin").asBoolean();
bool upload_joints = mFMP->childGetValue("upload_joints").asBoolean();
- bool resetJoints = false;
if ( upload_joints != mLastJointUpdate )
{
- if ( mLastJointUpdate )
- {
- resetJoints = true;
- }
-
mLastJointUpdate = upload_joints;
-
}
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
@@ -5053,15 +5095,7 @@ BOOL LLModelPreview::render()
LLRect preview_rect;
- LLFloaterModelWizard* floater_wizard = dynamic_cast<LLFloaterModelWizard*>(mFMP);
- if (floater_wizard)
- {
- preview_rect = floater_wizard->getPreviewRect();
- }
- else
- {
- preview_rect = mFMP->getChildView("preview_panel")->getRect();
- }
+ preview_rect = mFMP->getChildView("preview_panel")->getRect();
F32 aspect = (F32) preview_rect.getWidth()/preview_rect.getHeight();
@@ -5086,6 +5120,11 @@ BOOL LLModelPreview::render()
refresh();
}
+ if (use_shaders)
+ {
+ gObjectPreviewProgram.bind();
+ }
+
gGL.loadIdentity();
gPipeline.enableLightsPreview();
@@ -5111,11 +5150,6 @@ BOOL LLModelPreview::render()
const U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
- if (use_shaders)
- {
- gObjectPreviewProgram.bind();
- }
-
LLGLEnable normalize(GL_NORMALIZE);
if (!mBaseModel.empty() && mVertexBuffer[5].empty())
@@ -5304,7 +5338,7 @@ BOOL LLModelPreview::render()
hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 128));
}
- glColor4ubv(hull_colors[i].mV);
+ gGL.diffuseColor4ubv(hull_colors[i].mV);
LLVertexBuffer::drawArrays(LLRender::TRIANGLES, physics.mMesh[i].mPositions, physics.mMesh[i].mNormals);
if (explode > 0.f)
@@ -5531,6 +5565,15 @@ BOOL LLModelPreview::render()
buffer->setBuffer(type_mask & buffer->getTypeMask());
gGL.diffuseColor4fv(material.mDiffuseColor.mV);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+ if (material.mDiffuseMap.notNull())
+ {
+ if (material.mDiffuseMap->getDiscardLevel() > -1)
+ {
+ gGL.getTexUnit(0)->bind(material.mDiffuseMap, true);
+ mTextureSet.insert(material.mDiffuseMap.get());
+ }
+ }
+
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
gGL.diffuseColor3f(0.4f, 0.4f, 0.4f);
@@ -5605,7 +5648,6 @@ void LLModelPreview::setPreviewLOD(S32 lod)
combo_box->setCurrentByIndex((NUM_LOD-1)-mPreviewLOD); // combo box list of lods is in reverse order
mFMP->childSetText("lod_file_" + lod_name[mPreviewLOD], mLODFile[mPreviewLOD]);
- // the wizard has three lod drop downs
LLComboBox* combo_box2 = mFMP->getChild<LLComboBox>("preview_lod_combo2");
combo_box2->setCurrentByIndex((NUM_LOD-1)-mPreviewLOD); // combo box list of lods is in reverse order
@@ -5767,6 +5809,12 @@ void LLFloaterModelPreview::onLoDSourceCommit(S32 lod)
{
mModelPreview->updateLodControls(lod);
refresh();
+
+ LLComboBox* lod_source_combo = getChild<LLComboBox>("lod_source_" + lod_name[lod]);
+ if (lod_source_combo->getCurrentIndex() == LLModelPreview::GENERATE)
+ { //rebuild LoD to update triangle counts
+ onLODParamCommit(lod, true);
+ }
}
void LLFloaterModelPreview::resetDisplayOptions()
@@ -5890,3 +5938,5 @@ void LLFloaterModelPreview::setPermissonsErrorStatus(U32 status, const std::stri
LLNotificationsUtil::add("MeshUploadPermError");
}
+
+