Skip to content
Snippets Groups Projects
Commit 8ec5de37 authored by ag15g21's avatar ag15g21
Browse files

Loads .obj into the scene

parent b2507a78
No related branches found
No related tags found
2 merge requests!9working premade rooms ui, also exportable as .exe (works),!8added #if UNITY_EDITOR #endif directives to all editor related scripts to...
...@@ -155,6 +155,23 @@ public class ImportScenery : MonoBehaviour ...@@ -155,6 +155,23 @@ public class ImportScenery : MonoBehaviour
} }
} }
public static GameObject GetNewMesh(string objPath, string mtlPath)
{
if (objPath == null || objPath == "" || !objPath.EndsWith(".obj"))
{
return null;
}
if (mtlPath == null || mtlPath == "" || !mtlPath.EndsWith(".mtl"))
{
return null;
}
// use objloader library to load in new game object from mesh filepath
GameObject newObj = new OBJLoader().Load(objPath, mtlPath);
return newObj;
}
static void InitialiseMesh(GameObject uninitialisedGameObject) static void InitialiseMesh(GameObject uninitialisedGameObject)
{ {
// add assign materials component to game object (will iterate through children to assign) // add assign materials component to game object (will iterate through children to assign)
......
...@@ -9,6 +9,7 @@ public class BuildRoom : MonoBehaviour { ...@@ -9,6 +9,7 @@ public class BuildRoom : MonoBehaviour {
public Button buildButton; // The submit/build room button public Button buildButton; // The submit/build room button
public GameObject interactableAudioSourcePrefab; public GameObject interactableAudioSourcePrefab;
public Dictionary<string, object> allData;
void Update() { void Update() {
// Check if all inputs have been entered and enable/disable the button // Check if all inputs have been entered and enable/disable the button
...@@ -58,7 +59,7 @@ public class BuildRoom : MonoBehaviour { ...@@ -58,7 +59,7 @@ public class BuildRoom : MonoBehaviour {
// } // }
public void OnButtonPress() { public void OnButtonPress() {
// Compile all the inputs into one dictionary // Compile all the inputs into one dictionary
Dictionary<string, object> allData = new Dictionary<string, object>(); allData = new Dictionary<string, object>();
foreach (LabelledInputValidator labelledInputValidator in labelledInputValidators) { foreach (LabelledInputValidator labelledInputValidator in labelledInputValidators) {
allData[labelledInputValidator.name] = labelledInputValidator.inputValidator.GetData(); allData[labelledInputValidator.name] = labelledInputValidator.inputValidator.GetData();
} }
...@@ -67,7 +68,10 @@ public class BuildRoom : MonoBehaviour { ...@@ -67,7 +68,10 @@ public class BuildRoom : MonoBehaviour {
// Load the VR prefab scene // Load the VR prefab scene
SceneManager.LoadScene("VRPrefabScene"); SceneManager.LoadScene("VRPrefabScene");
SceneManager.sceneLoaded += OnSceneLoaded;
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
// Extract speaker data from the dictionary // Extract speaker data from the dictionary
if (allData.ContainsKey("speakers")) if (allData.ContainsKey("speakers"))
{ {
...@@ -96,7 +100,14 @@ public class BuildRoom : MonoBehaviour { ...@@ -96,7 +100,14 @@ public class BuildRoom : MonoBehaviour {
} }
} }
// TODO: Handle .obj and .mtl files // Handles .obj and .mtl files
Dictionary<string, object> objDict = (Dictionary<string, object>) allData["obj"];
string objPath = (string) objDict["path"];
Dictionary<string, object> mtlDict = (Dictionary<string, object>) allData["mtl"];
string mtlPath = (string) mtlDict["path"];
ImportScenery.ImportScene(ImportScenery.GetNewMesh(objPath, mtlPath));
} }
string DictionaryToString(Dictionary<string, object> dictionary, int depth = 0) { string DictionaryToString(Dictionary<string, object> dictionary, int depth = 0) {
......
...@@ -11,6 +11,9 @@ EditorBuildSettings: ...@@ -11,6 +11,9 @@ EditorBuildSettings:
- enabled: 1 - enabled: 1
path: Assets/Scenes/MenuInterface.unity path: Assets/Scenes/MenuInterface.unity
guid: 71ca599599e48294ea268eef3bfef344 guid: 71ca599599e48294ea268eef3bfef344
- enabled: 1
path: Assets/Prefabs/VRPrefabScene.unity
guid: 6929320f83fe53548ac8d17e96c11caa
m_configObjects: m_configObjects:
Unity.XR.Oculus.Settings: {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2} Unity.XR.Oculus.Settings: {fileID: 11400000, guid: bfa1182bd221b4ca89619141f66f1260, type: 2}
Unity.XR.WindowsMR.Settings: {fileID: 11400000, guid: dc5a169419fa04987b057f65238cf3ba, type: 2} Unity.XR.WindowsMR.Settings: {fileID: 11400000, guid: dc5a169419fa04987b057f65238cf3ba, type: 2}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment