change structure from pull to push for kinect data passing

This commit is contained in:
Chikashi Miyama 2019-10-31 13:40:44 +01:00
parent 66907c8492
commit 955434878a
21 changed files with 292 additions and 410 deletions

View file

@ -69,8 +69,6 @@
<Compile Include="Assets\Editor\UnitTest\UnitTest_RectangularSelection.cs" />
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorEditMode.cs" />
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorPlayMode.cs" />
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\ComponentFactoryTestCase.cs" />
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\KinectSensorTestCase.cs" />
<Compile Include="Assets\ThridParty\Editor\KinectCopyPluginDataHelper.cs" />
<Reference Include="UnityEditor.TestRunner">
<HintPath>C:/Users/chikashi/Development/Soundvision/UnityProject/Library/ScriptAssemblies/UnityEditor.TestRunner.dll</HintPath>

View file

@ -100,15 +100,12 @@
<Compile Include="Assets\Scripts\StateManagement\StateManager.cs" />
<Compile Include="Assets\Scripts\TemplateLibrary\ChangeObserver.cs" />
<Compile Include="Assets\Scripts\Versioning\VersionToggleBehaviour.cs" />
<Compile Include="Assets\Scripts\VideoInput\ComponentFactory.cs" />
<Compile Include="Assets\Scripts\VideoInput\InfraredCamera.cs" />
<Compile Include="Assets\Scripts\VideoInput\KinectFacade.cs" />
<Compile Include="Assets\Scripts\VideoInput\KinectManagerBehaviour.cs" />
<Compile Include="Assets\Scripts\VideoInput\KinectSensor.cs" />
<Compile Include="Assets\Scripts\VideoInput\SkeletonTracker.cs" />
<Compile Include="Assets\Scripts\Visualizer\CombMesh.cs" />
<Compile Include="Assets\Scripts\Visualizer\IRPanelBehaviour.cs" />
<Compile Include="Assets\Scripts\Visualizer\PointCloudBehaviour.cs" />
<Compile Include="Assets\Scripts\Visualizer\SpectrumVisualizer.cs" />
<Compile Include="Assets\Scripts\Visualizer\WaterfallVisualizer.cs" />
<Compile Include="Assets\Scripts\Visualizer\WaveformVisualizerBehaviour.cs" />

View file

@ -1,6 +1,6 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6543630110689268649
--- !u!1 &1755305043
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -8,46 +8,46 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6543630110689268650}
- component: {fileID: 6543630110689268629}
- component: {fileID: 6543630110689268628}
- component: {fileID: 6543630110689268651}
- component: {fileID: 1755305047}
- component: {fileID: 1755305046}
- component: {fileID: 1755305045}
- component: {fileID: 1755305044}
m_Layer: 0
m_Name: IRPanel
m_Name: Plane
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6543630110689268650
--- !u!4 &1755305047
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6543630110689268649}
m_LocalRotation: {x: -0.7071068, y: 0, z: -0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_GameObject: {fileID: 1755305043}
m_LocalRotation: {x: -0.67983025, y: 0.17033821, z: 0.1669823, w: 0.6934931}
m_LocalPosition: {x: 0, y: 0, z: 2.21}
m_LocalScale: {x: 10, y: 1, z: 10}
m_Children: []
m_Father: {fileID: 6543630111923623140}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
--- !u!33 &6543630110689268629
m_LocalEulerAnglesHint: {x: -88.86, y: 27.6, z: 0}
--- !u!33 &1755305046
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6543630110689268649}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6543630110689268628
m_GameObject: {fileID: 1755305043}
m_Mesh: {fileID: 4300000, guid: 2af19fd62c4ff574a88cdb7412a28be6, type: 2}
--- !u!23 &1755305045
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6543630110689268649}
m_GameObject: {fileID: 1755305043}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
@ -58,7 +58,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a8f5d1054ef74a44b9ad9a606a412c6a, type: 2}
- {fileID: 2100000, guid: 08091c5640297a64496a47b90b015414, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -70,7 +70,7 @@ MeshRenderer:
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
@ -79,20 +79,19 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &6543630110689268651
--- !u!114 &1755305044
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6543630110689268649}
m_GameObject: {fileID: 1755305043}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0603bf64edb4c8885cefbc40ee206fe, type: 3}
m_Name:
m_EditorClassIdentifier:
kinectManagerBehaviour: {fileID: 6724733047624778891}
panel: {fileID: 6543630110689268649}
panel: {fileID: 1755305043}
--- !u!1 &6543630111923623163
GameObject:
m_ObjectHideFlags: 0
@ -121,7 +120,7 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6543630110689268650}
- {fileID: 1755305047}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -137,3 +136,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5b54a31bc1a14c1abb51fe86c56c6227, type: 3}
m_Name:
m_EditorClassIdentifier:
infrared: 1
infraredFrameReceived:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1755305044}
m_MethodName: OnInfraredFrameReceived
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
skeleton: 0
skeletonDataReveived:
m_PersistentCalls:
m_Calls: []

View file

@ -564,115 +564,5 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6543630110689268649, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 367ac1ecba1e2584c816e0372e8d9b31, type: 3}
--- !u!1 &1755305043
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1755305047}
- component: {fileID: 1755305046}
- component: {fileID: 1755305045}
- component: {fileID: 1755305044}
m_Layer: 0
m_Name: Plane
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1755305044
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1755305043}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0603bf64edb4c8885cefbc40ee206fe, type: 3}
m_Name:
m_EditorClassIdentifier:
kinectManagerBehaviour: {fileID: 1809500800}
panel: {fileID: 1755305043}
--- !u!23 &1755305045
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1755305043}
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: 08091c5640297a64496a47b90b015414, 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 &1755305046
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1755305043}
m_Mesh: {fileID: 4300000, guid: 2af19fd62c4ff574a88cdb7412a28be6, type: 2}
--- !u!4 &1755305047
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1755305043}
m_LocalRotation: {x: -0.67983025, y: 0.1703382, z: 0.1669823, w: 0.69349307}
m_LocalPosition: {x: 0, y: 0, z: 2.21}
m_LocalScale: {x: 10, y: 1, z: 10}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: -88.86, y: 27.6, z: 0}
--- !u!114 &1809500800 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6724733047624778891, guid: 367ac1ecba1e2584c816e0372e8d9b31,
type: 3}
m_PrefabInstance: {fileID: 880921870}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b54a31bc1a14c1abb51fe86c56c6227, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -22,6 +22,10 @@ Material:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MyTexture:
m_Texture: {fileID: 2800000, guid: 965d36ee5de48ea459184ffdd20071a1, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _kinectTexture:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}

View file

@ -187,6 +187,46 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infrared
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: skeleton
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 2080636163}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: OnInfraredFrameReceived
objectReference: {fileID: 0}
- target: {fileID: 5059429581819481323, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
propertyPath: infraredFrameReceived.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2cf41770dc7914b46aa31a442508dd25, type: 3}
--- !u!1 &1931119204
@ -282,6 +322,8 @@ GameObject:
m_Component:
- component: {fileID: 2001908823}
- component: {fileID: 2001908822}
- component: {fileID: 2001908825}
- component: {fileID: 2001908824}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
@ -300,7 +342,7 @@ Light:
serializedVersion: 9
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Intensity: 3.1415927
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
@ -340,7 +382,7 @@ Light:
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_LightShadowCasterMode: 2
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
@ -363,3 +405,116 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!114 &2001908824
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2001908821}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Version: 1
shadowResolution: 512
shadowDimmer: 1
volumetricShadowDimmer: 1
shadowFadeDistance: 10000
contactShadows: 0
shadowTint: {r: 0, g: 0, b: 0, a: 1}
viewBiasMin: 0.2
viewBiasMax: 100
viewBiasScale: 1
normalBiasMin: 0.5
normalBiasMax: 0.5
normalBiasScale: 1
sampleBiasScale: 0
edgeLeakFixup: 0
edgeToleranceNormal: 1
edgeTolerance: 1
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowCascadeBorders:
- 0.2
- 0.2
- 0.2
- 0.2
shadowAlgorithm: 0
shadowVariant: 0
shadowPrecision: 0
--- !u!114 &2001908825
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2001908821}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 5
m_Version: 5
directionalIntensity: 3.1415927
punctualIntensity: 600
areaIntensity: 200
enableSpotReflector: 0
luxAtDistance: 1
m_InnerSpotPercent: 0
lightDimmer: 1
m_VolumetricDimmer: 1
lightUnit: 2
fadeDistance: 10000
affectDiffuse: 1
affectSpecular: 1
nonLightmappedOnly: 0
lightTypeExtent: 0
m_SpotLightShape: 0
shapeWidth: 0.5
shapeHeight: 0.5
aspectRatio: 1
shapeRadius: 0
maxSmoothness: 0.99
applyRangeAttenuation: 1
useOldInspector: 0
useVolumetric: 1
featuresFoldout: 1
showAdditionalSettings: 0
displayLightIntensity: 3.1415927
displayAreaLightEmissiveMesh: 0
areaLightCookie: {fileID: 0}
areaLightShadowCone: 120
useScreenSpaceShadows: 0
evsmExponent: 15
evsmLightLeakBias: 0
evsmVarianceBias: 0.00001
evsmBlurPasses: 0
lightLayers: 1
lightlayersMask: 1
linkShadowLayers: 1
shadowNearPlane: 0.1
shadowSoftness: 0.5
blockerSampleCount: 24
filterSampleCount: 16
minFilterSize: 0.00001
kernelSize: 5
lightAngle: 1
maxDepthBias: 0.001
--- !u!114 &2080636163 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4731626929094548427, guid: 2cf41770dc7914b46aa31a442508dd25,
type: 3}
m_PrefabInstance: {fileID: 1384498139}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c0603bf64edb4c8885cefbc40ee206fe, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -1,16 +0,0 @@
namespace cylvester
{
public class ComponentFactory
{
public IKinectSensor CreateKinectSensor()
{
return new KinectSensor(CreateInfraredCamera());
}
public IInfraredCamera CreateInfraredCamera()
{
return new InfraredCamera();
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b3510aec53634387bd87c7ebae1d41ae
timeCreated: 1562447022

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: fc8188340da14e1ab2aca454bb779e56
timeCreated: 1562450252

View file

@ -1,24 +0,0 @@
using NUnit.Framework;
namespace cylvester.Editor.UnitTest
{
public class UnitTestComponentFactory
{
[Test]
public void CreateKinectSensor()
{
var componentFactory = new ComponentFactory();
var kinectSensor = componentFactory.CreateKinectSensor();
Assert.NotNull(kinectSensor);
}
[Test]
public void CreateInfraredCamera()
{
var componentFactory = new ComponentFactory();
var infraredCamera = componentFactory.CreateInfraredCamera();
Assert.NotNull(infraredCamera);
}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 7e1eccfbf87e70645afd4bef217cc3d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,33 +0,0 @@
using NUnit.Framework;
using NSubstitute;
namespace cylvester.Editor.UnitTest
{
[TestFixture]
public class UnitTestKinectSensor
{
private IInfraredCamera infraredCameraMock_;
[SetUp]
public void SetUp()
{
infraredCameraMock_ = Substitute.For<IInfraredCamera>();
}
[Test]
public void InfraredCamera()
{
var kinectSensor = new KinectSensor(infraredCameraMock_);
Assert.AreSame(infraredCameraMock_, kinectSensor.InfraredCamera);
}
[Test]
public void Update()
{
var kinectSensor = new KinectSensor(infraredCameraMock_);
kinectSensor.Update();
infraredCameraMock_.Received(1).Update();
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 898dc2d4dc394ea6b80a1cc09d63121c
timeCreated: 1562450837

View file

@ -5,60 +5,6 @@ using Windows.Kinect;
namespace cylvester
{
public interface IInfraredCamera
{
Texture2D InfraredTexture { get; }
void Update();
}
public class InfraredCamera : IInfraredCamera
{
public Texture2D InfraredTexture { get; }
private Windows.Kinect.KinectSensor sensor_;
private readonly InfraredFrameReader reader_;
private readonly ushort [] irData_;
public InfraredCamera()
{
sensor_ = Windows.Kinect.KinectSensor.GetDefault();
if (sensor_ == null)
{
throw new IOException("cannot find Kinect Sensor ");
}
reader_ = sensor_.InfraredFrameSource.OpenReader();
var frameDesc = sensor_.InfraredFrameSource.FrameDescription;
irData_ = new ushort[frameDesc.LengthInPixels];
InfraredTexture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.R16, false);
if (!sensor_.IsOpen)
sensor_.Open();
}
public void Update()
{
if (reader_ == null)
throw new IOException("Kinect reader not opened");
var frame = reader_.AcquireLatestFrame();
if (frame == null) return;
frame.CopyFrameDataToArray(irData_);
unsafe
{
fixed(ushort* irDataPtr = irData_)
{
InfraredTexture.LoadRawTextureData((IntPtr) irDataPtr, sizeof(ushort) * irData_.Length);
}
}
InfraredTexture.Apply();
frame.Dispose();
}
}
}

View file

@ -1,20 +1,100 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
using Windows.Kinect;
using UnityEngine;
using UnityEngine.Events;
namespace cylvester
{
[Serializable] public class UnityInfraredCameraEvent : UnityEvent<Texture2D>{ }
[Serializable] public class UnitySkeletonEvent : UnityEvent<IList<Body>>{ }
public class KinectManagerBehaviour : MonoBehaviour
{
public IKinectSensor KinectSensor { get; private set; }
[SerializeField] private bool infrared;
[SerializeField] public UnityInfraredCameraEvent infraredFrameReceived;
private void Awake()
[SerializeField] private bool skeleton;
[SerializeField] public UnitySkeletonEvent skeletonDataReveived;
private Texture2D InfraredTexture { get; set;}
private KinectSensor sensor_;
private InfraredFrameReader infraredFrameReader_;
private BodyFrameReader bodyFrameReader_;
private ushort [] irData_;
private EventHandler<InfraredFrameArrivedEventArgs> onInfraredFrameArrived_;
private EventHandler<BodyFrameArrivedEventArgs> onSkeletonFrameArrived_;
private void Start()
{
var componentFactory = new ComponentFactory();
KinectSensor = componentFactory.CreateKinectSensor();
sensor_ = KinectSensor.GetDefault();
if (sensor_ == null)
throw new IOException("cannot find Kinect Sensor ");
InitInfraredCamera();
InitSkeletonTracking();
if (!sensor_.IsOpen)
sensor_.Open();
}
private void Update()
private void InitInfraredCamera()
{
KinectSensor.Update();
infraredFrameReader_ = sensor_.InfraredFrameSource.OpenReader();
var frameDesc = sensor_.InfraredFrameSource.FrameDescription;
irData_ = new ushort[frameDesc.LengthInPixels];
InfraredTexture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.R16, false);
onInfraredFrameArrived_ = (frameReader, eventArgs) =>
{
if(!infrared)
return;
using (var infraredFrame = infraredFrameReader_.AcquireLatestFrame())
{
if (infraredFrame == null) return;
infraredFrame.CopyFrameDataToArray(irData_);
unsafe
{
fixed (ushort* irDataPtr = irData_)
{
InfraredTexture.LoadRawTextureData((IntPtr) irDataPtr, sizeof(ushort) * irData_.Length);
}
}
InfraredTexture.Apply();
}
infraredFrameReceived.Invoke(InfraredTexture);
};
infraredFrameReader_.FrameArrived += onInfraredFrameArrived_;
}
private void InitSkeletonTracking()
{
bodyFrameReader_ = sensor_.BodyFrameSource.OpenReader();
onSkeletonFrameArrived_ = (frameReader, eventArgs) =>
{
if(!skeleton)
return;
using (var bodyFrame = eventArgs.FrameReference.AcquireFrame())
{
}
};
bodyFrameReader_.FrameArrived += onSkeletonFrameArrived_;
}
private void OnDestroy()
{
infraredFrameReader_.FrameArrived -= onInfraredFrameArrived_;
bodyFrameReader_.FrameArrived -= onSkeletonFrameArrived_;
}
}
}

View file

@ -1,23 +0,0 @@
namespace cylvester
{
public interface IKinectSensor : IUpdater
{
IInfraredCamera InfraredCamera { get; }
}
public class KinectSensor : IKinectSensor
{
public IInfraredCamera InfraredCamera { get; }
public KinectSensor(IInfraredCamera infraredCamera)
{
InfraredCamera = infraredCamera;
}
public void Update()
{
InfraredCamera.Update();
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 752e0ad44789447883d4db6794deceb9
timeCreated: 1562446718

View file

@ -4,7 +4,6 @@ namespace cylvester
{
class IRPanelBehaviour : MonoBehaviour
{
[SerializeField] private KinectManagerBehaviour kinectManagerBehaviour = null;
[SerializeField] private GameObject panel = null;
private Renderer renderer_;
@ -15,9 +14,9 @@ namespace cylvester
renderer_ = panel.GetComponent<Renderer>();
}
void Update()
public void OnInfraredFrameReceived(Texture2D texture)
{
renderer_.material.SetTexture(KinectTexture, kinectManagerBehaviour.KinectSensor.InfraredCamera.InfraredTexture);
renderer_.material.SetTexture(KinectTexture, texture);
}
}
}

View file

@ -1,83 +0,0 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace cylvester
{
public class PointCloudBehaviour : MonoBehaviour
{
#pragma warning disable 649
[Header("Modifier Parameters")]
[SerializeField] private float zScale;
[Header("Connections")]
[SerializeField] private KinectManagerBehaviour kinectManagerBehaviour;
[SerializeField] private MeshFilter meshFilter;
#pragma warning restore 649
private Material material_;
private static readonly int Scale = Shader.PropertyToID("_Scale");
private void Start()
{
var texture = kinectManagerBehaviour.KinectSensor.InfraredCamera.InfraredTexture;
var numPixels = texture.height * texture.width;
meshFilter.mesh = new Mesh {
vertices = MakeVertices(texture),
uv = MakeTexCoord(texture),
indexFormat = IndexFormat.UInt32
};
meshFilter.mesh.SetIndices(MakeIndecies(numPixels), MeshTopology.Points, 0, false);
material_ = GetComponent<Renderer>().material;
material_.mainTexture = kinectManagerBehaviour.KinectSensor.InfraredCamera.InfraredTexture;
}
private void Update()
{
material_.SetFloat(Scale, zScale);
}
private Vector3[] MakeVertices(Texture2D texture)
{
var vertices = new Vector3[texture.width * texture.height];
for (var i = 0; i < texture.height; ++i)
{
var offset = texture.width * i;
var hPhase = (float) i / texture.height;
for (var j = 0; j < texture.width; ++j)
{
var wPhase = (float) j / texture.width;
vertices[offset + j] = new Vector3(wPhase * 10f - 5f, (hPhase * 10f - 5f) * -1f, 0f);
}
}
return vertices;
}
private Vector2[] MakeTexCoord(Texture2D texture)
{
var texCoords = new Vector2[texture.width * texture.height];
for (var i = 0; i < texture.height; ++i)
{
var offset = texture.width * i;
var hPhase = (float) i / texture.height;
for (var j = 0; j < texture.width; ++j)
{
var wPhase = (float) j / texture.width;
texCoords[offset + j].x = wPhase;
texCoords[offset + j].y = hPhase;
}
}
return texCoords;
}
private int[] MakeIndecies(int numPixels)
{
var array = new int[numPixels];
for (var i = 0; i < numPixels; ++i)
array[i] = i;
return array;
}
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ffecec984845420991cec1a5fcf11959
timeCreated: 1562500684