Advertisement
Guest User

code

a guest
Dec 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. public void CapturePhotoAsync (OnCaptured callback) {
  2.  
  3. _callback = callback;
  4.  
  5.  
  6.  
  7. PhotoCapture.CreateAsync(showHolograms, (_photoCapture) => {
  8.  
  9. this.photoCaptureObject = _photoCapture;
  10.  
  11. Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
  12.  
  13. //1280x720
  14.  
  15. targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
  16.  
  17. cameraParameters = new CameraParameters();
  18.  
  19. cameraParameters.hologramOpacity = 0.0f;
  20.  
  21. cameraParameters.cameraResolutionWidth = cameraResolution.width;
  22.  
  23. cameraParameters.cameraResolutionHeight = cameraResolution.height;
  24.  
  25. cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
  26.  
  27.  
  28.  
  29. //Activate the camera
  30.  
  31. photoCaptureObject.StartPhotoModeAsync(cameraParameters, onPhotoModeStarted);
  32.  
  33. });
  34.  
  35. }
  36.  
  37. void onPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
  38.  
  39. {
  40.  
  41. if (result.success)
  42.  
  43. {
  44.  
  45. //Take Picture
  46.  
  47. Debug.Log("Taking Foto...");
  48.  
  49. //photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
  50.  
  51. photoCaptureObject.TakePhotoAsync(putPhotoOnObject); //I want to put it on a quad
  52.  
  53. }
  54.  
  55. else
  56.  
  57. {
  58.  
  59. Debug.Log("Unable to start photo mode");
  60.  
  61. }
  62.  
  63. }
  64.  
  65. void putPhotoOnObject(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
  66.  
  67. {
  68.  
  69. if (!result.success)
  70.  
  71. {
  72.  
  73. Debug.LogError("Error CapturedPhotoToMemory");
  74.  
  75. return;
  76.  
  77. }
  78.  
  79. //Copy image data into the target texture
  80.  
  81. Debug.Log("Image to Texture");
  82.  
  83. photoCaptureFrame.UploadImageDataToTexture(targetTexture);
  84.  
  85.  
  86.  
  87. //Create GameObject
  88.  
  89. Debug.Log("Create GameObhect");
  90.  
  91. GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
  92.  
  93. Renderer quadRenderer = quad.GetComponent<Renderer>() as Renderer;
  94.  
  95. //quadRenderer.material = new Material(Shader.Find("Transparent/Diffuse"));
  96.  
  97. quadRenderer.material.color = Color.white;
  98.  
  99.  
  100.  
  101. quad.transform.parent = this.transform;
  102.  
  103. quad.transform.localPosition = new Vector3(3.0f, 0.0f, 0.0f);
  104.  
  105. quad.AddComponent<Billboard>();
  106.  
  107.  
  108.  
  109. quadRenderer.material.SetTexture("_MainTex", targetTexture);
  110.  
  111. Debug.Log("Object should exist");
  112.  
  113. photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement