Crash fixes in model upload
This commit is contained in:
@@ -241,6 +241,22 @@ bool ll_is_degenerate(const LLVector4a& a, const LLVector4a& b, const LLVector4a
|
||||
|
||||
bool validate_face(const LLVolumeFace& face)
|
||||
{
|
||||
|
||||
for (S32 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 (S32 i = 0; i < face.mNumIndices; ++i)
|
||||
{
|
||||
if (face.mIndices[i] >= face.mNumVertices)
|
||||
@@ -3807,15 +3823,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;
|
||||
@@ -3849,6 +3880,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
|
||||
@@ -3953,7 +3986,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);
|
||||
@@ -4135,28 +4168,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 (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 = mModel[lod][i]->getVolumeFace(j);
|
||||
cur_tris += face.mNumIndices/3;
|
||||
cur_verts += face.mNumVertices;
|
||||
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;
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4334,34 +4375,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4523,7 +4568,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)
|
||||
@@ -4536,7 +4581,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)
|
||||
|
||||
Reference in New Issue
Block a user