|
|
|
|
@ -1,12 +1,8 @@ |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using UnityEngine; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Amazon; |
|
|
|
|
using Amazon.S3; |
|
|
|
|
using Amazon.S3.Transfer; |
|
|
|
|
using Amazon.S3.Model; |
|
|
|
|
using UltraCombos.Upload; |
|
|
|
|
using OscJack; |
|
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
|
|
[System.Serializable] |
|
|
|
|
public class S3Tag |
|
|
|
|
@ -24,6 +20,8 @@ public class SaveImage : MonoBehaviour |
|
|
|
|
public RenderTexture renderTexture; |
|
|
|
|
public string OutputFolder = "output"; |
|
|
|
|
|
|
|
|
|
public string FirebaseUrl = "https://firestore.googleapis.com/v1/projects/uc-24070-thegreattipsy/databases/(default)/documents/"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update |
|
|
|
|
void Start() |
|
|
|
|
@ -42,7 +40,7 @@ public class SaveImage : MonoBehaviour |
|
|
|
|
|
|
|
|
|
public void save(string filename) |
|
|
|
|
{ |
|
|
|
|
if(string.IsNullOrEmpty(filename)) |
|
|
|
|
if (string.IsNullOrEmpty(filename)) |
|
|
|
|
{ |
|
|
|
|
Debug.LogError("Filename cannot be null or empty."); |
|
|
|
|
return; |
|
|
|
|
@ -78,20 +76,23 @@ public class SaveImage : MonoBehaviour |
|
|
|
|
byte[] bytes = tex.EncodeToPNG(); |
|
|
|
|
System.IO.File.WriteAllBytes(filePath, bytes); |
|
|
|
|
|
|
|
|
|
Debug.Log("Saved RenderTexture to PNG at " + filePath+ " with size: " + bytes.Length + " bytes"); |
|
|
|
|
Debug.Log("Saved RenderTexture to PNG at " + filePath + " with size: " + bytes.Length + " bytes"); |
|
|
|
|
|
|
|
|
|
RenderTexture.active = currentRT; |
|
|
|
|
Destroy(tex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void upload(string filename){ |
|
|
|
|
void upload(string filename) |
|
|
|
|
{ |
|
|
|
|
if (uploader != null) |
|
|
|
|
{ |
|
|
|
|
uploader.Upload(filename, (response) => |
|
|
|
|
{ |
|
|
|
|
if (response.success) |
|
|
|
|
{ |
|
|
|
|
Debug.Log("Upload successful: " + response); |
|
|
|
|
Debug.Log("Upload successful: " + response.message); |
|
|
|
|
|
|
|
|
|
writeToFirebase(filename, response.message); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
@ -105,5 +106,66 @@ public class SaveImage : MonoBehaviour |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void writeToFirebase(string filename, string url) |
|
|
|
|
{ |
|
|
|
|
Debug.Log("Writing to Firebase: " + filename); |
|
|
|
|
StartCoroutine(WriteToFirebaseCoroutine(filename, url)); |
|
|
|
|
|
|
|
|
|
IEnumerator WriteToFirebaseCoroutine(string filename, string url) |
|
|
|
|
{ |
|
|
|
|
string id=filename.Split('/')[2].Split('.')[0]; |
|
|
|
|
Debug.Log("Extracted ID: " + id); |
|
|
|
|
|
|
|
|
|
string firebaseUrl = FirebaseUrl + "prints/" + id; |
|
|
|
|
string jsonData = "{ \"fields\": { " + |
|
|
|
|
"\"url\": { \"stringValue\": \"" + url + "\" }, " + |
|
|
|
|
"\"timestamp\": { \"timestampValue\": \"" + System.DateTime.UtcNow.ToString("o") + "\" } " + |
|
|
|
|
"} }"; |
|
|
|
|
|
|
|
|
|
using (var www = new UnityEngine.Networking.UnityWebRequest(firebaseUrl, "PATCH")) |
|
|
|
|
{ |
|
|
|
|
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData); |
|
|
|
|
www.uploadHandler = new UnityEngine.Networking.UploadHandlerRaw(bodyRaw); |
|
|
|
|
www.downloadHandler = new UnityEngine.Networking.DownloadHandlerBuffer(); |
|
|
|
|
www.SetRequestHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
|
yield return www.SendWebRequest(); |
|
|
|
|
|
|
|
|
|
#if UNITY_2020_1_OR_NEWER |
|
|
|
|
if (www.result != UnityEngine.Networking.UnityWebRequest.Result.Success) |
|
|
|
|
#else |
|
|
|
|
if (www.isNetworkError || www.isHttpError) |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
Debug.LogError("Error writing to Firebase: " + www.error); |
|
|
|
|
Debug.LogError("Response: " + www.downloadHandler.text); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Debug.Log("Successfully wrote to Firebase: " + www.downloadHandler.text); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void sendOscMessage(string message) |
|
|
|
|
{ |
|
|
|
|
// Implement your OSC message sending logic here |
|
|
|
|
Debug.Log("Sending OSC message: " + message); |
|
|
|
|
StartCoroutine(SendOscMessageCoroutine(message)); |
|
|
|
|
} |
|
|
|
|
public IEnumerator SendOscMessageCoroutine(string message){ |
|
|
|
|
|
|
|
|
|
using (var client = new OscClient("127.0.0.1", 9000)) |
|
|
|
|
{ |
|
|
|
|
// Send two-component float values ten times. |
|
|
|
|
for (var i = 0; i < 1; i++) |
|
|
|
|
{ |
|
|
|
|
yield return new WaitForSeconds(0.5f); |
|
|
|
|
client.Send("/uploaded", // OSC address |
|
|
|
|
message); // Message content |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |