00001 /* 00002 --------------------------------------------------------------------------- 00003 Direct3D AssimpRenderer by ponx 00004 --------------------------------------------------------------------------- 00005 00006 This code is heavily based on the "AssimpView" project of the Open Asset Import Library (ASSIMP). 00007 http://assimp.sourceforge.net 00008 00009 /* 00010 --------------------------------------------------------------------------- 00011 Open Asset Import Library (ASSIMP) 00012 --------------------------------------------------------------------------- 00013 00014 Copyright (c) 2006-2008, ASSIMP Development Team 00015 00016 All rights reserved. 00017 00018 Redistribution and use of this software in source and binary forms, 00019 with or without modification, are permitted provided that the following 00020 conditions are met: 00021 00022 * Redistributions of source code must retain the above 00023 copyright notice, this list of conditions and the 00024 following disclaimer. 00025 00026 * Redistributions in binary form must reproduce the above 00027 copyright notice, this list of conditions and the 00028 following disclaimer in the documentation and/or other 00029 materials provided with the distribution. 00030 00031 * Neither the name of the ASSIMP team, nor the names of its 00032 contributors may be used to endorse or promote products 00033 derived from this software without specific prior 00034 written permission of the ASSIMP Development Team. 00035 00036 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00037 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00038 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00039 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00040 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00043 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00044 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00045 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00046 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00047 --------------------------------------------------------------------------- 00048 */ 00049 00050 #pragma once 00051 00052 00053 #define AI_VIEW_ALPHA_SORT_DELTA 3 00054 00055 00056 namespace AssimpRendererD3d 00057 { 00058 class AssetHelper; 00059 class AssimpRenderer; 00060 00061 //------------------------------------------------------------------------------- 00062 /* Helper class tp render meshes 00063 */ 00064 //------------------------------------------------------------------------------- 00065 class CMeshRenderer 00066 { 00067 private: 00068 friend class AssimpRenderer; 00069 00070 // default constructor 00071 CMeshRenderer() 00072 : m_bRotationChanged(true), 00073 m_iFrameCount(AI_VIEW_ALPHA_SORT_DELTA-1) 00074 { 00075 // no other members to initialize 00076 } 00077 00078 public: 00079 00080 //------------------------------------------------------------------ 00081 // Singleton accessors 00082 static CMeshRenderer s_cInstance; 00083 inline static CMeshRenderer& Instance () 00084 { 00085 return s_cInstance; 00086 } 00087 00088 00089 //------------------------------------------------------------------ 00090 // Draw a mesh in the global mesh list using the current pipeline state 00091 // iIndex Index of the mesh to be drawn 00092 // 00093 // The function draws all faces in order, regardless of their distance 00094 int DrawUnsorted(const AssetHelper* g_pcAsset, unsigned int iIndex); 00095 00096 //------------------------------------------------------------------ 00097 // Draw a mesh in the global mesh list using the current pipeline state 00098 // iIndex Index of the mesh to be drawn 00099 // 00100 // The method sorts all vertices by their distance (back to front) 00101 // 00102 // mWorld World matrix for the node 00103 int DrawSorted(const AssetHelper* g_pcAsset, unsigned int iIndex, const aiMatrix4x4& mWorld); 00104 00105 00106 //------------------------------------------------------------------ 00107 // Indicate that the rotation of the object or the camera has 00108 // been changed, thus the alpha order tree must be updated 00109 inline void SetRotationChangedFlag() 00110 { 00111 this->m_bRotationChanged = true; 00112 } 00113 00114 //------------------------------------------------------------------ 00115 // Reset the state of the class 00116 // Called whenever a new asset is loaded 00117 inline void Reset() 00118 { 00119 this->m_bRotationChanged = true; 00120 this->m_iFrameCount = 2; 00121 } 00122 00123 //------------------------------------------------------------------ 00124 // Called at the beginning of the frame. Reset the state 00125 // of the instance 00126 inline void OnBeginFrame() 00127 { 00128 if (0 == this->m_iFrameCount) 00129 { 00130 this->m_bRotationChanged = false; 00131 } 00132 } 00133 00134 private: 00135 00136 // true if the rotation of the object or camera has changed 00137 // in the last frame. If there were no changes it should 00138 // not be necessary to update the alpha ordering tree 00139 bool m_bRotationChanged; 00140 00141 // only update the alpha order each AI_VIEW_ALPHA_SORT_DELTA frames 00142 unsigned int m_iFrameCount; 00143 }; 00144 00145 } // namespace