Skip to content

Commit 0732874

Browse files
committed
add the title to the obj output as name
1 parent 2f86b5f commit 0732874

File tree

8 files changed

+79
-54
lines changed

8 files changed

+79
-54
lines changed

phigs.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ Workstation example for output svg
5757
%wp 0.0 1.0 0.0 1. position
5858
%hs 1. scale factor for hardcopy
5959
%bg 0. 0. 0. Background color R G B
60+
61+
Workstation example for output obj
62+
%wk 93 Workstation for hardcopy
63+
%wg 2480 2480 0 0 1 Window width height px py border
64+
%wp 0.0 1.0 0.0 1. position
65+
%hs 1. scale factor for hardcopy
66+
%bg 0. 0. 0. Background color R G B

src/include/phigs/private/wsglP.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ extern int geom_count;
142142
extern Ppoint3 current_normal;
143143

144144
extern int record_geom;
145+
extern int record_geom_fill;
145146
extern int normal_valid;
146147

147-
#define MAX_VERTICES 500000
148+
#define MAX_VERTICES 10000
148149
/*******************************************************************************
149150
* wsgl_set_current_normal(float x, float y, float z)
150151
*
@@ -178,12 +179,12 @@ extern int normal_valid;
178179
void wsgl_add_geometry(GeomType type, const int* verts, const int* norms, int count);
179180

180181
/*******************************************************************************
181-
* wsgl_export_obj(const char* filename)
182+
* wsgl_export_obj(const char* filename, const char* title)
182183
* DESCR: export as OBJ file
183184
* RETURNS: Non zero or zero on error
184185
*/
185186

186-
void wsgl_export_obj(const char* filename);
187+
void wsgl_export_obj(const char* filename, const char* title);
187188
/*******************************************************************************
188189
* wsgl_clear_geometry()
189190
*

src/libphigs/c_binding/cb_ws.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void pclose_ws(
369369
gl2ps = GL2PS_SVG;
370370
break;
371371
case PCAT_OBJ:
372-
wsgl_export_obj(wsh->filename);
372+
wsgl_export_obj(wsh->filename, config[ws_id].window_title);
373373
record_geom = FALSE;
374374
wsgl_clear_geometry();
375375
clean_fb = TRUE;

src/libphigs/wsgl/wsgl_fasd3fill.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void priv_fill_area3_points(
5555
glVertex3f(points[i].x,
5656
points[i].y,
5757
points[i].z);
58-
if (record_geom){
58+
if (record_geom && record_geom_fill){
5959
vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x,
6060
points[i].y,
6161
points[i].z);
@@ -66,7 +66,7 @@ static void priv_fill_area3_points(
6666
n_normals ++;
6767
}
6868
}
69-
if (record_geom){
69+
if (record_geom && record_geom_fill){
7070
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
7171
}
7272
glEnd();
@@ -99,7 +99,7 @@ static void priv_fill_area3_ptcolrs(
9999
glVertex3f(ptcolrs[i].point.x,
100100
ptcolrs[i].point.y,
101101
ptcolrs[i].point.z);
102-
if (record_geom){
102+
if (record_geom && record_geom_fill){
103103
vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x,
104104
ptcolrs[i].point.y,
105105
ptcolrs[i].point.z);
@@ -110,7 +110,7 @@ static void priv_fill_area3_ptcolrs(
110110
n_normals ++;
111111
}
112112
}
113-
if (record_geom){
113+
if (record_geom && record_geom_fill){
114114
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
115115
}
116116
glEnd();
@@ -143,7 +143,7 @@ static void priv_back_area3_ptcolrs(
143143
glVertex3f(ptcolrs[i].point.x,
144144
ptcolrs[i].point.y,
145145
ptcolrs[i].point.z);
146-
if (record_geom){
146+
if (record_geom && record_geom_fill){
147147
vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x,
148148
ptcolrs[i].point.y,
149149
ptcolrs[i].point.z);
@@ -154,7 +154,7 @@ static void priv_back_area3_ptcolrs(
154154
n_normals ++;
155155
}
156156
}
157-
if (record_geom){
157+
if (record_geom && record_geom_fill){
158158
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
159159
}
160160
glEnd();
@@ -189,7 +189,7 @@ static void priv_fill_area3_ptnorms(
189189
glVertex3f(ptnorms[i].point.x,
190190
ptnorms[i].point.y,
191191
ptnorms[i].point.z);
192-
if (record_geom){
192+
if (record_geom && record_geom_fill){
193193
vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[i].point.x,
194194
ptnorms[i].point.y,
195195
ptnorms[i].point.z);
@@ -200,7 +200,7 @@ static void priv_fill_area3_ptnorms(
200200
n_normals ++;
201201
}
202202
}
203-
if (record_geom){
203+
if (record_geom && record_geom_fill){
204204
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
205205
}
206206
glEnd();
@@ -240,7 +240,7 @@ static void priv_fill_area3_ptconorms(
240240
glVertex3f(ptconorms[i].point.x,
241241
ptconorms[i].point.y,
242242
ptconorms[i].point.z);
243-
if (record_geom){
243+
if (record_geom && record_geom_fill){
244244
vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x,
245245
ptconorms[i].point.y,
246246
ptconorms[i].point.z);
@@ -251,7 +251,7 @@ static void priv_fill_area3_ptconorms(
251251
n_normals ++;
252252
}
253253
}
254-
if (record_geom){
254+
if (record_geom && record_geom_fill){
255255
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
256256
}
257257
glEnd();
@@ -291,7 +291,7 @@ static void priv_back_area3_ptconorms(
291291
glVertex3f(ptconorms[i].point.x,
292292
ptconorms[i].point.y,
293293
ptconorms[i].point.z);
294-
if (record_geom){
294+
if (record_geom && record_geom_fill){
295295
vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x,
296296
ptconorms[i].point.y,
297297
ptconorms[i].point.z);
@@ -302,7 +302,7 @@ static void priv_back_area3_ptconorms(
302302
n_normals ++;
303303
}
304304
}
305-
if (record_geom){
305+
if (record_geom && record_geom_fill){
306306
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
307307
}
308308
glEnd();

src/libphigs/wsgl/wsgl_fasdfill.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void priv_fill_area_points(
5757
glVertex3f(points[i].x,
5858
points[i].y,
5959
0.0);
60-
if (record_geom){
60+
if (record_geom && record_geom_fill){
6161
vertex_indices[n_vertices] = wsgl_add_vertex(points[i].x,
6262
points[i].y,
6363
0.0);
@@ -68,7 +68,7 @@ static void priv_fill_area_points(
6868
n_normals ++;
6969
}
7070
}
71-
if (record_geom){
71+
if (record_geom && record_geom_fill){
7272
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
7373
}
7474
glEnd();
@@ -101,7 +101,7 @@ static void priv_fill_area_ptcolrs(
101101
glVertex3f(ptcolrs[i].point.x,
102102
ptcolrs[i].point.y,
103103
0.0);
104-
if (record_geom){
104+
if (record_geom && record_geom_fill){
105105
vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x,
106106
ptcolrs[i].point.y,
107107
0.0);
@@ -112,7 +112,7 @@ static void priv_fill_area_ptcolrs(
112112
n_normals ++;
113113
}
114114
}
115-
if (record_geom){
115+
if (record_geom && record_geom_fill){
116116
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
117117
}
118118
glEnd();
@@ -145,7 +145,7 @@ static void priv_back_area_ptcolrs(
145145
glVertex3f(ptcolrs[i].point.x,
146146
ptcolrs[i].point.y,
147147
0.0);
148-
if (record_geom){
148+
if (record_geom && record_geom_fill){
149149
vertex_indices[n_vertices] = wsgl_add_vertex(ptcolrs[i].point.x,
150150
ptcolrs[i].point.y,
151151
0.0);
@@ -156,7 +156,7 @@ static void priv_back_area_ptcolrs(
156156
n_normals ++;
157157
}
158158
}
159-
if (record_geom){
159+
if (record_geom && record_geom_fill){
160160
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
161161
}
162162
glEnd();
@@ -191,7 +191,7 @@ static void priv_fill_area_ptnorms(
191191
glVertex3f(ptnorms[i].point.x,
192192
ptnorms[i].point.y,
193193
0.0);
194-
if (record_geom){
194+
if (record_geom && record_geom_fill){
195195
vertex_indices[n_vertices] = wsgl_add_vertex(ptnorms[i].point.x,
196196
ptnorms[i].point.y,
197197
0.0);
@@ -202,7 +202,7 @@ static void priv_fill_area_ptnorms(
202202
n_normals ++;
203203
}
204204
}
205-
if (record_geom){
205+
if (record_geom && record_geom_fill){
206206
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
207207
}
208208
glEnd();
@@ -242,7 +242,7 @@ static void priv_fill_area_ptconorms(
242242
glVertex3f(ptconorms[i].point.x,
243243
ptconorms[i].point.y,
244244
0.0);
245-
if (record_geom){
245+
if (record_geom && record_geom_fill){
246246
vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x,
247247
ptconorms[i].point.y,
248248
0.0);
@@ -253,7 +253,7 @@ static void priv_fill_area_ptconorms(
253253
n_normals ++;
254254
}
255255
}
256-
if (record_geom){
256+
if (record_geom && record_geom_fill){
257257
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
258258
}
259259
glEnd();
@@ -293,7 +293,7 @@ static void priv_back_area_ptconorms(
293293
glVertex3f(ptconorms[i].point.x,
294294
ptconorms[i].point.y,
295295
0.0);
296-
if (record_geom){
296+
if (record_geom && record_geom_fill){
297297
vertex_indices[n_vertices] = wsgl_add_vertex(ptconorms[i].point.x,
298298
ptconorms[i].point.y,
299299
0.0);
@@ -304,7 +304,7 @@ static void priv_back_area_ptconorms(
304304
n_normals ++;
305305
}
306306
}
307-
if (record_geom){
307+
if (record_geom && record_geom_fill){
308308
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
309309
}
310310
glEnd();

src/libphigs/wsgl/wsgl_fill.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ void priv_fill_area(
4949
for (i = 0; i < point_list->num_points; i++) {
5050
glVertex2f(point_list->points[i].x,
5151
point_list->points[i].y);
52-
if (record_geom){
52+
if (record_geom && record_geom_fill){
53+
#ifdef DEBUG_OBJ
54+
printf("wsgl_fill: priv_fill_area called\n");
55+
#endif
5356
vertex_indices[n_vertices] = wsgl_add_vertex(point_list->points[i].x,
5457
point_list->points[i].y,
5558
0.0);
@@ -60,7 +63,7 @@ void priv_fill_area(
6063
n_normals ++;
6164
}
6265
}
63-
if (record_geom){
66+
if (record_geom && record_geom_fill){
6467
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
6568
}
6669
glEnd();
@@ -120,7 +123,10 @@ void priv_fill_area3(
120123
glVertex3f(point_list->points[i].x,
121124
point_list->points[i].y,
122125
point_list->points[i].z);
123-
if (record_geom){
126+
if (record_geom && record_geom_fill){
127+
#ifdef DEBUG_OBJ
128+
printf("wsgl_fill: priv_fill_area3 called\n");
129+
#endif
124130
vertex_indices[n_vertices] = wsgl_add_vertex(point_list->points[i].x,
125131
point_list->points[i].y,
126132
point_list->points[i].z);
@@ -131,7 +137,7 @@ void priv_fill_area3(
131137
n_normals ++;
132138
}
133139
}
134-
if (record_geom){
140+
if (record_geom && record_geom_fill){
135141
wsgl_add_geometry(GEOM_FACE, vertex_indices, normal_indices, n_vertices);
136142
}
137143
glEnd();

src/libphigs/wsgl/wsgl_obj.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int geom_count = 0;
4545
Ppoint3 current_normal;
4646

4747
int record_geom = FALSE;
48+
int record_geom_fill = TRUE;
4849
int normal_valid = FALSE;
4950

5051
/*******************************************************************************
@@ -67,10 +68,6 @@ void wsgl_set_current_normal(float x, float y, float z) {
6768
* RETURNS: Non zero or zero on error
6869
*/
6970
int wsgl_add_vertex(float x, float y, float z) {
70-
if (vertex_count >= MAX_VERTICES){
71-
printf("Error: maximum number %d of vertices exceeded \n", vertex_count);
72-
return vertex_count;
73-
}
7471
vertices = realloc(vertices, sizeof(Ppoint3) * (vertex_count + 1));
7572
if (!vertices) {
7673
fprintf(stderr, "Out of memory adding vertex\n");
@@ -92,10 +89,6 @@ int wsgl_add_vertex(float x, float y, float z) {
9289
* RETURNS: Non zero or zero on error
9390
*/
9491
int wsgl_add_normal(float x, float y, float z) {
95-
if (normal_count >= MAX_VERTICES){
96-
printf("Error: maximum number %d of vertices exceeded \n", normal_count);
97-
return normal_count;
98-
}
9992
normals = realloc(normals, sizeof(Ppoint3) * (normal_count + 1));
10093
if (!normals) {
10194
fprintf(stderr, "Out of memory adding normal\n");
@@ -144,7 +137,7 @@ void wsgl_add_geometry(GeomType type, const int* verts, const int* norms, int co
144137
* DESCR: export as OBJ file
145138
* RETURNS: Non zero or zero on error
146139
*/
147-
void wsgl_export_obj(const char* filename) {
140+
void wsgl_export_obj(const char* filename, const char* title) {
148141
FILE* f = fopen(filename, "w");
149142
if (!f) {
150143
perror("fopen");
@@ -153,7 +146,7 @@ void wsgl_export_obj(const char* filename) {
153146
#ifdef DEBUG_OBJ
154147
printf("wsgl_obj: exporting %d vertices and %d normals\n", vertex_count, normal_count);
155148
#endif
156-
149+
fprintf(f, "#name:%s\n", title);
157150
for (int i = 0; i < normal_count; ++i) {
158151
fprintf(f, "vn %f %f %f\n",
159152
normals[i].x,

0 commit comments

Comments
 (0)