ASE (ASCII Scene Export) loader for Irrlicht, need some help

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nieka

ASE (ASCII Scene Export) loader for Irrlicht, need some help

Post by nieka »

Hi,

I'm working on a ASE (ASCII Scene Export) file format loader for Irrlicht.
It would be nice to import whole scenes directly from 3DSMax.

Unfortunately I can only get the debug boundingboxes to show up. Not the vertices or the textures. If anyone could help a bit with this it would be great!

Image

This is the code that should do it:

Code: Select all

CASELoader::CASELoader(irr::scene::ISceneManager *smgr, char *filename)
{
	ASE_Scene *scene = ASE_loadFilename(filename);
	if(!scene){
		trace("ERROR loading ase file\n");
		return;
	}
	irr::video::IVideoDriver *driver = smgr->getVideoDriver();

	for(int i=0;i<scene->objectCount;i++)
	{
		ASE_GeomObject obj = scene->objs[i];
		ASE_Material mat = scene->materials[i];

		scene::SMesh *mesh = new scene::SMesh();
		scene::SMeshBuffer *mb = new scene::SMeshBuffer();
		for(int j=0;j<obj.mesh.vertexCount;j++)
		{	
			ASE_Vector3D asevec3d = obj.mesh.vertices[j];
			ASE_Vector3D asenormal3d = obj.mesh.vertex_normals[j];

			core::vector3df asevec(asevec3d.x,asevec3d.y,asevec3d.z);
			core::vector3df normal(asenormal3d.x,asenormal3d.y,asenormal3d.z);
			irr::video::S3DVertex s3dvertext(asevec, normal,
				video::SColor(255,255,255,255), core::vector2df(1.0f,1.0f));
			mb->Vertices.push_back(s3dvertext);
		}
		mb->recalculateBoundingBox();
		mb->Material.DiffuseColor.set(255,s32(mat.diffuse.r*255.0f),s32(mat.diffuse.g*255.0f),s32(mat.diffuse.b*255.0f));
		mb->Material.AmbientColor.set(255,s32(mat.ambient.r*255.0f),s32(mat.ambient.g*255.0f),s32(mat.ambient.b*255.0f));
		mesh->addMeshBuffer(mb);
		mesh->recalculateBoundingBox();
		scene::ISceneNode *node = smgr->addMeshSceneNode(mesh);
		node->setDebugDataVisible(true);

  	    wchar_t objname[100]; 
	    swprintf(objname,100,L"%S",obj.name);
   
		node->setName(objname);
		node->setRotation(node->getRotation()+core::vector3df(90.0f,0.0f,0.0f));
		//		node->setScale(core::vector3df(10.0f,10.0f,10.0f));
		node->setMaterialTexture(0,driver->getTexture(mat.diffuseMaterialMap.image_path));
		node->setVisible(true);
	}
}
You can download the whole project here:

http://213.189.20.120/~nieka/ASELoader.zip
zola
Posts: 52
Joined: Thu Jul 15, 2004 2:31 pm
Location: switzerland
Contact:

Post by zola »

Nice, You're almost there.

This is what I see from the code

- meshbuffer vertices need proper texture coordinate settings
- meshbuffer need faces (indices)

I have been able to find the code for the inidces but the texture coordinates are something else! It would be nice if irrlicht had a function like this

drawIndexedTraingles(vector3df[] vertices, vector3df[] normals, s32[] uv, u32[] indices, u32 vertexCount, u32 indexCount);

... would make life much easyer :lol:

so, here's the index setting for the meshbuffer (You could insert this after the vertexloop...)

Code: Select all

for(int j=0; j<obj.mesh.faceCount;j++)
		{
			mb->Indices.push_back(obj.mesh.faces[j].vertex[0]);
			mb->Indices.push_back(obj.mesh.faces[j].vertex[1]);
			mb->Indices.push_back(obj.mesh.faces[j].vertex[2]);
		}
good luck.
nieka

Post by nieka »

Great thanx!

With the following code, it looks like this! Now only that texture coordinate thing. It seems that the textures already make the color now.

Image

Code: Select all

CASELoader::CASELoader(irr::scene::ISceneManager *smgr, char *filename)
{
	ASE_Scene *scene = ASE_loadFilename(filename);
	if(!scene){
		trace("ERROR loading ase file\n");
		return;
	}
	irr::video::IVideoDriver *driver = smgr->getVideoDriver();

	for(int i=0;i<scene->objectCount;i++)
	{
		ASE_GeomObject obj = scene->objs[i];
		ASE_Material mat = scene->materials[i];

		scene::SMesh *mesh = new scene::SMesh();
		scene::SMeshBuffer *mb = new scene::SMeshBuffer();
		for(int j=0;j<obj.mesh.vertexCount;j++)
		{	
			ASE_Vector3D asevec3d = obj.mesh.vertices[j];
			ASE_Vector3D asenormal3d = obj.mesh.vertex_normals[j];

			core::vector3df asevec(asevec3d.x,asevec3d.y,asevec3d.z);
			core::vector3df normal(asenormal3d.x,asenormal3d.y,asenormal3d.z);
			irr::video::S3DVertex s3dvertext(asevec, normal,
				video::SColor(255,255,255,255), core::vector2df(1.0f,1.0f));
			mb->Vertices.push_back(s3dvertext);
		}
		for(j=0;j<obj.mesh.faceCount;j++) 
	   { 
       mb->Indices.push_back(obj.mesh.faces[j].vertex[0]); 
       mb->Indices.push_back(obj.mesh.faces[j].vertex[1]); 
       mb->Indices.push_back(obj.mesh.faces[j].vertex[2]); 
      } 
		
		mb->recalculateBoundingBox();
		mb->Material.DiffuseColor.set(255,s32(mat.diffuse.r*255.0f),s32(mat.diffuse.g*255.0f),s32(mat.diffuse.b*255.0f));
		mb->Material.AmbientColor.set(255,s32(mat.ambient.r*255.0f),s32(mat.ambient.g*255.0f),s32(mat.ambient.b*255.0f));
		
		mesh->addMeshBuffer(mb);
		mesh->recalculateBoundingBox();
	
		scene::ISceneNode *node = smgr->addMeshSceneNode(mesh);
//		node->setDebugDataVisible(true);
		
  	    wchar_t objname[100]; 
	    swprintf(objname,100,L"%S",obj.name);
   
		node->setName(objname);
		node->setRotation(node->getRotation()+core::vector3df(90.0f,0.0f,0.0f));
		//		node->setScale(core::vector3df(10.0f,10.0f,10.0f));
		node->setMaterialTexture(0,driver->getTexture(mat.diffuseMaterialMap.image_path));
		node->setVisible(true);
		node->setMaterialFlag(video::EMF_LIGHTING, false);
	}
}
Guest

Post by Guest »

Cool it looks like You're making progress.

There's one thing I'd like to suggest. If You would implement the IMeshLoader inferface we would afterwards be able to include this loader easyer in our projects (or even in irrlichtnx) :)

To get some help and see how this would look like You could take a look at the following files:
- IMeshLoader.h (the inferface)
- C3DSMeshFileLoader.h C3DSMeshFileLoader.cpp (an example implementation of IMeshLoader)

We could then add Your meshloader to the scenemanager and use it like every other meshloader "smgr->getMesh("city.ase");"

Think about it :)

Keep up the good work
Guest

Post by Guest »

Well I've been rewriting the ASE loader completely so it doesn't need any
external libs anymore. I cannot make it a meshloader subclass since it uses multiple scenenodes.

It works quite nice now. It loads meshes, materials, lights and cameras.
When exporting from 3dsmax to .ASE make sure you enable all checkboxes
for the exported items.

I've only got a problem with shadows. I've subclasses CMeshSceneNode
to have it contain a CShadowSceneNode. Unfortunately it crashes in the shadow creation code.

If anyone could help debugging this problem it would be great.
To enable the shadow loader uncomment line 282 of ASELoader.cpp

Here's the project: http://213.189.20.120/~nieka/ASELoader.zip

Image
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

this loader rocks! it would be cool if you could track the shadow bug down.

Zola seems to be an excellent programmer. He might be able to help out.

congrats Nieka. gr8 work! :D

ps. I'm glad so many gr8 things are happening in the community! excellent programs for the engine!
Image
Post Reply