ComputerKnowledgeandTechnology:710(20114)OBJOpenGL,((),100083):Maya,MayaOBJ,OBJOpenGL(OpenGraphicLibrary)。OBJ、,OpenGL。:;OpenGL;OBJ;:TP391:A:1009-3044(2011)10-2393-04ObjThree-dimensionalModelFileFormatinOpenGL,InputandProcessingWANGJin-feng,YAOGuo-qing(ChinaUniversityofGeosciences,Beijing100083,China)Abstract:Introducedthethree-dimensionalmappingtoolsoftoday'spopularMaya,expoundstheMaya3dformatOBJgenerated,Thefileformatsof3DfilesOBJisintroducedandthewayshowtotransfer3DmodelfilestoOpenGLarediscussed.ThepaperlaysastrongemphasisonthefileformatsofOBJfileandhowtousecodetoformthemodelingdatastructureandhowtopainttheobjectmodels.ThenthepowerfulfunctionofOpenGLcanbeusedto3Ddisplayandinteractiveoperation.Keywords:3Dmodelfile;OpenGL;OBJfile;interact1OpenGL(OpenGraphicLibrary),。SGIIRISGL,,SGIOpenGL,19927OpenGL1.0。OpenGL,,。OpenGL,(Microsoft、IBM、DEC、SUN),OpenGL。,;OpenGLVisualC++,;OpenGL,。OpenGL、,:、、、、、。Windows。2MayaMayaAliaso/Wavafront,、、、、、、、、MTV、。MayaAliaso/Wavefront。,、、、。MayaWin-dowsNTSGIIRIX。,Maya。Maya,,。OpenGL,OpenGL[1]。3OBJOBJAlias/WavefrontMaya,。,3D。OBJ[2],3D,Wavefront3D,。OBJ,ASCII,.mod,ASCII.obj。3.1OBJMayaMEL,DXF,Explore,Geo,OBJ,IGES,Aliaswire,Aiff,Image,RIB,MOV(Aaciimotion),VRML2。OBJ,,,、,:2011-02-16:(1987-),,,,;,,。E-mail:eduf@cccc.net.cn,23992393ComputerKnowledgeandTechnology:710(20114)、。。obj[3]。OBJ[4]。OBJ(FileHeader),。OBJ,“#”,。(Keyword),。,(\)。(\)Tab,。OBJ。,,。(Vertexdata):v:(Geometricvertices)。。3,X、Y、Z。Vt:(Texturevertices)。。。U、V。Vn:(Vertexnormals)。。3,X、Y、Z。Vp:(Parameterspacevertices)。(Free-formcurve)/(surfaceattributes):Deg:(Degree)。Bmat:(Basismatrix)。Step:(Stepsize)。cstype(Curveorsurfacetype):(Elements):P:(Point)L:(Line)F:(Face)Curv:(Curve)curv22D:(2Dcurve)surf:(Surface)(Free-formcurve)/(surfacebodystatements):Parm:(Parametervalues)Trim:(Outertrimmingloop)Hole:(Innertrimmingloop)Scrv:(Specialcurve)sp:(Specialpoint)end:(Endstatement)(Connectivitybetweenfree-formsurfaces):Con:(Connect)(Grouping):G:(Groupname)S:(Smoothinggroup)Mg:(Merginggroup)O:(Objectname)(Display)/(renderattributes):Bevel:(Bevelinterpolation)c_interp:(Colorinterpolation)d_interp:(Dissolveinterpolation)lod:(Levelofdetail)usemtl:(Materialname)mtllib:(Materiallibrary)shadow_obj:(Shadowcasting)trace_obj:(Raytracing)ctech:(Curveapproximationtechnique)stech:(Surfaceapproximationtechnique)OBJ,,.mtl。mtllib[5]。(diffuse),(ambient),(specular)RGB(),(specularity),(refraction),(transparency)。usemtl,,usemtl。3.2OBJOBJ。OBJsquare.obj。2394ComputerKnowledgeandTechnology:710(20114)#square.objv0.0000002.0000000.000000v0.0000000.0000000.000000v2.0000000.0000000.000000v2.0000002.0000000.000000f12344v,f,。。#。#twosquare.objv0.0000002.0000000.000000v0.0000000.0000000.000000v2.0000000.0000000.000000v2.0000002.0000000.000000v4.0000000.000000-1.255298v4.0000002.000000-1.255298vn0.0000000.0000001.000000vn0.0000000.0000001.000000vn0.2765970.0000000.960986vn0.2765970.0000000.960986vn0.5316110.0000000.846988vn0.5316110.0000000.846988#6vertices#6normalsgalls1f1//12//23//34//4f4//43//35//56//6#2elementstwosqaure.obj:vn,ggroup,allgroup。facegroup,g。s,1groupall。1//1,1,1,,vt。2//2,3//3,4//4,[6]。3.3OBJOBJ,,。OBJ,、、。://typedefstruct_GLMnode{GLuintindex;GLbooleanaveraged;struct_GLMnode*next;}GLMnode;///*glmWeldVectors:eliminate(weld)vectorsthatarewithinan*epsilonofeachother.**vectors-arrayofGLfloat[3]'stobewelded*numvectors-numberofGLfloat[3]'sinvectors*epsilon-maximumdifferencebetweenvectors**/GLfloat*glmWeldVectors(GLfloat*vectors,GLuint*numvectors,GLfloatepsilon){GLfloat*copies;GLuintcopied;GLuinti,j;copies=(GLfloat*)malloc(sizeof(GLfloat)*3*(*numvectors+1));memcpy(copies,vectors,(sizeof(GLfloat)*3*(*numvectors+1)));copied=1;2395ComputerKnowledgeandTechnology:710(20114)for(i=1;i=*numvectors;i++){for(j=1;j=copied;j++){if(glmEqual(&vectors[3*i],&copies[3*j],epsilon)){gotoduplicate;}}/*mustnotbeanyduplicates--addtothecopiesarray*/copies[3*copied+0]=vectors[3*i+0];copies[3*copied+1]=vectors[3*i+1];copies[3*copied+2]=vectors[3*i+2];j=copied;/*passthisalongforbelow*/copied++;duplicate:/*setthefirstcomponentofthisvectortopointatthecorrectindexintothenewcopiesarray*/vectors[3*i+0]=(GLfloat)j;}*numvectors=copied-1;returncopies;}/*glmFindGroup:Findagroupinthemodel*/GLMgroup*glmFindGroup(GLMmodel*model,char*name){GLMgroup*group;assert(model);group=model-groups;while(group){if(!strcmp(name,group-name))break;group=group-next;}returngroup;},,。1OBJ,2。4OBJwindowsOpenGLglut。GLUTOpenGL,,。WindowsGLUT:1),5。2)“”“gl.h”,(VisualStudio2005,“VC\PlatformSDK\include\gl”)。glut.h。3)glut.libglut32.lib(VisualStudio2005,“VC\lib”)。4)glut.dllglut32.dllsystem32。(:C:\Windows\System32)。,,MayaOBJMaya[7],。MayaOpenGL,OpenGL、、、、,、、[8]。2。5MayaOpenGL,OpenGL,。,OpenGL,Maya.OBJ,,、。,,,,LOD,,。3DMAX,AutoCAD,OpenGL,、、、。(2399)1OBJ22396ComputerKnowledgeandTechnology:710(20114)(2396):[1],,,.OpenGL[M].:,1999.[2],.OpenGL[M].:,2001.[3]ShreinerD.OpenGL[M].5.:,2006.[4],.OpenGL[M].:,2000.[5]AngelE.OpenGL[M].2.:,2005.[6