Page 1 of 1
ogre-next crrate entity from ManualObject
Posted: Wed Nov 27, 2024 8:51 pm
by jordiperezarti
I am creating a floor plane:
Ogre::ManualObject* man = this->sceneManager->createManualObject();
man->begin("Examples/floor");
....
man->end();
Code: Select all
v1::MeshPtr planeMeshPtr = man->convertToMesh("floor_meshptr");
v1::Entity *planeEntity = sceneManager->createEntity(planeMeshPtr);
planeEntity->getMesh()->buildTangentVectors();
this->sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(planeEntity);
When compiling fails, appears some errors in the OgreSharedPtr.h
Someone has tried this before?
Re: ogre-next crrate entity from ManualObject
Posted: Thu Dec 05, 2024 4:06 am
by rpgplayerrobin
It can be a number of different things that can cause this I think.
You must supply your full code in order to know for sure though, but if you do not supply to manual object what is needed to calculate tangents, it is impossible to do the calculations, which may make it crash even (last time I checked).
I think you need position, UV and normal per vertex in order to be able to generate tangents.
If you have all those 3 per vertex and it still fails, try to also add a Vector3::ZERO for tangents per vertex as well, as creating them later might just replace the ones you added.
But I would suggest you to build Ogre from source in order to be able to debug these kind of crashes, because in that case it would most likely show what caused it to crash in more detail.
Re: ogre-next crrate entity from ManualObject
Posted: Thu Dec 05, 2024 5:08 pm
by jordiperezarti
Ogre::ManualObject* man = this->sceneManager->createManualObject();
man->begin("Examples/floor");
Code: Select all
man->position(-200, 0, 200);
man->normal(0, 1, 0);
man->textureCoord(0, 0);
man->position(-200, 0, -200);
man->normal(0, 1, 0);
man->textureCoord(0, 1);
man->position(200, 0, -200);
man->normal(0, 1, 0);
man->textureCoord(1, 1);
man->position(200, 0, 200);
man->normal(0, 1, 0);
man->textureCoord(1, 0);
man->quad(0, 1, 2, 3);
man->end();
man->setCastShadows(false);
MeshPtr planeMeshPtr = man->convertToMesh("floor_meshptr");
v1::MeshPtr v1PlaneMeshPtr;
v1PlaneMeshPtr->importV2(planeMeshPtr.get());
v1::Entity *planeEntity = sceneManager->createEntity(v1PlaneMeshPtr);
Seems that i need to convert from Mesh to v1:Mesh,
here is crashing at:
Code: Select all
v1PlaneMeshPtr->importV2(planeMeshPtr.get());
because the pointer is not allocated yet.
But how do i allocate the v1PlaneMeshPtr? which is the constructor or how i get a new instance?
Re: ogre-next crrate entity from ManualObject
Posted: Sat Dec 07, 2024 4:43 am
by rpgplayerrobin
If planeMeshPtr simply is null, have you debugged why that happens in convertToMesh?
Because the convertToMesh function in my version of Ogre works correctly with your code, and using "Mesh* test = planeMeshPtr.get();" does not return a null pointer.
Re: ogre-next crrate entity from ManualObject
Posted: Sat Dec 07, 2024 9:44 am
by jordiperezarti
the convertToMesh call is right,
the problem is in the next line:
Code: Select all
v1::MeshPtr v1PlaneMeshPtr;
v1PlaneMeshPtr->importV2(planeMeshPtr.get());
i need to allocate the v1PlaneMeshPtr, class of v1::MeshPtr
but i dont know hot to get the new instance from v1::MeshPtr
Re: ogre-next crrate entity from ManualObject
Posted: Sun Dec 08, 2024 11:06 pm
by rpgplayerrobin
I would guess it is the same like any other manual mesh is created:
Code: Select all
MeshPtr v1PlaneMeshPtr = MeshManager::getSingleton().createManual("testmesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Re: ogre-next crrate entity from ManualObject
Posted: Mon Dec 09, 2024 3:31 pm
by jordiperezarti
MeshManager::getSingleton().createManual(...)
returns MeshPtr, but i am looking for v1::MeshPtr
why?
v1::Entity *planeEntity = sceneManager->createEntity(v1PlaneMeshPtr);
only accepts v1:MeshPtr as argument, doesn't compile with MeshPtr as argument
Re: ogre-next crrate entity from ManualObject
Posted: Mon Dec 09, 2024 9:05 pm
by rpgplayerrobin
Since I don't use OgreNext I have no idea how to help with this, but it should not be that hard to create a v2 or v1 mesh in it. There must be some documentation regarding this in your version, even a simple F12 in Visual Studio on the function should show you exactly why it cannot use a v2 instead of a v1.
Also, there must be example code somewhere on how to create a v1 mesh in your Ogre source code.
Re: ogre-next crrate entity from ManualObject
Posted: Tue Dec 10, 2024 11:29 am
by Crystal Hammer
In Ogre Next, all old v1 things are in v1 namespace:
Code: Select all
v1::MeshPtr m1 = v1::MeshManager::getSingleton().create(s1, "General",
v1::HardwareBuffer::HBU_STATIC, v1::HardwareBuffer::HBU_STATIC );
So you should use v1::MeshManager.
Also Ogre Next has Item, which was Entity in old v1 Ogre.
There is also a useful method here, if you want to convert your v1 mesh to v2:
Code: Select all
void MeshUtils::importV1Mesh( const Ogre::String &meshName, const Ogre::String &groupName )
{
Ogre::v1::MeshPtr v1Mesh;
Ogre::MeshPtr v2Mesh;
v1Mesh = Ogre::v1::MeshManager::getSingleton().load( meshName, groupName,
Ogre::v1::HardwareBuffer::HBU_STATIC, Ogre::v1::HardwareBuffer::HBU_STATIC );
//Create a v2 mesh to import to, with the same name (arbitrary).
v2Mesh = Ogre::MeshManager::getSingleton().createByImportingV1( meshName, groupName,
v1Mesh.get(), true, true, true );
//Free memory
v1Mesh->unload();
// Do not destroy mesh, it could be used to recover from lost device.
// Ogre::v1::MeshManager::getSingleton().remove( meshName );
Here is an example from my demo project, creating a v1 plane in Ogre Next:
https://github.com/cryham/ogre3ter-demo ... ky.cpp#L32
Code: Select all
void CreatePlane(), DestroyPlane();
Ogre::Item *planeItem = 0;
Ogre::SceneNode *planeNode = 0;
Ogre::v1::MeshPtr planeMeshV1 = 0;
Ogre::MeshPtr planeMesh = 0;
Code: Select all
void TerrainGame::CreatePlane()
{
sizeXZ = 2000.0f;
planeMeshV1 = v1::MeshManager::getSingleton().createPlane(
"Plane v1", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Plane( Vector3::UNIT_Y, 1.0f ), sizeXZ, sizeXZ,
10, 10, true, 1, 40.0f, 40.0f, Vector3::UNIT_Z,
v1::HardwareBuffer::HBU_STATIC, v1::HardwareBuffer::HBU_STATIC );
planeMesh = MeshManager::getSingleton().createByImportingV1(
"Plane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
planeMeshV1.get(), true, true, true );
SceneManager *mgr = mGraphicsSystem->getSceneManager();
SceneNode *rootNode = mgr->getRootSceneNode( SCENE_STATIC );
planeItem = mgr->createItem( planeMesh, SCENE_STATIC );
planeItem->setDatablock( "Ground" );
planeNode = rootNode->createChildSceneNode( SCENE_STATIC );
planeNode->setPosition( 0, 0, 0 );
planeNode->attachObject( planeItem );
}
void TerrainGame::DestroyPlane()
{
SceneManager *mgr = mGraphicsSystem->getSceneManager();
if (planeNode)
{ mgr->destroySceneNode(planeNode); planeNode = 0; }
if (planeItem)
{ mgr->destroyItem(planeItem); planeItem = 0; }
auto& ms = MeshManager::getSingleton();
auto& m1 = v1::MeshManager::getSingleton();
if (planeMesh) ms.remove(planeMesh); planeMesh.reset();
if (planeMeshV1) m1.remove(planeMeshV1); planeMeshV1.reset();
}
Re: ogre-next crrate entity from ManualObject
Posted: Tue Dec 10, 2024 4:58 pm
by jordiperezarti
Code: Select all
v1PlaneMeshPtr = v1::MeshManager::getSingleton().create("planeV1Mesh", "General");
this is the instance i was looking for.
Thanks.