forked from cgvr/DeltaVR
can insert printable into 3d printer, 3d printer starts printing
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
rigidbody.isKinematic = true;
|
||||
|
||||
//spawnedObject.AddComponent<NetworkObject>();
|
||||
//spawnedObject.AddComponent<NetworkTransform>();
|
||||
|
||||
MeshCollider spawnedObjectCollider = spawnedObject.GetComponent<MeshCollider>();
|
||||
spawnedObjectCollider.convex = false;
|
||||
spawnedObject.transform.parent = spawnedObjectParent.transform;
|
||||
spawnedObject.transform.position = spawnedObjectParent.transform.position;
|
||||
spawnedObject.tag = shapeScannerTag;
|
||||
spawnedObject.layer = ignorePlayerCollisionLayer;
|
||||
|
||||
spawnedObjectParent.AddComponent<TwoHandScaleGrabInteractable>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Image>();
|
||||
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<Transform>())
|
||||
{
|
||||
childTrans.gameObject.layer = ignorePlayerCollisionLayer;
|
||||
}
|
||||
|
||||
printable.transform.DOMove(ejectionDestination.position, ejectionDuration).OnComplete(() =>
|
||||
{
|
||||
|
||||
@@ -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<Image>();
|
||||
imageDisplay.sprite = sprite;
|
||||
attachedTexture = texture;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb8ba6b5820955f4a95511b55c3a8db9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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>();
|
||||
rigidbody.isKinematic = true;
|
||||
|
||||
//spawnedObject.AddComponent<NetworkObject>();
|
||||
//spawnedObject.AddComponent<NetworkTransform>();
|
||||
|
||||
MeshCollider spawnedObjectCollider = spawnedObject.GetComponent<MeshCollider>();
|
||||
spawnedObjectCollider.convex = false;
|
||||
spawnedObject.transform.parent = spawnedObjectParent.transform;
|
||||
spawnedObject.transform.position = spawnedObjectParent.transform.position;
|
||||
spawnedObject.tag = shapeScannerTag;
|
||||
spawnedObject.layer = ignorePlayerCollisionLayer;
|
||||
|
||||
spawnedObjectParent.AddComponent<TwoHandScaleGrabInteractable>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 165a0eb9b371428468a9f9253668ef2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<Printable>();
|
||||
if (printable != null)
|
||||
{
|
||||
printer.PrintObject(printable.GetTexture());
|
||||
Destroy(printable.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2970ff5f70d74904ea849da1b6364e0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user