-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathOgreMeshWriter.h
114 lines (86 loc) · 5.64 KB
/
OgreMeshWriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// OgreMeshWriter.h, a class declaration for Collada import into a single Ogre mesh
// Author: Jeff Trull <[email protected]>
/*
Copyright (c) 2011 Aditazz, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef OGRE_COLLADA_MESHWRITER
#define OGRE_COLLADA_MESHWRITER
#include <OgreMesh.h>
namespace COLLADABU { namespace Math { class Matrix4; } }
#include "OgreColladaWriter.h"
namespace OgreCollada {
class MeshWriter : public Writer {
public:
MeshWriter(const Ogre::String& // dir to find materials etc. in
);
~MeshWriter();
// user access to generated data
Ogre::MeshPtr getMesh() { return m_mesh; }
// ColladaWriter methods we will implement
virtual bool writeGeometry(const COLLADAFW::Geometry*);
virtual void finish();
// a replacement for finish(), for the the first pass only
void pass1Finish();
private:
// hide default xtor and compiler-generated copy and assignment operators
MeshWriter();
MeshWriter( const MeshWriter& pre );
const MeshWriter& operator= ( const MeshWriter& pre );
// record, for every library geometry, all the places where it's used, and their transforms
typedef std::vector<std::pair<const COLLADAFW::MaterialBindingArray*, Ogre::Matrix4> > GeoInstUsageList;
typedef GeoInstUsageList::const_iterator GeoInstUsageListIter;
typedef std::map<COLLADAFW::UniqueId, GeoInstUsageList> GeoUsageMap;
typedef GeoUsageMap::const_iterator GeoUsageMapIter;
GeoUsageMap m_geometryUsage;
Ogre::ManualObject* m_manobj;
Ogre::MeshPtr m_mesh;
// scene graph traversal function
bool createSceneDFS(const COLLADAFW::Node*, // node to instantiate
Ogre::Matrix4); // accumulated transform
// dispatch classes. Instead of defining a single writer that checks to see what mode it's in,
// define two proxy writers, one for each pass, that either forward the write method to its
// parent or do nothing.
// Using this pattern we can invoke the converter methods in an arbitrary order, in fact, as long
// as we are willing to run the loader N times... Thanks to Michael Caisse for this idea.
class OgreMeshDispatchPass1 : public WriterBase {
MeshWriter* m_converter; // dispatch target (the "real" methods)
public:
OgreMeshDispatchPass1(MeshWriter* converter) : m_converter(converter) {}
// forward everything except geometry
virtual void start() { m_converter->start(); }
virtual bool writeGlobalAsset(const COLLADAFW::FileInfo* fi) { return m_converter->writeGlobalAsset(fi); }
virtual bool writeScene(const COLLADAFW::Scene* s) { return m_converter->writeScene(s); }
virtual bool writeLibraryNodes(const COLLADAFW::LibraryNodes* ln) { return m_converter->writeLibraryNodes(ln); }
virtual bool writeMaterial(const COLLADAFW::Material* m) { return m_converter->writeMaterial(m); }
virtual bool writeEffect(const COLLADAFW::Effect* e) { return m_converter->writeEffect(e); }
virtual bool writeCamera(const COLLADAFW::Camera* c) { return m_converter->writeCamera(c); }
virtual bool writeImage(const COLLADAFW::Image* i) { return m_converter->writeImage(i); }
virtual bool writeLight(const COLLADAFW::Light* l) { return m_converter->writeLight(l); }
virtual bool writeAnimation(const COLLADAFW::Animation* a) { return m_converter->writeAnimation(a); }
virtual bool writeAnimationList(const COLLADAFW::AnimationList* al) { return m_converter->writeAnimationList(al); }
virtual bool writeSkinControllerData(const COLLADAFW::SkinControllerData* d) { return m_converter->writeSkinControllerData(d); }
virtual bool writeController(const COLLADAFW::Controller* c) { return m_converter->writeController(c); }
virtual bool writeFormulas(const COLLADAFW::Formulas* f) { return m_converter->writeFormulas(f); }
virtual bool writeKinematicsScene(const COLLADAFW::KinematicsScene* s) { return m_converter->writeKinematicsScene(s); }
virtual bool writeVisualScene(const COLLADAFW::VisualScene* vs) { return m_converter->writeVisualScene(vs); }
virtual void finish() { m_converter->pass1Finish(); }
};
class OgreMeshDispatchPass2 : public WriterBase {
MeshWriter* m_converter; // dispatch target (the "real" methods)
public:
OgreMeshDispatchPass2(MeshWriter* converter) : m_converter(converter) {}
// Forward only writeGeometry and finish
virtual bool writeGeometry(const COLLADAFW::Geometry* g) { return m_converter->writeGeometry(g); }
virtual void finish() { m_converter->finish(); }
};
OgreMeshDispatchPass1* m_pass1Writer;
OgreMeshDispatchPass2* m_pass2Writer;
public:
OgreMeshDispatchPass1* getPass1ProxyWriter() { return m_pass1Writer; }
OgreMeshDispatchPass2* getPass2ProxyWriter() { return m_pass2Writer; }
};
} // end namespace OgreCollada
#endif