Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/3dsmaxExport/LEXIExporter/LexiExport/Sources/LexiExportObjectPoseAnim.cpp @ 6

Last change on this file since 6 was 6, checked in by anonymous, 17 years ago

=…

File size: 6.8 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Mark Folkenberg,
9Bo Krohn
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GNU Lesser General Public License as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/copyleft/lesser.txt.
24-----------------------------------------------------------------------------
25*/
26
27#include "LexiStdAfx.h"
28#include "LexiDialogPoseProperties.h"
29#include "LexiExportObjectPoseAnim.h"
30#include "LexiOgreMeshCompiler.h"
31#include "LexiOgreMaterialCompiler.h"
32#include "LexiIntermediateBuilder.h"
33#include "LexiIntermediateMesh.h"
34
35#include <dbghelp.h>
36#pragma comment(lib,"Dbghelp.lib")
37//
38
39CPosePropertiesDlg *CPoseAnimExportObject::m_pEditDlg=NULL;
40CDDObject* CPoseAnimExportObject::m_pDDMetaDesc=NULL;
41
42CPoseAnimExportObject::CPoseAnimExportObject(CDDObject *pConfig) : CExportObject(pConfig)
43{
44}
45
46CPoseAnimExportObject::~CPoseAnimExportObject()
47{
48}
49
50// Get window for editing ExportObject properties
51GDI::Window* CPoseAnimExportObject::GetEditWindow(GDI::Window *pParent)
52{
53        if(m_pEditDlg==NULL)
54        {
55                m_pEditDlg=new CPosePropertiesDlg(pParent);
56                m_pEditDlg->Create();
57                m_pDDMetaDesc=BuildMetaDesc();
58                m_pEditDlg->Init(m_pDDMetaDesc, ".mesh");       
59        }
60
61        m_pEditDlg->SetInstance(m_pDDConfig, this);
62        return m_pEditDlg;
63}
64
65// End edit
66void CPoseAnimExportObject::CloseEditWindow()
67{
68        if(m_pEditDlg!=NULL)
69        {
70                //LOGDEBUG "Window Ended:\t%i (handle)", m_pEditDlg->m_hWnd);
71                m_pEditDlg->EndDialog(0);
72                delete m_pEditDlg;
73                m_pEditDlg=NULL;
74                if(m_pDDMetaDesc)
75                {
76                        m_pDDMetaDesc->Release();
77                        m_pDDMetaDesc=NULL;
78                }
79        }
80}
81
82// Called when object is first created [by user].
83// This allows for wizard-style editing of required data
84// If this function returns false, the object is not created
85bool CPoseAnimExportObject::OnCreate(CExporterPropertiesDlg *pPropDialog)
86{
87        CExportObject *pParent=GetParent();
88        if(pParent==NULL) return false;
89        std::string sName=pParent->GetName();
90        sName+=" Animation";
91        m_pDDConfig->SetString("Name", sName.c_str());
92        return true;
93}
94
95// Check if ExportObject supports a given ExportObject instance as parent
96bool CPoseAnimExportObject::SupportsParentType(const CExportObject *pParent) const
97{       
98        const IExportObjectMeshSupport* pMeshSupport;
99        try {
100                pMeshSupport = dynamic_cast<const IExportObjectMeshSupport*>(pParent);
101                if(pMeshSupport == NULL)
102                        return false;
103        } catch (...) 
104        {
105          LOGERROR "Error while attempting to check compatible parent type. Parent must atleast support a mesh type.");
106        }
107
108        return true;
109}
110
111//
112CDDObject* CPoseAnimExportObject::BuildMetaDesc( void )
113{
114        int iStartFrame = GetAnimStart()/GetTicksPerFrame();
115        int iEndFrame = GetAnimEnd()/GetTicksPerFrame();
116
117        CDDObject* AnimContainer = new CDDObject();
118
119        fastvector< const CDDObject* > lAnimSettings;
120        CDDObject* pDDAnimElement;
121
122        // --- General Animation ---
123
124        pDDAnimElement = new CDDObject();
125        pDDAnimElement->SetString("ID","AnimationOptimizeID");
126        pDDAnimElement->SetString("Type","Bool");
127        pDDAnimElement->SetString("Group","Animation");
128        pDDAnimElement->SetString("Caption","Optimize");
129        pDDAnimElement->SetString("Help","Reduces the amount of KeyFrames by removing redundant data.");
130        pDDAnimElement->SetBool("Default", true);
131        lAnimSettings.push_back(pDDAnimElement);
132
133        // --- Bone Animation ---
134
135        pDDAnimElement = new CDDObject();
136        pDDAnimElement->SetString("ID","AnimationStartID");
137        pDDAnimElement->SetString("Type","Int");
138        pDDAnimElement->SetBool("EnableSlider", false);
139        pDDAnimElement->SetString("Group","Bone");
140        pDDAnimElement->SetString("Caption","Start Frame");
141        pDDAnimElement->SetString("Help","Frame which the animation begins");
142        pDDAnimElement->SetInt("Default", iStartFrame);
143        lAnimSettings.push_back(pDDAnimElement);
144
145        pDDAnimElement = new CDDObject();
146        pDDAnimElement->SetString("ID","AnimationEndID");
147        pDDAnimElement->SetString("Type","Int");
148        pDDAnimElement->SetBool("EnableSlider", false);
149        pDDAnimElement->SetString("Group","Bone");
150        pDDAnimElement->SetString("Caption","End Frame");
151        pDDAnimElement->SetString("Help","Frame which the animation stops");
152        pDDAnimElement->SetInt("Default", iEndFrame);
153        lAnimSettings.push_back(pDDAnimElement);
154
155        pDDAnimElement = new CDDObject();
156        pDDAnimElement->SetString("ID","AnimationSampleRateID");
157        pDDAnimElement->SetString("Type","Float");
158        pDDAnimElement->SetBool("EnableSlider", false);
159        pDDAnimElement->SetString("Group","Bone");
160        pDDAnimElement->SetString("Caption","Samplerate");
161        pDDAnimElement->SetString("Help","Rate at which samples should be done. e.g 2 yields every second frame in max.");
162        pDDAnimElement->SetFloat("Default", 1.0);
163        lAnimSettings.push_back(pDDAnimElement);
164
165        AnimContainer->SetDDList("MetaList", lAnimSettings, false);
166        return AnimContainer;
167}
168
169bool CPoseAnimExportObject::Export(CExportProgressDlg *pProgressDlg, bool bForceAll)
170{       
171
172        if(m_bEnabled || bForceAll)
173        {
174                // Do pose animation export
175
176                CExportObject *pBaseParent = GetParent();
177                IExportObjectMeshSupport* pParent;
178                try {
179                        pParent = dynamic_cast<IExportObjectMeshSupport*>(pBaseParent);
180                        if(pParent == NULL)
181                                return false;
182                } catch (...) 
183                {
184                  LOGERROR "Error while attempting to check compatible parent type. Parent must atleast support a mesh type.");
185                }
186
187                CIntermediateMesh* pIMesh = pParent->GetIntermediateMesh();
188
189                if(pIMesh->IsCollapsed())
190                {
191                        LOGERROR "Cannot create pose data for collapsed Meshes. Pose Ignored");
192                        return false;
193                }
194
195                //// Check vertex count before adding pose description to Intermediate Mesh
196                //CMeshArray* lVerts = pIMesh->GetArray("position", 0);
197                //int iOrigVertCount = lVerts->Size();
198
199                int iStartFrame = m_pDDConfig->GetInt("AnimationStartID",0);
200                int iEndFrame = m_pDDConfig->GetInt("AnimationEndID",0);
201                float fRate = m_pDDConfig->GetFloat("AnimationSampleRateID",1.0f);
202
203                faststring sPoseAnimName = m_pDDConfig->GetString("Name");
204                bool bOptimize = m_pDDConfig->GetBool("OptimizeID",true);
205
206
207                //lVerts = pIMesh->GetArray("position",iFrame);
208                //int iPoseVertCount = lVerts->Size();
209                //if(iPoseVertCount != iOrigVertCount)
210                //{
211                //      LOGERROR "Pose(%s) does not contain same amount of verticies as base mesh. Pose Ignored", sPoseAnimName.c_str() );
212                //      return false;
213                //}
214
215                pIMesh->AddPoseAnimation(sPoseAnimName.c_str(), iStartFrame, iEndFrame, fRate, bOptimize);
216
217        }
218
219        return CExportObject::Export(pProgressDlg, bForceAll); 
220}
Note: See TracBrowser for help on using the repository browser.