示例#1
0
 public bool SuperficialComparison(SnapshotScene other)
 {
     if (other.nmodels != nmodels)
     {
         return(false);
     }
     SnapshotModel[] lmodels = Models;
     SnapshotModel[] omodels = other.Models;
     for (int i = 0; i < nmodels; i++)
     {
         if (omodels[i].nverts != lmodels[i].nverts)
         {
             return(false);
         }
         for (int ig = 0; ig < 4; ig++)
         {
             if (omodels[i].GetGroups()[ig].Count != lmodels[i].GetGroups()[ig].Count)
             {
                 return(false);                                                                      //.groups
             }
         }
         if (omodels[i].selinds.Where((int ind) => !lmodels[i].selinds.Contains(ind)).Count() > 0)
         {
             return(false);
         }
         if (lmodels[i].selinds.Where((int ind) => !omodels[i].selinds.Contains(ind)).Count() > 0)
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
        public static SnapshotScene ReadBinaryFile(BinaryReader br)
        {
            SnapshotScene scene = new SnapshotScene();

            scene.ReadBinary(br);
            return(scene);
        }
示例#3
0
 public ModelTreeSingle(SnapshotScene snapshot)
 {
     this.snapshot   = snapshot;
     this.label      = snapshot.GetLabel();
     this.command    = snapshot.command;
     this.parameters = snapshot.opts;
     this.cameras    = snapshot.cameras;
 }
示例#4
0
 public void SetPrevScene(SnapshotScene prev)
 {
     this.prevscene = prev;
     foreach (SnapshotModel model in models)
     {
         if (model != null)
         {
             model.prev = prev.GetObjectFromUID(model.objuid);
         }
     }
 }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
        public CameraProperties[] GetCameras()
        {
            ModelingHistory history = ModelingHistory.history;

            CameraProperties artist   = null;
            CameraProperties bestview = null;

            Vec3f tar   = new Vec3f();
            Quatf rot   = new Quatf();
            float dist  = 0.0f;
            float ortho = 0.0f;

            List <Vec3f> selverts = new List <Vec3f>();
            Vec3f        anorm    = new Vec3f();

            foreach (int isnapshot in snapshots)
            {
                SnapshotScene    scene = history[isnapshot];
                CameraProperties cam   = scene.GetCamera();

                tar   += cam.GetTarget();
                rot   += cam.GetRotation();
                dist  += cam.GetDistance();
                ortho += (cam.GetOrtho() ? 1.0f : 0.0f);

                foreach (SnapshotModel model in scene.GetSelectedModels())
                {
                    Vec3f[] verts  = model.GetVerts();
                    Vec3f[] vnorms = model.GetVertNormals();
                    foreach (int ind in model.selinds)
                    {
                        selverts.Add(verts[ind]); anorm += vnorms[ind];
                    }
                }
            }

            int nsnapshots = snapshots.Count;

            if (nsnapshots == 0)
            {
                rot  = new Quatf(0.5f, -0.5f, -0.5f, -0.5f);
                dist = 10.0f;
                System.Console.WriteLine("Cluster with no snapshots " + start + ":" + end);
            }
            else
            {
                tar   /= (float)nsnapshots;
                rot   /= (float)nsnapshots;
                dist  /= (float)nsnapshots;
                ortho /= (float)nsnapshots;
            }

            artist = new CameraProperties(tar, rot, dist, (ortho >= 0.5f))
            {
                Name = "Artist"
            };

            bestview = artist;

            return(new CameraProperties[] { artist, bestview });
        }
示例#8
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];
                }
            }
        }