diff --git a/vr-configurator/Assets/Scripts/Models/ChildModel.cs b/vr-configurator/Assets/Scripts/Models/ChildModel.cs index 7e242b2..9e6433c 100644 --- a/vr-configurator/Assets/Scripts/Models/ChildModel.cs +++ b/vr-configurator/Assets/Scripts/Models/ChildModel.cs @@ -5,20 +5,28 @@ using UnityEngine; // Data definition of ChildModel public class ChildModel : Model { - public string Port { get; private set; } + public string ParentPort { get; private set; } - public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, - Quaternion rotation, Vector3 scale, List ports = null, List colors = null) - : base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports, colors) + public ChildModel(string parentPort, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, + Quaternion rotation, Vector3 scale, List ports = null, List colors = null, bool passthrough = false) + : base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports, colors, passthrough) { - this.Port = port; + this.ParentPort = parentPort; } - public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, - Material material, List ports = null, List color = null) - : base(nameHuman, nameId, mesh, material, ports, color) + public ChildModel(string parentPort, string nameHuman, string nameId, Mesh mesh, + Material material, List ports = null, List color = null, bool passthrough = false) + : base(nameHuman, nameId, mesh, material, ports, color, passthrough) { - this.Port = port; + this.ParentPort = parentPort; + } + + // For Groups, no Mesh + public ChildModel(string parentPort, string nameHuman, string nameId, Material material, Vector3 offset, + Quaternion rotation, Vector3 scale, List ports = null, List colors = null, bool passthrough = false) + : base(nameHuman, nameId, new Mesh(), material, offset, rotation, scale, ports, colors, passthrough) + { + this.ParentPort = parentPort; } } diff --git a/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs index c3f323d..b766f38 100644 --- a/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs @@ -1,4 +1,5 @@ using System; +using UnityEngine; public class ChildModelBehaviour : ModelBehaviour { @@ -21,5 +22,21 @@ public class ChildModelBehaviour : ModelBehaviour Model = value; } } - + public ModelBehaviour Parent { get; set; } + + public Port GetParentPort() + { + Debug.Log($"Searching port for {name} with PortID {ChildModel.ParentPort} with parent {Parent}"); + foreach (Port parentPort in Parent.Model.Ports) + { + if (parentPort.PortID == ChildModel.ParentPort) + { + Debug.Log($"Found port for {name} with PortID {parentPort.PortID} {parentPort.PortName} for {ChildModel.ParentPort}"); + return parentPort; + } + } + Debug.LogWarning($"Didn't find port for {name} with PortID {ChildModel.ParentPort}"); + return null; + } + } diff --git a/vr-configurator/Assets/Scripts/Models/Definitions.cs b/vr-configurator/Assets/Scripts/Models/Definitions.cs index 1d8f690..e7c9970 100644 --- a/vr-configurator/Assets/Scripts/Models/Definitions.cs +++ b/vr-configurator/Assets/Scripts/Models/Definitions.cs @@ -96,14 +96,15 @@ public class Definitions public const string PORT_ERLBACH_77 = "portErlbach77"; public const string PORT_ERLBACH_78 = "portErlbach78"; public const string PORT_ERLBACH_79 = "portErlbach79"; - public const string PORT_ERL_RIM_LH = "erlRimLH"; - public const string PORT_ERL_RIM_LV = "erlRimLV"; - public const string PORT_ERL_RIM_RV = "erlRimRV"; - public const string PORT_ERL_RIM_RH = "erlRimRH"; - public const string PORT_ERL_TIRE_LH = "erlTire"; - public const string PORT_ERL_TIRE_LV = "tire1"; - public const string PORT_ERL_TIRE_RH = "tire2"; - public const string PORT_ERL_TIRE_RV = "tire3"; + public const string PORT_ERL_RIMS = "erlRims"; + public const string PORT_ERL_RIM_LH = "erlRimLinksHinten"; + public const string PORT_ERL_RIM_LV = "erlRimLinksVorne"; + public const string PORT_ERL_RIM_RV = "erlRimRechtsVorne"; + public const string PORT_ERL_RIM_RH = "erlRimRechtsHinten"; + public const string PORT_ERL_TIRE_LH = "erlTireLinksHinten"; + public const string PORT_ERL_TIRE_LV = "erlTireLinksVorne"; + public const string PORT_ERL_TIRE_RV = "erlTireRechtsVorne"; + public const string PORT_ERL_TIRE_RH = "erlTireRechtsHinten"; public const string PORT_ERLBACH_Body = "body"; public const string PORT_ERLBACH_Bumper = "portErlbach85"; public const string PORT_ERLBACH_FrontBumper = "portErlbach86"; diff --git a/vr-configurator/Assets/Scripts/Models/Model.cs b/vr-configurator/Assets/Scripts/Models/Model.cs index b7f4dd7..e167ca2 100644 --- a/vr-configurator/Assets/Scripts/Models/Model.cs +++ b/vr-configurator/Assets/Scripts/Models/Model.cs @@ -9,6 +9,7 @@ public class Model public Material Material { get; internal set; } // skin public List Color { get; set; } // koleur + public readonly bool Passthrough; //whether this passes through color public readonly List Ports; @@ -17,7 +18,7 @@ public class Model public readonly Vector3 Scale; public Model(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, - Quaternion rotation, Vector3 scale, List ports = null, List color = null) + Quaternion rotation, Vector3 scale, List ports = null, List color = null, bool passthrough = false) { this.NameHuman = nameHuman; this.NameId = nameId; @@ -28,8 +29,9 @@ public class Model this.Rotation = rotation; this.Scale = scale; this.Color = color; + this.Passthrough = passthrough; } - public Model(string nameHuman, string nameId, Mesh mesh, Material material, List ports = null, List color = null) + public Model(string nameHuman, string nameId, Mesh mesh, Material material, List ports = null, List color = null, bool passthrough = false) { this.NameHuman = nameHuman; this.NameId = nameId; @@ -40,6 +42,7 @@ public class Model this.Rotation = Quaternion.identity; this.Scale = Vector3.one; this.Color = color; + this.Passthrough = passthrough; } public bool HasColor() @@ -51,10 +54,5 @@ public class Model { return Ports != null && Ports.Count > 0; } - - public void AddPort(Port port) - { - Ports.Add(port); - } } diff --git a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs index f3437c0..a637655 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs @@ -5,7 +5,7 @@ using UnityEngine; /// /// Base for BaseModelBehaviour and ChildModelBehaviour /// -public class ModelBehaviour : MonoBehaviour +public class ModelBehaviour : MonoBehaviour, IResettable { public ModelManager ModelManager; private Model _model; @@ -22,11 +22,35 @@ public class ModelBehaviour : MonoBehaviour _model = value; } } //should be verified - private readonly List _children = new List(); - private MeshFilter _meshFilter; - private MeshRenderer _meshRenderer; - - private Color Color = Color.black; + readonly List _children = new List(); + MeshFilter _meshFilter; + MeshRenderer _meshRenderer; + + Color _color = Color.black; + Color Color + { + get + { + return _color; + } + set + { + var clonedMaterial = new Material(_meshRenderer.material); //clone da sonst alle anderen mit dem mat auch colorchanged werden + clonedMaterial.color = value; + _meshRenderer.material = clonedMaterial; + Debug.Log($"{name}: Set color from {_color} to {value}"); + _color = value; + if (Model.Passthrough) + { + Debug.Log($"{name}: Passthrough {_children.Count}"); + foreach (GameObject go in _children) + { + Debug.Log($"{name}: coloring {go.name}"); + go.GetComponent().Color = value; + } + } + } + } void Start() { @@ -45,26 +69,26 @@ public class ModelBehaviour : MonoBehaviour void UpdateModel(Model newModel) { + Debug.Log($"UpdateModel: {name} updates from {(Model == null ? "null" : Model.NameId)} to {newModel.NameId}"); Init(); // I love race conditions if (newModel is BaseModel) { - this.name = "BaseModel:" + newModel.NameId; + name = "BaseModel:" + newModel.NameId; } else if (newModel is ChildModel cModel) { - this.name = cModel.Port + ":" + newModel.NameId; + Debug.Log($"UpdateModel Name: {name} to {cModel.ParentPort}:{newModel.NameId}"); + name = cModel.ParentPort + ":" + newModel.NameId; } //unapply previous model offset if (Model != null) { - Debug.Log($"Model {name} reset old {Model} offsets."); + Debug.Log($"UpdateModel: Model {name} reset old {Model} offsets."); transform.localPosition -= Model.Offset; transform.localRotation *= Quaternion.Inverse(Model.Rotation); transform.localScale -= Model.Scale; } - Debug.Log($"Model {name} update to new {newModel} Model."); - //kill old children foreach (var compo in GetComponentsInChildren()) { @@ -72,15 +96,9 @@ public class ModelBehaviour : MonoBehaviour { continue; } - Debug.Log($"Destroying {name}'s Child {compo.gameObject.name}"); + Debug.Log($"UpdateModel: Destroying {name}'s Child {compo.gameObject.name}"); Destroy(compo.gameObject); // will be destroyed next frame - } - - //spawn new childPorts - if (newModel.HasPorts()) - { - Debug.Log($"Spawning {gameObject.name}'s ports"); - SpawnChildPorts(newModel); + _children.Remove(compo.gameObject); } //change ourselves _meshFilter.mesh = newModel.Mesh; @@ -90,6 +108,13 @@ public class ModelBehaviour : MonoBehaviour transform.localRotation = newModel.Rotation; transform.localScale = newModel.Scale; transform.localPosition += newModel.Offset; + + //spawn new childPorts + if (newModel.HasPorts()) + { + Debug.Log($"Spawning {gameObject.name}'s ports"); + SpawnChildPorts(newModel); + } } public void UpdateChild(int childNum, string id) @@ -100,7 +125,9 @@ public class ModelBehaviour : MonoBehaviour } Model.Ports[childNum].Unapply(_children[childNum].transform); //set new - _children[childNum].GetComponent().ChildModel = ModelManager.GetById(id); + var cmb = _children[childNum].GetComponent(); + cmb.ChildModel = ModelManager.GetById(id); + cmb.Parent = this; Model.Ports[childNum].Apply(_children[childNum].transform); } @@ -108,9 +135,9 @@ public class ModelBehaviour : MonoBehaviour /// Spawns all Port-GO's, should be called only on Model Switch after cleanup /// /// Model the New Model to spawn ports from - private void SpawnChildPorts(Model newModel) + void SpawnChildPorts(Model newModel) { - Debug.Log($"{newModel.NameId}: Spawning {this.name} count of {newModel.Ports.Count} Ports"); + Debug.Log($"SpawnChildPorts: {name} : {newModel.NameId} spawns {newModel.Ports.Count} Ports"); if (ModelManager == null) { Debug.LogError("ModelManager not found"); @@ -121,8 +148,8 @@ public class ModelBehaviour : MonoBehaviour { var port = newModel.Ports[i]; Debug.Log(i + ". Creating port " + port.PortID); - // bike:wheel:num - GameObject child = new GameObject(this.name + ":" + port.PortID + ":" + i); + // name is set in UpdateModel of own model + GameObject child = new GameObject("unattended child"); child.transform.SetParent(this.transform); //makes this an actual child child.transform.localPosition = Vector3.zero; //i love unity ChildModelBehaviour cmb = child.AddComponent(); @@ -136,9 +163,12 @@ public class ModelBehaviour : MonoBehaviour continue; } - Debug.Log($"POS {child.transform.gameObject.name} pos {child.transform.localPosition} {child.transform.rotation} {child.transform.localScale}"); + Debug.Log($"SET POS {child.transform.gameObject.name} pos {child.transform.localPosition} {child.transform.rotation} {child.transform.localScale}"); + cmb.Parent = this; cmb.ChildModel = childModel; + Debug.Log($"AFTER SET PRE PORT POS {child.transform.gameObject.name} pos {child.transform.localPosition} {child.transform.rotation} {child.transform.localScale}"); port.Apply(child.transform); // move to correct position + Debug.Log($"AFTER PORT POS {child.transform.gameObject.name} pos {child.transform.localPosition} {child.transform.rotation} {child.transform.localScale}"); } } @@ -159,16 +189,16 @@ public class ModelBehaviour : MonoBehaviour export += $"\"modelId\": \"{Model.NameId}\""; if(Model is ChildModel cm) { - export += $", \"portId\": \"{cm.Port}\""; + export += $", \"portId\": \"{cm.ParentPort}\""; } if (Model.HasColor()) { export += $", \"color\": \"{Color}\""; } if (!Model.HasPorts()) - { - return export; - } + { + return export; + } export += ", \"ports\": ["; for (int i = 0; i < Model.Ports.Count; i++) { @@ -203,24 +233,11 @@ public class ModelBehaviour : MonoBehaviour Debug.LogWarning($"PortIndex {portIndex} invalid: there are {_children.Count} children."); return; } - - var child = _children[portIndex]; - var meshRenderer = child.GetComponent(); - child.GetComponent().Color = color; - if (meshRenderer == null) - { - Debug.LogWarning($"MeshRenderer for {portIndex} is null, skipping color set"); - return; - } - // Klonen des Materials und Setzen der Farbe - var clonedMaterial = new Material(meshRenderer.material); - clonedMaterial.color = color; - meshRenderer.material = clonedMaterial; // Setzt den MeshRenderer auf den Klon - Debug.Log($"PortNum {portIndex}: Cloned Material and Set color to {color}"); + _children[portIndex].GetComponent().Color = color; } public void ClearChildren() { - Debug.Log("Removing Children..."); + Debug.Log($"Removing Children of {name}..."); foreach (var child in _children) { if (child != null) @@ -231,5 +248,10 @@ public class ModelBehaviour : MonoBehaviour _children.Clear(); Debug.Log("Removed."); } - + + public void ResetThis() + { + Debug.Log($"Resetting {name}..."); + ClearChildren(); + } } diff --git a/vr-configurator/Assets/Scripts/Models/ModelList.cs b/vr-configurator/Assets/Scripts/Models/ModelList.cs index 9a38439..904f43b 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelList.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelList.cs @@ -137,14 +137,11 @@ public class ModelList Port.Hidden(Definitions.PORT_ERLBACH_77, "idErlbachPart77", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 0f, 30f)), Port.Hidden(Definitions.PORT_ERLBACH_78, "idErlbachPart78", Vector3.zero), Port.Hidden(Definitions.PORT_ERLBACH_79, "idErlbachPart79", Vector3.zero), - Port.Hidden(Definitions.PORT_ERL_TIRE_LH, "LH", new Vector3(0f,0f,0f), Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), - Port.Choosable("Back Wheel Right", Definitions.PORT_ERL_RIM_LH, "idErlbachWheel_LH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), - Port.Hidden(Definitions.PORT_ERL_TIRE_LV, "LV", new Vector3(0f,0f,0f), Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), - Port.Choosable("Front Wheel Right", Definitions.PORT_ERL_RIM_LV, "idErlbachWheel_LV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), - Port.Hidden(Definitions.PORT_ERL_TIRE_RH, "RH", new Vector3(0f,0f,0f), Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), - Port.Choosable("Back Wheel Left", Definitions.PORT_ERL_RIM_RH, "idErlbachWheel_RH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), - Port.Hidden(Definitions.PORT_ERL_TIRE_RV, "RV", new Vector3(0f,0f,0f), Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), - Port.Choosable("Front Wheel Left", Definitions.PORT_ERL_RIM_RV, "idErlbachWheel_RV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_TIRE_LH, "erlTire1_LH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_TIRE_LV, "erlTire1_LV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_TIRE_RH, "erlTire1_RH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_TIRE_RV, "erlTire1_RV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Choosable("Rims", Definitions.PORT_ERL_RIMS, "erlRims_1", Vector3.zero, Quaternion.identity, 1f), Port.Choosable("Body", Definitions.PORT_ERLBACH_Body, "idErlbachPart84", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 0f, 100f)), Port.Choosable("Rear Bumper", Definitions.PORT_ERLBACH_Bumper, "idErlbachPart85", Vector3.zero, Quaternion.identity, 1f, new Vector3(20f, 0f, 0f)), Port.Hidden(Definitions.PORT_ERLBACH_Headlight_V_Cover, "idErlbachPart86", new Vector3(2.1f, 0f, 0f), Quaternion.identity, 1f, new Vector3(-10f, 0f, 0f)), @@ -161,11 +158,66 @@ public class ModelList }; public static readonly List ChildModels = new List() { - //Felge 1 + //Felgensets + new ChildModel( + Definitions.PORT_ERL_RIMS, + "Normal Rims", + "erlRims_1", + Resources.Load($"Material/AluminiumScratched"), + Vector3.zero, // offset to the port + Quaternion.identity, + Vector3.one, + new List + { + Port.Hidden(Definitions.PORT_ERL_RIM_LH, "erlRim1_LH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_LV, "erlRim1_LV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RH, "erlRim1_RH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RV, "erlRim1_RV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + }, + DefaultColors, + true + ), + new ChildModel( + Definitions.PORT_ERL_RIMS, + "Sport Rims", + "erlRims_2", + Resources.Load($"Material/AluminiumScratched"), + Vector3.zero, // offset to the port + Quaternion.identity, + Vector3.one, + new List + { + Port.Hidden(Definitions.PORT_ERL_RIM_LH, "erlRim2_LH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_LV, "erlRim2_LV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RH, "erlRim2_RH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RV, "erlRim2_RV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + }, + DefaultColors, + true + ), + new ChildModel( + Definitions.PORT_ERL_RIMS, + "Elegance Rims", + "erlRims_3", + Resources.Load($"Material/AluminiumScratched"), + Vector3.zero, // offset to the port + Quaternion.identity, + Vector3.one, + new List + { + Port.Hidden(Definitions.PORT_ERL_RIM_LH, "erlRim3_LH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_LV, "erlRim3_LV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, -30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RH, "erlRim3_RH", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + Port.Hidden(Definitions.PORT_ERL_RIM_RV, "erlRim3_RV", Vector3.zero, Quaternion.identity, 1f, new Vector3(0f, 30f, 0f)), + }, + DefaultColors, + true + ), + // Sport new ChildModel( Definitions.PORT_ERL_RIM_RH, "Sport Rim", - "radRH", + "erlRim2_RH", Resources.Load($"Model/ERLbach/Felge1"), Resources.Load($"Material/AluminiumScratched"), new Vector3(60f, 65f, -15f), // offset to the port @@ -177,7 +229,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_RV, "Sport Rim", - "radRV", + "erlRim2_RV", Resources.Load($"Model/ERLbach/Felge1"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-105f, 65f, -15f), // offset to the port @@ -189,7 +241,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_LV, "Sport Rim", - "radLV", + "erlRim2_LV", Resources.Load($"Model/ERLbach/Felge1"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-105f, -30f, -15f), // offset to the port @@ -201,7 +253,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_LH, "Sport Rim", - "rimLH", + "erlRim2_LH", Resources.Load($"Model/ERLbach/Felge1"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-60f, -30f, -15f), // offset to the port @@ -210,11 +262,11 @@ public class ModelList null, DefaultColors ), - //Felge 2 + // Elegance new ChildModel( Definitions.PORT_ERL_RIM_RH, "Elegance Rim", - "erlRimRH3", + "erlRim3_RH", Resources.Load($"Model/ERLbach/Felge3"), Resources.Load($"Material/AluminiumScratched"), new Vector3(60f, 65f, -15f), // offset to the port @@ -226,7 +278,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_RV, "Elegance Rim", - "erlRimRV3", + "erlRim3_RV", Resources.Load($"Model/ERLbach/Felge3"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-105f, 65f, -15f), // offset to the port @@ -238,7 +290,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_LV, "Elegance Rim", - "erlRimLV3", + "erlRim3_LV", Resources.Load($"Model/ERLbach/Felge3"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-105f, -30f, -15f), // offset to the port @@ -250,7 +302,7 @@ public class ModelList new ChildModel( Definitions.PORT_ERL_RIM_LH, "Elegance Rim", - "erlRimLH3", + "erlRim3_LH", Resources.Load($"Model/ERLbach/Felge3"), Resources.Load($"Material/AluminiumScratched"), new Vector3(-60f, -30f, -15f), // offset to the port @@ -259,6 +311,7 @@ public class ModelList null, DefaultColors ), + // GRILL new ChildModel( Definitions.PORT_ERLBACH_GRILL, "Grille Elegance", @@ -389,14 +442,14 @@ public class ModelList new ModelElement( Definitions.PORT_ERLBACH_77, "Erlbach Part 77", "idErlbachPart77", Resources.Load($"Material/PVC"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), new ModelElement( Definitions.PORT_ERLBACH_78, "Erlbach Part 78", "idErlbachPart78", Resources.Load($"Material/PVC"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), new ModelElement( Definitions.PORT_ERLBACH_79, "Erlbach Part 79", "idErlbachPart79", Resources.Load($"Material/PVC"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), - new ModelElement( Definitions.PORT_ERL_TIRE_LH, "Tire LH", "LH", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), - new ModelElement( Definitions.PORT_ERL_RIM_LH, "Standard Rim", "idErlbachWheel_LH", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), - new ModelElement( Definitions.PORT_ERL_TIRE_LV, "Tire LV", "LV", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), - new ModelElement( Definitions.PORT_ERL_RIM_LV, "Standard Rim", "idErlbachWheel_LV", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), - new ModelElement( Definitions.PORT_ERL_TIRE_RH, "Tire RH", "RH", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), - new ModelElement( Definitions.PORT_ERL_RIM_RH, "Standard Rim", "idErlbachWheel_RH", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), - new ModelElement( Definitions.PORT_ERL_TIRE_RV, "Tire RV", "RV", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), - new ModelElement( Definitions.PORT_ERL_RIM_RV, "Standard Rim", "idErlbachWheel_RV", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), + new ModelElement( Definitions.PORT_ERL_TIRE_LH, "Tire LH", "erlTire1_LH", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), + new ModelElement( Definitions.PORT_ERL_RIM_LH, "Standard Rim", "erlRim1_LH", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), + new ModelElement( Definitions.PORT_ERL_TIRE_LV, "Tire LV", "erlTire1_LV", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), + new ModelElement( Definitions.PORT_ERL_RIM_LV, "Standard Rim", "erlRim1_LV", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), + new ModelElement( Definitions.PORT_ERL_TIRE_RH, "Tire RH", "erlTire1_RH", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), + new ModelElement( Definitions.PORT_ERL_RIM_RH, "Standard Rim", "erlRim1_RH", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), + new ModelElement( Definitions.PORT_ERL_TIRE_RV, "Tire RV", "erlTire1_RV", Resources.Load($"Material/CarTire"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), + new ModelElement( Definitions.PORT_ERL_RIM_RV, "Standard Rim", "erlRim1_RV", Resources.Load($"Material/AluminiumScratched"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), new ModelElement( Definitions.PORT_ERLBACH_Body, "Body", "idErlbachPart84", Resources.Load($"Material/AluminiumPolished"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), new ModelElement( Definitions.PORT_ERLBACH_Bumper, "Rear Bumper", "idErlbachPart85", Resources.Load($"Material/AluminiumPolished"), Vector3.zero, Quaternion.identity, Vector3.one, null, DefaultColors ), new ModelElement( Definitions.PORT_ERLBACH_Headlight_V_Cover, "Headlight Cover", "idErlbachPart86", Resources.Load($"Material/AluminiumPolished"), Vector3.zero, Quaternion.identity, Vector3.one, null, null ), diff --git a/vr-configurator/Assets/Scripts/Models/ModelManager.cs b/vr-configurator/Assets/Scripts/Models/ModelManager.cs index 956cda9..d3ad94f 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelManager.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelManager.cs @@ -73,7 +73,7 @@ public class ModelManager : MonoBehaviour, IResettable void RegisterChildModel(ChildModel model) { - Debug.Log($"Registering {model.NameId} for Port {model.Port} ({model})"); + Debug.Log($"Registering {model.NameId} for Port {model.ParentPort} ({model})"); //childModelDict if (_childModelDict.ContainsKey(model.NameId)) { @@ -83,21 +83,21 @@ public class ModelManager : MonoBehaviour, IResettable _childModelDict[model.NameId] = model; //portDict - if (string.IsNullOrEmpty(model.Port)) + if (string.IsNullOrEmpty(model.ParentPort)) { Debug.LogWarning("Model " + model.NameId + " has no Port! [portDict] Skipping..."); return; } - if (!_portDict.ContainsKey(model.Port)) + if (!_portDict.ContainsKey(model.ParentPort)) { - _portDict.Add(model.Port, new HashSet()); + _portDict.Add(model.ParentPort, new HashSet()); } - if (_portDict[model.Port].Contains(model)) + if (_portDict[model.ParentPort].Contains(model)) { Debug.LogWarning("Model " + model.NameId + " already registered! [portDict] Skipping..."); return; } - _portDict[model.Port].Add(model); + _portDict[model.ParentPort].Add(model); } void RegisterBaseModel(BaseModel baseModel) @@ -132,22 +132,20 @@ public class ModelManager : MonoBehaviour, IResettable public void LoadSelectedModel(BaseModel baseModel) { + Debug.Log($"Model {baseModel.NameHuman} started loading."); //create if doesn't exist - if (this.baseModelGO == null) + if (baseModelGO == null) { - // Create new GameObject for the baseModel - this.baseModelGO = new GameObject(baseModel.NameId) - { - name = baseModel.NameId, - }; - this.baseModelGO.AddComponent(); - // Positioning - this.baseModelGO.transform.position = new Vector3(0, 0, 1); - this.baseModelGO.transform.localRotation = Quaternion.Euler(0, 90, 0); - this.baseModelGO.SetActive(true); + Debug.Log($"Spawning BaseModelGO."); + baseModelGO = new GameObject(baseModel.NameId); + baseModelGO.AddComponent(); + baseModelGO.transform.position = new Vector3(0, 0, 1); + baseModelGO.transform.localRotation = Quaternion.Euler(0, 90, 0); + baseModelGO.SetActive(true); + Debug.Log($"Spawned BaseModelGO."); } - this.baseModelGO.GetComponent().BaseModel = baseModel; - this.baseModelGO.SetActive(true); + baseModelGO.GetComponent().BaseModel = baseModel; + baseModelGO.SetActive(true); Debug.Log($"Model {baseModel.NameHuman} lock and loaded."); } @@ -176,23 +174,9 @@ public class ModelManager : MonoBehaviour, IResettable tw.Write(BaseModelBehaviour.ExportJson()); tw.Close(); } - public Port GetPortForChildModel(ChildModel childModel) - { - foreach (var port in BaseModel.Ports) - { - if (port.PortID == childModel.Port) - { - return port; - } - } - Debug.Log($"No child model found for port {childModel.Port}"); - return null; - - } public void ResetThis() { OpenSelector(); - BaseModelBehaviour.ClearChildren(); } } diff --git a/vr-configurator/Assets/Scripts/UI/ChildModelSelector.cs b/vr-configurator/Assets/Scripts/UI/ChildModelSelector.cs index 7207ab6..57cf752 100644 --- a/vr-configurator/Assets/Scripts/UI/ChildModelSelector.cs +++ b/vr-configurator/Assets/Scripts/UI/ChildModelSelector.cs @@ -37,7 +37,7 @@ public class ChildModelSelector : MonoBehaviour, IResettable foreach (var childModel in childModels) { Debug.Log($"Adding {childModel}"); - GameObject go = Spawn.GO(cmpPrefab, daddy.transform, Vector3.zero, "picker:" + childModel.Port + ":" + childModel.NameId); + GameObject go = Spawn.GO(cmpPrefab, daddy.transform, Vector3.zero, "picker:" + childModel.ParentPort + ":" + childModel.NameId); go.SetActive(true); go.GetNamedChild("Icon").GetComponent().sprite = Resources.Load($"sprites/" + childModel.NameId); TextMeshProUGUI[] label = go.GetComponentsInChildren();