private void SpecialBottomPointsUpdate(List <HeadPoint> points) { var bottomPoints = new int[] { 9, 10, 11, 33, 32, 31 }; for (var i = 0; i < bottomPoints.Length; ++i) { var point = points[bottomPoints[i]]; var delta = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedBottomPoints[i], ProgramCore.CurrentProgram) - point.Value; point.Value += delta; autodotsShapeHelper.Transform(point.Value, bottomPoints[i]); } var bottomPointsX = new int[] { 7, 8, 30, 29 }; for (var i = 0; i < bottomPointsX.Length; ++i) { var point = points[bottomPointsX[i]]; var delta = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedBottomPoints[i + 6], ProgramCore.CurrentProgram) - point.Value; delta = new Vector2(point.Value.X + delta.X, point.Value.Y) - point.Value; point.Value += delta; foreach (var l in point.LinkedPoints) { var p = points[l]; p.Value += delta; autodotsShapeHelper.Transform(p.Value, l); } autodotsShapeHelper.Transform(point.Value, bottomPointsX[i]); } }
private void SpecialCenterUpdate(List <HeadPoint> points, List <int> indexes, Vector2 targetPoint) { float maxX, minX; var center = GetCenter(points, indexes, out minX, out maxX); var rightPosUserSelected = MirroredHeadPoint.GetFrontWorldPoint(targetPoint, ProgramCore.CurrentProgram); // перенояем координаты с левой картинки в правой var delta2 = rightPosUserSelected - center; foreach (var index in indexes) { var p = points[index]; p.Value += delta2; autodotsShapeHelper.Transform(p.Value, index); } }
private void SpecialTopHaedWidth(List <HeadPoint> points) { var topHeadIndices = new int[] { 6, 5, 4, 3, 0, 25, 26, 27, 28 }; var a = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedTopPoints[0], ProgramCore.CurrentProgram); var b = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedTopPoints[1], ProgramCore.CurrentProgram); var width = b.X - a.X; var invOldWidth = 1.0f / (points[28].Value.X - points[6].Value.X); var minX = points[6].Value.X; foreach (var index in topHeadIndices) { var point = points[index]; var x = (point.Value.X - minX) * invOldWidth * width + a.X; point.Value = new Vector2(x, point.Value.Y); autodotsShapeHelper.Transform(point.Value, index); } }
private void SpecialEyePointsUpdate(List <HeadPoint> points, bool isLeft) { var eyePoints = isLeft ? new[] { 21, 22, 23, 24 } : new[] { 45, 44, 43, 46 }; for (var i = 0; i < eyePoints.Length; ++i) { var point = points[eyePoints[i]]; var delta = MirroredHeadPoint.GetFrontWorldPoint(isLeft ? ProgramCore.Project.DetectedLeftEyePoints[i] : ProgramCore.Project.DetectedRightEyePoints[i], ProgramCore.CurrentProgram) - point.Value; point.Value += delta; foreach (var l in point.LinkedPoints) { var p = points[l]; p.Value += delta; autodotsShapeHelper.Transform(p.Value, l); } autodotsShapeHelper.Transform(point.Value, eyePoints[i]); } }
private void SpecialNosePointsUpdate(List <HeadPoint> points) { var bottomNosePoints = new int[] { 19, 41, 52 }; for (var i = 0; i < bottomNosePoints.Length; ++i) { var point = points[bottomNosePoints[i]]; var delta = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedNosePoints[i], ProgramCore.CurrentProgram) - point.Value; if (bottomNosePoints[i] != 52) { delta.Y -= 0.2f; } //delta = new Vector2(point.Value.X + delta.X, point.Value.Y) - point.Value; point.Value += delta; foreach (var l in point.LinkedPoints) { var p = points[l]; p.Value += delta; autodotsShapeHelper.Transform(p.Value, l); } autodotsShapeHelper.Transform(point.Value, bottomNosePoints[i]); } }
public void btnPolyLine_Click(object sender, EventArgs e) { if (btnPolyLine.Tag.ToString() == "2") { if (ProgramCore.MainForm.HeadProfile && ProgramCore.MainForm.ctrlTemplateImage.ControlPointsMode != ProfileControlPointsMode.None) { MessageBox.Show("Set Control Points !", "HeadShop", MessageBoxButtons.OK); return; // значит загрузили картинку, но не назначили ей опорные точки. нельзя ниче делатЬ! } ++ProgramCore.MainForm.ctrlRenderControl.historyController.currentGroup; btnPolyLine.Tag = "1"; btnDots.Tag = btnShapeTool.Tag = "2"; btnPolyLine.Image = Properties.Resources.btnPolyLinePressed; btnDots.Image = Properties.Resources.btnDotsNormal; btnShapeTool.Image = Properties.Resources.btnHandNormal1; SetDefaultHeadRotation(); ProgramCore.MainForm.DisableRotating(); ProgramCore.MainForm.ctrlRenderControl.Mode = Mode.HeadLine; ProgramCore.MainForm.ctrlTemplateImage.UpdateUserCenterPositions(false, true); UpdateFlipEnable(ProgramCore.Project.ShapeFlip); SetPanelLogic(); if (ProgramCore.MainForm.HeadProfile) { ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.ProfileTop; } } else { btnPolyLine.Tag = "2"; btnPolyLine.Image = Properties.Resources.btnPolyLineNormal; var userPoints = ProgramCore.MainForm.ctrlRenderControl.headController.AllPoints.Select(x => x.Value).ToList(); if (userPoints.Count >= 3) // если твое условие - просто не выполняем ничего. но интерфейсно все равно отключить надо! { #region История (undo) Dictionary <Guid, MeshUndoInfo> undoInfo; ProgramCore.MainForm.ctrlRenderControl.headMeshesController.GetUndoInfo(out undoInfo); var isProfile = ProgramCore.MainForm.HeadProfile; var teInfo = isProfile ? ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo : ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo; var historyElem = new HistoryHeadShapeLines(undoInfo, ProgramCore.MainForm.ctrlRenderControl.headController.Lines, teInfo, isProfile); historyElem.Group = ProgramCore.MainForm.ctrlRenderControl.historyController.currentGroup; ProgramCore.MainForm.ctrlRenderControl.historyController.Add(historyElem); #endregion ProgramCore.MainForm.ctrlTemplateImage.FinishLine(); switch (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode) { case MeshPartType.LEye: case MeshPartType.REye: userPoints.RemoveAt(userPoints.Count - 1); var center = ProgramCore.MainForm.ctrlRenderControl.HeadLineMode == MeshPartType.LEye ? ProgramCore.Project.LeftEyeUserCenter : ProgramCore.Project.RightEyeCenter; center = MirroredHeadPoint.UpdateWorldPoint(center); ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, center); break; case MeshPartType.Nose: //тут центр не нужен,сказал воваш.. ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, Vector2.Zero); break; case MeshPartType.Lip: // ТУТ ЦЕНТР??? ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, Vector2.Zero); break; case MeshPartType.Head: userPoints.RemoveAt(userPoints.Count - 1); var leftTop = new Vector2(ProgramCore.Project.LeftEyeUserCenter.X, Math.Max(ProgramCore.Project.LeftEyeUserCenter.Y, ProgramCore.Project.RightEyeUserCenter.Y)); var rightBottom = new Vector2(ProgramCore.Project.RightEyeUserCenter.X, ProgramCore.Project.MouthUserCenter.Y); var eyesMouthRect = new RectangleF(leftTop.X, leftTop.Y, rightBottom.X - leftTop.X, rightBottom.Y - leftTop.Y); center = new Vector2(eyesMouthRect.X + eyesMouthRect.Width * 0.5f, eyesMouthRect.Y + eyesMouthRect.Height * 0.5f); center = MirroredHeadPoint.UpdateWorldPoint(center); ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode, userPoints, center); break; } } ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Clear(); ProgramCore.MainForm.EnableRotating(); UpdateNormals(); ProgramCore.MainForm.ctrlRenderControl.Mode = Mode.None; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.None; ProgramCore.MainForm.ctrlTemplateImage.LineSelectionMode = false; ProgramCore.MainForm.ctrlTemplateImage.ResetProfileRects(); ProgramCore.MainForm.ctrlRenderControl.ProfileFaceRect = RectangleF.Empty; DisableFlip(); SetPanelLogic(); } }
public void pictureTemplate_MouseUp(object sender, MouseEventArgs e) { startMousePoint = Vector2.Zero; if (e.Button == MouseButtons.Left) { headLastPoint = Vector2.Zero; switch (ProgramCore.MainForm.ctrlRenderControl.ScaleMode) { case ScaleMode.Zoom: tempOffsetPoint = Vector2.Zero; break; case ScaleMode.None: #region Обычные режимы switch (ProgramCore.MainForm.ctrlRenderControl.Mode) { case Mode.HeadAutodotsFirstTime: case Mode.HeadAutodots: { if (ProgramCore.Project.ShapeFlip != FlipType.None) return; if (!startMove && !dblClick) { if (!shiftKeyPressed) ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.ClearSelection(); if (e.X >= MouthTransformed.X - HalfPointRectSize && e.X <= MouthTransformed.X + HalfPointRectSize && e.Y >= MouthTransformed.Y - HalfPointRectSize && e.Y <= MouthTransformed.Y + HalfPointRectSize) // рот ProgramCore.MainForm.ctrlRenderControl.headController.SelectAutdotsMouth(); else if (e.X >= LeftEyeTransformed.X - HalfPointRectSize && e.X <= LeftEyeTransformed.X + HalfPointRectSize && e.Y >= LeftEyeTransformed.Y - HalfPointRectSize && e.Y <= LeftEyeTransformed.Y + HalfPointRectSize) // левый глаз ProgramCore.MainForm.ctrlRenderControl.headController.SelectAutodotsLeftEye(); else if (e.X >= RightEyeTransformed.X - HalfPointRectSize && e.X <= RightEyeTransformed.X + HalfPointRectSize && e.Y >= RightEyeTransformed.Y - HalfPointRectSize && e.Y <= RightEyeTransformed.Y + HalfPointRectSize) // правый глаз ProgramCore.MainForm.ctrlRenderControl.headController.SelectAutodotsRightEye(); else if (e.X >= NoseTransformed.X - HalfPointRectSize && e.X <= NoseTransformed.X + HalfPointRectSize && e.Y >= NoseTransformed.Y - HalfPointRectSize && e.Y <= NoseTransformed.Y + HalfPointRectSize) // нос ProgramCore.MainForm.ctrlRenderControl.headController.SelectAutodotsNose(); else if (e.X >= CentralFacePoint.X - HalfPointRectSize && e.X <= CentralFacePoint.X + HalfPointRectSize && e.Y >= CentralFacePoint.Y - HalfPointRectSize && e.Y <= CentralFacePoint.Y + HalfPointRectSize) // прямоугольник и выделение всех точек { if (RectTransformMode) { RectTransformMode = false; ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.ClearSelection(); } else { RectTransformMode = true; UpdateUserCenterPositions(true, true); ProgramCore.MainForm.ctrlRenderControl.headController.SelectAutodotsFaceEllipse(); } } else ProgramCore.MainForm.ctrlRenderControl.headController.UpdateAutodotsPointSelection(e.X, e.Y, true); } else { RecalcEyeMouthRect(); if (ProgramCore.MainForm.ctrlRenderControl.Mode == Mode.HeadAutodots) { ProgramCore.MainForm.ctrlRenderControl.CalcReflectedBitmaps(); ProgramCore.MainForm.ctrlRenderControl.headController.EndAutodots(false); ProgramCore.MainForm.ctrlRenderControl.ApplySmoothedTextures(); for (var i = 0; i < ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Count; i++) // после слияние с ShapeDots. Проверить! { var p = ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots[i]; if (p.Selected) ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(p.Value, i); // точка в мировых координатах } } } } break; /* case Mode.HeadShapedots: if (ProgramCore.Project.ShapeFlip != FlipType.None) return; if (!startMove && !dblClick) { if (!shiftKeyPressed) ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.ClearSelection(); if (e.X >= MouthTransformed.X - HalfPointRectSize && e.X <= MouthTransformed.X + HalfPointRectSize && e.Y >= MouthTransformed.Y - HalfPointRectSize && e.Y <= MouthTransformed.Y + HalfPointRectSize) // рот ProgramCore.MainForm.ctrlRenderControl.headController.SelectShapedotsMouth(); else if (e.X >= LeftEyeTransformed.X - HalfPointRectSize && e.X <= LeftEyeTransformed.X + HalfPointRectSize && e.Y >= LeftEyeTransformed.Y - HalfPointRectSize && e.Y <= LeftEyeTransformed.Y + HalfPointRectSize) // левый глаз ProgramCore.MainForm.ctrlRenderControl.headController.SelectShapedotsLeftEye(); else if (e.X >= RightEyeTransformed.X - HalfPointRectSize && e.X <= RightEyeTransformed.X + HalfPointRectSize && e.Y >= RightEyeTransformed.Y - HalfPointRectSize && e.Y <= RightEyeTransformed.Y + HalfPointRectSize) // правый глаз ProgramCore.MainForm.ctrlRenderControl.headController.SelectShapedotsRightEye(); else if (e.X >= NoseTransformed.X - HalfPointRectSize && e.X <= NoseTransformed.X + HalfPointRectSize && e.Y >= NoseTransformed.Y - HalfPointRectSize && e.Y <= NoseTransformed.Y + HalfPointRectSize) // нос ProgramCore.MainForm.ctrlRenderControl.headController.SelectShapedotsNose(); else if (e.X >= CentralFacePoint.X - HalfPointRectSize && e.X <= CentralFacePoint.X + HalfPointRectSize && e.Y >= CentralFacePoint.Y - HalfPointRectSize && e.Y <= CentralFacePoint.Y + HalfPointRectSize) // прямоугольник и выделение всех точек { if (RectTransformMode) { RectTransformMode = false; ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.ClearSelection(); } else { RectTransformMode = true; UpdateUserCenterPositions(true, true); ProgramCore.MainForm.ctrlRenderControl.headController.SelectShapedotsFaceEllipse(); } } else ProgramCore.MainForm.ctrlRenderControl.headController.UpdateShapedotsPointSelection(e.X, e.Y, true); } else { for (var i = 0; i < ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Count; i++) { var p = ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots[i]; if (p.Selected) ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.Transform(p.Value, i); // точка в мировых координатах } } break;*/ case Mode.HeadAutodotsLassoStart: headAutodotsLassoPoints.Add(new Vector2(e.X, e.Y)); break; /* case Mode.HeadShapedotsLassoStart: headShapedotsLassoPoints.Add(new Vector2(e.X, e.Y)); break;*/ case Mode.HeadLine: { if (ProgramCore.Project.ShapeFlip != FlipType.None) return; if (ProgramCore.MainForm.HeadFront) { #region вид спереди if (!startMove && !dblClick) { #region Проверяем, начали ли что-то обводить линиями var firstTime = false; if (e.X >= MouthTransformed.X - 2.5 && e.X <= MouthTransformed.X + 2.5 && e.Y >= MouthTransformed.Y - 2.5 && e.Y <= MouthTransformed.Y + 2.5) // рот { if (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode != MeshPartType.Lip) { firstTime = true; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.Lip; } } else if (e.X >= LeftEyeTransformed.X - 2.5 && e.X <= LeftEyeTransformed.X + 2.5 && e.Y >= LeftEyeTransformed.Y - 2.5 && e.Y <= LeftEyeTransformed.Y + 2.5) // левый глаз { firstTime = true; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.LEye; } else if (e.X >= RightEyeTransformed.X - 2.5 && e.X <= RightEyeTransformed.X + 2.5 && e.Y >= RightEyeTransformed.Y - 2.5 && e.Y <= RightEyeTransformed.Y + 2.5) // правый глаз { firstTime = true; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.REye; } else if (e.X >= NoseTransformed.X - 2.5 && e.X <= NoseTransformed.X + 2.5 && e.Y >= NoseTransformed.Y - 2.5 && e.Y <= NoseTransformed.Y + 2.5) // нос { firstTime = true; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.Nose; } else if (e.X >= CentralFacePoint.X - 2.5 && e.X <= CentralFacePoint.X + 2.5 && e.Y >= CentralFacePoint.Y - 2.5 && e.Y <= CentralFacePoint.Y + 2.5) { firstTime = true; ProgramCore.MainForm.ctrlRenderControl.HeadLineMode = MeshPartType.Head; } #endregion if (firstTime) // выбираем режим линии { ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Clear(); ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ResetPoints(ProgramCore.MainForm.ctrlRenderControl.HeadLineMode); } else if (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode != MeshPartType.None) // добавляем новые точки { var point = new MirroredHeadPoint(headLastPointRelative, headLastPointRelative, false); point.UpdateWorldPoint(); #region Проверка на количество линий и режим выделения if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count > 1) { var condition = false; switch (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode) { case MeshPartType.Lip: if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count > 2) condition = true; break; default: if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count > 1) condition = true; break; } if (condition) // если ничего не выделили - начинаем рисовать новую линию. иначе уходим в режим выделения и таскания точек { if (!shiftKeyPressed) ProgramCore.MainForm.ctrlRenderControl.headController.ClearPointsSelection(); if (ProgramCore.MainForm.ctrlRenderControl.headController.UpdatePointSelection(point.Value.X, point.Value.Y)) LineSelectionMode = true; else { if (LineSelectionMode) { LineSelectionMode = false; ProgramCore.MainForm.ctrlRenderControl.headController.ClearPointsSelection(); break; } else ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Clear(); } } } #endregion if (!LineSelectionMode) { #region Добавляем новые точки линии if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count == 0) { var line = new HeadLine(); line.Add(point); ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Add(line); } else { var currentLine = ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Last(); var hasIntersections = false; if (currentLine.Count > 1) // проверка на пересечения линий { var lastPoint = currentLine.Last(); float ua, ub; for (var i = currentLine.Count - 2; i >= 0; i--) { var pointA = currentLine[i]; var pointB = currentLine[i + 1]; if (AutodotsShapeHelper.GetUaUb(ref lastPoint.Value, ref point.Value, ref pointA.Value, ref pointB.Value, out ua, out ub)) { if (ua > 0 && ua < 1 && ub > 0 && ub < 1) { hasIntersections = true; break; } } } } var inAnotherPoint = false; if (ProgramCore.MainForm.ctrlRenderControl.HeadLineMode == MeshPartType.Lip && ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count == 2) { // ЭТо вторая линия губ foreach (var lPoint in ProgramCore.MainForm.ctrlRenderControl.headController.Lines.First()) if (point.Value.X >= lPoint.Value.X - 0.25 && point.Value.X <= lPoint.Value.X + 0.25 && point.Value.Y >= lPoint.Value.Y - 0.25 && point.Value.Y <= lPoint.Value.Y + 0.25 && !currentLine.Contains(lPoint)) { if (currentLine.Count == 0) currentLine.Add(lPoint); else { currentLine.Add(lPoint); ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Add(new HeadLine()); } inAnotherPoint = true; break; } if (currentLine.Count == 0) //первую точку добавляем всегда в пересечении с другой точкой. inAnotherPoint = true; } // прочие случаи if (!hasIntersections && !inAnotherPoint) { var firstPoint = currentLine.First(); if (point.Value.X >= firstPoint.Value.X - 0.25 && point.Value.X <= firstPoint.Value.X + 0.25 && point.Value.Y >= firstPoint.Value.Y - 0.25 && point.Value.Y <= firstPoint.Value.Y + 0.25) { currentLine.Add(firstPoint); ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Add(new HeadLine()); } else currentLine.Add(point); } } #endregion } } } #endregion } else { #region Вид сбоку if (isProfileSmoothing) return; if (!startMove && !dblClick) { var point = new MirroredHeadPoint(headLastPointRelative, headLastPointRelative, false); point.UpdateWorldPoint(); #region Проверка на количество линий и режим выделения if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count > 1) // если ничего не выделили - начинаем рисовать новую линию. иначе уходим в режим выделения и таскания точек { if (!shiftKeyPressed) ProgramCore.MainForm.ctrlRenderControl.headController.ClearPointsSelection(); if (ProgramCore.MainForm.ctrlRenderControl.headController.UpdatePointSelection(point.Value.X, point.Value.Y)) LineSelectionMode = true; else { if (LineSelectionMode) { LineSelectionMode = false; ProgramCore.MainForm.ctrlRenderControl.headController.ClearPointsSelection(); break; } } } #endregion if (!LineSelectionMode) { #region Добавляем новые точки линии if (ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Count == 0) { var line = new HeadLine(); line.Add(point); ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Add(line); } else { var currentLine = ProgramCore.MainForm.ctrlRenderControl.headController.Lines.Last(); var hasIntersections = false; if (currentLine.Count > 1) // проверка на пересечения линий { var lastPoint = currentLine.Last(); float ua, ub; for (var i = currentLine.Count - 2; i >= 0; i--) { var pointA = currentLine[i]; var pointB = currentLine[i + 1]; if (AutodotsShapeHelper.GetUaUb(ref lastPoint.Value, ref point.Value, ref pointA.Value, ref pointB.Value, out ua, out ub)) { if (ua > 0 && ua < 1 && ub > 0 && ub < 1) { hasIntersections = true; break; } } } } // прочие случаи if (!hasIntersections) currentLine.Add(point); } #endregion } } #endregion } } break; case Mode.None: { if (ProgramCore.MainForm.HeadProfile) { switch (ControlPointsMode) { case ProfileControlPointsMode.SetControlPoints: // в профиле. расставляем опорные точки { if (headLastPointRelative != Vector2.Zero) { profileControlPoints[profileControlPointIndex].ValueMirrored = headLastPointRelative; ++profileControlPointIndex; if (profileControlPointIndex == 4) { ControlPointsMode = ProfileControlPointsMode.MoveControlPoints; profileControlPointIndex = 0; } } } break; case ProfileControlPointsMode.MoveControlPoints: // выделяем и двигаем опорные точки { if (!startMove && !dblClick) { if (!shiftKeyPressed) foreach (var point in profileControlPoints) point.Selected = false; foreach (var point in profileControlPoints) { var pointK = new Vector2(point.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX, point.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY); if (e.X >= pointK.X - 5 && e.X <= pointK.X + 5 && e.Y >= pointK.Y - 5 && e.Y <= pointK.Y + 5) { point.Selected = true; break; } } } } break; case ProfileControlPointsMode.UpdateRightLeft: // выделяем и двигаем опорные точки { if (!startMove && !dblClick) { if (!shiftKeyPressed) foreach (var point in profileControlPoints) point.Selected = false; for (var i = 0; i < profileControlPoints.Count; i += 3) { var point = profileControlPoints[i]; var pointK = new Vector2(point.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX, point.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY); if (e.X >= pointK.X - 5 && e.X <= pointK.X + 5 && e.Y >= pointK.Y - 5 && e.Y <= pointK.Y + 5) { point.Selected = true; break; } } } else if (startMove) { UpdateProfileRectangle(); } } break; } } } break; } #endregion break; } } moveRectIndex = -1; startMove = false; leftMousePressed = false; dblClick = false; headLastPointRelative = Vector2.Zero; headTempPoints.Clear(); Cursor = Cursors.Arrow; }
/// <summary> Смасштабировать и повернуть изображение профиля по опорным точкам </summary> private void UpdateProfileImageByControlPoints() { #region Обрезание var image = ProgramCore.Project.ProfileImage; var leftX = (int)(profileControlPoints.Min(x => x.ValueMirrored.X) * image.Width); var topY = (int)(profileControlPoints.Min(x => x.ValueMirrored.Y) * image.Height); var bottomY = (int)(profileControlPoints.Max(x => x.ValueMirrored.Y) * image.Height); leftX = leftX - 100 < 0 ? 0 : leftX - 100; // ширину хз как определять, ой-вей topY = topY - 10 < 0 ? 0 : topY - 10; bottomY = bottomY + 10 > image.Height ? image.Height : bottomY + 10; var height = bottomY - topY; var faceRectangle = new Rectangle(leftX, topY, image.Width - leftX, height); var croppedImage = ImageEx.Crop(image, faceRectangle); for (var i = 0; i < profileControlPoints.Count; i++) // смещаем все точки, чтобы учесть обрезанное { var point = profileControlPoints[i]; var pointK = new Vector2(point.ValueMirrored.X * image.Width, point.ValueMirrored.Y * image.Height); // по старой ширине-высоте pointK.X -= leftX; pointK.Y -= topY; profileControlPoints[i] = new MirroredHeadPoint(point.Value, new Vector2(pointK.X / (croppedImage.Width * 1f), pointK.Y / (croppedImage.Height * 1f)), false); // и в новые } #endregion #region Поворот var xVector = new Vector2(1, 0); var vectorLeft = profileControlPoints[2].ValueMirrored - profileControlPoints[1].ValueMirrored; // из глаза рот vectorLeft = new Vector2(vectorLeft.X * croppedImage.Width, vectorLeft.Y * croppedImage.Height); vectorLeft.Normalize(); var xDiff = xVector.X - vectorLeft.X; var yDiff = xVector.Y - vectorLeft.Y; var angleLeft = Math.Atan2(yDiff, xDiff); var vectorRight = profileControlPoints[2].Value - profileControlPoints[1].Value; vectorRight.Normalize(); xDiff = xVector.X - vectorRight.X; yDiff = xVector.Y - vectorRight.Y; var angleRight = -Math.Atan2(yDiff, xDiff); var angleDiffRad = angleRight - angleLeft; var angleDiff = angleDiffRad * 180.0 / Math.PI; using (var ii = ImageEx.RotateImage(croppedImage, (float)angleDiff)) { ProgramCore.Project.ProfileImage = new Bitmap(ii); SetTemplateImage(ProgramCore.Project.ProfileImage, false); } var center = new Vector2(ProgramCore.Project.ProfileImage.Width * 0.5f, ProgramCore.Project.ProfileImage.Height * 0.5f); var cosAngle = Math.Cos(angleDiffRad); var sinAngle = Math.Sin(angleDiffRad); for (var i = 0; i < profileControlPoints.Count; i++) // смещаем все точки, чтобы учесть обрезанное { var point = profileControlPoints[i]; var pointAbsolute = new Vector2(point.ValueMirrored.X * ProgramCore.Project.ProfileImage.Width, point.ValueMirrored.Y * ProgramCore.Project.ProfileImage.Height); // по старой ширине-высоте var newPoint = pointAbsolute - center; newPoint = new Vector2((float)(newPoint.X * cosAngle - newPoint.Y * sinAngle), (float)(newPoint.Y * cosAngle + newPoint.X * sinAngle)); newPoint += center; profileControlPoints[i] = new MirroredHeadPoint(point.Value, new Vector2(newPoint.X / (ProgramCore.Project.ProfileImage.Width * 1f), newPoint.Y / (ProgramCore.Project.ProfileImage.Height * 1f)), false); // и в новые } ProgramCore.MainForm.ctrlRenderControl.InitializeProfileCamera(ModelAdaptParamProfile); #endregion var projectPath = Path.Combine(ProgramCore.Project.ProjectPath, "ProfileImage.jpg"); ProgramCore.Project.ProfileImage.Save(projectPath); ControlPointsMode = ProfileControlPointsMode.UpdateRightLeft; }
private void pictureTemplate_Paint(object sender, PaintEventArgs e) { if (ProgramCore.MainForm == null) return; e.Graphics.DrawImage(DrawingImage, ImageTemplateOffsetX, ImageTemplateOffsetY, ImageTemplateWidth, ImageTemplateHeight); if (ProgramCore.Debug && ProgramCore.MainForm.HeadFront) e.Graphics.DrawRectangle(DrawingTools.GreenPen, EyesMouthRectTransformed.X, EyesMouthRectTransformed.Y, EyesMouthRectTransformed.Width, EyesMouthRectTransformed.Height); switch (ProgramCore.MainForm.ctrlRenderControl.Mode) { // case Mode.HeadShapedots: case Mode.HeadAutodots: case Mode.HeadAutodotsFirstTime: DrawAutodotsGroupPoints(e.Graphics); if (RectTransformMode) { e.Graphics.DrawRectangle(DrawingTools.RedPen, FaceRectTransformed); var pointRect = new RectangleF(FaceRectTransformed.X - HalfPointRectSize, FaceRectTransformed.Y - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(DrawingTools.BlueSolidBrush, pointRect); pointRect = new RectangleF(FaceRectTransformed.X + FaceRectTransformed.Width - HalfPointRectSize, FaceRectTransformed.Y - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(DrawingTools.BlueSolidBrush, pointRect); pointRect = new RectangleF(FaceRectTransformed.X + FaceRectTransformed.Width - HalfPointRectSize, FaceRectTransformed.Y + FaceRectTransformed.Height - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(DrawingTools.BlueSolidBrush, pointRect); pointRect = new RectangleF(FaceRectTransformed.X - HalfPointRectSize, FaceRectTransformed.Y + FaceRectTransformed.Height - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(DrawingTools.BlueSolidBrush, pointRect); if (ProgramCore.Project.TextureFlip != FlipType.None) { var centerX = FaceRectTransformed.X + (FaceRectTransformed.Width * 0.5f); e.Graphics.DrawLine(DrawingTools.BluePen, centerX, FaceRectTransformed.Y, centerX, FaceRectTransformed.Bottom); } } break; case Mode.HeadAutodotsLassoStart: case Mode.HeadAutodotsLassoActive: DrawLassoOnPictureBox(e.Graphics, true); break; /*case Mode.HeadShapedotsLassoStart: case Mode.HeadShapedotsLassoActive: DrawLassoOnPictureBox(e.Graphics, false);*/ break; case Mode.HeadLine: if (ProgramCore.MainForm.HeadFront) { #region вид спереди DrawAutodotsGroupPoints(e.Graphics); #endregion } else { #region Вид сбоку if (ProgramCore.Debug) e.Graphics.DrawRectangle(DrawingTools.RedPen, ProfileFaceRectTransformed); #region Верхняя и нижняя точки var points = new[] { ProfileScreenTopLocation, ProfileScreenEyeLocation, ProfileScreenMouthLocation, ProfileScreenBottomLocation }; for (var i = 0; i < points.Length; i += 3) { var point = points[i]; var pointRect = new RectangleF(point.X - HalfPointRectSize, point.Y - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(profileControlPoints[i].Selected ? DrawingTools.RedSolidBrush : DrawingTools.BlueSolidBrush, pointRect); } #endregion #endregion } break; case Mode.None: switch (ControlPointsMode) { case ProfileControlPointsMode.SetControlPoints: case ProfileControlPointsMode.MoveControlPoints: { foreach (var point in profileControlPoints) { if (point.ValueMirrored == Vector2.Zero) continue; var pointK = new Vector2(point.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX, point.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY); var pointRect = new RectangleF(pointK.X - HalfPointRectSize, pointK.Y - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(point.Selected ? DrawingTools.RedSolidBrush : DrawingTools.BlueSolidBrush, pointRect); } } break; case ProfileControlPointsMode.UpdateRightLeft: #region Верхняя и нижняя точки for (var i = 0; i < profileControlPoints.Count; i += 3) { var point = profileControlPoints[i]; if (point.ValueMirrored == Vector2.Zero) continue; var pointK = new Vector2(point.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX, point.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY); var pointRect = new RectangleF(pointK.X - HalfPointRectSize, pointK.Y - HalfPointRectSize, PointRectSize, PointRectSize); e.Graphics.FillRectangle(point.Selected ? DrawingTools.RedSolidBrush : DrawingTools.BlueSolidBrush, pointRect); } #endregion #region Линии лица foreach (var rect in ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ProfileRects) if (rect.LinkedShapeRect != null) { for (var i = 1; i < rect.Points.Length; i++) { var point1 = new Vector2(-rect.Points[i - 1].X, rect.Points[i - 1].Y); var point2 = new Vector2(-rect.Points[i].X, rect.Points[i].Y); var pointM = new MirroredHeadPoint(point1, point1); var pointB = new MirroredHeadPoint(point2, point2); e.Graphics.DrawLine(DrawingTools.GreenPen, (pointM.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX), pointM.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY, (pointB.ValueMirrored.X * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateWidth + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetX), pointB.ValueMirrored.Y * ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateHeight + ProgramCore.MainForm.ctrlTemplateImage.ImageTemplateOffsetY); } } #endregion break; } break; } if (ImageTemplateOffsetX != -1) ProgramCore.MainForm.ctrlRenderControl.headController.DrawOnPictureBox(e.Graphics); }
private void SpecialLipsPointsUpdate(List <HeadPoint> points, Vector2 targetPoint) { var mouthIndices = headController.GetMouthIndexes(); var borders = new Vector3[] { ProgramCore.Project.DetectedLipsPoints[0], ProgramCore.Project.DetectedLipsPoints[4] }; float maxX, minX; var center = GetCenter(points, mouthIndices, out minX, out maxX); var rightPosUserSelected = MirroredHeadPoint.GetFrontWorldPoint(targetPoint, ProgramCore.CurrentProgram); // перенояем координаты с левой картинки в правой var delta2 = rightPosUserSelected - center; var leftBorder = MirroredHeadPoint.GetFrontWorldPoint(borders[0], ProgramCore.CurrentProgram) - rightPosUserSelected; var rightBorder = MirroredHeadPoint.GetFrontWorldPoint(borders[1], ProgramCore.CurrentProgram) - rightPosUserSelected; minX = minX - center.X; maxX = maxX - center.X; //Подгоняем все точки в центр и растягиваем по ширине foreach (var index in mouthIndices) { var p = points[index]; var dx = p.Value.X - center.X; dx = dx < 0.0f ? (dx * leftBorder.X / minX) : (rightBorder.X * dx / maxX); p.Value = new Vector2(center.X + dx + delta2.X, p.Value.Y + delta2.Y); } //Проставляем фиксированные точки var indices = new int[] { 15, 17, 1, 39, 37, 38, 16, 51, 53 }; var i = 0; foreach (var index in indices) { var p = points[index]; p.Value = MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedLipsPoints[i++], ProgramCore.CurrentProgram); } foreach (var index in mouthIndices) { var p = points[index]; autodotsShapeHelper.Transform(p.Value, index); } var lipsPoints = new List <Vector2>(); for (int j = 9; j < 13; ++j) { lipsPoints.Add(MirroredHeadPoint.GetFrontWorldPoint(ProgramCore.Project.DetectedLipsPoints[j], ProgramCore.CurrentProgram)); } autodotsShapeHelper.TransformLips(lipsPoints); var aIndex = indices[indices.Length - 2]; var a = points[aIndex]; var bIndex = indices[indices.Length - 1]; var b = points[bIndex]; const float minLipsDist = 0.3f; if (a.Value.Y - b.Value.Y < minLipsDist) { var centerY = (a.Value.Y + b.Value.Y) * 0.5f; a.Value.Y = centerY - minLipsDist * 0.5f; b.Value.Y = centerY + minLipsDist * 0.5f; } autodotsShapeHelper.Transform(a.Value, aIndex); autodotsShapeHelper.Transform(b.Value, bIndex); }
/// <summary> Load project from path </summary> public static Project FromStream(string path) { Project result; using (var br = new BinaryReader(File.Open(path, FileMode.Open))) { var projectFi = new FileInfo(path); var projectName = br.ReadString(); #region template image var templateImagePath = br.ReadString(); if (!string.IsNullOrEmpty(templateImagePath)) { var fiName = Path.Combine(projectFi.DirectoryName, templateImagePath); var fi = new FileInfo(fiName); if (!fi.Exists) { ProgramCore.EchoToLog("Can't find template image in project.", EchoMessageType.Warning); templateImagePath = string.Empty; } } #endregion var headModelPath = br.ReadString(); var genesisType = (GenesisType)br.ReadInt32(); var manType = (ManType)br.ReadInt32(); var textureFlip = (FlipType)br.ReadInt32(); var shapeFlip = (FlipType)br.ReadInt32(); var isOpenSmile = br.ReadBoolean(); var textureSize = 1024; switch (ProgramCore.CurrentProgram) { case ProgramCore.ProgramMode.HeadShop_OneClick: case ProgramCore.ProgramMode.HeadShop_v11: case ProgramCore.ProgramMode.FaceAge2_Partial: case ProgramCore.ProgramMode.HeadShop_OneClick_v2: case ProgramCore.ProgramMode.HeadShop_Rotator: textureSize = 2048; // если поставит ьу нас в проге 4096 - то все крашится к хуям. Пусть уж только на экспорте будет. break; /* textureSize = 4096; * break;*/ } result = new Project(projectName, projectFi.DirectoryName, templateImagePath, genesisType, manType, headModelPath, false, textureSize, isOpenSmile); result.LoadMeshes(); result.TextureFlip = textureFlip; result.ShapeFlip = shapeFlip; var partsCount = br.ReadInt32(); //part's library for (var i = 0; i < partsCount; i++) { var title = br.ReadString(); var meshType = br.ReadBoolean() ? MeshType.Accessory : MeshType.Hair; var meshVisible = br.ReadBoolean(); var meshPath = br.ReadString(); var meshCounts = br.ReadInt32(); for (var j = 0; j < meshCounts; j++) { var meshTitle = br.ReadString(); DynamicRenderMesh mesh; if (meshType == MeshType.Accessory) { mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes[meshTitle]; } else { mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes[meshTitle]; } if (mesh == null) { continue; } mesh.Title = title + "_" + j; mesh.IsVisible = meshVisible; mesh.Path = meshPath; if (!ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.ContainsKey(title)) { ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.Add(title, new DynamicRenderMeshes()); } ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes[title].Add(mesh); } } result.AutodotsUsed = br.ReadBoolean(); result.RotatedAngle = br.ReadDouble(); // загружаем прямоугольник лица (фронт) result.FaceRectRelative = new RectangleF(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); result.MouthCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.LeftEyeCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.RightEyeCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.NoseUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.MouthUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.LeftEyeUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.RightEyeUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.AgeCoefficient = br.ReadSingle(); result.FatCoefficient = br.ReadSingle(); //Сохраняем цвет головы result.FaceColor = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), 1.0f); #region Информация о модели головы var rmPath = Path.Combine(projectFi.DirectoryName, "Model", "MeshParts.rm"); result.RenderMainHelper.headMeshesController.RenderMesh.Load(rmPath); foreach (var part in result.RenderMainHelper.headMeshesController.RenderMesh.Parts) { if (!string.IsNullOrEmpty(part.TextureName)) { part.Texture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TextureName); } if (!string.IsNullOrEmpty(part.TransparentTextureName)) { part.TransparentTexture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TransparentTextureName); } } var baseDotsCount = br.ReadInt32(); for (var i = 0; i < baseDotsCount; i++) { result.BaseDots.Add(HeadPoint.FromStream(br)); } var profileBaseDotsCount = br.ReadInt32(); for (var i = 0; i < profileBaseDotsCount; i++) { result.ProfileBaseDots.Add(HeadPoint.FromStream(br)); } result.RenderMainHelper.autodotsShapeHelper.ShapeInfo = TexturingInfo.FromStream(br); result.RenderMainHelper.autodotsShapeHelper.ShapeProfileInfo = TexturingInfo.FromStream(br); result.RenderMainHelper.headMeshesController.TexturingInfo = TexturingInfo.FromStream(br); result.RenderMainHelper.headController.AutoDotsv2.Clear(); result.RenderMainHelper.headController.ShapeDots.Clear(); var cnt = br.ReadInt32(); for (var i = 0; i < cnt; i++) { result.RenderMainHelper.headController.ShapeDots.Add(MirroredHeadPoint.FromStreamW(br)); } cnt = br.ReadInt32(); for (var i = 0; i < cnt; i++) { result.RenderMainHelper.headController.AutoDotsv2.Add(HeadPoint.FromStream(br)); } result.CustomHeadNeedProfileSetup = br.ReadBoolean(); #endregion result.ProfileEyeLocation = new Vector2(br.ReadSingle(), br.ReadSingle()); result.ProfileMouthLocation = new Vector2(br.ReadSingle(), br.ReadSingle()); var fi1 = new FileInfo(Path.Combine(projectFi.DirectoryName, "ProfileImage.jpg")); if (fi1.Exists) { using (var fs = new FileStream(fi1.FullName, FileMode.Open)) { using (var bmp = new Bitmap(fs)) result.ProfileImage = (Bitmap)bmp.Clone(); } } try { var hasStage = br.ReadBoolean(); if (hasStage) { ProgramCore.MainForm.ctrlRenderControl.BackgroundTexture = br.ReadString(); } ProgramCore.MainForm.activePanel = br.ReadInt32(); result.projectCamera = new Camera(); result.projectCamera.Scale = br.ReadSingle(); result.projectCamera.beta = br.ReadDouble(); result.projectCamera._dy = br.ReadSingle(); } catch { } try { result.MorphingScale = br.ReadSingle(); } catch { } try { result.TextureSize = br.ReadInt32(); } catch { } } return(result); }
/// <summary> Load project from path </summary> public static Project FromStream(string path) { Project result; using (var br = new BinaryReader(File.Open(path, FileMode.Open))) { var projectFi = new FileInfo(path); var projectName = br.ReadString(); #region template image var templateImagePath = br.ReadString(); if (!string.IsNullOrEmpty(templateImagePath)) { var fiName = Path.Combine(projectFi.DirectoryName, templateImagePath); var fi = new FileInfo(fiName); if (!fi.Exists) { ProgramCore.EchoToLog("Can't find template image in project.", EchoMessageType.Warning); templateImagePath = string.Empty; } } #endregion var headModelPath = br.ReadString(); var manType = (ManType)br.ReadInt32(); var textureFlip = (FlipType)br.ReadInt32(); var shapeFlip = (FlipType)br.ReadInt32(); result = new Project(projectName, projectFi.DirectoryName, templateImagePath, manType, headModelPath, false); result.TextureFlip = textureFlip; result.ShapeFlip = shapeFlip; var partsCount = br.ReadInt32(); //part's library for (var i = 0; i < partsCount; i++) { var title = br.ReadString(); var meshType = br.ReadBoolean() ? MeshType.Accessory : MeshType.Hair; var meshVisible = br.ReadBoolean(); var meshCounts = br.ReadInt32(); for (var j = 0; j < meshCounts; j++) { var meshTitle = br.ReadString(); DynamicRenderMesh mesh; if (meshType == MeshType.Accessory) { mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.AccesoryMeshes[meshTitle]; } else { mesh = ProgramCore.MainForm.ctrlRenderControl.pickingController.HairMeshes[meshTitle]; } if (mesh == null) { continue; } mesh.Title = title + "_" + j; mesh.IsVisible = meshVisible; if (!ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.ContainsKey(title)) { ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes.Add(title, new DynamicRenderMeshes()); } ProgramCore.MainForm.ctrlRenderControl.PartsLibraryMeshes[title].Add(mesh); } } result.AutodotsUsed = br.ReadBoolean(); // загружаем прямоугольник лица (фронт) result.FaceRectRelative = new RectangleF(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); result.MouthCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.LeftEyeCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.RightEyeCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.NoseUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.MouthUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.LeftEyeUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.RightEyeUserCenter = new Vector2(br.ReadSingle(), br.ReadSingle()); result.AgeCoefficient = br.ReadSingle(); result.FatCoefficient = br.ReadSingle(); #region Информация о модели головы var rmPath = Path.Combine(projectFi.DirectoryName, "Model", "MeshParts.rm"); ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Load(rmPath); foreach (var part in ProgramCore.MainForm.ctrlRenderControl.headMeshesController.RenderMesh.Parts) { if (!string.IsNullOrEmpty(part.TextureName)) { part.Texture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TextureName); } if (!string.IsNullOrEmpty(part.TransparentTextureName)) { part.TransparentTexture = ProgramCore.MainForm.ctrlRenderControl.GetTexture(part.TransparentTextureName); } } var baseDotsCount = br.ReadInt32(); for (var i = 0; i < baseDotsCount; i++) { result.BaseDots.Add(HeadPoint.FromStream(br)); } var profileBaseDotsCount = br.ReadInt32(); for (var i = 0; i < profileBaseDotsCount; i++) { result.ProfileBaseDots.Add(HeadPoint.FromStream(br)); } ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeInfo = TexturingInfo.FromStream(br); ProgramCore.MainForm.ctrlRenderControl.autodotsShapeHelper.ShapeProfileInfo = TexturingInfo.FromStream(br); ProgramCore.MainForm.ctrlRenderControl.headMeshesController.TexturingInfo = TexturingInfo.FromStream(br); ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Clear(); ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Clear(); var cnt = br.ReadInt32(); for (var i = 0; i < cnt; i++) { ProgramCore.MainForm.ctrlRenderControl.headController.ShapeDots.Add(MirroredHeadPoint.FromStreamW(br)); } cnt = br.ReadInt32(); for (var i = 0; i < cnt; i++) { ProgramCore.MainForm.ctrlRenderControl.headController.AutoDots.Add(MirroredHeadPoint.FromStreamW(br)); } result.CustomHeadNeedProfileSetup = br.ReadBoolean(); #endregion var fi1 = new FileInfo(Path.Combine(projectFi.DirectoryName, "ProfileImage.jpg")); if (fi1.Exists) { using (var fs = new FileStream(fi1.FullName, FileMode.Open)) { var bmp = new Bitmap(fs); result.ProfileImage = (Bitmap)bmp.Clone(); } } } return(result); }