game engine gaming delta3d
p-51 open source GNU Lesser General Public License
Fedora Surface Tactics Visualization Plane Guard ChrAVE
Chromakeyed Augmented Virtual Environment CAVE Automatic Virtual Environment National Geospatial-Intelligence Agency Terrian Forward Observer PC Simulator FOPCSIM Shipboard Firefighting Trainer
backed by the U.S. military sourceforge eric johnson I/ITSEC Interservice Industry Training Simulation and Education Conference
Delta3D - Open source gaming & simulation engine
      Welcome to Delta3D | Login 
Monday, September 06 2010 @ 02:53 AM EDT 
MOVES Institute Naval Postgraduate School Naval Education and Training Command
  
IITSEC


AND     OR
 

 
 Home »  Delta3D Support »  Loading all textures
     Prev TopicNext Topic          Printable Version
Loading all textures Views: 532
 Wednesday, January 27 2010 @ 06:37 AM EST

Hi,

I have an application that uses Delta3D. The map is correctly loaded, and everyting seems to work fine. However, I have a problem: Some textures are only loaded when the camera poits at them.

Is there a way to load every textures before starting to navigate in a virutal environment?

Best regards,

Alex.

 Quote   

 
 Wednesday, January 27 2010 @ 08:43 AM EST

you have to compile all the object in the scene at the beginning of the program if you dont want any compilation on viewing...

i will give you the code we use in our programs:

class CompileGLObjectsCallback : public osg::Operation
{
public:
	CompileGLObjectsCallback(osg::Node* node):
	  osg::Operation("CompileStateCallback", false),
		  _scene(node) {}

	  virtual void operator () (osg::Object* object)
	  {
		  osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
		  if (!context) return;

		  if (_scene)
		  {

			  compileTextureObjects(_scene, context->getState());

			  osgUtil::GLObjectsVisitor compile;
			  compile.setMode(osgUtil::GLObjectsVisitor::Mode(osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS | 
				  osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES |
				  osgUtil::GLObjectsVisitor::SWITCH_ON_DISPLAY_LISTS |
				  osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS |
				  osgUtil::GLObjectsVisitor::CHECK_BLACK_LISTED_MODES	));
			  compile.setState(context->getState());
			  compile.apply(*_scene);
			
			 

		  }
	  }

	  void compileTextureObjects(osg::Node* node, osg::State* state)
	  {

		  osg::ref_ptr<osg::Geode> geode = dynamic_cast<osg::Geode*>(node);
		  if ( geode != NULL )
		  {
			  for(unsigned int j = 0; j < geode->getNumDrawables(); j++)
			  {
				  for(unsigned int i = 0; i < 8; i++)
				  {
					  osg::Texture2D* textureAttribute = static_cast<osg::Texture2D*>geode->
						  getOrCreateStateSet()->getTextureAttribute(i, osg::StateAttribute::TEXTURE));
					  if (textureAttribute != NULL)
					  {
							textureAttribute->compileGLObjects(*state);
					  }
				  }
			  }
		  }

		  osg::ref_ptr<osg::Group> group = dynamic_cast<osg::Group*>(node);
		  if ( group != NULL )
		  {
			  for (unsigned int i = 0; i < group->getNumChildren(); i++)
			  {
				  compileTextureObjects(group->getChild(i), state);				  
			  }
		  }
	  }

	  osg::Node*  _scene;
};


in application we use like:
void Application::compileGLObjects(osg::Node* node)
{
	CompileGLObjectsCallback* compile = new CompileGLObjectsCallback(node);	

	osgViewer::CompositeViewer* viewer = GetCompositeViewer();
	for (unsigned int i = 0; i < viewer->getNumViews(); i++)
	{
		osg::View* view = viewer->getView(i);
		if (view->getCamera()->getNodeMask() != 0)
		{
			view->getCamera()->getGraphicsContext()->add(compile);	  
		}
	}
}


sorry, since i use the code a little different, i have to change for you. it may not work directly but i gave the main idea...

here we give sceneNode to compileGLObjects than there is no loading textures after starting the frame.


Ufuk Gün

 Quote   

 
 Monday, February 08 2010 @ 09:06 PM EST

Is there a way to use these functions by converting a dtCore::Object into a osg::Node? That's because I'm loading the osg map into a dtCore::Object, and I believe that it converts all osg nodes into dtCore nodes.

...Or is there another solution?

Regards.

 Quote   

 
 Tuesday, February 09 2010 @ 02:56 AM EST

all dtCore::Object stores an osg::Node inside.

dtCore::Drawable => it has a member osg::Node
   ^
   |
dtCore::Transformable
   ^
   |
dtCore::Object


you can just call GetOSGNode() function on dtCore::Object to get osg::Node


Ufuk Gün

 Quote   

 

 


Delta3D is released under the GNU Lesser General Public License (LGPL) | Powered by GeekLog