FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
Fg3CmdCoord.cpp
1//
2// Copyright (c) Singular Inversions Inc. 2012
3//
4// Authors: Andrew Beatty
5// Created: Feb 16, 2012
6//
7
8#include "stdafx.h"
9
10#include "Fg3Face.hpp"
11#include "FgCommand.hpp"
12
13#include "FgSerial.hpp"
14#include "FgFileSystem.hpp"
15#include "FgTestUtils.hpp"
16#include "FgParse.hpp"
17
18using namespace std;
19
20namespace Fg {
21
22namespace {
23
24void
25cmdSplice(CLArgs const & args)
26{
27 Syntax syn(args,
28 "<shape>.fg <color>.fg <result>.fg"
29 );
30 Face3 shape(syn.next());
31 Face3 color(syn.next());
32 color.coord.ts(0,0) = shape.coord.ts(0,0);
33 color.coord.ts(0,1) = shape.coord.ts(0,1);
34 color.save(syn.next());
35}
36
37void
38cmdList(CLArgs const & args)
39{
40 Syntax syn(args,
41 "<face>.fg [(<index> <value>)+]\n"
42 " <face>.fg - will be modified if additional valid arguments are supplied\n"
43 " <index> - coordinate index (starts at 0)\n"
44 " <value> - value to set that coordinate index to"
45 );
46 if (args.size() == 1)
47 syn.error();
48 string fgfile = syn.next();
49 Face3 face;
50 face.load(fgfile);
51
52 Floats coord = face.coord.getVector();
53 if (syn.more()) {
54 while (syn.more()) {
55 size_t idx = syn.nextAs<size_t>();
56 float val = syn.nextAs<float>();
57 if (idx >= coord.size())
58 fgThrow("Face coordinate index out of range",toStr(idx));
59 coord[idx] = val;
60 }
61 face.coord.setVector(coord);
62 face.save(fgfile);
63 }
64 fgout << fgnl << "Face Coordinate:" << fgpush;
65 for (size_t ii=0; ii<coord.size(); ++ii)
66 fgout << fgnl << toStrDigits(ii,3) << ": " << coord[ii];
67}
68
69void
70exportFace(CLArgs const & args)
71{
72 Syntax syn(args,"<face>.fg <base>\n"
73 " Export respective face sub-space coordinates to space-separated-value text files:\n"
74 " <base>_shape_symm.txt\n"
75 " <base>_shape_asym.txt\n"
76 " <base>_color_symm.txt\n"
77 " <base>_color_asym.txt (usually empty - ignore)"
78 );
79 Face3 face(syn.next());
80 string base(syn.next());
81 for (uint mm=0; mm<2; ++mm) {
82 string mode = (mm == 0) ? "shape" : "color";
83 for (uint ss=0; ss<2; ++ss) {
84 string symm = (ss == 0) ? "symm" : "asym";
85 string data;
86 for (float v : face.coord.ts(mm,ss))
87 data += std::to_string(v) + " ";
88 saveRaw(data,base+"_"+mode+"_"+symm+".txt");
89 }
90 }
91}
92
93void
94importFace(CLArgs const & args)
95{
96 Syntax syn(args,"<base> <face>.fg\n"
97 " Read face coordinate from the following space-separated-value text files:\n"
98 " <base>_shape_symm.txt\n"
99 " <base>_shape_asym.txt\n"
100 " <base>_color_symm.txt\n"
101 " <base>_color_asym.txt (usually empty - ignore)"
102 );
103 Face3 face;
104 string base(syn.next());
105 for (uint mm=0; mm<2; ++mm) {
106 string mode = (mm == 0) ? "shape" : "color";
107 for (uint ss=0; ss<2; ++ss) {
108 string symm = (ss == 0) ? "symm" : "asym";
109 string data = loadRawString(base+"_"+mode+"_"+symm+".txt");
110 Strings toks = splitWhitespace(data);
111 face.coord.ts(mm,ss).clear();
112 for (string const & tok : toks)
113 face.coord.ts(mm,ss).push_back(std::stof(tok));
114 }
115 }
116 face.save(syn.next());
117}
118
119}
120
125void
126cmd3Coord(CLArgs const & args)
127{
128 Cmds cmds {
129 {cmdSplice,"splice","Splice shape and color sub-coordinates"},
130 {cmdList,"list","List or set individual coordinates"},
131 {exportFace,"export","Export face coordinates to .txt"},
132 {importFace,"import","Import face coordinates from .txt"},
133 };
134 doMenu(args,cmds);
135}
136
137}
void cmd3Coord(CLArgs const &)