Page 1 of 1

Alternative textures

Posted: Thu Nov 11, 2010 7:05 pm
by Smivs
Hi all, silly question maybe, but is it possible within the shipdata.plist to call on more than one texture for a ship?
What I mean is, say I have a red version, a blue and a green version of the same texture, is there a simple way of calling them at random to get a bit of variety?
I've tried something like this

Code: Select all

materials = 
		{ 
			"myship.png" = 
                                          { 
diffuse_map = "redtexture.png(0.3)" "bluetexture.png(0.3)" "greentexture.png(0.3)";
                                          };  
		};
		model = "myship_redux.dat";
where myship_redux.dat specifies myship.png as the default diffuse map.
But no suprises, it didn't work. I have tried various permutations, such as commas (,) after each one, and without the 'chance' element (the (0.3)) to no avail.
Am I trying to do the impossible here?

Posted: Thu Nov 11, 2010 8:52 pm
by Kaks
Err, no, there's at least 3 different things that would break that plist...

You can achieve the desired result in 2 different ways:

The first is the .plist method - you define one ship (let's say you called it 'shipred', with one material. then you define 2 more like_ships, which are meant to be absolutely identical in all other respects:

Code: Select all

	"shipblue" =
	{
		like_ship = "shipred";
		materials={
                        "myship.png" ={ diffuse_map = "bluetexture.png"; }; 
                };
	};
	"shipgreen" =
	{
		like_ship = "shipred";
		materials={
                        "myship.png" ={ diffuse_map = "greentexture.png"; };
                };
	};
edit: oops, I typed the stuff in braindamaged mode earlier...

Since they're absolutely identical in all other respects, they'll all have a 1/3 chance of appearing in a given system. In any case, if you want to start modifying the relative likelihood of appearance you can only do it inside the role key.

The second method would be to have a ship script that retextures the ship randomly inside a this.shipSpawned event, but most people are more confortable with .plists

Posted: Thu Nov 11, 2010 8:57 pm
by Smivs
Thanks, Kaks.
Funnily enough that's exactly what I've just been trying...it's not working but now I can see why. Brilliant! :D

Posted: Thu Nov 11, 2010 9:07 pm
by Kaks
Oops, I just noticed I made a silly mistake in my example code. It should now be ok... sorry about that!

Posted: Thu Nov 11, 2010 9:16 pm
by Thargoid
To flesh-out Kaks' method, of using scripting to "dye" the ship different colours.

Download my Butterflies demo OXP - that does something along those lines when they are spawned. There are 9 different coloured butterflies in the game, all using a single texture (ok a pair of them, one for the body and one for the wings but you get what I mean). The script also changes their displayed name as an added little bonus.

They have an 0.1 weighted trader role, or you can spawn them via the JS console with role "butterflies_butterfly".

Posted: Thu Nov 11, 2010 9:23 pm
by Smivs
Kaks wrote:
Oops, I just noticed I made a silly mistake in my example code. It should now be ok... sorry about that!
Ah, I was using the 'diffuse_map' part and assumed that's why it wasn't working. :( I'll go and have a thorough look at it again...knowing me I've done something stoopid!

@Thargoid, thanks, I'll have a look, although js is not a strong point of mine.

Edit:- Yes, I'd done something stupid :oops: it's working fine now. Thanks.

Posted: Thu Nov 11, 2010 9:32 pm
by Thargoid
It's quite a simple script (ignore the lower bit about moving wings, that's just to make them flap). It uses the setMaterials command, which is the scripting equivalent of what Kaks describes above using the colour parameter which is passed to the function from the call in shipSpawned.