Random Textures

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Staer9
---- E L I T E ----
---- E L I T E ----
Posts: 570
Joined: Fri Feb 18, 2011 4:53 pm
Location: Hatfield, Hertfordshire (poor industrial)

Random Textures

Post 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
Image
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Random Textures

Post 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.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Random Textures

Post 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).
User avatar
Staer9
---- E L I T E ----
---- E L I T E ----
Posts: 570
Joined: Fri Feb 18, 2011 4:53 pm
Location: Hatfield, Hertfordshire (poor industrial)

Re: Random Textures

Post 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.
Image
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Random Textures

Post 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.
User avatar
Staer9
---- E L I T E ----
---- E L I T E ----
Posts: 570
Joined: Fri Feb 18, 2011 4:53 pm
Location: Hatfield, Hertfordshire (poor industrial)

Re: Random Textures

Post 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
Image
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Random Textures

Post 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?
My OXP's
And Latest Mission Coyote's Run
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Random Textures

Post by Commander McLane »

The dumb question first: do the specified textures actually exist?
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Random Textures

Post 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.
My OXP's
And Latest Mission Coyote's Run
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2482
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Random Textures

Post 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" }});
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Random Textures

Post 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.
My OXP's
And Latest Mission Coyote's Run
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Random Textures

Post 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).
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Random Textures

Post 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?
My OXP's
And Latest Mission Coyote's Run
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Random Textures

Post 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.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Random Textures

Post 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.
Post Reply