add:增加了虚拟骨骼,用于验证方向计算的正确性

This commit is contained in:
Ichirinko 2023-02-26 21:02:08 +08:00
parent d13b0b0b2b
commit 31ce446737
5 changed files with 80 additions and 11 deletions

View File

@ -4,8 +4,8 @@ namespace Models
{ {
public class Bonds public class Bonds
{ {
private GameObject start; public GameObject start;
private GameObject end; public GameObject end;
private GameObject bond; private GameObject bond;
@ -17,6 +17,9 @@ public Bonds(GameObject start,GameObject end,float scale)
bond = GameObject.CreatePrimitive(PrimitiveType.Cylinder); bond = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
bond.transform.localScale = new Vector3(scale/2, scale/2, scale/2); bond.transform.localScale = new Vector3(scale/2, scale/2, scale/2);
//这里可以设置材质,具体自己设置
bond.GetComponent<Renderer>().material.color = Color.cyan;
} }
@ -36,8 +39,8 @@ public void UpdateBond()
bond.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation); bond.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation);
bond.transform.localScale = new Vector3(LThickness, HalfLength, LThickness); bond.transform.localScale = new Vector3(LThickness, HalfLength, LThickness);
//这里可以设置材质,具体自己设置
bond.GetComponent<Renderer>().material.color = Color.cyan;
} }
} }

View File

@ -7,16 +7,19 @@ public class MainBehaviour : MonoBehaviour
{ {
private readonly List<GameObject> _nodes = new List<GameObject>(); private readonly List<GameObject> _nodes = new List<GameObject>();
private readonly List<Bonds> _bonds = new List<Bonds>(); private readonly List<Bonds> _bonds = new List<Bonds>();
private readonly List<VirtualSkeleton> _virtualSkeletons = new List<VirtualSkeleton>();
private readonly List<PoseTransform> _poseTransforms = new List<PoseTransform>(); private readonly List<PoseTransform> _poseTransforms = new List<PoseTransform>();
private readonly UdpListener _listener = new UdpListener(); private readonly UdpListener _listener = new UdpListener();
private const float _scale = 0.2f; private const float _scale = 0.2f;
private GameObject sample ;
// Start is called before the first frame update // Start is called before the first frame update
private void Start() private void Start()
{ {
CreateNodes(); CreateNodes();
CreateBonds(); CreateBonds();
_listener.AddHandler(OnReceive); _listener.AddHandler(OnReceive);
_listener.Connect(5000); _listener.Connect(5000);
} }
@ -42,6 +45,11 @@ private void Update()
{ {
bond.UpdateBond(); bond.UpdateBond();
} }
/*foreach (var vs in _virtualSkeletons)
{
vs.UpdateVS();
}*/
} }
private void OnDisable() private void OnDisable()
@ -186,6 +194,15 @@ private void CreateBonds()
temp = new Bonds(_nodes[29], _nodes[31], _scale); temp = new Bonds(_nodes[29], _nodes[31], _scale);
_bonds.Add(temp); _bonds.Add(temp);
/*foreach (var bond in _bonds)
{
var temp2 = new VirtualSkeleton(bond.start, bond.end, _scale);
_virtualSkeletons.Add(temp2);
}*/
} }

View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0} m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18029127, g: 0.22572401, b: 0.3069303, a: 1} m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -436,14 +436,14 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2045151417} m_GameObject: {fileID: 2045151417}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 1, z: -7.44} m_LocalPosition: {x: 0, y: 0, z: 7}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!114 &2045151421 --- !u!114 &2045151421
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

46
Assets/VirtualSkeleton.cs Normal file
View File

@ -0,0 +1,46 @@
using UnityEngine;
using UnityEngine.PlayerLoop;
namespace Models
{
public class VirtualSkeleton : Bonds
{
//private GameObject start;
//private GameObject end;
private GameObject virtualskeleton;
public VirtualSkeleton(GameObject start,GameObject end,float scale) : base(start,end,scale)
{
this.start = start;
this.end = end;
virtualskeleton = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
virtualskeleton.transform.localScale = new Vector3(scale/2, scale/2, scale/2);
virtualskeleton.GetComponent<Renderer>().material.color = Color.white;
}
public void UpdateVS()
{
var startpos = start.transform.position;
var endpos = end.transform.position;
Vector3 rightPosition = (startpos + endpos) / 2;
Vector3 rightRotation = endpos - startpos;
float LThickness = 0.2f;//线的粗细
//创建圆柱体
//bond.gameObject.transform.parent = transform;
virtualskeleton.transform.position = rightPosition;
virtualskeleton.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation);
//virtualskeleton.transform.rotation = Quaternion.LookRotation(rightRotation, Vector3.forward);
virtualskeleton.transform.localScale = new Vector3(LThickness, LThickness, LThickness);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f725336fc6a4481a4c7d74ec0e3b17b
timeCreated: 1677413910