view3ds_src

所属分类:3D图形编程
开发工具:C/C++
文件大小:2098KB
下载次数:33
上传日期:2007-09-12 23:42:37
上 传 者proudmoore
说明:  用于方便查看由3DSMax导出的3ds格式,功能比较强大和完善!
(For easy viewing from 3DSMax export 3ds format, features more powerful and perfect!)

文件列表:
blinn-dusty.pdf (877756, 2007-06-28)
D37.pdf (86041, 2007-06-28)
nishitaSiggraph96clouds.pdf (1197432, 2007-06-28)
view3ds (0, 1998-07-25)
view3ds\3dsload.c (21513, 1998-07-25)
view3ds\3dsload.h (3497, 1998-07-25)
view3ds\bmf (0, 1998-07-25)
view3ds\bmf.h (2575, 1998-07-25)
view3ds\bmf\bmf.h (2575, 1998-06-25)
view3ds\bmf\camera.c (2795, 1998-06-25)
view3ds\bmf\camera.h (597, 1998-06-25)
view3ds\bmf\drawbmf.c (1978, 1998-06-25)
view3ds\bmf\hubble.bmf (93508, 1998-07-25)
view3ds\bmf\loadbmf.c (5841, 1998-06-25)
view3ds\bmf\main.c (3039, 1998-07-25)
view3ds\bmf\makefile (434, 1998-06-25)
view3ds\bmf\makefile.win (1538, 1998-06-25)
view3ds\bmf\types.h (300, 1998-06-25)
view3ds\camera.c (2795, 1998-07-25)
view3ds\camera.h (597, 1998-07-25)
view3ds\main.c (8272, 1998-07-25)
view3ds\makefile (1241, 1998-06-25)
view3ds\makefile.win (1642, 1998-06-25)
view3ds\outgl.c (42993, 1998-07-25)
view3ds\outgl.h (2419, 1998-07-25)
view3ds\skeleton (0, 1998-07-25)
view3ds\skeleton\camera.c (2795, 1998-06-25)
view3ds\skeleton\camera.h (597, 1998-06-25)
view3ds\skeleton\hubble.gl (83008, 1998-07-25)
view3ds\skeleton\hubble.h (69924, 1998-07-25)
view3ds\skeleton\main.c (3343, 1998-07-25)
view3ds\skeleton\makefile (939, 1998-06-25)
view3ds\skeleton\makefile.win (1521, 1998-06-25)
view3ds\stars.c (2084, 1998-07-25)
view3ds\stars.h (133, 1998-07-25)
view3ds\stripe.mak (1033, 1998-07-25)
view3ds\types.h (296, 1998-07-25)
view3ds\versions (2145, 1998-07-25)
... ...

3D Studio->OpenGL Converter by David Farrell fdavid@cyberramp.net http://www.cyberramp.net/~fdavid 0. RELEASE NOTES This is version 1.10 of this program. Contact me at the above email address to report any problems or bugs. If you find the program useful, please email me; I enjoy hearing about how it is used. VIEW3DS is an OpenGL-based 3D Studio model viewer. It accepts .3DS files as input and renders them in real-time using OpenGL. It can convert the .3DS file into either OpenGL C code fragments that are easily includable in any program or a more simple file format that I have devised. VIEW3DS can also convert the polygon mesh into a set of triangle strips; this can greatly decrease rendering time. VIEW3DS was developed using Mesa, the free OpenGL-like API, on a PC running Linux, the free UNIX operating system. It is very portable; the same code compiles under Windows 95/NT with just the addition of a few #include "windows.h". I've made a separate ZIPped distribution with a Makefile.win that you can compile under Windows 95 and NT. As of version 1.04, it should be endian-safe and run on any processor out there. I think. Because I don't have access to many machines, I can't personally verify this, so if you have any succes stories running this on a Sun, SGI, Mac, Commodore *** :), etc., I'd like to hear about it. 1. INTRODUCTION This program reads in 3D Studio files ending in .3DS and renders them using OpenGL. You can then interactively fly around the model or spin the model. Finally, the program can export the data into either OpenGL C code or a .BMF file. Exporting the data as OpenGL C code makes two files. One file is a C .h include file that can simply be included in your own program; the other file is raw binary data that you need to have in the same directory as your executable. It's all very easy and (hopefully!) automated. There's a sample application in the skeleton/ directory that shows exactly what you need to do, as well as a more thorough explanation below. The second option is exporting the data into a .BMF file. This is the Basic Model Format that I've come up with. It's nothing fancy, just an easy-to-use file that I can read in. Information on the format and sample readers are in the bmf/ directory. VIEW3DS features smooth normal generation with preservation of hard edges. The number of normals generated can be controlled through the -T command line option. More information is in later sections. VIEW3DS can generate triangle strips through the use of STRIPE. Use this feature through the -S command line option. You will need the STRIPE executable somewhere in your path or in the same directory as VIEW3DS. More information is in later sections. 2. STARTING VIEW3DS To start the parser, type: view3ds [-t??] [-s] [-r] [-f] [-c] [-x] * The filename is the exact name of the file to be parsed, such as model.3ds. Be sure to include the .3ds suffix. * The -t argument is optional. It turns on the edge preservation when VIEW3DS generates the normals. This can make a model look better at the expense of rendering speed. If you just type -t, the default threshold is 90 degrees. Otherwise, put a number after -t to set the threshold. * The -s argument is optional. It turns on triangle strip detection. This can speed up rendering time significantly if your OpenGL implementation takes advantage of it. It can take a very long time at startup to detect the strips, so be sure that you want to do it. * The -r option reverses the polygon winding. If your model looks inside out, turn this option on. Often, -r and -f are used together. * The -f option flips the direction of the normals. If your model looks right but the lighting looks strange, try turning this on. Often, -r and -f are used together. * The -c option centers the object around (0,0,0) instead of wherever in space 3D Studio put the model. * The -x option will export the file as a .BMF file without displaying it first. 3. KEYBOARD COMMANDS When you run the parser, an OpenGL window will open. This is approximately what your model will look like in your own code. It might look different in your own program depending on your lighting and other parameters. If you press the left mouse button, you will be presented with a menu of options that you can click on, or press the keyboard shortcut to invoke. Here is a listing of the keyboard commands that you can use: F <- Capital F flips the direction of the normals. If your model looks strangely inside-out or the lighting is wrong, press shift-F and see if it helps. R <- Reverses the winding of the polygons. This is often used with the F option above. W <- Render the model in wireframe mode instead of filled polygons. X <- Exports the display list to your hard drive. It will make two files: .h and .gl. These are saved in the same directory that the .3DS file is in, which may not be your current directory. - <- The minus sign will cause the model to uniformly scale 10% down. This is useful if your model is too large in comparison to other things. + <- The plus sign will cause the model to uniformly scale 10% up. If your model is tiny and appears far away, make it larger. H <- Pops up this README in a separate window. ESC <- To exit and export the display list. Movement Controls: * Camera Movement: w <- Pitches the camera down, like you are pushing forward on a joystick. s <- Pitches the camera up, like you are pulling back on a joystick. a <- Yaws to the left, like you turned the chair you're sitting in to your left. d <- Yaws to the right, like you turned your chair to your right. Cursor Keys <- The up and down arrows move you forward and back. The left and right arrows roll you left and right. * Model Rotation: 4,6 <- Rotates the model (not the camera) along the world X axis. 8,2 <- Rotates the model along the world Y axis. 7,9 <- Rotates the model along the world Z axis. The movement keys may feel awkward at first, but I find them very convenient. If they bother you too much, edit main.c and change them. They are the same keys I use to play Descent, a 3D flight game. 3. USING THE OPENGL OUTPUT FILES Writing your own OpenGL application that uses 3D Studio models is easy if you follow these steps: 1) Create your model in 3D Studio, and save it as a .3DS file. 2) Run the converter to convert the data from .3DS to OpenGL display lists. 3) Write your own application, including the display lists with a #include . 4) Call the GL3DS_initialize... function, position your modelview matrix, and call glCallList to draw the display list. There are two output files created. One is .h, and the other is .gl, where is the name of the 3D Studio file without the .3ds extension. The .h file is a standard C or C++ include file that you can #include into your own program. The .gl file is a binary file filled with the vertex and normal data that the .h file reads in. Both these files are saved to the same directory that you got your .3DS file from, which may or may not be your current working directory if you specified somewhere else. As many .h display list files can be included in your program as you would like. They all have unique names beginning with GL3DS_ so I don't think that conflicting variable names with your own progams will be a problem. Each .h file has a function which loads the vertex and normal data and compiles the display list, then returns this display list's number. This function is called GL3DS_initialize_. Thus, if you invoked the parser with view3ds xwing.3ds you would want to call the function like this: int ListNumber = GL3DS_initialize_xwing(); Then, to draw the display list, be sure to enable lighting and position your modelview matrix, then call glCallList(ListNumber); The display list may leave OpenGL in a different state than how you left it. In particular, polygon winding may or may not be clockwise. Be sure to re-specify these settings in your own application. 4. THE SKELETON EXAMPLE Included in the skeleton/ directory is a sample skeleton OpenGL/GLUT application that uses a model already converted with VIEW3DS. I have commented it to show you what needs to be done, although I think the above explanation should be clear enough. The camera controls are the same as they are in the model previewer. A makefile is included that will compile it. The skeleton example does not include a starfield background like VIEW3DS does. If you would like to use the starfield background, compile and link into my stars module. Call the stars initialization function somewhere early in your program, and then call the draw stars fucntion immediately after you clear the frame and depth buffers. It draws with the depth buffer turned off so render the stars first and then render everything else. If you look at the source code in main.c you should find everything you should need to use the stars. EMail me if you have any questions. 5. COMMAND-LINE OPTIONS Invoke VIEW3DS like so: view3ds .3ds [-t??] [-s] [-f] [-r] [-c] [-x] The -t sets the polygon normal threshold. In other words, multiple normals will be generated per vertex if the polygons touching that vertex are more than the specified ?? angle apart. For instance, you will want multiple vertices for a cube so that it will shade properly. The default value is 90 degress, but some models look better with different values. Play with this to get the optimum look for your model. A natural, organic model will probably look good with a 90 degree or more threshold; human-made objects (such as planes) will look good with a 60 or 50 degree threshold. A very small threshold is ridiculous because it becomes very expensive flat shading. See the section on normal generation below. The -s option turns on triangle strip conversion. Using STRIPE, the program will now convert the model into a series of triangle strips. This can speed up rendering time significantly if your OpenGL implementation takes advantage of it. To use this option, you'll need to get STRIPE from the web and then copy the Stripe executable to the same directory that VIEW3DS is in. VIEW3DS only works with Stripe 2.0. The -f and -r options are if your model doesn't appear quite right. Use these to tweak the appearance of your model. Sometimes the .3DS file format is inconsistent and saves normal information wrong, so try these options if your files don't render properly. The -c option will center the object around (0,0,0). Sometimes you want this, and sometimes you intentionally position objects away from (0,0,0). If you start the program and don't see the model, try this option and maybe it will appear. The -x option will export the file as a .BMF file without any user interactivity. This is useful if you know the options you've set are correct and you don't need to look at the model first. 6. BMF FILES The OpenGL export option is convenient for throwing display lists into your program but it's not very flexible. To get around this, I've created what I call the Basic Model Format. Nothing fancy here, just a generic binary 3D file. Included with these files should be a README.bmf file. Read this for a description of the BMF file format. Also, in the bmf/ directory is a sample BMF file reader and viewer. It should be very easy to modify it to include in your own program. Particularly look at the LOADBMF.C and DRAWBMF.C files. You should be able to easily modify it to read the BMF file into whatever data structures you want to use for your own program. Basically, in MAIN.C, it initially calls LoadBMF() with the file name of the BMF file to load. The function returns a pointer to a BMF object. To render this object, all you have to do is call DrawBMFObject() and pass it a pointer to the BMF object you want rendered. You'll want to write your own renderer, but this is a start. 7. SOURCE CODE * Linux The source code for VIEW3DS is included. It should work fine on any Linux with Mesa. I assume that your Mesa libraries are in /usr/local/Mesa-3.0/libs. If they are anywhere else, edit the top of the Makefile and change the OPENGL_LIBS variable to point to your libraries. You can replace the debugging compiler option with optimizations on, but the performance increase is very little because OpenGL does almost all of the work. All my program does in the rendering loop is tell OpenGL to draw a display list made with large vertex arrays. * Windows The Win95/NT version was made with Windows NT and Visual C++ 5.0. I assume that the Makefile.win will work on earlier versions of VC++. It links with Microsoft's OpenGL libraries which are opengl32.dll and glu32.dll. You will also need the Windows port of GLUT which is at http://www.cs.utah.edu/~narobins/glut.html. 8. NORMAL GENERATION The 3D Studio file format only specifies the normal for an entire polygon. If you want to do smooth shading in OpenGL, you have to specify a different normal for each vertex of the polygon. Thus, I have to calculate the normals myself. VIEW3DS generates each of the polygon normals, then generates the normals for each vertex. The vertex normals are averaged by the angle of the polygon that touches it. Thus, if there are two large triangles sharing a vertex along with a sliver of a smaller triangle, the sliver only contributes a little bit to the final normal. This makes much better looking normals than just averaging all normals together and producing an unweighted average. VIEW3DS also preserves edges by not averaging a polygon into a vertex's normal if the polygon is more than a threshold angle from the vertex. This is turned off by default as it can generate a lot of extra normals. It can be turned on through the -T command line option. 9. TRIANGLE STRIPIFICATION VIEW3DS can turn models into triangle strips, which can potentially reduce drawing time by quite a bit. To do this, VIEW3DS interfaces with a program called STRIPE, which is at http://www.cs.suny.edu/~stripe.html. You will have to download the STRIPE code yourself to get the STRIPE executable. The current version is 2.0; be sure you use it, since VIEW3DS is incompatible with the old version. You must place the STRIPE executable either in your current working directory or in your path. A good idea is just to put STRIPE in the same directory as VIEW3DS. If you are using Windows, copy STRIPE.EXE to the directory that VIEW3DS is in. If you are using Linux, build the executable, which is called "stripe", and copy it to the directory that VIEW3DS is in. Currently, there is not a Windows makefile to build STRIPE. I've included one in the VIEW3DS distribution called "stripe.mak". Assuming you are using Visual C++, unzip STRIPE into a directory and type: nmake -f stripe.mak and it should build a file called STRIPE.EXE. This is not needed if you are not going to use triangle strips. 10. EXIT Bug reports, questions, comments, improvements, etc. can be directed to fdavid@cyberramp.net. Please drop me a line if you find this at all useful!

近期下载者

相关文件


收藏者