Created
December 24, 2017 20:05
-
-
Save cabbibo/6d9a4c34a9e4bf6ce45e10d2c98178f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float totalArea = 0; | |
for( int i = 0; i < triBuffer.triangles.Length/3; i++ ){ | |
int tri0 = i * 3; | |
int tri1 = tri0 + 1; | |
int tri2 = tri0 + 2; | |
tri0 = triBuffer.triangles[tri0]; | |
tri1 = triBuffer.triangles[tri1]; | |
tri2 = triBuffer.triangles[tri2]; | |
float area = AreaOfTriangle( vertBuffer.vertices[tri0] , vertBuffer.vertices[tri1] , vertBuffer.vertices[tri2] ); | |
triAreas[i] = area; | |
totalArea += area; | |
} | |
print( totalArea ); | |
for( int i = 0; i < triAreas.Length; i++ ){ | |
triAreas[i] /= totalArea; | |
} | |
// Then later | |
getTri( Random.value ); | |
Where: | |
int getTri(float randomVal){ | |
int triID = 0; | |
float totalTest = 0; | |
for( int i = 0; i < triAreas.Length; i++ ){ | |
totalTest += triAreas[i]; | |
if( randomVal <= totalTest){ | |
triID = i; | |
break; | |
} | |
} | |
return triID; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment