HH
5 年前
当前提交
f06849e0
共有 16 个文件被更改,包括 4723 次插入 和 1 次删除
-
110Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerDynamic.unity
-
93Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerDynamicVariableSpeed.unity
-
60Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity
-
60Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStaticVariableSpeed.unity
-
334Project/Assets/ML-Agents/Examples/Walker/Scripts/AvgCenterOfMass.cs
-
11Project/Assets/ML-Agents/Examples/Walker/Scripts/AvgCenterOfMass.cs.meta
-
8Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamic.nn
-
11Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamic.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamicVariableSpeed.nn
-
11Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamicVariableSpeed.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStatic.nn
-
11Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStatic.nn.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStaticVariableSpeed.nn
-
11Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStaticVariableSpeed.nn.meta
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
/// <summary>
|
|||
/// Used for visualizing the average center of mass of a ragdoll
|
|||
/// </summary>
|
|||
[DisallowMultipleComponent] |
|||
[ExecuteInEditMode] |
|||
public class AvgCenterOfMass : MonoBehaviour |
|||
{ |
|||
/// <summary>
|
|||
/// Enable to show a green spehere at the current center of mass.
|
|||
/// </summary>
|
|||
[Tooltip("Enable to show a green spehere at the current center of mass.")] |
|||
public bool active; |
|||
public bool showCOMGizmos = true; |
|||
public Vector3 avgCOMWorldSpace; |
|||
public Vector3 avgCOMVelocityWorldSpace; |
|||
public Vector3 previousAvgCOM; |
|||
public Color avgCOMColor = Color.green; |
|||
public Color bodyPartCOMColor = Color.yellow; |
|||
List<Rigidbody> rbList = new List<Rigidbody>(); |
|||
public float totalMass; |
|||
[Tooltip("Visualize Relative Pos")] |
|||
public bool showBPPosRelToBody; |
|||
public bool useTransformPoint = true; |
|||
public bool useTransformVector; |
|||
public bool useTransformDir; |
|||
public bool showRBPos; |
|||
public bool showRelPosVectorOnly; |
|||
public bool showInverseTransformPointUnscaledRelToBody; |
|||
public bool showInverseTransformPointRelToBody; |
|||
public bool showInverseTransformVectorRelToBody; |
|||
public bool showInverseTransformDirRelToBody; |
|||
public Transform body_T; |
|||
void OnEnable() |
|||
{ |
|||
SetUpRigidbodies(); |
|||
} |
|||
|
|||
void SetUpRigidbodies() |
|||
{ |
|||
rbList.Clear(); |
|||
totalMass = 0; |
|||
foreach(var item in GetComponentsInChildren<Rigidbody>()) |
|||
{ |
|||
rbList.Add(item); |
|||
totalMass += item.mass; |
|||
} |
|||
} |
|||
|
|||
// void FixedUpdate()
|
|||
// {
|
|||
// if(Application.isPlaying)
|
|||
// {
|
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// }
|
|||
// }
|
|||
|
|||
public Vector3 GetCoMWorldSpace() |
|||
{ |
|||
Vector3 CoM = Vector3.zero; |
|||
avgCOMWorldSpace = Vector3.zero; |
|||
float c = 0f; |
|||
|
|||
foreach(var item in rbList) |
|||
{ |
|||
CoM += item.worldCenterOfMass * item.mass; |
|||
c += item.mass; |
|||
} |
|||
avgCOMWorldSpace = CoM/c; |
|||
avgCOMVelocityWorldSpace = (avgCOMWorldSpace - previousAvgCOM)/Time.fixedDeltaTime; |
|||
// Debug.DrawRay(avgCOMWorldSpace, avgCOMVelocityWorldSpace, Color.green,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(avgCOMWorldSpace, Vector3.ProjectOnPlane( avgCOMVelocityWorldSpace, Vector3.up), Color.green,Time.fixedDeltaTime);
|
|||
|
|||
previousAvgCOM = avgCOMWorldSpace; |
|||
return avgCOMWorldSpace; |
|||
} |
|||
|
|||
|
|||
void FixedUpdate() |
|||
{ |
|||
if(Application.isPlaying) |
|||
{ |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
|
|||
// if (active)
|
|||
// {
|
|||
GetCoMWorldSpace(); |
|||
// }
|
|||
|
|||
|
|||
// Vector3 CoM = Vector3.zero;
|
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
// float c = 0f;
|
|||
//
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// CoM += item.worldCenterOfMass * item.mass;
|
|||
// c += item.mass;
|
|||
// }
|
|||
// avgCOMWorldSpace = CoM/c;
|
|||
// avgCOMVelocityWorldSpace = previousAvgCOM - avgCOMWorldSpace;
|
|||
// Debug.DrawRay(avgCOMWorldSpace, avgCOMVelocityWorldSpace, Color.green,Time.fixedDeltaTime);
|
|||
//
|
|||
// previousAvgCOM = avgCOMWorldSpace;
|
|||
// // CoM /= c;
|
|||
//
|
|||
|
|||
if (showBPPosRelToBody) |
|||
{ |
|||
var pos = body_T.position; |
|||
Matrix4x4 bodyMatrix = body_T.localToWorldMatrix; |
|||
// get position from the last column
|
|||
var bodyPos = new Vector3(bodyMatrix[0,3], bodyMatrix[1,3], bodyMatrix[2,3]); |
|||
Debug.DrawRay(bodyPos, Vector3.up, Color.yellow,Time.fixedDeltaTime); |
|||
foreach (var rb in rbList) |
|||
{ |
|||
if (showRBPos) |
|||
{ |
|||
Debug.DrawRay(rb.position, Vector3.up, Color.green,Time.fixedDeltaTime); |
|||
} |
|||
if (rb.transform != body_T) |
|||
{ |
|||
if (showRelPosVectorOnly) |
|||
{ |
|||
var relPosVector = rb.position - body_T.position; |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
Debug.DrawRay(body_T.position + relPosVector, Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
// Vector3 currentLocalPosRelToMatrix = bodyMatrix.inverse.MultiplyPoint(rb.position);
|
|||
Vector3 currentLocalPosRelToMatrix = bodyMatrix.inverse.MultiplyVector(rb.position - bodyPos); |
|||
|
|||
Debug.DrawRay(body_T.position + currentLocalPosRelToMatrix, Vector3.up, Color.green,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformPointUnscaledRelToBody) |
|||
{ |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPointUnscaled(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
|
|||
//disabled this
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPointUnscaled(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
} |
|||
if (showInverseTransformPointRelToBody) |
|||
{ |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformDirRelToBody) |
|||
{ |
|||
Debug.DrawRay(body_T.InverseTransformDirection(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformVectorRelToBody) |
|||
{ |
|||
Debug.DrawRay(body_T.position + body_T.InverseTransformVector(rb.position - body_T.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
// var localPosRelToBody = body.InverseTransformPoint(rb.position);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + rb.transform.TransformVector(rb.transform.localPosition), Vector3.up, Color.cyan,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(rb.transform.TransformPoint(rb.position), Vector3.up, Color.green,Time.fixedDeltaTime);
|
|||
|
|||
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformVector(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformDirection(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.TransformPoint(rb.transform.localPosition), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
|
|||
if (useTransformPoint) |
|||
{ |
|||
|
|||
} |
|||
else if (useTransformVector) |
|||
{ |
|||
|
|||
} |
|||
else if (useTransformDir) |
|||
{ |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
// private void OnDrawGizmosSelected()
|
|||
private void OnDrawGizmos() |
|||
{ |
|||
if(!Application.isPlaying) |
|||
{ |
|||
if (showCOMGizmos) |
|||
{ |
|||
Vector3 CoM = Vector3.zero; |
|||
float c = 0f; |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
//SHOW BODY PART GIZMOS
|
|||
foreach(var item in rbList) |
|||
{ |
|||
// if (item)
|
|||
// {
|
|||
Gizmos.color = bodyPartCOMColor; |
|||
float drawCOMRadius = item.mass/totalMass; |
|||
Gizmos.DrawSphere(item.worldCenterOfMass, drawCOMRadius); |
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
CoM += item.worldCenterOfMass * item.mass; |
|||
c += item.mass; |
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
} |
|||
|
|||
//DRAW AVG GIZMOS
|
|||
avgCOMWorldSpace = CoM/c; |
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
float avgCOMRadius = 0.5f; //radius of gizmo
|
|||
Gizmos.color = avgCOMColor; |
|||
Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMRadius); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (showCOMGizmos) |
|||
{ |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
//SHOW BODY PART GIZMOS
|
|||
foreach(var item in rbList) |
|||
{ |
|||
// if (item)
|
|||
// {
|
|||
Gizmos.color = bodyPartCOMColor; |
|||
float drawCOMRadius = item.mass/totalMass; |
|||
Gizmos.DrawSphere(item.worldCenterOfMass, drawCOMRadius); |
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
} |
|||
|
|||
//DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
float avgCOMGizmoRadius = 0.5f; //radius of gizmo
|
|||
Gizmos.color = avgCOMColor; |
|||
Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMGizmoRadius); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
// {
|
|||
// if(!Application.isPlaying)
|
|||
// {
|
|||
// if (showCOMGizmos)
|
|||
// {
|
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// //SHOW BODY PART GIZMOS
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// Gizmos.color = bodyPartCOMColor;
|
|||
// float drawCOMRadius = item.mass/totalMass;
|
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// float avgCOMRadius = 0.1f; //radius of gizmo
|
|||
// Gizmos.color = avgCOMColor;
|
|||
// Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMRadius);
|
|||
// }
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// if (showCOMGizmos)
|
|||
// {
|
|||
// // avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// //SHOW BODY PART GIZMOS
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// Gizmos.color = bodyPartCOMColor;
|
|||
// float drawCOMRadius = item.mass/totalMass;
|
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// // avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// // avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// float avgCOMGizmoRadius = 0.1f; //radius of gizmo
|
|||
// Gizmos.color = avgCOMColor;
|
|||
// Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMGizmoRadius);
|
|||
// }
|
|||
|
|||
// }
|
|||
// }
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 74cc05b039aa04d3da17ac9921123c22 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8d773733493b846e9ac5f499b49ee72c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 6fa638926d5204c779388e48e6255ad8 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 19ed1486aa27d4903b34839f37b8f69f, type: 3} |
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerDynamicVariableSpeed.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: db7b60f9ef4594117b8c652234fee72d |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 19ed1486aa27d4903b34839f37b8f69f, type: 3} |
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStatic.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 48d9838ba2af64512a599f6cecee6ce9 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 19ed1486aa27d4903b34839f37b8f69f, type: 3} |
1001
Project/Assets/ML-Agents/Examples/Walker/TFModels/20kDistToTargCloud/WalkerStaticVariableSpeed.nn
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 163fdf9da8bd8441c97f6e760543fa06 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: main obj |
|||
11400002: model data |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 19ed1486aa27d4903b34839f37b8f69f, type: 3} |
撰写
预览
正在加载...
取消
保存
Reference in new issue