PixelLightAPI  .
MeshFile.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: MeshFile.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMESH_MESHFILE_H__
00024 #define __PLMESH_MESHFILE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/PLCore.h>
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLMesh {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    PL mesh file format (binary, Little-Endian)
00046 *
00047 *  @verbatim
00048   PixelLight mesh format description:
00049 
00050     MESHFILE
00051     |
00052     +--PLCore::uint32 nMagic
00053     |
00054     +--PLCore::uint32 nVersion
00055     |
00056     +--MATERIALS
00057     |  |
00058     |  +--PLCore::uint32 nMaterials
00059     |  |
00060     |  +--char szName[256][nMaterials]
00061     |
00062     +--MESH
00063     |  |
00064     |  +--PLCore::uint32 nLODLevels
00065     |  |
00066     |  +--PLCore::uint32 nMorphTargets
00067     |  |
00068     |  +--PLCore::uint32 nWeights
00069     |  |
00070     |  +--PLCore::uint32 nVertexWeights
00071     |  |
00072     |  +--LODLEVEL (*)
00073     |  |  |
00074     |  |  +--float fDistance
00075     |  |  |
00076     |  |  +--PLCore::uint32 nGeometries
00077     |  |  |
00078     |  |  +--PLCore::uint32 nOctreeSubdivide
00079     |  |  |
00080     |  |  +--PLCore::uint32 nOctreeMinGeometries
00081     |  |  |
00082     |  |  +--INDEXBUFFER
00083     |  |  |  |
00084     |  |  |  +--PLCore::uint32 nElementType
00085     |  |  |  |
00086     |  |  |  +--PLCore::uint32 nElements
00087     |  |  |  |
00088     |  |  |  +--PLCore::uint32 nSize;
00089     |  |  |  |
00090     |  |  |  +--... 'nElements' indices of type 'nElementType'
00091     |  |  |
00092     |  |  +--GEOMETRY (*)
00093     |  |  |  |
00094     |  |  |  +--char szName[64]
00095     |  |  |  |
00096     |  |  |  +--PLCore::uint32 nFlags
00097     |  |  |  |
00098     |  |  |  +--bool bActive
00099     |  |  |  |
00100     |  |  |  +--int nPrimitiveType
00101     |  |  |  |
00102     |  |  |  +--int nMaterial
00103     |  |  |  |
00104     |  |  |  +--int nStartIndex
00105     |  |  |  |
00106     |  |  |  +--int nIndexSize
00107     |  |  |
00108     |  |  +--... 'nGeometries' geometries
00109     |  |
00110     |  +--... 'nLODLevels' LOD levels
00111     |  |
00112     |  +--MORPHTARGET (*)
00113     |  |  |
00114     |  |  +--char szName
00115     |  |  |
00116     |  |  +--bool bRelative
00117     |  |  |
00118     |  |  +--PLCore::uint32 nVertexIDs
00119     |  |  |
00120     |  |  +--PLCore::uint32 nVertexBuffers
00121     |  |  |
00122     |  |  +--'nVertexIDs' vertex ID's
00123     |  |  |
00124     |  |  +--VERTEXBUFFER (*)
00125     |  |  |  |
00126     |  |  |  +--PLCore::uint32 nVertexAttributes
00127     |  |  |  |
00128     |  |  |  +--PLCore::uint32 nVertices
00129     |  |  |  |
00130     |  |  |  +--PLCore::uint32 nSize;
00131     |  |  |  |
00132     |  |  |  +--VERTEXATTRIBUTE (*)
00133     |  |  |  |  |
00134     |  |  |  |  +--int nSemantic;
00135     |  |  |  |  |
00136     |  |  |  |  +--int nChannel;
00137     |  |  |  |  |
00138     |  |  |  |  +--int nType;
00139     |  |  |  |
00140     |  |  |  +--... 'nVertexAttributes' vertex attributes
00141     |  |  |  |
00142     |  |  |  +--... 'nVertices' vertices, a vertex consists of 'nVertexAttributes' attributes
00143     |  |  |
00144     |  |  +--... 'nVertexBuffers' vertex buffers
00145     |  |
00146     |  +--... 'nMorphTargets' morph targets
00147     |  |
00148     |  +--WEIGHT (*)
00149     |  |  |
00150     |  |  +--int nJoint
00151     |  |  |
00152     |  |  +--float fBias
00153     |  |
00154     |  +--... 'nWeights' weights
00155     |  |
00156     |  +--VERTEXWEIGHTS (*)
00157     |  |  |
00158     |  |  +--PLCore::uint32 nWeights
00159     |  |  |
00160     |  |  +-- 'nWeights' weight indices for the vertex
00161     |  |
00162     |   +--... one vertex weight for each LOD level vertex
00163     |
00164     +--MORPHTARGETANIMATION (*)
00165     |  |
00166     |  +--char szName
00167     |  |
00168     |  +--PLCore::uint32 nMorphTargets
00169     |  |
00170     |  +--PLCore::uint32 nFrames
00171     |  |
00172     |  +--MORPHTARGETANIMATIONTARGET (*)
00173     |  |  |
00174     |  |  +-- char szName[64]
00175     |  |
00176     |  +--... 'nMorphTargets' animation morph targets
00177     |  |
00178     |  +--FRAMEKEYS (*)
00179     |  |  |
00180     |  |  +-- FRAMEKEY (*)
00181     |  |  |   |
00182     |  |  |   +-- float fKey
00183     |  |  |
00184     |  |  +--... for each animation morph target
00185     |  |
00186     |  +-... 'nFrames' frame keys
00187     |
00188     +--SKELETON
00189     |  |
00190     |  +--char szName
00191     |  |
00192     |  +--PLCore::uint32 nJoints
00193     |  |
00194     |  +--PLCore::uint32 nFrames
00195     |  |
00196     |  +--JOINT (*)
00197     |  |  |
00198     |  |  +-- char szName[64]
00199     |  |  |
00200     |  |  +-- int nParent
00201     |  |  |
00202     |  |  +-- PLCore::uint8 nAnimatedComponents
00203     |  |
00204     |  +--... 'nJoints' joints
00205     |  |
00206     |  +--BASEFRAME
00207     |  |  |
00208     |  |  +--JOINTSTATE (*)
00209     |  |  |  |
00210     |  |  |  +-- float fTranslation[3]
00211     |  |  |  |
00212     |  |  |  +-- float fRotation[4]
00213     |  |  |  |
00214     |  |  |  +-- float fTranslationJointSpace[3]
00215     |  |  |  |
00216     |  |  |  +-- float fRotationJointSpace[4]
00217     |  |  |
00218     |  |  +--... 'nJoints' joint states
00219     |  |
00220     |  +--FRAMEKEYS (*)
00221     |  |  |
00222     |  |  +-- FRAMEKEY (*)
00223     |  |  |   |
00224     |  |  |   +-- float fKey
00225     |  |  |
00226     |  |  +--... for each animated component
00227     |  |
00228     |  +-... 'nFrames' frame keys
00229     |
00230     +--ANCHORPOINTS
00231     |  |
00232     |  +--PLCore::uint32 nAnchorPoints
00233     |  |
00234     |  +--ANCHORPOINT (*)
00235     |  |  |
00236     |  |  +-- char szName[64]
00237     |  |  |
00238     |  |  +-- bool bType
00239     |  |  |
00240     |  |  +-- int nID
00241     |  |
00242     |  +--... 'nAnchorPoints' anchor points
00243     |
00244     +--ANIMATIONS
00245     |  |
00246     |  +--PLCore::uint32 nAnimations
00247     |  |
00248     |  +--ANIMATION (*)
00249     |  |  |
00250     |  |  +--char szName[64]
00251     |  |  |
00252     |  |  +--int nType
00253     |  |  |
00254     |  |  +--int nStart
00255     |  |  |
00256     |  |  +--int nEnd
00257     |  |  |
00258     |  |  +--float fSpeed
00259     |  |  |
00260     |  |  +--PLCore::uint32 nFlags
00261     |  |  |
00262     |  |  +--int nEvents
00263     |  |  |
00264     |  |  +--ANIMATION_FRAMES
00265     |  |  |  |
00266     |  |  |  +--ANIMATION_FRAME (*)
00267     |  |  |  |  |
00268     |  |  |  |  +--float fSpeed
00269     |  |  |  |
00270     |  |  |  +--... |nEnd-nStart| animation frames
00271     |  |  |
00272     |  |  +--ANIMATION_EVENTS
00273     |  |     |
00274     |  |     +--ANIMATION_EVENT (*)
00275     |  |     |  |
00276     |  |     |  +--int nID
00277     |  |     |  |
00278     |  |     |  +--int nFrame
00279     |  |     |
00280     |  |     +--... 'nEvents' animation events
00281     |  |
00282     |  +--MESHBOUNDINGBOX (*)
00283     |  |  |
00284     |  |  +--float fMin[3]
00285     |  |  |
00286     |  |  +--float fMax[3]
00287     |  |
00288     |  +--...
00289     |
00290    @endverbatim
00291 */
00292 class MeshFile {
00293 
00294 
00295     //[-------------------------------------------------------]
00296     //[ Constants                                             ]
00297     //[-------------------------------------------------------]
00298     public:
00299         // Format definition
00300         static const PLCore::uint32 MAGIC                       = 0x57754631;
00301         static const PLCore::uint32 VERSION                     = 2;
00302 
00303         // Chunk types (0x0-------)
00304         static const PLCore::uint32 CHUNK_MESHFILE              = 0x00000001;
00305         static const PLCore::uint32 CHUNK_MATERIALS             = 0x00000010;
00306         static const PLCore::uint32 CHUNK_MESH                  = 0x00000011;
00307         static const PLCore::uint32 CHUNK_LODLEVEL              = 0x00000012;
00308         static const PLCore::uint32 CHUNK_INDEXBUFFER           = 0x00000013;
00309         static const PLCore::uint32 CHUNK_GEOMETRY              = 0x00000014;
00310         static const PLCore::uint32 CHUNK_MORPHTARGET           = 0x00000015;
00311         static const PLCore::uint32 CHUNK_VERTEXBUFFER          = 0x00000016;
00312         static const PLCore::uint32 CHUNK_VERTEXATTRIBUTE       = 0x00000017;
00313         static const PLCore::uint32 CHUNK_WEIGHT                = 0x00000018;
00314         static const PLCore::uint32 CHUNK_VERTEXWEIGHTS         = 0x00000019;
00315         static const PLCore::uint32 CHUNK_SKELETON              = 0x00000020;
00316         static const PLCore::uint32 CHUNK_SKELETONANIMATION     = 0x00000021;
00317         static const PLCore::uint32 CHUNK_ANCHORPOINTS          = 0x00000022;
00318         static const PLCore::uint32 CHUNK_ANIMATIONS            = 0x00000023;
00319         static const PLCore::uint32 CHUNK_MORPHTARGETANIMATION  = 0x00000024;
00320         static const PLCore::uint32 CHUNK_MESHBOUNDINGBOX       = 0x00000025;
00321 
00322         // Experimental chunks (0xA-------)
00323 
00324         // Unimplemented chunks (0xE-------)
00325 
00326         // Obsolete chunks (0xF-------)
00327 
00328 
00329     //[-------------------------------------------------------]
00330     //[ File format structures                                ]
00331     //[-------------------------------------------------------]
00332     public:
00333         /** 
00334         *  @brief
00335         *    Chunk header
00336         */
00337         struct Chunk {
00338             PLCore::uint32 nType;   /**< Chunk type (e.g. CHUNK_MESHFILE) */
00339             PLCore::uint32 nSize;   /**< Chunk size in bytes (including the 8 bytes for the chunk header) */
00340         };
00341 
00342         /** 
00343         *  @brief
00344         *    Main file header
00345         */
00346         struct MeshFileHeader {
00347             PLCore::uint32 nMagic;      /**< MeshFile ID "" (see MAGIC above) */
00348             PLCore::uint32 nVersion;    /**< MeshFile Version (see VERSION above) */
00349         };
00350 
00351         /** 
00352         *  @brief
00353         *    Material list
00354         */
00355         struct Materials {
00356             PLCore::uint32 nMaterials;  /**< Number of materials */
00357         };
00358 
00359         /** 
00360         *  @brief
00361         *    Mesh
00362         */
00363         struct Mesh {
00364             PLCore::uint32 nLODLevels;      /**< Number of LOD levels */
00365             PLCore::uint32 nMorphTargets;   /**< Number of morph targets */
00366             PLCore::uint32 nWeights;        /**< Total number of weights */
00367             PLCore::uint32 nVertexWeights;  /**< Number of vertices with weights */
00368         };
00369 
00370         /** 
00371         *  @brief
00372         *    Bounding box
00373         */
00374         struct BoundingBox {
00375             float fMin[3];  /**< Minimum bounding box position */
00376             float fMax[3];  /**< Maximum bounding box position */
00377         };
00378 
00379         /** 
00380         *  @brief
00381         *    Weight
00382         */
00383         struct Weight {
00384             int   nJoint;   /**< Joint this weight is for */
00385             float fBias;    /**< Bias factor */
00386         };
00387 
00388         /** 
00389         *  @brief
00390         *    Vertex weights
00391         */
00392         struct VertexWeights {
00393             PLCore::uint32 nWeights;    /**< Number of weights for the vertex */
00394         };
00395 
00396         /** 
00397         *  @brief
00398         *    LOD level
00399         */
00400         struct LODLevel {
00401             float          fDistance;               /**< Distance this LOD level is used */
00402             PLCore::uint32 nGeometries;             /**< Number of geometries */
00403             PLCore::uint32 nOctreeSubdivide;        /**< Octree subdivide */
00404             PLCore::uint32 nOctreeMinGeometries;    /**< Minimum number of geometries per octree */
00405         };
00406 
00407         /** 
00408         *  @brief
00409         *    Index buffer
00410         */
00411         struct IndexBuffer {
00412             PLCore::uint32 nElementType;    /**< Index element type (see IndexBuffer::EType) */
00413             PLCore::uint32 nElements;       /**< Number of indices */
00414             PLCore::uint32 nSize;           /**< Total index buffer size in bytes */
00415         };
00416 
00417         /** 
00418         *  @brief
00419         *    Geometry object
00420         */
00421         struct Geometry {
00422             char           szName[64];      /**< Optional geometry name */
00423             PLCore::uint32 nFlags;          /**< Optional geometry flags */
00424             bool           bActive;         /**< Is the geometry active/inactive? */
00425             int            nPrimitiveType;  /**< Geometry primitive type (see PLRenderer::Primitive) */
00426             int            nMaterial;       /**< ID of the material the geometry is using */
00427             int            nStartIndex;     /**< First geometry index within the index buffer */
00428             int            nIndexSize;      /**< Number of indices */
00429         };
00430 
00431         /** 
00432         *  @brief
00433         *    Morph target
00434         */
00435         struct MorphTarget {
00436             char           szName[64];      /**< Name of the morph target */
00437             bool           bRelative;       /**< Is this morph target relative to the basis morph target? */
00438             PLCore::uint32 nVertexIDs;      /**< Number of vertex ID's, if 0 ALL vertices are influenced */
00439             PLCore::uint32 nVertexBuffers;  /**< Number of vertex buffers (one VB per LOD level) */
00440         };
00441 
00442         /** 
00443         *  @brief
00444         *    Vertex buffer
00445         */
00446         struct VertexBuffer {
00447             PLCore::uint32 nVertexAttributes;   /**< Number of vertex attributes */
00448             PLCore::uint32 nVertices;           /**< Number of vertices */
00449             PLCore::uint32 nSize;               /**< Total vertex buffer size in bytes */
00450         };
00451 
00452         /** 
00453         *  @brief
00454         *    Vertex attribute of a vertex buffer
00455         */
00456         struct VertexAttribute {
00457             int nSemantic;  /**< Semantic of the vertex attribute (see VertexBuffer::ESemantic) */
00458             int nChannel;   /**< Vertex attribute pipeline channel (primary color, secondary color,
00459                                  first texture unit, second texture unit etc.) */
00460             int nType;      /**< Vertex attribute type (see VertexBuffer::EType) */
00461         };
00462 
00463         /** 
00464         *  @brief
00465         *    Morph target animation
00466         */
00467         struct MorphTargetAnimation {
00468             char           szName[64];      /**< Name of the morph target animation */
00469             PLCore::uint32 nMorphTargets;   /**< Number of morph targets */
00470             PLCore::uint32 nFrames;         /**< Number of morph target animation frames */
00471         };
00472 
00473         /** 
00474         *  @brief
00475         *    Skeleton
00476         */
00477         struct Skeleton {
00478             char           szName[64];  /**< Name of the skeleton (animation) */
00479             PLCore::uint32 nJoints;     /**< Number of joints the skeleton consists of */
00480             PLCore::uint32 nFrames;     /**< Number of skeleton animation frames */
00481         };
00482 
00483         /** 
00484         *  @brief
00485         *    Joint
00486         */
00487         struct Joint {
00488             char          szName[64];           /**< Unique joint name */
00489             int           nParent;              /**< Number of the parent joint, < 0 if no parent */
00490             PLCore::uint8 nAnimatedComponents;  /**< X, Y, Z, Yaw, Pitch, Roll, W */
00491         };
00492 
00493         /** 
00494         *  @brief
00495         *    Joint state
00496         */
00497         struct JointState {
00498             float fTranslation[3];              /**< Joint x/y/z translation, relative if the joint has a parent */
00499             float fRotation[4];                 /**< Joint w/x/y/z rotation quaternion, relative if the joint has a parent */
00500             float fTranslationJointSpace[3];    /**< Joint x/y/z translation in joint space */
00501             float fRotationJointSpace[4];       /**< Joint w/x/y/z rotation quaternion in joint space */
00502         };
00503 
00504         /** 
00505         *  @brief
00506         *    Anchor points list
00507         */
00508         struct AnchorPoints {
00509             PLCore::uint32 nAnchorPoints;   /**< Number of anchor points */
00510         };
00511 
00512         /** 
00513         *  @brief
00514         *    Anchor point
00515         */
00516         struct AnchorPoint {
00517             char szName[64];    /**< Unique anchor point name */
00518             bool bType;         /**< Anchor point type (0=vertex  1=joint) */
00519             int  nID;           /**< Vertex/bone ID the anchor is attached to */
00520         };
00521 
00522         /** 
00523         *  @brief
00524         *    Animations list
00525         */
00526         struct Animations {
00527             PLCore::uint32 nAnimations; /**< Number of animations */
00528         };
00529 
00530         /** 
00531         *  @brief
00532         *    Animation
00533         */
00534         struct Animation {
00535             char              szName[64];   /**< Unique animation name */
00536             int               nType;        /**< Animation type (0=vertex  1=skeleton) */
00537             int               nStart;       /**< Start frame of the animation (inclusive) */
00538             int               nEnd;         /**< End frame of the animation (inclusive) */
00539             float             fSpeed;       /**< Playback speed (1.0 = normal) */
00540             PLCore::uint32 nFlags;      /**< Animation information flags */
00541             int               nEvents;      /**< Number of animation events */
00542         };
00543 
00544         /** 
00545         *  @brief
00546         *    Animation frame
00547         */
00548         struct AnimationFrame {
00549             float m_fSpeed; /**< Frame speed (1.0 = normal) */
00550         };
00551 
00552         /** 
00553         *  @brief
00554         *    Animation event
00555         */
00556         struct AnimationEvent {
00557             int m_nID;      /**< Event ID */
00558             int m_nFrame;   /**< Frame causing this event */
00559         };
00560 
00561 
00562 };
00563 
00564 
00565 //[-------------------------------------------------------]
00566 //[ Namespace                                             ]
00567 //[-------------------------------------------------------]
00568 } // PLMesh
00569 
00570 
00571 #endif // __PLMESH_MESHFILE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:57
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported