示例#1
0
int
main(
	int	argc,
	char	*argv[]
)
{
	int	i;

	matfp = stdout;
				/* print out parser version */
	printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR);
				/* initialize dispatch table */
	mg_ehand[MG_E_COMMENT] = r_comment;	/* we pass comments */
	mg_ehand[MG_E_COLOR] = c_hcolor;	/* they get color */
	mg_ehand[MG_E_CONE] = r_cone;		/* we do cones */
	mg_ehand[MG_E_CMIX] = c_hcolor;		/* they mix colors */
	mg_ehand[MG_E_CSPEC] = c_hcolor;	/* they get spectra */
	mg_ehand[MG_E_CXY] = c_hcolor;		/* they get chromaticities */
	mg_ehand[MG_E_CCT] = c_hcolor;		/* they get color temp's */
	mg_ehand[MG_E_CYL] = r_cyl;		/* we do cylinders */
	mg_ehand[MG_E_ED] = c_hmaterial;	/* they get emission */
	mg_ehand[MG_E_FACE] = r_face;		/* we do faces */
	mg_ehand[MG_E_IES] = r_ies;		/* we do IES files */
	mg_ehand[MG_E_IR] = c_hmaterial;	/* they get refractive index */
	mg_ehand[MG_E_MATERIAL] = c_hmaterial;	/* they get materials */
	mg_ehand[MG_E_NORMAL] = c_hvertex;	/* they get normals */
	mg_ehand[MG_E_OBJECT] = obj_handler;	/* they track object names */
	mg_ehand[MG_E_POINT] = c_hvertex;	/* they get points */
	mg_ehand[MG_E_RD] = c_hmaterial;	/* they get diffuse refl. */
	mg_ehand[MG_E_RING] = r_ring;		/* we do rings */
	mg_ehand[MG_E_RS] = c_hmaterial;	/* they get specular refl. */
	mg_ehand[MG_E_SIDES] = c_hmaterial;	/* they get # sides */
	mg_ehand[MG_E_SPH] = r_sph;		/* we do spheres */
	mg_ehand[MG_E_TD] = c_hmaterial;	/* they get diffuse trans. */
	mg_ehand[MG_E_TS] = c_hmaterial;	/* they get specular trans. */
	mg_ehand[MG_E_VERTEX] = c_hvertex;	/* they get vertices */
	mg_ehand[MG_E_XF] = xf_handler;		/* they track transforms */
	mg_init();		/* initialize the parser */
					/* get our options & print header */
	printf("## %s", argv[0]);
	for (i = 1; i < argc && argv[i][0] == '-'; i++) {
		printf(" %s", argv[i]);
		switch (argv[i][1]) {
		case 'g':			/* glow distance (meters) */
			if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
				goto userr;
			glowdist = atof(argv[++i]);
			printf(" %s", argv[i]);
			break;
		case 'e':			/* emitter multiplier */
			if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
				goto userr;
			emult = atof(argv[++i]);
			printf(" %s", argv[i]);
			break;
		case 'm':			/* materials file */
			matfp = fopen(argv[++i], "a");
			if (matfp == NULL) {
				fprintf(stderr, "%s: cannot append\n", argv[i]);
				exit(1);
			}
			printf(" %s", argv[i]);
			break;
		default:
			goto userr;
		}
	}
	putchar('\n');
	if (i == argc) {		/* convert stdin */
		if (mg_load(NULL) != MG_OK)
			exit(1);
		if (mg_nunknown)
			printf("## %s: %u unknown entities\n",
					argv[0], mg_nunknown);
	} else				/* convert each file */
		for ( ; i < argc; i++) {
			printf("## %s %s ##############################\n",
					argv[0], argv[i]);
			if (mg_load(argv[i]) != MG_OK)
				exit(1);
			if (mg_nunknown) {
				printf("## %s %s: %u unknown entities\n",
						argv[0], argv[i], mg_nunknown);
				mg_nunknown = 0;
			}
		}
	exit(0);
userr:
	fprintf(stderr, "Usage: %s [-g dist][-e mult][-m matf] [file.mgf] ..\n",
			argv[0]);
	exit(1);
}
示例#2
0
int
main(
	int	argc,
	char	*argv[]
)
{
	int	i;
				/* initialize dispatch table */
	mg_ehand[MG_E_COMMENT] = i_comment;	/* we pass comments */
	mg_ehand[MG_E_COLOR] = c_hcolor;	/* they get color */
	mg_ehand[MG_E_CMIX] = c_hcolor;		/* they mix colors */
	mg_ehand[MG_E_CSPEC] = c_hcolor;	/* they get spectra */
	mg_ehand[MG_E_CXY] = c_hcolor;		/* they get chromaticities */
	mg_ehand[MG_E_CCT] = c_hcolor;		/* they get color temp's */
	mg_ehand[MG_E_CYL] = i_cyl;		/* we do cylinders */
	mg_ehand[MG_E_ED] = c_hmaterial;	/* they get emission */
	mg_ehand[MG_E_FACE] = i_face;		/* we do faces */
	mg_ehand[MG_E_MATERIAL] = c_hmaterial;	/* they get materials */
	mg_ehand[MG_E_NORMAL] = c_hvertex;	/* they get normals */
	mg_ehand[MG_E_OBJECT] = i_object;	/* we track object names */
	mg_ehand[MG_E_POINT] = c_hvertex;	/* they get points */
	mg_ehand[MG_E_RD] = c_hmaterial;	/* they get diffuse refl. */
	mg_ehand[MG_E_RS] = c_hmaterial;	/* they get specular refl. */
	mg_ehand[MG_E_SIDES] = c_hmaterial;	/* they get # sides */
	mg_ehand[MG_E_SPH] = i_sph;		/* we do spheres */
	mg_ehand[MG_E_TD] = c_hmaterial;	/* they get diffuse trans. */
	mg_ehand[MG_E_TS] = c_hmaterial;	/* they get specular trans. */
	mg_ehand[MG_E_VERTEX] = c_hvertex;	/* they get vertices */
	mg_ehand[MG_E_XF] = i_xf;		/* we track transforms */
	mg_init();		/* initialize the parser */
				/* get options and print format line */
	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		if (!strcmp(argv[i], "-vrml"))
			outtype = O_VRML1;
		else if (!strcmp(argv[i], "-1"))
			outtype = O_INV1;
		else if (!strcmp(argv[i], "-2"))
			outtype = O_INV2;
		else
			goto userr;
	switch (outtype) {
	case O_INV1:
		printf("#Inventor V1.0 ascii\n");
		break;
	case O_INV2:
		printf("#Inventor V2.0 ascii\n");
		break;
	case O_VRML1:
		printf("#VRML V1.0 ascii\n");
		break;
	}
	printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR);
	printf("Separator {\n");		/* begin root node */
						/* general properties */
	printf("MaterialBinding { value OVERALL }\n");
	printf("NormalBinding { value PER_VERTEX_INDEXED }\n");
	if (outtype != O_INV1) {
		printf("ShapeHints {\n");
		printf("\tvertexOrdering CLOCKWISE\n");
		printf("\tfaceType UNKNOWN_FACE_TYPE\n");
		printf("}\n");
	}
	if (i == argc) {	/* load standard input */
		if (mg_load(NULL) != MG_OK)
			exit(1);
		if (mg_nunknown)
			printf("## %s: %u unknown entities\n",
					argv[0], mg_nunknown);
	}
				/* load MGF files */
	for ( ; i < argc; i++) {
		printf("## %s %s ##############################\n",
				argv[0], argv[i]);
		mg_nunknown = 0;
		if (mg_load(argv[i]) != MG_OK)
			exit(1);
		if (mg_nunknown)
			printf("## %s %s: %u unknown entities\n",
					argv[0], argv[i], mg_nunknown);
	}
	flush_cache();		/* flush face cache, just in case */
	printf("}\n");		/* close root node */
	exit(0);
userr:
	fprintf(stderr, "%s: [-1|-2|-vrml] [file] ..\n", argv[0]);
	exit(1);
}