1
0
forked from cgvr/DeltaVR

implemented shape scanner

This commit is contained in:
2026-01-11 17:48:58 +02:00
parent 23c89e97ce
commit d2ac917db3
16 changed files with 1027 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af360726de5c7f44bb1ea9ce40becf9c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -29,6 +29,7 @@ public class MicrophoneStand : MonoBehaviour
stream = await whisper.CreateStream(microphoneRecord);
stream.OnResultUpdated += OnWhisperResult;
//stream.StartStream();
microphoneOffStatus.SetActive(true);
microphoneOnStatus.SetActive(false);
@@ -51,6 +52,7 @@ public class MicrophoneStand : MonoBehaviour
microphoneOnStatus.SetActive(true);
stream.StartStream();
//microphoneRecord.StartRecord();
Debug.Log("Whisper stream started.");
}
}
@@ -64,6 +66,7 @@ public class MicrophoneStand : MonoBehaviour
microphoneOnStatus.SetActive(false);
stream.StopStream();
//microphoneRecord.StopRecord();
textOutput = outputText.text;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 32cc0ecba4f62654583aca9fbc246706
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
[System.Serializable]
public class BoolRow
{
public bool[] cells;
}
public class ShapeScanner : MonoBehaviour
{
public List<BoolRow> configuration;
public ShapeScannerRay rayPrefab;
public Transform raySpawnCorner1;
public Transform raySpawnCorner2;
public Transform rayParent;
public Material requiredAndActive;
public Material requiredAndPassive;
public Material notRequiredAndActive;
public Material notRequiredAndPassive;
public TextMeshProUGUI displayText;
private int rayCount;
private int correctRayStates;
private void Awake()
{
correctRayStates = 0;
}
// Start is called before the first frame update
void Start()
{
float raySpawnDistanceX = raySpawnCorner2.localPosition.x - raySpawnCorner1.localPosition.x;
float raySpawnDistanceZ = raySpawnCorner2.localPosition.z - raySpawnCorner1.localPosition.z;
int rayRowCount = configuration.Count;
for (int i = 0; i < rayRowCount; i++)
{
float rayPosX = raySpawnCorner1.localPosition.x + i * raySpawnDistanceX / (rayRowCount - 1);
for (int j = 0; j < rayRowCount; j++)
{
rayCount++;
// Local position
float rayPosZ = raySpawnCorner1.localPosition.z + j * raySpawnDistanceZ / (rayRowCount - 1);
Vector3 rayPos = new Vector3(rayPosX, 0, rayPosZ);
ShapeScannerRay ray = Instantiate(rayPrefab, rayParent);
ray.transform.localPosition = rayPos;
bool rayCollisionRequired = configuration[i].cells[j];
if (rayCollisionRequired)
{
ray.Initialize(this, rayCollisionRequired, requiredAndActive, requiredAndPassive);
} else
{
ray.Initialize(this, rayCollisionRequired, notRequiredAndActive, notRequiredAndPassive);
IncrementCorrectRayCount();
}
}
}
}
// Update is called once per frame
void Update()
{
}
public void IncrementCorrectRayCount()
{
correctRayStates++;
UpdateDisplay();
}
public void DecrementCorrectRayCount()
{
correctRayStates--;
UpdateDisplay();
}
private void UpdateDisplay()
{
int percentage = Mathf.RoundToInt((float) correctRayStates / rayCount * 100);
displayText.text = percentage.ToString() + " %";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b2226de466bbe814d8bfe0cb0fce83f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShapeScannerRay : MonoBehaviour
{
public Material _activeMaterial;
public Material _passiveMaterial;
private ShapeScanner _scanner;
private MeshRenderer meshRenderer;
private bool _collisionRequired;
void Awake()
{
meshRenderer = GetComponent<MeshRenderer>();
}
// Update is called once per frame
void Update()
{
}
public void Initialize(ShapeScanner scanner, bool collisionRequired, Material activeMaterial, Material passiveMaterial)
{
_scanner = scanner;
_collisionRequired = collisionRequired;
_activeMaterial = activeMaterial;
_passiveMaterial = passiveMaterial;
meshRenderer.material = _passiveMaterial;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "ShapeScannable")
{
meshRenderer.material = _activeMaterial;
if (_collisionRequired)
{
_scanner.IncrementCorrectRayCount();
} else
{
_scanner.DecrementCorrectRayCount();
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "ShapeScannable")
{
meshRenderer.material = _passiveMaterial;
if (_collisionRequired)
{
_scanner.DecrementCorrectRayCount();
} else
{
_scanner.IncrementCorrectRayCount();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: db942dc95bda5a149b7e9358de43a923
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: