Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-06-17 14:27:34 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-06-17 14:27:34 +0400
commit272a91f754fd215f2ad9b48ba80fe56ee0564d7a (patch)
treef34afc9fd09b6a2bbcacd0709190969d09dc748f /source/gameengine/Converter/BL_MeshDeformer.cpp
parentc9d1924ea5575ae2a4ce2cc7fd16e63e6ef14d84 (diff)
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW ==== Added the GLEW opengl extension library into extern/, always compiled into Blender now. This is much nicer than doing this kind of extension management manually, and will be used in the game engine, for GLSL, and other opengl extensions. * According to the GLEW website it works on Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris. There might still be platform specific issues due to this commit, so let me know and I'll look into it. * This means also that all extensions will now always be compiled in, regardless of the glext.h on the platform where compilation happens. Game Engine =========== Refactoring of the use of opengl extensions and other drawing code in the game engine, and cleaning up some hacks related to GLSL integration. These changes will be merged into trunk too after this. The game engine graphics demos & apricot level survived my tests, but this could use some good testing of course. For users: please test with the options "Generate Display Lists" and "Vertex Arrays" enabled, these should be the fastest and are supposed to be "unreliable", but if that's the case that's probably due to bugs that can be fixed. * The game engine now also uses GLEW for extensions, replacing the custom opengl extensions code that was there. Removes a lot of #ifdef's, but the runtime checks stay of course. * Removed the WITHOUT_GLEXT environment variable. This was added to work around a specific bug and only disabled multitexturing anyway. It might also have caused a slowdown since it was retrieving the environment variable for every vertex in immediate mode (bug #13680). * Refactored the code to allow drawing skinned meshes with vertex arrays too, removing some specific immediate mode drawing functions for this that only did extra normal calculation. Now it always splits vertices of flat faces instead. * Refactored normal recalculation with some minor optimizations, required for the above change. * Removed some outdated code behind the __NLA_OLDDEFORM #ifdef. * Fixed various bugs in setting of multitexture coordinates and vertex attributes for vertex arrays. These were not being enabled/disabled correct according to the opengl spec, leading to crashes. Also tangent attributes used an immediate mode call for vertex arrays, which can't work. * Fixed use of uninitialized variable in RAS_TexVert. * Exporting skinned meshes was doing O(n^2) lookups for vertices and deform weights, now uses same trick as regular meshes.
Diffstat (limited to 'source/gameengine/Converter/BL_MeshDeformer.cpp')
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.cpp160
1 files changed, 108 insertions, 52 deletions
diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp
index ab31179b047..85ba894f9a5 100644
--- a/source/gameengine/Converter/BL_MeshDeformer.cpp
+++ b/source/gameengine/Converter/BL_MeshDeformer.cpp
@@ -43,27 +43,25 @@
#include "BL_SkinMeshObject.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
-#include "BLI_arithb.h"
#include "GEN_Map.h"
#include "STR_HashedString.h"
-
bool BL_MeshDeformer::Apply(RAS_IPolyMaterial *mat)
{
size_t i, j, index;
vecVertexArray array;
vecIndexArrays mvarray;
vecIndexArrays diarray;
-
+
RAS_TexVert *tv;
MVert *mvert;
-
+
// For each material
array = m_pMeshObject->GetVertexCache(mat);
mvarray = m_pMeshObject->GetMVertCache(mat);
diarray = m_pMeshObject->GetDIndexCache(mat);
-
+
// For each array
for (i=0; i<array.size(); i++){
// For each vertex
@@ -81,9 +79,9 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial *mat)
BL_MeshDeformer::~BL_MeshDeformer()
{
if (m_transverts)
- delete []m_transverts;
+ delete [] m_transverts;
if (m_transnors)
- delete []m_transnors;
+ delete [] m_transnors;
};
/**
@@ -91,65 +89,123 @@ BL_MeshDeformer::~BL_MeshDeformer()
*/
void BL_MeshDeformer::RecalcNormals()
{
- int v, f;
- float fnor[3], co1[3], co2[3], co3[3], co4[3];
+ /* We don't normalize for performance, not doing it for faces normals
+ * gives area-weight normals which often look better anyway, and use
+ * GL_NORMALIZE so we don't have to do per vertex normalization either
+ * since the GPU can do it faster
+ *
+ * There's a lot of indirection here to get to the data, can this work
+ * with less arrays/indirection? */
- /* Clear all vertex normal accumulators */
- for (v =0; v<m_bmesh->totvert; v++){
- m_transnors[v]=MT_Point3(0,0,0);
- }
-
- /* Find the face normals */
- for (f = 0; f<m_bmesh->totface; f++){
- // Make new face normal based on the transverts
- MFace *mf= &((MFace*)m_bmesh->mface)[f];
-
- if (mf->v3) {
- for (int vl=0; vl<3; vl++){
- co1[vl]=m_transverts[mf->v1][vl];
- co2[vl]=m_transverts[mf->v2][vl];
- co3[vl]=m_transverts[mf->v3][vl];
- if (mf->v4)
- co4[vl]=m_transverts[mf->v4][vl];
+ vecIndexArrays indexarrays;
+ vecIndexArrays mvarrays;
+ vecIndexArrays diarrays;
+ vecVertexArray vertexarrays;
+ size_t i, j;
+
+ /* set vertex normals to zero */
+ for (i=0; i<(size_t)m_bmesh->totvert; i++)
+ m_transnors[i] = MT_Vector3(0.0f, 0.0f, 0.0f);
+
+ /* add face normals to vertices. */
+ for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
+ mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
+ RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
+
+ indexarrays = m_pMeshObject->GetIndexCache(mat);
+ vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ diarrays = m_pMeshObject->GetDIndexCache(mat);
+ mvarrays = m_pMeshObject->GetMVertCache(mat);
+
+ for (i=0; i<indexarrays.size(); i++) {
+ KX_VertexArray& vertexarray = (*vertexarrays[i]);
+ const KX_IndexArray& mvarray = (*mvarrays[i]);
+ const KX_IndexArray& diarray = (*diarrays[i]);
+ const KX_IndexArray& indexarray = (*indexarrays[i]);
+ int nvert = mat->UsesTriangles()? 3: 4;
+
+ for(j=0; j<indexarray.size(); j+=nvert) {
+ MT_Point3 mv1, mv2, mv3, mv4, fnor;
+ int i1 = indexarray[j];
+ int i2 = indexarray[j+1];
+ int i3 = indexarray[j+2];
+ RAS_TexVert& v1 = vertexarray[i1];
+ RAS_TexVert& v2 = vertexarray[i2];
+ RAS_TexVert& v3 = vertexarray[i3];
+
+ /* compute face normal */
+ mv1 = MT_Point3(v1.getLocalXYZ());
+ mv2 = MT_Point3(v2.getLocalXYZ());
+ mv3 = MT_Point3(v3.getLocalXYZ());
+
+ if(nvert == 4) {
+ int i4 = indexarray[j+3];
+ RAS_TexVert& v4 = vertexarray[i4];
+ mv4 = MT_Point3(v4.getLocalXYZ());
+
+ fnor = (((mv2-mv1).cross(mv3-mv2))+((mv4-mv3).cross(mv1-mv4))); //.safe_normalized();
+ }
+ else
+ fnor = ((mv2-mv1).cross(mv3-mv2)); //.safe_normalized();
+
+ /* add to vertices for smooth normals */
+ m_transnors[mvarray[diarray[i1]]] += fnor;
+ m_transnors[mvarray[diarray[i2]]] += fnor;
+ m_transnors[mvarray[diarray[i3]]] += fnor;
+
+ /* in case of flat - just assign, the vertices are split */
+ if(v1.getFlag() & TV_CALCFACENORMAL) {
+ v1.SetNormal(fnor);
+ v2.SetNormal(fnor);
+ v3.SetNormal(fnor);
+ }
+
+ if(nvert == 4) {
+ int i4 = indexarray[j+3];
+ RAS_TexVert& v4 = vertexarray[i4];
+
+ /* same as above */
+ m_transnors[mvarray[diarray[i4]]] += fnor;
+
+ if(v4.getFlag() & TV_CALCFACENORMAL)
+ v4.SetNormal(fnor);
+ }
}
+ }
+ }
- /* FIXME: Use moto */
- if (mf->v4)
- CalcNormFloat4(co1, co2, co3, co4, fnor);
- else
- CalcNormFloat(co1, co2, co3, fnor);
-
- /* Decide which normals are affected by this face's normal */
- m_transnors[mf->v1]+=MT_Point3(fnor);
- m_transnors[mf->v2]+=MT_Point3(fnor);
- m_transnors[mf->v3]+=MT_Point3(fnor);
- if (mf->v4)
- m_transnors[mf->v4]+=MT_Point3(fnor);
+ /* assign smooth vertex normals */
+ for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
+ mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
+ RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
+
+ vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ diarrays = m_pMeshObject->GetDIndexCache(mat);
+ mvarrays = m_pMeshObject->GetMVertCache(mat);
+
+ for (i=0; i<vertexarrays.size(); i++) {
+ KX_VertexArray& vertexarray = (*vertexarrays[i]);
+ const KX_IndexArray& mvarray = (*mvarrays[i]);
+ const KX_IndexArray& diarray = (*diarrays[i]);
+
+ for(j=0; j<vertexarray.size(); j++)
+ if(!(vertexarray[j].getFlag() & TV_CALCFACENORMAL))
+ vertexarray[j].SetNormal(m_transnors[mvarray[diarray[j]]]); //.safe_normalized()
}
}
-
- for (v =0; v<m_bmesh->totvert; v++){
-// float nor[3];
-
- m_transnors[v]=m_transnors[v].safe_normalized();
-// nor[0]=m_transnors[v][0];
-// nor[1]=m_transnors[v][1];
-// nor[2]=m_transnors[v][2];
-
- };
}
void BL_MeshDeformer::VerifyStorage()
{
/* Ensure that we have the right number of verts assigned */
- if (m_tvtot!=m_bmesh->totvert+m_bmesh->totface){
+ if (m_tvtot!=m_bmesh->totvert+m_bmesh->totface) {
if (m_transverts)
- delete []m_transverts;
+ delete [] m_transverts;
if (m_transnors)
- delete []m_transnors;
+ delete [] m_transnors;
- m_transnors =new MT_Point3[m_bmesh->totvert+m_bmesh->totface];
m_transverts=new float[(sizeof(*m_transverts)*m_bmesh->totvert)][3];
+ m_transnors=new MT_Vector3[m_bmesh->totvert];
m_tvtot = m_bmesh->totvert;
}
}