Add Ability for predefined Offset, Rotation, Scale on Models

This commit is contained in:
Tim
2025-04-29 01:36:00 +02:00
parent d6c1bc4521
commit 28ecedf3b7
6 changed files with 43 additions and 9 deletions

View File

@@ -4,7 +4,12 @@ using UnityEngine;
// Data definition of BaseModel
public class BaseModel : Model
{
public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, List<Port> ports = null)
public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List<Port> ports)
: base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports)
{
}
public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, List<Port> ports)
: base(nameHuman, nameId, mesh, material, ports)
{

View File

@@ -6,6 +6,12 @@ public class ChildModel : Model
{
public string port { get; private set; } // port
public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List<Port> ports = null)
: base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports)
{
this.port = port;
}
public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, List<Port> ports = null)
: base(nameHuman, nameId, mesh, material, ports)
{

View File

@@ -7,10 +7,24 @@ public class Model
public string nameId { get; internal set; } // JSON export name, should be unique
public Mesh mesh { get; internal set; } // obj/fbx
public Material material { get; internal set; } // skin
public readonly List<Port> ports;
public readonly Vector3 offset;
public readonly Quaternion rotation;
public readonly Vector3 scale;
public Model(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List<Port> ports = null)
{
this.nameHuman = nameHuman;
this.nameId = nameId;
this.mesh = mesh;
this.material = material;
this.ports = ports;
this.offset = offset;
this.rotation = rotation;
this.scale = scale;
}
public Model(string nameHuman, string nameId, Mesh mesh, Material material, List<Port> ports = null)
{
this.nameHuman = nameHuman;
@@ -18,6 +32,9 @@ public class Model
this.mesh = mesh;
this.material = material;
this.ports = ports;
this.offset = Vector3.zero;
this.rotation = Quaternion.identity;
this.scale = Vector3.one;
}
public bool hasPorts()

View File

@@ -19,7 +19,7 @@ public class ModelBehaviour : MonoBehaviour
set
{
_model = value;
UpdateModel( value);
UpdateModel(value);
}
} //should be verified
internal List<GameObject> children;
@@ -63,6 +63,9 @@ public class ModelBehaviour : MonoBehaviour
meshFilter.sharedMesh = _model.mesh;
meshRenderer.material = _model.material;
meshRenderer.sharedMaterial = _model.material;
transform.rotation = _model.rotation;
transform.localScale = _model.scale;
transform.localPosition += _model.offset;
}
public void UpdateChild(int childNum, string id)

View File

@@ -15,6 +15,9 @@ public class ModelList
"bike",
Resources.Load<Mesh>("Model/Bicycle/Models/Low-Poly Bicycle"),
new Material(Shader.Find("VR/SpatialMapping/Occlusion")),
Vector3.zero,
Quaternion.Euler(0,90,0),
Vector3.one,
new List<Port>
{
//please dont ask about the numbers
@@ -32,6 +35,9 @@ public class ModelList
"erlbach",
Resources.Load<Mesh>("Model/ERLbach/02.01.98.0000-ERLbach_vereinfacht"),
new Material(Shader.Find("VR/SpatialMapping/Occlusion")),
new Vector3(0,0,4f), //big car needs big space
Quaternion.Euler(-90f,0f,0f), //rotate correctly
new Vector3(0.03f,0.03f,0.03f), //model bisschen groß
new List<Port>
{
new Port(Definitions.PORT_ERLBACH_0, new Vector3(0f, 0f, 0f), "idErlbachPart0"),

View File

@@ -1,8 +1,5 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
public class ModelManager : MonoBehaviour
{
@@ -12,7 +9,7 @@ public class ModelManager : MonoBehaviour
public List<BaseModel> baseModelList; //available BaseModels
public GameObject baseModel; //current baseModel
public AutoModelSelector autoModelSelector;
public BaseModelSelector baseModelSelector;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
@@ -21,7 +18,7 @@ public class ModelManager : MonoBehaviour
portDict = new Dictionary<string, HashSet<ChildModel>>();
childModelDict = new Dictionary<string, ChildModel>();
baseModelList = new List<BaseModel>();
autoModelSelector = FindFirstObjectByType<AutoModelSelector>();
baseModelSelector = FindFirstObjectByType<BaseModelSelector>();
foreach (var baseModel in ModelList.BaseModels)
{