void CTmpBrush::Refresh() { CUtlVector<TTmpFaceHelper> oldhelpers; oldhelpers = m_helpers; m_numFaces = m_polyhedron->iPolygonCount; if(m_visible) m_tmpTriangles.SetCountNonDestructively(m_numFaces); m_helpers.SetCountNonDestructively(m_numFaces); for(int i = 0; i < m_numFaces; i++) { const Polyhedron_IndexedPolygon_t& polygon = m_polyhedron->pPolygons[i]; Assert(polygon.iIndexCount == 3); const Vector * triPts[3]; for(int j = 0; j < 3; j++) { triPts[j] = &GetPolygonVertex(m_polyhedron, polygon, j); } if(m_visible) m_tmpTriangles[i].SetPoints(triPts); //todo - we should modify helpers when rotating/scaling to avoid errors ComputeTriangleNormal(*triPts[0], *triPts[1], *triPts[2], m_helpers[i].normal); m_helpers[i].normal = -m_helpers[i].normal; float bestdot = -1.0; m_helpers[i].index = -1; FOR_EACH_VEC(oldhelpers, it) { float dot = DotProduct(oldhelpers[it].normal, m_helpers[i].normal); if(dot > bestdot) { bestdot = dot; m_helpers[i].index = oldhelpers[it].index; } } }
void CTriangleObj::ComputePolygonNormals(void) { int f; if (m_pPolyNorm==NULL){ //this is modified for deformable surface const int NSIZE = DETERMINE_DEFORMABLE_POLYSIZE(m_nPolygonCount); m_pPolyNorm = new Vector3f[NSIZE]; assert(m_pPolyNorm!=NULL); } for (f=0; f<m_nPolygonCount; f++){ m_pPolyNorm[f]=ComputeTriangleNormal(f); } }
void CTriangleObj::ComputeVertexNormals(void) { int i; Vector3f zero(0,0,0); Vector3i* m_pTriangle = (Vector3i*)m_pPolygon; if (m_pVertexNorm==NULL){ m_pVertexNorm = new Vector3f[m_nVertexCount]; assert(m_pVertexNorm!=NULL); } for (i=0; i<m_nVertexCount; i++) m_pVertexNorm[i]=zero; //need the polygon normals { if (m_pPolyNorm==NULL){ //this is modified for deformable surface const int NSIZE = DETERMINE_DEFORMABLE_POLYSIZE(m_nPolygonCount); m_pPolyNorm = new Vector3f[NSIZE]; assert(m_pPolyNorm!=NULL); } for (int f=0; f<m_nPolygonCount; f++){ m_pPolyNorm[f]=ComputeTriangleNormal(f, true); } } //==sum up for (i=0; i<m_nPolygonCount; i++){ const Vector3i& t = m_pTriangle[i]; m_pVertexNorm[t.x]+= m_pPolyNorm[i]; m_pVertexNorm[t.y]+= m_pPolyNorm[i]; m_pVertexNorm[t.z]+= m_pPolyNorm[i]; } for (i=0; i<m_nVertexCount; i++) m_pVertexNorm[i].normalize(); for (i=0; i<m_nPolygonCount; i++) m_pPolyNorm[i].normalize(); }