1 //////////////////////////////////////////////////////////////////////
2 //
3 // Pixie
4 //
5 // Copyright � 1999 - 2003, Okan Arikan
6 //
7 // Contact: okan@cs.utexas.edu
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 ///////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////
25 //
26 // File : texmake.cpp
27 // Classes : -
28 // Description : Texture making program
29 //
30 ////////////////////////////////////////////////////////////////////////
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "common/global.h"
36 #include "common/os.h"
37 #include "ri/ri.h"
38
39 const char *tileSizeArgument = "-tilesize";
40 const char *resizeModeArgument = "-resize";
41 const char *smodeArgument = "-smode";
42 const char *tmodeArgument = "-tmode";
43 const char *filterArgument = "-filter";
44 const char *filterWidthArgument = "-filterwidth";
45 const char *sfilterWidthArgument = "-sfilterwidth";
46 const char *tfilterWidthArgument = "-tfilterwidth";
47 const char *inputPathArgument = "-input";
48 const char *outputPathArgument = "-output";
49 const char *shadowArgument = "-shadow";
50 const char *envlatArgument = "-envlatl";
51 const char *envcubeArgument = "-envcube";
52 const char *fovArgument = "-fov";
53 const char *texture3dArgument = "-texture3d";
54 const char *maxerrorArgument = "-maxerror";
55 const char *radiusscaleArgument = "-radiusscale";
56 const char *maxdepthArgument = "-maxdepth";
57
printUsage()58 void printUsage() {
59 printf("Usage: texmake [-(shadow|envlatl|envcube)] [-resize <mode>] [-smode <mode>] [-tmode <mode>] [-filter <filter>] [-filterwidth <width>] [-filterheight <height>] [-sfilterwidth <width>] [-tfilterwidth <width>] <inputfile> <outputfile>\n");
60 printf(" texmake -texture3d [-maxerror <number>] [-radiusscale <number>] [-maxdepth <number>] <inputfile> <outputfile>\n");
61 }
62
main(int argc,char * argv[])63 int main(int argc, char* argv[]) {
64 int tileSize = 32;
65 const char *resizeMode = "up";
66 const char *smode = "periodic";
67 const char *tmode = "periodic";
68 float filterWidth = 3;
69 float filterHeight = 3;
70 const char *inPath = ".";
71 const char *outPath = ".";
72 float fov = 90;
73 RtFilterFunc filter = RiCatmullRomFilter;
74 float maxerror = 0.002f;
75 float radiusScale = 1.0f;
76 int maxDepth = 10;
77 int i;
78 const char *textureMode = "texture";
79 int processed;
80
81 RtToken tokens[50];
82 RtPointer vals[50];
83 const char *files[50];
84 int currentFile = 0;
85 int currentParameter = 0;
86
87 if (argc == 1) {
88 printUsage();
89 return 0;
90 }
91
92 for (i=1;i<argc;i++) {
93 if (strcmp(argv[i],"--help") == 0) {
94 printUsage();
95 } else if (strcmp(argv[i],shadowArgument) == 0) {
96 textureMode = "shadow";
97 } else if (strcmp(argv[i],envlatArgument) == 0) {
98 textureMode = "envlat";
99 } else if (strcmp(argv[i],envcubeArgument) == 0) {
100 textureMode = "envcube";
101 } else if (strcmp(argv[i],texture3dArgument) == 0) {
102 textureMode = "texture3d";
103 } else if (strcmp(argv[i],tileSizeArgument) == 0) {
104 i++;
105 tileSize = atoi(argv[i]);
106 } else if (strcmp(argv[i],resizeModeArgument) == 0) {
107 i++;
108 resizeMode = argv[i];
109 } else if (strcmp(argv[i],smodeArgument) == 0) {
110 i++;
111 smode = argv[i];
112 } else if (strcmp(argv[i],tmodeArgument) == 0) {
113 i++;
114 tmode = argv[i];
115 } else if (strcmp(argv[i],filterArgument) == 0) {
116 i++;
117 if (strcmp(argv[i],"box") == 0) {
118 filter = RiBoxFilter;
119 } else if (strcmp(argv[i],"triangle") == 0) {
120 filter = RiTriangleFilter;
121 } else if (strcmp(argv[i],"gaussian") == 0) {
122 filter = RiGaussianFilter;
123 } else if (strcmp(argv[i],"catmull-rom") == 0) {
124 filter = RiCatmullRomFilter;
125 } else if (strcmp(argv[i],"sinc") == 0) {
126 filter = RiSincFilter;
127 } else {
128 fprintf(stderr,"Unknown filter: %s\n",argv[i]);
129 }
130 } else if (strcmp(argv[i],filterWidthArgument) == 0) {
131 i++;
132 filterWidth = (float) atof(argv[i]);
133 filterHeight = (float) atof(argv[i]);
134 } else if (strcmp(argv[i],sfilterWidthArgument) == 0) {
135 i++;
136 filterWidth = (float) atof(argv[i]);
137 } else if (strcmp(argv[i],tfilterWidthArgument) == 0) {
138 i++;
139 filterHeight = (float) atof(argv[i]);
140 } else if (strcmp(argv[i],fovArgument) == 0) {
141 i++;
142 fov = (float) atof(argv[i]);
143 } else if (strcmp(argv[i],maxerrorArgument) == 0) {
144 i++;
145 maxerror = (float) atof(argv[i]);
146 } else if (strcmp(argv[i],radiusscaleArgument) == 0) {
147 i++;
148 radiusScale = (float) atof(argv[i]);
149 } else if (strcmp(argv[i],maxdepthArgument) == 0) {
150 i++;
151 maxDepth = (int) atoi(argv[i]);
152 } else if (strcmp(argv[i],inputPathArgument) == 0) {
153 i++;
154 inPath = argv[i];
155 } else if (strcmp(argv[i],outputPathArgument) == 0) {
156 i++;
157 outPath = argv[i];
158 } else {
159 files[currentFile++] = argv[i];
160 }
161 }
162
163 processed = FALSE;
164
165 if (strcmp(textureMode,"texture") == 0) {
166 if (currentFile == 2) {
167 RiBegin(RI_NULL);
168 tokens[currentParameter] = "resize";
169 vals[currentParameter++] = (RtPointer) &resizeMode;
170 RiMakeTextureV(files[0],files[1],smode,tmode,filter,filterWidth,filterHeight,currentParameter,tokens,vals);
171 RiEnd();
172
173 processed = TRUE;
174 }
175 } else if (strcmp(textureMode,"shadow") == 0) {
176 if (currentFile == 2) {
177 RiBegin(RI_NULL);
178 tokens[currentParameter] = "resize";
179 vals[currentParameter++] = (RtPointer) &resizeMode;
180 RiMakeShadowV(files[0],files[1],currentParameter,tokens,vals);
181 RiEnd();
182
183 processed = TRUE;
184 }
185 } else if (strcmp(textureMode,"envlat") == 0) {
186 if (currentFile == 2) {
187 RiBegin(RI_NULL);
188 tokens[currentParameter] = "resize";
189 vals[currentParameter++] = (RtPointer) &resizeMode;
190 RiMakeLatLongEnvironmentV(files[0],files[1],filter,filterWidth,filterHeight,currentParameter,tokens,vals);
191 RiEnd();
192
193 processed = TRUE;
194 }
195 } else if (strcmp(textureMode,"envcube") == 0) {
196 if (currentFile == 7) {
197 RiBegin(RI_NULL);
198 tokens[currentParameter] = "resize";
199 vals[currentParameter++] = &resizeMode;
200 RiMakeCubeFaceEnvironmentV(files[0],files[1],files[2],files[3],files[4],files[5],files[6],fov,filter,filterWidth,filterHeight,currentParameter,tokens,vals);
201 RiEnd();
202
203 processed = TRUE;
204 }
205 } else if (strcmp(textureMode,"texture3d") == 0) {
206 if (currentFile == 2) {
207 RiBegin(RI_NULL);
208 tokens[currentParameter] = RI_MAXERROR;
209 vals[currentParameter++] = (RtPointer) &maxerror;
210 tokens[currentParameter] = "radiusscale";
211 vals[currentParameter++] = (RtPointer) &radiusScale;
212 tokens[currentParameter] = "maxdepth";
213 vals[currentParameter++] = (RtPointer) &maxDepth;
214 RiMakeBrickMapV(1,&files[0],files[1],currentParameter,tokens,vals);
215 RiEnd();
216
217 processed = TRUE;
218 }
219 }
220
221 if (processed == FALSE) {
222 fprintf(stderr,"Unknown texture mode (\"%s\") or invalid number of arguments (%d)\n",textureMode,currentFile);
223 }
224
225 return 0;
226 }
227
228