2009-05-15 07:04:50 +00:00
|
|
|
/**
|
2009-05-16 17:58:08 +00:00
|
|
|
* holds data that is passed to the mesh renderer. heights normals etc
|
2009-05-15 07:04:50 +00:00
|
|
|
*
|
2009-05-16 17:58:08 +00:00
|
|
|
* This needs a rework, as really the mesh renderer should accept just
|
|
|
|
* a set of verts Normals and indicies to allow us to pass optimized
|
|
|
|
* meshes
|
2009-05-15 07:04:50 +00:00
|
|
|
*/
|
2009-05-16 18:47:49 +00:00
|
|
|
enum SplitState { SS_NONE, SS_SPLIT, SS_UNSPLIT };
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
class QuadData
|
|
|
|
{
|
2009-05-16 17:58:08 +00:00
|
|
|
typedef std::list<Ogre::ResourcePtr> ResourceList;
|
|
|
|
typedef std::list<Ogre::ResourcePtr>::const_iterator ResourceListCItr;
|
2009-05-15 07:04:50 +00:00
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
public:
|
|
|
|
virtual ~QuadData()
|
|
|
|
{
|
|
|
|
const ResourceListCItr end = mResources.end();
|
|
|
|
for ( ResourceListCItr itr = mResources.begin(); itr != end; ++itr )
|
|
|
|
(*itr)->getCreator()->remove((*itr)->getHandle());
|
|
|
|
}
|
2009-05-15 07:04:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How many vertes wide the qd is. Usally 65.
|
|
|
|
* @todo cache?
|
|
|
|
*/
|
|
|
|
inline int getVertexWidth() {
|
|
|
|
return sqrt(getHeightsRef().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::vector<float>& getHeightsRef() {
|
|
|
|
return mHeights;
|
|
|
|
}
|
|
|
|
inline float getVertex(int offset){
|
|
|
|
return getHeightsRef().at(offset);
|
|
|
|
}
|
|
|
|
inline std::vector<char>& getNormalsRef() {
|
|
|
|
return mNormals;
|
|
|
|
}
|
|
|
|
inline float getNormal(int offset){
|
|
|
|
return getNormalsRef().at(offset);
|
|
|
|
}
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
inline ResourceList& getUsedResourcesRef()
|
|
|
|
{ return mResources; }
|
|
|
|
|
|
|
|
inline void setTexture(const std::string& t)
|
|
|
|
{ mTexture = t; }
|
|
|
|
|
|
|
|
inline std::string& getTexture()
|
|
|
|
{ return mTexture; }
|
|
|
|
|
|
|
|
inline std::vector<int>& getTextureIndexRef()
|
|
|
|
{ return mTextureIndex; }
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
/**
|
2009-05-16 17:58:08 +00:00
|
|
|
* @brief should be removed when we get around to developing optimized meshes
|
2009-05-15 07:04:50 +00:00
|
|
|
*/
|
|
|
|
inline int getVertexSeperation() {
|
|
|
|
return mVertexSeperation;
|
|
|
|
}
|
|
|
|
inline void setVertexSeperation(int vs) {
|
|
|
|
mVertexSeperation = vs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-05-16 17:58:08 +00:00
|
|
|
* @brief lazy get function. Avoids creating material until requested
|
2009-05-15 07:04:50 +00:00
|
|
|
*/
|
|
|
|
inline Ogre::MaterialPtr getMaterial() {
|
|
|
|
if ( mMaterial.isNull() )
|
|
|
|
createMaterial();
|
|
|
|
assert(!mMaterial.isNull());
|
|
|
|
return mMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief gets the texture for the above quad
|
|
|
|
*/
|
|
|
|
inline const std::string& getParentTexture() const {
|
|
|
|
return mParentTexture;
|
|
|
|
}
|
|
|
|
inline bool hasParentTexture() const {
|
|
|
|
return (mParentTexture.length() > 0);
|
|
|
|
}
|
|
|
|
inline void setParentTexture(const std::string& c) {
|
|
|
|
mParentTexture = c;
|
|
|
|
}
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
private:
|
2009-05-15 07:04:50 +00:00
|
|
|
void createMaterial()
|
|
|
|
{
|
2009-05-16 17:58:08 +00:00
|
|
|
assert(mTexture.length());
|
|
|
|
|
|
|
|
mMaterial = g_materialGen->generateSingleTexture(mTexture, mResources);
|
2009-05-15 07:04:50 +00:00
|
|
|
}
|
2009-05-16 17:58:08 +00:00
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
Ogre::MaterialPtr mMaterial;
|
|
|
|
|
|
|
|
std::string mParentTexture;
|
|
|
|
|
|
|
|
int mVertexSeperation;
|
|
|
|
std::vector<float> mHeights;
|
|
|
|
std::vector<char> mNormals;
|
|
|
|
|
|
|
|
///Holds the resources used by the quad
|
|
|
|
ResourceList mResources;
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
std::vector<int> mTextureIndex; ///holds index that correspond to the palette
|
2009-05-15 07:04:50 +00:00
|
|
|
std::string mTexture; ///The land texture. Mutally exclusive with the above
|
|
|
|
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the data for the heights, noramals and texture indexies.
|
|
|
|
* Texture as well
|
|
|
|
*/
|
|
|
|
template<class Archive>
|
|
|
|
inline void serialize(Archive& ar, const unsigned int version){
|
|
|
|
ar &mVertexSeperation;
|
|
|
|
ar &mHeights;
|
|
|
|
ar &mNormals;
|
|
|
|
ar &mParentTexture;
|
|
|
|
|
|
|
|
ar &mTextureIndex;
|
|
|
|
ar &mTexture;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
BOOST_CLASS_TRACKING(QuadData, boost::serialization::track_never);
|