示例#1
0
    public void LoadPC(MegaCachePointCloud mod, string filename, int first, int last, int step)
    {
        if (mod.image == null)
        {
            mod.image = ScriptableObject.CreateInstance <MegaCachePCImage>();
        }

        if (mod.image && mod.image.frames.Count > 0)
        {
            if (!EditorUtility.DisplayDialog("Add to or Replace", "Add new Frames to existing list, or Replace All", "Add", "Replace"))
            {
                mod.image.frames.Clear();
                mod.image.maxpoints = 0;
            }
        }

        if (step < 1)
        {
            step = 1;
        }

        for (int i = first; i <= last; i += step)
        {
            float a = (float)(i + 1 - first) / (last - first);
            if (!EditorUtility.DisplayCancelableProgressBar("Loading Clouds", "Frame " + i, a))
            {
                MegaCachePCFrame fr = mod.LoadFrame(filename, i);
                if (fr != null)
                {
                    mod.image.frames.Add(fr);

                    if (fr.points.Length > mod.image.maxpoints)
                    {
                        mod.image.maxpoints = fr.points.Length;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't Load File", "Could not load frame " + i + " of sequence! Import Stopped.", "OK");
                    break;
                }
            }
            else
            {
                break;
            }
        }

        EditorUtility.ClearProgressBar();
    }
示例#2
0
    public static void LoadFile(MegaCachePointCloud mod, string filename)
    {
        StreamReader stream     = File.OpenText(filename);
        string       entireText = stream.ReadToEnd();

        stream.Close();

        char[] splitIdentifier = { ',' };

        //StringReader reader = new StringReader(entireText);
        MegaCacheParticle.offset = 0;
        List <Vector3> pos   = new List <Vector3>();
        List <float>   inten = new List <float>();

        Vector3 p  = Vector3.zero;
        float   it = 0.0f;

        MegaCachePCFrame frame = new MegaCachePCFrame();

        while (true)
        {
            //string ps = reader.ReadLine();
            string ps = MegaCacheParticle.ReadLine(entireText);
            if (ps.Length == 0)
            {
                break;
            }

            string[] brokenString = ps.Split(splitIdentifier, 50);

            p.x = float.Parse(brokenString[0]);
            p.y = float.Parse(brokenString[1]);
            p.z = float.Parse(brokenString[2]);

            if (mod.yupimport)
            {
                p = AdjustYUp(p);
            }

            it = float.Parse(brokenString[3]);
            pos.Add(p);
            inten.Add(it);
        }

        frame.points    = pos.ToArray();
        frame.intensity = inten.ToArray();

        mod.image.frames.Add(frame);
    }
    public void LoadPC(MegaCachePointCloud mod, string filename, int first, int last, int step)
    {
        if ( mod.image == null )
        {
            mod.image = ScriptableObject.CreateInstance<MegaCachePCImage>();
        }

        if ( mod.image && mod.image.frames.Count > 0 )
        {
            if ( !EditorUtility.DisplayDialog("Add to or Replace", "Add new Frames to existing list, or Replace All", "Add", "Replace") )
            {
                mod.image.frames.Clear();
                mod.image.maxpoints = 0;
            }
        }

        if ( step < 1 )
            step = 1;

        for ( int i = first; i <= last; i += step )
        {
            float a = (float)(i + 1 - first) / (last - first);
            if ( !EditorUtility.DisplayCancelableProgressBar("Loading Clouds", "Frame " + i, a) )
            {
                MegaCachePCFrame fr = mod.LoadFrame(filename, i);
                if ( fr != null )
                {
                    mod.image.frames.Add(fr);

                    if ( fr.points.Length > mod.image.maxpoints )
                    {
                        mod.image.maxpoints = fr.points.Length;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Can't Load File", "Could not load frame " + i + " of sequence! Import Stopped.", "OK");
                    break;
                }
            }
            else
                break;
        }

        EditorUtility.ClearProgressBar();
    }
    public static void LoadFile(MegaCachePointCloud mod, string filename)
    {
        StreamReader stream = File.OpenText(filename);
        string entireText = stream.ReadToEnd();
        stream.Close();

        char[] splitIdentifier = { ',' };

        StringReader reader = new StringReader(entireText);

        List<Vector3> pos = new List<Vector3>();
        List<float> inten = new List<float>();

        Vector3 p = Vector3.zero;
        float	it = 0.0f;

        MegaCachePCFrame frame = new MegaCachePCFrame();

        while ( true )
        {
            string ps = reader.ReadLine();
            if ( ps.Length == 0 )
                break;

            string[] brokenString = ps.Split(splitIdentifier, 50);

            p.x = float.Parse(brokenString[0]);
            p.y = float.Parse(brokenString[1]);
            p.z = float.Parse(brokenString[2]);

            it = float.Parse(brokenString[3]);
            pos.Add(p);
            inten.Add(it);
        }

        frame.points = pos.ToArray();
        frame.intensity = inten.ToArray();

        mod.image.frames.Add(frame);
    }
    public MegaCachePCXYZFrame LoadFrame(string filename)
    {
        StreamReader stream = File.OpenText(filename);

        if (stream == null)
        {
            return(null);
        }

        string entireText = stream.ReadToEnd();

        stream.Close();

        entireText.Replace('\n', '\r');

        char[] splitIdentifier = { ' ' };

        //StringReader reader = new StringReader(entireText);
        MegaCacheParticle.offset = 0;

        List <Vector3> pos = new List <Vector3>();
        List <Color32> col = new List <Color32>();

        Vector3 p = Vector3.zero;
        Color32 c = new Color32(255, 255, 255, 255);

        MegaCachePCXYZFrame frame = new MegaCachePCXYZFrame();

        int sk = 0;

        while (true)
        {
            //string ps = reader.ReadLine();
            string ps = MegaCacheParticle.ReadLine(entireText);
            if (ps == null || ps.Length == 0)
            {
                break;
            }

            sk--;
            if (sk < 0)
            {
                string[] brokenString = ps.Split(splitIdentifier, 50);

                if (brokenString.Length == 6)
                {
                    p.x = float.Parse(brokenString[0]);
                    p.y = float.Parse(brokenString[1]);
                    p.z = float.Parse(brokenString[2]);

                    if (yupimport)
                    {
                        p = MegaCachePointCloud.AdjustYUp(p);
                    }

                    c.r = byte.Parse(brokenString[3]);
                    c.g = byte.Parse(brokenString[4]);
                    c.b = byte.Parse(brokenString[5]);

                    pos.Add(p * importscale);
                    col.Add(c);
                }
                sk = particleskip;
            }
        }

        frame.points = pos.ToArray();
        frame.color  = col.ToArray();

        //mod.image.frames.Add(frame);
        return(frame);
    }
示例#6
0
    public override void OnInspectorGUI()
    {
        MegaCachePointCloud mod = (MegaCachePointCloud)target;

        serializedObject.Update();

#if !UNITY_5 && !UNITY_2017 && !UNITY_2018
        EditorGUIUtility.LookLikeControls();
#endif

        EditorGUILayout.PropertyField(_prop_particle, new GUIContent("Particle System"));
        EditorGUILayout.PropertyField(_prop_importscale, new GUIContent("Import Scale"));
        EditorGUILayout.PropertyField(_prop_sizescale, new GUIContent("Size Scale"));

        mod.playscale = EditorGUILayout.FloatField("Play Scale", mod.playscale);
        mod.playsize  = EditorGUILayout.FloatField("Play Size", mod.playsize);
        //mod.color = EditorGUILayout.ColorField("Color", mod.color);

        EditorGUILayout.PropertyField(_prop_framenum, new GUIContent("Frame Num"));
        EditorGUILayout.PropertyField(_prop_time, new GUIContent("Time"));
        EditorGUILayout.PropertyField(_prop_animate, new GUIContent("Animate"));
        EditorGUILayout.PropertyField(_prop_fps, new GUIContent("Fps"));
        EditorGUILayout.PropertyField(_prop_speed, new GUIContent("Speed"));
        EditorGUILayout.PropertyField(_prop_loopmode, new GUIContent("Loop Mode"));


        EditorGUILayout.BeginVertical("box");
        mod.showdataimport = EditorGUILayout.Foldout(mod.showdataimport, "Data Import");

        if (mod.showdataimport)
        {
            EditorGUILayout.PropertyField(_prop_firstframe, new GUIContent("First"));
            EditorGUILayout.PropertyField(_prop_lastframe, new GUIContent("Last"));
            EditorGUILayout.PropertyField(_prop_skip, new GUIContent("Skip"));
            EditorGUILayout.PropertyField(_prop_yup, new GUIContent("Y Up Change"));

            //int val = 0;
            //mod.decformat = EditorGUILayout.IntSlider("Format name" + val.ToString("D" + mod.decformat) + ".csv", mod.decformat, 1, 6);
            //mod.namesplit = EditorGUILayout.TextField("Name Split Char", mod.namesplit);

            if (GUILayout.Button("Load Frames"))
            {
                string file = EditorUtility.OpenFilePanel("Point Cloud CSV File", mod.lastpath, "csv");

                if (file != null && file.Length > 1)
                {
                    mod.lastpath = file;
                    LoadPC(mod, file, mod.firstframe, mod.lastframe, mod.skip);
                }
            }
        }

        EditorGUILayout.EndVertical();

        string infstring = "";
        if (mod.image)
        {
            infstring  = "Current Memory: " + 0 + "KB";
            infstring += "\nMax Points: " + mod.image.maxpoints;
        }

        EditorGUILayout.HelpBox(infstring, MessageType.None);

        if (GUI.changed)
        {
            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(target);
        }
    }