-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateExamplesChangeColorAndLight.m
152 lines (115 loc) · 4.5 KB
/
CreateExamplesChangeColorAndLight.m
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
pathToAverage = 'Data/average.obj';
pathToTemplate = 'Data/template.obj';
pathToRegions = "Data/template_color.ply";
pathToFaces = 'Data/Faces';
addpath(genpath('C:/Users/HP/Documents/GitHub/meshmonk'));
numModels = 6;
numExamples = 8;
faceCounts = [4, 5, 6, 4, 5, 6, 4, 5];
rainbow = [255, 0, 0; ...
255, 127, 0; ...
255, 255, 0; ...
0, 255, 0; ...
0, 0, 255; ...
46, 43, 95; ...
139, 0, 255];
for exampleId = 1:numExamples
readPath = ['Examples/', num2str(exampleId), '/In'];
readPathHidden = [readPath, '/Hidden'];
% Read initial faces.
for faceId = 1:faceCounts(exampleId)
name = ['\part', num2str(faceId), '.obj'];
% Read obj.
face = LoadFace([readPath, name]);
% Change colors.
face.VertexRGB = repmat(rainbow(faceId, :) / 255, face.nVertices, 1);
face.SingleColor = rainbow(faceId, :) / 255;
face.ColorMode = 'single';
% Change light and take pictures.
v8 = DrawFace(face, "Interpolated face", false);
v8.SceneLightVisible = true;
v8.SceneLightLinked = true;
v8.CameraTarget = [0, 0, 0];
v8.CameraUpVector = [0, 1, 0];
v8.SceneLightPosition = [0, 0, 180];
% Right
v8.CameraPosition = [-180, 0, 0];
saveas(v8.Figure, [readPath, '\part', num2str(faceId), '-Right.png']);
% Right-front
v8.CameraPosition = [-127, 0, +127];
saveas(v8.Figure, [readPath, '\part', num2str(faceId), '-FrontRight.png']);
% Front
v8.CameraPosition = [0, 0, 180];
saveas(v8.Figure, [readPath, '\part', num2str(faceId), '-Front.png']);
% Left-front
v8.CameraPosition = [+127, 0, +127];
saveas(v8.Figure, [readPath, '\part', num2str(faceId), '-FrontLeft.png']);
% Left
v8.CameraPosition = [+180, 0, 0];
saveas(v8.Figure, [readPath, '\part', num2str(faceId), '-Left.png']);
end
% Read spliced.
name = '\inFace.obj';
% Read obj.
face = LoadFace([readPath, name]);
regionByIndex = readmatrix([readPathHidden, '\regionByIndex']);
for j = 1:length(regionByIndex)
face.VertexRGB(j, :) = rainbow(regionByIndex(j), :) / 255;
end
face.ColorMode = 'texture';
% Change light and take pictures.
v8 = DrawFace(face, "Interpolated face", false);
v8.SceneLightVisible = true;
v8.SceneLightLinked = true;
v8.CameraTarget = [0, 0, 0];
v8.CameraUpVector = [0, 1, 0];
v8.SceneLightPosition = [0, 0, 180];
% Right
v8.CameraPosition = [-180, 0, 0];
saveas(v8.Figure, [readPath, '\inFace-Right.png']);
% Right-front
v8.CameraPosition = [-127, 0, +127];
saveas(v8.Figure, [readPath, '\inFace-FrontRight.png']);
% Front
v8.CameraPosition = [0, 0, 180];
saveas(v8.Figure, [readPath, '\inFace-Front.png']);
% Left-front
v8.CameraPosition = [+127, 0, +127];
saveas(v8.Figure, [readPath, '\inFace-FrontLeft.png']);
% Left
v8.CameraPosition = [+180, 0, 0];
saveas(v8.Figure, [readPath, '\inFace-Left.png']);
% Read model outputs.
for modelId = 1:numModels
writePath = ['Examples/', num2str(exampleId), '/Out ', num2str(modelId)];
name = '\outFace.obj';
% Read obj.
face = LoadFace([writePath, name]);
% Change colors.
face.VertexRGB = repmat([0xff, 0xdb, 0xac] / 255, face.nVertices, 1);
face.SingleColor = [0xff, 0xdb, 0xac]; % Why not dividing by 255 here?
face.ColorMode = 'single';
% Change light and take pictures.
v8 = DrawFace(face, "Interpolated face", false);
v8.SceneLightVisible = true;
v8.SceneLightLinked = true;
v8.CameraTarget = [0, 0, 0];
v8.CameraUpVector = [0, 1, 0];
v8.SceneLightPosition = [0, 0, 180];
% Right
v8.CameraPosition = [-180, 0, 0];
saveas(v8.Figure, [writePath, '\outFace-Right.png']);
% Right-front
v8.CameraPosition = [-127, 0, +127];
saveas(v8.Figure, [writePath, '\outFace-FrontRight.png']);
% Front
v8.CameraPosition = [0, 0, 180];
saveas(v8.Figure, [writePath, '\outFace-Front.png']);
% Left-front
v8.CameraPosition = [+127, 0, +127];
saveas(v8.Figure, [writePath, '\outFace-FrontLeft.png']);
% Left
v8.CameraPosition = [+180, 0, 0];
saveas(v8.Figure, [writePath, '\outFace-Left.png']);
end
end