Problem using ofusion-loader in compositor-demo

mhebel

11-02-2008 23:18:43

Hi,
I'm having problems getting the ofusion loader running in the compositor demo which is coming with the standard OgreSDK.

As I've read the tutorials and especially this post
Problem load .osm file-Post
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=5368&postdays=0&postorder=asc&start=0
I managed to run the oSceneLoader_demo_dagon from the ofusion website. My Scene is working, everything is loading, just fine.

As I'm going to write some shaders "specialized" on my scene, I wanted to load the exact same scene into the compositor demo where I already have plugined some new shaders.

I thought it must be very simple to add some code lines and the scene will load, but it doesn't. There is always a crash. Here's what I've got (only my parts mentioned in the named methods:

file compositor.cpp

// ...

#include "OgreOSMScene.cpp"
#include "tinystr.cpp"
#include "tinystr.h"
#include "tinyxml.cpp"
#include "tinyxml.h"
#include "tinyxmlerror.cpp"
#include "tinyxmlparser.cpp"

// more code...


bool CompositorDemo::setup(void)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
Ogre::String mResourcePath;
mResourcePath = bundlePath() + "/Contents/Resources/";
mRoot = new Ogre::Root(mResourcePath + "plugins.cfg",
mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log");
#else

mRoot = new Ogre::Root();

#endif

setupResources();
bool carryOn = configure();
if (!carryOn) return false;


// now here is the ofusion stuff
OSMScene oScene;
oScene.initialise("scene.osm");
oScene.createScene();
mSceneMgr = oScene.getSceneManager();

/* comment out the original methods handling scene manager, camera, viewports
*/
//chooseSceneManager();
//createCamera();
//createViewports();

// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
loadResources();

// Create the scene
createScene();

createFrameListener();

// load some GUI stuff for demo.
//loadAllMaterialControlFiles(mMaterialControlsContainer);

return true;

}

// ...

/* and in method createScene() I commented out some parts that will collide with my scene*/
void CompositorDemo::createScene(void)
{

/*mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE);
mSceneMgr->setShadowFarDistance(1000);
*/
// setup GUI system
mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
// load scheme and set up defaults
mGUISystem = new CEGUI::System(mGUIRenderer, (CEGUI::ResourceProvider *)0, (CEGUI::XMLParser*)0,
(CEGUI::ScriptModule*)0, (CEGUI::utf8*)"CompositorDemoCegui.config");
CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

Ogre::MovableObject::setDefaultVisibilityFlags(0x00000001);

/* // Set ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.2));

Ogre::Light* l = mSceneMgr->createLight("Light2");
Ogre::Vector3 dir(-1,-1,0);
dir.normalise();
l->setType(Ogre::Light::LT_DIRECTIONAL);
l->setDirection(dir);
l->setDiffuseColour(1, 1, 0.8);
l->setSpecularColour(1, 1, 1);


Ogre::Entity* pEnt;

// House
pEnt = mSceneMgr->createEntity( "1", "tudorhouse.mesh" );
Ogre::SceneNode* n1 = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(350, 450, -200));
n1->attachObject( pEnt );

pEnt = mSceneMgr->createEntity( "2", "tudorhouse.mesh" );
Ogre::SceneNode* n2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-350, 450, -200));
n2->attachObject( pEnt );

pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
mSpinny = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0, 300));
mSpinny->attachObject( pEnt );
pEnt->setMaterialName("Examples/MorningCubeMap");

//pEnt = mSceneMgr->createEntity( "3", "hut.mesh" );
//mSpinny = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0, 300));
//mSpinny->attachObject( pEnt );
//pEnt->setMaterialName("Examples/MorningCubeMap");

mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");


Ogre::Plane plane;
plane.normal = Ogre::Vector3::UNIT_Y;
plane.d = 100;
Ogre::MeshManager::getSingleton().createPlane("Myplane",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500, 1500, 10, 10, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
Ogre::Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
pPlaneEnt->setMaterialName("Examples/Rockwall");
pPlaneEnt->setCastShadows(false);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

mCamera->setPosition(-400, 50, 900);
mCamera->lookAt(0,80,0);
*/

connectEventHandlers();
/// Create a couple of hard coded postfilter effects as an example of how to do it
/// but the preferred method is to use compositor scripts.
createEffects();
}


}
// ...


What am I doing wrong? The compiler tells me everything is ok, the original compositor demo is compiling perfectly but when my scene is loaded via "oScene.createScene" on execution the build crashes.

Lioric

13-02-2008 23:36:15

You might need to load the scene in the "createScene" method, because in the part you are currently loading it the resources are not registered with the system

If you need more details, post your ogre.log file and the exact error message or the stack trace of your application

mhebel

14-02-2008 19:39:43

Hi Lioric,
thanks alot, now it works. But there are some restrictions I have noticed:

In method "setup" "createViewports()" must be disabled, otherwise the build crashes.

bool CompositorDemo::setup(void)
{
...
chooseSceneManager();
createCamera();
// createViewports(); // must be disabled, otherwise crashes

// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
loadResources();

// Create the scene
createScene();
...
}



in method "createScene" "Ogre::Entity* pEnt;" has to stay, but don't know why.

void CompositorDemo::createScene(void)
{
OSMScene oScene;
oScene.initialise("scene.osm");
oScene.createScene();
mSceneMgr = oScene.getSceneManager();

// disable this part to get the right shadows
// mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE);
// mSceneMgr->setShadowFarDistance(1000);


// setup GUI system
mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mSceneMgr);
// load scheme and set up defaults
mGUISystem = new CEGUI::System(mGUIRenderer, (CEGUI::ResourceProvider *)0, (CEGUI::XMLParser*)0,
(CEGUI::ScriptModule*)0, (CEGUI::utf8*)"CompositorDemoCegui.config");
CEGUI::System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

// not necessary
// Ogre::MovableObject::setDefaultVisibilityFlags(0x00000001);

// disable this part to only let the ofusion stuff be shown
// Set ambient light
// mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.2));

/* Ogre::Light* l = mSceneMgr->createLight("Light2");
Ogre::Vector3 dir(-1,-1,0);
dir.normalise();
l->setType(Ogre::Light::LT_DIRECTIONAL);
l->setDirection(dir);
l->setDiffuseColour(1, 1, 0.8);
l->setSpecularColour(1, 1, 1);
*/

// this must stay, don't know why
Ogre::Entity* pEnt;

// House
/* pEnt = mSceneMgr->createEntity( "1", "tudorhouse.mesh" );
Ogre::SceneNode* n1 = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(350, 450, -200));
n1->attachObject( pEnt );

pEnt = mSceneMgr->createEntity( "2", "tudorhouse.mesh" );
Ogre::SceneNode* n2 = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-350, 450, -200));
n2->attachObject( pEnt );

pEnt = mSceneMgr->createEntity( "3", "knot.mesh" );
mSpinny = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0, 300));
mSpinny->attachObject( pEnt );
pEnt->setMaterialName("Examples/MorningCubeMap");
*/
pEnt = mSceneMgr->createEntity( "3", "hut.mesh" );
mSpinny = mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0, 300));
mSpinny->attachObject( pEnt );
pEnt->setMaterialName("Examples/MorningCubeMap");

mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox");


/* Ogre::Plane plane;
plane.normal = Ogre::Vector3::UNIT_Y;
plane.d = 100;
Ogre::MeshManager::getSingleton().createPlane("Myplane",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500, 1500, 10, 10, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
Ogre::Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
pPlaneEnt->setMaterialName("Examples/Rockwall");
pPlaneEnt->setCastShadows(false);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
*/
mCamera->setPosition(-400, 50, 900);
mCamera->lookAt(0,80,0);

connectEventHandlers();
/// Create a couple of hard coded postfilter effects as an example of how to do it
/// but the preferred method is to use compositor scripts.
createEffects();
}



At last I noticed that the ofusion camera is fixed and cannot be manipulated interactively like the coded one (don't need it, so it's ok).
But I wonder why the rotation values aren't transfered the right way (as another post showed). The ofusion values go from 0 to 1 but the values still are the degree values from max (going from 0 to 360). You have to transfer these values manually. So if you know this, its no problem, but if you don't.... :-)

So again thank you for the quick help.

Lioric

15-02-2008 15:55:49

You can put the "createViewports" method after the scene is loaded, becasue if you are not using your own scene manager, then this will only be created automatically when the scene is loaded (that createViewports method will need it, but if you are not using any custom spcecifc viewports, then all you need is automatically created by the loader and you can comment that line)

The "Entity* pEnt" needs to be there because you are creating an entity (with the name "3" and mesh "hut.mesh") and you are using the "pEnt" pointer for it

The camera(s) created by the loader are the camera(s) saved with the scene, they can be moved and positionated as any other camera, maybe the camera is animated and that is why is uses a fixed position (defined in the keyframes), but if not you can use it as any camera

You dont need to transfer any values manually, all is automatic, probably you can provide a sample scene or more details about this issue

mhebel

16-02-2008 22:35:24

Hmm, as I am using my own scene manager, I commented "createViewports".

The "Entity* pEnt" needs to be there because you are creating an entity (with the name "3" and mesh "hut.mesh") and you are using the "pEnt" pointer for it
Well, commenting both will create an error/crash on execution. Don't know why, but isn't that important. It can stay.

The camera issue stays, whatever I do. Here you can have the compositor.cpp and the scene.osm-files:

http://www.hs-augsburg.de/~mhebel/ofusion.rar