30 GameObject _genericModel;
31 GameObject _snakeImageplane;
40 _genericModel = GameObject.Find(
"Head_mesh");
42 _controlPoints = _genericModel.GetComponent<
ControlPoints> ();
44 _snake = gameObject.GetComponent<
Snake> ();
47 bool finished =
false;
61 public void findFaceContours(Vector2 leftEyeCenter, Vector2 rightEyeCenter, Vector2 mouthCenter){
73 public void findEyebrows(Vector2 leftEyeBrowCenter, Vector2 rightEyeBrowCenter){
85 _snake.enabled =
false;
86 _controlPoints.enabled =
false;
87 _snake.enabled =
true;
88 _controlPoints.enabled =
true;
98 _snake.enabled =
true;
99 _controlPoints.enabled =
true;
103 Vector3[] offsets = RunExpandingSnake (_controlPoints.
ContourFCP);
109 Vector3 eyeScale =
new Vector3(1.5f, 2.3f, 1f);
110 Vector3 eyeBrowsScale =
new Vector3(1.5f, 2f, 1f);
119 _snake.enabled =
true;
120 _controlPoints.enabled =
true;
123 Vector3[] offsets = RunContractingSnake (_controlPoints.
LEyeFCP);
136 _snake.enabled =
true;
137 _controlPoints.enabled =
true;
141 Vector3[] offsets = RunContractingSnake (_controlPoints.
REyeFCP);
153 _snake.enabled =
true;
154 _controlPoints.enabled =
true;
157 Vector3[] offsets = RunContractingSnake (_controlPoints.
LEyebrowCP);
170 _snake.enabled =
true;
171 _controlPoints.enabled =
true;
174 Vector3[] offsets = RunContractingSnake (_controlPoints.
REyebrowCP);
187 _snake.enabled =
true;
188 _controlPoints.enabled =
true;
192 Vector3[] offsets = RunExpandingSnake (_controlPoints.
MouthFCP);
197 bool drawSteps =
true;
207 Vector3[] RunExpandingSnake(Vector3[] startpoints) {
212 Vector3[] startExpWPoints = startpoints;
213 Vector3 meshPos =
new Vector3 (1f, 0f, 0f);
215 for (
int i = 0; i < startExpWPoints.Length; i++ ) {
216 startExpWPoints[i] -= meshPos;
217 startExpWPoints[i].z = -2.0f;
224 Vector3[] expOffsets = _controlPoints.
CalculateOffset (startExpWPoints, expWPoints);
238 Vector3[] RunContractingSnake(Vector3[] startpoints){
242 Vector3[] startContWPoints = startpoints;
243 Vector3 meshPos =
new Vector3 (1f, 0f, 0f);
245 for (
int i = 0; i < startContWPoints.Length; i++ ) {
246 startContWPoints[i] -= meshPos;
247 startContWPoints[i].z = -2.0f;
253 Vector3[] contOffsets = _controlPoints.
CalculateOffset (startContWPoints, contWPoints);
266 Vector3[] transformContour(Vector3[] points, Vector3 scaleFactor, Vector2 newCenter){
268 float xMin =
float.MaxValue;
270 float yMin =
float.MaxValue;
272 float zMin =
float.MaxValue;
276 foreach (Vector3 p
in points) {
291 Vector3 center =
new Vector3 ((xMin + xMax) / 2, (yMin + yMax) / 2, (zMin + zMax) / 2);
293 Vector3 newCenter3 =
new Vector3 (newCenter.x + 1f, newCenter.y, center.z);
295 for (
int i=0; i<points.Length; i++)
296 points[i] = newCenter3 - Vector3.Scale((center - points[i]), scaleFactor);
void DeformMouth(Vector3[] offsets)
Deforms the mouth.
ControlPoints script on mesh.
void DeformREye(Vector3[] offsets)
Deforms the right eye.
void RunLEyeDeformation(Vector2 center)
runs the deformation for the left eye
void resetSnake()
Reinitializes the snake and control points script.
void DeformLEyeBrow(Vector3[] offsets)
Deforms the left eyebrow.
void ApplyDeformation()
Applies the average of the calculated weighted offsets to every vertex in the mesh.
void findEyebrows(Vector2 leftEyeBrowCenter, Vector2 rightEyeBrowCenter)
Runs the eyebrow deformation.
void RunContourDeformation()
runs the deformation for the face contour
void DeformLEye(Vector3[] offsets)
Deforms the left eye.
void SetControlPoints(Vector3[] controlPoints)
Sets the contour.
void DeformContour(Vector3[] offsets)
Deforms the face contour.
void DeformREyeBrow(Vector3[] offsets)
Deforms the right eyebrow.
Vector3[] GetSnakeWorldPoints()
Gets the resulting contour in world coordinates.
void RunREyeDeformation(Vector2 center)
runs the deformation for the right eye
void RunLEyeBrowDeformation(Vector2 center)
runs the deformation for the left eyebrow
void InitSnake(bool expanding=false)
Initializes the snake with the given contour.
void UpdateSnake(int iterations, bool drawSteps)
Executes the snake algorithm.
void ApplyDeformation()
Applies the deformation to the model.
void RunREyeBrowDeformation(Vector2 center)
runs the deformation for the right eyebrow
Vector3[] CalculateOffset(Vector3[] startPoints, Vector3[] endPoints, bool side=false)
Calculates the offset of two contours in world coordinates.
void RunMouthDeformation(Vector2 center)
runs the deformation for the mouth
void findFaceContours(Vector2 leftEyeCenter, Vector2 rightEyeCenter, Vector2 mouthCenter)
Runs the left/rigt eye and mouth deformation.