|
|
|
|
@@ -1,6 +1,4 @@
|
|
|
|
|
/* exotic.c
|
|
|
|
|
*
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
@@ -32,6 +30,45 @@
|
|
|
|
|
* Copyright (C) 2004 by Etheract Software Labs
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* eigen videoscape formaat:
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* lamp:
|
|
|
|
|
* 3DG2
|
|
|
|
|
aantal_lampen
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
spsi spbl
|
|
|
|
|
r, g, b, energy
|
|
|
|
|
locx, locy, locz
|
|
|
|
|
vecx, vecy, vecz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
curve / nurbs:
|
|
|
|
|
3DG3
|
|
|
|
|
5 of 11 (curve of surf)
|
|
|
|
|
aantal_nurbs
|
|
|
|
|
extr1 extr2
|
|
|
|
|
|
|
|
|
|
mat[0][0] mat[0][1] mat[0][2] mat[0][3]
|
|
|
|
|
mat[1][0] mat[1][1] mat[1][2] mat[1][3]
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
pntsu, pntsv
|
|
|
|
|
resolu, resolv
|
|
|
|
|
orderu, orderv
|
|
|
|
|
flagu, flagv
|
|
|
|
|
|
|
|
|
|
(als type==nurb) x y z w
|
|
|
|
|
x y z w
|
|
|
|
|
...
|
|
|
|
|
(als type==bez) xyz xyz xyz h1 h2 h3
|
|
|
|
|
xyz xyz xyz h1 h2 h3
|
|
|
|
|
...
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -445,6 +482,569 @@ static void read_stl_mesh_ascii(char *str)
|
|
|
|
|
#undef STLREADLINE
|
|
|
|
|
#undef STLREADVERT
|
|
|
|
|
|
|
|
|
|
static void read_videoscape_mesh(char *str)
|
|
|
|
|
{
|
|
|
|
|
Object *ob;
|
|
|
|
|
Mesh *me;
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
MFace *mface;
|
|
|
|
|
Material *ma;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
float *vertdata, *vd, min[3], max[3], cent[3], ftemp;
|
|
|
|
|
unsigned int color[32], col;
|
|
|
|
|
int totcol, a, b, verts, tottria=0, totquad=0, totedge=0, poly, nr0, nr, first;
|
|
|
|
|
int end;
|
|
|
|
|
char s[50];
|
|
|
|
|
|
|
|
|
|
fp= fopen(str, "rb");
|
|
|
|
|
if(fp==NULL) {
|
|
|
|
|
error("Can't read file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d\n", &verts);
|
|
|
|
|
if(verts<=0) {
|
|
|
|
|
fclose(fp);
|
|
|
|
|
error("Read error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(verts>MESH_MAX_VERTS) {
|
|
|
|
|
error("too many vertices");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
vd= vertdata= MEM_mallocN(sizeof(float)*3*verts, "videoscapelezer");
|
|
|
|
|
|
|
|
|
|
for(a=0; a<verts; a++) {
|
|
|
|
|
fscanf(fp, "%f %f %f", vd, vd+1, vd+2);
|
|
|
|
|
DO_MINMAX(vd, min, max);
|
|
|
|
|
vd+=3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* count faces and colors */
|
|
|
|
|
for(a=0; a<32; a++) color[a]= 0;
|
|
|
|
|
totcol= 0;
|
|
|
|
|
end= 1;
|
|
|
|
|
while(end>0) {
|
|
|
|
|
end= fscanf(fp,"%d", &poly);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
if(poly==3) tottria++;
|
|
|
|
|
else if(poly==4) totquad++;
|
|
|
|
|
else totedge+= poly;
|
|
|
|
|
|
|
|
|
|
for(a=0;a<poly;a++) {
|
|
|
|
|
end= fscanf(fp,"%d", &nr);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
}
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
end= fscanf(fp,"%i\n", &col);
|
|
|
|
|
col &= 0xF0F0F0;
|
|
|
|
|
for(a=0; a<totcol; a++) {
|
|
|
|
|
if(color[a]==col) break;
|
|
|
|
|
}
|
|
|
|
|
if(a>=totcol && totcol<32) {
|
|
|
|
|
color[totcol]= col;
|
|
|
|
|
totcol++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* new object */
|
|
|
|
|
ob= add_object(OB_MESH);
|
|
|
|
|
me= ob->data;
|
|
|
|
|
me->totvert= verts;
|
|
|
|
|
me->totface= totedge+tottria+totquad;
|
|
|
|
|
|
|
|
|
|
me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC,
|
|
|
|
|
NULL, me->totvert);
|
|
|
|
|
me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC,
|
|
|
|
|
NULL, me->totface);
|
|
|
|
|
|
|
|
|
|
/* colors */
|
|
|
|
|
if(totcol) {
|
|
|
|
|
ob->mat= MEM_callocN(sizeof(void *)*totcol, "ob->mat");
|
|
|
|
|
me->mat= MEM_callocN(sizeof(void *)*totcol, "me->mat");
|
|
|
|
|
me->totcol= totcol;
|
|
|
|
|
ob->totcol= (unsigned char) me->totcol;
|
|
|
|
|
ob->actcol= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* materials */
|
|
|
|
|
for(a=0; a<totcol; a++) {
|
|
|
|
|
ma= G.main->mat.first;
|
|
|
|
|
while(ma) {
|
|
|
|
|
if(ma->mtex[0]==0) {
|
|
|
|
|
col= rgb_to_cpack(ma->r, ma->g, ma->b);
|
|
|
|
|
if(color[a]==col) {
|
|
|
|
|
me->mat[a]= ma;
|
|
|
|
|
ma->id.us++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ma= ma->id.next;
|
|
|
|
|
}
|
|
|
|
|
if(ma==0) {
|
|
|
|
|
ma= add_material("ext");
|
|
|
|
|
me->mat[a]= ma;
|
|
|
|
|
cpack_to_rgb(color[a], cent, cent+1, cent+2);
|
|
|
|
|
ma->r= cent[0];
|
|
|
|
|
ma->g= cent[1];
|
|
|
|
|
ma->b= cent[2];
|
|
|
|
|
automatname(ma);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* verts */
|
|
|
|
|
|
|
|
|
|
cent[0]= (min[0]+max[0])/2.0f;
|
|
|
|
|
cent[1]= (min[1]+max[1])/2.0f;
|
|
|
|
|
cent[2]= (min[2]+max[2])/2.0f;
|
|
|
|
|
VECCOPY(ob->loc, cent);
|
|
|
|
|
|
|
|
|
|
a= me->totvert;
|
|
|
|
|
vd= vertdata;
|
|
|
|
|
mvert= me->mvert;
|
|
|
|
|
while(a--) {
|
|
|
|
|
VecSubf(mvert->co, vd, cent);
|
|
|
|
|
mvert++;
|
|
|
|
|
vd+= 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* faces */
|
|
|
|
|
if(me->totface) {
|
|
|
|
|
rewind(fp);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
fscanf(fp, "%d\n", &verts);
|
|
|
|
|
/* fake read */
|
|
|
|
|
for(a=0;a<verts;a++) {
|
|
|
|
|
fscanf(fp, "%f %f %f", &ftemp, &ftemp, &ftemp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a= me->totface;
|
|
|
|
|
mface= me->mface;
|
|
|
|
|
while(a--) {
|
|
|
|
|
end= fscanf(fp,"%d", &poly);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
if(poly==3 || poly==4) {
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v1= MIN2(nr, me->totvert-1);
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v2= MIN2(nr, me->totvert-1);
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v3= MIN2(nr, me->totvert-1);
|
|
|
|
|
if(poly==4) {
|
|
|
|
|
if( fscanf(fp,"%d", &nr) <=0 ) break;
|
|
|
|
|
mface->v4= MIN2(nr, me->totvert-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_index_face(mface, NULL, 0, poly);
|
|
|
|
|
|
|
|
|
|
mface++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if( fscanf(fp,"%d", &nr0) <=0) break;
|
|
|
|
|
first= nr0;
|
|
|
|
|
for(b=1; b<poly; b++) {
|
|
|
|
|
end= fscanf(fp,"%d", &nr);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
nr= MIN2(nr, me->totvert-1);
|
|
|
|
|
mface->v1= nr;
|
|
|
|
|
mface->v2= nr0;
|
|
|
|
|
nr0= nr;
|
|
|
|
|
mface++;
|
|
|
|
|
a--;
|
|
|
|
|
}
|
|
|
|
|
mface->v1= first;
|
|
|
|
|
mface->v2= nr;
|
|
|
|
|
mface++;
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
}
|
|
|
|
|
end= fscanf(fp,"%i", &col);
|
|
|
|
|
col &= 0xF0F0F0;
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
for(b=0; b<totcol; b++) {
|
|
|
|
|
if(color[b]==col) {
|
|
|
|
|
(mface-1)->mat_nr= b;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
MEM_freeN(vertdata);
|
|
|
|
|
|
|
|
|
|
mesh_add_normals_flags(me);
|
|
|
|
|
make_edges(me, 0);
|
|
|
|
|
|
|
|
|
|
waitcursor(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void read_radiogour(char *str)
|
|
|
|
|
{
|
|
|
|
|
Object *ob;
|
|
|
|
|
Mesh *me;
|
|
|
|
|
MVert *mvert;
|
|
|
|
|
MFace *mface;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
float *vertdata, *vd, min[3], max[3], cent[3], ftemp;
|
|
|
|
|
unsigned int *colv, *colf, *colvertdata;
|
|
|
|
|
int itemp, a, b, verts, tottria=0, totquad=0, totedge=0, poly, nr0, nr, first;
|
|
|
|
|
int end;
|
|
|
|
|
char s[50];
|
|
|
|
|
|
|
|
|
|
fp= fopen(str, "rb");
|
|
|
|
|
if(fp==NULL) {
|
|
|
|
|
error("Can't read file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d\n", &verts);
|
|
|
|
|
if(verts<=0) {
|
|
|
|
|
fclose(fp);
|
|
|
|
|
error("Read error");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(verts>MESH_MAX_VERTS) {
|
|
|
|
|
error("too many vertices");
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
vd= vertdata= MEM_mallocN(sizeof(float)*3*verts, "videoscapelezer");
|
|
|
|
|
colv= colvertdata= MEM_mallocN(verts*sizeof(float), "coldata");
|
|
|
|
|
|
|
|
|
|
for(a=0; a<verts; a++) {
|
|
|
|
|
fscanf(fp, "%f %f %f %i", vd, vd+1, vd+2, colv);
|
|
|
|
|
DO_MINMAX(vd, min, max);
|
|
|
|
|
vd+=3;
|
|
|
|
|
colv++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* count faces */
|
|
|
|
|
end= 1;
|
|
|
|
|
while(end>0) {
|
|
|
|
|
end= fscanf(fp,"%d", &poly);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
if(poly==3) tottria++;
|
|
|
|
|
else if(poly==4) totquad++;
|
|
|
|
|
else totedge+= poly;
|
|
|
|
|
|
|
|
|
|
for(a=0;a<poly;a++) {
|
|
|
|
|
end= fscanf(fp,"%d", &nr);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
}
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(totedge+tottria+totquad>MESH_MAX_VERTS) {
|
|
|
|
|
printf(" var1: %d, var2: %d, var3: %d \n", totedge, tottria, totquad);
|
|
|
|
|
error("too many faces");
|
|
|
|
|
MEM_freeN(vertdata);
|
|
|
|
|
MEM_freeN(colvertdata);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* new object */
|
|
|
|
|
ob= add_object(OB_MESH);
|
|
|
|
|
me= ob->data;
|
|
|
|
|
me->totvert= verts;
|
|
|
|
|
me->totface= totedge+tottria+totquad;
|
|
|
|
|
me->flag= 0;
|
|
|
|
|
|
|
|
|
|
me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC,
|
|
|
|
|
NULL, me->totvert);
|
|
|
|
|
me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC,
|
|
|
|
|
NULL, me->totface);
|
|
|
|
|
|
|
|
|
|
/* verts */
|
|
|
|
|
|
|
|
|
|
cent[0]= (min[0]+max[0])/2.0f;
|
|
|
|
|
cent[1]= (min[1]+max[1])/2.0f;
|
|
|
|
|
cent[2]= (min[2]+max[2])/2.0f;
|
|
|
|
|
VECCOPY(ob->loc, cent);
|
|
|
|
|
|
|
|
|
|
a= me->totvert;
|
|
|
|
|
vd= vertdata;
|
|
|
|
|
mvert= me->mvert;
|
|
|
|
|
while(a--) {
|
|
|
|
|
VecSubf(mvert->co, vd, cent);
|
|
|
|
|
mvert++;
|
|
|
|
|
vd+= 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* faces */
|
|
|
|
|
if(me->totface) {
|
|
|
|
|
rewind(fp);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
fscanf(fp, "%d\n", &verts);
|
|
|
|
|
for(a=0;a<verts;a++) {
|
|
|
|
|
fscanf(fp, "%f %f %f %i", &ftemp, &ftemp, &ftemp, &itemp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a= me->totface;
|
|
|
|
|
mface= me->mface;
|
|
|
|
|
while(a--) {
|
|
|
|
|
end= fscanf(fp,"%d", &poly);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
|
|
|
|
|
if(poly==3 || poly==4) {
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v1= MIN2(nr, me->totvert-1);
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v2= MIN2(nr, me->totvert-1);
|
|
|
|
|
fscanf(fp,"%d", &nr);
|
|
|
|
|
mface->v3= MIN2(nr, me->totvert-1);
|
|
|
|
|
if(poly==4) {
|
|
|
|
|
if( fscanf(fp,"%d", &nr) <=0 ) break;
|
|
|
|
|
mface->v4= MIN2(nr, me->totvert-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_index_face(mface, NULL, 0, poly);
|
|
|
|
|
|
|
|
|
|
mface++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if( fscanf(fp,"%d", &nr0) <=0) break;
|
|
|
|
|
first= nr0;
|
|
|
|
|
for(b=1; b<poly; b++) {
|
|
|
|
|
end= fscanf(fp,"%d", &nr);
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
nr= MIN2(nr, me->totvert-1);
|
|
|
|
|
mface->v1= nr;
|
|
|
|
|
mface->v2= nr0;
|
|
|
|
|
nr0= nr;
|
|
|
|
|
mface++;
|
|
|
|
|
a--;
|
|
|
|
|
}
|
|
|
|
|
mface->v1= first;
|
|
|
|
|
mface->v2= nr;
|
|
|
|
|
mface->flag= ME_SMOOTH;
|
|
|
|
|
|
|
|
|
|
mface++;
|
|
|
|
|
if(end<=0) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* mcol is 4 colors per face */
|
|
|
|
|
me->mcol= MEM_mallocN(4*sizeof(int)*me->totface, "mcol");
|
|
|
|
|
colf= (unsigned int *)me->mcol;
|
|
|
|
|
|
|
|
|
|
a= me->totface;
|
|
|
|
|
mface= me->mface;
|
|
|
|
|
while(a--) {
|
|
|
|
|
|
|
|
|
|
colf[0]= colvertdata[mface->v1];
|
|
|
|
|
colf[1]= colvertdata[mface->v2];
|
|
|
|
|
colf[2]= colvertdata[mface->v3];
|
|
|
|
|
colf[3]= colvertdata[mface->v4];
|
|
|
|
|
|
|
|
|
|
colf+= 4;
|
|
|
|
|
mface++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(colvertdata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
MEM_freeN(vertdata);
|
|
|
|
|
|
|
|
|
|
mesh_add_normals_flags(me);
|
|
|
|
|
make_edges(me, 0);
|
|
|
|
|
|
|
|
|
|
waitcursor(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void read_videoscape_lamp(char *str)
|
|
|
|
|
{
|
|
|
|
|
Object *ob;
|
|
|
|
|
Lamp *la;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
float vec[3], *q1;
|
|
|
|
|
int tot, val;
|
|
|
|
|
char s[50];
|
|
|
|
|
|
|
|
|
|
fp= fopen(str, "rb");
|
|
|
|
|
if(fp==NULL) {
|
|
|
|
|
error("Can't read file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
fscanf(fp, "%d\n", &tot);
|
|
|
|
|
|
|
|
|
|
while(tot--) {
|
|
|
|
|
ob= add_object(OB_LAMP);
|
|
|
|
|
la= ob->data;
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d\n", &val);
|
|
|
|
|
la->type= val;
|
|
|
|
|
if(la->type==1) la->type= LA_SPOT;
|
|
|
|
|
else if(la->type==2) la->type= LA_SUN;
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%f %f\n", &la->spotsize, &la->spotblend);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%f %f %f %f\n", &la->r, &la->g, &la->b, &la->energy);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%f %f %f\n", ob->loc, ob->loc+1, ob->loc+2);
|
|
|
|
|
val= fscanf(fp, "%f %f %f\n", vec, vec+1, vec+2);
|
|
|
|
|
q1= vectoquat(vec, 5, 2);
|
|
|
|
|
QuatToEul(q1, ob->rot);
|
|
|
|
|
|
|
|
|
|
if(val<=0) break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void read_videoscape_nurbs(char *str)
|
|
|
|
|
{
|
|
|
|
|
Object *ob;
|
|
|
|
|
Curve *cu;
|
|
|
|
|
Nurb *nu;
|
|
|
|
|
BezTriple *bezt;
|
|
|
|
|
BPoint *bp;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
float tmat[4][4], omat[3][3], imat[3][3], mat[3][3];
|
|
|
|
|
int a, tot, type, val;
|
|
|
|
|
char s[50];
|
|
|
|
|
|
|
|
|
|
fp= fopen(str, "rb");
|
|
|
|
|
if(fp==NULL) {
|
|
|
|
|
error("Can't read file");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%40s", s);
|
|
|
|
|
fscanf(fp, "%d\n", &type);
|
|
|
|
|
|
|
|
|
|
if(type==5) ob= add_object(OB_SURF);
|
|
|
|
|
else ob= add_object(OB_CURVE);
|
|
|
|
|
cu= ob->data;
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d\n", &tot);
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
|
|
|
|
|
cu->ext1= 0.002f*type;
|
|
|
|
|
cu->ext2= 0.002f*val;
|
|
|
|
|
|
|
|
|
|
for(a=0; a<4; a++) fscanf(fp, "%e %e %e %e\n", tmat[a], tmat[a]+1, tmat[a]+2, tmat[a]+3);
|
|
|
|
|
|
|
|
|
|
VECCOPY(ob->loc, tmat[3]);
|
|
|
|
|
|
|
|
|
|
Mat3CpyMat4(omat, tmat);
|
|
|
|
|
Mat3ToEul(omat, ob->rot);
|
|
|
|
|
EulToMat3(ob->rot, mat);
|
|
|
|
|
Mat3Inv(imat, mat);
|
|
|
|
|
Mat3MulMat3((float ( * )[3])tmat, imat, omat);
|
|
|
|
|
|
|
|
|
|
while(tot--) {
|
|
|
|
|
nu= (Nurb*)MEM_callocN(sizeof(Nurb),"nu from exotic");
|
|
|
|
|
BLI_addtail(&cu->nurb, nu);
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d\n", &type);
|
|
|
|
|
nu->type= type;
|
|
|
|
|
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
nu->pntsu= type; nu->pntsv= val;
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
nu->resolu= type; nu->resolv= val;
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
nu->orderu= type; nu->orderv= val;
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
nu->flagu= type; nu->flagv= val;
|
|
|
|
|
|
|
|
|
|
if( (nu->type & 7)==CU_BEZIER) {
|
|
|
|
|
a= nu->pntsu;
|
|
|
|
|
nu->bezt= bezt= MEM_callocN(a*sizeof(BezTriple), "bezt from exotic");
|
|
|
|
|
while(a--) {
|
|
|
|
|
fscanf(fp, "%f %f %f ", bezt->vec[0], bezt->vec[0]+1, bezt->vec[0]+2);
|
|
|
|
|
Mat4MulVecfl(tmat, bezt->vec[0]);
|
|
|
|
|
fscanf(fp, "%f %f %f ", bezt->vec[1], bezt->vec[1]+1, bezt->vec[1]+2);
|
|
|
|
|
Mat4MulVecfl(tmat, bezt->vec[1]);
|
|
|
|
|
fscanf(fp, "%f %f %f ", bezt->vec[2], bezt->vec[2]+1, bezt->vec[2]+2);
|
|
|
|
|
Mat4MulVecfl(tmat, bezt->vec[2]);
|
|
|
|
|
fscanf(fp, "%d %d\n", &type, &val);
|
|
|
|
|
bezt->h1= type;
|
|
|
|
|
bezt->h2= val;
|
|
|
|
|
bezt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
a= nu->pntsu*nu->pntsv;
|
|
|
|
|
if(a) {
|
|
|
|
|
nu->bp= bp= MEM_callocN(a*sizeof(BPoint), "bp from exotic");
|
|
|
|
|
while(a--) {
|
|
|
|
|
fscanf(fp, "%f %f %f %f\n", bp->vec, bp->vec+1, bp->vec+2, bp->vec+3);
|
|
|
|
|
Mat4MulVecfl(tmat, bp->vec);
|
|
|
|
|
bp++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val= KNOTSU(nu);
|
|
|
|
|
nu->knotsu= MEM_mallocN(sizeof(float)*val, "knots");
|
|
|
|
|
for(a=0; a<val; a++) fscanf(fp, "%f\n", nu->knotsu+a);
|
|
|
|
|
|
|
|
|
|
if(nu->pntsv>1) {
|
|
|
|
|
val= KNOTSV(nu);
|
|
|
|
|
nu->knotsv= MEM_mallocN(sizeof(float)*val, "knots");
|
|
|
|
|
for(a=0; a<val; a++) fscanf(fp, "%f\n", nu->knotsv+a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_remlink(&cu->nurb, nu);
|
|
|
|
|
MEM_freeN(nu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void read_videoscape(char *str)
|
|
|
|
|
{
|
|
|
|
|
int file, type;
|
|
|
|
|
unsigned int val;
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char name[FILE_MAXDIR+FILE_MAXFILE], head[FILE_MAXDIR+FILE_MAXFILE], tail[FILE_MAXFILE];
|
|
|
|
|
|
|
|
|
|
strcpy(name, str);
|
|
|
|
|
|
|
|
|
|
while( TRUE ) {
|
|
|
|
|
file= open(name, O_BINARY|O_RDONLY);
|
|
|
|
|
if(file<=0) break;
|
|
|
|
|
else {
|
|
|
|
|
read(file, &type, 4);
|
|
|
|
|
close(file);
|
|
|
|
|
|
|
|
|
|
if(type==DDG1) read_videoscape_mesh(name);
|
|
|
|
|
else if(type==DDG2) read_videoscape_lamp(name);
|
|
|
|
|
else if(type==DDG3) read_videoscape_nurbs(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val = BLI_stringdec(name, head, tail, &numlen);
|
|
|
|
|
BLI_stringenc(name, head, tail, numlen, val + 1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ***************** INVENTOR ******************* */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1782,7 +2382,23 @@ int BKE_read_exotic(char *name)
|
|
|
|
|
|
|
|
|
|
waitcursor(1);
|
|
|
|
|
|
|
|
|
|
if(strncmp(str, "#Inventor V1.0", 14)==0) {
|
|
|
|
|
if(*s0==GOUR) {
|
|
|
|
|
if(G.obedit) {
|
|
|
|
|
error("Unable to perform function in EditMode");
|
|
|
|
|
} else {
|
|
|
|
|
read_radiogour(name);
|
|
|
|
|
retval = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ELEM4(*s0, DDG1, DDG2, DDG3, DDG4) {
|
|
|
|
|
if(G.obedit) {
|
|
|
|
|
error("Unable to perform function in EditMode");
|
|
|
|
|
} else {
|
|
|
|
|
read_videoscape(name);
|
|
|
|
|
retval = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(strncmp(str, "#Inventor V1.0", 14)==0) {
|
|
|
|
|
if( strncmp(str+15, "ascii", 5)==0) {
|
|
|
|
|
read_inventor(name, &lbase);
|
|
|
|
|
displist_to_objects(&lbase);
|
|
|
|
|
@@ -1952,6 +2568,163 @@ void write_stl(char *str)
|
|
|
|
|
waitcursor(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void write_videoscape_mesh(Object *ob, char *str)
|
|
|
|
|
{
|
|
|
|
|
EditMesh *em = G.editMesh;
|
|
|
|
|
Mesh *me;
|
|
|
|
|
Material *ma;
|
|
|
|
|
MFace *mface;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
EditVert *eve;
|
|
|
|
|
EditFace *evl;
|
|
|
|
|
unsigned int kleur[32];
|
|
|
|
|
float co[3];
|
|
|
|
|
int a;
|
|
|
|
|
long tot;
|
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
|
|
if(ob && ob->type==OB_MESH);
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kleur[0]= 0x00C0C0C0;
|
|
|
|
|
|
|
|
|
|
cp= (char *)kleur;
|
|
|
|
|
for(a=0; a<ob->totcol; a++, cp+=4) {
|
|
|
|
|
|
|
|
|
|
ma= give_current_material(ob, a+1);
|
|
|
|
|
if(ma) {
|
|
|
|
|
cp[0]= (unsigned char) (255.0*ma->emit);
|
|
|
|
|
cp[1]= (unsigned char) (255.0*ma->b);
|
|
|
|
|
cp[2]= (unsigned char) (255.0*ma->g);
|
|
|
|
|
cp[3]= (unsigned char) (255.0*ma->r);
|
|
|
|
|
if(G.order==L_ENDIAN) SWITCH_INT(kleur[a]);
|
|
|
|
|
}
|
|
|
|
|
else kleur[a]= 0x00C0C0C0;
|
|
|
|
|
|
|
|
|
|
if(a>30) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fp= fopen(str, "wb");
|
|
|
|
|
if(fp==NULL) return;
|
|
|
|
|
|
|
|
|
|
fprintf(fp,"3DG1\n");
|
|
|
|
|
|
|
|
|
|
if(G.obedit) {
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "%d\n", G.totvert);
|
|
|
|
|
|
|
|
|
|
tot= 0;
|
|
|
|
|
eve= em->verts.first;
|
|
|
|
|
while(eve) {
|
|
|
|
|
VECCOPY(co, eve->co);
|
|
|
|
|
Mat4MulVecfl(ob->obmat, co);
|
|
|
|
|
fprintf(fp, "%f %f %f\n", co[0], co[1], co[2] );
|
|
|
|
|
eve->tmp.l = tot;
|
|
|
|
|
tot++;
|
|
|
|
|
eve= eve->next;
|
|
|
|
|
}
|
|
|
|
|
evl= em->faces.first;
|
|
|
|
|
while(evl) {
|
|
|
|
|
|
|
|
|
|
if(evl->v4==0) {
|
|
|
|
|
fprintf(fp, "3 %ld %ld %ld 0x%x\n",
|
|
|
|
|
evl->v1->tmp.l,
|
|
|
|
|
evl->v2->tmp.l,
|
|
|
|
|
evl->v3->tmp.l,
|
|
|
|
|
kleur[evl->mat_nr]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(fp, "4 %ld %ld %ld %ld 0x%x\n",
|
|
|
|
|
evl->v1->tmp.l,
|
|
|
|
|
evl->v2->tmp.l,
|
|
|
|
|
evl->v3->tmp.l,
|
|
|
|
|
evl->v4->tmp.l,
|
|
|
|
|
kleur[evl->mat_nr]);
|
|
|
|
|
}
|
|
|
|
|
evl= evl->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DerivedMesh *dm = mesh_get_derived_deform(ob, CD_MASK_BAREMESH);
|
|
|
|
|
|
|
|
|
|
me= ob->data;
|
|
|
|
|
|
|
|
|
|
fprintf(fp, "%d\n", me->totvert);
|
|
|
|
|
|
|
|
|
|
mface= me->mface;
|
|
|
|
|
for(a=0; a<me->totvert; a++) {
|
|
|
|
|
dm->getVertCo(dm, a, co);
|
|
|
|
|
Mat4MulVecfl(ob->obmat, co);
|
|
|
|
|
fprintf(fp, "%f %f %f\n", co[0], co[1], co[2] );
|
|
|
|
|
}
|
|
|
|
|
for(a=0; a<me->totface; a++, mface++) {
|
|
|
|
|
if(mface->v4==0) {
|
|
|
|
|
fprintf(fp, "3 %d %d %d 0x%x\n", mface->v1, mface->v2, mface->v3, kleur[mface->mat_nr]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(fp, "4 %d %d %d %d 0x%x\n", mface->v1, mface->v2, mface->v3, mface->v4, kleur[mface->mat_nr]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dm->release(dm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void write_videoscape(char *str)
|
|
|
|
|
{
|
|
|
|
|
Base *base;
|
|
|
|
|
int file, val, lampdone=0;
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char head[FILE_MAXFILE], tail[FILE_MAXFILE];
|
|
|
|
|
|
|
|
|
|
if(BLI_testextensie(str,".trace")) str[ strlen(str)-6]= 0;
|
|
|
|
|
if(BLI_testextensie(str,".blend")) str[ strlen(str)-6]= 0;
|
|
|
|
|
if(BLI_testextensie(str,".ble")) str[ strlen(str)-4]= 0;
|
|
|
|
|
if(BLI_testextensie(str,".obj")==0) strcat(str, ".obj");
|
|
|
|
|
|
|
|
|
|
file= open(str,O_BINARY|O_RDONLY);
|
|
|
|
|
close(file);
|
|
|
|
|
if(file>-1) if(!during_script() && saveover(str)==0) return;
|
|
|
|
|
|
|
|
|
|
strcpy(temp_dir, str);
|
|
|
|
|
|
|
|
|
|
base= G.scene->base.first;
|
|
|
|
|
while(base) {
|
|
|
|
|
if((base->flag & SELECT) && (base->lay & G.scene->lay)) {
|
|
|
|
|
if(base->object->type==OB_MESH) {
|
|
|
|
|
write_videoscape_mesh(base->object, str);
|
|
|
|
|
val = BLI_stringdec(str, head, tail, &numlen);
|
|
|
|
|
BLI_stringenc(str, head, tail, numlen, val + 1);
|
|
|
|
|
}
|
|
|
|
|
else if(base->object->type==OB_CURVE || base->object->type==OB_SURF) {
|
|
|
|
|
/* write_videoscape_nurbs(base->object, str); */
|
|
|
|
|
/* val = stringdec(str, head, tail, &numlen); */
|
|
|
|
|
/* stringenc(str, head, tail, numlen, val + 1); */
|
|
|
|
|
}
|
|
|
|
|
else if(lampdone==0 && base->object->type==OB_LAMP) {
|
|
|
|
|
/* lampdone= 1; */
|
|
|
|
|
/* write_videoscape_lamps(str); */
|
|
|
|
|
/* val = stringdec(str, head, tail, &numlen); */
|
|
|
|
|
/* stringenc(str, head, tail, numlen, val + 1); */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
base= base->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* remove when higher numbers exist */
|
|
|
|
|
while(remove(str)==0) {
|
|
|
|
|
|
|
|
|
|
val = BLI_stringdec(str, head, tail, &numlen);
|
|
|
|
|
BLI_stringenc(str, head, tail, numlen, val + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******************************* WRITE VRML ***************************** */
|
|
|
|
|
|
|
|
|
|
|