Beispiel #1
0
        void BakeMesh()
        {
            VoxelSystemGroup voxelSystemGroup = space.GetOrCreateSystem <VoxelSystemGroup>();

            if (space.EntityManager.Exists(world))
            {
                voxelSystemGroup.worldSpawnSystem.DestroyWorld(world);
            }
            //voxDatam.bakedMaterial = voxMaterial;
            world         = voxelSystemGroup.worldSpawnSystem.SpawnModel(float3.zero, voxDatam);
            bakedVoxDatam = voxDatam;
            space.EntityManager.SetComponentData(world,
                                                 new Unity.Transforms.NonUniformScale {
                Value = new float3(spawnScale, spawnScale, spawnScale)
            });
        }
Beispiel #2
0
        public static void SaveMesh(Mesh mesh, VoxDatam voxDatam)//, string name, bool makeNewInstance, bool optimizeMesh)
        {
            string name = voxDatam.name;

            if (name.Contains("Vox"))
            {
                name = name.Replace("Vox", "Model");
            }
            // bool makeNewInstance = true;
            //Debug.LogError("Saving with bones: " + mesh.bindposes.Length);
            BoneWeight[] newWeights = new BoneWeight[mesh.boneWeights.Length];
            for (int i = 0; i < mesh.boneWeights.Length; i++)
            {
                BoneWeight weight = mesh.boneWeights[i];
                if (mesh.boneWeights[i].boneIndex0 < 0 ||
                    mesh.boneWeights[i].boneIndex0 >= mesh.bindposes.Length)
                {
                    weight.boneIndex0 = 0;
                    Debug.LogError("Bone Index out of range: " + mesh.boneWeights[i].boneIndex0);
                }
                newWeights[i] = weight;
            }
            mesh.boneWeights = newWeights;
            string startFolder = AssetDatabase.GetAssetPath(voxDatam);

            startFolder = System.IO.Path.GetDirectoryName(startFolder);
            Debug.Log("Asset path of vox: " + startFolder);
            ///string startFolder = FileUtil.GetProjectRelativePath(assetPath);
            //Debug.Log("GetProjectRelativePath: " + startFolder);
            string path = EditorUtility.SaveFilePanel("Save Mesh Asset", startFolder, name, "asset");

            if (string.IsNullOrEmpty(path))
            {
                Debug.Log("Decided not to save.");
                return;
            }
            path = FileUtil.GetProjectRelativePath(path);

            //  Mesh meshToSave = (makeNewInstance) ? UnityEngine.Object.Instantiate(mesh) as Mesh : mesh;

            //if (optimizeMesh)
            //    MeshUtility.Optimize(meshToSave);
            AssetDatabase.CreateAsset(mesh, path);
            AssetDatabase.SaveAssets();
        }
Beispiel #3
0
 void OnGUI()
 {
     if (gameDatam == null)
     {
         GUILayout.Label("Re open.");
         return;
     }
     //gameDatam = EditorGUILayout.ObjectField(gameDatam, typeof(GameDatam), false) as GameDatam;
     //voxMaterial = EditorGUILayout.ObjectField(voxMaterial, typeof(Material), false) as Material;
     GUILayout.Label("Select a Vox Data.");
     Bootstrap.DebugMeshWeights = GUILayout.Toggle(Bootstrap.DebugMeshWeights, "Debug Mesh Weights");
     voxDatam = EditorGUILayout.ObjectField(voxDatam, typeof(VoxDatam), false) as VoxDatam;
     //if (voxDatam)
     //   voxDatam.skeleton = EditorGUILayout.ObjectField(voxDatam.skeleton, typeof(SkeletonDatam), false) as SkeletonDatam;
     // mesh = EditorGUILayout.ObjectField(mesh, typeof(Mesh), false) as Mesh;
     if (voxDatam)
     {
         if (space == null)
         {
             if (GUILayout.Button("Spawn Mesh"))
             {
                 InitECS();
                 BakeMesh();
             }
         }
         else
         {
             if (!space.EntityManager.Exists(world))
             {
                 if ((bakedVoxDatam != voxDatam) && GUILayout.Button("ReBake Mesh"))
                 {
                     BakeMesh();
                     Repaint();
                 }
             }
             else
             {
                 if (mesh == null)
                 {
                     GUILayout.Label("Fetching Mesh.");
                     FetchMesh();
                 }
                 if (mesh != null)
                 {
                     if (GUILayout.Button("Centre Mesh"))
                     {
                         CentreMesh();
                     }
                     if (GUILayout.Button("Rotate Mesh"))
                     {
                         RotateMesh();
                     }
                     if (GUILayout.Button("Save Mesh"))
                     {
                         SaveMesh();
                     }
                 }
             }
             if (GUILayout.Button("Despawn Mesh"))
             {
                 mesh = null;
                 DestroyECS();
             }
         }
     }
 }