Page 1 of 2

Random Textures

Posted: Wed May 11, 2011 12:44 pm
by Staer9
Is there any way of listing the testures in the shipdata.plist and it randomly selecting one of them?

I looked on the wiki and was unable to find anything about it, so I have decided to resort to the friendliest board this side of Riedquat :lol:

any help will be greatly apreiciated

Re: Random Textures

Posted: Wed May 11, 2011 1:21 pm
by JensAyton
If you have several variants of a ship with different textures, and the same role, using that role will select one of the ships at random.

Re: Random Textures

Posted: Wed May 11, 2011 3:36 pm
by Thargoid
Or if you know the list of textures you want to chose from to apply to the ship you can change texture on-the-run using JS.

Via the setMaterials command. See also here for details of materials usage in the game.

A simple example is in my Butterlies demo oxp, although that changes the texture colour on the fly rather than the texture itself (although the principle is the same).

Re: Random Textures

Posted: Thu May 12, 2011 10:14 am
by Staer9
So just make a separate section in the Shipdata.plist for each one but give them all different textures?

is it easier just to make a template and then use likeship to duplicate it with different textures?

Thanks anyway.

Re: Random Textures

Posted: Thu May 12, 2011 10:27 am
by Commander McLane
Staer9 wrote:
So just make a separate section in the Shipdata.plist for each one but give them all different textures?

is it easier just to make a template and then use likeship to duplicate it with different textures?
Yes and yes.

Re: Random Textures

Posted: Thu May 12, 2011 12:02 pm
by Staer9
Well I have made it all now in 2 hours and 45 minutes the full shipdata.plist is finished using likeships and templates... however, like with most of my oxps there is a problem. before I changed the shipdata file it was fine, and yes I did hold down shift and when that didn't work I moved it out of the folder, started the game then put it back and restarted it. but it still didn't work which makes me think my programing skills are showing again.

is there an easy way of testing for errors in it or do I have to go through all 1148 lines of it?

<edit> oops, I just noticed that I forgot to include the:

}

on the end :oops:

<edit2> that didn't help... it still is refusing to work

Re: Random Textures

Posted: Tue May 17, 2011 11:47 am
by Okti
Hi,

I am just trying to change the texture of a ship by setMaterials method. The code is below:

Code: Select all

this.shipSpawned = function()
{		    
	this.mat = true;
	this.materialTimer = new Timer(this,this.setMaterials1,0,5);
}
this.setMaterials1 = function()
{
	if (this.mat == true)
	{	
		log(this.name,this.mat);
		log(this.name,"1");
		this.ship.setMaterials({"texture1.png":{}});
		this.mat = !this.mat;
	}
	else
	{	
		log(this.name,this.mat);
		log(this.name,"2");
		this.ship.setMaterials({"texture2.png":{}});
		this.mat = !this.mat;
	}
}
I am getting the log statements but the texture of the ship does not change. What I am doing wrong?

Re: Random Textures

Posted: Tue May 17, 2011 12:42 pm
by Commander McLane
The dumb question first: do the specified textures actually exist?

Re: Random Textures

Posted: Tue May 17, 2011 12:46 pm
by Okti
Commander McLane wrote:
The dumb question first: do the specified textures actually exist?
Yes they do, when I used to give them as a difuse_map they worked.

Re: Random Textures

Posted: Tue May 17, 2011 2:10 pm
by Griff
I'm very likely reading your code wrongly but the wiki has the this.ship.setMaterials syntax as

Code: Select all

this.ship.setMaterials({"my_ship_diffuse.png": { diffuse_map: "my_ship_damaged_diffuse.png" }});
it looks like in your code you're only listing the first texture (which should be the one referenced in your models .dat), try adding in the { diffuse_map: "texture2.png" } bit, eg

Code: Select all

this.ship.setMaterials({"my_ship_diffuse.png": { diffuse_map: "texture2.png" }});

Re: Random Textures

Posted: Tue May 17, 2011 2:15 pm
by Okti
Griff wrote:
I'm very likely reading your code wrongly but the wiki has the this.ship.setMaterials syntax as

Code: Select all

this.ship.setMaterials({"my_ship_diffuse.png": { diffuse_map: "my_ship_damaged_diffuse.png" }});
it looks like in your code you're only listing the first texture (which should be the one referenced in your models .dat), try adding in the { diffuse_map: "texture2.png" } bit, eg

Code: Select all

this.ship.setMaterials({"my_ship_diffuse.png": { diffuse_map: "texture2.png" }});
Thanks Griff, diffuse_map or emission_map works fine. What I was trying to do was to change texture file completely to a new one. I don't know if it posible, if not I will use either one of the above.

Re: Random Textures

Posted: Tue May 17, 2011 4:52 pm
by Thargoid
The "texture file" in the sense that I think you mean is the diffuse map. So if you set the diffuse map as Griff suggested, then you are essentially changing the texture. Unless of course you are using it as one of the other maps (emission or normal etc) then substitute the relevant map type in the command.

If by "texture file" you are meaning diffuse, emission and normal map, then you need to change the components individually. But for many ships the "texture file" is the diffuse map (possibly with others, but the diffuse is the main one).

Re: Random Textures

Posted: Tue May 17, 2011 5:09 pm
by Okti
Thanks Thargoid,

I am very new to Materials and textures used by oolite. I am trying to understand them.

Is the diffuse_map points to the texture file in the model.dat?

Re: Random Textures

Posted: Tue May 17, 2011 5:14 pm
by Smivs
That's right. The .dat specifies the diffuse_map. The materials can replace this and specifies other things like the emission_map and shininess and specular.

This example is from my shipset, which has a special Adder for the 'scavenger' role.

Code: Select all

materials = 
		{ 
			"smivs'-adder.png" = 
                                           {  
diffuse_map = "smivs'-adder-scavenger.png";
emission_map = "smivs'-adder_em-map.png";
shininess = 10;
specular_color = ( 0.3, 0.3, 0.3, 0.5 ); 
                                            };  
		};
The standard Adder has this

Code: Select all

materials = 
		{ 
			"smivs'-adder.png" = 
                                           {  
emission_map = "smivs'-adder_em-map.png";
shininess = 10;
specular_color = ( 0.3, 0.3, 0.3, 0.5 );  
                                            };  
		};
The diffuse_map 'smivs'-adder.png' is specified in the .dat file.

If no materials were specified in the shipdata.plist, tha Adder (both varieties) would appear with just the 'smivs'-adder.png' texture but no emission_map or shininess/specular.

Re: Random Textures

Posted: Tue May 17, 2011 6:51 pm
by Svengali
The "xyz.png":{} is only the identifier for Oolite which material should be altered and must match the models material. It's usually (but not always) the same as the diffuse_map.