Esempio n. 1
0
        public static SnapshotModel ReadBinaryFile(BinaryReader br)
        {
            SnapshotModel model = new SnapshotModel();

            model.ReadBinary(br);
            return(model);
        }
Esempio n. 2
0
        public IndexedViewableAlpha GetSelection(Vec3f[] match, bool applymodifiers)
        {
            SnapshotModel modeledit = GetEditModel();

            if (modeledit != null)
            {
                return(modeledit.GetSelection(match, applymodifiers));
            }

            IndexedViewableAlpha viewable = null;

            foreach (SnapshotModel model in Models)
            {
                if (!model.objselected || !model.objvisible)
                {
                    continue;
                }
                IndexedViewableAlpha nview = model.GetSelection(match, applymodifiers, true);
                viewable = IndexedViewableAlpha.Attach(viewable, nview);
            }
            return(viewable);

            /*IndexedViewableAlpha viewable = null;
             *          foreach( SnapshotModel model in Models )
             *          {
             *                  IndexedViewableAlpha viewadd = model.GetSelection( match, applymodifiers );
             *                  viewable = IndexedViewableAlpha.CombineFat( viewable, viewadd );
             *          }
             *          return viewable;*/
        }
Esempio n. 3
0
        public void DeleteNoChangeData(SnapshotModel prev)
        {
            this.verts       = null;
            this.vertnormals = null;
            this.vertuids    = null;
            this.vertlabels  = null;

            this.groups[0] = null;
            this.groups[1] = null;
            this.groups[2] = null;
            this.groups[3] = null;
            this.groups    = null;

            this.facenormals[0] = null;
            this.facenormals[1] = null;
            this.facenormals    = null;

            this.nochange = true;
            this.prev     = prev;
        }
Esempio n. 4
0
        public static IndexedViewableAlpha MeshDiff(SnapshotScene snapshot0, SnapshotScene snapshot1, Vec3f[] verts, bool applymods)
        {
            SnapshotModel[] models0 = snapshot0.Models;
            SnapshotModel[] models1 = snapshot1.Models;

            IndexedViewableAlpha viewable = null;

            int i;
            int c = models1.Length;

            foreach (SnapshotModel model0 in models0)
            {
                int uid = model0.objuid;
                for (i = 0; i < c; i++)
                {
                    if (models1[i].objuid == uid)
                    {
                        break;
                    }
                }
                if (i == c)
                {
                    viewable += model0.GetViewable(verts, applymods); continue;
                }
                SnapshotModel model1 = models1[i];

                if (model0.GetEditCount() == model1.GetEditCount())
                {
                    continue;
                }
                IndexedViewableAlpha diff = SnapshotModel.MeshDiff(model0, model1, verts, applymods);
                viewable += diff;

                //IndexedViewableAlpha view0 = model0.GetViewable( verts, applymods );
                //IndexedViewableAlpha view1 = model1.GetViewable( verts, applymods );
                //viewable += view0 - view1;
            }

            return(viewable);
        }
Esempio n. 5
0
        public static IndexedViewableAlpha MeshIntersectAttach(SnapshotScene snapshot0, SnapshotScene snapshot1, Vec3f[] verts, bool applymods)
        {
            SnapshotModel[] models0 = snapshot0.Models;
            SnapshotModel[] models1 = snapshot1.Models;

            IndexedViewableAlpha viewable = null;

            int i;
            int c = models1.Length;

            foreach (SnapshotModel model0 in models0)
            {
                int uid = model0.objuid;
                for (i = 0; i < c; i++)
                {
                    if (models1[i].objuid == uid)
                    {
                        break;
                    }
                }
                if (i == c)
                {
                    continue;
                }
                SnapshotModel model1 = models1[i];

                if (model0.GetEditCount() == model1.GetEditCount())
                {
                    viewable = IndexedViewableAlpha.Attach(viewable, model0.GetViewable(verts, applymods));
                }
                else
                {
                    viewable = IndexedViewableAlpha.Attach(viewable, SnapshotModel.MeshIntersect(model0, model1, verts, applymods));
                }
            }

            return(viewable);
        }
Esempio n. 6
0
        public static IndexedViewableAlpha MeshIntersect(SnapshotModel model0, SnapshotModel model1, Vec3f[] match, bool applymods)
        {
            int nverts = model0.nverts;

            Vec3f[]              verts         = null;
            int[]                vertuids      = null;
            bool[]               vsel          = null;
            int[][]              visiblegroups = null;
            Vec4f[][]            colors        = { new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts] };
            float[]              pointsizes    = (model0.objedit ? pointsizes_edit : pointsizes_view).DeepCopy();
            float[]              linewidths    = (model0.objedit ? linewidths_edit : (model0.objselected ? linewidths_selected : linewidths_unselected)).DeepCopy();
            IndexedViewableAlpha viewable      = null;


            for (int i = 0; i < nverts; i++)
            {
                if (!model0.objvisible)
                {
                    colors[0][i] = colorobjhidden;
                    colors[1][i] = colorobjhidden;
                    colors[2][i] = colorobjhidden;
                    colors[3][i] = colorobjhidden;
                }
                else if (model0.objedit)
                {
                    colors[0][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected );
                    colors[1][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected );
                    colors[2][i] = colorface;
                    colors[3][i] = colorface;
                }
                else if (model0.objselected)
                {
                    if (model0.objactive)
                    {
                        colors[0][i] = colorobjactive;
                        colors[1][i] = colorobjactive;
                        colors[2][i] = colorface;
                        colors[3][i] = colorface;
                    }
                    else
                    {
                        colors[0][i] = colorobjselected;
                        colors[1][i] = colorobjselected;
                        colors[2][i] = colorface;
                        colors[3][i] = colorface;
                    }
                }
                else
                {
                    colors[0][i] = colorobjunselected;
                    colors[1][i] = colorobjunselected;
                    colors[2][i] = colorface;
                    colors[3][i] = colorface;
                }
            }

            List <GroupInfo>[] groups0          = model0.GetGroups();
            List <GroupInfo>[] groups1          = model1.GetGroups();
            List <int>[]       lstvisiblegroups = new List <int>[] {
                new List <int>(groups0[0].Count),
                new List <int>(groups0[1].Count * 2),
                new List <int>(groups0[2].Count * 3),
                new List <int>(groups0[3].Count * 4)
            };
            int[] uids0 = model0.GetVertUIDs();
            int[] uids1 = model1.GetVertUIDs();

            for (int igroups = 0; igroups < 4; igroups++)
            {
                List <int> lstcurrent = lstvisiblegroups[igroups];

                int i0 = 0;
                int i1 = 0;
                List <GroupInfo> grps0 = groups0[igroups];
                List <GroupInfo> grps1 = groups1[igroups];
                int c0 = grps0.Count;
                int c1 = grps1.Count;

                while (i0 < c0 && i1 < c1)
                {
                    GroupInfo g0 = grps0[i0];
                    GroupInfo g1 = grps1[i1];
                    string    k0 = g0.GetKeyNoVis(uids0);
                    string    k1 = g1.GetKeyNoVis(uids1);

                    int comp = k0.CompareTo(k1);
                    if (comp == 1)
                    {
                        i1++; continue;
                    }
                    if (comp == -1)
                    {
                        i0++; continue;
                    }
                    lstcurrent.AddRange(g0.inds);
                    i0++;
                    i1++;
                }
            }
            visiblegroups = new int[][] { lstvisiblegroups[0].ToArray(), lstvisiblegroups[1].ToArray(), lstvisiblegroups[2].ToArray(), lstvisiblegroups[3].ToArray() };

            verts    = model0.GetVerts().CloneArray();
            vertuids = model0.GetVertUIDs().CloneArray();
            if (model0.objedit)
            {
                vsel = model0.isvertselected.CloneArray();
            }
            else
            {
                vsel = new bool[nverts];
            }



            viewable = new IndexedViewableAlpha(verts, colors, visiblegroups, pointsizes, linewidths, groupsizes.CloneArray(), vertuids, vsel);

            if (match != null)
            {
                viewable = history.MakeVertsConsistent(viewable, match);
            }

            if (applymods)
            {
                foreach (Modifier m in model0.modifiers)
                {
                    if (m is ModifierMirror)
                    {
                        ModifierMirror mirror = (ModifierMirror)m;
                        viewable += viewable.CreateMirrorData_Each(mirror.usex, mirror.usey, mirror.usez, mirror.mergethreshold);
                    }
                }
            }

            return(viewable);
        }
Esempio n. 7
0
        public SnapshotScene(string sPLYFilename, int timeindex, string command, string opts, SnapshotScene prev, bool nochange, bool cmdobjlist)
        {
            this.file      = MiscFileIO.GetFileNameOnly(sPLYFilename);
            this.timeindex = timeindex;
            this.command   = command;
            this.opts      = opts;
            this.prevscene = prev;

            cselected = 0;
            cedited   = 0;

            string[] objnames;
            bool[]   objvisibles;
            bool[]   objselecteds;
            bool[]   objactives;
            bool[]   objedits;
            string[] objplyfilenames;

            using (Stream s = new FileStream(sPLYFilename, FileMode.Open))
            {
                string plyline = FileIOFunctions.ReadTextString(s);
                if (plyline != "ply")
                {
                    throw new ArgumentException("SnapshotScene: Specified file is not .ply file");
                }

                ncameras = 0;
                nmodels  = 0;
                bool header = true;
                while (header)
                {
                    string cmd = FileIOFunctions.ReadTextString(s);
                    switch (cmd)
                    {
                    case "format":
                    case "property":
                        while (s.ReadByte() != 10)
                        {
                            ;                            // ignore the rest of the line
                        }
                        break;

                    case "comment":
                        string str = FileIOFunctions.ReadTextLine(s);
                        if (str.StartsWith("Created"))
                        {
                            switch (str.Split(new char[] { ' ' })[2])
                            {
                            case "Blender": ApplicationType = ApplicationTypes.BLENDER; break;
                            }
                        }
                        break;

                    case "element":
                        string variable = FileIOFunctions.ReadTextString(s);
                        int    val      = FileIOFunctions.ReadTextInteger(s);
                        switch (variable)
                        {
                        case "views": ncameras = val; break;

                        case "objects": nmodels = val; break;

                        default: throw new Exception("SnapshotScene: Unhandled element type " + variable);
                        }
                        break;

                    case "end_header": header = false; break;

                    default: throw new Exception("SnapshotScene: Unhandled command type " + cmd);
                    }
                }

                if (ApplicationType == ApplicationTypes.UNKNOWN)
                {
                    throw new Exception("SnapshotScene: PLY was created by an unknown application");
                }

                cameras = new CameraProperties[ncameras];
                for (int i = 0; i < ncameras; i++)
                {
                    // read viewing info
                    Vec3f  loc = new Vec3f(FileIOFunctions.ReadTextFloat(s), FileIOFunctions.ReadTextFloat(s), FileIOFunctions.ReadTextFloat(s));
                    float  w   = FileIOFunctions.ReadTextFloat(s);
                    float  x   = FileIOFunctions.ReadTextFloat(s);
                    float  y   = FileIOFunctions.ReadTextFloat(s);
                    float  z   = FileIOFunctions.ReadTextFloat(s);
                    Quatf  qua = (new Quatf(w, x, y, z)).Normalize();
                    float  dis = FileIOFunctions.ReadTextFloat(s);
                    String per = FileIOFunctions.ReadTextString(s);
                    cameras[i] = new CameraProperties(loc, qua, dis, (per == "ORTHO"));
                }

                int istart = 0, iend = 0, iinc = 0;
                switch (ApplicationType)
                {
                case ApplicationTypes.BLENDER:              // blender writes list of objects "backwards"; new objects are at beginning of list!
                    istart = nmodels - 1;
                    iend   = 0;
                    iinc   = -1;
                    break;

                default: throw new Exception("SnapshotScene: Unimplemented ApplicationType");
                }

                objnames        = new string[nmodels];
                objvisibles     = new bool[nmodels];
                objselecteds    = new bool[nmodels];
                objactives      = new bool[nmodels];
                objedits        = new bool[nmodels];
                objplyfilenames = new string[nmodels];

                for (int i = istart; i != iend + iinc; i += iinc)
                {
                    objnames[i]        = FileIOFunctions.ReadTextQuotedString(s);
                    objvisibles[i]     = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objselecteds[i]    = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objactives[i]      = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objedits[i]        = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objplyfilenames[i] = FileIOFunctions.ReadTextString(s);

                    if (objselecteds[i])
                    {
                        cselected++;
                    }
                    if (objedits[i])
                    {
                        cedited++;
                    }
                }
            }

            if (cedited > 1)
            {
                throw new Exception("more than one object being edited");
            }

            bool loadall = (prev == null || cmdobjlist);                // need to load every object?

            models       = new SnapshotModel[nmodels];
            modelscached = new SnapshotModel[nmodels];
            SnapshotModel[] pmodels = null;
            if (prev != null)
            {
                pmodels = prev.Models;
            }
            for (int i = 0; i < nmodels; i++)
            {
                bool prevsel = !cmdobjlist && (pmodels != null && pmodels[i] != null && pmodels[i].objselected);
                if (loadall || (objselecteds[i] && !nochange) || objselecteds[i] != prevsel || pmodels == null || pmodels[i] == null)
                {
                    models[i]             = new SnapshotModel(objplyfilenames[i]);
                    models[i].objind      = i;
                    models[i].objname     = objnames[i];
                    models[i].objvisible  = objvisibles[i];
                    models[i].objselected = objselecteds[i];
                    models[i].objactive   = objactives[i];
                    models[i].objedit     = objedits[i];
                    modelscached[i]       = models[i];
                }
                else
                {
                    models[i]       = null;
                    modelscached[i] = pmodels[i];
                }
            }
        }