Ejemplo n.º 1
0
int
main(int argc, char** argv)
{
    struct rt_wdb* outfp;
    ON_Brep* brep;
    ON_TextLog error_log;
    const char* id_name = "B-Rep Example";
    const char* geom_name = "cube.s";

    ON::Begin();

    if (argc > 1) {
	printf("Writing a twisted cube b-rep...\n");
	outfp = wdb_fopen("brep_cube1.g");
	mk_id(outfp, id_name);
	brep = MakeTwistedCube(error_log);
	mk_brep(outfp, geom_name, brep);

	//mk_comb1(outfp, "cube.r", geom_name, 1);
	unsigned char rgb[] = {255,255,255};
	mk_region1(outfp, "cube.r", geom_name, "plastic", "", rgb);

	wdb_close(outfp);
	delete brep;
    }

    printf("Reading a twisted cube b-rep...\n");
    struct db_i* dbip = db_open("brep_cube1.g", "r");
    db_dirbuild(dbip);
    struct directory* dirp;
    if ((dirp = db_lookup(dbip, "cube.s", 0)) != DIR_NULL) {
	printf("\tfound cube.s\n");
	struct rt_db_internal ip;
	mat_t mat;
	MAT_IDN(mat);
	if (rt_db_get_internal(&ip, dirp, dbip, mat, &rt_uniresource) >= 0) {
	    printPoints((struct rt_brep_internal*)ip.idb_ptr);
	} else {
	    fprintf(stderr, "problem getting internal object rep\n");
	}
    }
    db_close(dbip);

    ON::End();

    return 0;
}
Ejemplo n.º 2
0
void
do_light(char *name, fastf_t *pos, fastf_t *dir_at, int da_flag, double r, unsigned char *rgb, struct wmember *headp)


    /* direction or aim point */
    /* 0 = direction, !0 = aim point */
    /* radius of light */


{
    char	nbuf[64];
    vect_t	center;
    mat_t	rot;
    mat_t	xlate;
    mat_t	both;
    vect_t	from;
    vect_t	dir;

    if ( da_flag )  {
	VSUB2( dir, dir_at, pos );
	VUNITIZE( dir );
    } else {
	VMOVE( dir, dir_at );
    }

    snprintf( nbuf, 64, "%s.s", name );
    VSETALL( center, 0 );
    mk_sph( outfp, nbuf, center, r );

    /*
     * Need to rotate from 0, 0, -1 to vect "dir",
     * then xlate to final position.
     */
    VSET( from, 0, 0, -1 );
    bn_mat_fromto( rot, from, dir );
    MAT_IDN( xlate );
    MAT_DELTAS_VEC( xlate, pos);
    bn_mat_mul( both, xlate, rot );

    mk_region1( outfp, name, nbuf, "light", "shadows=1", rgb );
    (void)mk_addmember( name, &(headp->l), NULL, WMOP_UNION );
}
Ejemplo n.º 3
0
void
make_pillar(char *prefix, int ix, int iy, fastf_t *center, fastf_t *lwh, struct wmember *headp)


    /* center of base */


{
    vect_t	min, max;
    unsigned char	rgb[4];		/* needs all 4 */
    char	pilname[32], rname[32], sname[32], oname[32];
    int	i;
    struct wmember head;
    struct wmember *wp;

    BU_LIST_INIT( &head.l );

    snprintf( pilname, 32, "%s%d,%d", prefix, ix, iy );
    snprintf( rname, 32, "%s.r", pilname );
    snprintf( sname, 32, "%s.s", pilname );
    snprintf( oname, 32, "Obj%d,%d", ix, iy );

    VMOVE( min, center );
    min[X] -= lwh[X];
    min[Y] -= lwh[Y];
    VADD2( max, center, lwh );
    mk_rpp( outfp, sname, min, max );

    /* Needs to be in a region, with color!  */
    get_rgb(rgb);
    i = PICK_MAT;
    mk_region1( outfp, rname, sname,
		mtab[i].mt_name, mtab[i].mt_param, rgb );

    (void)mk_addmember( rname, &head.l, NULL, WMOP_UNION );
    wp = mk_addmember( oname, &head.l, NULL, WMOP_UNION );
    MAT_DELTAS( wp->wm_mat, center[X], center[Y], center[Z]+lwh[Z] );
    mk_lfcomb( outfp, pilname, &head, 0 );

    (void)mk_addmember( pilname, &(headp->l), NULL, WMOP_UNION );
}
Ejemplo n.º 4
0
void
make_carpet(char *rname, fastf_t *min, fastf_t *max, char *file, struct wmember *headp)
{
    char	sname[32];
    char	args[128];
    vect_t	cmin, cmax;

    VMOVE( cmin, min );
    VMOVE( cmax, max );
    cmax[Z] = cmin[Z] + 10;		/* not very plush carpet */
    min[Z] = cmax[Z];		/* raise the caller's floor */

    snprintf( sname, 32, "%s.s", rname );
    snprintf( args, 128, "texture file=%s;plastic", file );
    mk_rpp( outfp, sname, cmin, cmax );
    mk_region1( outfp, rname, sname,
		"stack", args,
		(unsigned char *)0 );

    (void)mk_addmember( rname, &(headp->l), NULL, WMOP_UNION );
}
Ejemplo n.º 5
0
int
main(int argc, char** argv)
{
    struct rt_wdb* outfp;
    ON_Brep* brep;
    ON_TextLog error_log;
    ON_3dPoint origin(0.0,0.0,0.0);
    const char* id_name = "B-Rep Cobb Sphere";
    const char* geom_name = "cobb.s";

    if (argc > 1 || BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) {
	return 0;
    }

    ON::Begin();

    /* export brep to file */
    bu_log("Writing a Cobb unit sphere b-rep...\n");
    outfp = wdb_fopen("brep_cobb.g");
    mk_id(outfp, id_name);


    brep = Cobb_Sphere(1, &origin);
    mk_brep(outfp, geom_name, brep);

    //mk_comb1(outfp, "cube.r", geom_name, 1);
    unsigned char rgb[] = {50, 255, 50};
    mk_region1(outfp, "cobb.r", geom_name, "plastic", "", rgb);

    wdb_close(outfp);
    delete brep;

    ON::End();

    return 0;
}
Ejemplo n.º 6
0
int
main(int argc, char **argv)
{
    vect_t	norm;
    unsigned char	rgb[3];
    int	ix;
    double	x;
    double	size;
    int	quant;
    struct wmember head;
    vect_t	bmin, bmax, bthick;
    vect_t	r1min, r1max, r1thick;
    vect_t	lwh;		/* length, width, height */
    vect_t	pbase;

    BU_LIST_INIT( &head.l );

    MAT_IDN( identity );
    sin60 = sin(60.0 * 3.14159265358979323846264 / 180.0);

    outfp = wdb_fopen("room.g");
    mk_id( outfp, "Procedural Rooms" );

    /* Create the building */
    VSET( bmin, 0, 0, 0 );
    VSET( bmax, 80000, 60000, HEIGHT );
    VSET( bthick, 100, 100, 100 );
    make_room( "bldg", bmin, bmax, bthick, &head );

    /* Create the first room */
    VSET( r1thick, 100, 100, 0 );
    VMOVE( r1min, bmin );
    VSET( r1max, 40000, 10000, HEIGHT );
    VADD2( r1max, r1min, r1max );
    make_walls( "rm1", r1min, r1max, r1thick, NORTH|EAST, &head );
    make_carpet( "rm1carpet", r1min, r1max, "carpet.pix", &head );

    /* Create the golden earth */
    VSET( norm, 0, 0, 1 );
    mk_half( outfp, "plane", norm, -bthick[Z]-10.0 );
    rgb[0] = 240;	/* gold/brown */
    rgb[1] = 180;
    rgb[2] = 64;
    mk_region1( outfp, "plane.r", "plane", NULL, NULL, rgb );
    (void)mk_addmember( "plane.r", &head.l, NULL, WMOP_UNION );

    /* Create the display pillars */
    size = 4000;	/* separation between centers */
    quant = 5;	/* pairs */
    VSET( lwh, 400, 400, 1000 );
    for ( ix=quant-1; ix>=0; ix-- )  {
	x = 10000 + ix*size;
	VSET( pbase, x, 10000*.25, r1min[Z] );
	make_pillar( "Pil", ix, 0, pbase, lwh, &head );
	VSET( pbase, x, 10000*.75, r1min[Z] );
	make_pillar( "Pil", ix, 1, pbase, lwh, &head );
    }

#ifdef never
    /* Create some light */
    white[0] = white[1] = white[2] = 255;
    base = size*(quant/2+1);
    VSET( aim, 0, 0, 0 );
    VSET( pos, base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l1", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l2", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l3", pos, aim, 1, 100.0, white, &head );
    VSET( pos, base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l4", pos, aim, 1, 100.0, white, &head );
#endif

    /* Build the overall combination */
    mk_lfcomb( outfp, "room", &head, 0 );

    return 0;
}