Sharing objects beween scenes

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Sharing objects beween scenes

Post by NZ_ »

Hi all
I have started to use Ogre few months ago, aiming at a CAD application

Is it possible to add objects from one scene to another "by reference" without creating their replicas?

I need to create a popup window which displays scene from the main window plus some additional objects like measurements. The main objective is to analyze surface of some objects. It would be good to be able to display only few of them, not the whole scene

I do not mind messing a bit with Ogre code. Any pointers would be great. Any idea how hard it would be?

Thank you
Nick
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

Regarding sharing objects by reference - i dont think it's possible( maybe i'm wrong - never tried that )
But for what u try to achive( if i understand correctly ) - u just need to create another RenderWindow( if u want different window with the "measurements" ) with the same SceneManager then use a FrameListener with RenderQueue and RenderQueueListener....
http://www.ogre3d.org/docs/api/1.9/clas ... tener.html
http://www.ogre3d.org/docs/api/1.9/clas ... Queue.html
http://www.ogre3d.org/docs/api/1.9/clas ... tener.html

if the frameListener doesn't work for you for some reason then you can: attach windowA-> render the scene, detach windowA - attach windowB ->render the scene, detach windowB and so on.....youl'e still need the renderQueue to disable/enable rendering of a specific sceneNode....
samples for frameListener:
http://www.ogre3d.org/tikiwiki/BulletDe ... e=Cookbook
http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook

sample for renderQueue
http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Cookbook

more samples: http://www.ogre3d.org/tikiwiki/tiki-ind ... e=Snippets ... search the wiki and forum....
you may also use overlays - if u want to show it on the same window - without creating another renderWindow....http://ogre3d.org/forums/viewtopic.php? ... 54&start=0
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Re: Sharing objects beween scenes

Post by NZ_ »

Thank You for the info!
I am digging in
Nick
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

i'm so into Ogre that i forgot about the basic stuff that just works - no need to dig too deep( unless you want to ) since you are just beginning to learn ogre...
http://ogre3d.org/forums/viewtopic.php?f=2&t=26361
with that technique dont use the ogre::Root->renderOneFrame(...) or the SceneManager->update()....
just use your own custom rendering loop:
renderWindowA->update(...)
SceneNodes[a...z]->setVisible( false )
renderWindowB->update(...)
SceneNodes[a...z]->setVisible( true )

you will have to invoke frame-rendering started,queue,end...and similar events yourself...just in case your app will need them for other listeners( users plugins, sample code etc... )...
take a look at Ogre::Root::renderOneFrame: source code...http://www.ogre3d.org/tikiwiki/Basic+Tutorial+4

if u do use the Ogre::Root->renderOneFrame...you can use renderWindow->setIsAutoUpdate( false )...look in the API
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

ok lets make this even easier...
windowA->setActive( true )
windowB->setActive( false )
SceneNodes[a...z]->setVisible( false ) or for each SceneNode[a...z] : sceneNode->getParent()->removeChild( sceneNode )
Ogre:root->renderOneFrame(...)

windowA->setActive( false )
windowB->setActive( true )
SceneNodes[a...z]->setVisible( true ) or reatach SceneNodes[a...z] to there previous parents...
Ogre:root->renderOneFrame(...)

no need for renderQueues frame->start,end etc here...
you will still need to dig in the FrameListener samples in order to make window specific draw calls...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Re: Sharing objects beween scenes

Post by NZ_ »

Thank you for that.
Most likely this is what I will have to do

What I am looking for is more fundamental.
I had it in my soft a while ago with GL immediate mode. It was like myMesh.Draw(). This call only used internal geometry: points, normal and indices.
When a near collision of two objects happens I could throw up a 3D exception which is a new window with new scene. The new scene displays the original objects and also shows two nearest points on the surfaces, segment connecting them, normals and a separating plane

To do that inside the rendering loop of the popup I called reference_to_myMesh->Draw(); It worked because Draw() uses only internal staff and can be called in any context

If it works in Ogre it would allow using a scene as sub scene. No need for replicating possibly huge objects and caring about updating replicas

It looks like Ogre mesh can be shared between scenes. So I am thinking whether I can have SceneManager::addSceneNode(SceneNode* snOfAnotherScene)
Inside there would be a new scene node created, which is native to this SceneManager, but the mesh is a reference to the original, now shared mesh. It would be even better to share the MovableObjects inside both SceneNodes
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Re: Sharing objects beween scenes

Post by NZ_ »

Ha, the first dumb test seem to be working!
Ogre is super!

I am not sure this will do for general public, but for me it is a kind of debugging view-only functionality

I have added:

Code: Select all

SceneNode* SceneNode::addChildSceneNode(SceneNode* node)
	{
		SceneNode* nodeReplica = static_cast<SceneNode*>(this->createChild());
		nodeReplica->copy(node);
		return nodeReplica;
	}
	//-----------------------------------------------------------------------
	void SceneNode::copy(SceneNode* node)
	{
		mYawFixed = node->mYawFixed;
		mYawFixedAxis = node->mYawFixedAxis;
		mAutoTrackTarget = node->mAutoTrackTarget;
		mAutoTrackOffset = node->mAutoTrackOffset;
		mAutoTrackLocalDirection = node->mAutoTrackLocalDirection;
		mWorldAABB = node->mWorldAABB;
		mShowBoundingBox = node->mShowBoundingBox;
		mHideBoundingBox = node->mHideBoundingBox;
		//Not copied: bool mIsInSceneGraph, mCreator, mWireBoundingBox

		// Move to base::copy() in a minute
		mCachedTransform = node->mCachedTransform;
		mCachedTransformOutOfDate = node->mCachedTransformOutOfDate;
		mDebug = node->mDebug;
		mDerivedOrientation = node->mDerivedOrientation;
		mDerivedPosition = node->mDerivedPosition;
		mDerivedScale = node->mDerivedScale;
		mInitialOrientation = node->mInitialOrientation;
		mInitialPosition = node->mInitialPosition;
		mInitialScale = node->mInitialScale;
		mName = node->mName;
		mOrientation = node->mOrientation;
		// Important: Leave mParent as it is
		mPosition = node->mPosition;
		mScale = node->mScale;

		// Copy objects by reference
		mObjectsByName.clear();
		ObjectMap::iterator oi, oiend;
		oiend = node->mObjectsByName.end();
		for (oi = node->mObjectsByName.begin(); oi != oiend; ++oi)
		{
			attachObject(oi->second);
		}
	}
I called it to attach the last scene node from main window to the root scene node of the popup window. In debugger I have stepped over an exception complaining that the node already has a parent and over obj->_notifyAttached(this); (Will add a parameter in a minute) and got the correct 3D scene

So I will persist further. This is sharing of MovableObjects, not meshes. There might be more problems like MovableObject::mParentNode, but it could point to its original parent and the MovableObjects can be considered as a second-rate citizen in the scene
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

Is it possible to add objects from one scene to another "by reference" without creating their replicas?
if this is what u asked for - then the answer is NO!!!
But still after i spend time to give u 3 detailed answers on how to achive what u want , u go and clone the scene node to a another node,
and now you want to hack ogre and change how the source code works....very disapointing.... :(
ogre give you many ways of achiving your goals in the main-stream, so why go against the stream?
more work for u, do expect problems as your app grows bigger... its not very good programming , so good luck with that...

btw: meshes can be shared since they are created by the RenderingSystem and not by the SceneManager...basic parameters( Vector3, Matrix, bool etc ) for sure...
SceneNodes and Movable object thats a different story....they have parents...( for the love of code, dont break up the family....if u do ,that will make you responsible for the children.... )
Last edited by frostbyte on Thu Jun 19, 2014 6:46 am, edited 4 times in total.
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Re: Sharing objects beween scenes

Post by NZ_ »

Sorry, mate
I did not expect you to spend much time on it. I was checking for a quick suggestion
I saw somebody was looking for a similar thing. If this works it could be an improvement for Ogre. It is a useful information anyway

This is not exactly cloning. Only the container node of the hierarchy tree is cloned. The rest, a large chunk of memory, is shared
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

Ogre exist for 14 years - it does'nt need this kind of hacks...if it did it would be in the main stream...
every API have its own way of achiving stuff...from my experiance....bad programmers( i used to be one :oops: ) tend not to try and understand the API but rather presist with there own methods...thats not good programming....i'm not angry , i just want u to understand my point.... :D
in your case - there doesn't seem the need to create two different scenes....unless i complitly misunderstood....
your bettrer off writing a new SceneManager to share by ref.... you will have problems with adding attaching and destroying MovableObject and problem with other Plugins,Codes trying to play nicely with your SceneManager...at the end of the day it will be more work then reading the manuals and going mainStream...
Dont be sorry -i'm also learning from answering you...
As long as you take care of what i write, thats fine by me...your code....your time...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
NZ_
Gnoblar
Posts: 12
Joined: Wed Jun 18, 2014 2:45 am
x 1

Re: Sharing objects beween scenes

Post by NZ_ »

Please take it easy, man. These are just my thoughts
Delete this post if you wish
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Sharing objects beween scenes

Post by frostbyte »

well i'm taking it very easy, as a matter of fact i dont realy care about what you do... 8)
I have no intention of deleting my post since i wish other people watching this thread not to go your path and suffer...
just trying to be helpful( since i'm probebly board and don't want to get back to real work.... :mrgreen: )
The main thing i learned from your reactions( which lots of ogre begginers share )... is not to try waste my time helping begginers...
good luck with rewiting Ogre ... code crushing etc... :lol:

this is how this thread should have looked like http://www.ogre3d.org/forums/viewtopic.php?p=255668
instead u r being kind of rude...to somone who try to help u....thats not nice...
next time just say somthing like "thanks for the advice..."....not "take it easy..."
i'm done here...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
Post Reply