/** * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. * * The Original Code is: all of this file. * * Contributor(s): none yet. * * ***** END GPL LICENSE BLOCK ***** * Simple deformation controller that restores a mesh to its rest position */ #ifdef HAVE_CONFIG_H #include #endif #ifdef WIN32 // This warning tells us about truncation of __long__ stl-generated names. // It can occasionally cause DevStudio to have internal compiler warnings. #pragma warning( disable : 4786 ) #endif #include "RAS_IPolygonMaterial.h" #include "BL_MeshDeformer.h" #include "BL_SkinMeshObject.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.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; isize(); j++){ tv = &((*array[i])[j]); index = ((*diarray[i])[j]); mvert = &(m_bmesh->mvert[((*mvarray[i])[index])]); tv->SetXYZ(MT_Point3(mvert->co)); } } return true; } BL_MeshDeformer::~BL_MeshDeformer() { if (m_transverts) delete [] m_transverts; if (m_transnors) delete [] m_transnors; }; /** * @warning This function is expensive! */ void BL_MeshDeformer::RecalcNormals() { /* 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? */ 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; iUsesTriangles()? 3: 4; for(j=0; jGetFirstMaterial(); 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; itotvert){ if (m_transverts) delete [] m_transverts; if (m_transnors) delete [] m_transnors; m_transverts=new float[(sizeof(*m_transverts)*m_bmesh->totvert)][3]; m_transnors=new MT_Vector3[m_bmesh->totvert]; m_tvtot = m_bmesh->totvert; } }