// (from ximosoft rolaboratory) // RSM : Resource Model File // Model 3D of an object // // Resource Model File, this file contains a model with textures and polygons. -------------------------------------------------------------------------------- // Model // Versions: // 1.1 - base version // 1.2 - color added to texture vertices; smoothGroup added to faces // 1.3 - flag added to volume boxes // 1.4 - alpha added to header // 1.5 - position animation for each node instead of global(?) [ Header ] Field Size Comment ----- ---- ------- magic 4 "GRSM" (0x47 0x52 0x53 0x4D) majorVer 1 (uchar) major version minorVer 1 (uchar) minor version animLen 4 (int) shadeType 4 (int) { >= v1.4 Field Size Comment ----- ---- ------- alpha 1 (uchar) alpha of the model? (default 0xff) } reserved 16 ??? (ignored) numTexture 4 (int) number of textures { * numTexture Field Size Comment ----- ---- ------- texture 40 (char[40]) filepath of a texture } mainNode 40 (char[40]) name of the main node numNodes 4 (int) number of nodes { * numNodes [ Node ] Field Size Comment ----- ---- ------- name 40 (char[40]) name of the node parentname 40 (char[40]) name of the parent node numTexture 4 (int) number of textures used by this node { * numTexture Field Size Comment ----- ---- ------- index 4 (int) index of the texture } offsetMT 48 (matrix) 4x4 matrix that identifies the axis and origin of this node, see http://www.gamedev.net/reference/articles/article695.asp pos 12 (float[3]) translation of the node rotangle 4 (float) angle of rotation around the axis in radians rotaxis 12 (float[3]) axis of rotation scale 12 (float[3]) scale of the node numVert 4 (int) number of vertices { * numVert Field Size Comment ----- ---- ------- vert 12 (vector3d) vertice/point coordinate } numTVert 4 (int) number of texture vertices { * numTVert { >= v1.2 Field Size Comment ----- ---- ------- tvert 12 (tvertex3d) texture vertices } { < v1.2 Field Size Comment ----- ---- ------- tvert 8 (texCoor) texture vertices (color=0xFFFFFFFF) } } numFace 4 (int) number of faces { * numFace { >= v1.2 [ Face ] Field Size Comment ----- ---- ------- vertindex 12 (ushort[3]) vertice indexes (for the triangle sides) tvertindex 12 (ushort[3]) texture vertice indexes (for the triangle sides) meshMtlId 2 (ushort) target texture index (padding) 2 (padding) twoSide 4 (int) smoothGroup 4 (int) (default 0) } { < v1.2 [ Face ] Field Size Comment ----- ---- ------- vertindex 12 (ushort[3]) vertice indexes (for the triangle sides) tvertindex 12 (ushort[3]) texture vertice indexes (for the triangle sides) meshMtlId 2 (ushort) target texture index (padding) 2 (padding) twoSide 4 (int) } } { >= v1.5 [ Position Animation ] Field Size Comment ----- ---- ------- numPosKeyframe 4 (int) number of position key frames { * numPosKeyframe [ posKeyframe ] Field Size Comment ----- ---- ------- frame 4 (int) px 4 (float) py 4 (float) pz 4 (float) } } [ Rotation Animation ] Field Size Comment ----- ---- ------- numRotKeyframe 4 (int) number of rotation key frames { * numRotKeyframe [ rotKeyframe ] Field Size Comment ----- ---- ------- frame 4 (int) qx 4 (float) qy 4 (float) qz 4 (float) qw 4 (float) } } { < v1.5 [ Position Animation ] (global? data is put in the main node) Field Size Comment ----- ---- ------- numPosKeyframe 4 (int) number of position key frames { * numPosKeyframe [ posKeyframe ] Field Size Comment ----- ---- ------- frame 4 (int) px 4 (float) py 4 (float) pz 4 (float) } } numVol 4 (int) number of volume boxes { * numVol { >= v1.3 [ VolumeBox ] Field Size Comment ----- ---- ------- size 12 (vector3d) pos 12 (vector3d) rot 12 (vector3d) flag 4 (int) (default 0) // if( flag != 0 ) size += vector3d(3,0,3); } { < v1.3 [ VolumeBox ] Field Size Comment ----- ---- ------- size 12 (vector3d) pos 12 (vector3d) rot 12 (vector3d) } } // ------------------------------------------------------------------ // ------------------------------------------------------------------ // ------------------------------------------------------------------ // client can handle smoothGroup [0,32[ struct matrix {float v11,v12,v13,v21,v22,v23,v31,v32,v33,v41,v42,v43;} struct vector3d {float x,y,z;} struct tvertex3d {ulong color; float u,v;} struct texCoor {float u,v;} Shading: 0 - no shading 1 - flat shading 2 - smooth shading 3 - black // calculating face normals: for i = [0,numFaces[ vertindex = face[i].vertindex; faceNormal[i].x = (vert[vertindex[2]].y - vert[vertindex[1]].y) * (vert[vertindex[2]].z - vert[vertindex[0]].z) - (vert[vertindex[2]].z - vert[vertindex[1]].z) * (vert[vertindex[2]].y - vert[vertindex[0]].y); faceNormal[i].y = (vert[vertindex[2]].z - vert[vertindex[1]].z) * (vert[vertindex[2]].x - vert[vertindex[0]].x) - (vert[vertindex[2]].z - vert[vertindex[0]].z) * (vert[vertindex[2]].x - vert[vertindex[1]].x); faceNormal[i].z = (vert[vertindex[2]].y - vert[vertindex[0]].y) * (vert[vertindex[2]].x - vert[vertindex[1]].x) - (vert[vertindex[2]].y - vert[vertindex[1]].y) * (vert[vertindex[2]].x - vert[vertindex[0]].x); faceNormal[i] = faceNormal[i] * 1.0 / sqrt(faceNormal[i].x * faceNormal[i].x + faceNormal[i].y * faceNormal[i].y + faceNormal[i].z * faceNormal[i].z); // calculating vector normals: vector shadeGroup[32]; for f = [0,numFace[ shadeGroup[face[f].smoothGroup].push_back(f); tmp = new vector3d[numVert] for g = [0,32[ for v = [0,numVert[ tmp[v] = vector3d(0,0,0); for f = [0,numFace[ if( face[f].smoothGroup != g ) continue; if( face[f].vertindex[0] == v || face[f].vertindex[1] == v || face[f].vertindex[2] == v ) tmp[v] += faceNormal[f]; if( sqrt(tmp[v].x * tmp[v].x + tmp[v].y * tmp[v].y + tmp[v].z * tmp[v].z) != 0.0 ) tmp[v] = tmp[v] * 1.0 / sqrt(tmp[v].x * tmp[v].x + tmp[v].y * tmp[v].y + tmp[v].z * tmp[v].z); for f in shadeGroup[g] vertindex = face[f].vertindex; vectorNormal[f*3+0] = tmp[vertindex[0]]; vectorNormal[f*3+1] = tmp[vertindex[1]]; vectorNormal[f*3+2] = tmp[vertindex[2]]; delete tmp