From ab662ba3269f03ac975fdbf489c6ebed32f82461 Mon Sep 17 00:00:00 2001 From: Chikashi Miyama Date: Thu, 31 Oct 2019 21:08:01 +0100 Subject: [PATCH] add basic kinect skelton --- .../Examples/KinectSkeleton/Skeleton.unity | 223 +++++++++--------- .../KinectSkeleton/script/Skeleton.cs | 30 +-- .../VideoInput/KinectManagerBehaviour.cs | 7 +- 3 files changed, 132 insertions(+), 128 deletions(-) diff --git a/UnityProject/Assets/Scenes/Examples/KinectSkeleton/Skeleton.unity b/UnityProject/Assets/Scenes/Examples/KinectSkeleton/Skeleton.unity index b473b04..fb80a74 100644 --- a/UnityProject/Assets/Scenes/Examples/KinectSkeleton/Skeleton.unity +++ b/UnityProject/Assets/Scenes/Examples/KinectSkeleton/Skeleton.unity @@ -120,115 +120,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &863219604 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 863219609} - - component: {fileID: 863219608} - - component: {fileID: 863219607} - - component: {fileID: 863219606} - - component: {fileID: 863219605} - m_Layer: 0 - m_Name: Cube - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!111 &863219605 -Animation: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 863219604} - m_Enabled: 1 - serializedVersion: 3 - m_Animation: {fileID: 7400000, guid: 5adbcf2e6f7f1d24e91fb33e84d0df0e, type: 2} - m_Animations: - - {fileID: 0} - m_WrapMode: 0 - m_PlayAutomatically: 1 - m_AnimatePhysics: 1 - m_CullingType: 0 ---- !u!65 &863219606 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 863219604} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &863219607 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 863219604} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &863219608 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 863219604} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &863219609 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 863219604} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.2028971, y: -0.6283364, z: 0.5670376} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1384498139 PrefabInstance: m_ObjectHideFlags: 0 @@ -296,6 +187,16 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 4731626929094548426, guid: 2cf41770dc7914b46aa31a442508dd25, + type: 3} + propertyPath: m_LocalPosition.x + value: -5 + objectReference: {fileID: 0} + - target: {fileID: 4731626929094548426, guid: 2cf41770dc7914b46aa31a442508dd25, + type: 3} + propertyPath: m_LocalPosition.z + value: 2.36 + objectReference: {fileID: 0} - target: {fileID: 826238034, guid: 2cf41770dc7914b46aa31a442508dd25, type: 3} propertyPath: spherePrefab value: @@ -314,6 +215,7 @@ GameObject: - component: {fileID: 1931119207} - component: {fileID: 1931119206} - component: {fileID: 1931119205} + - component: {fileID: 1931119208} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -365,8 +267,8 @@ Camera: m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 + m_HDR: 0 + m_AllowMSAA: 0 m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 @@ -386,6 +288,105 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1931119208 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1931119204} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 23c1ce4fb46143f46bc5cb5224c934f6, type: 3} + m_Name: + m_EditorClassIdentifier: + clearColorMode: 0 + backgroundColorHDR: {r: 0.025, g: 0.07, b: 0.19, a: 0} + clearDepth: 1 + volumeLayerMask: + serializedVersion: 2 + m_Bits: 1 + volumeAnchorOverride: {fileID: 0} + antialiasing: 0 + SMAAQuality: 2 + dithering: 0 + stopNaNs: 0 + physicalParameters: + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 + flipYMode: 0 + fullscreenPassthrough: 0 + allowDynamicResolution: 0 + customRenderingSettings: 0 + invertFaceCulling: 0 + probeLayerMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPathCustomFrameSettings: + bitDatas: + data1: 69284264935197 + data2: 4539628424389459968 + lodBias: 1 + lodBiasMode: 0 + maximumLODLevel: 0 + maximumLODLevelMode: 0 + renderingPathCustomFrameSettingsOverrideMask: + mask: + data1: 0 + data2: 0 + defaultFrameSettings: 0 + m_Version: 5 + m_ObsoleteRenderingPath: 0 + m_ObsoleteFrameSettings: + overrides: 0 + enableShadow: 0 + enableContactShadows: 0 + enableShadowMask: 0 + enableSSR: 0 + enableSSAO: 0 + enableSubsurfaceScattering: 0 + enableTransmission: 0 + enableAtmosphericScattering: 0 + enableVolumetrics: 0 + enableReprojectionForVolumetrics: 0 + enableLightLayers: 0 + enableExposureControl: 1 + diffuseGlobalDimmer: 0 + specularGlobalDimmer: 0 + shaderLitMode: 0 + enableDepthPrepassWithDeferredRendering: 0 + enableTransparentPrepass: 0 + enableMotionVectors: 0 + enableObjectMotionVectors: 0 + enableDecals: 0 + enableRoughRefraction: 0 + enableTransparentPostpass: 0 + enableDistortion: 0 + enablePostprocess: 0 + enableOpaqueObjects: 0 + enableTransparentObjects: 0 + enableRealtimePlanarReflection: 0 + enableMSAA: 0 + enableAsyncCompute: 0 + runLightListAsync: 0 + runSSRAsync: 0 + runSSAOAsync: 0 + runContactShadowsAsync: 0 + runVolumeVoxelizationAsync: 0 + lightLoopSettings: + overrides: 0 + enableDeferredTileAndCluster: 0 + enableComputeLightEvaluation: 0 + enableComputeLightVariants: 0 + enableComputeMaterialVariants: 0 + enableFptlForForwardOpaque: 0 + enableBigTilePrepass: 0 + isFptlEnabled: 0 --- !u!1 &2001908821 GameObject: m_ObjectHideFlags: 0 diff --git a/UnityProject/Assets/Scenes/Examples/KinectSkeleton/script/Skeleton.cs b/UnityProject/Assets/Scenes/Examples/KinectSkeleton/script/Skeleton.cs index 7c634c6..708e8e0 100644 --- a/UnityProject/Assets/Scenes/Examples/KinectSkeleton/script/Skeleton.cs +++ b/UnityProject/Assets/Scenes/Examples/KinectSkeleton/script/Skeleton.cs @@ -20,26 +20,26 @@ namespace cylvester } } - public void OnSkeletonFrameReceived(Body[] bodies) { - if (bodies.Length == 0) - return; - - var body = bodies[0]; - - var i = 0; - foreach(var pair in body.Joints) + foreach (var body in bodies) { - var joint = pair.Value; - if(joint.TrackingState == TrackingState.NotTracked) - balls_[i].SetActive(false); - else + if(!body.IsTracked) + continue; + + var i = 0; + foreach(var pair in body.Joints) { - balls_[i].SetActive(true); - balls_[i].transform.position = new Vector3(joint.Position.X, joint.Position.Y, 0f); + var joint = pair.Value; + if(joint.TrackingState == TrackingState.NotTracked) + balls_[i].SetActive(false); + else + { + balls_[i].SetActive(true); + balls_[i].transform.position = new Vector3(joint.Position.X * 10f , joint.Position.Y * 10f, 0f); + } + i++; } - i++; } } } diff --git a/UnityProject/Assets/Scripts/VideoInput/KinectManagerBehaviour.cs b/UnityProject/Assets/Scripts/VideoInput/KinectManagerBehaviour.cs index 4bc9fc9..90619dc 100644 --- a/UnityProject/Assets/Scripts/VideoInput/KinectManagerBehaviour.cs +++ b/UnityProject/Assets/Scripts/VideoInput/KinectManagerBehaviour.cs @@ -55,9 +55,10 @@ namespace cylvester using (var infraredFrame = eventArgs.FrameReference.AcquireFrame()) { - if (infraredFrame == null) return; + if (infraredFrame == null) + return; + infraredFrame.CopyFrameDataToArray(irData_); - unsafe { fixed (ushort* irDataPtr = irData_) @@ -86,6 +87,8 @@ namespace cylvester using (var bodyFrame = eventArgs.FrameReference.AcquireFrame()) { + if (bodyFrame == null) + return; Array.Resize(ref bodies_, bodyFrame.BodyCount); bodyFrame.GetAndRefreshBodyData(bodies_); skeletonDataReceived.Invoke(bodies_);