-
Notifications
You must be signed in to change notification settings - Fork 1
/
instructionCreation.js
279 lines (258 loc) · 9.9 KB
/
instructionCreation.js
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
inputs = [];
let modificationsCount = 0;
let counter = 1;
let allChangeList = [];
function modificationJSON(abbrv, dx, dy, dz, infl, transformation) {
modification = {
"Feature-abbrv": abbrv,
"Delta-Magnitude-X": dx,
"Delta-Magnitude-Y": dy,
"Delta-Magnitude-Z": dz,
"InfluenceRadius": infl,
"TransformationType": transformation
}
return modification;
}
function targetModificationsJSON(counter, modelName, falloff, modifications) {
targetModifications = {
"ThreeDModel": modelName,
"OriginalOBJFile": modelName + ".obj",
"OriginalLandmarkFile": modelName + ".json",
"TargetOBJFile": modelName + "-Target-" + counter + ".obj",
"TargetLandmarkFile": modelName + "-Target-" + counter +".json",
"Folder": ".",
"FallOffType": falloff,
"Modifications": modifications
}
return targetModifications;
}
function allModificationsJSON() {
var modelname = document.getElementById("modelname").value;
var falloff = document.getElementById("falloff").value;
var allTargetChanges = [];
counter = 0;
loopContinue = true;
loopIndexCurrent = [];
loopIndexLength = [];
for(i = 0; i < allChangeList.length; i++){
loopIndexCurrent.push(0);
loopIndexLength.push(allChangeList[i].length);
//console.log('current:' + loopIndexCurrent[i] + " - length:" + loopIndexLength[i]);
}
//console.log('loop starts');
while (loopContinue)
{
//console.log('loop next items');
j = 0;
var targetChanges = [];
for (i = 0; i < loopIndexCurrent.length; i++)
{
console.log(i + ": " + loopIndexCurrent[i]);
j = loopIndexCurrent[i];
targetChanges.push(
//(abbrv, dx, dy, dz, infl, transformation)
modificationJSON(
allChangeList[i][j][0],
allChangeList[i][j][3],
allChangeList[i][j][4],
allChangeList[i][j][5],
allChangeList[i][j][6],
allChangeList[i][j][7] )
);
if (allChangeList[i][j][1] == 'Y')
{
targetChanges.push(
//(dualabbrv, -dx, -dy, -dz, infl, transformation)
modificationJSON(
allChangeList[i][j][2],
(allChangeList[i][j][3] * -1),
(allChangeList[i][j][4] * -1),
(allChangeList[i][j][5] * -1),
allChangeList[i][j][6],
allChangeList[i][j][7] )
);
}
}
counter++;
allTargetChanges.push(targetModificationsJSON(counter, modelname, falloff, targetChanges));
// This for loop prepares the index of the next item
// Increments the index of the last abbrv
// If the last abbrv index exceeds the number of items (length),
// it increments the previous item's index
// If first item's (i == 0) current index reaches its length,
// then it means we are done with the outher loop
for (i = loopIndexCurrent.length-1; i >= 0; i--)
{
loopIndexCurrent[i] ++;
if (loopIndexCurrent[i] < loopIndexLength[i])
{
break;
}
else if (i == 0)
{
loopContinue = false;
}
else
{
loopIndexCurrent[i] = 0;
}
}
}
//console.log('loop ended');
return allTargetChanges;
}
function finalModificationsJSON(){
modfiles = {
"ModificationFiles":allModificationsJSON()
}
return modfiles;
}
function prepareChanges() {
document.getElementById("abbrv").value,
document.getElementById("dual").value,
document.getElementById("dualabbrv").value,
document.getElementById("changenumber").value,
document.getElementById("startx").value,
document.getElementById("starty").value,
document.getElementById("startz").value,
document.getElementById("dx").value,
document.getElementById("dy").value,
document.getElementById("dz").value,
document.getElementById("influence").value,
//document.getElementById("modelname").value,
//document.getElementById("falloff").value,
document.getElementById("transformation").value
for (i = 0; i < inputs.length; i++) {
// get inner array
var vals = inputs[i];
var currentAbbrv = vals[0];
var currentDual = vals[1];
var currentDualAbbrv = vals[2];
var iterationNo = parseInt(vals[3]); //changenumber
var currentInfl = vals[10];
var currentTranslation = vals[11];
var startX = 0.0;
var startY = 0.0;
var startZ = 0.0;
var changeDx = 0.0;
var changeDy = 0.0;
var changeDz = 0.0;
var changes = [];
//dx, dy, dz, influence, changenumber, abbrv, modelname, falloff
for (var j = 0; j < iterationNo; j++) {
changeDx = parseFloat(vals[4]) + (parseFloat(vals[7]) * j);
changeDy = parseFloat(vals[5]) + (parseFloat(vals[8]) * j);
changeDz = parseFloat(vals[6]) + (parseFloat(vals[9]) * j);
changes.push([currentAbbrv,
currentDual,
currentDualAbbrv,
changeDx,
changeDy,
changeDz,
currentInfl,
currentTranslation]);
}
console.log(changes);
allChangeList.push(changes);
}
}
function prepareJSON() {
prepareChanges();
var thejson = JSON.stringify(finalModificationsJSON(), null, 4);// last parameter is for space
return thejson;
}
function createAddCell(row, cellValue, bold) {
var cell = document.createElement('td');
cell.textContent = cellValue;
cell.style.border = '1px solid black';
if (bold == 'Y') cell.style = 'font-weight:bold';
row.appendChild(cell);
}
function addModification() {
//startx, starty, startz, dx, dy, dz, influence, changenumber, abbrv, modelname, falloff, translation
currentInput = [
document.getElementById("abbrv").value,
document.getElementById("dual").value,
document.getElementById("dualabbrv").value,
document.getElementById("changenumber").value,
document.getElementById("startx").value,
document.getElementById("starty").value,
document.getElementById("startz").value,
document.getElementById("dx").value,
document.getElementById("dy").value,
document.getElementById("dz").value,
document.getElementById("influence").value,
//document.getElementById("modelname").value,
//document.getElementById("falloff").value,
document.getElementById("transformation").value
];
//console.log(thisInput);
inputs.push(currentInput);
//alert("Modification Added!");
//console.log(inputs);
modificationsCount++;
var container = document.getElementById('container');
container.innerHTML = '';
// create table element
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var row = document.createElement('tr');
createAddCell(row, "Abbrv", 'Y');
createAddCell(row, "Dual", 'Y');
createAddCell(row, "Dual Abbrv", 'Y');
createAddCell(row, "Number of Iterations", 'Y');
createAddCell(row, "Start X", 'Y');
createAddCell(row, "Start Y", 'Y');
createAddCell(row, "Start Z", 'Y');
createAddCell(row, "Magnitude X", 'Y');
createAddCell(row, "Magnitude Y", 'Y');
createAddCell(row, "Magnitude Z", 'Y');
createAddCell(row, "Influence", 'Y');
//createAddCell(row, "Model Name", 'Y');
//createAddCell(row, "Fall Off", 'Y');
createAddCell(row, "Transformation", 'Y');
tbody.appendChild(row);
for (i = 0; i < inputs.length; i++) {
// get inner array
var vals = inputs[i];
// create tr element
var row = document.createElement('tr');
// loop inner array
for (var j = 0; j < vals.length; j++) {
createAddCell(row, vals[j], 'N');
}
//append tr to tbody
tbody.appendChild(row);
}
// append tbody to table
table.appendChild(tbody);
// append table to container
container.appendChild(table);
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Start file download.
function downloadJSON(){
var inputAbbrvs = "";
for (i = 0; i < inputs.length; i++) {
console.log(inputAbbrvs);
// get inner array
var vals = inputs[i];
if (i>0)
inputAbbrvs = inputAbbrvs + "_" + vals[0];//adds abbrv names to the list
else
inputAbbrvs = vals[0];
}
var modelName = document.getElementById("modelname").value;
var filename = modelName + "_" + inputAbbrvs + ".json";
console.log(inputAbbrvs);
console.log(filename);
download(filename, prepareJSON());
}