| 2007 | } |
| 2008 | |
| 2009 | Tr2GrannyIntersectionResultPtr GrannyRayIntersection( granny_file_info* fi, const Vector3& pos, const Vector3& dir, int32_t meshIndex, int32_t areaIndex ) |
| 2010 | { |
| 2011 | if( !fi ) |
| 2012 | { |
| 2013 | return nullptr; |
| 2014 | } |
| 2015 | |
| 2016 | if( meshIndex >= 0 && meshIndex >= fi->MeshCount ) |
| 2017 | { |
| 2018 | return nullptr; |
| 2019 | } |
| 2020 | if( areaIndex >= 0 && meshIndex < 0 ) |
| 2021 | { |
| 2022 | return nullptr; |
| 2023 | } |
| 2024 | if( areaIndex >= 0 ) |
| 2025 | { |
| 2026 | if( !fi->Meshes[meshIndex]->PrimaryTopology ) |
| 2027 | { |
| 2028 | return nullptr; |
| 2029 | } |
| 2030 | if( areaIndex >= fi->Meshes[meshIndex]->PrimaryTopology->GroupCount ) |
| 2031 | { |
| 2032 | return nullptr; |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | int32_t meshCount, meshOffset; |
| 2037 | if( meshIndex >= 0 ) |
| 2038 | { |
| 2039 | meshCount = 1; |
| 2040 | meshOffset = meshIndex; |
| 2041 | } |
| 2042 | else |
| 2043 | { |
| 2044 | meshCount = fi->MeshCount; |
| 2045 | meshOffset = 0; |
| 2046 | } |
| 2047 | |
| 2048 | Tr2GrannyIntersectionResult::Result result; |
| 2049 | float closestDist = std::numeric_limits<float>::max(); |
| 2050 | bool foundIntersection = false; |
| 2051 | |
| 2052 | for( int32_t i = 0; i < meshCount; ++i ) |
| 2053 | { |
| 2054 | auto mesh = fi->Meshes[i + meshOffset]; |
| 2055 | if( !mesh->PrimaryTopology ) |
| 2056 | { |
| 2057 | continue; |
| 2058 | } |
| 2059 | |
| 2060 | int32_t index, triCount; |
| 2061 | if( areaIndex >= 0 ) |
| 2062 | { |
| 2063 | index = mesh->PrimaryTopology->Groups[areaIndex].TriFirst * 3; |
| 2064 | triCount = mesh->PrimaryTopology->Groups[areaIndex].TriCount; |
| 2065 | } |
| 2066 | else |
no test coverage detected