1
0
forked from cgvr/DeltaVR

fix shapescanner incorrect ray counting and make asynchronous

This commit is contained in:
2026-03-16 11:28:58 +02:00
parent 717964affd
commit db60947749
6 changed files with 42 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
### TODO ### TODO
* teha build kus archery range'is spawnitud objektid * teha build kus archery range'is spawnitud objektid
* FMOD ChannelControl errorid * FMOD ChannelControl errorid
* glTF-StableFramerate, Parent-GeneratedModel eemaldada?
* speech-to-text: * speech-to-text:
* uurida miks buildis Whisper halvemini töötab * uurida miks buildis Whisper halvemini töötab
* proovida suuremat Whisperi mudelit, äkki töötab mürases keskkonnas paremini * proovida suuremat Whisperi mudelit, äkki töötab mürases keskkonnas paremini

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit; using UnityEngine.XR.Interaction.Toolkit;
@@ -99,13 +99,7 @@ public class ShapeScanner : MonoBehaviour
private void InitializeConfiguration(ShapeScannerConfiguration configuration) private void InitializeConfiguration(ShapeScannerConfiguration configuration)
{ {
// Recreate all existing rays // Create rays
foreach (ShapeScannerRay ray in existingRays)
{
Destroy(ray.gameObject);
}
existingRays.Clear();
int rayRowCount = configuration.rows.Count; int rayRowCount = configuration.rows.Count;
for (int i = 0; i < rayRowCount; i++) for (int i = 0; i < rayRowCount; i++)
{ {
@@ -133,13 +127,14 @@ public class ShapeScanner : MonoBehaviour
totalRayCount = configuration.rows.SelectMany(row => row.cells).Count(); totalRayCount = configuration.rows.SelectMany(row => row.cells).Count();
correctRayCount = configuration.rows.SelectMany(row => row.cells).Count(cell => !cell); correctRayCount = configuration.rows.SelectMany(row => row.cells).Count(cell => !cell);
float percentage = calculateCorrectPercentage(); float percentage = CalculateCorrectPercentage();
UpdateDisplay(percentage); UpdateDisplay(percentage);
} }
private void OnConfigurationComplete() private void OnConfigurationComplete()
{ {
HashSet<GameObject> allCollidingObjects = new HashSet<GameObject>(); // Destroy colliding scannable objects
HashSet<GameObject> allCollidingObjects = new();
foreach (ShapeScannerRay ray in existingRays) foreach (ShapeScannerRay ray in existingRays)
{ {
allCollidingObjects.UnionWith(ray.GetCollidingObjects()); allCollidingObjects.UnionWith(ray.GetCollidingObjects());
@@ -161,20 +156,28 @@ public class ShapeScanner : MonoBehaviour
Destroy(collidingObject); Destroy(collidingObject);
} }
// Destroy all existing rays
foreach (ShapeScannerRay ray in existingRays)
{
Destroy(ray.gameObject);
}
existingRays.Clear();
// Play sound effect and emit particles
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject); AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
if (!particles.isPlaying) particles.Play(); if (!particles.isPlaying) particles.Play();
particles.Emit(100); particles.Emit(100);
} }
private float calculateCorrectPercentage() private float CalculateCorrectPercentage()
{ {
return (float) correctRayCount / totalRayCount * 100; return (float) correctRayCount / totalRayCount * 100;
} }
public void IncrementCorrectRayCount() public async void IncrementCorrectRayCount()
{ {
correctRayCount++; correctRayCount++;
float correctPercentage = calculateCorrectPercentage(); float correctPercentage = CalculateCorrectPercentage();
UpdateDisplay(correctPercentage); UpdateDisplay(correctPercentage);
if (isCompleted) if (isCompleted)
{ {
@@ -183,6 +186,8 @@ public class ShapeScanner : MonoBehaviour
if (correctPercentage >= configurations[currentConfiguration].requiredCorrectPercentage) if (correctPercentage >= configurations[currentConfiguration].requiredCorrectPercentage)
{ {
OnConfigurationComplete(); OnConfigurationComplete();
await Task.Delay(1000);
UpdateCurrentConfigurationDisplay(currentConfiguration + 1); UpdateCurrentConfigurationDisplay(currentConfiguration + 1);
if (currentConfiguration + 1 < configurations.Count) if (currentConfiguration + 1 < configurations.Count)
{ {
@@ -202,12 +207,11 @@ public class ShapeScanner : MonoBehaviour
public void DecrementCorrectRayCount() public void DecrementCorrectRayCount()
{ {
correctRayCount--; correctRayCount--;
UpdateDisplay(calculateCorrectPercentage()); UpdateDisplay(CalculateCorrectPercentage());
} }
private void UpdateDisplay(float percentage) private void UpdateDisplay(float percentage)
{ {
Debug.Log("updating display to: " + percentage);
correctPercentageDisplay.text = Mathf.Round(percentage).ToString() + " %"; correctPercentageDisplay.text = Mathf.Round(percentage).ToString() + " %";
} }

View File

@@ -4,6 +4,10 @@
"name": "Perfoon", "name": "Perfoon",
"score": 416.0 "score": 416.0
}, },
{
"name": "jjkujkkg",
"score": 194.0
},
{ {
"name": "h", "name": "h",
"score": 138.0 "score": 138.0
@@ -11,6 +15,18 @@
{ {
"name": "raimps", "name": "raimps",
"score": 115.0 "score": 115.0
},
{
"name": "k",
"score": 58.0
},
{
"name": "kr",
"score": 53.0
},
{
"name": "krr",
"score": 34.0
} }
] ]
} }