Handmenu: make Screenshot without rendering hands + smartphone; fix positioning

programming
Nadine Ganz 2025-02-11 11:57:17 +01:00
parent 3bec521669
commit c55e456702
3 changed files with 73 additions and 44 deletions

View File

@ -872,13 +872,13 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1053014236144696775} m_GameObject: {fileID: 1053014236144696775}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0.7071065, y: -0, z: -0, w: 0.7071071} m_LocalRotation: {x: -0, y: -0.7071068, z: -0.7071068, w: 0}
m_LocalPosition: {x: 0, y: 0.0123, z: 0.0493} m_LocalPosition: {x: 0, y: 0.0123, z: 0.04929924}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 5063272971443299340} m_Father: {fileID: 1996412656006795194}
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: -90, y: 0, z: -180}
--- !u!20 &7001199050030130134 --- !u!20 &7001199050030130134
Camera: Camera:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1619,9 +1619,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 107801045539344950} - {fileID: 1996412656006795194}
- {fileID: 6202651521140937909}
- {fileID: 7824485373208701159}
m_Father: {fileID: 5630431603393244975} m_Father: {fileID: 5630431603393244975}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1897047047148633122 --- !u!1 &1897047047148633122
@ -2823,6 +2821,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_previewImg: {fileID: 437821110515054555} _previewImg: {fileID: 437821110515054555}
_capturecam: {fileID: 7001199050030130134}
--- !u!1 &3665889797944952490 --- !u!1 &3665889797944952490
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4607,14 +4606,14 @@ RectTransform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5117592593628755675} m_GameObject: {fileID: 5117592593628755675}
m_LocalRotation: {x: 0, y: 0.70710677, z: 0.70710677, w: 0} m_LocalRotation: {x: -0, y: 0.7071068, z: 0.7071068, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.15144438, y: 0.17863165, z: 0.571365} m_LocalScale: {x: 0.15144433, y: 0.17863162, z: 0.5713649}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 7413929428606852214} - {fileID: 7413929428606852214}
- {fileID: 1816826061814438359} - {fileID: 1816826061814438359}
m_Father: {fileID: 5063272971443299340} m_Father: {fileID: 1996412656006795194}
m_LocalEulerAnglesHint: {x: -90, y: 90, z: 90} m_LocalEulerAnglesHint: {x: -90, y: 90, z: 90}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
@ -5008,6 +5007,40 @@ MonoBehaviour:
m_Interactions: m_Interactions:
m_SingletonActionBindings: [] m_SingletonActionBindings: []
m_Flags: 0 m_Flags: 0
--- !u!1 &5547875041402855972
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1996412656006795194}
m_Layer: 9
m_Name: SmartphoneParent
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1996412656006795194
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5547875041402855972}
serializedVersion: 2
m_LocalRotation: {x: -0.15405792, y: 0.17151026, z: 0.027164565, w: 0.9726832}
m_LocalPosition: {x: -0.02, y: -0.03, z: 0.02}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 107801045539344950}
- {fileID: 6202651521140937909}
- {fileID: 7824485373208701159}
m_Father: {fileID: 5063272971443299340}
m_LocalEulerAnglesHint: {x: -18, y: 20, z: 0}
--- !u!1 &5702985173780472227 --- !u!1 &5702985173780472227
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -6134,7 +6167,7 @@ PrefabInstance:
serializedVersion: 2 serializedVersion: 2
m_Modification: m_Modification:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 5063272971443299340} m_TransformParent: {fileID: 1996412656006795194}
m_Modifications: m_Modifications:
- target: {fileID: 152089758756199514, guid: fd16c97ca719775409e646d3ee101b19, type: 3} - target: {fileID: 152089758756199514, guid: fd16c97ca719775409e646d3ee101b19, type: 3}
propertyPath: m_Layer propertyPath: m_Layer

View File

@ -3,27 +3,24 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System; using System;
using UnityEngine.UI; using UnityEngine.UI;
using Oculus.Platform;
public class Screenshot : MonoBehaviour public class Screenshot : MonoBehaviour
{ {
[SerializeField] [SerializeField]
RawImage _previewImg; RawImage _previewImg;
GameObject XRCamera; //the XR Player Camera, named "Main Camera" [SerializeField]
GameObject XRHoloVideoCamera; //the XR Player Camera, named "Main Camera no-post-processing" Camera _capturecam;
GameObject SmartphoneCaptureCamera; //the GameObject, named "SmartphoneCaptureCamera" is a Camera with a CullingMask where the Layer "hands" is excluded ("_HANDMENU" and "XR Interactions Hands Setup" are on the "hands" layer)
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
//StartCoroutine(TakeScreenshot());
/* if (Input.GetKeyDown(KeyCode.P)) /* if (Input.GetKeyDown(KeyCode.P))
{ {
StartCoroutine(TakeScreenshot()); CreatePreview();
} }*/
*/
} }
public void OnClickTakeScreenshot() public void OnClickTakeScreenshot()
@ -33,7 +30,7 @@ public class Screenshot : MonoBehaviour
public void OnClickPreview() public void OnClickPreview()
{ {
StartCoroutine(CreatePreview()); CreatePreview();
} }
public void DestroyPreviewTexture() public void DestroyPreviewTexture()
@ -51,31 +48,27 @@ public class Screenshot : MonoBehaviour
ScreenCapture.CaptureScreenshot("snapshot_" + timpStamp + ".png"); ScreenCapture.CaptureScreenshot("snapshot_" + timpStamp + ".png");
} }
IEnumerator CreatePreview() void CreatePreview()
{ {
yield return new WaitForEndOfFrame();
// find all Cameras: _capturecam.enabled = true;
XRCamera = GameObject.Find("Main Camera"); RenderTexture screenTexture = new RenderTexture(Screen.width, Screen.height, 16);
XRHoloVideoCamera = GameObject.Find("Main Camera no-post-processing"); _capturecam.targetTexture = screenTexture;
SmartphoneCaptureCamera = GameObject.Find("SmartphoneCaptureCamera"); RenderTexture.active = screenTexture;
_capturecam.Render();
// get the Camera components: Texture2D renderedTexture = new Texture2D(Screen.width, Screen.height);
Camera vrcam = XRCamera.GetComponent<Camera>(); renderedTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
Camera vrcamnopost = XRHoloVideoCamera.GetComponent<Camera>(); renderedTexture.Apply();
Camera capturecam = SmartphoneCaptureCamera.GetComponent<Camera>();
// switch active Cameras RenderTexture.active = null;
vrcam.enabled = false; _capturecam.enabled = false;
vrcamnopost.enabled = false;
capturecam.enabled = true;
// call the function to take actual screenshot _previewImg.texture = renderedTexture;
_previewImg.texture = ScreenCapture.CaptureScreenshotAsTexture();
// switch active Cameras back // Save texture in png file
vrcam.enabled = true; byte[] byteArray = renderedTexture.EncodeToPNG();
vrcamnopost.enabled = true; string timpStamp = DateTime.Now.ToString("ddMMyyyyHHmmssffff");
capturecam.enabled = false; System.IO.File.WriteAllBytes(Application.persistentDataPath + $"/snapshot_{timpStamp}.png", byteArray);
} }
} }

View File

@ -140,6 +140,9 @@ PlayerSettings:
bundleVersion: 0.1 bundleVersion: 0.1
preloadedAssets: preloadedAssets:
- {fileID: 11400000, guid: be340e3c48769439d8d18a5a2bccd498, type: 2} - {fileID: 11400000, guid: be340e3c48769439d8d18a5a2bccd498, type: 2}
- {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2}
- {fileID: -8196854396901781169, guid: 1a4c68ca72a83449f938d669337cb305, type: 2}
- {fileID: 7708199778347151547, guid: 0f4832b23b368b643bc8a91696fbb473, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1