.x Model - No Texture

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

.x Model - No Texture

Post by kgorsky »

I'm creating a small game for school using Irrlicht.

I've loaded in an IAnimatedMesh as the level and followed the Collision Detection Tutorial.

No matter what I do I cannot get the level mesh to show the textures I've added. It also comes out all white. I've been searching for weeks now and can't solve the problem. Help!

Code: Select all

// LevelOne.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "LevelOne.h"

#include <irrlicht.h>
#include <iostream>
#include <windows.h>
#include <audiere.h>

#pragma comment(lib, "Irrlicht.lib")

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace audiere;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	
	// let user select driver type
	video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

	// create device  
	IrrlichtDevice *device = createDevice(driverType, core::dimension2d<s32>(1024, 768), 32, true);

	if (device == 0)    
		return 1; 
	
	// could not create selected driver.  
	
	video::IVideoDriver* driver = device->getVideoDriver();  
	scene::ISceneManager* smgr = device->getSceneManager();

		
	scene::IAnimatedMesh* levelmesh = smgr->getMesh("LevelOne.x");
	scene::ISceneNode* node = 0;

	
	
	if (levelmesh)
		node = smgr->addOctTreeSceneNode(levelmesh->getMesh(0));

	scene::ITriangleSelector* selector = 0;

	
	
	if (node)
	{		
		node->setPosition(core::vector3df(0,0,0));

		selector = smgr->createOctTreeTriangleSelector(levelmesh->getMesh(0), node, 128);
		node->setTriangleSelector(selector);
		selector->drop();
	}

	//node->SetMaterialFlag(MaterialFlag.LIGHTING,false);

	//driver->setFog(video::SColor(0,200,200,200), true, 50, 3000, 0, true);
	//driver->setAmbientLight(video::SColor(100,100,100,100));

	node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
	node->setMaterialFlag(video::EMF_LIGHTING, false); 
	node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); 
	//node->setMaterialTexture(0, driver->getTexture("texture/terrain.jpg"));


	//node->setMaterialFlag(video::EMF_WIREFRAME, true);

	

	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
	camera->setPosition(core::vector3df(0,20,0));

	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, camera, core::vector3df(10,10,10),core::vector3df(0,-3,0),core::vector3df(0,20,0));
	
	camera->addAnimator(anim);

	device->getCursorControl()->setVisible(false);

	scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();

	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
	bill->setMaterialTexture(0, driver->getTexture("texture/particle2.bmp"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));

	video::SMaterial material;

	/*

	//material.Texture1 = driver->getTexture("texture/guard.bmp");
	material.Lighting = false;

	scene::IAnimatedMeshSceneNode* guard1 = 0;
	scene::IAnimatedMeshSceneNode* guard2 = 0;
	scene::IAnimatedMeshSceneNode* guard3 = 0;

	scene::IAnimatedMesh* guard = smgr->getMesh("model/julia.x");

	if (guard)
	{
		guard1 = smgr->addAnimatedMeshSceneNode(guard);
		guard1->setPosition(core::vector3df(-70,0,-90));
		//guard1->setMD2Animation(scene::EMAT_RUN);
		//guard1->getMaterial(0) = material;

		guard2 = smgr->addAnimatedMeshSceneNode(guard);
		guard2->setPosition(core::vector3df(-70,0,-30));
	//	guard2->setMD2Animation(scene::EMAT_SALUTE);
		//guard2->getMaterial(0) = material;

		guard3 = smgr->addAnimatedMeshSceneNode(guard);
		guard3->setPosition(core::vector3df(-70,0,-60));
	//	guard3->setMD2Animation(scene::EMAT_JUMP);
		//guard3->getMaterial(0) = material;
	}

	scene::ISceneNodeAnimator* ani = smgr->createCollisionResponseAnimator( 
      selector, guard3, core::vector3df(60,0,60), 
      core::vector3df(0,-3,0), 
      core::vector3df(0,50,0)); 
   guard3->addAnimator(ani); 
   ani->drop(); 

   guard3->setMaterialFlag(video::EMF_LIGHTING, true);


  */
	material.Texture1 = 0;
	material.Lighting = false;

	scene::ISceneNode* SkyBox = 0;

	SkyBox = smgr->addSkyBoxSceneNode(		
		driver->getTexture("texture/default_skyboxup.jpg"),		
		driver->getTexture("texture/default_skyboxdn.jpg"),		
		driver->getTexture("texture/default_skybox3.jpg"),		
		driver->getTexture("texture/default_skybox1.jpg"),		
		driver->getTexture("texture/default_skybox2.jpg"),		
		driver->getTexture("texture/default_skybox0.jpg"));

	scene::ISceneNode* selectedSceneNode = 0;
	scene::ISceneNode* lastSelectedSceneNode = 0;

	int lastFPS = -1;

	while(device->run())  
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, video::SColor(255,255,255,255));

			smgr->drawAll();

			core::line3d<f32> line;
			line.start = camera->getPosition();
			line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;

			core::vector3df intersection;
			core::triangle3df tri;

			if (smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, intersection, tri))
			{
				bill->setPosition(intersection);
				
				driver->setTransform(video::ETS_WORLD, core::matrix4());
				driver->setMaterial(material);
				driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
			}

			selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

			if (lastSelectedSceneNode)
				lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

			if (selectedSceneNode == node || selectedSceneNode == bill)
				selectedSceneNode = 0;

			if (selectedSceneNode)
				selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

			lastSelectedSceneNode = selectedSceneNode;

			driver->endScene();

			int fps = driver->getFPS();

			if (lastFPS != fps)
			{
				core::stringw str = L"Collision detection example - Irrlicht Engine [";
				str += driver->getName();		 
				str += "] FPS:";		  
				str += fps;		 
				device->setWindowCaption(str.c_str());	
				lastFPS = fps;	
			}
		}

	device->drop();
	
	return 0;

}


kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

Also...

Post by kgorsky »

The model was created in Maya and exporting to .x format. The texturing was also done in Maya.
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Could you post what shows up in your console as well as a screenshot? It would definately help. Since you have no lights I dont think its a lighting problem...the only other thing I can think of is that the program cannot find the textures and your default model color is all white.
trivtn
Posts: 132
Joined: Tue Jan 17, 2006 12:30 pm
Location: Viet Nam
Contact:

Post by trivtn »

Hi kgorsky!
I think Irrlicht engine can't find your textures, may be the exporter plugin from the Maya. You can export the model in the Maya to .x with the textures and in the .x don't include the path of textures. You can find in the .x find to check these problems. Good luck!
There's something is fantastic, there's nothing is absolute.
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

Screen Shot

Post by kgorsky »

This is what it looks like...

Image
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

Output

Post by kgorsky »

Here's what the Output looks like:

Code: Select all

Irrlicht Engine version 1.2
Microsoft Windows XP Professional Service Pack 2 (Build 2600)
Using renderer: Direct3D 8.1
RADEON 9600 Family (Microsoft Corporation) ati2dvag.dll 6.14.10.6462
Unknown data object in x file: AnimTicksPerSecond
Unknown data object in mesh in x file: DeclData
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/OakTree/BARK.
PNG
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/OakTree/leaf.
png
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Fence/Back Fe
nce/BackFence1.tga
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Tank/tank.jpg

Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Antenas/TOWER
_MA.JPG
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Antenas/TOWER
_BA.JPG
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Cement/cement
_box.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Cement/cement
Block_1.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
HeadlightOrange.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
logo_metal.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
body color 01.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
chrome.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
body color 02.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
suspension.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
body color 04.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
body color 03.jpg
Could not open file of texture:
Loaded texture: H:/4th Year/Levels/OutsideReactorFacility/textures/Custom Truck/
Headlight.jpg
Loaded mesh: LevelOne.x
Needed 4203ms to create OctTree SceneNode.(1751 nodes, 47188 polys)
Needed 16048ms to create OctTreeTriangleSelector.(925 nodes, 47188 polys)
Loaded texture: texture/particle2.bmp
Loaded texture: texture/default_skybox0.jpg
Loaded texture: texture/default_skybox2.jpg
Loaded texture: texture/default_skybox1.jpg
Loaded texture: texture/default_skybox3.jpg
Loaded texture: texture/default_skyboxdn.jpg
Loaded texture: texture/default_skyboxup.jpg
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

New Screen Shot

Post by kgorsky »

So I had the FOG turned on and that's why everything was white.

here's the screen shot with the FOG turned off:

Image
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

whatevernodename->setMaterialFlag(EMF_LIGHTING, false);
unless you plan on using lights

the fog can be fixed by doing something like this

Code: Select all

drv->setFog(SColor(255,140,140,140), true, 2200, 3300, 1.0f, false, true);
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

Response

Post by kgorsky »

The fog isn't the problem... I can get that to work... it's the non-textured terrain model...

I tried: whatevernodename->setMaterialFlag(EMF_LIGHTING, false);

I had tried this before with no effects.

I went through the .x file in a word editor and replaced the texture paths and I still got nothing.
kgorsky
Posts: 7
Joined: Tue Jan 23, 2007 11:34 pm
Contact:

Post by kgorsky »

In the console info I posted above, what does "Could not open file of texture:" mean...
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

yeah the same problem and i noticed that (in irredit also) even if u tried to
->setMaterialFlag(EMF_LIGHTING, false);
it will not appear i added lights in irredit and the textures appeared it seams u must add light so the textures appear try it :wink:
Athlon_Jedi
Posts: 156
Joined: Wed Jul 21, 2004 4:29 am
Location: Mishawaka, In

@Omarr

Post by Athlon_Jedi »

have a look at my IrrEdit Scripts posted in the IrrEdit Section of the forum.


I have a few useful ones posted and for the lighing to make it "Toggle" on and off, just take my lighting script and follow the scripts Niko includes in the package , modify it similar , and you now have a toolbar entry to toggle lighting on and off :)
Robert Y.
Posts: 212
Joined: Sun Jan 28, 2007 11:23 pm

Post by Robert Y. »

Maybe you could post one of the models to see if that causes the problem. The X importer doesn't handle all X varieties...
Viniterra
Posts: 12
Joined: Sun Dec 17, 2006 5:44 am

Post by Viniterra »

I had experiencing a similar problem exporting from Blender

Maybe the solution could be the same:
Open your .X on notepad, and then locate all the image citations on the file, (by extension: .bmp, .jpg etc).
In my Blender exported models, there was something like "picture.bmp.001"
I just take out this .001 and the model was displayed correctly on the screen.
Praetor
Posts: 42
Joined: Wed Jun 20, 2007 2:31 am

Post by Praetor »

I had similar problems with .x meshes exported from blender, also I noticed that when it finally did display the textures it slowed the framerate to the 60's when it was always in the 100-200's before. I found that if I didn't use the texture path in the .x file and simply manually assigned the texture in the code of my project it worked fine (Im unsure if it was a problem with the irrlicht .x reader or with the exporter for blender).
Post Reply