Skip to content

Commit

Permalink
3d model improvement & fixes (#452)
Browse files Browse the repository at this point in the history
* Scenes and DLL changed

* Update TaskListDisplay to fix syntax

* Update Modeling3dDemoManager.cs

* Success condition fixed for tasklist.
* TaskID logic changed.
* Syntax fixed.

* Update Modeling3dMeterialDemoManager.cs

* TaskID logic changed.
* APIKey logic changed.
* Result & Progress & Error listener added to upload as an example.
* Modeling3dTextureSetting null issue fixed.
* Added folder picker for uploading & downloading material.
* MaterialPreview method added.
* Syntax fixed.

* Modeling tab created

* ModelingManagers updated.

* Material upload listener fixed.
* Path logic fixed.
* ProgressStatus, and RestrictStatus added.
* Syntax fixed.

* ModelingKit Android package removed.

It has manifest and gradleTemplate.properties.
* Manifest for permissions.
* gradleTemplate.properties for enabling AndroidX.
Now they need to implement it manually.

* Meta files added

* Create HMSModelingKitSettings.cs

* Delete HMSUnityModelingKit.plugin.meta

* IdentifyProgressStatus method added
* No API key causing NullPointerexception fixed
* Task list no TASKID Download fixed
* Task list status meaning added.
* Getting APIKEY from ModelingKitSetting fixed.
* TaskList reorganized
  • Loading branch information
alihan98ersoy authored Dec 5, 2023
1 parent 0bbe1f8 commit 0c37dd5
Show file tree
Hide file tree
Showing 34 changed files with 495 additions and 250 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Huawei/Demos/Location/ActivityIdentificationDemo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Huawei/Demos/Location/FusedLocationDemo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Huawei/Demos/Location/GeocodingDemo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Huawei/Demos/Location/GeofenceDemo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Huawei/Demos/Location/LocationDemoManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 40 additions & 7 deletions Assets/Huawei/Demos/Modeling3D/Modeling3dDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &226796066
RectTransform:
m_ObjectHideFlags: 0
Expand All @@ -501,7 +501,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -175, y: 400}
m_AnchoredPosition: {x: -206, y: 400}
m_SizeDelta: {x: 160, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &226796067
Expand Down Expand Up @@ -547,7 +547,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 226796068}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 298829229}
m_TargetAssemblyTypeName: TaskListDisplay, HuaweiMobileServices.Core
m_MethodName: DownloadTask
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &226796068
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -597,6 +609,7 @@ GameObject:
- component: {fileID: 298829226}
- component: {fileID: 298829228}
- component: {fileID: 298829227}
- component: {fileID: 298829229}
m_Layer: 5
m_Name: TaskList
m_TagString: Untagged
Expand Down Expand Up @@ -665,6 +678,26 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 298829225}
m_CullTransparentMesh: 1
--- !u!114 &298829229
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 298829225}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fa179a0ae9214b44298e348efe22a5e1, type: 3}
m_Name:
m_EditorClassIdentifier:
Name: {fileID: 0}
Status: {fileID: 0}
Image: {fileID: 0}
RawImage: {fileID: 0}
PreviewButton: {fileID: 0}
DownloadButton: {fileID: 0}
HasDownloaded: {fileID: 0}
TaskId:
--- !u!1 &468504793
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2388,7 +2421,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &1339655658
RectTransform:
m_ObjectHideFlags: 0
Expand All @@ -2407,7 +2440,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 150, y: 400}
m_AnchoredPosition: {x: 207, y: 398}
m_SizeDelta: {x: 160, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1339655659
Expand Down Expand Up @@ -3523,7 +3556,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &1841041448
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3622,7 +3655,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: -76}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1880429680
Expand Down
41 changes: 13 additions & 28 deletions Assets/Huawei/Demos/Modeling3D/Modeling3dDemoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using UnityEngine.Android;
using UnityEngine.UI;


public class Modeling3dDemoManager : MonoBehaviour
{
///It is necessary to add permissions in the Android manifest. Assets\Huawei\Plugins\Android\HMSUnityModelingKit.plugin\AndroidManifest.xml
Expand All @@ -24,7 +23,6 @@ public class Modeling3dDemoManager : MonoBehaviour
};

//Getting apikey in agconnect json file.
private const string YOUR_API_KEY = "";
private const string TASK_LIST_PREFS_KEY = "3dTaskList";
private const string TAG = "[HMS] Modeling3dDemoManager ";

Expand All @@ -38,7 +36,7 @@ public class Modeling3dDemoManager : MonoBehaviour
[SerializeField] private GameObject taskList;
[SerializeField] private GameObject taskItemPrefab;
#endregion
/// TODO: This singleton can be written as a generic class to extend MonoBehavior. It saves code repetition and is available in every demo manager.r.
/// TODO: This singleton can be written as a generic class to extend MonoBehavior. It saves code repetition and is available in every demo manager.
#region Singleton

public static Modeling3dDemoManager Instance { get; private set; }
Expand Down Expand Up @@ -74,10 +72,8 @@ void Start()
HMSModeling3dKitManager.Instance.OnResultDownload = OnResultDownload;
//HMSModeling3dKitManager.Instance.OnResultPreview = OnResultPreview;

Debug.Log(TAG + "LogIn By API key");

HMSModeling3dKitManager.Instance.AuthWithApiKey(YOUR_API_KEY);

string APIKEY = HMSModelingKitSettings.Instance.Settings.Get(HMSModelingKitSettings.ModelingKeyAPI);
HMSModeling3dKitManager.Instance.AuthWithApiKey(APIKEY);
}
public void OnUploadProgress(string taskId, double progress, AndroidJavaObject obj) {
progressBar.current = Mathf.RoundToInt((float)progress);
Expand All @@ -93,7 +89,6 @@ public void OnUploadProgress(string taskId, double progress, AndroidJavaObject o
modeling3dTaskEntity.Update(data);
PlayerPrefs.SetString("currentTaskId", taskId);
});

}
public void OnResultUpload(string taskId, Modeling3dReconstructUploadResult result, AndroidJavaObject obj)
{
Expand All @@ -111,9 +106,9 @@ public void OnResultUpload(string taskId, Modeling3dReconstructUploadResult resu
data.Type = 1;
modeling3dTaskEntity.Update(data);
PlayerPrefs.SetString("currentTaskId", taskId);
PlayerPrefs.Save();
AndroidToast.MakeText("Upload Complated. Open Task List and Check It.").Show();
progressBar.gameObject.SetActive(false);

});
}
else
Expand All @@ -127,17 +122,18 @@ public void OnResultUpload(string taskId, Modeling3dReconstructUploadResult resu
public void OnDownloadProgress(string taskId, double progress, AndroidJavaObject obj)
{
progressBar.current = Mathf.RoundToInt((float)progress);

Debug.Log($"{TAG} OnDownloadProgress Android Obj: {obj?.GetRawObject()} and TaskId: {taskId} and Result: {progress}");
HMSDispatcher.Invoke(() =>
{
var taskListItem = taskItemPrefab.GetComponent<TaskListDisplay>();
var data = new Modeling3dDTO();
var currentTaskId = PlayerPrefs.GetString("currentTaskId");
var currentTaskId = taskListItem.TaskId;
Debug.Log($"{TAG} OnDownloadProgress TaskId: {currentTaskId}");
data = modeling3dTaskEntity.Find(currentTaskId);
data.TaskId = taskId;
data.Status = $"DownloadProgress";
data.Type = 2;
modeling3dTaskEntity.Update(data);
PlayerPrefs.SetString("currentTaskId", taskId);
});
}
public void OnResultDownload(string taskId, Modeling3dReconstructDownloadResult result, AndroidJavaObject obj)
Expand All @@ -158,7 +154,6 @@ public void OnResultDownload(string taskId, Modeling3dReconstructDownloadResult
PlayerPrefs.SetString("currentTaskId", taskId);
AndroidToast.MakeText($"Download Complated.\n Download Path: {currentDownloadFilePath}").Show();
progressBar.gameObject.SetActive(false);

});
}
else
Expand All @@ -168,7 +163,6 @@ public void OnResultDownload(string taskId, Modeling3dReconstructDownloadResult
AndroidToast.MakeText("Download Not Complated").Show();
});
}

}
public void OnResultPreview(string taskId, AndroidJavaObject obj)
{
Expand All @@ -185,7 +179,6 @@ public void OnResultPreview(string taskId, AndroidJavaObject obj)
modeling3dTaskEntity.Update(data);
PlayerPrefs.SetString("currentTaskId", taskId);
AndroidToast.MakeText("Preview Complated").Show();

});
}
private bool ArePermissionsGranted(string[] permissions)
Expand All @@ -201,9 +194,9 @@ private bool ArePermissionsGranted(string[] permissions)
}
public void UploadFile()
{
AndroidToast.MakeText("Number of Input Images:20 to 200 (at least 50 recommended.)").Show();
AndroidFolderPicker.mOnSuccessListener = OnUploadSuccessFolderPicker;
AndroidFolderPicker.OpenFolderPicker();

}
public void OnUploadSuccessFolderPicker(AndroidIntent androidIntent)
{
Expand All @@ -215,11 +208,9 @@ public void OnUploadSuccessFolderPicker(AndroidIntent androidIntent)
progressBar.current = 0;
HMSModeling3dKitManager.Instance.UploadFile(settings, currentUploadFilePath);
AndroidToast.MakeText("Start Uploading...").Show();

}
public void DownloadFile(string TaskId, string ModelFormat = null, int? TextureMode = null)
{
PlayerPrefs.SetString("currentTaskId", TaskId);
this.modelFormat = ModelFormat;
this.textureMode = TextureMode;
AndroidFolderPicker.mOnSuccessListener = OnDownloadSuccessFolderPicker;
Expand All @@ -237,7 +228,6 @@ public void OnDownloadSuccessFolderPicker(AndroidIntent androidIntent)
progressBar.current = 0;
HMSModeling3dKitManager.Instance.DownloadFile(config, PlayerPrefs.GetString("currentTaskId"), currentDownloadFilePath);
AndroidToast.MakeText("Start Downloading...\n Please Back to Main Menu.").Show();

}
public void PreviewFile(string TaskId, int? TextureMode = null)
{
Expand All @@ -250,16 +240,14 @@ public void PreviewFile(string TaskId, int? TextureMode = null)

HMSModeling3dKitManager.Instance.PreviewFile(config, TaskId);
AndroidToast.MakeText("Start Previewing...").Show();


}
public Modeling3dReconstructQueryResult QueryTask(string taskId = null)
{
if (taskId == null)
{
taskId = PlayerPrefs.GetString("currentTaskId");
}
Debug.Log($"Current TaskId {taskId}");
Debug.Log($"{TAG} Current TaskId {taskId}");
return HMSModeling3dKitManager.Instance.QueryTask(taskId);
}
public void Create3DCaptureImage()
Expand Down Expand Up @@ -296,7 +284,6 @@ public void Cancel3dModelReconstruct()
Invoke("CancelOperationWait", 5);
});
}

}
private void CancelOperationWait()
{
Expand All @@ -322,11 +309,10 @@ public void TaskList()
var noDataText = FindObjectsOfType<Text>().FirstOrDefault(t => t.name == "NoDataText");
var taskListData = modeling3dTaskEntity.GetAll();
Debug.LogFormat(TAG + "PlayerPrefsJsonDatabase Count {0}", taskListData.Count);
noDataText.gameObject.SetActive(taskListData.Count == 0 ? true : false);
noDataText?.gameObject.SetActive(taskListData.Count == 0 ? true : false);

DestoryChildrenByType(taskListItemParentObj, typeof(TaskListDisplay));
CreateTaskListItem(taskListData, taskListItem, taskListItemParentObj);

}
private void CreateTaskListItem(List<Modeling3dDTO> taskListData, TaskListDisplay taskListItem, GameObject taskListItemParentObj){
foreach (var task in taskListData)
Expand All @@ -342,7 +328,7 @@ private void CreateTaskListItem(List<Modeling3dDTO> taskListData, TaskListDispla
taskListItem.RawImage.texture = texture;
}
taskListItem.HasDownloaded.gameObject.SetActive(!string.IsNullOrWhiteSpace(task.DownloadFilePath));
var successCondition = task.Status.Contains("3") && task.Status.Contains("success");
var successCondition = task.Status.Contains("3") && task.Status.Contains("Success");
taskListItem.PreviewButton.gameObject.SetActive(successCondition);
taskListItem.DownloadButton.gameObject.SetActive(successCondition);

Expand All @@ -357,7 +343,6 @@ private void CreateTaskListItem(List<Modeling3dDTO> taskListData, TaskListDispla
obj.transform.SetSiblingIndex(lastChild.GetSiblingIndex() + 1);
obj.transform.SetPositionAndRotation(new Vector3(lastChild.position.x, lastChild.position.y - 150, lastChild.position.z), lastChild.rotation);
}

}
}
private void DestoryChildrenByType(GameObject parent, Type type)
Expand All @@ -378,7 +363,7 @@ public void DeleteTask(string taskId = null)
{
taskId = PlayerPrefs.GetString("currentTaskId");
}
Debug.Log($"Current TaskId {taskId}");
Debug.Log($"{TAG} Current TaskId {taskId}");
HMSModeling3dKitManager.Instance.DeleteTask(taskId);
}

Expand Down
Loading

0 comments on commit 0c37dd5

Please sign in to comment.