forked from cgvr/DeltaVR
can insert printable into 3d printer, 3d printer starts printing
This commit is contained in:
@@ -87,6 +87,7 @@ GameObject:
|
|||||||
- component: {fileID: 3870989277732630730}
|
- component: {fileID: 3870989277732630730}
|
||||||
- component: {fileID: 7594134409976187304}
|
- component: {fileID: 7594134409976187304}
|
||||||
- component: {fileID: 1297641575955202044}
|
- component: {fileID: 1297641575955202044}
|
||||||
|
- component: {fileID: 6521999952126795650}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Printable
|
m_Name: Printable
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -274,6 +275,18 @@ MonoBehaviour:
|
|||||||
m_StartingSingleGrabTransformers: []
|
m_StartingSingleGrabTransformers: []
|
||||||
m_StartingMultipleGrabTransformers: []
|
m_StartingMultipleGrabTransformers: []
|
||||||
m_AddDefaultGrabTransformers: 1
|
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
|
--- !u!1 &6791306317367082968
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
Binary file not shown.
@@ -102,7 +102,6 @@ public abstract class NPCController : MonoBehaviour
|
|||||||
// apply mouth scale
|
// apply mouth scale
|
||||||
Vector3 s = mouth.localScale;
|
Vector3 s = mouth.localScale;
|
||||||
s.y = smoothed;
|
s.y = smoothed;
|
||||||
Debug.Log("mouth scale: " + smoothed);
|
|
||||||
mouth.localScale = s;
|
mouth.localScale = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +117,6 @@ public abstract class NPCController : MonoBehaviour
|
|||||||
scale.y = smoothed;
|
scale.y = smoothed;
|
||||||
mouth.localScale = scale;
|
mouth.localScale = scale;
|
||||||
}
|
}
|
||||||
Debug.Log("mouth scale stopped: " + smoothed);
|
|
||||||
|
|
||||||
currentVoicelineEvent.release();
|
currentVoicelineEvent.release();
|
||||||
}
|
}
|
||||||
@@ -193,7 +191,6 @@ public abstract class NPCController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
var lines = File.ReadAllLines(filePath);
|
var lines = File.ReadAllLines(filePath);
|
||||||
Debug.Log("read lines: " + lines.Length);
|
|
||||||
rmsCurve = lines.Select(l => float.Parse(l, System.Globalization.CultureInfo.InvariantCulture)).ToArray();
|
rmsCurve = lines.Select(l => float.Parse(l, System.Globalization.CultureInfo.InvariantCulture)).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,7 @@ public class ShapeDetectionNPC : NPCController
|
|||||||
public Image imageDisplay;
|
public Image imageDisplay;
|
||||||
public ShapeScanner shapeScanner;
|
public ShapeScanner shapeScanner;
|
||||||
public float radioAmount = 1f;
|
public float radioAmount = 1f;
|
||||||
|
|
||||||
public GameObject GeneratedModel { get; private set; }
|
|
||||||
public Transform modelSpawnPoint;
|
|
||||||
public string shapeScannerTag = "ShapeScannable";
|
|
||||||
public int ignorePlayerCollisionLayer = 2;
|
|
||||||
|
|
||||||
// states:
|
// states:
|
||||||
// 0 - idle
|
// 0 - idle
|
||||||
@@ -144,14 +140,8 @@ public class ShapeDetectionNPC : NPCController
|
|||||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||||
|
|
||||||
GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel);
|
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();
|
modelGenerationButton.Deactivate();
|
||||||
|
|
||||||
if (state == 5)
|
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 DG.Tweening;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class ComputerPrinter : MonoBehaviour
|
public class ComputerPrinter : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -9,8 +8,9 @@ public class ComputerPrinter : MonoBehaviour
|
|||||||
public PushableButton enterKey;
|
public PushableButton enterKey;
|
||||||
public Transform ejectionOrigin;
|
public Transform ejectionOrigin;
|
||||||
public Transform ejectionDestination;
|
public Transform ejectionDestination;
|
||||||
public GameObject printablePrefab;
|
public Printable printablePrefab;
|
||||||
public float ejectionDuration = 1.0f;
|
public float ejectionDuration = 1.0f;
|
||||||
|
public int ignorePlayerCollisionLayer = 2;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@@ -29,11 +29,14 @@ public class ComputerPrinter : MonoBehaviour
|
|||||||
string inputPrompt = textDisplay.text;
|
string inputPrompt = textDisplay.text;
|
||||||
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt);
|
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt);
|
||||||
Texture2D generatedTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
Texture2D generatedTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
||||||
Sprite sprite = ModelGenerationUtils.CreateSprite(generatedTexture);
|
|
||||||
|
Printable printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity);
|
||||||
GameObject printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity);
|
printable.AttachTexture(generatedTexture);
|
||||||
Image printableDisplay = printable.GetComponentInChildren<Image>();
|
printable.gameObject.layer = ignorePlayerCollisionLayer;
|
||||||
printableDisplay.sprite = sprite;
|
foreach (Transform childTrans in printable.transform.GetComponentInChildren<Transform>())
|
||||||
|
{
|
||||||
|
childTrans.gameObject.layer = ignorePlayerCollisionLayer;
|
||||||
|
}
|
||||||
|
|
||||||
printable.transform.DOMove(ejectionDestination.position, ejectionDuration).OnComplete(() =>
|
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