This repository was archived by the owner on Nov 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneratorCoroutine.cs
73 lines (62 loc) · 2.27 KB
/
GeneratorCoroutine.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GeneratorCoroutine
{
private EmotionsController emotionsController;
private SnapshotCamera snapshotCamera;
private GameObject directionalLight;
public int frame = 0;
public EmotionsDistribution currentEmotionsDistribution;
public GeneratorCoroutine() {}
public GeneratorCoroutine SetEmotionsController(EmotionsController emotionsController)
{
this.emotionsController = emotionsController;
return this;
}
public GeneratorCoroutine SetSnapshotCamera(SnapshotCamera snapshotCamera)
{
this.snapshotCamera = snapshotCamera;
return this;
}
public GeneratorCoroutine SetDirectionalLight(GameObject directionalLight)
{
this.directionalLight = directionalLight;
return this;
}
public IEnumerator Start(int numberOfImages)
{
if (this.emotionsController == null || this.directionalLight == null
|| this.snapshotCamera == null)
{
throw new Exception("You cannot start without all fields.");
}
List<IEmotion> emotionsPool = emotionsController.GetPool();
int totalEmotions = emotionsPool.Count;
for (int i = 0; i < numberOfImages; i++)
{
// Emotions
this.emotionsController.Reset();
IEmotion mainEmotion = emotionsPool[i % totalEmotions];
this.currentEmotionsDistribution = this.emotionsController.Randomize(mainEmotion, 0.7f, 0.95f);
// Lights
Vector3 rotation = new Vector3(UnityEngine.Random.Range(1.0f, 45.0f),
UnityEngine.Random.Range(-15.0f, 15.0f),
this.directionalLight.transform.eulerAngles.z);
this.directionalLight.transform.eulerAngles = rotation;
// Camera
this.snapshotCamera.RandomizePosition();
this.snapshotCamera.SetActive(true);
yield return new WaitUntil(() =>
{
if (this.frame > 3)
{
this.frame = 0;
return true;
}
else return false;
});
}
}
}