Exemplo n.º 1
0
 private void tbFaceKnown_Click(object sender, RoutedEventArgs e)
 {
     if ((bool)tbFaceKnown.IsChecked)
     {
         FaceList.Clear();
         faceRec.FaceList?.ForEach((face) =>
         {
             FaceList.Add(face);
         });
     }
 }
Exemplo n.º 2
0
        public virtual void FromStream(Stream s, bool id)
        {
            Action <Action> action = delegate(Action a)
            {
                try
                {
                    a();
                }
                catch (Exception)
                {
                    LoadErrCount++;
                }
            };
            PmxHeader head = new PmxHeader();

            head.FromStreamEx(s);
            Header.FromHeader(head);
            head.ElementFormat.WithID = id;
            action(delegate
            {
                ModelInfo.FromStreamEx(s, head.ElementFormat);
            });
            int count = 0;

            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            VertexList.Clear();
            VertexList.Capacity = count;
            for (int k = 0; k < count; k++)
            {
                PmxVertex v = new PmxVertex();
                action(delegate
                {
                    v.FromStreamEx(s, head.ElementFormat);
                });
                VertexList.Add(v);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            FaceList.Clear();
            FaceList.Capacity = count;
            for (int l = 0; l < count; l++)
            {
                int ix = 0;
                action(delegate
                {
                    ix = PmxStreamHelper.ReadElement_Int32(s, head.ElementFormat.VertexSize, signed: false);
                });
                FaceList.Add(ix);
            }
            PmxTextureTable tx = new PmxTextureTable();

            action(delegate
            {
                tx.FromStreamEx(s, head.ElementFormat);
            });
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            MaterialList.Clear();
            MaterialList.Capacity = count;
            for (int m = 0; m < count; m++)
            {
                PmxMaterial j = new PmxMaterial();
                action(delegate
                {
                    j.FromStreamEx_TexTable(s, tx, head.ElementFormat);
                });
                MaterialList.Add(j);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            BoneList.Clear();
            BoneList.Capacity = count;
            for (int n = 0; n < count; n++)
            {
                PmxBone b = new PmxBone();
                action(delegate
                {
                    b.FromStreamEx(s, head.ElementFormat);
                });
                BoneList.Add(b);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            MorphList.Clear();
            MorphList.Capacity = count;
            for (int num = 0; num < count; num++)
            {
                PmxMorph morph = new PmxMorph();
                action(delegate
                {
                    morph.FromStreamEx(s, head.ElementFormat);
                });
                MorphList.Add(morph);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            NodeList.Clear();
            NodeList.Capacity = count;
            for (int num2 = 0; num2 < count; num2++)
            {
                PmxNode node = new PmxNode();
                action(delegate
                {
                    node.FromStreamEx(s, head.ElementFormat);
                });
                NodeList.Add(node);
                if (NodeList[num2].SystemNode)
                {
                    if (NodeList[num2].Name == "Root")
                    {
                        RootNode = NodeList[num2];
                    }
                    else if (NodeList[num2].Name == "表情")
                    {
                        ExpNode = NodeList[num2];
                    }
                }
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            BodyList.Clear();
            BodyList.Capacity = count;
            for (int num3 = 0; num3 < count; num3++)
            {
                PmxBody b2 = new PmxBody();
                action(delegate
                {
                    b2.FromStreamEx(s, head.ElementFormat);
                });
                BodyList.Add(b2);
            }
            action(delegate
            {
                count = PmxStreamHelper.ReadElement_Int32(s);
            });
            JointList.Clear();
            JointList.Capacity = count;
            for (int num4 = 0; num4 < count; num4++)
            {
                PmxJoint i = new PmxJoint();
                action(delegate
                {
                    i.FromStreamEx(s, head.ElementFormat);
                });
                JointList.Add(i);
            }
            if (head.Ver >= 2.1f)
            {
                action(delegate
                {
                    count = PmxStreamHelper.ReadElement_Int32(s);
                });
                SoftBodyList.Clear();
                SoftBodyList.Capacity = count;
                for (int num5 = 0; num5 < count; num5++)
                {
                    PmxSoftBody b3 = new PmxSoftBody();
                    action(delegate
                    {
                        b3.FromStreamEx(s, head.ElementFormat);
                    });
                    SoftBodyList.Add(b3);
                }
            }
            if (id)
            {
                action(delegate
                {
                    FilePath = PmxStreamHelper.ReadString(s, head.ElementFormat);
                });
            }
            head.ElementFormat.WithID = false;
        }
Exemplo n.º 3
0
        public void FromPmx(Pmx pmx)
        {
            Clear();
            FilePath     = pmx.FilePath;
            LoadErrCount = pmx.LoadErrCount;
            Header       = pmx.Header.Clone();
            ModelInfo    = pmx.ModelInfo.Clone();
            int count = pmx.VertexList.Count;

            VertexList.Capacity = count;
            for (int i = 0; i < count; i++)
            {
                VertexList.Add(pmx.VertexList[i].Clone());
            }
            count             = pmx.FaceList.Count;
            FaceList.Capacity = count;
            for (int j = 0; j < count; j++)
            {
                FaceList.Add(pmx.FaceList[j]);
            }
            count = pmx.MaterialList.Count;
            MaterialList.Capacity = count;
            for (int k = 0; k < count; k++)
            {
                MaterialList.Add(pmx.MaterialList[k].Clone());
            }
            count             = pmx.BoneList.Count;
            BoneList.Capacity = count;
            for (int l = 0; l < count; l++)
            {
                BoneList.Add(pmx.BoneList[l].Clone());
            }
            count = pmx.MorphList.Count;
            MorphList.Capacity = count;
            for (int m = 0; m < count; m++)
            {
                MorphList.Add(pmx.MorphList[m].Clone());
            }
            count = pmx.NodeList.Count;
            NodeList.Clear();
            NodeList.Capacity = count;
            for (int n = 0; n < count; n++)
            {
                NodeList.Add(pmx.NodeList[n].Clone());
                if (NodeList[n].SystemNode)
                {
                    if (NodeList[n].Name == "Root")
                    {
                        RootNode = NodeList[n];
                    }
                    else if (NodeList[n].Name == "表情")
                    {
                        ExpNode = NodeList[n];
                    }
                }
            }
            count             = pmx.BodyList.Count;
            BodyList.Capacity = count;
            for (int num = 0; num < count; num++)
            {
                BodyList.Add(pmx.BodyList[num].Clone());
            }
            count = pmx.JointList.Count;
            JointList.Capacity = count;
            for (int num2 = 0; num2 < count; num2++)
            {
                JointList.Add(pmx.JointList[num2].Clone());
            }
            count = pmx.SoftBodyList.Count;
            SoftBodyList.Capacity = count;
            for (int num3 = 0; num3 < count; num3++)
            {
                SoftBodyList.Add(pmx.SoftBodyList[num3].Clone());
            }
        }
        public static Mesh BuildMeshFromLevelingData(PrinterConfig printer)
        {
            var printerShim = ApplicationController.Instance.Shim(printer);
            PrintLevelingData levelingData = printer.Settings.Helpers.PrintLevelingData;
            var currentLevelingFunctions   = new LevelingFunctions(printerShim, levelingData);

            var vertices = new List <Vector3Float>();

            var pointCounts = new Dictionary <Vector3Float, int>();

            var points = new int[3];

            var faces = new FaceList();

            // Add top faces
            foreach (var region in currentLevelingFunctions.Regions)
            {
                int i = 0;

                foreach (var point in new[] { new Vector3Float(region.V0), new Vector3Float(region.V1), new Vector3Float(region.V2) })
                {
                    int index = vertices.IndexOf(point);
                    if (index == -1)
                    {
                        index = vertices.Count;
                        vertices.Add(point);
                    }

                    if (!pointCounts.TryGetValue(point, out int pointCount))
                    {
                        pointCount = 0;
                    }

                    pointCounts[point] = pointCount + 1;

                    points[i++] = index;
                }

                faces.Add(new Face(points[0], points[2], points[1], vertices));
            }

            List <Vector3Float> outerPoints = GetOuterPoints(vertices, pointCounts, printer.Bed.BedCenter);

            // Add reflected hull points at the bed - reflected point for item in negative z should be the negative value
            var reflectedVertices = outerPoints.Select(h => new Vector3Float(h.X, h.Y, h.Z > 0 ? 0 : h.Z)).ToList();

            vertices.AddRange(reflectedVertices);

            int lastReflected = vertices.IndexOf(reflectedVertices.Last());

            int currIndex, reflectedIndex, nextIndex = -1;

            var anchorIndex = vertices.IndexOf(reflectedVertices.First());

            // Loop over all outer points, reflecting a point onto the bed and stitching the current, reflect and next points together
            for (var i = 0; i < outerPoints.Count; i++)
            {
                var point     = outerPoints[i];
                var reflected = reflectedVertices[i];

                bool lastIndex = (i == outerPoints.Count - 1);

                Vector3Float nextPoint = lastIndex ? outerPoints.First() : outerPoints[i + 1];

                currIndex      = vertices.IndexOf(point);
                nextIndex      = vertices.IndexOf(nextPoint);
                reflectedIndex = vertices.IndexOf(reflected);

                Face faceA, faceB;

                // Add face back to previous
                faces.Add(faceB = new Face(currIndex, lastReflected, reflectedIndex, vertices));

                // Add face for current
                faces.Add(faceA = new Face(currIndex, reflectedIndex, nextIndex, vertices));

                lastReflected = reflectedIndex;
            }

            // Add bottom faces
            foreach (var region in currentLevelingFunctions.Regions)
            {
                int i = 0;

                foreach (var point in new[] { GetReflected(region.V0), GetReflected(region.V1), GetReflected(region.V2) })
                {
                    int index = vertices.IndexOf(point);
                    if (index == -1)
                    {
                        index = vertices.Count;
                        vertices.Add(point);
                    }

                    points[i++] = index;
                }

                faces.Add(new Face(points[0], points[1], points[2], vertices));
            }

            return(new Mesh(vertices, faces));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="data">The exiftool data which is needed to build this object</param>
        internal ImageInfo(ExifToolPictureData data)
        {
            _ExifToolPictureData = data;

             // Create the face list with all XMP faces
             _XmpFaces = new FaceList();
             if (data.RegionInfoMp != null && data.RegionInfoMp.Regions != null)
             {
            foreach (RegionMp region in data.RegionInfoMp.Regions)
            {
               string[] rect = region.Rectangle.Split(new char[] { ',' });
               float x, y, w, h;
               x = (float)Math.Round(Convert.ToSingle(rect[0]), Precision);
               y = (float)Math.Round(Convert.ToSingle(rect[1]), Precision);
               w = (float)Math.Round(Convert.ToSingle(rect[2]), Precision);
               h = (float)Math.Round(Convert.ToSingle(rect[3]), Precision);
               Face f = new Face(region.PersonConvertedName, new RectangleF(x, y, w, h));
               _XmpFaces.Add(f);
            }
             }

             // Create the face list with all Picasa faces
             _PicasaFaces = new FaceList();
             if (data.RegionInfo.RegionList != null)
             {
            foreach (ExifTool.Region region in data.RegionInfo.RegionList)
            {

               float x, y, w, h;

               x = (float)Math.Round(region.Area.X - (region.Area.W / 2), Precision);
               y = (float)Math.Round(region.Area.Y - (region.Area.H / 2), Precision);
               w = (float)Math.Round(region.Area.W, Precision);
               h = (float)Math.Round(region.Area.H, Precision);
               Face f = new Face(region.PersonConvertedName, new RectangleF(x, y, w, h));
               _PicasaFaces.Add(f);
            }
             }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check the Pictures, if delta is found, set it to DeltaList
        /// </summary>
        /// <returns>true, DeltaList is built</returns>
        public bool CheckPics()
        {
            _DeltaList = new FaceList();
             _OnlyInPicasa = new FaceList();
             _OnlyInExif = new FaceList();
             _RegionMismatch = new FaceList();
             _WriteData = new FaceList();
            #if oldcode
             // 1) if there are faces in Picasa and none in exif: copy all
             // 2) if there are none in Picasa and some in exif: do nothing
             // 3) compare, list difference

             // 1)
             if (ExifInfoMissing && !PicasaInfoMissing)
             {
            foreach (KeyValuePair<string, Face> kp in PicasaInfo.Faces)
            {
               _DeltaList.Add(kp.Key, kp.Value);
               _OnlyInPicasa.Add(kp.Key, kp.Value);
               _WriteData.Add(kp.Key, kp.Value);
               Debug.WriteLine("No XMP Info read with exiftool", this.FileName);
            }
            return true;
             }
             // 2)
             if (PicasaInfoMissing && !ExifInfoMissing)
             {
            foreach (KeyValuePair<string, Face> kp in ExifInfo.Faces)
            {
               _OnlyInExif.Add(kp.Key, kp.Value);
               _WriteData.Add(kp.Key, kp.Value);
               Debug.WriteLine("XMP Info available but none from Picasa", this.FileName);
            }
            return false;
             }
             // 3) Compare: not only the name, also the region
             foreach (KeyValuePair<string, Face> kp in PicasaInfo.Faces)
             {
            if (!ExifInfo.Faces.ContainsKey(kp.Key))
            {  // name was found in Picasa but not in exif. But what if it was
               // renamed in picasa? we add it here, but we have to check it
               // when reading exiftool data later on
               _DeltaList.Add(kp.Key, kp.Value);
               _OnlyInPicasa.Add(kp.Key, kp.Value);
               Debug.WriteLine("Found in Picasa but not in XMP", this.FileName);
               _WriteData.Add(kp.Key, kp.Value);
            }
            else
            { // how about the region?
               if (!CompareRectangle(kp.Value.Rect, ExifInfo.Faces[kp.Key].Rect))
               {
                  if (_RegionMismatch.ContainsKey(kp.Key))
                  {
                     _RegionMismatch.Add(kp.Key, kp.Value);
                  }
                  else
                  {
                     Debug.WriteLine("Rectangle mismatch", this.FileName);
                     _WriteData.Add(kp.Key, kp.Value);
                     _DeltaList.Add(kp.Key, kp.Value);
                  }
               }
               else
               { // is the same, so add to "write data" (otherwise we loose this info)
                  Debug.WriteLine("Same in Picasa and XMP", this.FileName);
                  _WriteData.Add(kp.Key, kp.Value);
               }
            }
             }
             foreach (KeyValuePair<string, Face> kp in ExifInfo.Faces)
             {
            if (!PicasaInfo.Faces.ContainsKey(kp.Key))
            {  // Name in Exif but not in Picasa. As picasa has the higher priority,
               // we have to check whether the region is already used or not
               bool found = false;
               foreach (KeyValuePair<string, Face> alreadyHere in _WriteData)
               {
                  if (CompareRectangle(alreadyHere.Value.Rect, kp.Value.Rect, 10))
                  { // yes, it is here! Ignore this one
                     found = true;
                     break;
                  }
               }
               if (!found)
               {
                  _OnlyInExif.Add(kp.Key, kp.Value);
                  _WriteData.Add(kp.Key, kp.Value);
                  Debug.WriteLine("Found in XMP but not in Picasa", this.FileName);
               }
               else
               {
                  _DeltaList.Add(kp.Key, kp.Value);
               }
            }
            else
            { // region?
               if (!CompareRectangle(kp.Value.Rect, PicasaInfo.Faces[kp.Key].Rect))
               {
                  if (_RegionMismatch.ContainsKey(kp.Key))
                  {
                     _RegionMismatch.Add(kp.Key, kp.Value);
                  }
                  else
                  {
                     if (!_WriteData.ContainsKey(kp.Key))
                     {
                        _WriteData.Add(kp.Key, kp.Value);
                     }
                  }
               }
               else
               { // is the same, so add to "write data" (otherwise we loose this info)
                  if (!_WriteData.ContainsKey(kp.Key))
                  {
                     Debug.WriteLine("Same in Picasa and XMP", this.FileName);
                     _WriteData.Add(kp.Key, kp.Value);
                  }
               }
            }
             }
            #endif
             return _WriteData.Count > 0;
        }