protected virtual void Update()
 {
     if (computer == null)
     {
         return;
     }
     SplineUser[] users = computer.GetComponents <SplineUser>();
     foreach (SplineUser user in users)
     {
         user.Rebuild(true);
     }
     computer.Rebuild();
     SceneView.RepaintAll();
 }
Exemplo n.º 2
0
 void Bake()
 {
     meshGen.Bake(isStatic, true);
     if (permanent && !copy)
     {
         SplineComputer meshGenComputer = meshGen.spline;
         if (permanent)
         {
             meshGenComputer.Unsubscribe(meshGen);
             DestroyImmediate(meshGen);
         }
         if (removeComputer)
         {
             if (meshGenComputer.GetComponents <Component>().Length == 2)
             {
                 DestroyImmediate(meshGenComputer.gameObject);
             }
             else
             {
                 DestroyImmediate(meshGenComputer);
             }
         }
     }
 }
Exemplo n.º 3
0
        private void Bake(MeshGenerator gen)
        {
            MeshFilter filter = gen.GetComponent <MeshFilter>();

            if (filter == null)
            {
                EditorUtility.DisplayDialog("Save error", "No mesh present in " + gen.name, "OK");
                return;
            }
            if (copy)
            {
                UnityEditor.MeshUtility.Optimize(filter.sharedMesh);
                Unwrapping.GenerateSecondaryUVSet(filter.sharedMesh);
            }
            else
            {
                gen.Bake(isStatic, true);
            }

            if (format == BakeMeshWindow.SaveFormat.OBJ)
            {
                MeshRenderer renderer = gen.GetComponent <MeshRenderer>();
                dirInfo = new DirectoryInfo(savePath);
                FileInfo[] files    = dirInfo.GetFiles(filter.sharedMesh.name + "*.obj");
                string     meshName = filter.sharedMesh.name;
                if (files.Length > 0)
                {
                    meshName += "_" + files.Length;
                }
                string path      = savePath + "/" + meshName + ".obj";
                string objString = Dreamteck.MeshUtility.ToOBJString(filter.sharedMesh, renderer.sharedMaterials);
                File.WriteAllText(path, objString);
                if (copy)
                {
                    string relativepath = "Assets" + path.Substring(Application.dataPath.Length);
                    AssetDatabase.ImportAsset(relativepath, ImportAssetOptions.ForceSynchronousImport);
                    filter.sharedMesh = AssetDatabase.LoadAssetAtPath <Mesh>(relativepath);
                }
            }

            if (format == BakeMeshWindow.SaveFormat.MeshAsset)
            {
                dirInfo = new DirectoryInfo(savePath);
                FileInfo[] files    = dirInfo.GetFiles(filter.sharedMesh.name + "*.asset");
                string     meshName = filter.sharedMesh.name;
                if (files.Length > 0)
                {
                    meshName += "_" + files.Length;
                }
                string path         = savePath + "/" + meshName + ".asset";
                string relativepath = "Assets" + path.Substring(Application.dataPath.Length);
                if (copy)
                {
                    Mesh assetMesh = Dreamteck.MeshUtility.Copy(filter.sharedMesh);
                    AssetDatabase.CreateAsset(assetMesh, relativepath);
                }
                else
                {
                    AssetDatabase.CreateAsset(filter.sharedMesh, relativepath);
                }
            }

            if (permanent && !copy)
            {
                SplineComputer meshGenComputer = gen.spline;
                if (permanent)
                {
                    meshGenComputer.Unsubscribe(gen);
                    Object.DestroyImmediate(gen);
                }
                if (removeComputer)
                {
                    if (meshGenComputer.GetComponents <Component>().Length == 2)
                    {
                        Object.DestroyImmediate(meshGenComputer.gameObject);
                    }
                    else
                    {
                        Object.DestroyImmediate(meshGenComputer);
                    }
                }
            }
        }