-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added several scripts, edited some stuff
• Added screenshot script. • Changed how original bone positions are referenced. • Added basic script to compare points & calculate score. • Added script to limit bone positions.
- Loading branch information
Showing
8 changed files
with
317 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
//Add this script to the armature. | ||
public class Bones : MonoBehaviour | ||
{ | ||
public static List<Vector3> originalPositions; | ||
|
||
void Start () | ||
{ | ||
originalPositions = new List<Vector3>(); | ||
SaveOriginals(); | ||
} | ||
|
||
void Update () | ||
{ | ||
|
||
} | ||
|
||
void SaveOriginals() | ||
{ | ||
int boneCount = transform.childCount - 1; | ||
for (int i = 0; i < boneCount; i++) | ||
{ | ||
Transform bone = transform.GetChild(i); | ||
if (!bone.gameObject.name.Contains("Base")) | ||
originalPositions.Add(bone.position); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System; | ||
|
||
public class PositionComparison : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
GameObject armature; | ||
|
||
const float MAX_POINTS = 100.0f; | ||
int boneCount = 0; | ||
float pointTotal = 0.0f; | ||
|
||
[SerializeField] | ||
RefPositions refPositions; | ||
|
||
List<Vector3> currentPositions; | ||
Vector3[] selectedRef; | ||
|
||
// Use this for initialization | ||
void Start () | ||
{ | ||
//Use -1 to exclude the base bone. | ||
boneCount = armature.transform.childCount - 1; | ||
selectedRef = refPositions.vectorList[UnityEngine.Random.Range(0,1)].vectorSet; | ||
Debug.Log(selectedRef); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Return)) | ||
Compare(); | ||
} | ||
|
||
void Compare () | ||
{ | ||
double xTotalDiff = 0; | ||
double yTotalDiff = 0; | ||
for (int i = 0; i < boneCount; i++) | ||
{ | ||
Vector3 refVector = selectedRef[i]; | ||
double xFinal = Math.Round(Math.Abs(armature.transform.GetChild(i).position.x), 1); | ||
double yFinal = Math.Round(Math.Abs(armature.transform.GetChild(i).position.y), 1); | ||
|
||
double xRef = Mathf.Abs(selectedRef[i].x); | ||
double yRef = Mathf.Abs(selectedRef[i].y); | ||
|
||
xTotalDiff += Math.Abs(xFinal - xRef); | ||
yTotalDiff += Math.Abs(yFinal - yRef); | ||
} | ||
|
||
//Grade factor is 0.125, received from formula below. works | ||
//for pumpkin, not sure about other models... | ||
Debug.Log("X Total Diff: " + xTotalDiff); | ||
Debug.Log("Y Total Diff: " + yTotalDiff); | ||
double boneFloat = boneCount; | ||
double combinedDiff = (xTotalDiff + yTotalDiff) * (1 / (boneFloat / (100 / (boneFloat * 2)))); | ||
Debug.Log("Combined Diff: " + combinedDiff); | ||
double scoreFinal = Math.Round((MAX_POINTS - combinedDiff), 1); | ||
if (scoreFinal < 0) | ||
scoreFinal = 0; | ||
Debug.Log("Score: " + scoreFinal); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PositionLimiter : MonoBehaviour | ||
{ | ||
GameObject armature; | ||
int boneCount; | ||
[SerializeField] | ||
int distanceLimit = 20; | ||
|
||
void Start() | ||
{ | ||
armature = transform.parent.gameObject; | ||
boneCount = armature.transform.childCount-1; | ||
} | ||
|
||
void Update() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.D)) | ||
ResetDefaults(); | ||
} | ||
|
||
void OnMouseUp() | ||
{ | ||
CheckPositionLimits(); | ||
} | ||
|
||
//Function to check that the x & y coordinates of each bone | ||
//don't go past a limit of +/- (distanceLimit) units from the original position. | ||
void CheckPositionLimits() | ||
{ | ||
int boneIndex = transform.GetSiblingIndex(); | ||
float xBone = Mathf.Abs(transform.position.x); | ||
float xOriginal = Mathf.Abs(Bones.originalPositions[boneIndex].x); | ||
float yBone = Mathf.Abs(transform.position.y); | ||
float yOriginal = Mathf.Abs(Bones.originalPositions[boneIndex].y); | ||
|
||
float xDiff = Mathf.Abs(xBone - xOriginal); | ||
float yDiff = Mathf.Abs(yBone - yOriginal); | ||
|
||
if (xDiff > 20) | ||
{ | ||
if (transform.position.x < Bones.originalPositions[boneIndex].x) | ||
transform.position = new Vector3(Bones.originalPositions[boneIndex].x - distanceLimit, | ||
transform.position.y, transform.position.z); | ||
else | ||
transform.position = new Vector3(Bones.originalPositions[boneIndex].x + distanceLimit, | ||
transform.position.y, transform.position.z); | ||
} | ||
|
||
if (yDiff > 20) | ||
{ | ||
if (transform.position.y < Bones.originalPositions[boneIndex].y) | ||
transform.position = new Vector3(transform.position.x, | ||
Bones.originalPositions[boneIndex].y - distanceLimit, transform.position.z); | ||
else | ||
transform.position = new Vector3(transform.position.x, | ||
Bones.originalPositions[boneIndex].y + distanceLimit, transform.position.z); | ||
} | ||
} | ||
|
||
void ResetDefaults() | ||
{ | ||
for (int i = 0; i < Bones.originalPositions.Count; i++) | ||
{ | ||
armature.transform.GetChild(i).position = Bones.originalPositions[i]; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
[System.Serializable] | ||
public class RefPositions | ||
{ | ||
[System.Serializable] | ||
public struct vectorData | ||
{ | ||
public Vector3[] vectorSet; | ||
} | ||
|
||
public vectorData[] vectorList = new vectorData[20]; | ||
} |
Oops, something went wrong.