Exemplo n.º 1
0
    /*
     * Save ourselves on quit. We do this because this script is really a cloud authoring tool.
     */
    void OnApplicationQuit()
    {
        /*
        if (!enabled)
            return;

        if (initiallyEnabledSet.SetEquals ((new List<Slice> (slices).FindAll (s => s.selected)))
            && initiallyEnabledSet2.SetEquals ((new List<Slice> (slices).FindAll (s => s.selectedForCamview)))
            && transform.worldToLocalMatrix == initialMatrix) {
            Debug.Log("Selection/transform haven't changed, don't have to save");
            return;
        }

        Debug.Log("Selection or transform changed, saving");
        */
        StopAllCoroutines();

        if (detailBranch)
            DestroyImmediate(detailBranch);
        if (binReader != null) {
            binReader.Close();
            binReader = null;
        }
        Object prefab = EditorUtility.GetPrefabParent (gameObject);
        EditorUtility.ReplacePrefab (gameObject, prefab);
    }
Exemplo n.º 2
0
 public ReaderTest()
 {
     reader = new CloudStream.Reader( TmpFileStream() );
 }
Exemplo n.º 3
0
    void Start()
    {
        binReader = new CloudStream.Reader(new FileStream(ExplodedPrefs.ImportedBin(name), FileMode.Open, FileAccess.Read));

        /* pre-calculate selection size */
        UpdateSelectionSize();

        /* pre-allocate some things */

        /* start the pool (actual pooled objects will be created as necessary) */
        detailBranch = new GameObject("Detail");
        ProceduralUtils.InsertAtOrigin(detailBranch.transform, transform);

        guiMessage = "";
        orbit = Object.FindObjectOfType(typeof(MouseOrbit)) as MouseOrbit;

        /* order slices by size */
        System.Array.Sort(slices, (s1,s2) => (s2.size - s1.size));

        /*
        initiallyEnabledSet = new HashSet<Slice>( new List<Slice>(slices).FindAll(s => s.selected) );
        initiallyEnabledSet2 = new HashSet<Slice> (new List<Slice> (slices).FindAll (s => s.selectedForCamview));
        initialMatrix = transform.worldToLocalMatrix;
        */
    }
Exemplo n.º 4
0
    public virtual void Awake()
    {
        // add detail node if don't have one already
        detail = transform.FindChild("Detail");
        if (detail == null) {
            detail = new GameObject("Detail").transform;
            ProceduralUtils.InsertAtOrigin(detail, transform);
        }

        try {
            reader = new CloudStream.Reader( new FileStream( BinPath, FileMode.Open, FileAccess.Read ) );
        } catch (IOException) {
            enabled = false;
        }
    }
Exemplo n.º 5
0
    void ShuffleBin(string path)
    {
        using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) {
            CloudStream.Reader reader = new CloudStream.Reader(fs);
            CloudStream.Writer writer = new CloudStream.Writer(fs);

            byte[] tmp_i = new byte[CloudStream.pointRecSize] , tmp_j = new byte[CloudStream.pointRecSize];
            ShuffleUtility.WithSwap((int)fs.Length / CloudStream.pointRecSize,
                                    (i, j) => {
                reader.SeekPoint(i);
                tmp_i = reader.ReadBytes( tmp_i.Length);
                reader.SeekPoint(j);
                tmp_j = reader.ReadBytes( tmp_j.Length);
                writer.SeekPoint(j);
                writer.Write(tmp_i);
                writer.SeekPoint(i);
                writer.Write(tmp_j);
            });
        }
    }
Exemplo n.º 6
0
    void CutToBoxes(GameObject cloud_go)
    {
        // using linked list so we can change order on the fly
        ImportedCloud iCloud = cloud_go.GetComponent<ImportedCloud>();
        slices = new LinkedList<Slice>( iCloud.slices );

        maxTodoCount = cutBoxes.Count * Prefs.MaxCompactSize;
        done = 0;
        portionCount = 0;

        Progressor prog = new Progressor ("Cutting " + cloud_go.name + " according to boxes");

        // open the original file for reading
        origReader = new CloudStream.Reader( new FileStream( Prefs.ImportedBin(cloud_go.name) , FileMode.Open, FileAccess.Read));
        try {
            // since we get rid of full boxes and exhausted slices ...
            while( cutBoxHelpers.Count > 0 && slices.Count > 0 ) {
                // iterate over remaining slices
                LinkedListNode<Slice> slice_iter = slices.First;
                do {
                    // deal with this once slice ...
                    SortSlicePortion(slice_iter, cutBoxHelpers, shadowBoxHelpers);
                    prog.Progress( (float)done/(float)maxTodoCount, "Sorting...");
                } while (cutBoxHelpers.Count > 0 && (slice_iter = slice_iter.Next) != null);
                portionCount++;
            }
            // close remaining boxes
            foreach (BoxHelper box in cutBoxHelpers)
                box.Finish ();
            foreach (BoxHelper box in shadowBoxHelpers)
                box.Finish ();

        } finally {
            prog.Done();
        }
    }
Exemplo n.º 7
0
    public Mesh SampleMinMesh( GameObject go )
    {
        using( CloudStream.Reader reader =
              new CloudStream.Reader(new FileStream( Prefs.BoxBin( go.name ) , FileMode.Open)) ) {

            int size = (int)System.Math.Min( (long)Prefs.MinMeshSize, reader.PointCount );

            CloudMeshConvertor conv = new CloudMeshConvertor( size );
            Mesh mesh = conv.MakeMesh();
            reader.ReadPoints(conv.vBuffer, conv.cBuffer);
            conv.Convert(mesh);
            // shut up the editor about the "shader wants normals" nonsense
            mesh.RecalculateNormals();
            mesh.name = go.name + "-minMesh";
            go.GetComponent<MeshFilter>().sharedMesh = mesh;
            go.GetComponent<MeshRenderer>().sharedMaterial =
                AssetDatabaseExt.LoadAssetAtPath<Material>("Assets/Materials/TrillingFastPoint.mat");
            return mesh;
        }
    }
Exemplo n.º 8
0
    void ShuffleSlicesAndSample(string bin_path)
    {
        using (FileStream stream = File.Open( bin_path, FileMode.Open)) {
            CloudStream.Reader reader = new CloudStream.Reader(stream);
            try {
                foreach(Slice slice in prog.Iterate(iCloud.slices)) {
                    int byteCount = slice.size * CloudStream.pointRecSize;
                    byte[] sliceBytes = new byte[byteCount];

                    reader.SeekPoint(slice.offset, SeekOrigin.Begin);
                    stream.Read( sliceBytes, 0, byteCount );

                    byte[] tmp = new byte[CloudStream.pointRecSize];
                    ShuffleUtility.WithSwap(slice.size, (i, j) =>
                    {
                        /*
                         * This is the fastest way I found to swap 16-byte long chunks in memory (tried MemoryStream and
                         * byte-by-byte swap loop).
                         */
                        System.Buffer.BlockCopy(sliceBytes, i * CloudStream.pointRecSize, tmp, 0, CloudStream.pointRecSize);
                        System.Buffer.BlockCopy(sliceBytes, j * CloudStream.pointRecSize, sliceBytes, i * CloudStream.pointRecSize, CloudStream.pointRecSize);
                        System.Buffer.BlockCopy(tmp, 0, sliceBytes, j * CloudStream.pointRecSize, CloudStream.pointRecSize);
                        // 'i' runs backwards from pointCount-1 to 0
                    });

                    reader.SeekPoint(slice.offset, SeekOrigin.Begin);
                    stream.Write( sliceBytes, 0, byteCount );

                    // may be sample
                    CloudStream.Reader mem = new CloudStream.Reader(new MemoryStream(sliceBytes));
                    int sampleSize = Math.Min( sliceSampleSize, (int)mem.PointCount );
                    mem.DecodePoints(meshConv, sampleSize );
                }
            } finally {
                prog.Done("Shuffled orig bin in {tt}");
            }
        } // using(stream)
    }