SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void Awake()
  2.     {
  3.  
  4.         var lel = Gizmos.matrix;
  5.         var lol = Matrix4x4.Scale(Vector3.one * 10);
  6.         lul = lel * lol;
  7.  
  8.         _sensor = KinectSensor.GetDefault();
  9.  
  10.         if (_sensor != null)
  11.         {
  12.             _bodySource = _sensor.BodyFrameSource;
  13.             _bodyReader = _bodySource.OpenReader();
  14.             _bodyReader.FrameArrived += BodyReader_FrameArrived;
  15.  
  16.             _faceSource = HighDefinitionFaceFrameSource.Create(_sensor);
  17.  
  18.             _faceReader = _faceSource.OpenReader();
  19.             _faceReader.FrameArrived += FaceReader_FrameArrived;
  20.  
  21.             _faceModel = FaceModel.Create();
  22.             _faceAlignment = FaceAlignment.Create();
  23.  
  24.             _sensor.Open();
  25.         }
  26.     }
  27.     private void Start()
  28.     {
  29.         if (_faceModel == null) return;
  30.  
  31.         IList<CameraSpacePoint> vertices = _faceModel.CalculateVerticesForAlignment(_faceAlignment);
  32.  
  33.         _points = vertices.Select(point => new Vector3(point.X, point.Y, point.Z)).ToList();
  34.     }
  35.  
  36.     private void Update()
  37.     {
  38.         if (_faceModel == null) return;
  39.  
  40.         _points = _faceModel.CalculateVerticesForAlignment(_faceAlignment).Select(point => new Vector3(point.X, point.Y, point.Z)).ToList();
  41.  
  42.     private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
  43.     {
  44.         using (var frame = e.FrameReference.AcquireFrame())
  45.         {
  46.             if (frame != null)
  47.             {
  48.                 Body[] bodies = new Body[frame.BodyCount];
  49.                 frame.GetAndRefreshBodyData(bodies);
  50.  
  51.                 Body body = bodies.Where(b => b.IsTracked).FirstOrDefault();
  52.  
  53.                 if (!_faceSource.IsTrackingIdValid)
  54.                 {
  55.                     if (body != null)
  56.                     {
  57.                         _faceSource.TrackingId = body.TrackingId;
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63.  
  64.     private void FaceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
  65.     {
  66.         using (var frame = e.FrameReference.AcquireFrame())
  67.         {
  68.             if (frame != null && frame.IsFaceTracked)
  69.             {
  70.                 frame.GetAndRefreshFaceAlignmentResult(_faceAlignment);
  71.                 Update();
  72.             }
  73.         }
  74.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top