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

следующий фpагмент (2)
========================================================================== 3D Studio File Formats Revision 2 February 27, 1993 Revision ========================================================================== This document describes the binary data contained within the most important of the files used by Autodesk 3D Studio to maintain 3D databases and supporting information. Files covered here are MLI, 3DS and PRJ. Autodesk Animator Pro file formats (some of which are used by 3D Studio) are discussed in a document available on Compuserve (in the AutoDesk Software Forum area) as FLCFILES.ZIP, which covers: .FLC Animation file, new improved format .FLI Original animation file .CEL Animation cel file .PIC Picture file .MSK Mask data files .COL Color map files .PLY Polygon files .TWE Tween data files .OPT Optics menu settings files The formats in this document were generated using binary file format reverse-engineering techniques, and are NOT garanteed to be accurate. If any errors and/or omissions are found, or you have improvements / additions, please report them to Kerry Bonin at: Compuserve 71055,2040 Voice evenings (408) 226-4636 Voice daytime (415) 637-9300 x117 Data 24hrs. (408) 226-2482 2400 N81 (DreamQuest BBS) I will attempt to maintain an updated copy of this file on the DreamQuest BBS listed above (see file area 22 - "VScape Virtual Reality System files"), and upload to Compuserve as often as possible to the Autodesk software forum IPAS area. So far, I have only received a few calls, so calling me voice for comments and questions is not a problem. The evening number is good 7 days a week, as I spend most of my weekends on this or related programming. Please don't call before 10am or after 10pm though... Some of the names (or whatever) in this file may be trademarked. So all trademarks are the property of theirs respective holders. As far as I can tell from the 3D Studio license agreement, I'm not breaking any laws or license terms by publicising this information - if I am, I'm sure the Autodesk lawyers will tell me. :) Thankx ========================================================================== Revision history Version 1 - 02/23/93 First version, contained structure summary but only data for MLI files. Version 2 - 02/27/93 Named object chunk (4000) documentation began. Documented data necessary to extract all Tri-mesh objects. Includes chunk types 4110, 4120, 4130, and 4140. Spotlight version of Direct Light documented. ========================================================================== File Format =========== Each of the file types (MLI, 3DS, PRJ) are composed of a stream of data chunks, just like the FLC file. Each chunk contains a header identifying the chunk type and the size of the chunk, and (usually) chunk data. An empty chunk may signal a boolean state (like reflection-mapping ON). Some chunks contain specific binary data, while others contain a list of subordinate chunks. Chunks may appear as both primary chunks and subordinate chunks - that is, it is possible for some files to contain a specific chunk type in the topmost chunk list, while another file may contain that chunk as a subordinate chunk of a parent chunk. An example of this is the material chunk - it is the only chunk type (currently) found in the MLI file, but it appears in the PRJ file as a member of the Mesh Database chunk. To parse any of these files, the most flexible way is to write a state machine that understands the construction of the chunk list - that way unknown chunks may be easily skipped, and new chunks added at any time. The identifiers in headers contain everything needed to drive such a state machine. It is important to recognize that the location of a given chunk MAY mean something, for example - an ambient color chunk as a subordinate chunk of a material is an ambient color definition for THAT material. Data types are stored IBM style. All numeric fields may assumed to be unsigned integers, with the length specified. Signed numbers will be indicated implicitly. Any description followed by the symbol (FP) designates that unit to be a 4-byte IEEE floating point representation, designated as "float" by MS-DOS 16 and 32 bit C compilers. Finally - there are a number of fields that are marked as "unknown". These are binary fields which I could'nt figure out as of this document. I have only researched each chunk to the point that I could extract the data needed to export the database - I am not trying to reproduce enough information to import back into 3D Studio. ( I only use 3D Studio to create databases for my VR real-time rendering engine ). File Headers ============ Each file begins with a common header, described below. It is interesting to note that the file header is actually just a chunk header, with the file contents being a list of subordinate chunks. The chunk type identifier identifies the file type. Identifiers are listed below. Note that they are shown in hexidecimal. Identifier File 3DAA .MLI - Material library file 4D4D .3DS - 3D Mesh file 3DC2 .PRJ - 3D Studio Project file Chunk Header ============ Each chunk begins with a common header, described below. Offset Length Name Description 0 2 magic Chunk type identifier. (See below) 2 4 size The size of the chunk, including all subordinate chunks. The chunk type identifier identifies the chunk type. Identifiers are listed below. Note that they are shown in hexidecimal. Identifier Chunk type 4000 Named Object 4110 Vertex Coordinate List Chunk 4120 Face List Chunk 4130 Material Application Chunk 4140 Mapping Coordinate List Chunk A000 Material name A010 Material Ambient color A020 Material Diffuse color A030 Material Specular color A040 Material Shininess A050 Material Transparency A052 Material Transparency fall-off A053 Material Reflection blur A200 Material Texture map A210 Material Opacity map A240 Material Transparency fall-off enable A250 Material Reflection blur enable AFFF Material chunk 4000 - Named Object =================== This chunk contains data describing a named object. Unlike most other chunks, it does not follow the normal conventions for it's internal data. (Internal data is NOT just flat data or a list of subordinate chunks.) All named object chunks begin with the same header, listed below: Length Name Description 2 magic Subordinate chunk identifier. Always hex 4000. varies name Object name w/ trailing zero 2 type Named object type identifier. 4 size Number of bytes of following data for entire chunk. The type of following data is specific to the named object type. Each names object type will be discussed seperately. Known named object chunk types are listed below. Identifier Chunk type 4100 Tri-mesh 4600 Direct light In addition, some named object chunks may have postpend chunks following the normal state chunk data. Any named object chunk which has known postpended chunks will be listed implicitly with that chunk's documentation. The format of modified header of these postpend chunks is listed below: Offset Length Name Description 0 2 magic Postpend chunk identifier. 2 4 size Number of bytes of following data. 4000 - Named Object, subtype 4100 - Tri-mesh ============================================ This chunk contains the data describing a 3D object composed of a mesh of triangular polygons. The data conststs of a standard named object header, then a list of conventional data chunks. Length Name Description 2 magic Subordinate chunk identifier. Always hex 4000. varies name Object name w/ trailing zero 2 type Named object type identifier, this type hex 4100. 4 size Number of bytes of following data for entire chunk. An example of chunks contained within this type of chunk is: 4110 Vertex Coordinate List Chunk 4140 Mapping Coordinate List Chunk 4120 Face List Chunk 4130 Material Application Chunk [s] 4000 - Named Object, subtype 4600 - Spotlight ============================================= This chunk contains the data describing a spotlight. Length Name Description 2 magic Subordinate chunk identifier. Always hex 4000. varies name Object name w/ trailing zero 2 type Named object type identifier, this type hex 4600. 4 size Number of bytes of following data for entire chunk. 4 posx Light position X coordinate (FP) 4 posy Light position Y coordinate (FP) 4 posz Light position Z coordinate (FP) 6 unknown Unknown 4 red Light color, red component, 0.0 - 1.0 (FP) 4 green Light color, green component, 0.0 - 1.0 (FP) 4 blue Light color, blue component, 0.0 - 1.0 (FP) There is one known postpend chunk, which is optional. If the following postpend chunks exists, then the light is turned off. Offset Length Name Description 0 2 magic Postpend chunk identifier. Always hex 4620. 2 4 size Number of following bytes, should be 0. 4110 - Vertex Coordinate List Chunk =================================== This chunk contains a list of coordinates defining a list of vertex locations. The locations are stored as in X,Y,Z triplets. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex 4110. 2 4 size The size of the chunk. 6 2 count Number of following vertices Each vertex is stored as follows: Offset Length Name Description 0 4 x X coordinate (FP) 4 4 y Y coordinate (FP) 8 4 z Z coordinate (FP) 4120 - Face List Chunk ====================== This chunk contains a list of faces. Faces are defined as a triangular polygon. The polygon vertex coordinates are defined as a index number into a 4110 Vertex Coordinate List Chunk which should be in the same named object chunk. If any materials are applied to the face, then those applications will be defined via 4130 Material Application Chunks also in the same name object chunk. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex 4120. 2 4 size The size of the chunk. 6 2 count Number of following faces Each face is stored as follows: Offset Length Name Description 0 2 a Vertex A number 2 2 b Vertex B number 4 2 c Vertex C number 6 2 flags Flags, see below. Known face flags are listed in the table below: Bits Meaning 0 CA edge flag 1 BC edge flag 2 AB edge flag 3-15 Unknown 4130 - Material Application Chunk ================================= This chunk defines the application of a material to a face. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex 4130. 2 4 size The size of the chunk. 6 varies name Material name w/ trailing zero name+0 2 unknown Unknown name+2 2 face Face number to apply this material to 4140 - Mapping Coordinate List Chunk ==================================== This chunk contains a list of coordinates defining a list of mapping values. The locations are stored as in X,Y pairs. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex 4140. 2 4 size The size of the chunk. 6 2 count Number of following mapping values. Each mapping value is stored as follows: Offset Length Name Description 0 4 x X coordinate (FP) 4 4 y Y coordinate (FP) AFFF - Material Chunk ===================== The material chunk contains everything needed to describe a surface material, such as color, reflectivity adjestments, and mapping file names. This data is expressed as a list of subordinate chunks. A000 - The Material Name Subordinate Chunk =================================== This chunk contains the name of the material as entered in the materials editor. This is an ASCII string uniquely identifying the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A000. 2 4 size The size of the chunk, including this header. 6 (size-6) name Material name w/ trailing zero A010 - The Material Ambient Color Subordinate Chunk =================================================== This chunk specifies the ambient color of the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A010. 2 4 size The size of the chunk, should be hex 000F. 6 6 unknown Unknown 12 1 red Ambient red intensity, 0-255 13 1 green Ambient green intensity, 0-255 14 1 blue Ambient blue intensity, 0-255 A020 - The Material Diffuse Color Subordinate Chunk =================================================== This chunk specifies the diffuse color of the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A020. 2 4 size The size of the chunk, should be hex 000F. 6 6 unknown Unknown 12 1 red Diffuse red intensity, 0-255 13 1 green Diffuse green intensity, 0-255 14 1 blue Diffuse blue intensity, 0-255 A030 - The Material Specular Color Subordinate Chunk ==================================================== This chunk specifies the specular color of the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A030. 2 4 size The size of the chunk, should be hex 000F. 6 6 unknown Unknown 12 1 red Specular red intensity, 0-255 13 1 green Specular green intensity, 0-255 14 1 blue Specular blue intensity, 0-255 A040 - The Material Shininess Subordinate Chunk =============================================== This chunk contains the shininess level adjustment of the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A040. 2 4 size The size of the chunk, should be hex 000E. 6 6 unknown Unknown 12 1 shininess Shininess level, 0-100 13 1 unknown Unknown A050 - The Material Transparency Subordinate Chunk ================================================== This chunk contains the transparency level adjustment for the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A050. 2 4 size The size of the chunk, should be hex 000E. 6 6 unknown Unknown 12 1 transp Transparency level, 0-100 13 1 unknown Unknown A052 - The Material Transparency Fall-Off Chunk =============================================== This chunk contains the transparency fall-off adjustment for the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A052. 2 4 size The size of the chunk, should be hex 000E. 6 6 unknown Unknown 12 1 falloff Outside = 0-100, inside = hex FF-9D 13 1 side Outside = hex 00, inside = hex FF A053 - The Material Reflection Blur Subordinate Chunk ===================================================== This chunk contains the reflection blur level adjustment for the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A053. 2 4 size The size of the chunk, should be hex 000E. 6 6 unknown Unknown 12 1 blur Reflection blur level, 0-100 13 1 unknown Unknown A200 - The Material Texture Map Subordinate Chunk ================================================= This chunk contains data describing the texture map to apply to the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A200. 2 4 size The size of the chunk, including this header. 6 6 unknown Unknown 12 1 intensity Intensity level, 0-100 13 7 unknown Unknown 20 (size-20) name Texture map filename w/ trailing zero A210 - The Material Opacity Map Subordinate Chunk ================================================= This chunk contains data describing the opacity map to apply to the material. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A210. 2 4 size The size of the chunk, including this header. 6 6 unknown Unknown 12 1 intensity Intensity level, 0-100 13 7 unknown Unknown 20 (size-20) name Opacity map filename w/ trailing zero A240 - The Material Transparency Fall-Off Enable Subordinate Chunk ================================================================== The presence of this empty chunk enables transparency fall-off. If it is not present in the material chunk, then transparency fall-off is assumed to be off. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A240. 2 4 size The size of the chunk, should be hex 6 A250 - The Material Reflection Blur Enable Subordinate Chunk ============================================================ The presence of this empty chunk enables reflection blur. If it is not present in the material chunk, then reflection blur is assumed to be off. Offset Length Name Description 0 2 magic Subordinate chunk identifier. Always hex A250. 2 4 size The size of the chunk, should be hex 6
следующий фpагмент (3)|пpедыдущий фpагмент (1)
/* * Simple 3DS loader example * by shodan@chat.ru, 15.jan.99 */ #include <setjmp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> /* * Camera is (0,0,-CAMDIST), camer target is (0,0,0) */ #define CAMDIST 320 /* * 3DS chunk ID's list */ enum { CHUNK_MAIN = 0x4D4D, CHUNK_OBJMESH = 0x3D3D, CHUNK_BKGCOLOR = 0x1200, CHUNK_AMBCOLOR = 0x2100, CHUNK_OBJBLOCK = 0x4000, CHUNK_TRIMESH = 0x4100, CHUNK_VERTLIST = 0x4110, CHUNK_VERTFLAGS = 0x4111, CHUNK_FACELIST = 0x4120, CHUNK_FACEMAT = 0x4130, CHUNK_MAPLIST = 0x4140, CHUNK_SMOOLIST = 0x4150, CHUNK_TRMATRIX = 0x4160, CHUNK_MESHCOLOR = 0x4165, CHUNK_TXTINFO = 0x4170, CHUNK_LIGHT = 0x4600, CHUNK_SPOTLIGHT = 0x4610, CHUNK_CAMERA = 0x4700, CHUNK_HIERARCHY = 0x4F00, CHUNK_VIEWPORT = 0x7001, CHUNK_MATERIAL = 0xAFFF, CHUNK_MATNAME = 0xA000, CHUNK_AMBIENT = 0xA010, CHUNK_DIFFUSE = 0xA020, CHUNK_SPECULAR = 0xA030, CHUNK_TEXTURE = 0xA200, CHUNK_BUMPMAP = 0xA230, CHUNK_MAPFILE = 0xA300, CHUNK_KEYFRAMER = 0xB000, CHUNK_AMBIENTKEY = 0xB001, CHUNK_TRACKINFO = 0xB002, CHUNK_TRACKOBJNAME = 0xB010, CHUNK_TRACKPIVOT = 0xB013, CHUNK_TRACKPOS = 0xB020, CHUNK_TRACKROTATE = 0xB021, CHUNK_TRACKSCALE = 0xB022, CHUNK_TRACKMORPH = 0xB026, CHUNK_TRACKHIDE = 0xB029, CHUNK_OBJNUMBER = 0xB030, CHUNK_TRACKCAMERA = 0xB003, CHUNK_TRACKFOV = 0xB023, CHUNK_TRACKROLL = 0xB024, CHUNK_TRACKCAMTGT = 0xB004, CHUNK_TRACKLIGHT = 0xB005, CHUNK_TRACKLIGTGT = 0xB006, CHUNK_TRACKSPOTL = 0xB007, CHUNK_FRAMES = 0xB008 }; /* * Handy aliases */ typedef int int32; typedef unsigned int uint32; typedef short int16; typedef unsigned short uint16; typedef unsigned char uchar; /* * 3D structures */ typedef struct { int32 x, y, z; int32 sx, sy; int32 u, v; } engVertex; typedef struct { int32 v0, v1, v2, mid_z; char *tex; } engFace; typedef struct { char name[32]; int32 begVert, endVert, begFace, endFace; } engObject; typedef struct { int32 objsNum, vertsNum, facesNum; engVertex *origVerts, *verts; engFace *faces; engObject *objs; } engScene; int fix(int); int unfix(int); int fixmul(int, int); int fixdiv(int, int); #pragma aux fix = " sal eax,16 " \ parm [eax] value [eax] modify [eax] #pragma aux unfix = " sar eax,16 " \ parm [eax] value [eax] modify [eax] #pragma aux fixmul = " imul ebx " " shrd eax,edx,16 " \ parm [eax] [ebx] value [eax] modify [eax ebx edx] #pragma aux fixdiv = " mov edx,eax " " shl eax,16 " " sar edx,16 " " idiv ebx " \ parm [eax] [ebx] value [eax] modify [eax ebx edx] /* * Video handling and output variables and routines */ int alias; int filter[192]; extern void setVideoMode(short mode); #pragma aux setVideoMode = \ " int 10h " \ parm [ax] \ modify [eax]; int amin(int a, int b) { if (a < b) return a; else return b; } void putPixel(int x, int y, char color) { char *d = (char*)(0xA0000L + y * 320 + x); int dd; dd = *d; *d = amin(color + dd, 255); } /* * Antialiasing line drawing code taken from FAQSYS * http://www.neutralzone.org/home/faqsys */ #define swap(a,b) (a)=(a)^(b);(b)=(b)^(a);(a)=(a)^(b) void AAline(int x0, int y0, int x1, int y1) { int p[2]; int i, dx, dy, xi, yi, x=0, y=1, dE, dNE, d; int vdx; float rdx, rvdx; if ((dx = x1 - x0) < 0) { dx = -dx; xi = -1; } else xi = 1; if ((dy = y1 - y0) < 0) { dy = -dy; yi = -1; } else yi = 1; if (dy > dx) { swap(dx, dy); swap(xi, yi); swap(x, y); swap(x0, y0); swap(x1, y1); } d = 2 * dy - dx; dE = 2 * dy; dNE = -2 * dx; /* dE component has been taken out */ vdx = 0; rvdx = 1.0 / (2.0 * sqrt(dx * dx + dy * dy)); rdx = 2.0 * dx * rvdx; for (i = dx, p[x] = x0, p[y] = y0; i > 0; i--) { if (alias) { putpixel(p[0], p[1], filter[(int) (128 * fabs(vdx * rvdx))]); p[y] += yi; putpixel(p[0], p[1], filter[(int) (128 * fabs(rdx - vdx * rvdx))]); p[y] -= yi * 2; putpixel(p[0], p[1], filter[(int) (128 * fabs(rdx + vdx * rvdx))]); p[y] += yi; } else putpixel(p[0], p[1], 255); if (d > 0) { vdx = d - dx; d += dNE; p[y] += yi; } else vdx = d+dx; d += dE; p[x] += xi; } } void initAAline(int aa) { int i; alias = aa; if (alias == 1) /* linear filter function */ for (i = 0; i < 192; i++) filter[i] = 255 - (255 * i / 192); else if (alias > 1) /* Gaussian filter function */ for (i = 0; i < 192; i++) filter[i] = (int) (255.0 * exp(-1.0 * pow(i / ((alias - 1.0) * 20.0), 2.0))); /* decrease brightness */ for (i = 0; i < 192; i++) filter[i] >>= 2; } /* * 3DS loader part */ jmp_buf env; FILE *infile; int dpos, dsize, objsNum, vertsNum, facesNum, matsNum, trackObj; char lastname[32], *err; /* * Generic data reader functions */ void drestart() { if (fseek(infile, 0, SEEK_SET)) longjmp(env, 1); dpos = 0; } void dinit() { if (fseek(infile, 0, SEEK_END)) longjmp(env, 1); dsize = ftell(infile); if (dsize == -1L) longjmp(env, 1); drestart(); } void dread(void *buf, int len) { if (fread(buf, 1, len, infile) != len) longjmp(env, 1); dpos += len; } char dgetc() { char r; dread(&r, 1); return r; } void dreadstr(char *buf) { char c; while ((c = dgetc()) != 0x00) *buf++ = c; *buf++ = 0x00; } void dskip(int len) { if (fseek(infile, len, SEEK_CUR)) longjmp(env, 1); dpos += len; } int deof() { return (dpos == dsize); } /* * Scene allocation and disposal routines */ void engFreeScene(engScene *scene) { int i; free(scene->objs); free(scene->verts); free(scene->origVerts); free(scene->faces); free(scene); } engScene *engNewScene(int32 objsNum, int32 vertsNum, int32 facesNum) { engScene *scene; if (scene = malloc(sizeof(engScene))) { scene->objsNum = objsNum; scene->vertsNum = vertsNum; scene->facesNum = facesNum; scene->objs = malloc(sizeof(engObject) * objsNum); scene->verts = malloc(sizeof(engVertex) * vertsNum); scene->faces = malloc(sizeof(engFace) * facesNum); scene->origVerts = malloc(sizeof(engVertex) * vertsNum); memset(scene->objs, 0x00, sizeof(engObject) * objsNum); if (!(scene->objs && scene->verts && scene->faces && scene->origVerts)) { engFreeScene(scene); scene = NULL; } } return scene; } /* * Loader routines */ void statChunk(int maxpos) { uint16 id, num; int32 len; char *c; while (dpos < maxpos) { dread(&id, 2); dread(&len, 4); if (len == 0) return; len -= 6; switch (id) { case CHUNK_MAIN: statChunk(dpos + len); break; case CHUNK_OBJMESH: statChunk(dpos + len); break; case CHUNK_OBJBLOCK: dreadstr(lastname); len -= (strlen(lastname) + 1); statChunk(dpos + len); break; case CHUNK_TRIMESH: objsNum++; statChunk(dpos + len); break; case CHUNK_VERTLIST: dread(&num, 2); vertsNum += num; dskip(len - 2); break; case CHUNK_FACELIST: dread(&num, 2); facesNum += num; dskip(len - 2); break; default: dskip(len); break; } } } void loadObjects(engScene *scene, int maxpos) { uint16 id, num, curr, tmp16, flags; int32 i, j, len; char buf[128], *texture; float tmpf; while (dpos < maxpos) { dread(&id, 2); dread(&len, 4); if (len == 0) return; len -= 6; switch (id) { case CHUNK_MAIN: case CHUNK_OBJMESH: loadObjects(scene, dpos + len); break; case CHUNK_OBJBLOCK: dreadstr(lastname); len -= (strlen(lastname) + 1); loadObjects(scene, dpos + len); break; case CHUNK_TRIMESH: strcpy(scene->objs[objsNum].name, lastname); loadObjects(scene, dpos + len); objsNum++; break; case CHUNK_VERTLIST: dread(&num, 2); for (i = vertsNum; i < vertsNum + num; i++) { dread(&tmpf, 4); scene->origVerts[i].x = (int) (tmpf * fix(1)); dread(&tmpf, 4); scene->origVerts[i].z = (int) (tmpf * fix(1)); dread(&tmpf, 4); scene->origVerts[i].y = (int) (tmpf * fix(1)); } scene->objs[objsNum].begVert = vertsNum; scene->objs[objsNum].endVert = vertsNum + num - 1; vertsNum += num; break; case CHUNK_FACELIST: dread(&num, 2); j = scene->objs[objsNum].begVert; for (i = facesNum; i < facesNum + num; i++) { dread(&tmp16, 2); scene->faces[i].v0 = j + tmp16; dread(&tmp16, 2); scene->faces[i].v1 = j + tmp16; dread(&tmp16, 2); scene->faces[i].v2 = j + tmp16; dskip(2); } scene->objs[objsNum].begFace = facesNum; scene->objs[objsNum].endFace = facesNum + num - 1; facesNum += num; break; case CHUNK_MAPLIST: dread(&num, 2); j = scene->objs[objsNum].begVert; for (i = j; i < j + num; i++) { dread(&tmpf, 4); scene->origVerts[i].u = (int) (tmpf * 0x4000); dread(&tmpf, 4); scene->origVerts[i].v = (int) (tmpf * 0x4000); } break; default: dskip(len); break; } } } engScene *engLoad3DS(char *filename, char *errmsg) { engScene *scene; int i; err = errmsg; sprintf(err, ""); if (!(infile = fopen(filename, "rb"))) { sprintf(err, "unable to open \"%s\".", filename); return NULL; } if (setjmp(env)) { sprintf(err, "statChunk() failed. \"%s\" is probably corrupted.", filename); fclose(infile); return NULL; } dinit(); objsNum = vertsNum = facesNum = matsNum = 0; statChunk(dsize); if (!(scene = engNewScene(objsNum, vertsNum, facesNum))) { sprintf(err, "unable to allocate memory for scene."); return NULL; } if (setjmp(env)) { if (strlen(err) == 0) sprintf(err, "read or seek error in \"%s\".", filename); fclose(infile); engFreeScene(scene); return NULL; } memset(scene->origVerts, 0x00, vertsNum * sizeof(engVertex)); objsNum = vertsNum = facesNum = 0; drestart(); loadObjects(scene, dsize); fclose(infile); return scene; } /* * Vertex projection */ void projectVertex(engVertex *v) { register int32 d = unfix(v->z) + CAMDIST; register int32 k = d ? fix(CAMDIST) / d : 0; v->sx = fix(160) + fixmul(v->x, k); v->sy = fix(100) - fixmul(v->y, k); } /* * Main routine */ void main() { engScene *scene; char errmsg[128]; int i; int x0, y0, x1, y1, x2, y2; scene = engLoad3DS("test.3ds", errmsg); if (scene == NULL) { printf("error: %s", errmsg); exit(0); } setVideoMode(0x13); outp(0x3C8, 0x00); for (i = 0; i < 0x100; i++) { outp(0x3C9, i >> 2); outp(0x3C9, i >> 2); outp(0x3C9, i >> 2); } initAAline(1); for (i = 0; i < scene->vertsNum; i++) projectVertex(&scene->origVerts[i]); for (i = 0; i < scene->facesNum; i++) { x0 = unfix(scene->origVerts[scene->faces[i].v0].sx); y0 = unfix(scene->origVerts[scene->faces[i].v0].sy); x1 = unfix(scene->origVerts[scene->faces[i].v1].sx); y1 = unfix(scene->origVerts[scene->faces[i].v1].sy); x2 = unfix(scene->origVerts[scene->faces[i].v2].sx); y2 = unfix(scene->origVerts[scene->faces[i].v2].sy); AAline(x0, y0, x1, y1); AAline(x0, y0, x2, y2); AAline(x1, y1, x2, y2); } getch(); setVideoMode(0x03); }

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

Если вы хотите дополнить 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".