📄 3dsimport_co.cxx
字号:
if(!argc) {
ivp_message(
"3D Studio native objectfile converter v2.0\n"
"by Mats Byggmastar 1996 Espoo, Finland\n"
"Use: 3DSCO [params...] inputfile.3DS [outputfile]\n"
"params:\n"
" -o name Object name (default "DEFNAME")\n"
" -v Verbose mode on\n"
" -a Assembly source output\n"
" -b Binary output (you must specify outputfile)\n"
" -c Centre objects\n"
" -s x y z Scale objects (x,y,z = floats)\n"
" -y Don't ask for file overwrite\n"
" -f Don't fix bad mapping coordinates\n"
" -m Don't output mapping coordinates\n"
" -n Don't remove null faces\n"
" -u Don't remove unused vertices\n"
" -d Don't remove duplicated vertices\n"
);
return 1;
}
// Get the parameters and filenames
for(n=0; n<argc; n++) {
if(argv[n][0] == '-' || argv[n][0] == '/') {
switch(toupper(argv[n][1])) {
case 'O': if(n+1<argc) { name=argv[++n]; break; }
else { ivp_message( "Missing object name!\n");
return 1; }
case 'S': if(n+3<argc) { flags |= SCALE;
xscale = atof(argv[++n]);
yscale = atof(argv[++n]);
zscale = atof(argv[++n]);
break; }
else { ivp_message( "Missing scale value!\n");
return 1; }
case 'V': flags |= VERBOSE; break;
case 'A': flags |= ASSEMBLY; break;
case 'B': flags |= BINARY; break;
case 'C': flags |= CENTRE; break;
case 'Y': flags |= OVERWR; break;
case 'F': flags |= NOMAPFIX; break;
case 'M': flags |= NOMAPPING; break;
case 'N': flags |= NORMNULL; break;
case 'U': flags |= NORMUNUSED; break;
case 'D': flags |= NORMDUP; break;
default: ivp_message( "Bad param: %s\n",argv[n]);
return 1;
}
} else {
if(!infn)
infn = argv[n];
else if(!outfn)
outfn = argv[n];
else {
ivp_message( "Too many filenames!\n");
return 1;
}
}
}
#else
infn = (char *)filename;
outf = NULL;
#endif
if(!infn) {
ivp_message( "No inputfile specified!\n");
return NULL;
}
// Open inputfile
if(!(inf = fopen(infn, "rb"))) {
ivp_message( "Failed to open %s\n", infn);
return NULL;
}
if(!outfn && (flags & BINARY) != 0) {
ivp_message( "Missing output filename!\n");
fclose(inf);
return NULL;
}
// Open, create or redirect outputfile
if(outfn) {
if((outf = fopen(outfn, "r+b")) != 0) {
if((flags & OVERWR) == 0) {
ivp_message( "%s exist, overwrite [y/n] ", outfn);
if(toupper(getc(stdin)) != 'Y') {
fclose(outf);
fclose(inf);
return 0;
}
ivp_message( "\n");
fclose(outf);
if((outf = fopen(outfn, "w+b")) == 0) {
ivp_message( "Unable to reopen %s\n", outfn);
fclose(inf);
return NULL;
}
}
} else {
if((outf = fopen(outfn, "w+b")) == 0) {
ivp_message( "Unable to create %s\n", outfn);
fclose(inf);
return NULL;
}
}
} else {
// Use stdout if not binary output and no outputfile was specified.
outf = stdout;
}
// Here we have both the source and destination files opened as:
// FILE * inf -> source file
// FILE * outf -> destination file (could be stdout)
long size;
if(fseek(inf, 0, SEEK_END)) {
ivp_message( "Error seeking %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return NULL;
}
if((size=ftell(inf)) == -1L) {
ivp_message( "Error seeking %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return NULL;
}
rewind(inf);
if((scene = HRead3dsScene(inf, 0, size)) == 0) {
ivp_message( "Failed to load %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return NULL;
}
fclose(inf);
// At this point we have all object's data loaded into memory.
// H3dsScene * scene -> object data
#if 0
if(flags & VERBOSE) {
// Print some interesting information about what we have
ivp_message( "3DS data size: %ld byte\n", size);
ivp_message( "object-name faces vertices maps matrix\n");
int f=0, v=0, m=0;
for(n=0; n<scene->meshobjs; n++) {
H3dsMeshObj * mo = &scene->meshobjlist[n];
char * mtrx="yes";
if(mo->matrix==0)
mtrx="no";
ivp_message( "%-14s %5d %5d %5d %s\n",
mo->name, mo->faces, mo->verts, mo->maps, mtrx);
f+=mo->faces;
v+=mo->verts;
m+=mo->maps;
}
if(scene->meshobjs>1)
ivp_message( "%d faces, %d vertices, %d maps in "
"%d objects loaded\n",
f, v, m, scene->meshobjs);
}
// Do any rotating, moving, scaling here before
// we convert all floats to integers.
if(!(flags & NOMAPFIX))
FixMaps(scene);
ScaleMaps(scene, 65535.0, 65535.0);
FindCentrePoints(scene);
if(flags & CENTRE)
Move(scene, -scene->centre.x, -scene->centre.y, -scene->centre.z);
if(flags & SCALE)
Scale(scene, xscale, yscale, zscale);
// ConvertFloatsToInts(scene);
// From this point we'll only work with integers.
if(!(flags & NORMNULL)) {
n = RemoveNullFaces(scene);
if(flags & VERBOSE)
ivp_message( "Removed %d null faces\n", n);
}
if(!(flags & NORMUNUSED)) {
n = RemoveUnusedVerts(scene);
if(flags & VERBOSE)
ivp_message( "Removed %d unused vertices\n", n);
}
#endif
if ( params->scale != 1.0f){
Scale(scene, params->scale, params->scale, params->scale);
}
// Prepare to collect all vertices to one big array
int verts=0;
for(n=0; n<scene->meshobjs; n++) {
int v=scene->meshobjlist[n].verts;
if(scene->meshobjlist[n].maps > v) {
ivp_message( "%-14s more maps than vertices, quitting!\n",
scene->meshobjlist[n].name);
if(outf!=stdout) fclose(outf);
return NULL;
}
// Get the total number of vertices in all objects
verts+=v;
}
H3dsMapVert * vrtmap = (H3dsMapVert *) p_malloc(verts*sizeof(H3dsMapVert));
if(!vrtmap) {
ivp_message( "Failed to allocate mem for vertice array\n");
HFree3dsScene(scene);
fclose(outf);
return NULL;
}
memset(vrtmap, 0, verts*sizeof(H3dsMapVert));
// Do it! Collect them
CollectVertsAndMaps(scene, vrtmap);
// Adjust the face indexes to the new vertice array
AdjustFaceIndexes(scene);
if(!(flags & NORMDUP)) {
if(flags & VERBOSE)
ivp_message( "Removing duplicated vertices ");
n = RemoveDupVerts(scene, vrtmap, verts);
if(flags & VERBOSE)
ivp_message( "\nRemoved %d duplicated vertices\n", verts-n);
verts=n;
}
#if 0
// Output data
int f=0;
if(!(flags & NOMAPPING))
f |= 1;
if(flags & BINARY) {
OutpHeadBin(outf, scene, verts, f);
OutpVertsBin(outf, vrtmap, verts, f);
OutpCentresBin(outf, scene);
OutpObjectsBin(outf, scene);
}
else
if(flags & ASSEMBLY) {
OutpHeadAsm(outf, scene, verts, name, f);
OutpVertsAsm(outf, vrtmap, verts, name, f);
OutpCentresAsm(outf, scene, name);
OutpObjectsAsm(outf, scene, name);
}
else {
OutpHead(outf, scene, verts, name, f);
OutpVerts(outf, vrtmap, verts, name, f);
OutpCentres(outf, scene, name);
OutpObjects(outf, scene, name);
}
P_FREE(vrtmap);
HFree3dsScene(scene);
if(outf!=stdout) fclose(outf);
#else
IVP_Concave_Polyhedron *concave_polyhedron = new IVP_Concave_Polyhedron();
#if 1
int x;
for (x=0; x<(int)verts; x++) {
H3dsMapVert *vm = &vrtmap[x];
IVP_U_Point *point = new IVP_U_Point();
point->k[0] = vm->x;
point->k[1] = vm->y;
point->k[2] = vm->z;
concave_polyhedron->points.add(point);
}
for (int o = 0; o < scene->meshobjs; o++){
H3dsMeshObj * mo = &scene->meshobjlist[o];
for (x=0; x<(int)mo->faces; ) {
H3dsFace * fa = &mo->facelist[x++];
IVP_Concave_Polyhedron_Face *face = new IVP_Concave_Polyhedron_Face();
face->add_offset(fa->p0);
face->add_offset(fa->p1);
face->add_offset(fa->p2);
concave_polyhedron->faces.add(face);
}
}
#endif
repair_geometry(concave_polyhedron);
#endif
return concave_polyhedron;
//****
#else // GEKKO
//****
return 0;
//****
#endif // GEKKO
//****
}
#include <ivp_surbuild_pointsoup.hxx>
class P_Hardware;
int p_graphlib_robust_convert_3dmax_object_to_compact_ledges(P_Hardware *hw, const char *filename, IVP_U_BigVector<IVP_Compact_Ledge> *ledges) {
#ifdef WIN32
// P_Hardware_W95 *w95_hw = (P_Hardware_W95 *)hw;
flags |= NORMDUP;
char * infn=0, * name=DEFNAME;
FILE * inf, * outf;
int n;
H3dsScene * scene;
// float32 xscale, yscale, zscale;
infn = (char *)filename;
outf = NULL;
if(!infn) {
ivp_message( "No inputfile specified!\n");
return 1;
}
// Open inputfile
if(!(inf = fopen(infn, "rb"))) {
ivp_message( "Failed to open %s\n", infn);
return 1;
}
// Here we have both the source and destination files opened as:
// FILE * inf -> source file
// FILE * outf -> destination file (could be stdout)
long size;
if(fseek(inf, 0, SEEK_END)) {
ivp_message( "Error seeking %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return 1;
}
if((size=ftell(inf)) == -1L) {
ivp_message( "Error seeking %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return 1;
}
rewind(inf);
if((scene = HRead3dsScene(inf, 0, size)) == 0) {
ivp_message( "Failed to load %s\n", infn);
if(outf!=stdout) fclose(outf);
fclose(inf);
return 1;
}
fclose(inf);
// At this point we have all object's data loaded into memory.
// H3dsScene * scene -> object data
// Prepare to collect all vertices to one big array
int verts=0;
for(n=0; n<scene->meshobjs; n++) {
int v=scene->meshobjlist[n].verts;
if(scene->meshobjlist[n].maps > v) {
ivp_message( "%-14s more maps than vertices, quitting!\n",
scene->meshobjlist[n].name);
if(outf!=stdout) fclose(outf);
return 1;
}
// Get the total number of vertices in all objects
verts+=v;
}
H3dsMapVert * vrtmap = (H3dsMapVert *) p_malloc(verts*sizeof(H3dsMapVert));
if(!vrtmap) {
ivp_message( "Failed to allocate mem for vertice array\n");
HFree3dsScene(scene);
fclose(outf);
return 1;
}
memset(vrtmap, 0, verts*sizeof(H3dsMapVert));
// Do it! Collect them
CollectVertsAndMaps(scene, vrtmap);
// Adjust the face indexes to the new vertice array
AdjustFaceIndexes(scene);
if(!(flags & NORMDUP)) {
if(flags & VERBOSE)
ivp_message( "Removing duplicated vertices ");
n = RemoveDupVerts(scene, vrtmap, verts);
if(flags & VERBOSE)
ivp_message( "\nRemoved %d duplicated vertices\n", verts-n);
verts=n;
}
#if 0
int x;
for (x=0; x<(int)verts; x++) {
H3dsMapVert *vm = &vrtmap[x];
IVP_U_Point *point = new IVP_U_Point();
point->k[0] = vm->x;
point->k[1] = vm->y;
point->k[2] = vm->z;
concave_polyhedron->points.add(point);
}
H3dsMeshObj * mo = &scene->meshobjlist[0];
for (x=0; x<(int)mo->faces; ) {
H3dsFace * fa = &mo->facelist[x++];
IVP_Concave_Polyhedron_Face *face = new IVP_Concave_Polyhedron_Face();
face->add_offset(fa->p0);
face->add_offset(fa->p1);
face->add_offset(fa->p2);
concave_polyhedron->faces.add(face);
}
// repair_geometry(concave_polyhedron);
#endif
//IVP_U_BigVector<IVP_Compact_Ledge> ledges;
IVP_U_Vector<IVP_U_Point> polygon;
int i;
for (i=0; i<scene->meshobjs; i++) {
H3dsMeshObj * mo = &scene->meshobjlist[i];
int x;
for (x=0; x<(int)mo->faces; ) {
H3dsFace * fa = &mo->facelist[x++];
IVP_U_Point *p0 = new IVP_U_Point();
p0->k[0] = vrtmap[fa->p0].x;
p0->k[1] = vrtmap[fa->p0].y;
p0->k[2] = vrtmap[fa->p0].z;
polygon.add(p0);
IVP_U_Point *p1 = new IVP_U_Point();
p1->k[0] = vrtmap[fa->p1].x;
p1->k[1] = vrtmap[fa->p1].y;
p1->k[2] = vrtmap[fa->p1].z;
polygon.add(p1);
IVP_U_Point *p2 = new IVP_U_Point();
p2->k[0] = vrtmap[fa->p2].x;
p2->k[1] = vrtmap[fa->p2].y;
p2->k[2] = vrtmap[fa->p2].z;
polygon.add(p2);
IVP_Compact_Ledge *compact_ledge = IVP_SurfaceBuilder_Pointsoup::convert_pointsoup_to_compact_ledge(&polygon);
if ( compact_ledge ) {
ledges->add(compact_ledge);
}
int y;
for (y=0; y<polygon.len(); y++) {
delete(polygon.element_at(y));
}
polygon.clear();
}
}
#endif
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -