上传者: andyhebear
|
上传时间: 2022-04-13 00:25:44
|
文件大小: 216KB
|
文件类型: RAR
真正的破解版本,测试可用#ifndef PROCEDURAL_MESH_GENERATOR_INCLUDED
#define PROCEDURAL_MESH_GENERATOR_INCLUDED
namespace Procedural
{
/**
\defgroup objgengrp Object generators
Elements for procedural mesh generation of various objects.
@{
@}
*/
/**
\ingroup objgengrp
Superclass of everything that builds meshes
*/
template
class MeshGenerator
{
protected:
/// A pointer to the default scene manager
//Ogre::SceneManager* mSceneMgr;
/// U tile for texture coords generation
Ogre::Real mUTile;
/// V tile for texture coords generation
Ogre::Real mVTile;
/// Whether to produces normals or not
bool mEnableNormals;
/// The number of texture coordinate sets to include
unsigned char mNumTexCoordSet;
/// Rectangle in which the texture coordinates will be placed
Ogre::Vector2 mUVOrigin;
/// If set to true, the UV coordinates coming from the mesh generator will be switched.
/// It can be used, for example, if your texture doesn't fit the mesh generator's assumptions about UV.
/// If UV were to fit in a given rectangle, they still fit in it after the switch.
bool mSwitchUV;
/// Orientation to apply the mesh
Ogre::Quaternion mOrientation;
/// Scale to apply the mesh
Ogre::Vector3 mScale;
/// Position to apply to the mesh
Ogre::Vector3 mPosition;
// Whether a transform has been defined or not
bool mTransform;
public:
/// Default constructor
/// \exception Ogre::InvalidStateException Scene Manager is not set in OGRE root object
MeshGenerator() : mUTile(1.f),
mVTile(1.f),
mEnableNormals(true),
mNumTexCoordSet(1),
mUVOrigin(0,0),
mSwitchUV(false),
mOrientation(Ogre::Quaternion::IDENTITY),
mScale(1,1,1),
mPosition(0,0,0),
mTransform(false)
{
}
/**
* Builds a mesh.
* @param name of the mesh for the MeshManager
* @param group ressource group in which the mesh will be created
*/
Ogre::MeshPtr realizeMesh(const std::string& name = "",
const Ogre::String& group = "General")
{
TriangleBuffer tbuffer;
addToTriangleBuffer(tbuffer);
Ogre::MeshPtr mesh;
if (name == "")
mesh = tbuffer.transformToMesh(Utils::getName(), group);
else
mesh = tbuffer.transformToMesh(name, group);
return mesh;
}
/**
* Outputs a triangleBuffer
*/
TriangleBuffer buildTriangleBuffer() const
{
TriangleBuffer tbuffer;
addToTriangleBuffer(tbuffer);
return tbuffer;
}
/**
* Overloaded by each generator to implement the specifics
*/
virtual void addToTriangleBuffer(TriangleBuffer& buffer) const=0;
/**
* Sets U Tile, ie the number by which u texture coordinates are multiplied (default=1)
*/
inline T& setUTile(Ogre::Real uTile)
{
mUTile = uTile;
return static_cast(*this);
}
/**
* Sets V Tile, ie the number by which v texture coordinates are multiplied (default=1)
*/
inline T& setVTile(Ogre::Real vTile)
{
mVTile = vTile;
return static_cast(*this);
}
/**
* Sets the texture rectangle
*/
inline T& setTextureRectangle(const Ogre::RealRect& textureRectangle)
{
mUVOrigin = Ogre::Vector2(textureRectangle.top, textureRectangle.left);
mUTile = textureRectangle.right-textureRectangle.left;
mVTile = textureRectangle.bottom-textureRectangle.top;
return static_cast(*this);
}
/**
* Sets whether normals are enabled or not (default=true)
*/
inline T& setEnableNormals(bool enableNormals)
{
mEnableNormals = enableNormals;
return static_cast(*this);
}
/**
* Sets the number of texture coordintate sets (default=1)
*/
inline T& setNumTexCoordSet(unsigned char numTexCoordSet)
{
mNumTexCoordSet = numTexCoordSet;
return static_cast(*this);
}
/// Sets whether to switch U and V texture coordinates
inline T& setSwitchUV(bool switchUV)
{
mSwitchUV = switchUV;
return static_cast(*this);
}
/// Sets an orientation to give when building the mesh
inline T& setOrientation(const Ogre::Quaternion& orientation)
{
mOrientation = orientation;
mTransform = true;
return static_cast(*this);
}
/// Sets a translation baked into the resulting mesh
inline T& setPosition(const Ogre::Vector3& position)
{
mPosition = position;
mTransform = true;
return static_cast(*this);
}
/// Sets a translation baked into the resulting mesh
inline T& setPosition(Ogre::Real x, Ogre::Real y, Ogre::Real z)
{
mPosition = Ogre::Vector3(x, y, z);
mTransform = true;
return static_cast(*this);
}
/// Sets a scale baked into the resulting mesh
inline T& setScale(const Ogre::Vector3& scale)
{
mScale = scale;
mTransform = true;
return static_cast(*this);
}
/// Sets a uniform scale baked into the resulting mesh
inline T& setScale(Ogre::Real scale)
{
mScale = Ogre::Vector3(scale);
mTransform = true;
return static_cast(*this);
}
/// Sets a scale baked into the resulting mesh
inline T& setScale(Ogre::Real x, Ogre::Real y, Ogre::Real z)
{
mScale = Ogre::Vector3(x, y, z);
mTransform = true;
return static_cast(*this);
}
/// Resets all transforms (orientation, position and scale) that would have been applied to the mesh to their default values
inline T& resetTransforms()
{
mTransform = false;
mPosition = Ogre::Vector3::ZERO;
mOrientation = Ogre::Quaternion::IDENTITY;
mScale = Ogre::Vector3(1);
return static_cast(*this);
}
protected:
/// Adds a new point to a triangle buffer, using the format defined for that MeshGenerator
/// @param buffer the triangle buffer to update
/// @param position the position of the new point
/// @param normal the normal of the new point
/// @param uv the uv texcoord of the new point
inline void addPoint(TriangleBuffer& buffer, const Ogre::Vector3& position, const Ogre::Vector3& normal, const Ogre::Vector2& uv) const
{
if (mTransform)
buffer.position(mPosition + mOrientation * (mScale * position));
else
buffer.position(position);
if (mEnableNormals)
{
if (mTransform)
buffer.normal(mOrientation * normal);
else
buffer.normal(normal);
}
if (mSwitchUV)
for (unsigned char i=0; i
//*
//\defgroup objgengrp Object generators
//Elements for procedural mesh generation of various objects.
//@{
//@}
//
//*
//\ingroup objgengrp
//Superclass of everything that builds meshes
//
public abstract class MeshGenerator
{
/// A pointer to the default scene manager
//Ogre::SceneManager* mSceneMgr;
/// U tile for texture coords generation
protected Ogre.Real mUTile = new Ogre.Real();
/// V tile for texture coords generation
protected Ogre.Real mVTile = new Ogre.Real();
/// Whether to produces normals or not
protected bool mEnableNormals;
/// The number of texture coordinate sets to include
protected byte mNumTexCoordSet;
/// Rectangle in which the texture coordinates will be placed
protected Ogre.Vector2 mUVOrigin = new Ogre.Vector2();
/// If set to true, the UV coordinates coming from the mesh generator will be switched.
/// It can be used, for example, if your texture doesn't fit the mesh generator's assumptions about UV.
/// If UV were to fit in a given rectangle, they still fit in it after the switch.
protected bool mSwitchUV;
/// Orientation to apply the mesh
protected Ogre.Quaternion mOrientation = new Ogre.Quaternion();
/// Scale to apply the mesh
protected Ogre.Vector3 mScale = new Ogre.Vector3();
/// Position to apply to the mesh
protected Ogre.Vector3 mPosition = new Ogre.Vector3();
// Whether a transform has been defined or not
protected bool mTransform;
/// Default constructor
/// \exception Ogre::InvalidStateException Scene Manager is not set in OGRE root object
public MeshGenerator()
{
mUTile = 1.f;
mVTile = 1.f;
mEnableNormals = true;
mNumTexCoordSet = 1;
mUVOrigin = new Ogre.Vector2(0,0);
mSwitchUV = false;
mOrientation = Ogre.Quaternion.IDENTITY;
mScale = new Ogre.Vector3(1,1,1);
mPosition = new Ogre.Vector3(0,0,0);
mTransform = false;
}
// *
// * Builds a mesh.
// * @param name of the mesh for the MeshManager
// * @param group ressource group in which the mesh will be created
//
public Ogre.MeshPtr realizeMesh(string name)
{
return realizeMesh(name, "General");
}
public Ogre.MeshPtr realizeMesh()
{
return realizeMesh("", "General");
}
//C++ TO C# CONVERTER NOTE: Overloaded method(s) are created above to convert the following method having default parameters:
//ORIGINAL LINE: Ogre::MeshPtr realizeMesh(const string& name = "", const Ogre::String& group = "General")
public Ogre.MeshPtr realizeMesh(string name, Ogre.String group)
{
TriangleBuffer tbuffer = new TriangleBuffer();
addToTriangleBuffer(ref tbuffer);
Ogre.MeshPtr mesh = new Ogre.MeshPtr();
if (name == "")
mesh = tbuffer.transformToMesh(Utils.getName(), group);
else
mesh = tbuffer.transformToMesh(name, group);
return mesh;
}
// *
// * Outputs a triangleBuffer
//
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: TriangleBuffer buildTriangleBuffer() const
public TriangleBuffer buildTriangleBuffer()
{
TriangleBuffer tbuffer = new TriangleBuffer();
addToTriangleBuffer(ref tbuffer);
return tbuffer;
}
// *
// * Overloaded by each generator to implement the specifics
//
public abstract void addToTriangleBuffer(ref TriangleBuffer buffer) const;
// *
// * Sets U Tile, ie the number by which u texture coordinates are multiplied (default=1)
//
public T setUTile(Ogre.Real uTile)
{
mUTile = uTile;
return (T)( this);
}
// *
// * Sets V Tile, ie the number by which v texture coordinates are multiplied (default=1)
//
public T setVTile(Ogre.Real vTile)
{
mVTile = vTile;
return (T)( this);
}
// *
// * Sets the texture rectangle
//
public T setTextureRectangle(Ogre.RealRect textureRectangle)
{
mUVOrigin = Ogre.Vector2(textureRectangle.top, textureRectangle.left);
mUTile = textureRectangle.right-textureRectangle.left;
mVTile = textureRectangle.bottom-textureRectangle.top;
return (T)( this);
}
// *
// * Sets whether normals are enabled or not (default=true)
//
public T setEnableNormals(bool enableNormals)
{
mEnableNormals = enableNormals;
return (T)( this);
}
// *
// * Sets the number of texture coordintate sets (default=1)
//
public T setNumTexCoordSet(byte numTexCoordSet)
{
mNumTexCoordSet = numTexCoordSet;
return (T)( this);
}
/// Sets whether to switch U and V texture coordinates
public T setSwitchUV(bool switchUV)
{
mSwitchUV = switchUV;
return (T)( this);
}
/// Sets an orientation to give when building the mesh
public T setOrientation(Ogre.Quaternion orientation)
{
mOrientation = orientation;
mTransform = true;
return (T)( this);
}
/// Sets a translation baked into the resulting mesh
public T setPosition(Ogre.Vector3 position)
{
mPosition = position;
mTransform = true;
return (T)( this);
}
/// Sets a translation baked into the resulting mesh
public T setPosition(Ogre.Real x, Ogre.Real y, Ogre.Real z)
{
mPosition = Ogre.Vector3(x, y, z);
mTransform = true;
return (T)( this);
}
/// Sets a scale baked into the resulting mesh
public T setScale(Ogre.Vector3 scale)
{
mScale = scale;
mTransform = true;
return (T)( this);
}
/// Sets a uniform scale baked into the resulting mesh
public T setScale(Ogre.Real scale)
{
mScale = Ogre.Vector3(scale);
mTransform = true;
return (T)( this);
}
/// Sets a scale baked into the resulting mesh
public T setScale(Ogre.Real x, Ogre.Real y, Ogre.Real z)
{
mScale = Ogre.Vector3(x, y, z);
mTransform = true;
return (T)( this);
}
/// Resets all transforms (orientation, position and scale) that would have been applied to the mesh to their default values
public T resetTransforms()
{
mTransform = false;
mPosition = Ogre.Vector3.ZERO;
mOrientation = Ogre.Quaternion.IDENTITY;
mScale = Ogre.Vector3(1);
return (T)( this);
}
/// Adds a new point to a triangle buffer, using the format defined for that MeshGenerator
/// @param buffer the triangle buffer to update
/// @param position the position of the new point
/// @param normal the normal of the new point
/// @param uv the uv texcoord of the new point
//C++ TO C# CONVERTER WARNING: 'const' methods are not available in C#:
//ORIGINAL LINE: inline void addPoint(TriangleBuffer& buffer, const Ogre::Vector3& position, const Ogre::Vector3& normal, const Ogre::Vector2& uv) const
protected void addPoint(ref TriangleBuffer buffer, Ogre.Vector3 position, Ogre.Vector3 normal, Ogre.Vector2 uv)
{
if (mTransform)
buffer.position(mPosition + mOrientation * (mScale * position));
else
buffer.position(position);
if (mEnableNormals)
{
if (mTransform)
buffer.normal(mOrientation * normal);
else
buffer.normal(normal);
}
if (mSwitchUV)
for (byte i =0; i