Unity初心者でUnityとKinectを用いて開発しています。
現在行いたいこととして、Kinectからの深度情報をもとに画像(Raw Image)を生成しQuadメッシュに画像を表示させています。
その、表示させている画像とGame Objectで当たり判定を行いたいと思っているのですが、うまくできません。
こちらがKinectから得たデータをもとにQuadメッシュに画像を表示させているソース全文になります。
C#
1using UnityEngine; 2using Windows.Kinect; 3using System; 4 5public class SimpleDepthView : MonoBehaviour 6{ 7 public GameObject depthSourceManager; 8 private DepthSourceManager depthSourceManagerScript; 9 10 Texture2D texture; 11 byte[] depthBitmapBuffer; 12 FrameDescription depthFrameDesc; 13 14 public float scale = 1.0f; 15 16 void Start() 17 { 18 // Get the description of the depth frames. 19 depthFrameDesc = KinectSensor.GetDefault().DepthFrameSource.FrameDescription; 20 21 // get reference to DepthSourceManager (which is included in the distributed 'Kinect for Windows v2 Unity Plugin zip') 22 depthSourceManagerScript = depthSourceManager.GetComponent<DepthSourceManager>(); 23 24 // allocate. 25 depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4]; 26 texture = new Texture2D(depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.BGRA32, false); 27 28 // arrange size of gameObject to be drawn 29 gameObject.transform.localScale = new Vector3(scale * depthFrameDesc.Width / depthFrameDesc.Height, scale, 1.0f); 30 } 31 32 void Update() 33 { 34 updateTexture(); 35 this.GetComponent<Renderer>().material.mainTexture = texture; 36 } 37 38 // Depth判定範囲 39 int min = 500; 40 int max = 1500; 41 void updateTexture() 42 { 43 // get new depth data from DepthSourceManager. 44 ushort[] rawdata = depthSourceManagerScript.GetData(); 45 46 // convert to byte data ( 47 for (int i = 0; i < rawdata.Length; i++) 48 { 49 // BGRAの順番 50 int colorindex = i * 4; 51 52 depthBitmapBuffer[i * 4 + 0] = (byte)0; // B // 53 depthBitmapBuffer[i * 4 + 1] = (byte)((min < rawdata[i]) && (rawdata[i] < max) ? 255 : 0); // G // COMMON 54 depthBitmapBuffer[i * 4 + 2] = (byte)0; // R // 55 depthBitmapBuffer[i * 4 + 3] = (byte)((min < rawdata[i]) && (rawdata[i] < max) ? 255 : 0); // A // COMMON 56 } 57 58 // make texture from byte array 59 texture.LoadRawTextureData(depthBitmapBuffer); 60 texture.Apply(); 61 } 62}
Mesh Colliderなども使ってみましたが、うまくできませんでした。
開発環境としては
・Windows 10 ( BootCamp )
・Visual Studio 2015
・Unity Personal v5.3.5
・Kinect v2
です。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/07 09:40
2016/09/07 12:46
2016/09/08 11:54 編集