3DS MAX EXPORTER ------ Mesh

xiaoxiao2021-03-06  36

Prepare:. 1 3D Studio MAX Plugin AppWizard can be found in the directory / 3dsmax5 / maxsdk / Help / SDKAPWZ2 Copy SDKAPWZ.awx file into Visual Studio directory, eg C:. / Program Files / Microsoft Visual Studio / Common / MSDev98 / Bin / IDE3. Run Visual C and click new. The appwizard will appear in the list of options.click "File Export", type exporter in the Plugin category, find the paths that you want to use and then the appwizard creates the skeleton code. Plug-in Requirements: int ExtCount (): Returns the number of file extensions that the exporter provides (for our example, we provide 1) const TCHAR Ext (int n): Returns the 3-letter file extension string for the given extension index (0-based) .const TCHAR longDesc (): Provides the long description of the file export format.const TCHAR ShortDesc (): Provides the short description of the file export format, shown in the file export dialog drop-down.const TCHAR Authorname (): provides the string That Describes the Author and / or Company of the export er plugin.const TCHAR CopyrightMessage (): Provides the string that shows the copyright for the given exporter and / or exporter format.const TCHAR OtherMessage1 (): not usedconst TCHAR OtherMessage2 (): not usedunsigned int Version (): Somewhat redundant, but returns a version number for the exporter.void ShowAbout (): Shows an about box, accessible by the user from the main MAX export dialog.int DoExport (): The actual export method BOOL SupportsOptions ():. Returns TRUE if the exporter supports . some custom export options Currently, only one option (export selected versus export entire scene) exists.Export Functions: // test if is a mesh nodeBOOL IsMesh (INode * pNode) {if (pNode == NULL) return FALSE;

if {ObjectState obs = pNode-> EvalWorldState (0) (pNode-> IsRootNode ()!); if (obs.obj) {// GEOMOBJECT_CLASS_ID is include EDITTRIOBJ_CLASS_ID // EDITTRIOBJ_CLASS_ID is EditMesh type id //if(obs.obj- > SuperClassID () == GEOMOBJECT_CLASS_ID) if (obs.obj-> ClassID () == class_ID (EDITTRIOBJ_CLASS_ID, 0)) return TRUE;}} return FALSE;} // test if is a bone or biped controllerBOOL IsBone (INode * Pnode) {if (pnode == null) Return False; ObjectState Obs = pnode-> evAlworldState (0); if (obs.obj == null) Return False; if (obs.obj-> classid () == bone_obj_classid) // bone class id return true; if (obs.obj-> classid () == class_id (bone_class_id, 0)) // include with helper return true; if (obs.obj-> classid () == Class_ID (Dummy_Class_ID) , 0) // include with helper return false; control * ctrl = pnode-> gettmcontroller (); if (ctrl-> classid () == bipslave_control_class_id || // Others Biped Parts Ctrl-> ClassID () == BIPBODY_CONTROL_CLASS_ID // biped root) return TRUE; return FALSE;} // Export meshBOOL ExportMesh (INode * pNode, FILE * out) {if ((pNode!) ||) return FALSE (IsMesh (pNode)!); Mesh_hdr meshHdr; MEMSET (& meshhdr, 0, sizeof (mesh_hdr)); Matrix3 TM = pnode-> getObjectTM (0); ObjectState OS = PNode-> EvalWorldState (0); if (os.obj) {Object * Obj = os.obj; if (obj && obj-> CanConvertToType (class_ID (TRIOBJ_CLASS_ID, 0))) {TriObject * tri = NULL; tri = (TriObject *) obj-> ConvertToType (0, class_ID (TRIOBJ_CLASS_ID, 0)); if (tri) {Mesh Mesh = tri->

GetMesh (); long startpos = ftell (out); fseek (out, sizeof (mesh_hdr), seek_cur); Mesh.BuildBoundingBox (); box3 b = Mesh.getBoundingBox (); ...... Meshhdr.Vertcnt = Mesh .getnumverts (); meshhdr.vertofs = ftell (out); for (int i = 0; i 0) {meshHdr.textureCnt = meshHdr.vertCnt; tp = new Texture_hdr [meshHdr.textureCnt]; memset (tp, 0, sizeof (Texture_hdr) * Meshhdr.texturecnt);} Meshhdr.facecnt = Mesh.GetNumface (); Meshdr.faceOfs = ftell (out); For (i = 0; i

} MeshHdr.textureOfS = ftell (out); if (tp) {fwrite (tp, sizeof (Texture_hdr), meshHdr.textureCnt, out);} // all texture vert is follow: / * meshHdr.textureCnt = mesh.getNumTVerts ( ); Meshhdr.textureofs = ftell (out); for (i = 0; i Getmtl (); // Just Only One or Zero if (MTL) {if (MTL-> ClassID () == Class_ID (DMTL_CLASS_ID, 0)) // Standard Material {stdmat * std = (stdmat *) MTL; IF std) {Material_hdr mHdr; Color tmpCl; memset (& mHdr, 0, sizeof (Material_hdr)); long mtlStart = ftell (out); fseek (out, sizeof (Material_hdr), SEEK_CUR); meshHdr.materialCnt = 1; tmpCl = std -> GetAmbient (0); ............. TMPC L = std-> getdiffuse (0); ........... TMPCL = std-> getSpecular (0); ............. MhDr.Shininess = STD-> getshininess (0); MHDR.OPACITY = STD-> getopacity (0);

TEXMAP * TMAP = std-> getSubtexmap (ID_DI); // Diffuce Channel if (TMAP) {IF (TMTEX_CLASS_ID, 0)) {BitmapTex * BMT = (Bitmaptex *) TMAP; / / bitmap inform ...............}} long mtlend = ftell (out); fseek (out, mtlstart, seek_set); FWRITE (& MHDR, SIZEOF (Material_HDR), 1, OUT FSeek (out, mtlend, seek_set);}} else if (mtl-> classid () == class_id (multi_class_id, 0)) {matial_hdr pmhdr; long pmtlstart = ftell (out); fseek (out, sizeof (matial_hdr) , Seek_cur); PMHDr.SUBCNT = MTL-> NumSubmtls (); pmHDr.SUBOFS = FTELL (OUT); for (int J = 0; j getSubmtl (j ); ........................}}} long endpos = ftell (out); fseek (out, startpos, seek_set); fwrite & meshhdr, SizeOf (Mesh_HDR), 1, OUT; FSEEK (OUT, ENDPOS, SEEK_SET); for (int N = 0; n number Ofchildren (); n ) {exportmesh (pnode-> getchildnode (n), pcnt, out, fp);}}}} Return True;} //}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} Return True;} //} NULLVIEW: PUBLIC View {public: Point2 ViewToscreen (POINT3 P) {Return Point2 (PX, PY);} nullview () {WorldToview.IdentityMatrix (); screenw = 800.0f; screenh = 600.0f;}

}

Static Nullview Nullview; Int Needdelete; Mesh & Mesh = * ((Geomobject *) Os.obj) -> GetRendermesh (0, PNode, Nullview, Needdelete);

转载请注明原文地址:https://www.9cbs.com/read-61877.html

New Post(0)