From 31ce446737d7795837a2df8b25df41d9d3a8c967 Mon Sep 17 00:00:00 2001 From: Ichirinko <1621543655@qq.com> Date: Sun, 26 Feb 2023 21:02:08 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E9=AA=A8=E9=AA=BC=EF=BC=8C=E7=94=A8=E4=BA=8E=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=96=B9=E5=90=91=E8=AE=A1=E7=AE=97=E7=9A=84=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Bonds.cs | 11 +++++--- Assets/MainBehaviour.cs | 23 ++++++++++++++--- Assets/Scenes/BallScene.unity | 8 +++--- Assets/VirtualSkeleton.cs | 46 ++++++++++++++++++++++++++++++++++ Assets/VirtualSkeleton.cs.meta | 3 +++ 5 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 Assets/VirtualSkeleton.cs create mode 100644 Assets/VirtualSkeleton.cs.meta diff --git a/Assets/Bonds.cs b/Assets/Bonds.cs index bd58eac..574f966 100644 --- a/Assets/Bonds.cs +++ b/Assets/Bonds.cs @@ -4,8 +4,8 @@ namespace Models { public class Bonds { - private GameObject start; - private GameObject end; + public GameObject start; + public GameObject end; private GameObject bond; @@ -17,6 +17,9 @@ public Bonds(GameObject start,GameObject end,float scale) bond = GameObject.CreatePrimitive(PrimitiveType.Cylinder); bond.transform.localScale = new Vector3(scale/2, scale/2, scale/2); + + //这里可以设置材质,具体自己设置 + bond.GetComponent().material.color = Color.cyan; } @@ -36,8 +39,8 @@ public void UpdateBond() bond.transform.rotation = Quaternion.FromToRotation(Vector3.up, rightRotation); bond.transform.localScale = new Vector3(LThickness, HalfLength, LThickness); - //这里可以设置材质,具体自己设置 - bond.GetComponent().material.color = Color.cyan; + + } } diff --git a/Assets/MainBehaviour.cs b/Assets/MainBehaviour.cs index 7b3787e..c3272ce 100644 --- a/Assets/MainBehaviour.cs +++ b/Assets/MainBehaviour.cs @@ -7,16 +7,19 @@ public class MainBehaviour : MonoBehaviour { private readonly List _nodes = new List(); private readonly List _bonds = new List(); + private readonly List _virtualSkeletons = new List(); private readonly List _poseTransforms = new List(); private readonly UdpListener _listener = new UdpListener(); private const float _scale = 0.2f; - + private GameObject sample ; // Start is called before the first frame update private void Start() { CreateNodes(); CreateBonds(); + + _listener.AddHandler(OnReceive); _listener.Connect(5000); } @@ -42,6 +45,11 @@ private void Update() { bond.UpdateBond(); } + + /*foreach (var vs in _virtualSkeletons) + { + vs.UpdateVS(); + }*/ } private void OnDisable() @@ -186,9 +194,18 @@ private void CreateBonds() temp = new Bonds(_nodes[29], _nodes[31], _scale); _bonds.Add(temp); + + + + /*foreach (var bond in _bonds) + { + var temp2 = new VirtualSkeleton(bond.start, bond.end, _scale); + _virtualSkeletons.Add(temp2); + }*/ + } - - + + private void OnReceive(List landmarks) { diff --git a/Assets/Scenes/BallScene.unity b/Assets/Scenes/BallScene.unity index b62cd46..b8324e2 100644 --- a/Assets/Scenes/BallScene.unity +++ b/Assets/Scenes/BallScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {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 --- !u!157 &3 LightmapSettings: @@ -436,14 +436,14 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2045151417} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -7.44} + m_LocalRotation: {x: 0, y: 1, z: 0, w: 0} + m_LocalPosition: {x: 0, y: 0, z: 7} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0} --- !u!114 &2045151421 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/VirtualSkeleton.cs b/Assets/VirtualSkeleton.cs new file mode 100644 index 0000000..4e286b2 --- /dev/null +++ b/Assets/VirtualSkeleton.cs @@ -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().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); + } + + } +} \ No newline at end of file diff --git a/Assets/VirtualSkeleton.cs.meta b/Assets/VirtualSkeleton.cs.meta new file mode 100644 index 0000000..067f9c7 --- /dev/null +++ b/Assets/VirtualSkeleton.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5f725336fc6a4481a4c7d74ec0e3b17b +timeCreated: 1677413910 \ No newline at end of file