forked from cgvr/DeltaVR
can insert printable into 3d printer, 3d printer starts printing
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user