| 1842 | } |
| 1843 | } |
| 1844 | void ConvexShape::Geometry::generate(const Vector< PlaneF > &planes, const Vector< Point3F > &tangents, const Vector< surfaceMaterial > surfaceTextures, const Vector< Point2F > texOffset, const Vector< Point2F > texScale, const Vector< bool > horzFlip, const Vector< bool > vertFlip) |
| 1845 | { |
| 1846 | PROFILE_SCOPE( Geometry_generate ); |
| 1847 | |
| 1848 | points.clear(); |
| 1849 | faces.clear(); |
| 1850 | |
| 1851 | AssertFatal( planes.size() == tangents.size(), "ConvexShape - incorrect plane/tangent count." ); |
| 1852 | |
| 1853 | #ifdef TORQUE_ENABLE_ASSERTS |
| 1854 | for ( S32 i = 0; i < planes.size(); i++ ) |
| 1855 | { |
| 1856 | F32 dt = mDot( planes[i], tangents[i] ); |
| 1857 | AssertFatal( mIsZero( dt, 0.0001f ), "ConvexShape - non perpendicular input vectors." ); |
| 1858 | AssertFatal( planes[i].isUnitLength() && tangents[i].isUnitLength(), "ConvexShape - non unit length input vector." ); |
| 1859 | } |
| 1860 | #endif |
| 1861 | |
| 1862 | const U32 planeCount = planes.size(); |
| 1863 | |
| 1864 | Point3F linePt, lineDir; |
| 1865 | |
| 1866 | for ( S32 i = 0; i < planeCount; i++ ) |
| 1867 | { |
| 1868 | Vector< MathUtils::Line > collideLines; |
| 1869 | |
| 1870 | // Find the lines defined by the intersection of this plane with all others. |
| 1871 | |
| 1872 | for ( S32 j = 0; j < planeCount; j++ ) |
| 1873 | { |
| 1874 | if ( i == j ) |
| 1875 | continue; |
| 1876 | |
| 1877 | if ( planes[i].intersect( planes[j], linePt, lineDir ) ) |
| 1878 | { |
| 1879 | collideLines.increment(); |
| 1880 | MathUtils::Line &line = collideLines.last(); |
| 1881 | line.origin = linePt; |
| 1882 | line.direction = lineDir; |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | if ( collideLines.empty() ) |
| 1887 | continue; |
| 1888 | |
| 1889 | // Find edges and points defined by the intersection of these lines. |
| 1890 | // As we find them we fill them into our working ConvexShape::Face |
| 1891 | // structure. |
| 1892 | |
| 1893 | Face newFace; |
| 1894 | |
| 1895 | for ( S32 j = 0; j < collideLines.size(); j++ ) |
| 1896 | { |
| 1897 | Vector< Point3F > collidePoints; |
| 1898 | |
| 1899 | for ( S32 k = 0; k < collideLines.size(); k++ ) |
| 1900 | { |
| 1901 | if ( j == k ) |
no test coverage detected