Skip to content

Commit cb021b6

Browse files
committed
ModelingManagers updated.
* Material upload listener fixed. * Path logic fixed. * ProgressStatus , RestrictStatus added. * Syntax fixed.
1 parent a57191c commit cb021b6

File tree

2 files changed

+61
-30
lines changed

2 files changed

+61
-30
lines changed

Assets/Huawei/Scripts/Modeling3D/HMSModeling3dKitManager.cs

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
public class HMSModeling3dKitManager : HMSManagerSingleton<HMSModeling3dKitManager>
1515
{
16-
1716
private readonly string TAG = "[HMS] HMSModeling3dKitManager ";
1817
private const string TASK_LIST_PREFS_KEY = "3dTaskList";
1918

@@ -30,7 +29,7 @@ public class HMSModeling3dKitManager : HMSManagerSingleton<HMSModeling3dKitManag
3029
public Action<string, Modeling3dReconstructUploadResult, AndroidJavaObject> OnResultUpload;
3130
public Action<string, AndroidJavaObject> OnResultPreview;
3231
public Action<string, Modeling3dTextureDownloadResult, AndroidJavaObject> OnResult3dTextureDownload;
33-
public Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> OnResult3dTextureUpload;
32+
public Action<string, Modeling3dTextureUploadResult, JavaObject> OnResult3dTextureUpload;
3433
public Action<string, AndroidJavaObject> OnResult3dTexturePreview;
3534
public Action OnResultCaptureImage;
3635
public Action<int, string> OnErrorCaptureImage;
@@ -53,16 +52,12 @@ public void Init()
5352
{
5453
reconstructApplication = ReconstructApplication.GetInstance();
5554
modeling3DReconstructEngine = Modeling3dReconstructEngine.GetInstance();
56-
Debug.Log(TAG + "Init: " + reconstructApplication);
57-
55+
Debug.Log(TAG + "Init: " + reconstructApplication);
5856
}
5957
catch (System.Exception ex)
6058
{
61-
6259
Debug.LogError(TAG + ex.Message);
6360
}
64-
65-
6661
}
6762
public void AuthWithAccessToken(string accessToken)
6863
{
@@ -162,7 +157,10 @@ public void UploadFile(Modeling3dReconstructSetting setting, string path = null)
162157
string uploadsPath = Application.persistentDataPath;
163158
if(!string.IsNullOrWhiteSpace(path))
164159
{
165-
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
160+
if (!File.Exists(path))
161+
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
162+
else
163+
uploadsPath = path;
166164
}
167165
Debug.Log(TAG + "Enviroment " + uploadsPath);
168166

@@ -349,11 +347,9 @@ public void Create3DCaptureImageEngine(AndroidJavaObject context)
349347
public Modeling3dTextureSetting Create3dTextureEngine()
350348
{
351349
modeling3DTextureEngine = Modeling3dTextureEngine.GetInstance();
352-
353350
var settings = new Modeling3dTextureSetting.Factory().SetTextureMode(Modeling3dTextureConstants.AlgorithmMode.AI).Create();
354351

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

358354
return settings;
359355
}
@@ -365,7 +361,7 @@ public Modeling3dTextureInitResult InitTask(Modeling3dTextureSetting setting)
365361

366362
return modeling3DTextureInitResult;
367363
}
368-
public string AsyncUploadFile(Modeling3dTextureSetting setting, string uploadPath)
364+
public string AsyncUploadFile(Modeling3dTextureSetting setting, string path)
369365
{
370366
var modeling3DTextureInitResult = InitTask(setting);
371367

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

384380
OnResult3dTextureUpload += (taskId, result, obj) =>
385381
{
386-
Debug.Log(TAG + "OnResult taskId:" + result.TaskId + " result:" + result);
382+
Debug.Log(TAG + "OnResult taskId:"+ result.TaskId + " result:" + result);
387383
};
388384

389-
var listener = new Modeling3dTextureUploadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnUploadProgress, OnError, OnResult3dTextureUpload));
385+
Modeling3dTextureUploadListener listener = new Modeling3dTextureUploadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnUploadProgress, OnError, OnResult3dTextureUpload));
386+
387+
modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();
390388

391389
modeling3DTextureEngine.SetTextureUploadListener(listener);
392390

393-
string uploadsPath = uploadPath ?? Application.persistentDataPath;
391+
string uploadsPath = Application.persistentDataPath;
392+
if (!string.IsNullOrWhiteSpace(path))
393+
{
394+
if (!File.Exists(path))
395+
uploadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + path.Split(':').Last();
396+
else
397+
uploadsPath = path;
398+
}
399+
394400
Debug.LogFormat(TAG + "AsyncUploadFile uploadPath: {0}", uploadsPath);
395401

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

420-
var listener = new Modeling3dTextureDownloadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTextureDownload));
425+
string downloadsPath = Application.persistentDataPath;
426+
if (!string.IsNullOrWhiteSpace(savePath))
427+
{
428+
downloadsPath = Application.persistentDataPath.Split('/').Take(4).Aggregate((a, b) => a + "/" + b) + "/" + savePath.Split(':').Last();
429+
}
430+
Debug.LogFormat(TAG + "AsyncDownloadFile taskId: {0} savePath: {1}", taskID, downloadsPath);
431+
432+
Modeling3dTextureDownloadListener listener = new Modeling3dTextureDownloadListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTextureDownload));
433+
434+
modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();
421435

422436
modeling3DTextureEngine.SetTextureDownloadListener(listener);
423437

424438
modeling3DTextureEngine.AsyncDownloadTexture(taskID, downloadsPath);
425-
426-
Debug.LogFormat(TAG + "AsyncDownloadFile taskId: {0} savePath: {1}", taskID, downloadsPath);
427-
428439
}
429440
public void PreviewFile3dTexture(string taskID)
430441
{
@@ -443,24 +454,28 @@ public void PreviewFile3dTexture(string taskID)
443454
Debug.Log(TAG + "OnResult taskId:" + taskId + " result:" + obj);
444455
};
445456

446-
var listener = new Modeling3dTexturePreviewListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTexturePreview));
457+
Modeling3dTexturePreviewListener listener = new Modeling3dTexturePreviewListener(new Modeling3dTextureUploadORDownloadORPreviewListener(OnDownloadProgress, OnError, OnResult3dTexturePreview));
458+
459+
modeling3DTextureEngine ??= Modeling3dTextureEngine.GetInstance();
447460

461+
modeling3DTextureEngine.PreviewTexture(taskID, listener);
448462
}
449463
public Modeling3dTextureQueryResult QueryTaskModeling3dTexture(string taskId)
450464
{
451-
var texture3dTaskUtils = Modeling3dTextureTaskUtils.GetInstance();
465+
Modeling3dTextureTaskUtils texture3dTaskUtils = Modeling3dTextureTaskUtils.GetInstance();
452466

453-
var result = texture3dTaskUtils.QueryTask(taskId);
467+
Modeling3dTextureQueryResult result = texture3dTaskUtils.QueryTask(taskId);
454468

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

457471
return result;
458472
}
459-
public void DeleteTaskModeling3dTexture(string taskId)
473+
public int DeleteTaskModeling3dTexture(string taskId)
460474
{
461-
Modeling3dTextureTaskUtils.GetInstance().DeleteTask(taskId);
475+
var result = Modeling3dTextureTaskUtils.GetInstance().DeleteTask(taskId);
462476

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

486503
return result;
487504
}
488505
#endregion
506+
507+
public enum ProgressStatus
508+
{
509+
INITED,
510+
UPLOAD_COMPLETED,
511+
TEXTURE_START,
512+
TEXTURE_COMPLETED,
513+
TEXTURE_FAILED
514+
}
515+
public enum RestrictStatus
516+
{
517+
UNRESTRICT,
518+
RESTRICT
519+
}
489520
}
490521

Assets/Huawei/Scripts/Modeling3D/Modeling3dListenerManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using static HuaweiMobileServices.Modeling3D.MeterialGenerateSdk.Cloud.Modeling3dTexturePreviewListener;
77
using static HuaweiMobileServices.Modeling3D.MeterialGenerateSdk.Cloud.Modeling3dTextureUploadListener;
88
using static HuaweiMobileServices.Modeling3D.ModelingCaptureSdk.Modeling3dCaptureImageListener;
9+
using HuaweiMobileServices.Utils;
910

1011
namespace HmsPlugin
1112
{
@@ -108,13 +109,13 @@ public class Modeling3dTextureUploadORDownloadORPreviewListener : IModeling3dTex
108109
{
109110
private Action<string, double, AndroidJavaObject> Progress;
110111
private Action<string, int, string> Error;
111-
private Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> UploadResult;
112+
private Action<string, Modeling3dTextureUploadResult, JavaObject> UploadResult;
112113
private Action<string, Modeling3dTextureDownloadResult, AndroidJavaObject> DownloadResult;
113114
private Action<string, AndroidJavaObject> PreviewResult;
114115

115116
public Modeling3dTextureUploadORDownloadORPreviewListener(Action<string, double, AndroidJavaObject> Progress,
116117
Action<string, int, string> Error
117-
, Action<string, Modeling3dTextureUploadResult, AndroidJavaObject> UploadResult)
118+
, Action<string, Modeling3dTextureUploadResult, JavaObject> UploadResult)
118119
{
119120
this.Progress = Progress;
120121
this.Error = Error;
@@ -147,7 +148,7 @@ public void onError(string taskId, int errorCode, string errorMessage)
147148
Error?.Invoke(taskId, errorCode, errorMessage);
148149
}
149150

150-
public void onResult(string taskId, Modeling3dTextureUploadResult result, AndroidJavaObject javaObject)
151+
public void onResult(string taskId, Modeling3dTextureUploadResult result, JavaObject javaObject)
151152
{
152153
UploadResult?.Invoke(taskId, result, javaObject);
153154
}
@@ -162,10 +163,9 @@ public void onResult(string taskId, AndroidJavaObject javaObject)
162163
PreviewResult?.Invoke(taskId, javaObject);
163164
}
164165

165-
public void onUploadProgress(string taskId, double progress, AndroidJavaObject javaObject)
166+
public void onUploadProgress(string taskId, double progress, JavaObject javaObject)
166167
{
167-
Progress?.Invoke(taskId, progress, javaObject);
168+
// Progress?.Invoke(taskId, progress, javaObject);
168169
}
169-
170170
}
171171
}

0 commit comments

Comments
 (0)