Skip to content

Commit

Permalink
ModelingManagers updated.
Browse files Browse the repository at this point in the history
* Material upload listener fixed.
* Path logic fixed.
* ProgressStatus , RestrictStatus added.
* Syntax fixed.
  • Loading branch information
alihan98ersoy committed Dec 4, 2023
1 parent a57191c commit cb021b6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
79 changes: 55 additions & 24 deletions Assets/Huawei/Scripts/Modeling3D/HMSModeling3dKitManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

public class HMSModeling3dKitManager : HMSManagerSingleton<HMSModeling3dKitManager>
{

private readonly string TAG = "[HMS] HMSModeling3dKitManager ";
private const string TASK_LIST_PREFS_KEY = "3dTaskList";

Expand All @@ -30,7 +29,7 @@ public class HMSModeling3dKitManager : HMSManagerSingleton<HMSModeling3dKitManag
public Action<string, Modeling3dReconstructUploadResult, AndroidJavaObject> OnResultUpload;
public Action<string, AndroidJavaObject> OnResultPreview;
public Action<string, Modeling3dTextureDownloadResult, AndroidJavaObject> OnResult3dTextureDownload;
public Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> OnResult3dTextureUpload;
public Action<string, Modeling3dTextureUploadResult, JavaObject> OnResult3dTextureUpload;
public Action<string, AndroidJavaObject> OnResult3dTexturePreview;
public Action OnResultCaptureImage;
public Action<int, string> OnErrorCaptureImage;
Expand All @@ -53,16 +52,12 @@ public void Init()
{
reconstructApplication = ReconstructApplication.GetInstance();
modeling3DReconstructEngine = Modeling3dReconstructEngine.GetInstance();
Debug.Log(TAG + "Init: " + reconstructApplication);

Debug.Log(TAG + "Init: " + reconstructApplication);
}
catch (System.Exception ex)
{

Debug.LogError(TAG + ex.Message);
}


}
public void AuthWithAccessToken(string accessToken)
{
Expand Down Expand Up @@ -162,7 +157,10 @@ public void UploadFile(Modeling3dReconstructSetting setting, string path = null)
string uploadsPath = Application.persistentDataPath;
if(!string.IsNullOrWhiteSpace(path))
{
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
if (!File.Exists(path))
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
else
uploadsPath = path;
}
Debug.Log(TAG + "Enviroment " + uploadsPath);

Expand Down Expand Up @@ -349,11 +347,9 @@ public void Create3DCaptureImageEngine(AndroidJavaObject context)
public Modeling3dTextureSetting Create3dTextureEngine()
{
modeling3DTextureEngine = Modeling3dTextureEngine.GetInstance();

var settings = new Modeling3dTextureSetting.Factory().SetTextureMode(Modeling3dTextureConstants.AlgorithmMode.AI).Create();

Debug.LogFormat(TAG + "Create3dTextureEngine settings texture mode: {0}", settings.TextureMode);


return settings;
}
Expand All @@ -365,7 +361,7 @@ public Modeling3dTextureInitResult InitTask(Modeling3dTextureSetting setting)

return modeling3DTextureInitResult;
}
public string AsyncUploadFile(Modeling3dTextureSetting setting, string uploadPath)
public string AsyncUploadFile(Modeling3dTextureSetting setting, string path)
{
var modeling3DTextureInitResult = InitTask(setting);

Expand All @@ -383,14 +379,24 @@ public string AsyncUploadFile(Modeling3dTextureSetting setting, string uploadPat

OnResult3dTextureUpload += (taskId, result, obj) =>
{
Debug.Log(TAG + "OnResult taskId:" + result.TaskId + " result:" + result);
Debug.Log(TAG + "OnResult taskId:"+ result.TaskId + " result:" + result);
};

var listener = new Modeling3dTextureUploadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnUploadProgress, OnError, OnResult3dTextureUpload));
Modeling3dTextureUploadListener listener = new Modeling3dTextureUploadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnUploadProgress, OnError, OnResult3dTextureUpload));

modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();

modeling3DTextureEngine.SetTextureUploadListener(listener);

string uploadsPath = uploadPath ?? Application.persistentDataPath;
string uploadsPath = Application.persistentDataPath;
if (!string.IsNullOrWhiteSpace(path))
{
if (!File.Exists(path))
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
else
uploadsPath = path;
}

Debug.LogFormat(TAG + "AsyncUploadFile uploadPath: {0}", uploadsPath);

modeling3DTextureEngine.AsyncUploadFile(taskID, uploadsPath);
Expand All @@ -415,16 +421,21 @@ public void AsyncDownloadFile(string taskID, string savePath)
{
Debug.Log(TAG + "OnResult taskId:" + taskId + " result:" + result);
};
string downloadsPath = savePath ?? Application.persistentDataPath;

var listener = new Modeling3dTextureDownloadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTextureDownload));
string downloadsPath = Application.persistentDataPath;
if (!string.IsNullOrWhiteSpace(savePath))
{
downloadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + savePath.Split(':').Last();
}
Debug.LogFormat(TAG + "AsyncDownloadFile taskId: {0} savePath: {1}", taskID, downloadsPath);

Modeling3dTextureDownloadListener listener = new Modeling3dTextureDownloadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTextureDownload));

modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();

modeling3DTextureEngine.SetTextureDownloadListener(listener);

modeling3DTextureEngine.AsyncDownloadTexture(taskID, downloadsPath);

Debug.LogFormat(TAG + "AsyncDownloadFile taskId: {0} savePath: {1}", taskID, downloadsPath);

}
public void PreviewFile3dTexture(string taskID)
{
Expand All @@ -443,24 +454,28 @@ public void PreviewFile3dTexture(string taskID)
Debug.Log(TAG + "OnResult taskId:" + taskId + " result:" + obj);
};

var listener = new Modeling3dTexturePreviewListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTexturePreview));
Modeling3dTexturePreviewListener listener = new Modeling3dTexturePreviewListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTexturePreview));

modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();

modeling3DTextureEngine.PreviewTexture(taskID, listener);
}
public Modeling3dTextureQueryResult QueryTaskModeling3dTexture(string taskId)
{
var texture3dTaskUtils = Modeling3dTextureTaskUtils.GetInstance();
Modeling3dTextureTaskUtils texture3dTaskUtils = Modeling3dTextureTaskUtils.GetInstance();

var result = texture3dTaskUtils.QueryTask(taskId);
Modeling3dTextureQueryResult result = texture3dTaskUtils.QueryTask(taskId);

Debug.Log(TAG + " Modeling3dTexture QueryTask result status:" + result.Status + " taskId:" + result.TaskId + " RedCode:" + result.RetCode + " RedMessage:" + result.RetMsg);

return result;
}
public void DeleteTaskModeling3dTexture(string taskId)
public int DeleteTaskModeling3dTexture(string taskId)
{
Modeling3dTextureTaskUtils.GetInstance().DeleteTask(taskId);
var result = Modeling3dTextureTaskUtils.GetInstance().DeleteTask(taskId);

Debug.Log(TAG + string.Format("Modeling3dTexture Task Deleted {0}", taskId));
return result;
}
public int QueryTaskRestrictStatusModeling3dTexture(string taskId)
{
Expand All @@ -481,10 +496,26 @@ public int SetTaskRestrictStatusModeling3dTexture(string taskId, int restrictSta
Call the synchronous API to obtain the generated texture maps in real time.*/
public int SyncGenerateTexture(string imagePath, string downloadPath, Modeling3dTextureSetting setting)
{
modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();

int result = modeling3DTextureEngine.SyncGenerateTexture(imagePath, downloadPath, setting);

return result;
}
#endregion

public enum ProgressStatus
{
INITED,
UPLOAD_COMPLETED,
TEXTURE_START,
TEXTURE_COMPLETED,
TEXTURE_FAILED
}
public enum RestrictStatus
{
UNRESTRICT,
RESTRICT
}
}

12 changes: 6 additions & 6 deletions Assets/Huawei/Scripts/Modeling3D/Modeling3dListenerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using static HuaweiMobileServices.Modeling3D.MeterialGenerateSdk.Cloud.Modeling3dTexturePreviewListener;
using static HuaweiMobileServices.Modeling3D.MeterialGenerateSdk.Cloud.Modeling3dTextureUploadListener;
using static HuaweiMobileServices.Modeling3D.ModelingCaptureSdk.Modeling3dCaptureImageListener;
using HuaweiMobileServices.Utils;

namespace HmsPlugin
{
Expand Down Expand Up @@ -108,13 +109,13 @@ public class Modeling3dTextureUploadORDownloadORPreviewListener : IModeling3dTex
{
private Action<string, double, AndroidJavaObject> Progress;
private Action<string, int, string> Error;
private Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> UploadResult;
private Action<string, Modeling3dTextureUploadResult, JavaObject> UploadResult;
private Action<string, Modeling3dTextureDownloadResult, AndroidJavaObject> DownloadResult;
private Action<string, AndroidJavaObject> PreviewResult;

public Modeling3dTextureUploadORDownloadORPreviewListener(Action<string, double, AndroidJavaObject> Progress,
Action<string, int, string> Error
, Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> UploadResult)
, Action<string, Modeling3dTextureUploadResult, JavaObject> UploadResult)
{
this.Progress = Progress;
this.Error = Error;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void onError(string taskId, int errorCode, string errorMessage)
Error?.Invoke(taskId, errorCode, errorMessage);
}

public void onResult(string taskId, Modeling3dTextureUploadResult result, AndroidJavaObject javaObject)
public void onResult(string taskId, Modeling3dTextureUploadResult result, JavaObject javaObject)
{
UploadResult?.Invoke(taskId, result, javaObject);
}
Expand All @@ -162,10 +163,9 @@ public void onResult(string taskId, AndroidJavaObject javaObject)
PreviewResult?.Invoke(taskId, javaObject);
}

public void onUploadProgress(string taskId, double progress, AndroidJavaObject javaObject)
public void onUploadProgress(string taskId, double progress, JavaObject javaObject)
{
Progress?.Invoke(taskId, progress, javaObject);
// Progress?.Invoke(taskId, progress, javaObject);
}

}
}

0 comments on commit cb021b6

Please sign in to comment.