38 #include "bu/parallel.h"
43 #include "../../plugin.h"
46 #define V3ARGSIN(a) (a)[X]/25.4, (a)[Y]/25.4, (a)[Z]/25.4
51 static long vert_offset = 0;
52 static long norm_offset = 0;
53 static int do_normals = 0;
56 static int usemtl = 0;
64 static const char *output_file = NULL;
65 static char *error_file = NULL;
68 static struct db_i *dbip;
71 static struct model *the_model;
75 static int regions_tried = 0;
76 static int regions_converted = 0;
77 static int regions_written = 0;
78 static int inches = 0;
81 gcv_obj_write(
const char *path,
struct db_i *vdbip,
85 size_t num_objects = 0;
86 char **object_names = NULL;
94 tree_state.
ts_m = &the_model;
116 if ((fp = fopen(output_file,
"wb+")) == NULL) {
118 bu_log(
"Cannot open output file (%s) for writing\n", output_file);
126 setmode(fileno(fpe), O_BINARY);
127 }
else if ((fpe = fopen(error_file,
"wb")) == NULL) {
129 bu_log(
"Cannot open output file (%s) for writing\n", error_file);
138 fprintf(fp,
"# BRL-CAD generated Wavefront OBJ file (Units in)\n");
140 fprintf(fp,
"# BRL-CAD generated Wavefront OBJ file (Units mm)\n");
142 fprintf(fp,
"# BRL-CAD model: %s\n# BRL_CAD objects:",
"obj-g");
155 (void)
db_walk_tree(dbip, num_objects, (
const char **)object_names,
163 bu_free(object_names,
"object_names");
165 if (regions_tried > 0) {
166 percent = ((double)regions_converted * 100.0) / regions_tried;
167 printf(
"Tried %d regions, %d converted to NMG's successfully. %g%%\n",
168 regions_tried, regions_converted, percent);
169 percent = ((double)regions_written * 100.0) / regions_tried;
170 printf(
" %d triangulated successfully. %g%%\n",
171 regions_written, percent);
185 {
"obj", NULL, gcv_obj_write},
193 nmg_to_obj(
struct nmgregion *r,
const struct db_full_path *pathp,
194 int UNUSED(region_id),
int aircode,
int los,
int material_id)
230 for (i = 0; i < numverts; i++) {
246 if (fu->orientation != OT_SAME)
271 bu_free(region_name,
"region name");
272 bu_log(
"Vertex from eu %p is not in nmgregion %p\n", (
void *)eu, (
void *)r);
273 bu_exit(1,
"ERROR: Can't find vertex in list!");
277 if (vert_count > 3) {
279 bu_free(region_name,
"region name");
280 bu_log(
"lu %p has %d vertices!\n", (
void *)lu, vert_count);
281 bu_exit(1,
"ERROR: LU is not a triangle\n");
282 }
else if (vert_count < 3)
294 fprintf(fp,
"usemtl %d_%d_%d\n", aircode, los, material_id);
298 for (i = 1; i < pathp->
fp_len; i++)
304 for (i = 0; i < numverts; i++) {
309 fprintf(fp,
"v %f %f %f\n",
V3ARGSIN(v->vg_p->coord));
311 fprintf(fp,
"v %f %f %f\n",
V3ARGS(v->vg_p->coord));
317 struct vertexuse_a_plane *va;
319 va = (
struct vertexuse_a_plane *)
BU_PTBL_GET(&norms, i);
320 NMG_CK_VERTEXUSE_A_PLANE(va);
323 fprintf(fp,
"vn %f %f %f\n",
V3ARGSIN(va->N));
325 fprintf(fp,
"vn %f %f %f\n",
V3ARGS(va->N));
340 if (fu->orientation != OT_SAME)
360 if (!eu->vu_p->a.magic_p) {
388 bu_log(
"Vertex from eu %p is not in nmgregion %p\n", (
void *)eu, (
void *)r);
389 bu_free(region_name,
"region name");
390 bu_exit(1,
"Can't find vertex in list!\n");
397 fprintf(fp,
" %ld//%ld", loc + 1 + vert_offset, j + 1 + norm_offset);
399 fprintf(fp,
" %ld", loc + 1 + vert_offset);
404 if (vert_count > 3) {
406 bu_free(region_name,
"region name");
407 bu_log(
"lu %p has %d vertices!\n", (
void *)lu, vert_count);
408 bu_exit(1,
"ERROR: LU is not a triangle\n");
419 vert_offset += numverts;
427 bu_free(region_name,
"region name");
432 process_triangulation(
struct nmgregion *r,
const struct db_full_path *pathp,
448 bu_log(
"FAILED in triangulator: %s\n", sofar);
449 bu_free((
char *)sofar,
"sofar");
463 bu_log(
"WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
492 bu_log(
"conversion of %s FAILED!\n", name);
509 bu_log(
"WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
512 bu_free(name,
"db_path_to_string");
530 union tree *curtree,
void *
UNUSED(client_data))
532 union tree *ret_tree;
540 NMG_CK_MODEL(*tsp->
ts_m);
546 bu_log(
"\ndo_region_end(%d %d%%) %s\n",
548 regions_tried > 0 ? (regions_converted * 100) / regions_tried : 0,
553 if (curtree->tr_op ==
OP_NOP)
558 ret_tree = process_boolean(curtree, tsp, pathp);
563 r = (
struct nmgregion *)NULL;
569 int empty_region = 0;
576 struct shell *next_s;
595 if (!empty_region && !empty_model) {
596 process_triangulation(r, pathp, tsp);
617 if (regions_tried > 0) {
621 npercent = (float)(regions_converted * 100) / regions_tried;
622 tpercent = (float)(regions_written * 100) / regions_tried;
623 printf(
"Tried %d regions; %d conv. to NMG's, %d conv. to tri.; nmgper = %.2f%%, triper = %.2f%%\n",
624 regions_tried, regions_converted, regions_written, npercent, tpercent);
char * d_namep
pointer to name string
const struct gcv_plugin_info gcv_plugin_conv_obj_write
#define BU_LIST_FOR(p, structure, hp)
struct model ** ts_m
ptr to ptr to NMG "model"
#define NMG_EDGEUSE_MAGIC
int nmg_model_fuse(struct model *m, const struct bn_tol *tol)
void bu_log(const char *,...) _BU_ATTR_PRINTF12
const struct db_tree_state rt_initial_tree_state
struct nmgregion * td_r
ptr to NMG region
int ts_gmater
GIFT compat material code.
#define OP_NOP
Leaf with no effect.
struct bu_list rtg_vlfree
head of bn_vlist freelist
int nmg_kr(struct nmgregion *r)
double dist_sq
dist * dist
void rt_vlist_cleanup(void)
Header file for the BRL-CAD common definitions.
int ts_los
equivalent LOS estimate
int ts_aircode
GIFT compat air code.
int nmg_ks(struct shell *s)
struct resource rt_uniresource
default. Defined in librt/globals.c
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
uint32_t NMG_debug
debug bits for NMG's see nmg.h
#define BU_ALLOC(_ptr, _type)
#define BU_PTBL_GET(ptbl, i)
#define RT_CK_TESS_TOL(_p)
void nmg_km(struct model *m)
void db_free_tree(union tree *tp, struct resource *resp)
union tree * nmg_booltree_leaf_tess(struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt_db_internal *ip, void *client_data)
union tree * do_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, union tree *curtree, void *client_data)
#define BU_LIST_PNEXT(structure, p)
#define UNUSED(parameter)
int nmg_kill_zero_length_edgeuses(struct model *m)
void nmg_triangulate_model(struct model *m, const struct bn_tol *tol)
Support for uniform tolerances.
#define BU_LIST_FIRST_MAGIC(hp)
struct directory ** fp_names
array of dir pointers
char * db_path_to_string(const struct db_full_path *pp)
struct tree::tree_nmgregion tr_d
size_t db_ls(const struct db_i *dbip, int flags, const char *pattern, struct directory ***dpv)
int bu_ptbl_locate(const struct bu_ptbl *b, const long *p)
#define BU_PTBL_LEN(ptbl)
void bu_ptbl_free(struct bu_ptbl *b)
#define RT_CK_FULL_PATH(_p)
struct model * nmg_mm(void)
char ** db_dpv_to_argv(struct directory **dpv)
#define BU_LIST_INIT(_hp)
void nmg_isect2d_final_cleanup(void)
int nmg_kill_cracks(struct shell *s)
#define BU_PTBL_END(ptbl)
const struct rt_tess_tol * ts_ttol
Tessellation tolerance.
double abs
absolute dist tol
#define NMG_VERTEXUSE_A_PLANE_MAGIC
union tree * nmg_booltree_evaluate(register union tree *tp, const struct bn_tol *tol, struct resource *resp)
void bu_free(void *ptr, const char *str)
#define RT_TESS_TOL_MAGIC
int ts_regionid
GIFT compat region ID code.
int db_walk_tree(struct db_i *dbip, int argc, const char **argv, int ncpu, const struct db_tree_state *init_state, int(*reg_start_func)(struct db_tree_state *, const struct db_full_path *, const struct rt_comb_internal *, void *client_data), union tree *(*reg_end_func)(struct db_tree_state *, const struct db_full_path *, union tree *, void *client_data), union tree *(*leaf_func)(struct db_tree_state *, const struct db_full_path *, struct rt_db_internal *, void *client_data), void *client_data)
#define DEBUG_TREEWALK
22 Database tree traversal
HIDDEN void verbose(struct human_data_t *dude)
void db_update_nref(struct db_i *dbip, struct resource *resp)
const struct bn_tol * ts_tol
Math tolerance.
#define BU_LIST_NOT_HEAD(p, hp)
#define BU_LIST_FIRST(structure, hp)
void nmg_vertex_tabulate(struct bu_ptbl *tab, const uint32_t *magic_p)
void nmg_vertexuse_normal_tabulate(struct bu_ptbl *tab, const uint32_t *magic_p)