public ModelSceneObjectModel(ModelItemModel itemModel) : base(itemModel)
 {
     Parameter.Add(new PositionModel());
     Parameter.Add(new RotationModel());
     Parameter.Add(new ScaleModel());
     Parameter.Add(new ObjectColorModel());
     Parameter.Add(new TextureModel());
 }
Example #2
0
    private void ImportModels()
    {
        string     importPath = Application.dataPath + "/Import/" + "Models";
        GameObject Plane      = GameObject.CreatePrimitive(PrimitiveType.Plane);

        Plane.transform.rotation = Quaternion.Euler(new Vector3(-90, 0, 0));
        ModelItemModel planeModel = new ModelItemModel {
            DisplayName = "Plane",
            Mesh        = Plane.GetComponent <MeshFilter>().mesh,
            Materials   = Plane.GetComponentInChildren <MeshRenderer>().materials
        };

        GlobalSettingsModel.EditorModel.AllModelItemsModel.Add(planeModel);
        foreach (string file in Directory.GetFiles(importPath))
        {
            if (file.EndsWith(".obj"))
            {
                OBJLoader  objLoader = new OBJLoader();
                GameObject tmpObject = objLoader.Load(file).gameObject;
                try
                {
                    ModelItemModel model = new ModelItemModel();
                    model.DisplayName = tmpObject.name;
                    model.Mesh        = tmpObject.GetComponentInChildren <MeshFilter>().mesh;
                    model.Materials   = tmpObject.GetComponentInChildren <MeshRenderer>().materials;
                    GlobalSettingsModel.EditorModel.AllModelItemsModel.Add(model);
                }
                catch (Exception e)
                {
                    Debug.Log("An error has ocured during import of " + tmpObject.name + "\n" + e.Message + "\n" + e.StackTrace);
                }
                finally
                {
                    Destroy(tmpObject);
                }
            }
        }
        Debug.Log(GlobalSettingsModel.EditorModel.AllModelItemsModel.Length() + " Models imported");
    }