本文整理汇总了C++中ogre::MeshPtr类的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr类的具体用法?C++ MeshPtr怎么用?C++ MeshPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MeshPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportMesh
bool AssetsManager::exportMesh(Ogre::MeshPtr mesh, const std::string& filePath)
{
if (filePath != "") {
Ogre::MeshSerializer serializer;
try {
std::string dirname(filePath);
size_t end = dirname.find_last_of("/\\");
if (end != std::string::npos) {
dirname = dirname.substr(0, end);
}
oslink::directory osdir(dirname);
if (!osdir.isExisting()) {
oslink::directory::mkdir(dirname.c_str());
}
serializer.exportMesh(mesh.get(), filePath);
S_LOG_INFO("Exported mesh " << filePath);
} catch (const Ogre::Exception& ex) {
S_LOG_FAILURE("Error when exporting mesh " << mesh->getName() << "to path " << filePath <<"." << ex);
return false;
}
return true;
}
return false;
}
示例2: MakeUnLoadedLocked
// Call for an unload when list is already locked
void OLMeshTracker::MakeUnLoadedLocked(Ogre::String meshName, Ogre::String stringParam, Ogre::Entity* entityParam) {
// see if in the loading list. Remove if there.
GenericQm* loadEntry = m_meshesToLoad->Find(meshName);
if (loadEntry != NULL) {
loadEntry->Abort();
m_meshesToLoad->Remove(meshName);
}
// see if in the serialize list. Mark for unload if it's there
GenericQm* serialEntry = m_meshesToSerialize->Find(meshName);
if (serialEntry != NULL) {
serialEntry->stringParam = "unload";
}
else {
Ogre::MeshPtr meshP = Ogre::MeshManager::getSingleton().getByName(meshName);
if (!meshP.isNull()) {
if (meshP.useCount() == 1) {
meshP->unload();
}
else {
LG::Log("OLMeshTracker::MakeUnLoaded: Didn't unload mesh because count = %d", meshP.useCount());
}
}
}
}
示例3: setMaterialName
//---------------------------------------------------------------------
void MeshElement::setMaterialName(const Ogre::String &name)
{
mMaterialName = name;
if (mEntity)
{
// if this is "none",we will use the origin material of the mesh
if (mMaterialName == "none")
{
if ( false == mMeshName.empty() )
{
Ogre::MeshPtr currentMesh = Ogre::MeshManager::getSingleton().getByName(mMeshName);
for ( unsigned short i=0; i<currentMesh->getNumSubMeshes(); ++i )
{
mEntity->getSubEntity(i)->setMaterialName( currentMesh->getSubMesh(i)->getMaterialName() );
}
}
}
else
mEntity->setMaterialName(mMaterialName);
}
}
示例4: createFakeEntity
void ESKOgre::createFakeEntity(Ogre::SceneManager *mSceneMgr) {
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual(name + "_skeleton", XENOVIEWER_RESOURCE_GROUP);
msh->setSkeletonName(name);
Ogre::SubMesh* sub = msh->createSubMesh();
const size_t nVertices = 3;
const size_t nVertCount = 3;
const size_t vbufCount = nVertCount*nVertices;
float *vertices = (float *)malloc(sizeof(float)*vbufCount);
for (size_t i = 0; i < nVertices; i++) {
vertices[i*nVertCount] = 0.0;
vertices[i*nVertCount + 1] = 0.0;
vertices[i*nVertCount + 2] = 0.0;
}
const size_t ibufCount = 3;
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i < ibufCount; i++) {
faces[i] = i;
}
msh->sharedVertexData = new Ogre::VertexData();
msh->sharedVertexData->vertexCount = nVertices;
Ogre::VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offset, msh->sharedVertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
msh->_setBounds(Ogre::AxisAlignedBox(-100, -100, -100, 100, 100, 100));
msh->_setBoundingSphereRadius(100);
msh->load();
free(faces);
free(vertices);
skeleton_entity = mSceneMgr->createEntity(name + "_skeleton");
skeleton_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
skeleton_node->attachObject(skeleton_entity);
skeleton_node->setVisible(false);
}
示例5: locateSkeleton
bool MilkshapePlugin::locateSkeleton(Ogre::MeshPtr& mesh)
{
//
// choose filename
//
OPENFILENAME ofn;
memset (&ofn, 0, sizeof (OPENFILENAME));
char szFile[MS_MAX_PATH];
char szFileTitle[MS_MAX_PATH];
char szDefExt[32] = "skeleton";
char szFilter[128] = "OGRE .skeleton Files (*.skeleton)\0*.skeleton\0All Files (*.*)\0*.*\0\0";
szFile[0] = '\0';
szFileTitle[0] = '\0';
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrDefExt = szDefExt;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MS_MAX_PATH;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MS_MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.lpstrTitle = "Locate OGRE Skeleton (since you're not exporting it)";
if (!::GetOpenFileName (&ofn))
return false;
// Strip off the path
Ogre::String skelName = szFile;
size_t lastSlash = skelName.find_last_of("\\");
skelName = skelName.substr(lastSlash+1);
Ogre::String msg = "Linking mesh to skeleton file '" + skelName + "'";
Ogre::LogManager::getSingleton().logMessage(msg);
// Create a dummy skeleton for Mesh to link to (saves it trying to load it)
Ogre::SkeletonPtr pSkel = Ogre::SkeletonManager::getSingleton().create(skelName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::LogManager::getSingleton().logMessage("Dummy Skeleton object created for link.");
mesh->_notifySkeleton(pSkel);
return true;
}
示例6: resolveFilePathForMesh
std::string AssetsManager::resolveFilePathForMesh(Ogre::MeshPtr meshPtr)
{
Ogre::ResourceGroupManager& manager = Ogre::ResourceGroupManager::getSingleton();
const std::multimap<std::string, std::string>& locations = EmberOgre::getSingleton().getResourceLocations();
for (std::multimap<std::string, std::string>::const_iterator I = locations.begin(); I != locations.end(); ++I) {
std::string group = I->first;
std::string fileName = meshPtr->getName();
Ogre::FileInfoListPtr files = manager.findResourceFileInfo(group, fileName, false);
for (Ogre::FileInfoList::const_iterator J = files->begin(); J != files->end(); ++J) {
if (J->filename == fileName) {
return I->second + J->filename;
}
}
}
return "";
}
示例7: Indicator
Indicator(const ObjectPtr &object, SceneManipulator *sceneManipulator)
: mProxy(NULL)
{
assert(sceneManipulator);
mUserAny = Ogre::Any();
mProxy = new ObjectProxy(object);
// 根据光源位置来定节点位置
Ogre::Vector3 pos = VariantCast<Ogre::Vector3>(object->getProperty("position"));
mIndicatorSceneNode = sceneManipulator->getIndicatorRootSceneNode()->createChildSceneNode(pos);
Real radius = 5;
int rings = 16;
int segments = 16;
Ogre::MeshPtr sphereMesh = createCommonSphere(radius, rings, segments);
Ogre::MaterialPtr material = createPureColourMaterial(
Ogre::ColourValue(1, 0, 0, 0.75) );
mIndicatorEntity = sceneManipulator->getSceneManager()->createEntity(mIndicatorSceneNode->getName(), sphereMesh->getName());
//david-<<
//mIndicatorEntity->setNormaliseNormals(true);
//david->>
mIndicatorEntity->setMaterialName(material->getName());
setUserObject(mProxy);
mIndicatorSceneNode->attachObject(mIndicatorEntity);
// 选择时不考虑粒子系统的包围盒,用的是指示器的包围盒
ParticleSystemObject *particleSystemObject = static_cast<ParticleSystemObject *> (object.get());
Ogre::ParticleSystem *system = particleSystemObject->getParticleSystem();
if (system)
system->setQueryFlags(0);
// 根据光源类型来挂接模型
showIndicator(false);
}
示例8: addMesh
void MergeMesh::addMesh( Ogre::MeshPtr mesh )
{
if( mesh->getSkeleton().isNull() )
{
log( "Skipped: " + mesh->getName() + " has no skeleton" );
return;
}
if( m_BaseSkeleton.isNull() )
{
m_BaseSkeleton = mesh->getSkeleton();
log( "Set: base skeleton (" + m_BaseSkeleton->getName()+")" );
}
if( mesh->getSkeleton() != m_BaseSkeleton )
{
log( "Skipped: " + mesh->getName() + " has other skeleton ("+ mesh->getSkeleton()->getName() +")" );
return;
}
m_Meshes.push_back( mesh );
}
示例9: DeleteMesh
// ===============================================================================
// Someone wants to delete this mesh. Check to see if it's a shared mesh and decide if we
// should actually delete it or not.
void OLMeshTracker::DeleteMesh(Ogre::MeshPtr mesh) {
Ogre::MeshManager::getSingleton().remove(mesh->getName());
}
示例10: doExportSkeleton
Ogre::SkeletonPtr MilkshapePlugin::doExportSkeleton(msModel* pModel, Ogre::MeshPtr& mesh)
{
Ogre::LogManager &logMgr = Ogre::LogManager::getSingleton();
Ogre::String msg;
//
// choose filename
//
OPENFILENAME ofn;
memset (&ofn, 0, sizeof (OPENFILENAME));
char szFile[MS_MAX_PATH];
char szFileTitle[MS_MAX_PATH];
char szDefExt[32] = "skeleton";
char szFilter[128] = "OGRE .skeleton Files (*.skeleton)\0*.skeleton\0All Files (*.*)\0*.*\0\0";
szFile[0] = '\0';
szFileTitle[0] = '\0';
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrDefExt = szDefExt;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MS_MAX_PATH;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MS_MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrTitle = "Export to OGRE Skeleton";
if (!::GetSaveFileName (&ofn))
return Ogre::SkeletonPtr();
// Strip off the path
Ogre::String skelName = szFile;
size_t lastSlash = skelName.find_last_of("\\");
skelName = skelName.substr(lastSlash+1);
// Set up
logMgr.logMessage("Trying to create Skeleton object");
Ogre::SkeletonPtr ogreskel = Ogre::SkeletonManager::getSingleton().create(skelName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
logMgr.logMessage("Skeleton object created");
// Complete the details
// Do the bones
int numBones = msModel_GetBoneCount(pModel);
msg = "Number of bones: " + Ogre::StringConverter::toString(numBones);
logMgr.logMessage(msg);
int i;
// Create all the bones in turn
for (i = 0; i < numBones; ++i)
{
msBone* bone = msModel_GetBoneAt(pModel, i);
Ogre::Bone* ogrebone = ogreskel->createBone(bone->szName);
msVec3 msBonePos, msBoneRot;
msBone_GetPosition(bone, msBonePos);
msBone_GetRotation(bone, msBoneRot);
Ogre::Vector3 bonePos(msBonePos[0], msBonePos[1], msBonePos[2]);
ogrebone->setPosition(bonePos);
// Hmm, Milkshape has chosen a Euler angle representation of orientation which is not smart
// Rotation Matrix or Quaternion would have been the smarter choice
// Might we have Gimbal lock here? What order are these 3 angles supposed to be applied?
// Grr, we'll try our best anyway...
Ogre::Quaternion qx, qy, qz, qfinal;
qx.FromAngleAxis(Ogre::Radian(msBoneRot[0]), Ogre::Vector3::UNIT_X);
qy.FromAngleAxis(Ogre::Radian(msBoneRot[1]), Ogre::Vector3::UNIT_Y);
qz.FromAngleAxis(Ogre::Radian(msBoneRot[2]), Ogre::Vector3::UNIT_Z);
// Assume rotate by x then y then z
qfinal = qz * qy * qx;
ogrebone->setOrientation(qfinal);
Ogre::LogManager::getSingleton().stream()
<< "Bone #" << i << ": " <<
"Name='" << bone->szName << "' " <<
"Position: " << bonePos << " " <<
"Ms3d Rotation: {" << msBoneRot[0] << ", " << msBoneRot[1] << ", " << msBoneRot[2] << "} " <<
"Orientation: " << qfinal;
}
// Now we've created all the bones, link them up
logMgr.logMessage("Establishing bone hierarchy..");
for (i = 0; i < numBones; ++i)
{
msBone* bone = msModel_GetBoneAt(pModel, i);
if (strlen(bone->szParentName) == 0)
{
// Root bone
msg = "Root bone detected: Name='" + Ogre::String(bone->szName) + "' Index="
+ Ogre::StringConverter::toString(i);
logMgr.logMessage(msg);
}
else
{
Ogre::Bone* ogrechild = ogreskel->getBone(bone->szName);
//.........这里部分代码省略.........
示例11: doExportMesh
void MilkshapePlugin::doExportMesh(msModel* pModel)
{
// Create singletons
Ogre::SkeletonManager skelMgr;
Ogre::DefaultHardwareBufferManager defHWBufMgr;
Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton();
Ogre::MeshManager meshMgr;
//
// choose filename
//
OPENFILENAME ofn;
memset (&ofn, 0, sizeof (OPENFILENAME));
char szFile[MS_MAX_PATH];
char szFileTitle[MS_MAX_PATH];
char szDefExt[32] = "mesh";
char szFilter[128] = "OGRE .mesh Files (*.mesh)\0*.mesh\0All Files (*.*)\0*.*\0\0";
szFile[0] = '\0';
szFileTitle[0] = '\0';
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrDefExt = szDefExt;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MS_MAX_PATH;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MS_MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrTitle = "Export to OGRE Mesh";
if (!::GetSaveFileName (&ofn))
return /*0*/;
logMgr.logMessage("Creating Mesh object...");
Ogre::MeshPtr ogreMesh = Ogre::MeshManager::getSingleton().create("export",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
logMgr.logMessage("Mesh object created.");
bool foundBoneAssignment = false;
// No shared geometry
int i;
int wh, numbones;
int intweight[3], intbones[3];
size_t j;
Ogre::Vector3 min, max, currpos;
Ogre::Real maxSquaredRadius;
bool first = true;
for (i = 0; i < msModel_GetMeshCount (pModel); i++)
{
msMesh *pMesh = msModel_GetMeshAt (pModel, i);
logMgr.logMessage("Creating SubMesh object...");
Ogre::SubMesh* ogreSubMesh = ogreMesh->createSubMesh();
logMgr.logMessage("SubMesh object created.");
// Set material
logMgr.logMessage("Getting SubMesh Material...");
int matIdx = msMesh_GetMaterialIndex(pMesh);
if (matIdx == -1)
{
// No material, use blank
ogreSubMesh->setMaterialName("BaseWhite");
logMgr.logMessage("No Material, using default 'BaseWhite'.");
}
else
{
msMaterial *pMat = msModel_GetMaterialAt(pModel, matIdx);
ogreSubMesh->setMaterialName(pMat->szName);
logMgr.logMessage("SubMesh Material Done.");
}
logMgr.logMessage("Setting up geometry...");
// Set up mesh geometry
ogreSubMesh->vertexData = new Ogre::VertexData();
ogreSubMesh->vertexData->vertexCount = msMesh_GetVertexCount (pMesh);
ogreSubMesh->vertexData->vertexStart = 0;
Ogre::VertexBufferBinding* bind = ogreSubMesh->vertexData->vertexBufferBinding;
Ogre::VertexDeclaration* decl = ogreSubMesh->vertexData->vertexDeclaration;
// Always 1 texture layer, 2D coords
#define POSITION_BINDING 0
#define NORMAL_BINDING 1
#define TEXCOORD_BINDING 2
decl->addElement(POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
decl->addElement(NORMAL_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
decl->addElement(TEXCOORD_BINDING, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
// Create buffers
Ogre::HardwareVertexBufferSharedPtr pbuf = Ogre::HardwareBufferManager::getSingleton().
createVertexBuffer(decl->getVertexSize(POSITION_BINDING), ogreSubMesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_DYNAMIC, false);
Ogre::HardwareVertexBufferSharedPtr nbuf = Ogre::HardwareBufferManager::getSingleton().
createVertexBuffer(decl->getVertexSize(NORMAL_BINDING), ogreSubMesh->vertexData->vertexCount,
Ogre::HardwareBuffer::HBU_DYNAMIC, false);
Ogre::HardwareVertexBufferSharedPtr tbuf = Ogre::HardwareBufferManager::getSingleton().
//.........这里部分代码省略.........
示例12: SceneNodeExplore
void CSaveSceneView::SceneNodeExplore(Ogre::SceneNode *SceneNode)
{
Ogre::Entity *Entity = NULL;
Ogre::Camera *Camera = NULL;
Ogre::Light *Light = NULL;
Ogre::ParticleSystem *ParticleSystem = NULL;
Ogre::ManualObject *ManualObject = NULL;
Ogre::BillboardSet *BillboardSet = NULL;
xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "SceneNode");
Ogre::String SceneNodeName = SceneNode->getName();
xmlTextWriterWriteAttribute(m_XmlWriter,
BAD_CAST "SceneNodeName",
BAD_CAST SceneNodeName.c_str());
Ogre::SceneNode::ObjectIterator obji = SceneNode->getAttachedObjectIterator();
while (obji.hasMoreElements())
{
Ogre::MovableObject* mobj = obji.getNext();
Ogre::String Type = mobj->getMovableType();
if (Type == "Entity")
{
Entity = (Ogre::Entity *)(mobj);
Ogre::String EntityName = Entity->getName();
xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Entity");
xmlTextWriterWriteAttribute(m_XmlWriter,
BAD_CAST "EntityName",
BAD_CAST EntityName.c_str());
Ogre::MeshPtr Mesh = Entity->getMesh();
Ogre::String MeshName = Mesh->getName();
xmlTextWriterWriteAttribute(m_XmlWriter,
BAD_CAST "MeshName",
BAD_CAST MeshName.c_str());
xmlTextWriterEndElement(m_XmlWriter);
}
if (Type == "Camera")
{
Camera = (Ogre::Camera *)(mobj);
Ogre::String CameraName = Camera->getName();
xmlTextWriterStartElement(m_XmlWriter, BAD_CAST "Camera");
xmlTextWriterWriteAttribute(m_XmlWriter,
BAD_CAST "CameraName",
BAD_CAST CameraName.c_str());
Ogre::Vector3 CameraPosition = Camera->getPosition();
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "XPosition",
"%f",CameraPosition.x);
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "YPosition",
"%f",CameraPosition.y);
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "ZPosition",
"%f",CameraPosition.z);
Ogre::Vector3 CameraDirection = Camera->getDirection();
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "XDirection",
"%f",CameraDirection.x);
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "YDirection",
"%f",CameraDirection.y);
xmlTextWriterWriteFormatAttribute(m_XmlWriter,
BAD_CAST "ZDirection",
"%f",CameraDirection.z);
xmlTextWriterEndElement(m_XmlWriter);
}
if (Type == "Light")
{
Light = (Ogre::Light *)(mobj);
}
if (Type == "ParticleSystem")
{
ParticleSystem = (Ogre::ParticleSystem *)(mobj);
}
if (Type == "ManualObject")
{
ManualObject = (Ogre::ManualObject *)(mobj);
}
if (Type == "BillboardSet")
{
BillboardSet = (Ogre::BillboardSet *)(mobj);
}
}
//.........这里部分代码省略.........
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:101,代码来源:SaveSceneView.cpp
示例13: SetPivotTransform
void NxMeshManager::SetPivotTransform( Ogre::MeshPtr mesh, const Nx::Vector3 & Position, const Nx::Quaternion & Rotation, const Nx::Vector3 & Scale )
{
//from mesh magick / mit licence
Nx::Matrix4 transform = Nx::Matrix4::IDENTITY;
Nx::Vector3 translate = Nx::Vector3::ZERO;
// Apply current transform to the mesh, to get the bounding box to
// base te translation on.
AxisAlignedBox aabb = getMeshAabb( mesh, transform);
//if (alignment == "left")
//{
// translate = Vector3(-aabb.getMinimum().x, 0, 0);
//}
//else if (alignment == "center")
//{
// translate = Vector3(-aabb.getCenter().x, 0, 0);
//}
//else if (alignment == "right")
//{
// translate = Vector3(-aabb.getMaximum().x, 0, 0);
//}
//Position .. only support pivot down / centered
//translate = Vector3(0, -aabb.getMinimum().y, 0);// pivot down
translate = Position;
transform = Nx::Matrix4::getTrans(translate) * transform;
//rotation
transform = Nx::Matrix4(Rotation) * transform;
//scale
transform = Nx::Matrix4::getScale(Scale) * transform;
// Check whether we have to flip vertex winding.
// We do have to, if we changed our right hand base.
// We can test it by using the cross product from X and Y and see, if it is a non-negative
// projection on Z. Actually it should be exactly Z, as we don't do non-uniform scaling yet,
// but the test is cheap either way.
Nx::Matrix3 m3;
transform.extract3x3Matrix(m3);
if (m3.GetColumn(0).crossProduct(m3.GetColumn(1)).dotProduct(m3.GetColumn(2)) < 0)
{
LogMsg("SetPivotPosition : Flipping vertex winding ... " );
mFlipVertexWinding = true;
}
//mTransform = transform;
NxMat4toOgre( mTransform, transform ) ;
mBoundingBox.setNull();
if( mesh->sharedVertexData != NULL)
{
processVertexData( mesh->sharedVertexData);
}else
{
LogMsg("mesh->sharedVertexData NULL");
}
for( int i = 0; i < mesh->getNumSubMeshes(); i++ )
{
SubMesh* submesh = mesh->getSubMesh(i);
if( submesh->vertexData != NULL )
{
LogMsg("SetPivotPosition : Processing vertex data ... " );
processVertexData(submesh->vertexData);
}else
{
LogMsg("submesh->vertexData NULL");
}
if (submesh->indexData != NULL)
{
LogMsg("SetPivotPosition : Processing Index data .." );
processIndexData(submesh->indexData);
}else
{
LogMsg("submesh->indexData NULL");
}
}
//process pose
for( unsigned short i = 0; i < mesh->getPoseCount(); ++i )
{
Ogre::Pose * pose = mesh->getPose(i);
Ogre::Matrix3 m3x3;
mTransform.extract3x3Matrix(m3x3);
Pose::VertexOffsetIterator it = pose->getVertexOffsetIterator();
while (it.hasMoreElements()) {
Ogre::Vector3 offset = it.peekNextValue();
Ogre::Vector3 newOffset = m3x3 * offset;
*it.peekNextValuePtr() = newOffset;
it.moveNext();
}
}
//.........这里部分代码省略.........
示例14: GetMeshInformation
// Get the mesh information for the given mesh.
// Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
void CollisionTools::GetMeshInformation(const Ogre::MeshPtr mesh,
size_t &vertex_count,
Ogre::Vector3* &vertices,
size_t &index_count,
Ogre::uint32* &indices,
const Ogre::Vector3 &position,
const Ogre::Quaternion &orient,
const Ogre::Vector3 &scale)
{
bool added_shared = false;
size_t current_offset = 0;
size_t shared_offset = 0;
size_t next_offset = 0;
size_t index_offset = 0;
vertex_count = index_count = 0;
// Calculate how many vertices and indices we're going to need
for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh( i );
// We only need to add the shared vertices once
if(submesh->useSharedVertices)
{
if( !added_shared )
{
vertex_count += mesh->sharedVertexData->vertexCount;
added_shared = true;
}
}
else
{
vertex_count += submesh->vertexData->vertexCount;
}
// Add the indices
index_count += submesh->indexData->indexCount;
}
// Allocate space for the vertices and indices
vertices = new Ogre::Vector3[vertex_count];
indices = new Ogre::uint32[index_count];
added_shared = false;
// Run through the submeshes again, adding the data into the arrays
for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
{
Ogre::SubMesh* submesh = mesh->getSubMesh(i);
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
{
if(submesh->useSharedVertices)
{
added_shared = true;
shared_offset = current_offset;
}
const Ogre::VertexElement* posElem =
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf =
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
unsigned char* vertex =
static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Ogre::Real or a double
// as second argument. So make it float, to avoid trouble when Ogre::Ogre::Real will
// be comiled/typedefed as double:
// Ogre::Ogre::Real* pOgre::Real;
float* pReal;
for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
{
posElem->baseVertexPointerToElement(vertex, &pReal);
Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
vertices[current_offset + j] = (orient * (pt * scale)) + position;
}
vbuf->unlock();
next_offset += vertex_data->vertexCount;
}
Ogre::IndexData* index_data = submesh->indexData;
size_t numTris = index_data->indexCount / 3;
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
Ogre::uint32* pLong = static_cast<Ogre::uint32*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
//.........这里部分代码省略.........
示例15: loadCorrelativeResource
Ogre::MeshPtr
loadMesh(const Ogre::String& meshName, const Ogre::String& groupName,
const Ogre::String& baseResourceName, const Ogre::String& baseGroupName)
{
// Load the mesh
Ogre::MeshPtr mesh = loadCorrelativeResource(
meshName, groupName,
baseResourceName, baseGroupName,
Ogre::MeshManager::getSingleton());
if (mesh.isNull())
{
OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Unable to load mesh " + meshName,
"loadMesh");
}
// Try to resolve skeleton resource
if (mesh->hasSkeleton() && mesh->getSkeleton().isNull())
{
// resolve correlative with mesh
Ogre::SkeletonPtr skeleton = loadCorrelativeResource(
mesh->getSkeletonName(), groupName,
mesh->getName(), mesh->getGroup(),
Ogre::SkeletonManager::getSingleton());
if (skeleton.isNull())
{
// resolve correlative with base resource
skeleton = loadCorrelativeResource(
mesh->getSkeletonName(), groupName,
baseResourceName, baseGroupName,
Ogre::SkeletonManager::getSingleton());
}
if (skeleton.isNull())
{
OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Unable to load skeleton " + mesh->getSkeletonName() +
" for mesh " + mesh->getName(),
"loadMesh");
}
// Set to the actual name
mesh->setSkeletonName(skeleton->getName());
}
return mesh;
}