private static void MorphBoneStretch(LimbDataBone bone, BonePixels bonePixel, StretchParameters stretchParameters) { var boneStartPoint = new Vector2(bone.StartPoint.X, bone.StartPoint.Y); var boneEndPoint = new Vector2(bone.EndPoint.X, bone.EndPoint.Y); var boneLength = Vector2.Distance(boneStartPoint, boneEndPoint); var indices = bonePixel.VertexIndices; foreach (var vertexIndex in indices) { var vertex = GB.LimbDataManager.LimbData.Mesh.Vertices[vertexIndex]; var vertexPoint = new Vector2(vertex.X, vertex.Y); var vertexWeight = GB.LimbDataManager.LimbData.Mesh.GetVertexWeight(vertex); var closestPointOnLine3D = Utils.GetClosestPointOnLine(bone.StartPoint, bone.EndPoint, new Vector3(vertexPoint.X, vertexPoint.Y, 0)); var closestPointOnLine2D = new Vector2(closestPointOnLine3D.X, closestPointOnLine3D.Y); var progressOnLine = Vector2.Distance(closestPointOnLine2D, boneStartPoint) / boneLength; if (progressOnLine < 0 || progressOnLine > 1) { continue; } var distance = Vector2.Distance(vertexPoint, closestPointOnLine2D); var directionVector = Vector2.Normalize(vertexPoint - closestPointOnLine2D); var distanceMultiplier = distance / 2f; var curveScale = 1f + stretchParameters.Power * stretchParameters.Curve.Evaluate(progressOnLine); vertex.X += curveScale * directionVector.X * stretchParameters.Power * distanceMultiplier * vertexWeight; vertex.Y += curveScale * directionVector.Y * stretchParameters.Power * distanceMultiplier * vertexWeight; vertex.Z = bone.BoneHash; GB.LimbDataManager.LimbData.Mesh.Vertices[vertexIndex] = vertex; } }
private static void MorphBoneGrow(LimbDataBone bone, BonePixels bonePixel, float scale) { var boneStartPoint = new Vector2(bone.StartPoint.X, bone.StartPoint.Y); var boneEndPoint = new Vector2(bone.EndPoint.X, bone.EndPoint.Y); var indices = bonePixel.VertexIndices; foreach (var vertexIndex in indices) { var vertex = GB.LimbDataManager.LimbData.Mesh.Vertices[vertexIndex]; var vertexPoint = new Vector2(vertex.X, vertex.Y); var vertexWeight = GB.LimbDataManager.LimbData.Mesh.GetVertexWeight(vertex); var distance = Vector2.Distance(vertexPoint, boneEndPoint); var directionVector = Vector2.Normalize(vertexPoint - boneEndPoint); vertex.X += distance * directionVector.X * scale * vertexWeight / 2f; vertex.Y += distance * directionVector.Y * scale * vertexWeight / 2f; vertex.Z = bone.BoneHash; GB.LimbDataManager.LimbData.Mesh.Vertices[vertexIndex] = vertex; } }