forked from cgvr/DeltaVR
printer input hole animation
This commit is contained in:
@@ -10,7 +10,6 @@ public class ComputerPrinter : MonoBehaviour
|
||||
public Transform ejectionDestination;
|
||||
public Printable printablePrefab;
|
||||
public float ejectionDuration = 1.0f;
|
||||
public int ignorePlayerCollisionLayer = 2;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -32,11 +31,6 @@ public class ComputerPrinter : MonoBehaviour
|
||||
|
||||
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(() =>
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using FMOD.Studio;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,12 +10,15 @@ public class Printer3D : MonoBehaviour
|
||||
public int ignorePlayerCollisionLayer = 2;
|
||||
public string shapeScannerTag = "ShapeScannable";
|
||||
|
||||
private bool isPrinting = false;
|
||||
private EventInstance printingSound;
|
||||
private GameObject GeneratedModel;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
printingSound = AudioManager.Instance.CreateInstance(FMODEvents.Instance.Printing);
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 1);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -25,6 +29,10 @@ public class Printer3D : MonoBehaviour
|
||||
|
||||
public async void PrintObject(Texture2D texture)
|
||||
{
|
||||
isPrinting = true;
|
||||
printingSound.start();
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 0);
|
||||
|
||||
string encodedTexture = Convert.ToBase64String(texture.EncodeToJPG());
|
||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||
|
||||
@@ -36,6 +44,9 @@ public class Printer3D : MonoBehaviour
|
||||
GeneratedModel.transform.position = Vector3.zero;
|
||||
}
|
||||
GeneratedModel = spawnedObject;
|
||||
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 1);
|
||||
isPrinting = false;
|
||||
}
|
||||
|
||||
private void InitializeSpawnedObject(GameObject spawnedObject)
|
||||
@@ -59,4 +70,9 @@ public class Printer3D : MonoBehaviour
|
||||
|
||||
spawnedObjectParent.AddComponent<TwoHandScaleGrabInteractable>();
|
||||
}
|
||||
|
||||
public bool IsPrinting()
|
||||
{
|
||||
return isPrinting;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class Printer3DInputHole : MonoBehaviour
|
||||
{
|
||||
public Printer3D printer;
|
||||
public XRInteractionManager interactionManager;
|
||||
public Transform insertionOrigin;
|
||||
public Transform insertionDestination;
|
||||
public float insertionDuration = 1f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -26,10 +30,56 @@ public class Printer3DInputHole : MonoBehaviour
|
||||
Printable printable = parent.GetComponent<Printable>();
|
||||
if (printable != null)
|
||||
{
|
||||
printer.PrintObject(printable.GetTexture());
|
||||
Destroy(printable.gameObject);
|
||||
if (printer.IsPrinting())
|
||||
{
|
||||
Debug.Log("priner is busy!");
|
||||
} else
|
||||
{
|
||||
ReleaseFromPlayer(printable);
|
||||
InsertPrintable(printable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ReleaseFromPlayer(Printable printable)
|
||||
{
|
||||
|
||||
var grab = printable.GetComponent<XRGrabInteractable>();
|
||||
var rb = printable.GetComponent<Rigidbody>();
|
||||
|
||||
// 1) If currently held, force release from the interactor
|
||||
if (grab != null && grab.isSelected)
|
||||
{
|
||||
var interactor = grab.firstInteractorSelecting; // the hand/controller currently holding it
|
||||
if (interactor != null)
|
||||
{
|
||||
// Transfer ownership: tell the manager to stop the selection
|
||||
interactionManager.SelectExit(interactor, grab);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Make sure physics doesn't fight the tween (optional but recommended)
|
||||
if (rb != null)
|
||||
{
|
||||
rb.isKinematic = true; // prevent forces during tween
|
||||
rb.velocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
// 3) Optionally disable grabbing during the tween so the player can't re-grab mid-flight
|
||||
if (grab != null) grab.enabled = false;
|
||||
}
|
||||
|
||||
private void InsertPrintable(Printable printable)
|
||||
{
|
||||
Transform printableTransform = printable.transform;
|
||||
printableTransform.position = insertionOrigin.position;
|
||||
printableTransform.rotation = insertionOrigin.rotation;
|
||||
printableTransform.DOMove(insertionDestination.position, insertionDuration).OnComplete(() =>
|
||||
{
|
||||
printer.PrintObject(printable.GetTexture());
|
||||
Destroy(printable.gameObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user