Drawing a Flexible Object made of Vertices (FAST)

Problems building or running the engine, queries about how to use features etc.

Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Wed Aug 30, 2017 3:22 pm

HI

I am looking to see the fastest possible way to draw a soft object made of vertices in OGRE.

I have an physics base model of an object that will calculate the vertex position of my VISUAL object vertices
every frame. I would like to draw this object to OGRE.

I am currently using a ManualObject that I create and draw the element and destroy each iteration. I think this
is a slow process. I am looking to see if there is a faster way to do this. If you have examples to provide that would
be great too.

Thanks
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Feanor16 » Thu Aug 31, 2017 9:13 am

ManualObject is outdated in Ogre 2.1 but you can use
Ogre::MeshPtr then create a Mesh mannually with getSingleton().createManual(const String& name, const String& groupName, ManualResourceLoader* loader = 0)
then create a VertexDeclaration to make your vertex point per point with indices

but that is a static build. To have something dynamic, Check out the samples "CustomRenderable" and "DynamicGeometry"
Feanor16
Kobold
 
Posts: 39
Kudos: 0
Joined: 18 Feb 2014

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby al2950 » Thu Aug 31, 2017 11:00 am

as Feanor16 said check out the "CustomRenderable" and "DynamicGeometry".

Do not use ManualObject even for static meshes! It was put in to help people port projects from 1.x, but it does not make sense in 2.1 and it is lacking a lot of features and is slooooooooooooooooooooow! Happy to help if you have any questions regarding the 2 sample projects. It may take a few attempts to get your head around it, but when you do it is very easy, (I would say it is easier than ManualObject.. or at least easier to follow for me anyway!)
al2950
OGRE Expert User
OGRE Expert User
 
Posts: 986
Kudos: 69
Joined: 11 Dec 2008
Location: Bristol, UK

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Thu Aug 31, 2017 6:28 pm

I am currently using 1.10.8 Ogre version are these samples available for this version? I am not using 2.1 yet.
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby al2950 » Thu Aug 31, 2017 7:56 pm

Sorry i jumped to the conclusion you were using 2.1.

Its been a while since i looked at ogre 1.x, however I had to do something similar and i used ManualObject. I believe manual object has a 'dynamic' mode, and you can reserve the max number of vertices you are going to use and then you can update it each frame.

ill try and dig out some old code if you get stuck.

FYI, it still might not be as fast as you require, so you may need to deal with hardware buffers which is not pleasant in 1.x. :(
al2950
OGRE Expert User
OGRE Expert User
 
Posts: 986
Kudos: 69
Joined: 11 Dec 2008
Location: Bristol, UK

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Sun Sep 03, 2017 1:28 am

If you have a sample code for this that would be greatly appreciated.

Thanks
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby al2950 » Sun Sep 03, 2017 12:11 pm

Something like this;

on construction:
Code: Select all
        m_manualObject = m_sceneMgr->createManualObject();
        m_manualObject->setDynamic(true);
        m_manualObject->estimateVertexCount(totalPossibleVertices);
        m_manualObject->estimateIndexCount(totalPossibleIndices);

        //put some initial data in
        m_manualObject->begin(m_material, Ogre::RenderOperation::OT_TRIANGLE_LIST);
        //fill in data ....
        m_manualObject->end();


on update:
Code: Select all
   //reset boundung box before update
   m_manualObject->setBoundingBox(Ogre::AxisAlignedBox::EXTENT_FINITE);

   //begin update of vertex buffers
   m_manualObject->beginUpdate(0);
       //fill in data just like you would normally ....
   m_manualObject->end();

        //dont forget to update the bounding box of the parent scene node.
   m_parentNode->_updateBounds();


I think that should work! But again its not the most efficient way of doing things, but should be better than creating a new manual object every frame.
al2950
OGRE Expert User
OGRE Expert User
 
Posts: 986
Kudos: 69
Joined: 11 Dec 2008
Location: Bristol, UK

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby paroj » Sun Sep 03, 2017 12:21 pm

the suggestion by al2950 is quite good already.

If your data is stored consecutively, you might save a memcpy by writing to the HardwareVertexBuffers directly:
http://www.ogre3d.org/tikiwiki/Generating+A+Mesh
paroj
OGRE Team Member
OGRE Team Member
 
Posts: 247
Kudos: 53
Joined: 30 Mar 2014

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Mon Sep 04, 2017 2:48 pm

Thanks very much
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Wed Sep 13, 2017 9:17 pm

I could use some direction here Please :)

Code: Select all
void MyTestApp::createColourCube()
{
   /// Create the mesh via the MeshManager
   Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual("ColourCube", "General");

   /// Create one submesh
   Ogre::SubMesh* sub = msh->createSubMesh();

   const float sqrt13 = 0.577350269f; /* sqrt(1/3) */

                              /// Define the vertices (8 vertices, each have 3 floats for position and 3 for normal)
   const size_t nVertices = 8;
   const size_t vbufCount = 3 * 2 * nVertices;
   float vertices[vbufCount] = {
      -10.0,10.0,-10.0,        //0 position
      -sqrt13,sqrt13,-sqrt13,     //0 normal
      10.0,10.0,-10.0,         //1 position
      sqrt13,sqrt13,-sqrt13,      //1 normal
      10.0,-10.0,-10.0,        //2 position
      sqrt13,-sqrt13,-sqrt13,     //2 normal
      -10.0,-10.0,-10.0,       //3 position
      -sqrt13,-sqrt13,-sqrt13,    //3 normal
      -10.0,10.0,10.0,         //4 position
      -sqrt13,sqrt13,sqrt13,      //4 normal
      10.0,10.0,10.0,          //5 position
      sqrt13,sqrt13,sqrt13,       //5 normal
      10.0,-10.0,10.0,         //6 position
      sqrt13,-sqrt13,sqrt13,      //6 normal
      -10.0,-10.0,10.0,        //7 position
      -sqrt13,-sqrt13,sqrt13,     //7 normal
   };

   Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
   Ogre::RGBA colours[nVertices];
   Ogre::RGBA *pColour = colours;
   // Use render system to convert colour value since colour packing varies
   rs->convertColourValue(Ogre::ColourValue(1.0, 0.0, 0.0), pColour++); //0 colour
   rs->convertColourValue(Ogre::ColourValue(1.0, 1.0, 0.0), pColour++); //1 colour
   rs->convertColourValue(Ogre::ColourValue(0.0, 1.0, 0.0), pColour++); //2 colour
   rs->convertColourValue(Ogre::ColourValue(0.0, 0.0, 0.0), pColour++); //3 colour
   rs->convertColourValue(Ogre::ColourValue(1.0, 0.0, 1.0), pColour++); //4 colour
   rs->convertColourValue(Ogre::ColourValue(1.0, 1.0, 1.0), pColour++); //5 colour
   rs->convertColourValue(Ogre::ColourValue(0.0, 1.0, 1.0), pColour++); //6 colour
   rs->convertColourValue(Ogre::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 Ogre::VertexData();
   msh->sharedVertexData->vertexCount = nVertices;

   /// Create declaration (memory format) of vertex data
   Ogre::VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
   size_t offset = 0;
   // 1st buffer
   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);
   /// Allocate vertex buffer of the requested number of vertices (vertexCount)
   /// and bytes per vertex (offset)
   Ogre::HardwareVertexBufferSharedPtr vbuf =
      Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
         offset, msh->sharedVertexData->vertexCount, Ogre::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
   Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
   bind->setBinding(0, vbuf);

   // 2nd buffer
   offset = 0;
   decl->addElement(1, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
   offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
   /// Allocate vertex buffer of the requested number of vertices (vertexCount)
   /// and bytes per vertex (offset)
   vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
      offset, msh->sharedVertexData->vertexCount, Ogre::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)
   Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
      createIndexBuffer(
         Ogre::HardwareIndexBuffer::IT_16BIT,
         ibufCount,
         Ogre::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(Ogre::AxisAlignedBox(-10, -10, -10, 10, 10, 10));
   msh->_setBoundingSphereRadius(Ogre::Math::Sqrt(3 * 10 * 10));

   /// Notify -Mesh object that it has been loaded
   msh->load();
}


Above code is from the wiki provided above. I have used it as follows:

In my project during setup I do the following (I can see the static cube drawn).

Code: Select all
        createColourCube();

   mEntity = mScnMgr->createEntity("cc", "ColourCube");
   mEntity->setMaterialName("Examples/BeachStones");
   mSceneNode = mScnMgr->getRootSceneNode()->createChildSceneNode();
   mSceneNode->setPosition(0, 0, 100);
   mSceneNode->attachObject(mEntity);


I changed the vertexdata and did a write buffer in frameRenderingQueued() as below.
So I assume to see a change in shape at least from the initial 10x10x10 to 25x25x25 after this
writedata executes... But there is no change in shape the cube is still 10x10x10.

Code: Select all
   const float sqrt13 = 0.577350269f;
   float vertices[48] = {
      -25.0,25.0,-25.0,        //0 position
      -sqrt13,sqrt13,-sqrt13,     //0 normal
      25.0,25.0,-25.0,         //1 position
      sqrt13,sqrt13,-sqrt13,      //1 normal
      25.0,-25.0,-25.0,        //2 position
      sqrt13,-sqrt13,-sqrt13,     //2 normal
      -25.0,-25.0,-25.0,       //3 position
      -sqrt13,-sqrt13,-sqrt13,    //3 normal
      -25.0,25.0,25.0,         //4 position
      -sqrt13,sqrt13,sqrt13,      //4 normal
      25.0,25.0,25.0,          //5 position
      sqrt13,sqrt13,sqrt13,       //5 normal
      25.0,-25.0,25.0,         //6 position
      sqrt13,-sqrt13,sqrt13,      //6 normal
      -25.0,-25.0,25.0,        //7 position
      -sqrt13,-sqrt13,sqrt13,     //7 normal
   };

   mvbuf->writeData(0, mvbuf->getSizeInBytes(), vertices, true);


What am I doing wrong to update the cube to 25x25x25 as the vertexdata in the frameRenderingQueued() shows..
Do I have to explicitly call render? if so how do I do that?

Thanks
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Fri Sep 15, 2017 10:24 pm

I am stuck.. I think I have tried everything I can to update the vertices of the cube after it is first created.
I see the 10x10x10 cube in the render window.... but it never becomes 25x25x25 cube after the frameRenderingQueued()
its like it never gets the new data or does not update the draw on the object.

What am I doing wrong????
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby al2950 » Mon Sep 18, 2017 10:10 pm

Sorry I never got my hands dirty with ogre 1.x hardwareVertexBuffers. I would suggest looking through the manual object code to get some ideas!
al2950
OGRE Expert User
OGRE Expert User
 
Posts: 986
Kudos: 69
Joined: 11 Dec 2008
Location: Bristol, UK

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Tue Sep 19, 2017 3:45 am

Can you point me to the manual object code samples i should look at.
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby al2950 » Tue Sep 19, 2017 9:39 am

I would start by looking at how manual object manipulates hardwareVertexBufferes like here;
https://bitbucket.org/sinbad/ogre/src/a ... ct.cpp-618
al2950
OGRE Expert User
OGRE Expert User
 
Posts: 986
Kudos: 69
Joined: 11 Dec 2008
Location: Bristol, UK

Re: Drawing a Flexible Object made of Vertices (FAST)

Postby Garibalde » Tue Sep 19, 2017 4:00 pm

Is it worth switching to 2.1? I am not great at Ogre. So is it stable enough for rendering objects.
My use is for rendering flexible structures with changing vertices positions. Also have static mesh also.

I would like textures and all the shaders. I assume 2.1 is in development so has bugs and issues that
I would not be able to resolve myself.

Do you advice in my case to switch to 2.1 is a benefit?

Thanks
Garibalde
VIRMED Simulation Technologies Inc.
http://www.virmed.com
Garibalde
Halfling
 
Posts: 61
Kudos: 0
Joined: 16 Apr 2009
Location: Montreal, Quebec


Return to Help

Who is online

Users browsing this forum: Garibalde, Google [Bot] and 7 guests