Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created November 6, 2017 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaneclaes/ee72e2ff7d4ac3d0430c4f62f707c346 to your computer and use it in GitHub Desktop.
Save zaneclaes/ee72e2ff7d4ac3d0430c4f62f707c346 to your computer and use it in GitHub Desktop.
MeshRenderBoneComposition comp =
creatureAsset.creature_manager.target_creature.render_composition;
List<MeshRenderRegion> regions = comp.getRegions();
foreach (MeshRenderRegion region in regions) {
Rect r = new Rect();
int uvIndex = region.getUVsIndex();
for (int i = 0; i < region.getNumPts(); i++) {
Vector2 p = new Vector2(region.store_uvs[uvIndex], region.store_uvs[uvIndex + 1]);
if (i == 0) {
r.xMax = r.xMin = (float)p.x;
r.yMax = r.yMin = (float)p.y;
} else {
r.xMin = Mathf.Min(r.xMin, (float)p.x);
r.xMax = Mathf.Max(r.xMax, (float)p.x);
r.yMin = Mathf.Min(r.yMin, (float)p.y);
r.yMax = Mathf.Max(r.yMax, (float)p.y);
}
uvIndex += 2;
}
// Now, r should be the UV box for the region...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment