forked from cgvr/DeltaVR
archery range glass display tank + wire
This commit is contained in:
@@ -12,8 +12,13 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
||||
public Texture2D GeneratedTexture { get; private set; }
|
||||
public Image imageDisplay;
|
||||
|
||||
public Transform modelSpawnPoint;
|
||||
public GameObject GeneratedModel { get; private set; }
|
||||
public float generatedObjectRotationSpeed = 10f;
|
||||
|
||||
public Transform modelDisplay;
|
||||
public Material modelDisplayActiveMaterial;
|
||||
public Transform wire;
|
||||
public Material wireActiveMaterial;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -25,7 +30,10 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (GeneratedModel != null)
|
||||
{
|
||||
GeneratedModel.transform.Rotate(Vector3.up, generatedObjectRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private async void InvokeImageGeneration()
|
||||
@@ -48,11 +56,13 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||
|
||||
GameObject spawnedObject = await PipelineManager.Instance.SpawnModel(encodedModel);
|
||||
spawnedObject.AddComponent<Rigidbody>();
|
||||
spawnedObject.transform.parent = modelSpawnPoint;
|
||||
spawnedObject.transform.position = modelSpawnPoint.position;
|
||||
// Destroy previous generated object
|
||||
Destroy(GeneratedModel);
|
||||
spawnedObject.transform.parent = modelDisplay;
|
||||
spawnedObject.transform.position = modelDisplay.position;
|
||||
GeneratedModel = spawnedObject;
|
||||
|
||||
OnModelReady();
|
||||
modelGenerationButton.MoveButtonUp();
|
||||
}
|
||||
|
||||
@@ -83,4 +93,14 @@ public class ArcheryRangeModelGenerationController : MonoBehaviour
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
private void OnModelReady()
|
||||
{
|
||||
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
meshRenderer.material = wireActiveMaterial;
|
||||
}
|
||||
|
||||
modelDisplay.GetComponent<MeshRenderer>().material = modelDisplayActiveMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
97
Assets/_PROJECT/Scripts/ModeGeneration/MicrophoneTesting.cs
Normal file
97
Assets/_PROJECT/Scripts/ModeGeneration/MicrophoneTesting.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class MicrophoneTesting : MonoBehaviour
|
||||
{
|
||||
[Header("Mic settings")]
|
||||
[Tooltip("Leave empty for default device")]
|
||||
public string deviceName = "";
|
||||
[Range(1, 60)] public int bufferLengthSec = 10; // rolling buffer for mic clip
|
||||
public int requestedSampleRate = 48000; // 48000 is best match for Quest & many headsets
|
||||
public bool playOnStart = true;
|
||||
|
||||
[Header("Runtime")]
|
||||
public bool isRecording;
|
||||
public bool isPlaying;
|
||||
|
||||
private AudioSource _src;
|
||||
private AudioClip _micClip;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_src = GetComponent<AudioSource>();
|
||||
_src.loop = true; // continuous playback
|
||||
_src.playOnAwake = false; // we will start manually
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (playOnStart)
|
||||
StartLoopback();
|
||||
}
|
||||
|
||||
public void StartLoopback()
|
||||
{
|
||||
if (isRecording) return;
|
||||
|
||||
// Pick default mic if none specified
|
||||
string dev = deviceName;
|
||||
if (string.IsNullOrEmpty(dev) && Microphone.devices.Length > 0)
|
||||
dev = Microphone.devices[0];
|
||||
|
||||
// Optionally query supported sample range
|
||||
Microphone.GetDeviceCaps(dev, out int minFreq, out int maxFreq);
|
||||
int sampleRate = requestedSampleRate;
|
||||
if (minFreq != 0 && maxFreq != 0)
|
||||
{
|
||||
// Clamp to supported range
|
||||
sampleRate = Mathf.Clamp(requestedSampleRate, minFreq, maxFreq);
|
||||
}
|
||||
|
||||
// Start recording into an AudioClip Unity manages
|
||||
_micClip = Microphone.Start(dev, true, bufferLengthSec, sampleRate);
|
||||
isRecording = true;
|
||||
|
||||
Debug.Log("Recording started. device name:");
|
||||
Debug.Log(Microphone.GetPosition(deviceName));
|
||||
|
||||
// Wait until the mic has written at least one sample
|
||||
StartCoroutine(PlayWhenReady());
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator PlayWhenReady()
|
||||
{
|
||||
// Ensure mic buffer has started writing
|
||||
Debug.Log("device name: " + deviceName);
|
||||
while (Microphone.GetPosition(deviceName) <= 0)
|
||||
{
|
||||
Debug.Log("Stuck in enumerator");
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_src.clip = _micClip;
|
||||
Debug.Log("Playing clip " + _src.clip);
|
||||
_src.Play();
|
||||
isPlaying = true;
|
||||
}
|
||||
|
||||
public void StopLoopback()
|
||||
{
|
||||
if (!isRecording) return;
|
||||
|
||||
_src.Stop();
|
||||
if (_micClip != null)
|
||||
{
|
||||
Microphone.End(null); // stop default device
|
||||
_micClip = null;
|
||||
}
|
||||
isPlaying = false;
|
||||
isRecording = false;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
StopLoopback();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0e7aa48ae4094e45b6f427987c2fc93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user