1
0
forked from cgvr/DeltaVR

can insert printable into 3d printer, 3d printer starts printing

This commit is contained in:
2026-02-14 16:08:13 +02:00
parent 884459842e
commit 17c9122a14
11 changed files with 192 additions and 45 deletions

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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>();
}
}

View File

@@ -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(() =>
{

View File

@@ -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;
}
}

View File

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

View File

@@ -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>();
}
}

View File

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

View File

@@ -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);
}
}
}
}

View File

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