Update WallArt.cs

pull/2/head
marcgauch 2023-12-14 19:58:00 +01:00
parent e06f0890dc
commit b774e84175
1 changed files with 25 additions and 15 deletions

View File

@ -1,15 +1,13 @@
using System.Collections; using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
public class WallArt : MonoBehaviour public class WallArt : MonoBehaviour
{ {
GameObject capsule;
public GameObject outsideCameraPrefab; public GameObject outsideCameraPrefab;
private Camera outsideCameraInstance; private Camera outsideCameraInstance;
public MeshRenderer meshRenderer; public MeshRenderer meshRenderer;
private OVRCameraRig ovrCameraRig;
private RenderTexture renderTexture; private RenderTexture renderTexture;
private Material material; private Material material;
@ -17,11 +15,9 @@ public class WallArt : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
var randomNumber = Random.Range(10000, 99999); var randomNumber = Random.Range(10000, 99999);
Log($"{randomNumber}-start"); Log($"{randomNumber}-start");
renderTexture = new RenderTexture(256, 256, 0) renderTexture = new RenderTexture(256, 256, 0)
{ {
dimension = UnityEngine.Rendering.TextureDimension.Tex2D, dimension = UnityEngine.Rendering.TextureDimension.Tex2D,
@ -33,10 +29,13 @@ public class WallArt : MonoBehaviour
depthStencilFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.D24_UNorm_S8_UInt, depthStencilFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.D24_UNorm_S8_UInt,
}; };
Log($"{randomNumber}-1"); Log($"{randomNumber}-1");
GameObject camera = Instantiate(outsideCameraPrefab, transform.position, Quaternion.identity); GameObject camera = Instantiate(outsideCameraPrefab, transform.position, Quaternion.identity);
Log($"{randomNumber}-1.1"); Log($"{randomNumber}-1.1");
outsideCameraInstance = camera.GetComponent<Camera>(); outsideCameraInstance = camera.GetComponent<Camera>();
Log($"{randomNumber}-2"); Log($"{randomNumber}-2");
try try
{ {
// Attempt to set the target texture // Attempt to set the target texture
@ -48,32 +47,44 @@ public class WallArt : MonoBehaviour
Debug.LogError("An error occurred: " + e.Message); Debug.LogError("An error occurred: " + e.Message);
} }
Log($"{randomNumber}-3"); Log($"{randomNumber}-3");
// Set the initial rotation of the camera
outsideCameraInstance.transform.rotation = Quaternion.Euler( outsideCameraInstance.transform.rotation = Quaternion.Euler(
Random.Range(0f, 360f), // Random rotation around X-axis Random.Range(0f, 360f),
Random.Range(0f, 360f), // Random rotation around Y-axis Random.Range(0f, 360f),
Random.Range(0f, 360f) // Random rotation around Z-axis Random.Range(0f, 360f)
); );
Log($"{randomNumber}-4"); Log($"{randomNumber}-4");
material = new Material(Shader.Find("Standard")); material = new Material(Shader.Find("Standard"));
Log($"{randomNumber}-5"); Log($"{randomNumber}-5");
material.mainTexture = renderTexture; material.mainTexture = renderTexture;
Log($"{randomNumber}-6"); Log($"{randomNumber}-6");
meshRenderer.material = material; meshRenderer.material = material;
// capsule.transform.rotation = Quaternion.Euler(
// Random.Range(0f, 360f), // Random rotation around X-axis
// Random.Range(0f, 360f), // Random rotation around Y-axis
// Random.Range(0f, 360f) // Random rotation around Z-axis
// );
Log($"{randomNumber}-7"); Log($"{randomNumber}-7");
ovrCameraRig = FindObjectOfType<OVRCameraRig>();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
// Check if the cameraRig is assigned
if (ovrCameraRig == null) return;
// Get the CenterEyeAnchor position
Vector3 centerEyePosition = ovrCameraRig.centerEyeAnchor.position;
//Vector3 centerEyePosition = new Vector3();
// Update the position of the object based on the CenterEyeAnchor position with an added offset to the y-axis
outsideCameraInstance.transform.position = new Vector3(centerEyePosition.x, centerEyePosition.y + 100f, centerEyePosition.z);
// Remove rotation around the z-axis
Vector3 eulerRotation = ovrCameraRig.centerEyeAnchor.rotation.eulerAngles;
//Vector3 eulerRotation = Vector3.right;
outsideCameraInstance.transform.rotation = Quaternion.Euler(eulerRotation.x, eulerRotation.y, 0f);
} }
private void Log(string message) private void Log(string message)
{ {
StartCoroutine(MakeGetRequest($"https://log.m-g.tech/?message={message}")); StartCoroutine(MakeGetRequest($"https://log.m-g.tech/?message={message}"));
@ -99,5 +110,4 @@ public class WallArt : MonoBehaviour
} }
} }
} }
} }