diff --git a/Assets/_PROJECT/Prefabs/ModelGeneration/Printable.prefab b/Assets/_PROJECT/Prefabs/ModelGeneration/Printable.prefab index 4c1fb94c..e895a356 100644 --- a/Assets/_PROJECT/Prefabs/ModelGeneration/Printable.prefab +++ b/Assets/_PROJECT/Prefabs/ModelGeneration/Printable.prefab @@ -87,6 +87,7 @@ GameObject: - component: {fileID: 3870989277732630730} - component: {fileID: 7594134409976187304} - component: {fileID: 1297641575955202044} + - component: {fileID: 6521999952126795650} m_Layer: 0 m_Name: Printable m_TagString: Untagged @@ -274,6 +275,18 @@ MonoBehaviour: m_StartingSingleGrabTransformers: [] m_StartingMultipleGrabTransformers: [] m_AddDefaultGrabTransformers: 1 +--- !u!114 &6521999952126795650 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1729028776279376009} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bb8ba6b5820955f4a95511b55c3a8db9, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &6791306317367082968 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/_PROJECT/Scenes/DeltaBuilding_base.unity b/Assets/_PROJECT/Scenes/DeltaBuilding_base.unity index 82bf5d3d..0771007a 100644 --- a/Assets/_PROJECT/Scenes/DeltaBuilding_base.unity +++ b/Assets/_PROJECT/Scenes/DeltaBuilding_base.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a090248a6b340a1953bacc4babafc1c4768cddca8fd5e679200df0fd31a8bbad -size 68539384 +oid sha256:6228744224992c84fc1a6de12e9565de32617c947d58b7e1ab7f0456d12b75fe +size 68556404 diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/NPCController.cs b/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/NPCController.cs index f1712fea..afc38ead 100644 --- a/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/NPCController.cs +++ b/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/NPCController.cs @@ -102,7 +102,6 @@ public abstract class NPCController : MonoBehaviour // apply mouth scale Vector3 s = mouth.localScale; s.y = smoothed; - Debug.Log("mouth scale: " + smoothed); mouth.localScale = s; } @@ -118,7 +117,6 @@ public abstract class NPCController : MonoBehaviour scale.y = smoothed; mouth.localScale = scale; } - Debug.Log("mouth scale stopped: " + smoothed); currentVoicelineEvent.release(); } @@ -193,7 +191,6 @@ public abstract class NPCController : MonoBehaviour } var lines = File.ReadAllLines(filePath); - Debug.Log("read lines: " + lines.Length); rmsCurve = lines.Select(l => float.Parse(l, System.Globalization.CultureInfo.InvariantCulture)).ToArray(); } } diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/ShapeDetectionNPC.cs b/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/ShapeDetectionNPC.cs index d082f19d..e31db2bc 100644 --- a/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/ShapeDetectionNPC.cs +++ b/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/ShapeDetectionNPC.cs @@ -15,11 +15,7 @@ public class ShapeDetectionNPC : NPCController public Image imageDisplay; public ShapeScanner shapeScanner; public float radioAmount = 1f; - - public GameObject GeneratedModel { get; private set; } - public Transform modelSpawnPoint; - public string shapeScannerTag = "ShapeScannable"; - public int ignorePlayerCollisionLayer = 2; + // states: // 0 - idle @@ -144,14 +140,8 @@ public class ShapeDetectionNPC : NPCController byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture); GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel); - InitializeSpawnedObject(spawnedObject); - if (GeneratedModel != null) - { - // Destroy previous generated object (first move out of ShapeScanner to trigger OnTriggerExit - GeneratedModel.transform.position = Vector3.zero; - } - GeneratedModel = spawnedObject; + modelGenerationButton.Deactivate(); if (state == 5) @@ -160,25 +150,5 @@ public class ShapeDetectionNPC : NPCController } } - private void InitializeSpawnedObject(GameObject spawnedObject) - { - GameObject spawnedObjectParent = new GameObject("SpawnedModelParent"); - spawnedObjectParent.transform.parent = modelSpawnPoint; - spawnedObjectParent.transform.position = modelSpawnPoint.transform.position; - spawnedObjectParent.layer = ignorePlayerCollisionLayer; - Rigidbody rigidbody = spawnedObjectParent.AddComponent(); - rigidbody.isKinematic = true; - - //spawnedObject.AddComponent(); - //spawnedObject.AddComponent(); - - MeshCollider spawnedObjectCollider = spawnedObject.GetComponent(); - spawnedObjectCollider.convex = false; - spawnedObject.transform.parent = spawnedObjectParent.transform; - spawnedObject.transform.position = spawnedObjectParent.transform.position; - spawnedObject.tag = shapeScannerTag; - spawnedObject.layer = ignorePlayerCollisionLayer; - - spawnedObjectParent.AddComponent(); - } + } diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/ComputerPrinter.cs b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/ComputerPrinter.cs index 3062bd93..875a6bdc 100644 --- a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/ComputerPrinter.cs +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/ComputerPrinter.cs @@ -1,7 +1,6 @@ using DG.Tweening; using TMPro; using UnityEngine; -using UnityEngine.UI; public class ComputerPrinter : MonoBehaviour { @@ -9,8 +8,9 @@ public class ComputerPrinter : MonoBehaviour public PushableButton enterKey; public Transform ejectionOrigin; public Transform ejectionDestination; - public GameObject printablePrefab; + public Printable printablePrefab; public float ejectionDuration = 1.0f; + public int ignorePlayerCollisionLayer = 2; // Start is called before the first frame update void Start() @@ -29,11 +29,14 @@ public class ComputerPrinter : MonoBehaviour string inputPrompt = textDisplay.text; byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt); Texture2D generatedTexture = ModelGenerationUtils.CreateTexture(imageBytes); - Sprite sprite = ModelGenerationUtils.CreateSprite(generatedTexture); - - GameObject printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity); - Image printableDisplay = printable.GetComponentInChildren(); - printableDisplay.sprite = sprite; + + Printable printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity); + printable.AttachTexture(generatedTexture); + printable.gameObject.layer = ignorePlayerCollisionLayer; + foreach (Transform childTrans in printable.transform.GetComponentInChildren()) + { + childTrans.gameObject.layer = ignorePlayerCollisionLayer; + } printable.transform.DOMove(ejectionDestination.position, ejectionDuration).OnComplete(() => { diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs new file mode 100644 index 00000000..84b30f33 --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class Printable : MonoBehaviour +{ + private Texture2D attachedTexture; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + public Texture2D GetTexture() + { + return attachedTexture; + } + + public void AttachTexture(Texture2D texture) + { + Sprite sprite = ModelGenerationUtils.CreateSprite(texture); + Image imageDisplay = GetComponentInChildren(); + imageDisplay.sprite = sprite; + attachedTexture = texture; + } +} diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs.meta b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs.meta new file mode 100644 index 00000000..451d3bcf --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bb8ba6b5820955f4a95511b55c3a8db9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs new file mode 100644 index 00000000..80dec9da --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Printer3D : MonoBehaviour +{ + public Transform spawnPoint; + public int ignorePlayerCollisionLayer = 2; + public string shapeScannerTag = "ShapeScannable"; + + private GameObject GeneratedModel; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + public async void PrintObject(Texture2D texture) + { + string encodedTexture = Convert.ToBase64String(texture.EncodeToJPG()); + byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture); + + GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel); + InitializeSpawnedObject(spawnedObject); + if (GeneratedModel != null) + { + // Destroy previous generated object (first move out of ShapeScanner to trigger OnTriggerExit + GeneratedModel.transform.position = Vector3.zero; + } + GeneratedModel = spawnedObject; + } + + private void InitializeSpawnedObject(GameObject spawnedObject) + { + GameObject spawnedObjectParent = new GameObject("SpawnedModelParent"); + spawnedObjectParent.transform.parent = spawnPoint; + spawnedObjectParent.transform.position = spawnPoint.transform.position; + spawnedObjectParent.layer = ignorePlayerCollisionLayer; + Rigidbody rigidbody = spawnedObjectParent.AddComponent(); + rigidbody.isKinematic = true; + + //spawnedObject.AddComponent(); + //spawnedObject.AddComponent(); + + MeshCollider spawnedObjectCollider = spawnedObject.GetComponent(); + spawnedObjectCollider.convex = false; + spawnedObject.transform.parent = spawnedObjectParent.transform; + spawnedObject.transform.position = spawnedObjectParent.transform.position; + spawnedObject.tag = shapeScannerTag; + spawnedObject.layer = ignorePlayerCollisionLayer; + + spawnedObjectParent.AddComponent(); + } +} diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs.meta b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs.meta new file mode 100644 index 00000000..cdc3600b --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3D.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 165a0eb9b371428468a9f9253668ef2b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs new file mode 100644 index 00000000..265d8d8f --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Printer3DInputHole : MonoBehaviour +{ + public Printer3D printer; + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log(other.gameObject.name); + Transform parent = other.transform.parent; + if (parent != null) { + Printable printable = parent.GetComponent(); + if (printable != null) + { + printer.PrintObject(printable.GetTexture()); + Destroy(printable.gameObject); + } + } + + } +} diff --git a/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs.meta b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs.meta new file mode 100644 index 00000000..dd5d1c87 --- /dev/null +++ b/Assets/_PROJECT/Scripts/ModeGeneration/ShapeDetection/Printer3DInputHole.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2970ff5f70d74904ea849da1b6364e0e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: