diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index 520074298..ad7a3164c 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -827,6 +827,8 @@ bool TSStatic::buildPolyList(PolyListContext context, AbstractPolyList* polyList return false; else if ( meshType == Bounds ) polyList->addBox( mObjBox ); + else if ( meshType == VisibleMesh ) + mShapeInstance->buildPolyList( polyList, 0 ); else { // Everything else is done from the collision meshes diff --git a/Engine/source/collision/abstractPolyList.h b/Engine/source/collision/abstractPolyList.h index 092cba435..9b3b00ef8 100644 --- a/Engine/source/collision/abstractPolyList.h +++ b/Engine/source/collision/abstractPolyList.h @@ -157,6 +157,11 @@ public: /// an ID number for that point. virtual U32 addPoint(const Point3F& p) = 0; + /// Adds a point and normal to the poly list, and returns + /// an ID number for them. Normals are ignored for polylists + /// that do not support them. + virtual U32 addPointAndNormal(const Point3F& p, const Point3F& normal) { return addPoint( p ); } + /// Adds a plane to the poly list, and returns /// an ID number for that point. virtual U32 addPlane(const PlaneF& plane) = 0; diff --git a/Engine/source/collision/clippedPolyList.cpp b/Engine/source/collision/clippedPolyList.cpp index 2f83da664..55bd5598e 100644 --- a/Engine/source/collision/clippedPolyList.cpp +++ b/Engine/source/collision/clippedPolyList.cpp @@ -74,6 +74,11 @@ bool ClippedPolyList::isEmpty() const //---------------------------------------------------------------------------- U32 ClippedPolyList::addPoint(const Point3F& p) +{ + return addPointAndNormal( p, Point3F::Zero ); +} + +U32 ClippedPolyList::addPointAndNormal(const Point3F& p, const Point3F& normal) { mVertexList.increment(); Vertex& v = mVertexList.last(); @@ -82,6 +87,14 @@ U32 ClippedPolyList::addPoint(const Point3F& p) v.point.z = p.z * mScale.z; mMatrix.mulP(v.point); + mNormalList.increment(); + VectorF& n = mNormalList.last(); + n = normal; + if ( !n.isZero() ) + mMatrix.mulV(n); + + AssertFatal(mNormalList.size() == mVertexList.size(), "Normals count does not match vertex count!"); + // Build the plane mask register U32 mask = 1; register S32 count = mPlaneList.size(); @@ -242,6 +255,13 @@ void ClippedPolyList::end() VectorF vv = v2 - v1; F32 t = -mPlaneList[p].distToPlane(v1) / mDot(mPlaneList[p],vv); + mNormalList.increment(); + VectorF& n1 = mNormalList[mIndexList[i1]]; + VectorF& n2 = mNormalList[mIndexList[i1]]; + VectorF nn = mLerp( n1, n2, t ); + nn.normalizeSafe(); + mNormalList.last() = nn; + mIndexList.push_back/*_noresize*/(mVertexList.size() - 1); Vertex& iv = mVertexList.last(); iv.point.x = v1.x + vv.x * t; @@ -343,12 +363,14 @@ void ClippedPolyList::cullUnusedVerts() if ( !result ) { mVertexList.setSize( i ); + mNormalList.setSize( i ); break; } // Erase unused verts. numDeleted = (k-1) - i + 1; mVertexList.erase( i, numDeleted ); + mNormalList.erase( i, numDeleted ); // Find any references to vertices after those deleted // in the mIndexList and correct with an offset @@ -407,7 +429,7 @@ void ClippedPolyList::generateNormals() { PROFILE_SCOPE( ClippedPolyList_GenerateNormals ); - mNormalList.setSize( mVertexList.size() ); + AssertFatal(mNormalList.size() == mVertexList.size(), "Normals count does not match vertex count!"); U32 i, polyCount; VectorF normal; @@ -418,6 +440,10 @@ void ClippedPolyList::generateNormals() U32 n = 0; for ( ; normalIter != mNormalList.end(); normalIter++, n++ ) { + // Skip normals that already have values. + if ( !normalIter->isZero() ) + continue; + // Average all the face normals which // share this vertex index. indexIter = mIndexList.begin(); diff --git a/Engine/source/collision/clippedPolyList.h b/Engine/source/collision/clippedPolyList.h index c3eb4e5e7..affce3401 100644 --- a/Engine/source/collision/clippedPolyList.h +++ b/Engine/source/collision/clippedPolyList.h @@ -119,6 +119,7 @@ public: // AbstractPolyList bool isEmpty() const; U32 addPoint(const Point3F& p); + U32 addPointAndNormal(const Point3F& p, const Point3F& normal); U32 addPlane(const PlaneF& plane); void begin(BaseMatInstance* material,U32 surfaceKey); void plane(U32 v1,U32 v2,U32 v3); diff --git a/Engine/source/ts/tsMesh.cpp b/Engine/source/ts/tsMesh.cpp index 4249efee1..aa430a557 100644 --- a/Engine/source/ts/tsMesh.cpp +++ b/Engine/source/ts/tsMesh.cpp @@ -322,9 +322,11 @@ bool TSMesh::buildPolyList( S32 frame, AbstractPolyList *polyList, U32 &surfaceK } else { - base = polyList->addPoint( mVertexData[firstVert].vert() ); + base = polyList->addPointAndNormal( mVertexData[firstVert].vert(), mVertexData[firstVert].normal() ); for ( i = 1; i < vertsPerFrame; i++ ) - polyList->addPoint( mVertexData[ i + firstVert ].vert() ); + { + polyList->addPointAndNormal( mVertexData[ i + firstVert ].vert(), mVertexData[ i + firstVert ].normal() ); + } } } else @@ -348,9 +350,9 @@ bool TSMesh::buildPolyList( S32 frame, AbstractPolyList *polyList, U32 &surfaceK } else { - base = polyList->addPoint( verts[firstVert] ); + base = polyList->addPointAndNormal( verts[firstVert], norms[firstVert] ); for ( i = 1; i < vertsPerFrame; i++ ) - polyList->addPoint( verts[ i + firstVert ] ); + polyList->addPointAndNormal( verts[ i + firstVert ], norms[ i + firstVert ] ); } } }