Material script loader for Irrlicht

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
r-type
Posts: 41
Joined: Sun Feb 12, 2006 1:54 am

Material script loader for Irrlicht

Post by r-type »

Hiya,

I'm almost finished with a material script loader for Irrlicht. I intend to finish it and publish it for your convenience ;) It supports pretty much all Irrlicht's material related features.

I made it based on material sequences in the .ms3d format, i don't know about the sequences in other formats(perhaps someone could enlighten me?).
Functions available now:
- Apply script to node
- Apply list gotten from the materialloader to a node
- Register callback under name for shaders
- and unregister

C&c welcome!

Code: Select all

	static irr::core::list<irr::video::SMaterial> *getMaterials( const irr::c8 *filename );
	static void applyToNode( irr::core::list<irr::video::SMaterial> *matlist, irr::scene::ISceneNode *node );
	static void applyToNode( const irr::c8 *filename, irr::scene::ISceneNode *node );
	static void setDriver( irr::video::IVideoDriver *vd );
	static int IMaterialLoader::createMaterialType(std::string vn=0,std::string ve=0,std::string pn=0,std::string pe=0,irr::video::E_MATERIAL_TYPE mt=irr::video::EMT_SOLID,std::string callbackname=0);
	static void registerCallBack(irr::video::IShaderConstantSetCallBack *cb,std::string name);
	static void unRegisterCallBack(std::string name);
And now for the script *drumroll*

Code: Select all

<root>
	<!-- Irrlicht doesn't support multiple passes yet but who knows in the future  -->
	<!-- Every feature except shaders will default to whatever is Irrlicht's if it is not defined -->
	
	<material>		
		<pass>
			<emissive value1="0" 	value2="0"   value3="255">
			<specular value1="255"  value2="255" value3="255">
			<shininess value1="20">
			<gouraud value1="true">
			<materialtype value1="EMT_SPHERE_MAP">
			<texture1 value1= "media/textures/1.jpg">
			<texture2 value1= "media/textures/2.jpg">
			<wireframe value1= "true">
		</pass>
	</material>

	<material>
		<pass>
			<emissive value1="0" 	value2="255" value3="0">
			<specular value1="255"  value2="255" value3="255">
			<shininess value1="20">
			<gouraud value1="true">
			<materialtype value1="EMT_SPHERE_MAP">
			<texture1  value1 = "media/textures/1.jpg">
			<texture2  value1 = "media/textures/2.jpg">
			<vs value1 = "dx_hlsl"  value2 = "media/shaders/shader.hlsl" value3 = "vertexMain">
			<ps value1 = "dx_hlsl"  value2 = "media/shaders/shader.hlsl" value3 = "pixelMain">
			<shadercallback value1 = "callbacky">
			
		</pass>
	</material>

	<material>
		<pass>
			<emissive value1="255" 	value2="0"   value3="0">
			<specular value1="255"  value2="255" value3="255">
			<shininess value1="20">
			<gouraud value1="true">
			<materialtype value1="EMT_SPHERE_MAP">
			<texture1  value1 = "media/textures/1.jpg">
			<texture2  value1 = "media/textures/2.jpg">	
			
		</pass>
	</material>
</root>
Screen from above script:
Image
WhiteNoise
Posts: 27
Joined: Wed Apr 19, 2006 5:10 pm
Contact:

Post by WhiteNoise »

Looks like a good addition. Should be useful to help keep the model setup data driven rather than being in the code.
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

Very nice!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Nice idea. But I have some suggestions. It would be nice to have a class structure around this which would also simplify the parameters.
I'd like to have names with materials which would make it much easier to choose from the list.
The names you chose for your format are a little too simple. Change root to materiallist, and valueX to correct names for the elements. If you want to allow structured file names you should change from attributes to xml nodes. And maybe gie all nodes an id tag.
r-type
Posts: 41
Joined: Sun Feb 12, 2006 1:54 am

Post by r-type »

Thanks for your replies. Hybrid , could you explain your ideas a little more (class structure,why xml nodes) ? thx
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you add a class such as MaterialList you could give access to materials by names, you don't have to copy with lots of irr::core::array pointers and no need for that many static methods. The idea of 'setDriver' is also confusing me. Where do you store this information?
With objects you'd do materialList.apply(node) instead of passing both elements to the static method. You could use constructors to load from files (maybe better use IReadFile anyway?) and you could extend these things more easily.
My suggestions for XML formats is to almost always use nodes instead of atttributes. Colors are a good example. Each color is a separate type in your schema. Even if you rename your attributes to red, blue, green they are not realted by any means. If you change to XML nodes like this:

Code: Select all

<ambientColor id="myAmbientColor1">
  <color type="float" id="myColor1">
    <alpha>0.5</alpha>
    <red>1.0</red>
    <green>0.5</green>
    <blue>0.1</blue>
  </color>
</ambientColor>
you can easily reuse your structures, keep them in sync, and even use the color structure in completely different situations (maybe you'd like to pass a color as an argument to a shader sometimes). Attributes are flat, unstructures values, so you'll loose most information when using attributes. Only use them with fixed enumerations such as in the example where possible values are probably just float and int.
IDs are really useful if you want to allow a more compact representation by referencing material properties in different locations. Think of lost of materials all using the same ambient color. You could introduce a ref="something" attribute which would copy the material definitions from the given location. You could even allow overwriting, so some kind of material inheritance.
juliusctw
Posts: 392
Joined: Fri Apr 21, 2006 6:56 am
Contact:

I am still rather new

Post by juliusctw »

Hello
Sorry, but I am kinda confused with what exactly your code does, i'm still kinda new with this thing, what does your code do?
Post Reply