void Start() { kinectManager = KinectManager.Instance; if (backgroundRemovalManager == null) { backgroundRemovalManager = FindObjectOfType <BackgroundRemovalManager>(); } Renderer meshRenderer = GetComponent <Renderer>(); if (meshRenderer && meshRenderer.material /**&& meshRenderer.material.mainTexture == null*/) { matRenderer = meshRenderer.material; } if (kinectManager && kinectManager.IsInitialized() && backgroundRemovalManager && backgroundRemovalManager.enabled) { // get sensor data sensorData = kinectManager.GetSensorData(backgroundRemovalManager.sensorIndex); sensorInt = sensorData != null ? (DepthSensorBase)sensorData.sensorInterface : null; } // find scene lights Light[] sceneLights = GameObject.FindObjectsOfType <Light>(); lighting.SetLightsAndBounds(sceneLights, transform.position, new Vector3(20f, 20f, 20f)); //Debug.Log("sceneLights: " + sceneLights.Length); //for(int i = 0; i < sceneLights.Length; i++) //{ // Debug.Log(i.ToString() + " - " + sceneLights[i].name + " - " + sceneLights[i].type); //} }
void Start() { kinectManager = KinectManager.Instance; sensorData = kinectManager != null && kinectManager.IsInitialized() ? kinectManager.GetSensorData(sensorIndex) : null; if (sensorData != null && sensorData.sensorInterface != null) { sensorInt = (DepthSensorBase)sensorData.sensorInterface; sensorInt.pointCloudResolution = pointCloudResolution; sensorInt.pointCloudVertexTexture = pointCloudVertexTexture; sensorInt.pointCloudColorTexture = pointCloudColorTexture; //Debug.Log("PointCloudResolution: " + pointCloudResolution + ", PointCloudVertexTexture: " + pointCloudVertexTexture + ", PointCloudColorTexture: " + pointCloudColorTexture); } }
void Start() { kinectManager = KinectManager.Instance; initialScale = transform.localScale; if (backgroundRemovalManager == null) { backgroundRemovalManager = FindObjectOfType <BackgroundRemovalManager>(); } Renderer meshRenderer = GetComponent <Renderer>(); if (meshRenderer) { Shader blendShader = Shader.Find("Kinect/ForegroundBlendShader"); if (blendShader != null) { matRenderer = new Material(blendShader); meshRenderer.material = matRenderer; } } if (kinectManager && kinectManager.IsInitialized() && backgroundRemovalManager && backgroundRemovalManager.enabled) { // get sensor data sensorData = kinectManager.GetSensorData(backgroundRemovalManager.sensorIndex); sensorInt = sensorData != null ? (DepthSensorBase)sensorData.sensorInterface : null; } if (foregroundCamera == null) { foregroundCamera = Camera.main; } // find scene lights Light[] sceneLights = GameObject.FindObjectsOfType <Light>(); lighting.SetLightsAndBounds(sceneLights, transform.position, new Vector3(20f, 20f, 20f)); //Debug.Log("sceneLights: " + sceneLights.Length); //for(int i = 0; i < sceneLights.Length; i++) //{ // Debug.Log(i.ToString() + " - " + sceneLights[i].name + " - " + sceneLights[i].type); //} }
private void Init(ExpSettings.DATA_REQUESTED dataRequest = ExpSettings.DATA_REQUESTED.Body) //private void Init(bool UseDepth = false, bool UseSkeleton = true) { Initialized = false; ManagerGO = Instantiate(Resources.Load <GameObject>(KINECT_PREFAB), transform); ManagerGO.name = "KinectManager"; KManager = ManagerGO.GetComponent <KinectManager>(); Debug.Log("CVInterface: Init platform " + Application.platform + "/ data req = " + dataRequest); LastResquestedData = dataRequest; if (Application.platform == RuntimePlatform.WindowsEditor) { GameObject igo = Instantiate(Resources.Load <GameObject>(K2_INTERFACE_PREFAB), ManagerGO.transform); CurrentSensorInterface = igo.GetComponent <DepthSensorBase>(); } else if (Application.platform == RuntimePlatform.WindowsPlayer) { GameObject igo = Instantiate(Resources.Load <GameObject>(K2_INTERFACE_PREFAB), ManagerGO.transform); CurrentSensorInterface = igo.GetComponent <DepthSensorBase>(); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { GameObject igo = Instantiate(Resources.Load <GameObject>(ARKIT_INTERFACE_PREFAB), ManagerGO.transform); CurrentSensorInterface = igo.GetComponent <DepthSensorBase>(); } else { Debug.LogWarning("What platform ?!? = " + Application.platform); } if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; } else if (Application.platform == RuntimePlatform.IPhonePlayer) { ARKitInterface ark = CurrentSensorInterface as ARKitInterface; if (dataRequest == ExpSettings.DATA_REQUESTED.Body) { KManager.getDepthFrames = KinectManager.DepthTextureType.None; KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; } else if (dataRequest == ExpSettings.DATA_REQUESTED.Depth) { KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; KManager.getBodyFrames = KinectManager.BodyTextureType.None; ark.depthMode = com.rfilkov.kinect.ARKitInterface.ArKitDepthMode.EnvironmentDepth; } else if (dataRequest == ExpSettings.DATA_REQUESTED.Users) { KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; KManager.getBodyFrames = KinectManager.BodyTextureType.None; ark.depthMode = com.rfilkov.kinect.ARKitInterface.ArKitDepthMode.HumanDepth; } else { Debug.Log("Probleme avec dataRequest : " + dataRequest); } Debug.Log("arkit depth set to " + ark.depthMode); } /* * if (UseDepth && !UseSkeleton) * { * if (KManager.getDepthFrames != KinectManager.DepthTextureType.DepthTexture) * { * KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; * KManager.getBodyFrames = KinectManager.BodyTextureType.None; * } * } * else if (!UseDepth && UseSkeleton) * { * if (KManager.getBodyFrames != KinectManager.BodyTextureType.UserTexture) * { * KManager.getDepthFrames = KinectManager.DepthTextureType.None; * KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; * } * } * else * { * if (Application.platform == RuntimePlatform.IPhonePlayer) * { * KManager.getDepthFrames = KinectManager.DepthTextureType.None; * KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; * } * else * { * KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; * KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; * } * } */ /* * if( Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) * { * KManager.getDepthFrames = KinectManager.DepthTextureType.DepthTexture; * KManager.getBodyFrames = KinectManager.BodyTextureType.UserTexture; * } */ SetDebug(LastDebugValue); KManager.StartDepthSensors(); Initialized = true; }
// inits the mesh and related data private void InitMesh() { // create mesh mesh = new Mesh { name = "User" + playerIndex + "Mesh-S" + sensorIndex, indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; MeshFilter meshFilter = GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.mesh = mesh; } else { Debug.LogWarning("MeshFilter not found! You may not see the mesh on screen"); } // create depth image buffer if (depthImageBuffer == null) { int depthImageLength = sensorData.depthImageWidth * sensorData.depthImageHeight; depthImageCopy = new ushort[depthImageLength]; int depthBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 2; depthImageBuffer = KinectInterop.CreateComputeBuffer(depthImageBuffer, depthBufferLength, sizeof(uint)); //depthBufferCreated = true; } // create body index buffer if (bodyIndexBuffer == null) { int bodyIndexLength = sensorData.depthImageWidth * sensorData.depthImageHeight; bodyIndexCopy = new byte[bodyIndexLength]; int bodyIndexBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 4; bodyIndexBuffer = KinectInterop.CreateComputeBuffer(bodyIndexBuffer, bodyIndexBufferLength, sizeof(uint)); //bodyIndexBufferCreated = true; } // create point cloud color texture if (sensorData != null && sensorData.sensorInterface != null) { sensorInt = (DepthSensorBase)sensorData.sensorInterface; Vector2Int imageRes = Vector2Int.zero; if (sensorInt.pointCloudColorTexture == null) { sensorInt.pointCloudResolution = sourceImageResolution; imageRes = sensorInt.GetPointCloudTexResolution(sensorData); colorTexture = KinectInterop.CreateRenderTexture(colorTexture, imageRes.x, imageRes.y, RenderTextureFormat.ARGB32); sensorInt.pointCloudColorTexture = colorTexture; colorTextureCreated = true; } else { sourceImageResolution = sensorInt.pointCloudResolution; imageRes = sensorInt.GetPointCloudTexResolution(sensorData); colorTexture = sensorInt.pointCloudColorTexture; colorTextureCreated = false; } // create space table spaceTable = sensorInt.pointCloudResolution == DepthSensorBase.PointCloudResolution.DepthCameraResolution ? sensorInt.GetDepthCameraSpaceTable(sensorData) : sensorInt.GetColorCameraSpaceTable(sensorData); int spaceBufferLength = imageRes.x * imageRes.y * 3; spaceTableBuffer = new ComputeBuffer(spaceBufferLength, sizeof(float)); spaceTableBuffer.SetData(spaceTable); spaceTable = null; // create copy texture colorTextureCopy = KinectInterop.CreateRenderTexture(colorTextureCopy, imageRes.x, imageRes.y, RenderTextureFormat.ARGB32); // set the color texture Renderer meshRenderer = GetComponent <Renderer>(); if (meshRenderer && meshRenderer.material /**&& meshRenderer.material.mainTexture == null*/) { meshShaderMat = meshRenderer.material; } // get reference to the transform trans = GetComponent <Transform>(); // image width & height imageWidth = imageRes.x; imageHeight = imageRes.y; // create mesh vertices & indices CreateMeshVertInd(); bMeshInited = true; } }
// inits the mesh and related data private void InitMesh() { // create mesh mesh = new Mesh { name = "SceneMesh-Sensor" + sensorIndex, indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; MeshFilter meshFilter = GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.mesh = mesh; } else { Debug.LogWarning("MeshFilter not found! You may not see the mesh on screen"); } if (sensorData != null && sensorData.sensorInterface != null) { sensorInt = (DepthSensorBase)sensorData.sensorInterface; Vector2Int imageRes = Vector2Int.zero; if (sensorInt.pointCloudColorTexture == null) { sensorInt.pointCloudResolution = sourceImageResolution; imageRes = sensorInt.GetPointCloudTexResolution(sensorData); colorTexture = KinectInterop.CreateRenderTexture(colorTexture, imageRes.x, imageRes.y, RenderTextureFormat.ARGB32); sensorInt.pointCloudColorTexture = colorTexture; colorTextureCreated = true; } else { imageRes = sensorInt.GetPointCloudTexResolution(sensorData); colorTexture = sensorInt.pointCloudColorTexture; colorTextureCreated = false; } if (sensorInt.pointCloudResolution == DepthSensorBase.PointCloudResolution.ColorCameraResolution) { // enable transformed depth frame sensorData.sensorInterface.EnableColorCameraDepthFrame(sensorData, true); } // create copy texture colorTextureCopy = KinectInterop.CreateRenderTexture(colorTextureCopy, imageRes.x, imageRes.y, RenderTextureFormat.ARGB32); // set the color texture Renderer meshRenderer = GetComponent <Renderer>(); if (meshRenderer && meshRenderer.material && meshRenderer.material.mainTexture == null) { meshRenderer.material.mainTexture = colorTextureCopy; // sensorInt.pointCloudColorTexture; //meshRenderer.material.SetTextureScale("_MainTex", kinectManager.GetColorImageScale(sensorIndex)); } // image width & height imageWidth = imageRes.x; imageHeight = imageRes.y; int pointCount = imageWidth * imageHeight; // mesh arrays meshVertices = new Vector3[pointCount]; meshIndices = new int[6 * pointCount]; // 2 triangles per vertex, last row and column excluded meshVertUsed = new byte[pointCount]; spaceScale = kinectManager.GetSensorSpaceScale(sensorIndex); // create space table spaceTable = sensorInt.pointCloudResolution == DepthSensorBase.PointCloudResolution.DepthCameraResolution ? sensorInt.GetDepthCameraSpaceTable(sensorData) : sensorInt.GetColorCameraSpaceTable(sensorData); // init mesh uv array //spaceTable = new Vector3[pointCount]; Vector2[] meshUv = new Vector2[pointCount]; for (int y = 0, i = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++, i++) { Vector2 imagePos = new Vector2(x, y); //spaceTable[i] = sensorInt.MapDepthPointToSpaceCoords(sensorData, imagePos, 1000); //sourceImageResolution == DepthSensorBase.PointCloudResolution.ColorCameraResolution ? //sensorInt.MapColorPointToSpaceCoords(sensorData, imagePos, 1000) : //sensorInt.MapDepthPointToSpaceCoords(sensorData, imagePos, 1000); meshUv[i] = new Vector2(imagePos.x / imageWidth, imagePos.y / imageHeight); } } mesh.vertices = meshVertices; mesh.SetIndices(meshIndices, MeshTopology.Triangles, 0); mesh.uv = meshUv; if (showAsPointCloud) { meshIndices = new int[pointCount]; for (int i = 0; i < pointCount; i++) { meshIndices[i] = i; } mesh.SetIndices(meshIndices, MeshTopology.Points, 0); } bMeshInited = true; } }
// inits the mesh and related data private void InitMesh() { // create mesh mesh = new Mesh { name = "User" + playerIndex + "Mesh-S" + sensorIndex, indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 }; MeshFilter meshFilter = GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.mesh = mesh; } else { Debug.LogWarning("MeshFilter not found! You may not see the mesh on screen"); } // set the color texture Renderer meshRenderer = GetComponent <Renderer>(); if (meshRenderer && meshRenderer.material /**&& meshRenderer.material.mainTexture == null*/) { Shader meshShader = Shader.Find("Kinect/UserMeshUShader"); // Kinect/UserMeshVShader if (meshShader != null) { meshShaderMat = new Material(meshShader); meshRenderer.material = meshShaderMat; } } // get reference to the transform trans = GetComponent <Transform>(); // get sensor interface sensorInt = sensorData != null ? (DepthSensorBase)sensorData.sensorInterface : null; // create point cloud color texture if (sensorData != null && sensorInt != null && meshShaderMat != null) { Vector2Int imageRes = Vector2Int.zero; if (sensorInt.pointCloudColorTexture == null) { sensorInt.pointCloudResolution = sourceImageResolution; imageRes = sensorInt.GetPointCloudTexResolution(sensorData); //colorTexture = KinectInterop.CreateRenderTexture(colorTexture, imageRes.x, imageRes.y, RenderTextureFormat.ARGB32); //sensorInt.pointCloudColorTexture = colorTexture; colorTextureCreated = true; } else { sourceImageResolution = sensorInt.pointCloudResolution; imageRes = sensorInt.GetPointCloudTexResolution(sensorData); colorTexture = sensorInt.pointCloudColorTexture; colorTextureCreated = false; } // get space scale sensorSpaceScale = kinectManager.GetSensorSpaceScale(sensorIndex); // kinectManager.GetDepthImageScale(sensorIndex) // update textures and buffers UpdateTexturesAndBuffers(); bMeshInited = true; } }