MCPcopy Create free account
hub / github.com/carbonengine/trinity / FillResult

Function FillResult

trinity/Resources/TriGrannyRes.cpp:1920–1978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1918}
1919
1920void FillResult( Tr2GrannyIntersectionResult::Result& result, const uint8_t** triangle, const granny_data_type_definition* vertexFormat, float u, float v )
1921{
1922 auto position = FindGrannyComponent( GrannyVertexPositionName, vertexFormat );
1923 if( position.first )
1924 {
1925 Vector3 p0 = ExtractVector3( triangle[0], position );
1926 Vector3 p1 = ExtractVector3( triangle[1], position );
1927 Vector3 p2 = ExtractVector3( triangle[2], position );
1928
1929 result.position = p0 + ( p1 - p0 ) * u + ( p2 - p0 ) * v;
1930 result.hasPosition = true;
1931 }
1932 else
1933 {
1934 result.position = Vector3( 0, 0, 0 );
1935 result.hasPosition = false;
1936 }
1937 auto normal = FindGrannyComponent( GrannyVertexNormalName, vertexFormat );
1938 if( normal.first )
1939 {
1940 Vector3 p0 = ExtractVector3( triangle[0], normal );
1941 Vector3 p1 = ExtractVector3( triangle[1], normal );
1942 Vector3 p2 = ExtractVector3( triangle[2], normal );
1943
1944 result.normal = Normalize( p0 + ( p1 - p0 ) * u + ( p2 - p0 ) * v );
1945 result.hasNormal = true;
1946 }
1947 else
1948 {
1949 result.normal = Vector3( 0, 0, 0 );
1950 result.hasNormal = false;
1951 }
1952 auto uv = FindGrannyComponent( GrannyVertexTextureCoordinatesName "0", vertexFormat );
1953 if( uv.first )
1954 {
1955 Vector2 p0 = ExtractVector2( triangle[0], uv );
1956 Vector2 p1 = ExtractVector2( triangle[1], uv );
1957 Vector2 p2 = ExtractVector2( triangle[2], uv );
1958
1959 result.uv = p0 + ( p1 - p0 ) * u + ( p2 - p0 ) * v;
1960 result.hasUv = true;
1961 }
1962 else
1963 {
1964 result.uv = Vector2( 0, 0 );
1965 result.hasUv = false;
1966 }
1967 auto boneIndex = FindGrannyComponent( GrannyVertexBoneIndicesName, vertexFormat );
1968 if( boneIndex.first )
1969 {
1970 result.boneIndex = triangle[0][boneIndex.second];
1971 result.hasBoneIndex = true;
1972 }
1973 else
1974 {
1975 result.boneIndex = -1;
1976 result.hasBoneIndex = false;
1977 }

Callers 1

GrannyRayIntersectionFunction · 0.85

Calls 4

FindGrannyComponentFunction · 0.85
ExtractVector3Function · 0.85
ExtractVector2Function · 0.85
Vector3Class · 0.50

Tested by

no test coverage detected