DEMO.DESIGN
Frequently Asked Questions
 
оглавление | demo party в ex-СССР | infused bytes e-mag | новости от ib/news | другие проекты | письмо | win koi lat

следующий фpагмент (2)
.DXF is an incredibly simple ASCII text format for storing 2D and 3D model info. That means that if you have any further questions about .DXF then you can simply open a .DXF file with any ASCII editor and answer them yourself! .DXF files are broken up into five sections: HEADER TABLES BLOCKS ENTITIES END OF FILE (helluva section, eh?) The ENTITIES section is all that really matters to most human beings in the milky way galaxy. I've heard that some of the more bizarre alien creatures of our universe actually use some of the crap which appears in the other sections, but most of those aliens work for AutoDesk. The ENTITIES section contains all of the info which describes the 2D and 3D shapes which appear in the file. Anything which is a drawable shape or 3D model is called an entity. Line, polygons, and circles are all examples of entities. The file is arranged as a simple vertical list of numerals and words (i.e. each line of the file is either a numeral or a word.) This means that you will never find two useful pieces of data on the same line. Basically, you will find one of two things on each line of the DXF file. It will either be what I call a delimiter or a piece of data. Delimiters tell you what sort of data is going to appear on the next line of the file. Here are the delimiters I know of and what they mean. Note that this is not an exhaustive list of all possible delimiters; these are simply the ones which I use often. If you want an exhaustive list, look 'em up in any good reference (see above)! An example .DXF file with comments follows and it should clear up the confusion you will surely feel when you read about these delimiters. Delimiter: Meaning: 0 This means you are beginning 'something new' in the file. It could be a new section, a new entity, etc. On the next line of the file there will be a text string which tells you what the new thing is. (for example, the following line might read 'ENTITIES' which means that you are entering the ENTITIES section of the file. 8 The data which follows is the name of the 'layer' this entity was drawn on if the user created the entity in CAD software. Most of us ignore this drek. 3DLINE The data which follows describes a 3D line. LINE Take a guess. CIRCLE Yep. 3DFACE The four vertices of a 3D polygon follow. 10 The x ordinate of the 1st vertex of current entity follows. 20 The y ordinate of the 1st vertex of current entity follows. 30 The z ordinate of the 1st vertex of current entity follows. 11 The x ordinate of the 2nd vertex of current entity follows. 21 The y ordinate of the 2nd vertex of current entity follows. 31 The z ordinate of the 2nd vertex of current entity follows. 12 The x ordinate of the 3rd vertex of current entity follows. 22 The y ordinate of the 3rd vertex of current entity follows. 32 The z ordinate of the 3rd vertex of current entity follows. 13 The x ordinate of the 4th vertex of current entity follows. 23 The y ordinate of the 4th vertex of current entity follows. 33 The z ordinate of the 4th vertex of current entity follows. EXAMPLE .DXF FILE This example is a 3D cube which I built in AutoCAD out of 3DFACES. (a 3DFACE is a polygon with 4 vertices.) Comments are indicated by // These are comments which I have added to explain the file. They DO NOT actually appear in .DXF files, Beavis! EXAMPLE FILE STARTS HERE ------------------------------------------------------ 0 // Delimiter means we're starting 'something new.' SECTION // Aha! The 'something new' we're starting is a section 2 // What section? 2 means ENTITIES section. ENTITIES // ENTITIES also means ENTITIES section. Sound redundant? 0 // Starting 'something new' again! 3DFACE // Oh, yeah, baby! It's a 3DFACE! 8 // 8 means the next line tells me what layer this is on 0 // It's on layer 0. I usually ignore the layer. 10 // The line which follows will be vertex 1 X. 50.0 // X of vertex 1 is 50.0. 20 -50.0 // Y of vertex 1 is -50.0. 30 -50.0 // Z of vertex 1 is -50.0 11 50.0 // X of vertex 2 is 50.0 21 50.0 // Y of vertex 2 is 50.0 31 -50.0 // And so on . . . 12 -50.0 22 50.0 32 -50.0 13 -50.0 23 -50.0 // Once we read 'em all, we see that this 3DFACE has four 33 // vertices with the following coordinates: -50.0 // (50,-50,-50);(50,50,-50);(-50,50,-50);(-50,-50,-50) 0 // Starting 'something new' again! ENDSEC // Ah, damn, it's the end of the ENTITIES section . . . 0 EOF // End of file, baby! You should stop reading now. ------------------------------------------------------ EXAMPLE FILE ENDS HERE The actual file included six 3DFACES which formed a cube. Other entities are just as easy to handle, and a little common sense will take you as far as you'll ever need to go with .DXF files. Note that most useful models in .DXF files will be comprised primarily of VERTEX entities. They're even easier to handle than 3DFACES are. Here's some sample C code which I use in my rendering software to read .DXF files into the memory arrays which I use in my code. My code simply takes 3DFACES in .DXF files reads their vertices into the array *vertex. Note that the approach I use is to ignore all of the delimiters and simply search for each occurance of the string '3DFACE'. Once I've found that, I know the first x coordinate is 4 spaces below that, the 1st y is 2 spaces further, etc. Like I said, .DXF files are VERY simple creatures. EXAMPLE .DXF CODE: void DXFIns (float *vertex[], char *filename, unsigned long NumberOfFaces) { FILE *dxf; unsigned long cx; char datain[20]; int ax,dx=1,bx; if ((dxf=fopen(filename,"rt"))==NULL) Error ("Unable to open .DXF file. Press any key."); for (ax=0; ax<NumberOfFaces; ax++) { // Initialize the data structure. for (cx=0; cx<POLYLENGTH+1; cx++) vertex[ax][cx]=1; vertex[ax][0]=1; // Find next occurance of 3DFACE while (dx!=0) { if ((fscanf (dxf,"%s",datain))==EOF) goto finished; dx=strcmp(datain,"3DFACE"); } // Skip first 3 entries fscanf (dxf,"%s",datain); fscanf(dxf,"%s",datain); fscanf (dxf,"%s",datain); // Read ordinate, skip entry, read ordinate, etc. 12 times for (bx=1; bx<13; bx++) { fscanf (dxf,"%s",datain); vertex[ax][bx]=atof(datain); fscanf (dxf,"%s",datain); } dx=1; } finished: fclose(dxf); } unsigned long sizeofdxf (char *filename) { // This function returns the number of 3dfaces which occur in a DXF file FILE *dxf; int cx; char datain[20]; unsigned long facecount=0; if ((dxf=fopen(filename,"rt"))==NULL) Error ("Unable to open .DXF file."); while(1) { cx=fscanf (dxf, "%s", datain); if (cx==EOF) goto FINISHED; if ( (strcmp (datain, "3DFACE"))==0) ++facecount; } FINISHED: fclose(dxf); return (facecount); }

Всего 1 фpагмент(а/ов) |пpедыдущий фpагмент (1)

Если вы хотите дополнить FAQ - пожалуйста пишите.

design/collection/some content by Frog,
DEMO DESIGN FAQ (C) Realm Of Illusion 1994-2000,
При перепечатке материалов этой страницы пожалуйста ссылайтесь на источник: "DEMO.DESIGN FAQ, http://www.enlight.ru/demo/faq".