Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented by 鄭游駿(Yu-Chun Cheng) 2009/11/27

Similar presentations


Presentation on theme: "Presented by 鄭游駿(Yu-Chun Cheng) 2009/11/27"— Presentation transcript:

1 Presented by 鄭游駿(Yu-Chun Cheng) 2009/11/27
Ogre Manual Mesh Presented by 鄭游駿(Yu-Chun Cheng) 2009/11/27

2 Step Create a mesh Create a submesh
Decide whether you want to share vertex data or not, and then create vertex data Define static buffer for vertex position, normal, texture coordinate, and vertex index Set data of all buffers Set vertex buffer bindings Set vertex buffer declaration Define the bound of the mesh

3 Create a mesh MeshPtr mesh = MeshManager::getSingleton().createManual(
“myMesh”, // mesh name ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME // the group name which mesh belongs to );

4 Create a submesh SubMesh* subMesh = mesh->createSubMesh();

5 Decide whether you want to share vertex data or not, and then create vertex data
// By default, the value is true subMesh->useSharedVertices = false; subMesh->vertexData = new VertexData(); subMesh->vertexData->vertexStart = 0; subMesh->vertexData->vertexCount = numVertices; 1 1 2 3 2 3 4 5 4 6

6 Define static buffer for vertex position, normal, texture coordinate, and vertex index
HardwareVertexBufferSharedPtr posVertexBuffer; HardwareVertexBufferSharedPtr normalVertexBuffer; HardwareVertexBufferSharedPtr texVertexBuffer; HardwareIndexBufferSharedPtr indexBuffer;

7 3*sizeof(float), // size of one vertex data
posVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer( 3*sizeof(float), // size of one vertex data numVertices, // number of vertices HardwareBuffer::HBU_STATIC_WRITE_ONLY, // the modification method of data false // no shadow buffer ); normalVertexBuffer = … texcoordsVertexBuffers = … indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( HardwareIndexBuffer::IT_16BIT, // index type mNumFaces*3, // total face number HardwareBuffer::HBU_STATIC_WRITE_ONLY); useShadowBuffer If set to true, this buffer will be 'shadowed' by one stored in system memory rather than GPU or AGP memory. You should set this flag if you intend to read data back from the vertex buffer, because reading data from a buffer in the GPU or AGP memory is very expensive, and is in fact impossible if you specify HBU_WRITE_ONLY for the main buffer. If you use this option, all reads and writes will be done to the shadow buffer, and the shadow buffer will be synchronised with the real buffer at an appropriate time

8 Set data of all buffer -1 // Lock the entire buffer for reading / writing float *posBufData = (float*)postVertexBuffer->lock(HardwareBuffer::HBL_NORMAL); posBufData[index] = x; // Releases the lock on this buffer postVertexBuffer->unlock(); float *normalBufData = … float *texcoordsBufData = … float *indexBuffer = …

9 Set data of all buffer -2 float * _vertexBuf = new float[num];
_vertexBuf[index] = x; posVertexBuffer->writeData( 0, // offset posVertexBuffer->getSizeInBytes(), // data size _vertexBuf, // source buffer true // discard? ); normalVertexBuffer->writeData(…) texcoordsVertexBuffers->writeData(…) indexBuffer->writeData(…)

10 Set vertex buffer bindings
VertexBufferBinding *vbind = subMesh->vertexData->vertexBufferBinding ; vbind->setBinding(0, posVertexBuffer); vbind->setBinding(1, normalVertexBuffer); vbind->setBinding(2, texcoordsVertexBuffers); // index, source buffer

11 Set vertex buffer declaration
VertexDeclaration *vdecl = subMesh->vertexData->vertexDeclaration; vdecl->addElement(0, 0, VET_FLOAT3, VES_POSITION); vdecl->addElement(1, 0, VET_FLOAT3, VES_NORMAL); vdecl->addElement(2, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); // index, initial location, component number, data type

12 Set index data subMesh->indexData->indexBuffer = indexBuffer;
subMesh->indexData->indexStart = 0; subMesh->indexData->indexCount = mNumFaces*3;

13 Define the bound of the mesh
AxisAlignedBox bounds(mx, my, mz, Mx, My, Mz); mesh->_setBounds(bounds); mesh->load(); mesh->touch(); /** Loads the resource, if it is not already. If the resource is loaded from a file, loading is automatic. If not, if for example this resource gained it's data from procedural calls rather than loading from a file, then this resource will not reload on it's own. */ /** 'Touches' the resource to indicate it has been used.

14 How to use the mesh createMesh(“myMesh”);
Entity* en = mSceneMgr->createEntity(“en”, “myMesh”); en->setMaterialName("Examples/GrassFloor"); SceneNode* sn = mSceneMgr->getRootSceneNode()->createChildSceneNode(“sn”); sn->attachObject(en);

15 Create a mesh with ManualObject
// create the triangular face by using ManualObject ManualObject* manual = mSceneMgr->createManualObject("triangle"); manual->begin(MaterialName, RenderOperation::OT_TRIANGLE_LIST); manual->position(-100.0,  100.0, 0.0); manual->position(-100.0, , 0.0); manual->position( 100.0, , 0.0); manual->end(); // attach the object to a scene node SceneNode* sn = mSceneMgr->getRootSceneNode()->createChildSceneNode("SceneNode"); sn->attachObject(manual);

16 Convert Manual Object to mesh
MeshPtr mesh = manual->convertToMesh(strName); AxisAlignedBox bounds = computeBounds(); mesh->_setBounds(bounds); Then, we can use the mesh data repetitively.


Download ppt "Presented by 鄭游駿(Yu-Chun Cheng) 2009/11/27"

Similar presentations


Ads by Google