コード例 #1
0
ファイル: MorphHelper.cs プロジェクト: n3td0g/HeadRotation
//=================================== OLD ===================================

        public void ProcessPoints_old(ProjectedDots dots, HeadPoints points)
        {
            projectedDots = dots;
            headPoints    = points;

            headIndices.Clear();
            for (int i = 0; i < dots.Points.Count; ++i)
            {
                headIndices.Add(i);
            }

            var rotaionMatrix = headPoints.HeadMesh.RotationMatrix;

            Matrix4.Invert(ref rotaionMatrix, out RotationMatrix);

            rightPower = 1.0f - Math.Abs(headPoints.HeadMesh.HeadAngle) * 2.0f / (float)Math.PI;
            //rightPower = Math.Min(1.0f, Math.Max(rightPower, 0.0f));
            // (float)Math.Cos(headPoints.HeadMesh.HeadAngle);

            rightVector   = headPoints.GetWorldPoint(new Vector3(1.0f, 0.0f, 0.0f));
            forwardVector = headPoints.GetWorldPoint(new Vector3(0.0f, 0.0f, 1.0f));

            ProcessHeadPoints_old();

            //SpecialAlignment();         // выравниваем точки рта-глаз-носа по центру лица
            //  MirrorPoints(headPoints.HeadMesh.HeadAngle > 0.0f);             // отразить форму лица зеркально
        }
コード例 #2
0
ファイル: MorphHelper.cs プロジェクト: n3td0g/HeadRotation
        public void ProcessPoints(ProjectedDots dots, HeadPoints points)
        {
            projectedDots = dots;
            headPoints    = points;

            rightVector   = headPoints.GetWorldPoint(new Vector3(1.0f, 0.0f, 0.0f));
            forwardVector = headPoints.GetWorldPoint(new Vector3(0.0f, 0.0f, 1.0f));
            upVector      = headPoints.GetWorldPoint(new Vector3(0.0f, 1.0f, 0.0f));

            headIndices.Clear();
            for (int i = 0; i < dots.Points.Count; ++i)
            {
                headIndices.Add(i);
            }

            var rotationMatrix = headPoints.HeadMesh.RotationMatrix;

            Matrix4.Invert(ref rotationMatrix, out RotationMatrix);

            ProcessHeadPoints();

            FixLipsPoints();
        }
コード例 #3
0
        public void Initialize(RenderMesh headMesh, ProjectedDots dots, HeadMorphing headMorphing)
        {
            HeadMesh = headMesh;

            MorphTriangleType realType = Type;

            if (IsReversed)
            {
                realType = Type == MorphTriangleType.Left ? MorphTriangleType.Right : MorphTriangleType.Left;
            }

            List <Vector2> points = new List <Vector2>();

            foreach (var part in HeadMesh.Parts)
            {
                foreach (var point in part.MorphPoints)
                {
                    if (point.TriangleType != realType || point.Position.Z < 0.0f)
                    {
                        continue;
                    }
                    if (IsReversed)
                    {
                        points.Add(point.ReversedWorldPosition.Xy);
                    }
                    else
                    {
                        points.Add(point.WorldPosition.Xy);
                    }
                }
            }

            Convex = Triangulate.ComputeConvexHull(points, (Type == MorphTriangleType.Left) == IsReversed);

            LastIndex = Convex.Count - 1;

            float prevX = Convex[LastIndex].X;
            float prevY = Convex[LastIndex].Y;

            for (int i = LastIndex - 1; i >= 0; --i)
            {
                float y = Convex[i].Y;
                float x = Convex[i].X;
                if (x > prevX == (Type == MorphTriangleType.Left))
                {
                    continue;
                }
                if (y < prevY)
                {
                    break;
                }
                prevX      = x;
                prevY      = y;
                FirstIndex = i;
            }
            Convex.RemoveRange(0, FirstIndex);
            if (Type == MorphTriangleType.Left)
            {
                Convex.Insert(0, GetPoint(dots.Points[52]));
                Convex.Insert(0, GetPoint(dots.Points[3]));
                Convex.Insert(0, GetPoint(dots.Points[58]));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[72].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[73].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[74].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[75].Xy));
            }
            else
            {
                Convex.Insert(0, GetPoint(dots.Points[53]));
                Convex.Insert(0, GetPoint(dots.Points[4]));
                Convex.Insert(0, GetPoint(dots.Points[59]));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[70].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[77].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[76].Xy));
                Convex.Insert(0, GetPoint(headMorphing.headPoints.Points[75].Xy));
            }
            FirstIndex = 7;
            LastIndex  = Convex.Count - 1;

            var tempPoints = new List <Point>();

            for (int index = 0; index < Convex.Count; ++index)
            {
                var position = Convex[index];
                tempPoints.Add(new Point((uint)index, position.X, position.Y));
            }
            Indices.Clear();
            Indices.AddRange(Triangulate.Delaunay(tempPoints));
        }
コード例 #4
0
        public void ProcessPoints(ProjectedDots dots)
        {
            /*foreach (var part in HeadMesh.Parts)
             * {
             *  foreach (var point in part.MorphPoints)
             *  {
             *      point.AdditionalTriangle.TriangleIndex = -1;
             *      if (point.Position.Z < 0.0f) //point.TriangleType != Type ||
             *          continue;
             *      for (int i = 0; i < Indices.Count; i += 3)
             *      {
             *          var index = i / 3;
             *          var a = Convex[(int)Indices[i]];
             *          var b = Convex[(int)Indices[i + 1]];
             *          var c = Convex[(int)Indices[i + 2]];
             *
             *          point.AdditionalInitialize(ref a, ref b, ref c, index, IsReversed);
             *      }
             *  }
             * }*/

            int[] dotIndices = Type == MorphTriangleType.Right ?
                               new int[] { 67, 69, 6, 8, 10, 11 } :
            new int[] { 66, 68, 5, 7, 9, 11 };

            var right = new Vector3(1.0f, 0.0f, 0.0f);

            right = HeadMesh.GetWorldPoint(right);

            var a = dots.Points[dotIndices.First()];
            var b = Convex[FirstIndex];

            var sa = Vector3.Dot(new Vector3(a.X, a.Y, 0.0f), right);
            var sb = Vector3.Dot(new Vector3(b.X, b.Y, 0.0f), right);

            A = new Vector3(a.X, a.Y, 0.0f);
            B = new Vector3(b.X, b.Y, 0.0f);

            var ds = Math.Abs(sa / sb);

            foreach (var part in HeadMesh.Parts)
            {
                foreach (var point in part.MorphPoints)
                {
                    point.Position.X *= ds;

                    foreach (var index in point.Indices)
                    {
                        part.Vertices[index].Position = point.Position;
                    }
                }

                part.UpdateBuffers();
            }


            /*List<Vector2> targetPoints = new List<Vector2>();
             * foreach (var index in dotIndices)
             *  targetPoints.Add(GetPoint(dots.Points[index]));
             *
             * float targetLength = 0.0f;
             * for (int i = 1; i < targetPoints.Count; ++i)
             *  targetLength += (targetPoints[i] - targetPoints[i - 1]).Length;
             *
             * float sourceLength = 0.0f;
             * for (int i = FirstIndex; i < LastIndex; ++i)
             *  sourceLength += (Convex[i + 1] - Convex[i]).Length;
             *
             * List<Vector2> NewConvex = new List<Vector2>();
             * NewConvex.AddRange(Convex);
             * NewConvex[FirstIndex] = targetPoints[0];
             * NewConvex[LastIndex] = targetPoints[targetPoints.Count - 1];
             *
             * float k = targetLength / sourceLength;
             * float sourceDistance = 0.0f;
             * float targetDistance = 0.0f;
             * int targetIndex = 0;
             * for (int i = FirstIndex + 1; i < LastIndex; ++i)
             * {
             *  var point = Convex[i];
             *  sourceDistance += (Convex[i - 1] - point).Length;
             *  var td = sourceDistance * k;
             *  var direction = targetPoints[targetIndex + 1] - targetPoints[targetIndex];
             *  var distance = direction.Length;
             *  while ((targetDistance + distance) < td)
             *  {
             *      targetDistance += distance;
             *      targetIndex++;
             *      direction = targetPoints[targetIndex + 1] - targetPoints[targetIndex];
             *      distance = direction.Length;
             *  }
             *  direction.Normalize();
             *  NewConvex[i] = targetPoints[targetIndex] + direction * (td - targetDistance);
             * }
             * Convex = NewConvex;
             *
             * MorphPoints();*/
        }