本文整理汇总了C++中ogre::MeshPtr::load方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::load方法的具体用法?C++ MeshPtr::load怎么用?C++ MeshPtr::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::load方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: dist
Ogre::SceneNode *TutorialApplication::loadBSP(std::shared_ptr<l2p::UModel> m, bool ignoreNonVisible) {
l2p::Name name = m->package->name;
std::vector<float> vertex_data;
std::vector<uint32_t> index_buf;
l2p::Box bounds;
// Build vertex and index buffer.
for (auto ni = m->nodes.begin(), ne = m->nodes.end(); ni != ne; ++ni) {
l2p::BSPNode &n = *ni;
l2p::BSPSurface &s = m->surfaces[n.surface];
if (ignoreNonVisible && ignoreNode(m.get(), n, s))
continue;
uint32_t vert_start = vertex_data.size() / 8;
const Ogre::Vector3 uvec = ogre_cast(m->vectors[s.U]);
const Ogre::Vector3 vvec = ogre_cast(m->vectors[s.V]);
const Ogre::Vector3 base = ogre_cast(m->points[s.base]);
int usize = 0;
int vsize = 0;
std::shared_ptr<l2p::UTexture> mat = s.material;
if (mat) {
usize = mat->USize;
vsize = mat->VSize;
}
if (usize == 0 || vsize == 0)
usize = vsize = 64;
// Vertex buffer.
if (n.num_verticies > 0) {
l2p::Vector Normal = m->vectors[s.normal];
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
bounds += pos;
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
if (s.flags & l2p::PF_TwoSided) {
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(-Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
}
}
// Index buffer.
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti - 1);
index_buf.push_back(vert_start + verti);
}
if (s.flags & l2p::PF_TwoSided) {
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti);
index_buf.push_back(vert_start + verti - 1);
}
}
}
if (vertex_data.size() == 0 || index_buf.size() == 0)
return nullptr;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(Ogre::String(name) + Ogre::String(m->name), "General");
Ogre::VertexData *data = new Ogre::VertexData();
mesh->sharedVertexData = data;
data->vertexCount = vertex_data.size() / 8;
Ogre::VertexDeclaration *decl = data->vertexDeclaration;
uint32_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
//.........这里部分代码省略.........
示例3: poll
bool ModelBackgroundLoader::poll(const TimeFrame& timeFrame)
{
#if OGRE_THREAD_SUPPORT
if (mState == LS_UNINITIALIZED) {
//Start to load the meshes
for (SubModelDefinitionsStore::const_iterator I_subModels = mModel.getDefinition()->getSubModelDefinitions().begin(); I_subModels != mModel.getDefinition()->getSubModelDefinitions().end(); ++I_subModels) {
Ogre::MeshPtr meshPtr = static_cast<Ogre::MeshPtr> (Ogre::MeshManager::getSingleton().getByName((*I_subModels)->getMeshName()));
if (meshPtr.isNull() || !meshPtr->isPrepared()) {
try {
Ogre::BackgroundProcessTicket ticket = Ogre::ResourceBackgroundQueue::getSingleton().prepare(Ogre::MeshManager::getSingleton().getResourceType(), (*I_subModels)->getMeshName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, 0, 0, createListener());
if (ticket) {
addTicket(ticket);
}
} catch (const std::exception& ex) {
S_LOG_FAILURE("Could not load the mesh " << (*I_subModels)->getMeshName() << " when loading model " << mModel.getName() << "." << ex);
continue;
}
}
}
mState = LS_MESH_PREPARING;
return poll(timeFrame);
} else if (mState == LS_MESH_PREPARING) {
if (areAllTicketsProcessed()) {
mState = LS_MESH_PREPARED;
return poll(timeFrame);
}
} else if (mState == LS_MESH_PREPARED) {
for (SubModelDefinitionsStore::const_iterator I_subModels = mModel.getDefinition()->getSubModelDefinitions().begin(); I_subModels != mModel.getDefinition()->getSubModelDefinitions().end(); ++I_subModels) {
Ogre::MeshPtr meshPtr = static_cast<Ogre::MeshPtr> (Ogre::MeshManager::getSingleton().getByName((*I_subModels)->getMeshName()));
if (!meshPtr.isNull()) {
if (!meshPtr->isLoaded()) {
#if OGRE_THREAD_SUPPORT == 1
Ogre::BackgroundProcessTicket ticket = Ogre::ResourceBackgroundQueue::getSingleton().load(Ogre::MeshManager::getSingleton().getResourceType(), meshPtr->getName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, 0, 0, createListener());
if (ticket) {
// meshPtr->setBackgroundLoaded(true);
addTicket(ticket);
}
#else
if (!timeFrame.isTimeLeft()) {
return false;
}
try {
meshPtr->load();
} catch (const std::exception& ex) {
S_LOG_FAILURE("Could not load the mesh " << meshPtr->getName() << " when loading model " << mModel.getName() << "." << ex);
continue;
}
#endif
}
}
}
mState = LS_MESH_LOADING;
return poll(timeFrame);
} else if (mState == LS_MESH_LOADING) {
if (areAllTicketsProcessed()) {
mState = LS_MESH_LOADED;
return poll(timeFrame);
}
} else if (mState == LS_MESH_LOADED) {
for (SubModelDefinitionsStore::const_iterator I_subModels = mModel.getDefinition()->getSubModelDefinitions().begin(); I_subModels != mModel.getDefinition()->getSubModelDefinitions().end(); ++I_subModels) {
Ogre::MeshPtr meshPtr = static_cast<Ogre::MeshPtr> (Ogre::MeshManager::getSingleton().getByName((*I_subModels)->getMeshName()));
if (!meshPtr.isNull()) {
if (meshPtr->isLoaded()) {
Ogre::Mesh::SubMeshIterator subMeshI = meshPtr->getSubMeshIterator();
while (subMeshI.hasMoreElements()) {
Ogre::SubMesh* submesh(subMeshI.getNext());
Ogre::MaterialPtr materialPtr = static_cast<Ogre::MaterialPtr> (Ogre::MaterialManager::getSingleton().getByName(submesh->getMaterialName()));
if (materialPtr.isNull() || !materialPtr->isPrepared()) {
// S_LOG_VERBOSE("Preparing material " << materialPtr->getName());
Ogre::BackgroundProcessTicket ticket = Ogre::ResourceBackgroundQueue::getSingleton().prepare(Ogre::MaterialManager::getSingleton().getResourceType(),submesh->getMaterialName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, 0, 0, createListener());
if (ticket) {
addTicket(ticket);
}
}
}
}
}
for (PartDefinitionsStore::const_iterator I_parts = (*I_subModels)->getPartDefinitions().begin(); I_parts != (*I_subModels)->getPartDefinitions().end(); ++I_parts) {
if ((*I_parts)->getSubEntityDefinitions().size() > 0) {
for (SubEntityDefinitionsStore::const_iterator I_subEntities = (*I_parts)->getSubEntityDefinitions().begin(); I_subEntities != (*I_parts)->getSubEntityDefinitions().end(); ++I_subEntities) {
const std::string& materialName = (*I_subEntities)->getMaterialName();
if (materialName != "") {
Ogre::MaterialPtr materialPtr = static_cast<Ogre::MaterialPtr> (Ogre::MaterialManager::getSingleton().getByName(materialName));
if (materialPtr.isNull() || !materialPtr->isPrepared()) {
// S_LOG_VERBOSE("Preparing material " << materialName);
Ogre::BackgroundProcessTicket ticket = Ogre::ResourceBackgroundQueue::getSingleton().prepare(Ogre::MaterialManager::getSingleton().getResourceType(), materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, 0, 0, createListener());
if (ticket) {
addTicket(ticket);
}
}
}
}
}
}
}
mState = LS_MATERIAL_PREPARING;
return poll(timeFrame);
} else if (mState == LS_MATERIAL_PREPARING) {
//.........这里部分代码省略.........
示例4: EngineSetup
//.........这里部分代码省略.........
ManualObject->position(1, 1, 1);
ManualObject->triangle(18, 19, 20);
ManualObject->position(1, 0, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(1, 0, 1);
ManualObject->triangle(21, 22, 23);
//face 5
ManualObject->position(0, 1, 0);
ManualObject->position(1, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(24, 25, 26);
ManualObject->position(1, 1, 0);
ManualObject->position(1, 1, 1);
ManualObject->position(0, 1, 1);
ManualObject->triangle(27, 28, 29);
//face 6
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 1);
ManualObject->position(0, 0, 1);
ManualObject->triangle(30, 31, 32);
ManualObject->position(0, 0, 0);
ManualObject->position(0, 1, 0);
ManualObject->position(0, 1, 1);
ManualObject->triangle(33, 34, 35);
ManualObject->end();
Ogre::MeshPtr MeshPtr = ManualObject->convertToMesh("Animation");
Ogre::SubMesh* sub = MeshPtr->getSubMesh(0);
Ogre::SkeletonPtr Skeleton = Ogre::SkeletonManager::getSingleton().create("Skeleton", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
MeshPtr.getPointer()->_notifySkeleton(Skeleton);
Ogre::Bone *Root1 = NULL;
Ogre::Bone *Child1 = NULL;
Ogre::Bone *Child2 = NULL;
Root1 = Skeleton.getPointer()->createBone("Root");
Root1->setPosition(Ogre::Vector3(0.0, 0.0, 0.0));
Root1->setOrientation(Ogre::Quaternion::IDENTITY);
Child1 = Root1->createChild(1);
Child1->setPosition(Ogre::Vector3(4.0, 0.0, 0.0));
Child1->setOrientation(Ogre::Quaternion::IDENTITY);
Child2 = Root1->createChild(2);
Child2->setPosition(Ogre::Vector3(5.0, 0.0, 0.0));
Child2->setOrientation(Ogre::Quaternion::IDENTITY);
Ogre::VertexBoneAssignment Assignment;
Assignment.boneIndex = 0;
Assignment.vertexIndex = 0;
Assignment.weight = 1.0;
Skeleton->setBindingPose();
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 1;
sub->addBoneAssignment(Assignment);
Assignment.vertexIndex = 2;
sub->addBoneAssignment(Assignment);
Ogre::Animation *Animation = MeshPtr->createAnimation("HandAnimation", 100.0);
Ogre::NodeAnimationTrack *Track = Animation->createNodeTrack(0, Root1);
Ogre::TransformKeyFrame *KeyFrame = NULL;
for (float FrameTime = 0.0; FrameTime < 100.0; FrameTime += 0.1)
{
KeyFrame = Track->createNodeKeyFrame(FrameTime);
KeyFrame->setTranslate(Ogre::Vector3(10.0, 0.0, 0.0));
}
Root1->setManuallyControlled(true);
Child1->setManuallyControlled(true);
Child2->setManuallyControlled(true);
MeshPtr->load();
MeshPtr.getPointer()->_notifySkeleton(Skeleton);
// Ogre::SkeletonSerializer skeletonSerializer;
// skeletonSerializer.exportSkeleton(Skeleton.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.skeleton");
// Ogre::MeshSerializer ser;
// ser.exportMesh(MeshPtr.get(), "C:\\Users\\Ilya\\Documents\\Visual Studio 2010\\Projects\\Recipes\\media\\models\\testskeleton.mesh");
Ogre::Entity *Entity = SceneManager->createEntity("Animation", "Animation"/*"testskeleton.mesh"*/);
Ogre::SceneNode *SceneNode = SceneManager->getRootSceneNode()->createChildSceneNode();
SceneNode->attachObject(Entity);
Entity->setDisplaySkeleton(true);
m_AnimationState = Entity->getAnimationState("HandAnimation");
m_AnimationState->setEnabled(true);
m_AnimationState->setLoop(true);
m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
Root->renderOneFrame();
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:101,代码来源:SceletalAnimationView.cpp
示例5: TOSTRING
//.........这里部分代码省略.........
size_t offset = 0;
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);
// Create and bind vertex buffer
mesh->sharedVertexData->vertexCount = 14;
Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
mesh->sharedVertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
// Vertex data
static const float vertexData[] = {
// Position Texture coordinates // Index
0.0, 2.0, -1.0, 1.0, 1.0, // 0
0.0, 1.0, -1.0, -1.0, 1.0, // 1
1.0, 2.0, -1.0, 1.0, -1.0, // 2
1.0, 1.0, -1.0, -1.0, -1.0, // 3
2.0, 2.0, 1.0, 1.0, -1.0, // 4
2.0, 1.0, 1.0, -1.0, -1.0, // 5
3.0, 2.0, 1.0, 1.0, 1.0, // 6
3.0, 1.0, 1.0, -1.0, 1.0, // 7
4.0, 2.0, -1.0, 1.0, 1.0, // 8
4.0, 1.0, -1.0, -1.0, 1.0, // 9
1.0, 3.0, -1.0, 1.0, 1.0, // 10
2.0, 3.0, 1.0, 1.0, 1.0, // 11
1.0, 0.0, -1.0, -1.0, 1.0, // 12
2.0, 0.0, 1.0, -1.0, 1.0, // 13
};
// Fill vertex buffer
float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
{
// Position
*pData++ = position.x + scale * vertexData[i++];
*pData++ = position.y + scale * vertexData[i++];
*pData++ = 0.0;
// Texture coordinates
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
}
vertexBuffer->unlock();
// Create index buffer
sub->indexData->indexCount = 36;
Ogre::HardwareIndexBufferSharedPtr indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
sub->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
sub->indexData->indexBuffer = indexBuffer;
// Index data
static const Ogre::uint16 indexData[] = {
// Indices // Face
0, 1, 2, // 0
2, 1, 3, // 1
2, 3, 4, // 2
4, 3, 5, // 3
4, 5, 6, // 4
6, 5, 7, // 5
6, 7, 8, // 6
8, 7, 9, // 7
10, 2, 11, // 8
11, 2, 4, // 9
3, 12, 5, // 10
5, 12, 13, // 11
};
// Fill index buffer
indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData, true);
mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE);
mesh->_setBoundingSphereRadius(10);
mesh->load();
Ogre::Entity* e = gEnv->sceneManager->createEntity(mesh->getName());
e->setCastShadows(false);
e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
e->setVisible(true);
e->setMaterialName("tracks/EnvMapDebug");
Ogre::SceneNode* mDebugSceneNode = new Ogre::SceneNode(gEnv->sceneManager);
mDebugSceneNode->attachObject(e);
mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5));
mDebugSceneNode->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
mDebugSceneNode->setVisible(true);
mDebugSceneNode->_update(true, true);
mDebugSceneNode->_updateBounds();
overlay->add3D(mDebugSceneNode);
overlay->show();
}
}
}
示例6: generateSphericDome
void GeometryFactory::generateSphericDome (const Ogre::String &name, int segments, DomeType type) {
// Return now if already exists
if (Ogre::MeshManager::getSingleton ().resourceExists (name)) {
return;
}
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: Creating " + name + " sphere mesh resource...");
// Use the mesh manager to create the mesh
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton ().createManual (name, RESOURCE_GROUP_NAME);
// Create a submesh
Ogre::SubMesh *sub = msh->createSubMesh ();
// Create the shared vertex data
Ogre::VertexData *vertexData = new Ogre::VertexData ();
msh->sharedVertexData = vertexData;
// Define the vertices' format
Ogre::VertexDeclaration *vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// Position
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Normal
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3);
// Texture coordinates
vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT2);
// Allocate the vertex buffer
switch (type) {
case DT_GRADIENTS:
vertexData->vertexCount = segments * (segments - 1) + 2;
break;
case DT_STARFIELD:
vertexData->vertexCount = (segments + 1) * (segments + 1);
break;
};
Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton ().createVertexBuffer (vertexDecl->getVertexSize (0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::VertexBufferBinding *binding = vertexData->vertexBufferBinding;
binding->setBinding (0, vBuf);
float *pVertex = static_cast<float *>(vBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Allocate the index buffer
switch (type) {
case DT_GRADIENTS:
sub->indexData->indexCount = 2 * segments * (segments - 1) * 3;
break;
case DT_STARFIELD:
sub->indexData->indexCount = 2 * (segments - 1) * segments * 3;
break;
};
sub->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton ().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_16BIT, sub->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::HardwareIndexBufferSharedPtr iBuf = sub->indexData->indexBuffer;
unsigned short *pIndices = static_cast<unsigned short *>(iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD));
// Fill the buffers
switch (type) {
case DT_GRADIENTS:
fillGradientsDomeBuffers (pVertex, pIndices, segments);
break;
case DT_STARFIELD:
fillStarfieldDomeBuffers (pVertex, pIndices, segments);
break;
};
// Close the vertex buffer
vBuf->unlock ();
// Close the index buffer
iBuf->unlock ();
// Finishing it...
sub->useSharedVertices = true;
msh->_setBounds (Ogre::AxisAlignedBox (-1, -1, -1, 1, 1, 1), false);
msh->_setBoundingSphereRadius (1);
msh->load ();
Ogre::LogManager::getSingleton ().logMessage (
"Caelum: generateSphericDome DONE");
}
示例7: sqrt
//.........这里部分代码省略.........
100.0,100.0,100.0, //5 position
sqrt13,sqrt13,sqrt13, //5 normal
100.0,-100.0,100.0, //6 position
sqrt13,-sqrt13,sqrt13, //6 normal
-100.0,-100.0,100.0, //7 position
-sqrt13,-sqrt13,sqrt13, //7 normal
};
RenderSystem* rs = Root::getSingleton().getRenderSystem();
RGBA colours[nVertices];
RGBA *pColour = colours;
// Use render system to convert colour value since colour packing varies
rs->convertColourValue(ColourValue(1.0,0.0,0.0), pColour++); //0 colour
rs->convertColourValue(ColourValue(1.0,1.0,0.0), pColour++); //1 colour
rs->convertColourValue(ColourValue(0.0,1.0,0.0), pColour++); //2 colour
rs->convertColourValue(ColourValue(0.0,0.0,0.0), pColour++); //3 colour
rs->convertColourValue(ColourValue(1.0,0.0,1.0), pColour++); //4 colour
rs->convertColourValue(ColourValue(1.0,1.0,1.0), pColour++); //5 colour
rs->convertColourValue(ColourValue(0.0,1.0,1.0), pColour++); //6 colour
rs->convertColourValue(ColourValue(0.0,0.0,1.0), pColour++); //7 colour
/// Define 12 triangles (two triangles per cube face)
/// The values in this table refer to vertices in the above table
const size_t ibufCount = 36;
unsigned short faces[ibufCount] = {
0,2,3,
0,1,2,
1,6,2,
1,5,6,
4,6,5,
4,7,6,
0,7,4,
0,3,7,
0,5,1,
0,4,5,
2,7,3,
2,6,7
};
/// Create vertex data structure for 8 vertices shared between submeshes
msh->sharedVertexData = new VertexData();
msh->sharedVertexData->vertexCount = nVertices;
/// Create declaration (memory format) of vertex data
VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
offset += VertexElement::getTypeSize(VET_FLOAT3);
decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
offset += VertexElement::getTypeSize(VET_FLOAT3);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
HardwareVertexBufferSharedPtr vbuf =
HardwareBufferManager::getSingleton().createVertexBuffer(
offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
// 2nd buffer
offset = 0;
decl->addElement(1, offset, VET_COLOUR, VES_DIFFUSE);
offset += VertexElement::getTypeSize(VET_COLOUR);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
offset, msh->sharedVertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), colours, true);
/// Set vertex buffer binding so buffer 1 is bound to our colour buffer
bind->setBinding(1, vbuf);
/// Allocate index buffer of the requested number of vertices (ibufCount)
HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
createIndexBuffer(
HardwareIndexBuffer::IT_16BIT,
ibufCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
/// Set parameters of the submesh
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
/// Set bounding information (for culling)
msh->_setBounds(AxisAlignedBox(-100,-100,-100,100,100,100));
msh->_setBoundingSphereRadius(Math::Sqrt(3*100*100));
/// Notify -Mesh object that it has been loaded
msh->load();
}
示例8: LoadSceneFile
void World::LoadSceneFile(string sceneFile)
{
Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_LOW);
Ogre::SceneNode* worldNode = m_sceneMgr->getRootSceneNode()->createChildSceneNode();
worldNode->rotate(Ogre::Vector3::UNIT_X, Ogre::Degree(-90.0f));
string meshName;
float fDrawDistance;
bool bIsLod;
Ogre::Vector3 position;
Ogre::Quaternion rotation;
ifstream sceneStream(sceneFile);
// skip the title and the table title of the file
string strline;
int i = 0;
while (!sceneStream.eof())
{
getline(sceneStream, strline);
if (strline.length() == 0)
continue;
std::istringstream ss(strline);
std::string token;
getline(ss, token, ',');
boost::trim(token);
meshName = token;
getline(ss, token, ',');
boost::trim(token);
fDrawDistance = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
bIsLod = lexical_cast<bool>(token);
getline(ss, token, ',');
boost::trim(token);
position.x = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
position.y = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
position.z = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
rotation.w = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
rotation.x = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
rotation.y = lexical_cast<float>(token);
getline(ss, token, ',');
boost::trim(token);
rotation.z = lexical_cast<float>(token);
Ogre::MeshPtr mesh;
Ogre::Entity* entity;
Ogre::Entity* realEntity = m_sceneMgr->createEntity(meshName);
if (fDrawDistance > 300.0f && !bIsLod)
continue;
if (bIsLod)
{
mesh = Ogre::MeshManager::getSingleton().createManual(meshName + "lod" + std::to_string(i), "General"); // empty mesh
mesh->createManualLodLevel(0, "NULL");
mesh->createManualLodLevel(700, meshName);
mesh->_setBounds( realEntity->getMesh()->getBounds());
mesh->_setBoundingSphereRadius(realEntity->getMesh()->getBoundingSphereRadius());
mesh->load();
entity->setRenderingDistance(fDrawDistance);
entity = m_sceneMgr->createEntity(mesh->getName());
}
else
{
mesh = Ogre::MeshManager::getSingleton().getByName(meshName);
entity = m_sceneMgr->createEntity(meshName);
entity->setRenderingDistance(fDrawDistance);
}
m_sceneMgr->destroyEntity(realEntity);
Ogre::SceneNode* sceneNode = worldNode->createChildSceneNode();
sceneNode->attachObject(entity);
fix_gta_coord(rotation);
sceneNode->rotate(rotation);
sceneNode->setPosition(position);
i++;
//.........这里部分代码省略.........
示例9: createSphere
void TutorialApplication::createSphere(const std::string& strName, const float r, const int nRings, const int nSegments) {
Ogre::MeshPtr pSphere = Ogre::MeshManager::getSingleton().createManual(Ogre::String(strName), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::SubMesh *pSphereVertex = pSphere->createSubMesh();
pSphere->sharedVertexData = new Ogre::VertexData();
Ogre::VertexData* vertexData = pSphere->sharedVertexData;
// define the vertex format
Ogre::VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
size_t currOffset = 0;
// positions
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// normals
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// two dimensional texture coordinates
vertexDecl->addElement(0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
// allocate the vertex buffer
vertexData->vertexCount = (nRings + 1) * (nSegments+1);
Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::VertexBufferBinding* binding = vertexData->vertexBufferBinding;
binding->setBinding(0, vBuf);
float* pVertex = static_cast<float*>(vBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
// allocate index buffer
pSphereVertex->indexData->indexCount = 6 * nRings * (nSegments + 1);
pSphereVertex->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, pSphereVertex->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
Ogre::HardwareIndexBufferSharedPtr iBuf = pSphereVertex->indexData->indexBuffer;
unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
float fDeltaRingAngle = (Ogre::Math::PI / nRings);
float fDeltaSegAngle = (2 * Ogre::Math::PI / nSegments);
unsigned short wVerticeIndex = 0 ;
// Generate the group of rings for the sphere
for( int ring = 0; ring <= nRings; ring++ ) {
float r0 = r * sinf (ring * fDeltaRingAngle);
float y0 = r * cosf (ring * fDeltaRingAngle);
// Generate the group of segments for the current ring
for(int seg = 0; seg <= nSegments; seg++) {
float x0 = r0 * sinf(seg * fDeltaSegAngle);
float z0 = r0 * cosf(seg * fDeltaSegAngle);
// Add one vertex to the strip which makes up the sphere
*pVertex++ = x0;
*pVertex++ = y0;
*pVertex++ = z0;
Ogre::Vector3 vNormal = Ogre::Vector3(x0, y0, z0).normalisedCopy();
*pVertex++ = vNormal.x;
*pVertex++ = vNormal.y;
*pVertex++ = vNormal.z;
*pVertex++ = (float) seg / (float) nSegments;
*pVertex++ = (float) ring / (float) nRings;
if (ring != nRings) {
// each vertex (except the last) has six indices pointing to it
*pIndices++ = wVerticeIndex + nSegments + 1;
*pIndices++ = wVerticeIndex;
*pIndices++ = wVerticeIndex + nSegments;
*pIndices++ = wVerticeIndex + nSegments + 1;
*pIndices++ = wVerticeIndex + 1;
*pIndices++ = wVerticeIndex;
wVerticeIndex ++;
}
}; // end for seg
} // end for ring
// Unlock
vBuf->unlock();
iBuf->unlock();
// Generate face list
pSphereVertex->useSharedVertices = true;
// the original code was missing this line:
pSphere->_setBounds( Ogre::AxisAlignedBox( Ogre::Vector3(-r, -r, -r), Ogre::Vector3(r, r, r) ), false );
pSphere->_setBoundingSphereRadius(r);
// this line makes clear the mesh is loaded (avoids memory leaks)
pSphere->load();
}