summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llmath/llvolume.cpp96
-rw-r--r--indra/llmath/llvolume.h1
-rw-r--r--indra/newview/pipeline.cpp9
3 files changed, 103 insertions, 3 deletions
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index f252b2a232..84da1b3c62 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -1925,7 +1925,9 @@ BOOL LLVolume::createVolumeFacesFromStream(std::istream& is)
S32 lod = llclamp((S32) mDetail, 0, 3);
- while (lod < 4 && header[nm[lod]]["offset"].asInteger() == -1)
+ while (lod < 4 &&
+ (header[nm[lod]]["offset"].asInteger() == -1 ||
+ header[nm[lod]]["size"].asInteger() == 0 ))
{
++lod;
}
@@ -1934,7 +1936,9 @@ BOOL LLVolume::createVolumeFacesFromStream(std::istream& is)
{
lod = llclamp((S32) mDetail, 0, 3);
- while (lod >= 0 && header[nm[lod]]["offset"].asInteger() == -1)
+ while (lod >= 0 &&
+ (header[nm[lod]]["offset"].asInteger() == -1 ||
+ header[nm[lod]]["size"].asInteger() == 0) )
{
--lod;
}
@@ -2135,6 +2139,94 @@ BOOL LLVolume::createVolumeFacesFromStream(std::istream& is)
return TRUE;
}
+void tetrahedron_set_normal(LLVolumeFace::VertexData* cv)
+{
+ LLVector3 nrm = (cv[1].mPosition-cv[0].mPosition)%(cv[2].mPosition-cv[0].mPosition);
+
+ nrm.normVec();
+
+ cv[0].mNormal = nrm;
+ cv[1].mNormal = nrm;
+ cv[2].mNormal = nrm;
+}
+
+void LLVolume::makeTetrahedron()
+{
+ mVolumeFaces.clear();
+
+ LLVolumeFace face;
+
+ F32 x = 0.5f;
+ LLVector3 p[] =
+ { //unit tetrahedron corners
+ LLVector3(x,x,x),
+ LLVector3(-x,-x,x),
+ LLVector3(-x,x,-x),
+ LLVector3(x,-x,-x)
+ };
+
+ LLVolumeFace::VertexData cv[3];
+
+ //set texture coordinates
+ cv[0].mTexCoord = LLVector2(0,0);
+ cv[1].mTexCoord = LLVector2(1,0);
+ cv[2].mTexCoord = LLVector2(0.5f, 0.5f*F_SQRT3);
+
+
+ //side 1
+ cv[0].mPosition = p[1];
+ cv[1].mPosition = p[0];
+ cv[2].mPosition = p[2];
+
+ tetrahedron_set_normal(cv);
+
+ face.mVertices.push_back(cv[0]);
+ face.mVertices.push_back(cv[1]);
+ face.mVertices.push_back(cv[2]);
+
+ //side 2
+ cv[0].mPosition = p[3];
+ cv[1].mPosition = p[0];
+ cv[2].mPosition = p[1];
+
+ tetrahedron_set_normal(cv);
+
+ face.mVertices.push_back(cv[0]);
+ face.mVertices.push_back(cv[1]);
+ face.mVertices.push_back(cv[2]);
+
+ //side 3
+ cv[0].mPosition = p[3];
+ cv[1].mPosition = p[1];
+ cv[2].mPosition = p[2];
+
+ tetrahedron_set_normal(cv);
+
+ face.mVertices.push_back(cv[0]);
+ face.mVertices.push_back(cv[1]);
+ face.mVertices.push_back(cv[2]);
+
+ //side 4
+ cv[0].mPosition = p[2];
+ cv[1].mPosition = p[0];
+ cv[2].mPosition = p[3];
+
+ tetrahedron_set_normal(cv);
+
+ face.mVertices.push_back(cv[0]);
+ face.mVertices.push_back(cv[1]);
+ face.mVertices.push_back(cv[2]);
+
+ //set index buffer
+ for (U32 i = 0; i < 12; i++)
+ {
+ face.mIndices.push_back(i);
+ }
+
+ mVolumeFaces.push_back(face);
+ mSculptLevel = 0;
+}
+
void LLVolume::copyVolumeFaces(LLVolume* volume)
{
mVolumeFaces = volume->mVolumeFaces;
diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h
index d2727d8f21..bf2854ede9 100644
--- a/indra/llmath/llvolume.h
+++ b/indra/llmath/llvolume.h
@@ -969,6 +969,7 @@ protected:
public:
virtual BOOL createVolumeFacesFromFile(const std::string& file_name);
virtual BOOL createVolumeFacesFromStream(std::istream& is);
+ virtual void makeTetrahedron();
protected:
BOOL mUnique;
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index c262e94ff4..3410ad6559 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -8976,6 +8976,9 @@ void LLPipeline::loadMesh(LLVOVolume* vobj, LLUUID mesh_id, S32 detail)
group->derefLOD(lod);
}
}
+
+ //nothing found, so make a tetrahedron
+ volume->makeTetrahedron();
}
}
@@ -9102,7 +9105,11 @@ void LLPipeline::notifyLoadedMeshes()
if (valid)
{
- mesh->mTargetVolume->copyVolumeFaces(mesh->mVolume);
+ if (mesh->mVolume->getNumVolumeFaces() > 0)
+ {
+ mesh->mTargetVolume->copyVolumeFaces(mesh->mVolume);
+ }
+
for (std::set<LLUUID>::iterator vobj_iter = obj_iter->second.begin(); vobj_iter != obj_iter->second.end(); ++vobj_iter)
{
LLVOVolume* vobj = (LLVOVolume*) gObjectList.findObject(*vobj_iter);