Game Development Community

GuiObjectViewer

by Davide Archetti · in Torque Game Engine Advanced · 12/30/2004 (4:40 am) · 11 replies

Hi,
I was trying to port the guiObjectViewer resource to TSE.
After a while, I was able to render the space orc in the gui, but it is totally dark.
Could someone give me some hints to why this happens?

In the renderWorld function, I have enable the lighting with
GFX->setLightingEnable(true);
	GFX->setAmbientLightColor(mAmbientColor);

added a light to the lightManager, and created a sceneState and set it with a call to TSMesh::setSceneState, and then the render method of the mesh is called like it is done in the normal render loop of a mission, so I think the problem should be in the initialization of something before.

Code in the next post :)

#1
12/30/2004 (4:40 am)
Here is the renderWorld function
void GuiObjectView::renderWorld( const RectI &updateRect )
{
	if (!(bool)mMeshObjects.mMainObject)
		return;
	    
	GFX->clear( GFXClearZBuffer, ColorI(0,0,0), 1.0f, 0); 
	
	GFX->setZEnable(true);
	GFX->setZWriteEnable(true); 
	GFX->setZFunc(GFXCmpLessEqual); 

	GFX->setLightingEnable(true);
	GFX->setAmbientLightColor(mAmbientColor);

        LightManager *lightManager = gClientSceneGraph->getLightManager();
        LightInfo light;
        if(lightManager)
       {
          light.mType      = LightInfo::Ambient;
          light.mDirection = mLightDirection;
          light.mColor     = mLightColor;
          light.mAmbient   = mAmbientColor;

          lightManager->setMaxGLLights(1);
          lightManager->addLight(&light);
          lightManager->installGLLights(Box3F(-1, -1, -1, 1, 1, 1));
       }

      // Determine the camera position, and store off render state...
      MatrixF modelview;
      MatrixF mv;
      Point3F cp;

      modelview = GFX->getWorldMatrix();

      mv = modelview;
      mv.inverse();
      mv.getColumn(3, &cp);

     // Set up the base SceneState.
     F32 left, right, top, bottom, nearPlane, farPlane;
     RectI viewport;

     GFX->getFrustum( &left, &right, &bottom, &top, &nearPlane, &farPlane );
     viewport = GFX->getViewport();

     SceneState* pBaseState = new SceneState(NULL,
                                           0,//mCurrZoneEnd,
                                           left, right,
                                           bottom, top,
                                           nearPlane,
                                           farPlane,	//F64(getVisibleDistanceMod()),
                                           viewport,
                                           cp,
                                           modelview,
                                           2000,			//getFogDistanceMod(),
                                           2000,			//getVisibleDistanceMod(),
                                           ColorF(0.1,0.1,0.1),  //mFogColor,
                                           0,			          //mNumFogVolumes,
                                           NULL,			//mFogVolumes,
                                           1);				  //smVisibleDistanceMod);

    pBaseState->mFlipCull = false;		

   TSMesh::setSceneState( pBaseState );
   TSMesh::setRefract(false);

   for (S32 i=0; i<33; i++)
  {
	if (mMeshObjects.mMesh[i].mesh)
	{
		// Animate and render
		if(mMeshObjects.mMesh[i].mode == 1)
		{
			S32 time = Platform::getVirtualMilliseconds();
			S32 dt = time - mMeshObjects.mMesh[i].lastRenderTime;
			mMeshObjects.mMesh[i].lastRenderTime = time;
			F32 fdt = dt;

			mMeshObjects.mMesh[i].mesh->advanceTime( fdt/1000.f, mMeshObjects.mMesh[i].thread );
			mMeshObjects.mMesh[i].mesh->animate();
		}

		// If this is a mounted object transform to the correct position
		if (mMeshObjects.mMesh[i].parentNode != -1)
		{
			MatrixF mat;
			getObjectTransform( &mat, i ); 
			GFX->pushWorldMatrix(); 
			GFX->multWorld(mat); 
			mMeshObjects.mMesh[i].mesh->render();
			GFX->popWorldMatrix(); 
		}
		else
		{
			mMeshObjects.mMesh[i].mesh->render();
		}
	}

  }

  TSMesh::setSceneState( NULL );
  delete pBaseState;

  if (lightManager)
  {
	lightManager->uninstallGLLights();
	lightManager->removeLight(&light);
  }	

  GFX->setLightingEnable(false);

  GFX->setZEnable(false);
  GFX->setClipRect( updateRect); //dglSetClipRect( updateRect );
  GFX_Canonizer("GuiObjectView", __FILE__, __LINE__);					
}
#2
04/24/2005 (1:54 am)
Hi,
I'm here again with an update.
I've discovered that if the shape doesn't have a material assigned, using the function addMateriaMapping, it is rendered correctly, obviously it is rendered with the base texture without bump mapping, so I suppose that it's just a shader problem, but which?
If someone can give me a hint, this would be very appreciated :)
Davide
#3
04/25/2005 (5:03 pm)
You have to set up the material when it is rendered -- don't ask me how though. I look forward to seeing progress here.

Look at the TSMesh render function...
#4
05/10/2005 (7:12 pm)
Did you try just execing materialmap.cs b4 the gui?
#5
05/11/2005 (11:03 am)
If you add these lines before the for loop
DetailManager::beginPrepRender();
DetailManager::endPrepRender();
it works but after exiting a mission it didn't display nothing, so I've written a new control stealing the code from the show mod, and it works always :), although since it uses the gClientSceneGraph for rendering the model, this control cannot be used while playing a mission, but I think that fixing this should be simple, perhaps just creating a new sceneGraph, but I haven't tried it yet.
This message is for who is interested and cannot wait until I'll find the time to create a resource for this, if your projects needs it right now send me an email and I'll send you the code (be clear in the subject of the message otherwise I'll miss it, too much spam in my email!).
Remember right now it does only what I need and most things are hardcoded in the code, no script functions to change its behaviour, just the basic function to add a model and mount an object.
#6
05/19/2005 (2:25 pm)
Strange, buy calling all the gui/cs in the proper order, we have had no problems at all using TSE guiObjectView. It works exactly as it should.
#7
05/19/2005 (3:02 pm)
Do you mean using the code above? whit the DetailManager::beginPrepRender?
The problem I have is after playing a mission, don't you have this kind of problem? although I'm using a heavely modified version of TSE :)
#8
06/24/2005 (8:23 pm)
Well, has anyone made a working version of this?
#9
11/05/2006 (10:48 am)
And now ???

With TSE MS4 and the TLK integration ???
#10
11/20/2006 (5:33 pm)
I used the renderWorld function code, but all saw nothing on the screen.
namely in importing tge to tse, it doesn't appear the 3d data(character, weapon..) on UI

Would you give me a source code that conneted with Guiobjectview??

thanks~~
#11
02/07/2007 (6:33 am)
Anyone made any progress?