Beispiel #1
0
static void
addface(			/* add a face to a cube */
	register CUBE  *cu,
	OBJECT	obj
)
{

	if (o_face(objptr(obj), cu) == O_MISS)
		return;

	if (istree(cu->cutree)) {
		CUBE  cukid;			/* do children */
		int  i, j;
		cukid.cusize = cu->cusize * 0.5;
		for (i = 0; i < 8; i++) {
			cukid.cutree = octkid(cu->cutree, i);
			for (j = 0; j < 3; j++) {
				cukid.cuorg[j] = cu->cuorg[j];
				if ((1<<j) & i)
					cukid.cuorg[j] += cukid.cusize;
			}
			addface(&cukid, obj);
			octkid(cu->cutree, i) = cukid.cutree;
		}
		return;
	}
	if (isempty(cu->cutree)) {
		OBJECT	oset[2];		/* singular set */
		oset[0] = 1; oset[1] = obj;
		cu->cutree = fullnode(oset);
		return;
	}
					/* add to full node */
	add2full(cu, obj);
}
Beispiel #2
0
static void
add2full(			/* add object to full node */
	register CUBE  *cu,
	OBJECT	obj
)
{
	OCTREE	ot;
	OBJECT	oset[MAXSET+1];
	CUBE  cukid;
	register int  i, j;

	objset(oset, cu->cutree);
	cukid.cusize = cu->cusize * 0.5;

	if (oset[0] < objlim || cukid.cusize <
			(oset[0] < MAXSET ? mincusize : mincusize/256.0)) {
						/* add to set */
		if (oset[0] >= MAXSET) {
			sprintf(errmsg, "set overflow in addobject (%s)",
					objptr(obj)->oname);
			error(INTERNAL, errmsg);
		}
		insertelem(oset, obj);
		cu->cutree = fullnode(oset);
		return;
	}
					/* subdivide cube */
	if ((ot = octalloc()) == EMPTY)
		error(SYSTEM, "out of octree space");
					/* assign subcubes */
	for (i = 0; i < 8; i++) {
		cukid.cutree = EMPTY;
		for (j = 0; j < 3; j++) {
			cukid.cuorg[j] = cu->cuorg[j];
			if ((1<<j) & i)
				cukid.cuorg[j] += cukid.cusize;
		}
		for (j = 1; j <= oset[0]; j++)
			addface(&cukid, oset[j]);
		addface(&cukid, obj);
					/* returned node */
		octkid(ot, i) = cukid.cutree;
	}
	cu->cutree = ot;
}
Beispiel #3
0
void
loadmboxfaces(char *maildir)
{
	CFid *dirfd;
	Dir *d;
	int i, n;

	dirfd = fsopen(mailfs, maildir, OREAD);
	if(dirfd != nil){
		while((n = fsdirread(dirfd, &d)) > 0){
			for(i=0; i<n; i++)
				addface(dirface(maildir, d[i].name));
			free(d);
		}
		fsclose(dirfd);
	}else
		sysfatal("open %s: %r", maildir);
}
Beispiel #4
0
void
loadmboxfaces(char *maildir)
{
	int dirfd;
	Dir *d;
	int i, n;

	dirfd = open(maildir, OREAD);
	if(dirfd >= 0){
		chdir(maildir);
		while((n = dirread(dirfd, &d)) > 0){
			for(i=0; i<n; i++)
				addface(dirface(maildir, d[i].name));
			free(d);
		}
		close(dirfd);
	}
}
Beispiel #5
0
int
main(		/* compile a .OBJ file into a mesh */
	int  argc,
	char  *argv[]
)
{
	int  nmatf = 0;
	char  pathnames[12800];
	char  *pns = pathnames;
	char  *matinp[128];
	char  *cp;
	int  i, j;

	progname = argv[0];
	ofun[OBJ_FACE].funp = o_face;

	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		switch (argv[i][1]) {
		case 'n':				/* set limit */
			objlim = atoi(argv[++i]);
			break;
		case 'r':				/* resolution limit */
			resolu = atoi(argv[++i]);
			break;
		case 'a':				/* material file */
			matinp[nmatf++] = argv[++i];
			break;
		case 'l':				/* library material */
			cp = getpath(argv[++i], getrlibpath(), R_OK);
			if (cp == NULL) {
				sprintf(errmsg,
					"cannot find library material: '%s'",
						argv[i]);
				error(USER, errmsg);
			}
			matinp[nmatf++] = strcpy(pns, cp);
			while (*pns++)
				;
			break;
		case 'w':				/* supress warnings */
			nowarn = 1;
			break;
		default:
			sprintf(errmsg, "unknown option: '%s'", argv[i]);
			error(USER, errmsg);
			break;
		}

	if (i < argc-2)
		error(USER, "too many file arguments");
					/* initialize mesh */
	cvinit(i==argc-2 ? argv[i+1] : "<stdout>");
					/* load material input */
	for (j = 0; j < nmatf; j++)
		readobj(matinp[j]);
					/* read .OBJ file into triangles */
	if (i == argc)
		wfreadobj(NULL);
	else
		wfreadobj(argv[i]);
	
	cvmeshbounds();			/* set octree boundaries */

	if (i == argc-2)		/* open output file */
		if (freopen(argv[i+1], "w", stdout) == NULL)
			error(SYSTEM, "cannot open output file");
	SET_FILE_BINARY(stdout);
	newheader("RADIANCE", stdout);	/* new binary file header */
	printargs(i<argc ? i+1 : argc, argv, stdout);
	fputformat(MESHFMT, stdout);
	fputc('\n', stdout);

	mincusize = ourmesh->mcube.cusize / resolu - FTINY;

	for (i = 0; i < nobjects; i++)	/* add triangles to octree */
		if (objptr(i)->otype == OBJ_FACE)
			addface(&ourmesh->mcube, i);

					/* optimize octree */
	ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree);

	if (ourmesh->mcube.cutree == EMPTY)
		error(WARNING, "mesh is empty");
	
	cvmesh();			/* convert mesh and leaf nodes */

	writemesh(ourmesh, stdout);	/* write mesh to output */
	
	/* printmeshstats(ourmesh, stderr); */

	quit(0);
	return 0; /* pro forma return */
}
Beispiel #6
0
void readobj(FILE *input)
{
	char buffer[256];
	int index_a_vertex, index_a_texture, index_b_vertex, index_b_texture, index_c_vertex, index_c_texture;
	int ignored_a_normal, ignored_b_normal, ignored_c_normal;
	float u, v;
	float x, y, z;
	bool normalsDetected = false;

	if (input == NULL)
	{
		return;
	}

	points = NULL;
	count_points = 0;

	uvcoords = NULL;
	count_uvcoords = 0;

	faces = NULL;
	count_faces = 0;

	while (fgets(buffer, 256, input) != NULL)
	{
		if (buffer[0] == 'v' && buffer[1] == 'n')
		{
			normalsDetected = true;
		}
		else if (buffer[0] == 'v' && buffer[1] == 't')
		{
			sscanf(&buffer[3], "%f %f", &u, &v);
			if (invertV)
				v = 1.0f - v;
			adduvcoord(u,v);
		}
		else if (buffer[0] == 'v')		// && buffer[1] != 't' && buffer[1] != 'n'
		{
			sscanf(&buffer[2], "%f %f %f", &x, &y, &z);
			addpoint(x*scaleFactor,
					 (swapYZ?z:y)*scaleFactor,
					 (swapYZ?y:z)*scaleFactor);
		}
		else if (buffer[0] == 'f' )
		{
			if(normalsDetected)
			{
				sscanf(&buffer[2], "%d/%d/%d %d/%d/%d %d/%d/%d",
					   &index_a_vertex, &index_a_texture, &ignored_a_normal,
					   &index_b_vertex, &index_b_texture, &ignored_b_normal,
					   &index_c_vertex, &index_c_texture, &ignored_c_normal);
			}
			else
			{
				sscanf(&buffer[2], "%d/%d %d/%d %d/%d",
					   &index_a_vertex, &index_a_texture,
					   &index_b_vertex, &index_b_texture,
					   &index_c_vertex, &index_c_texture);
			}

			if(reverseWinding || twoSided)
			{
				addface(index_c_vertex - 1, index_c_texture - 1,
						index_b_vertex - 1, index_b_texture - 1,
						index_a_vertex - 1, index_a_texture - 1);
			}
			if(!reverseWinding || twoSided)
			{
				addface(index_a_vertex - 1, index_a_texture - 1,
						index_b_vertex - 1, index_b_texture - 1,
						index_c_vertex - 1, index_c_texture - 1);
			}
		}
	}
}