本文整理汇总了C++中ogre::MeshPtr::_setBoundingSphereRadius方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::_setBoundingSphereRadius方法的具体用法?C++ MeshPtr::_setBoundingSphereRadius怎么用?C++ MeshPtr::_setBoundingSphereRadius使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::_setBoundingSphereRadius方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: aabb
Ogre::Entity*
ModelFile::GetModel( const ModelInfo& info )
{
VectorTexForGen textures;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create( info.data.name + "export", "General" );
Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create( info.data.name + "export", "General" );
int number_of_bones = GetU8( 0x02 );
int number_of_parts = GetU8( 0x03 );
int offset_to_bones = GetU32LE( 0x0c );
int offset_to_parts = GetU32LE( 0x10 );
Ogre::Bone* root1 = skeleton->createBone( "0", 0 );
Ogre::Bone* root2 = skeleton->createBone( "1", 1 );
root1->addChild( root2 );
for( int i = 0; i < number_of_bones; ++i )
{
Bone bone;
bone.parent_id = ( i != 0 ) ? ( s8 )GetU8( offset_to_bones + i * 0x04 + 0x03 ) : -1;
bone.length = ( s16 )GetU16LE( offset_to_bones + i * 0x04 + 0x00 );
m_Skeleton.push_back(bone);
Ogre::Bone* bone1 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 2 ), i * 2 + 2 );
Ogre::Bone* bone2 = skeleton->createBone( Ogre::StringConverter::toString( i * 2 + 3 ), i * 2 + 3 );
LOGGER->Log( "Add skeleton bone: bone_id = " + Ogre::StringConverter::toString( i ) + ", length = " + Ogre::StringConverter::toString( bone.length ) + ", parent = " + Ogre::StringConverter::toString( bone.parent_id ) + ".\n" );
if( bone.parent_id == -1 )
{
skeleton->getBone( 1 )->addChild( bone1 );
}
else
{
skeleton->getBone( bone.parent_id * 2 + 3 )->addChild( bone1 );
}
bone1->addChild( bone2 );
}
AnimationExtractor( skeleton, info, m_Skeleton );
// draw skeleton
{
//DrawSkeleton( m_Skeleton, mesh );
}
for( int i = 0; i < number_of_parts; ++i )
{
MeshExtractor( info.data, "ffix/field_model/" + info.data.name, this, offset_to_parts + i * 0x28, textures, mesh );
}
// <OGRE> ///////////////////////////////
skeleton->optimiseAllAnimations();
Ogre::SkeletonSerializer skeleton_serializer;
skeleton_serializer.exportSkeleton( skeleton.getPointer(), "exported/models/field/units/" + info.data.name + ".skeleton" );
// Update bounds
Ogre::AxisAlignedBox aabb( -999, -999, -999, 999, 999, 999 );
mesh->_setBounds( aabb, false );
mesh->_setBoundingSphereRadius( 999 );
mesh->setSkeletonName( "models/field/units/" + info.data.name + ".skeleton" );
Ogre::MeshSerializer ser;
ser.exportMesh( mesh.getPointer(), "exported/models/field/units/" + info.data.name + ".mesh" );
// create and export textures for model
//if (textures.size() > 0)
{
Vram* vram = new Vram();
File* tex = new File( "./data/field/5/1b/2/4/1.tim" );
LoadTimFileToVram( tex, 0, vram );
delete tex;
tex = new File( "./data/field/5/1b/2/4/2.tim" );
LoadTimFileToVram( tex, 0, vram );
delete tex;
vram->Save( "1.jpg" );
CreateTexture( vram, info.data, "exported/models/field/units/" + info.data.name + ".png", textures );
delete vram;
}
CreateMaterial( "ffix/field_model/" + info.data.name, "exported/models/field/units/" + info.data.name + ".material", ( textures.size() > 0 ) ? "models/field/units/" + info.data.name + ".png" : "", "", "" );
//.........这里部分代码省略.........
示例3: doExportMesh
//.........这里部分代码省略.........
// Face index
pIdx[j+k] = vertIdx;
// Vertex normals
// For the moment, ignore any discrepancies per vertex
msTriangleEx_GetNormal(pTriangleEx, k, &Normal[0]);
msTriangleEx_GetTexCoord(pTriangleEx, k, &uv[0]);
pTex[(vertIdx*2)]=uv[0];
pTex[(vertIdx*2)+1]=uv[1];
pNorm[(vertIdx*3)] = Normal[0];
pNorm[(vertIdx*3)+1] = Normal[1];
pNorm[(vertIdx*3)+2] = Normal[2];
}
} // Faces
nbuf->unlock();
ibuf->unlock();
tbuf->unlock();
// Now use Ogre's ability to reorganise the vertex buffers the best way
Ogre::VertexDeclaration* newDecl =
ogreSubMesh->vertexData->vertexDeclaration->getAutoOrganisedDeclaration(
foundBoneAssignment, false);
Ogre::BufferUsageList bufferUsages;
for (size_t u = 0; u <= newDecl->getMaxSource(); ++u)
bufferUsages.push_back(Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ogreSubMesh->vertexData->reorganiseBuffers(newDecl, bufferUsages);
logMgr.logMessage("Geometry done.");
} // SubMesh
// Set bounds
ogreMesh->_setBoundingSphereRadius(Ogre::Math::Sqrt(maxSquaredRadius));
ogreMesh->_setBounds(Ogre::AxisAlignedBox(min, max), false);
// Keep hold of a Skeleton pointer for deletion later
// Mesh uses Skeleton pointer for skeleton name
Ogre::SkeletonPtr pSkel;
if (exportSkeleton && foundBoneAssignment)
{
// export skeleton, also update mesh to point to it
pSkel = doExportSkeleton(pModel, ogreMesh);
}
else if (!exportSkeleton && foundBoneAssignment)
{
// We've found bone assignments, but skeleton is not to be exported
// Prompt the user to find the skeleton
if (!locateSkeleton(ogreMesh))
return;
}
// Export
logMgr.logMessage("Creating MeshSerializer..");
Ogre::MeshSerializer serializer;
logMgr.logMessage("MeshSerializer created.");
// Generate LODs if required
if (generateLods)
{
// Build LOD depth list
Ogre::Mesh::LodDistanceList distList;
float depth = 0;
示例4: 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();
}
}
}
示例5: dist
//.........这里部分代码省略.........
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(
offset,
data->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), &vertex_data.front(), true);
data->vertexBufferBinding->setBinding(0, vbuf);
// Setup index buffer.
Ogre::HardwareIndexBufferSharedPtr ibuf =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
index_buf.size(),
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), &index_buf.front(), true);
Ogre::SubMesh *subMesh = mesh->createSubMesh();
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = index_buf.size();
subMesh->indexData->indexStart = 0;
mesh->_setBounds(Ogre::AxisAlignedBox(bounds.min.X, bounds.min.Y, bounds.min.Z, bounds.max.X, bounds.max.Y, bounds.max.Z));
mesh->_setBoundingSphereRadius((std::max(bounds.max.X - bounds.min.X, std::max(bounds.max.Y - bounds.min.Y, bounds.max.Z - bounds.min.Z))) / 2.0);
mesh->load();
Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::String(name) + Ogre::String(m->name) + "E", Ogre::String(name) + Ogre::String(m->name));
ent->setUserAny(Ogre::Any(static_cast<l2p::UObject*>(m.get())));
ent->setMaterialName("StaticMesh/Default");
Ogre::SceneNode *node = mUnrealCordNode->createChildSceneNode();
node->attachObject(ent);
return node;
}
示例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();
}
示例10: aabb
Ogre::Entity*
StageFile::GetModel( const StageInfo& info )
{
//DumpSettings("exported/" + info.data.name + ".lua");
VectorTexForGen textures;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create(info.data.name + "export", "General");
Ogre::SkeletonPtr skeleton = Ogre::SkeletonManager::getSingleton().create(info.data.name + "export", "General");
u32 number_of_files = GetU32LE(0);
LOGGER->Log("Number of file " + IntToString(number_of_files) + "\n");
Ogre::Bone* root1 = skeleton->createBone( "0", 0 );
Ogre::Bone* root2 = skeleton->createBone( "1", 1 );
root1->addChild( root2 );
Ogre::Animation* anim = skeleton->createAnimation( "Idle", 1 );
Ogre::NodeAnimationTrack* track1 = anim->createNodeTrack( 0, root1 );
track1->removeAllKeyFrames();
Ogre::TransformKeyFrame* frame1 = track1->createNodeKeyFrame( 0 );
Ogre::Matrix3 matrix;
matrix.FromEulerAnglesYXZ( Ogre::Radian( Ogre::Degree( 0 ) ), Ogre::Radian( Ogre::Degree( -90 ) ), Ogre::Radian( Ogre::Degree( 0 ) ) );
Ogre::Quaternion rot;
rot.FromRotationMatrix( matrix );
frame1->setRotation( rot );
for (u32 i = 1; i < number_of_files - 1; ++i)
{
int offset_to_vertex = GetU32LE(0x04 + i * 0x04);
MeshExtractor(info.data, "ffvii/battle_stage/" + info.data.name, this, offset_to_vertex, textures, mesh, Ogre::StringConverter::toString(i), 1);
}
// <OGRE> ///////////////////////////////
skeleton->optimiseAllAnimations();
Ogre::SkeletonSerializer skeleton_serializer;
skeleton_serializer.exportSkeleton(skeleton.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".skeleton");
// Update bounds
Ogre::AxisAlignedBox aabb(-999, -999, -999, 999, 999, 999);
mesh->_setBounds(aabb, false);
mesh->_setBoundingSphereRadius(999);
mesh->setSkeletonName( "models/ffvii/battle/stages/" + info.data.name + ".skeleton" );
Ogre::MeshSerializer ser;
ser.exportMesh(mesh.getPointer(), "exported/models/ffvii/battle/stages/" + info.data.name + ".mesh");
// create and export textures for model
if( textures.size() > 0 )
{
int number_of_files = GetU32LE( 0x00 );
int offset_to_texture = GetU32LE( number_of_files * 0x04 );
Vram* vram = Vram::MakeInstance().release();
LoadTimFileToVram( this, offset_to_texture, vram );
//vram->Save( "qqq" );
CreateTexture( vram, info.data, "exported/models/ffvii/battle/stages/" + info.data.name + ".png", textures );
delete vram;
}
CreateMaterial("ffvii/battle_stage/" + info.data.name, "exported/models/ffvii/battle/stages/" + info.data.name + ".material", "models/ffvii/battle/stages/" + info.data.name + ".png", "", "");
Ogre::SceneManager* scene_manager = Ogre::Root::getSingleton().getSceneManager( "Scene" );
Ogre::Entity* thisEntity = scene_manager->createEntity( info.data.name, "models/ffvii/battle/stages/" + info.data.name + ".mesh" );
//thisEntity->setDisplaySkeleton(true);
//thisEntity->setDebugDisplayEnabled(true);
thisEntity->setVisible(false);
thisEntity->getAnimationState( "Idle" )->setEnabled( true );
thisEntity->getAnimationState( "Idle" )->setLoop( true );
Ogre::SceneNode* thisSceneNode = scene_manager->getRootSceneNode()->createChildSceneNode();
thisSceneNode->setPosition( 0, 0, 0 );
thisSceneNode->roll( Ogre::Radian( Ogre::Degree( 180.0f ) ) );
thisSceneNode->yaw( Ogre::Radian( Ogre::Degree( 120.0f ) ) );
thisSceneNode->pitch( Ogre::Radian( Ogre::Degree( 90.0f ) ) );
thisSceneNode->attachObject( thisEntity );
return thisEntity;
}