Created
November 18, 2017 16:45
-
-
Save zaneclaes/6ddddd168fd58c40c0b13efbf8f15016 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
// I created a shared base-class for both CreatureRenderer and CreatureCanvasRenderer, which removes tons and tons of copy/pasted code... | |
// Here's how I transform the vertices... | |
public void UpdateRenderingData() { | |
CreatureRenderModule.UpdateRenderingData( | |
creature_manager, | |
counter_clockwise, | |
ref vertices, | |
ref normals, | |
ref tangents, | |
ref colors, | |
ref uvs, | |
creature_asset, | |
skin_swap_active, | |
active_animation_name, | |
ref final_indices, | |
ref final_skin_swap_indices, | |
ref triangles, | |
ref skin_swap_triangles); | |
bool should_skin_swap = CreatureRenderModule.shouldSkinSwap(creature_asset, skin_swap_active, ref skin_swap_triangles); | |
active_mesh.vertices = TransformVertices(vertices); | |
active_mesh.colors32 = colors; | |
active_mesh.triangles = should_skin_swap ? skin_swap_triangles : triangles; | |
active_mesh.normals = normals; | |
active_mesh.tangents = tangents; | |
active_mesh.uv = uvs; | |
//CreatureRenderModule.debugDrawBones(creature_manager.target_creature.render_composition.getRootBone ()); | |
} | |
protected Rect _vertexBox = new Rect(); | |
protected Vector3 vertexOffset { | |
get { | |
if (_vertexBox.size.magnitude <= float.Epsilon) { | |
_vertexBox = new Rect { | |
xMin = float.MaxValue, | |
yMin = float.MaxValue | |
}; | |
foreach (Vector3 v in vertices) { | |
if (v.x < _vertexBox.xMin) _vertexBox.xMin = v.x; | |
if (v.x > _vertexBox.xMax) _vertexBox.xMax = v.x; | |
if (v.y < _vertexBox.yMin) _vertexBox.yMin = v.y; | |
if (v.y > _vertexBox.yMax) _vertexBox.yMax = v.y; | |
} | |
} | |
return _vertexBox.center; | |
} | |
} | |
protected virtual Vector3[] TransformVertices(Vector3[] vertices) { | |
return vertices.Select(v => v - vertexOffset).ToArray(); | |
} | |
// ------------------------------------------------------------------- | |
// In CreatureCanvasRenderer, I override the transform... | |
protected override Vector3[] TransformVertices(Vector3[] vertices) { | |
RectTransform canvasRect = canvas.transform as RectTransform; | |
return vertices.Select( | |
v => new Vector3( | |
(v.x - vertexOffset.x) / canvasRect.localScale.x, | |
(v.y - vertexOffset.y) / canvasRect.localScale.y, | |
v.z | |
) | |
).ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment