Skip to content

Commit 7dbbf29

Browse files
Merge pull request #20 from schwicke/obj
Add support to export the 3d scene as OBJ file
2 parents ac8b6be + a02961f commit 7dbbf29

32 files changed

+5287
-3645
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@ Some notes on differences with respect to other implementations.
6161
Workstation numbers can be in the range from 0 to 99.
6262

6363
### Workstation types
64-
* 0 PWST_OUTPUT_TRUE Output only on GL display
65-
* 1 PWST_OUTIN_TRUE Input/Output on GL display
66-
* 2 PWST_OUTPUT_TRUE_DB Output only on GL, buffered
67-
* 3 PWST_OUTIN_TRUE_DB Input/Output on GL display, buffered
68-
* 4 PWST_HCOPY_TRUE_TGA Hardcopy to file as TGA
69-
* 5 PWST_HCOPY_TRUE_RGB_PNG Hardcopy to file as PNG RGB only
70-
* 6 PWST_HCOPY_TRUE_RGBA_PNG Hardcopy to file as PNG with Alpha channel
71-
* 7 PWST_HCOPY_TRUE_EPS Hardcopy to file as Encapsulated PostScript, no shaders
72-
* 8 PWST_HCOPY_TRUE_PDF Hardcopy to file as PDF, no shaders
73-
* 9 PWST_HCOPY_TRUE_SVG Hardcopy to file as SVG, no shaders
64+
* 0 PWST_OUTPUT_TRUE Output only on GL display
65+
* 1 PWST_OUTIN_TRUE Input/Output on GL display
66+
* 2 PWST_OUTPUT_TRUE_DB Output only on GL, buffered
67+
* 3 PWST_OUTIN_TRUE_DB Input/Output on GL display, buffered
68+
* 4 PWST_HCOPY_TRUE_TGA Hardcopy to file as TGA
69+
* 5 PWST_HCOPY_TRUE_RGB_PNG Hardcopy to file as PNG RGB only
70+
* 6 PWST_HCOPY_TRUE_RGBA_PNG Hardcopy to file as PNG with Alpha channel
71+
* 7 PWST_HCOPY_TRUE_EPS Hardcopy to file as Encapsulated PostScript, no shaders
72+
* 8 PWST_HCOPY_TRUE_PDF Hardcopy to file as PDF, no shaders
73+
* 9 PWST_HCOPY_TRUE_SVG Hardcopy to file as SVG, no shaders
74+
* 10 PWST_HCOPY_TRUE_OBJ Export geometry as OBJ
7475

7576
Notes:
7677
* There is no support for PostScript at the moment.

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/phigs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (c) 1989, 1990, 1991 X Consortium
44
Copyright (c) 2014 Surplus Users Ham Society
5-
Copyright (c) 2022-2023 CERN
5+
Copyright (c) 2022-2025 CERN
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -163,7 +163,8 @@ typedef enum {
163163
PCAT_PNGA,
164164
PCAT_EPS,
165165
PCAT_PDF,
166-
PCAT_SVG
166+
PCAT_SVG,
167+
PCAT_OBJ
167168
} Pws_cat;
168169

169170
typedef enum {

src/include/phigs/private/wsglP.h

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* This file is part of Open PHIGS
55
* Copyright (C) 2014 Surplus Users Ham Society
6-
* (C) 2022-2023 CERN
6+
* (C) 2022-2025 CERN
77
*
88
* Open PHIGS is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
@@ -119,6 +119,80 @@ typedef struct _Wsgl {
119119
Ws_dev_st dev_st;
120120
} Wsgl;
121121

122+
/* record geometry */
123+
typedef enum {
124+
GEOM_LINE,
125+
GEOM_FACE
126+
} GeomType;
127+
128+
typedef struct {
129+
GeomType type;
130+
int* indices;
131+
int* norms;
132+
int count;
133+
} Geometry;
134+
135+
extern Ppoint3 * vertices;
136+
extern Ppoint3 * normals;
137+
extern int vertex_count;
138+
extern int normal_count;
139+
140+
extern Geometry* geometries;
141+
extern int geom_count;
142+
extern Ppoint3 current_normal;
143+
144+
extern int record_geom;
145+
extern int record_geom_fill;
146+
extern int normal_valid;
147+
148+
#define MAX_VERTICES 10000
149+
/*******************************************************************************
150+
* wsgl_set_current_normal(float x, float y, float z)
151+
*
152+
* DESCR: add 3d vertex
153+
* RETURNS: Non zero or zero on error
154+
*/
155+
void wsgl_set_current_normal(float x, float y, float z);
156+
157+
/*******************************************************************************
158+
* wsgl_add_vertex(float x, float y, float z)
159+
*
160+
* DESCR: add 3d vertex
161+
* RETURNS: Non zero or zero on error
162+
*/
163+
int wsgl_add_vertex(float x, float y, float z);
164+
165+
/*******************************************************************************
166+
* wsgl_add_normal(float x, float y, float z)
167+
*
168+
* DESCR: add 3d vertex
169+
* RETURNS: Non zero or zero on error
170+
*/
171+
int wsgl_add_normal(float x, float y, float z);
172+
173+
/*******************************************************************************
174+
* wsgl_add_geometry(GeomType type, const int* verts, const int* norms, int count)
175+
*
176+
* DESCR: add 3d geometry
177+
* RETURNS: Non zero or zero on error
178+
*/
179+
void wsgl_add_geometry(GeomType type, const int* verts, const int* norms, int count);
180+
181+
/*******************************************************************************
182+
* wsgl_export_obj(const char* filename, const char* title)
183+
* DESCR: export as OBJ file
184+
* RETURNS: Non zero or zero on error
185+
*/
186+
187+
void wsgl_export_obj(const char* filename, const char* title);
188+
/*******************************************************************************
189+
* wsgl_clear_geometry()
190+
*
191+
* DESCR: cleanup geometry records
192+
* RETURNS: Non zero or zero on error
193+
*/
194+
void wsgl_clear_geometry();
195+
122196
/*******************************************************************************
123197
* wsgl_init
124198
*
@@ -1209,8 +1283,7 @@ void wsgl_anno_text_rel(
12091283
* DESCR: Initialise shaders
12101284
* RETURNS: N/A
12111285
*/
1212-
1213-
void wsgl_shaders(Ws * ws);
1286+
void wsgl_shaders(Ws * ws);
12141287

12151288
extern Phg_font *fnt_fonts[];
12161289
extern unsigned char *wsgl_hatch_tbl[];

src/include/phigs/ws_type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (c) 1989, 1990, 1991 X Consortium
44
Copyright (c) 2014 Surplus Users Ham Society
5-
Copyright (c) 2022-2023 CERN
5+
Copyright (c) 2022-2025 CERN
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -67,6 +67,7 @@ extern "C" {
6767
#define PWST_HCOPY_TRUE_EPS 7
6868
#define PWST_HCOPY_TRUE_PDF 8
6969
#define PWST_HCOPY_TRUE_SVG 9
70+
#define PWST_HCOPY_TRUE_OBJ 10
7071

7172
/* Default tables */
7273
#define WST_MIN_PREDEF_LINE_REPS 1

src/libphigs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ SET(P_WSGL_SRCS
8181
wsgl/wsgl_light.c
8282
wsgl/wsgl_line.c
8383
wsgl/wsgl_marker.c
84+
wsgl/wsgl_obj.c
8485
wsgl/wsgl_shaders.c
8586
wsgl/wsgl_sofas3clear.c
8687
wsgl/wsgl_sofas3edge.c

src/libphigs/c_binding/cb_lite.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void pinq_light_src_rep( ws_id, index, type, err_ind, rep)
7070
dt->ws_category == PCAT_EPS ||
7171
dt->ws_category == PCAT_PDF ||
7272
dt->ws_category == PCAT_SVG ||
73+
dt->ws_category == PCAT_OBJ ||
7374
dt->ws_category == PCAT_OUTIN ||
7475
dt->ws_category == PCAT_MO) ) {
7576
*err_ind = ERR59;

src/libphigs/c_binding/cb_phg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void popen_phigs(
110110
phg_wst_add_ws_type(PCAT_EPS, 0);
111111
phg_wst_add_ws_type(PCAT_PDF, 0);
112112
phg_wst_add_ws_type(PCAT_SVG, 0);
113+
phg_wst_add_ws_type(PCAT_OBJ, 0);
113114

114115
PHG_WS_LIST = (Ws_handle *) malloc(sizeof(Ws_handle) * MAX_NO_OPEN_WS);
115116
if (PHG_WS_LIST == NULL) {

0 commit comments

Comments
 (0)