예제 #1
0
 public void SaveSelectionAndBoxes(ImportedCloud orig)
 {
     prefix = orig.name;
     selection = orig.Selection.Select(slice => slice.name).ToList<string>();
     Matrix4x4 cloud2world = orig.transform.localToWorldMatrix;
     foreach(Transform box in orig.transform.FindChild("CutBoxes")) {
         boxes.Add( box.worldToLocalMatrix * cloud2world );
         boxNames.Add( box.name );
     }
 }
예제 #2
0
    public bool BoxesChanged(ImportedCloud orig)
    {
        // FIXME this is too sensitive
        #if false
        HashSet<Matrix4x4> oldBoxes = new HashSet<Matrix4x4>( boxes );
        HashSet<Matrix4x4> newBoxes = new HashSet<Matrix4x4>();

        Matrix4x4 cloud2world = orig.transform.localToWorldMatrix;
        foreach(Transform box in orig.transform.FindChild("CutBoxes"))
            newBoxes.Add(box.worldToLocalMatrix * cloud2world);
        return ! oldBoxes.SetEquals( newBoxes );
        #endif
        return false;
    }
예제 #3
0
    CloudCompactor(ImportedCloud cloud)
    {
        using(TemporaryPrefabInstance tmp = new TemporaryPrefabInstance(cloud)) {
            base_name = tmp.Instance.name;

            string targetFName = Prefs.CompactPrefab(base_name + "--loc");
            if (File.Exists( targetFName )) {
                Debug.LogWarning(string.Format("{0} is in the way when compacting the cloud. Remove to recompact",
                                        targetFName), AssetDatabase.LoadMainAssetAtPath(targetFName));
                return;
            }

            Debug.Log(string.Format("Compacting {0}", base_name));

            EnsureCutBoxes( tmp.Instance as GameObject );
            if (cutBoxHelpers != null && shadowBoxHelpers != null)
                CutToBoxes( tmp.Instance as GameObject );
            /*
             * - requires post-shuffle of the cut-bins
             * - shadows are separate BinMesh'es with their own bin
             *
             * Prefab:
             * - After cutting  need to create a prefab
             * - Look for the sound then as well
             *
             */

            foreach(Transform box in cutBoxes)
                ShuffleBin( Prefs.BoxBin(cloud.name, box.name));
            foreach(Transform box in shadowBoxes)
                ShuffleBin( Prefs.BoxBin(cloud.name, box.name));

            CreateCompactPrefab(cutBoxes, shadowBoxes, tmp.Instance as GameObject);
            // don't commit, any changes to tmp.Instance are interim, only for compaction to work
        }
    }
예제 #4
0
 public Slice(string line, ImportedCloud cloud)
 {
     this.cloud = cloud;
     string[] tokens = line.Split('\t');
     name = Path.GetFileNameWithoutExtension(tokens[0]);
     offset = int.Parse(tokens[1]);
     size = int.Parse(tokens[2]);
     selected = true;
 }
예제 #5
0
 public bool SelectionChanged(ImportedCloud orig)
 {
     HashSet<string> oldSelection = new HashSet<string>( selection );
     HashSet<string> newSelection = new HashSet<string>( orig.Selection.Select(slice => slice.name) );
     return ! oldSelection.SetEquals( newSelection );
 }
예제 #6
0
    void ImportCloud(string cloud_path, string bin_path, string prefab_path)
    {
        string baseName = Path.GetFileNameWithoutExtension(cloud_path);

        using (TemporaryObject tmp = new TemporaryObject(new GameObject(baseName, typeof(ImportedCloud))) ) {
            GameObject root = tmp.Instance as GameObject;
            GameObject previewGo = new GameObject("Preview", typeof(MeshFilter), typeof(MeshRenderer));
            previewGo.transform.parent = root.transform;
            new GameObject("CutBoxes").transform.parent = root.transform;

            iCloud = root.GetComponent<ImportedCloud>();
            // parse the list of slices from .cloud file
            List<Slice> sliceList = ParseCloud(cloud_path);
            // sort slices on size
            sliceList.Sort((slice1, slice2) => (slice2.size - slice1.size));
            iCloud.slices = sliceList.ToArray ();

            sliceSampleSize = Prefs.OrigPreviewSize / System.Math.Min( Prefs.PreviewSlicesCount, sliceList.Count );
            // shuffle individual slices and sample prefs.origPreviewSize from first prefs.previewSlicesCount slices
            // sampled points end up in meshConv
            ShuffleSlicesAndSample(bin_path);
            Material material
                = AssetDatabase.LoadAssetAtPath("Assets/Materials/FastPoint.mat", typeof(Material)) as Material;
            previewGo.GetComponent<MeshRenderer>().material = material;

            // generate preview mesh by sampling some number of points over the whole original
            Mesh mesh = meshConv.MakeMesh();
            mesh.name = baseName + "-preview";
            meshConv.Convert(mesh);
            // it's ok, it's just a preview mesh, this will stop Unity from complaining...
            mesh.RecalculateNormals();
            previewGo.GetComponent<MeshFilter>().mesh = mesh;

            iCloud.skin = AssetDatabase.LoadAssetAtPath("Assets/GUI/ExplodedGUI.GUISkin",typeof(GUISkin)) as GUISkin;

            // turn it -90 degrees...
            root.transform.Rotate(-90,0,0);

            // save the branch into the prefab
            IOExt.Directory.EnsureExists(Prefs.PrefabsPath);
            Object prefab = EditorUtility.CreateEmptyPrefab(prefab_path);
            EditorUtility.ReplacePrefab(root, prefab);
            // save mesh into prefab and attach it to the Preview game object
            AssetDatabase.AddObjectToAsset(mesh, prefab);

            // do this last, after the rest succeeded
            IOExt.Directory.EnsureExists(Prefs.ImportedPath);
            FileUtil.MoveFileOrDirectory(bin_path, Prefs.ImportedBin(bin_path));
            FileUtil.MoveFileOrDirectory(cloud_path, Prefs.ImportedCloud(cloud_path));
        }
    }