读取stl文件解析成mc op

#include "stdafx.h"
#include <Windows.h>

double t[300000][3];
char temp[MAX_PATH];
double x1, y1, z1, x2, y2, z2, x3, y3, z3;
double maxx = 0, maxy = 0, maxz = 0;
bool redo[200][200][200];
typedef struct {
	int x, y, z;
} point_int;
void fill(point_int a, point_int b, point_int c) {
	point_int center;
	center.x = (a.x+b.x+c.x) / 3;
	center.y = (a.y + b.y + c.y) / 3;
	center.z = (a.z + b.z + c.z) / 3;
	redo[a.x + 100][a.y + 100][a.z + 100] = 1;//避免越界 +100
	redo[b.x + 100][b.y + 100][b.z + 100] = 1;
	redo[c.x + 100][c.y + 100][c.z + 100] = 1;
	if (center.x==a.x && center.y == a.y && center.z==a.z) return;
	if (center.x ==b.x && center.y == b.y && center.z == b.z) return;
	if (center.x == c.x && center.y == c.y && center.z == c.z) return;
	fill(a,b,center);
	fill(b,c,center);
	fill(a,c,center);
}


int main(int argc, char ** argv)
{
	printf("%d", argc);
	if (argc != 2) return 0;
	FILE *f;
	f = fopen(argv[1], "r");
	fscanf(f, "%s %s", temp, temp);
	int i = 0;
	for (i = 0;; i++) {
		fscanf(f, "%s %s", temp, temp);
		if (strcmp(temp, "normal") != 0)break;
		fscanf(f, "%lf %lf %lf\n", &x1, &y1, &z1);

		fscanf(f, "%s %s\n%s", temp, temp, temp);
		fscanf(f, "%lf %lf %lf\n", &x1, &y1, &z1);
		fscanf(f, "%s", temp);
		fscanf(f, "%lf %lf %lf\n", &x2, &y2, &z2);
		fscanf(f, "%s", temp);
		fscanf(f, "%lf %lf %lf\n", &x3, &y3, &z3);
		fscanf(f, "%s %s", temp, temp);
		t[i][0] = x1;
		t[i][1] = y1;
		t[i][2] = z1;
		maxx = maxx > t[i][0] ? maxx : t[i][0];
		maxy = maxy > t[i][1] ? maxy : t[i][1];
		maxz = maxz > t[i][2] ? maxz : t[i][2];
		i++;
		t[i][0] = x2;
		t[i][1] = y2;
		t[i][2] = z2;
		maxx = maxx > t[i][0] ? maxx : t[i][0];
		maxy = maxy > t[i][1] ? maxy : t[i][1];
		maxz = maxz > t[i][2] ? maxz : t[i][2];
		i++;
		t[i][0] = x3;
		t[i][1] = y3;
		t[i][2] = z3;
		maxx = maxx > t[i][0] ? maxx : t[i][0];
		maxy = maxy > t[i][1] ? maxy : t[i][1];
		maxz = maxz > t[i][2] ? maxz : t[i][2];
	}
	double r = 0;
	r = r < maxx ? maxx : r;
	r = r < maxy ? maxy : r;
	r = r < maxz ? maxz : r;
	int dx, dy, dz, size = 100;
	printf("input [dx dy dz](0 0 100):");
	scanf("%d %d %d", &dx, &dy, &dz);
	printf("input size scale(max size):");
	scanf("%d", &size);

	printf("input the block name:");
	scanf("%s", temp);
	freopen("d:\\out.txt", "w", stdout);

	memset(redo, 0, sizeof(redo));

	//scale
	for (int j = 0; j < i; j++) {
		for (int k = 0; k < 3; k++) {
			t[j + k][0] = t[j+k][0] / r * size;
			t[j + k][1] = t[j+k][1] / r * size;
			t[j + k][2] = t[j+k][2] / r * size;
			//printf("setblock  %.0lf %.0lf %.0lf %s\n", t[j][0], t[j][1], t[j][2],temp);
		}
		point_int a, b, c;
		a.x = t[j][0];
		a.y = t[j][1];
		a.z = t[j][2];

		b.x = t[j+1][0];
		b.y = t[j+1][1];
		b.z = t[j+1][2];

		c.x = t[j+2][0];
		c.y = t[j+2][1];
		c.z = t[j+2][2];

		fill(a, b, c);

	}

	//for (int j = 0; j < i; j++)
	//	redo[(int)t[j][0] + 100][(int)t[j][1] + 100][(int)t[j][2] + 100] = 1;
	for (int a = 0; a < 200; a++)
		for (int b = 0; b< 200; b++)
			for (int c = 0; c < 200; c++)
				if (redo[a][b][c])
					printf("setblock %d %d %d %s\n", a - 100 + dx, c - 100 + dz, b - 100 + dy, temp);
	return 0;
}


转载于:https://my.oschina.net/u/2357464/blog/504581

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值