Page 45 of 118
Re: Scripters cove
Posted: Tue May 29, 2012 8:32 pm
by Griff
Commander McLane wrote:Griff wrote:I was picking through Commander McLane's 3d_asteroids script to see if i had enough brainpower to adapt it into a 'C64 version of Elite Anarchies.oxp' that would spawn pirates in a cloud around you no matter whatever direction you were flying
Isn't that basically what Deep Space Pirates OXP is already doing? I think it would at the very least be a better starting point.
I think so, but in a much more advanced way! i just wanted to spawn a random amount of pirates roughly in front of the player after a few moments of jump-drive use, i thought maybe your bit of code to keep the asteroids near the player might be easier for me to pick apart
[spoiler] I'm out of my depth [/spoiler]
Re: Scripters cove
Posted: Tue May 29, 2012 8:59 pm
by Eric Walch
Griff wrote: i just wanted to spawn a random amount of pirates roughly in front of the player after a few moments of jump-drive use,
Code: Select all
var forwardPosition = playerPosition.add(heading.multiply(50E3));
var pirateGroup = system.addGroup("pirate", count, forwardPosition, 5E3);
This is the part from deepSpacPirates were McLane was referring to. All the other code is to decide when to add, deal with escorts and give them all custom scripts. Just make sure you add them far away or you will see them pop into existence. One scanner distance will not be enough, two is better as in above code.
Re: Scripters cove
Posted: Thu May 31, 2012 8:38 pm
by Thargoid
OK, time for a possibly dumb question. Is there any way to read the currently applied shaders (or materials generally) to an entity by script?
I know we have ship.setShaders
and ship.setMaterials
to change them (although arguably they should be under entity rather than ship these days?), but do we have any way to actually tell what the currently applied ones are?
I'm just starting to look at the cargo spotter idea from Griff on the previous page of this thread, and wanted to make sure that if we change the shaders on a shady cargo pod that if the system is de-activated it can be changed back afterwards. But currently I can't see a way to do it, as I can't see a way to tell what shaders are active to be able to store them away for later re-use.
Any clues, or is this one that needs requesting for 1.77?
Re: Scripters cove
Posted: Thu May 31, 2012 9:14 pm
by cim
Thargoid wrote:Is there any way to read the currently applied shaders (or materials generally) to an entity by script?
Unfortunately not.
Re: Scripters cove
Posted: Thu May 31, 2012 9:19 pm
by Thargoid
Could something suitable be added to 1.77 please, for both materials and shaders? Presumably to dump out a dictionary of current settings, similar to what you'd feed back with setShaders/setMaterials
if you wanted to apply them again?
Re: Scripters cove
Posted: Thu May 31, 2012 9:25 pm
by cim
Thargoid wrote:Could something suitable be added to 1.77 please, for both materials and shaders? Presumably to dump out a dictionary of current settings, similar to what you'd feed back with setShaders/setMaterials
if you wanted to apply them again?
I think that should be possible, yes. I've added it to my list of things to look at, anyway.
Re: Scripters cove
Posted: Fri Jun 01, 2012 11:48 am
by Thargoid
Thanks - and be careful not to trip over the end of the list if you get up
Re: Scripters cove
Posted: Sun Jun 03, 2012 7:03 pm
by Thargoid
Hmm, I'm getting some odd behaviour, or more specifically lack of behaviour - I can't get setShaders to do anything via the console. If I use:
Code: Select all
T.setShaders({"griff_barrel_glowtest_diffuse.png": { fragment_shader: "oolite-default-shader.fragment", vertex_shader: "oolite-standard-vertex.vertex" }});
on a freshly spawned test barrel (with the above-set diffuse map and its own shaders) to try and remove those shaders, basically nothing visibly changes on the entity. The code snippet returns true, so presumably something is going on, but nothing visual does. Similarly if I try
Code: Select all
T.setMaterials({"griff_barrel_glowtest_diffuse.png": { diffuse: "redColor" }});
again nothing visually happens, although the function returns true.
Am I doing something wrong here, or is this there a reason why it doesn't seem to work via the console?[/color]
Re: Scripters cove
Posted: Sun Jun 03, 2012 7:34 pm
by Svengali
When you want to apply a new shader you'll need to pass the textures and uniforms as well.
And the materials key is diffuse_color.
Re: Scripters cove
Posted: Sun Jun 03, 2012 8:04 pm
by Thargoid
Svengali wrote:When you want to apply a new shader you'll need to pass the textures and uniforms as well.
And the materials key is diffuse_color.
Doesn't seem to make any difference:
Code: Select all
T.setShaders({"griff_barrel_glowtest_diffuse.png": { textures: "griff_barrel_glowtest_diffuse.png", diffuse_map: "griff_barrel_glowtest_diffuse.png", fragment_shader: "oolite-default-shader.fragment", vertex_shader: "oolite-standard-vertex.vertex" }});
also does nothing other than return true. There aren't any uniforms to pass in the default shaders, so in this case the key isn't needed.
Also diffuse also works, at least in the Butterflies script (just tested it and it does change the color, although I agree the wiki defines it as diffuse_color).
But thanks for the suggestions, I'm still struggling here.[/color]
Re: Scripters cove
Posted: Mon Jun 04, 2012 6:20 am
by Capt. Murphy
Hi, when I helped Smivs with the texture switching code for his shipset I came across
the same problem - it appears the JS engine can't parse a dictionary into an object as a parameter (I think that makes sense??), so you need to separately define an object to hold the dictionary then use that object as the parameter for setMaterials or setShaders. Frustratingly it doesn't throw an error though.
Edit: thinking about this a bit more, I think this is a bug - reported
here.
This is the working code from Smivs shipset...
Code: Select all
var texture = this.ship.scriptInfo.smivs_texture; // uses scriptInfo key to build texture name
var diffuse = this.ship.scriptInfo.smivs_diffuse; // uses scriptInfo key to build diffuse map name
var emission = this.ship.scriptInfo.smivs_emission; // uses scriptInfo key to build emission map name
var material = new Object(); // declare variable
material[texture] = {diffuse_map:diffuse, emission_map: emission}; // set up material entry
this.ship.setMaterials(material); // apply material
Edit and for completeness an example of the associated scriptInfo in shipdata. It was done this way so a single generic shipScript could do all the texture switching for the entire ship set.
Code: Select all
script_info =
{smivs_texture = "smivs'-adder.png";
smivs_diffuse = "smivs'-adder-damaged.png";
smivs_emission = "smivs'-adder_em-map.png";};
Another edit: Discussion in the bug report I posted now makes me think you aren't having the same problem as I suffered. But I'm wondering if this works for you Thargoid?
T.setShaders({"griff_barrel_alt_diffuse.png": { textures: "griff_barrel_glowtest_diffuse.png", diffuse_map: "griff_barrel_glowtest_diffuse.png", fragment_shader: "oolite-default-shader.fragment", vertex_shader: "oolite-standard-vertex.vertex" }});
Re: Scripters cove
Posted: Mon Jun 04, 2012 1:44 pm
by Svengali
Yes, it works the same as the shipdata stuff. That's why I've said to pass the full set.
Capt. Murphy wrote:T.setShaders({"griff_barrel_alt_diffuse.png": { textures: "griff_barrel_glowtest_diffuse.png", diffuse_map: "griff_barrel_glowtest_diffuse.png", fragment_shader: "oolite-default-shader.fragment", vertex_shader: "oolite-standard-vertex.vertex" }});
Nope. textures are a array so you need to use ["tex0.png", "tex1.png"] or ["tex0.png",{name:"tex1.png", repeat_s:true}] and the uniforms for the texture units.
If you want to apply both (materials and shader) you need to pass both dictionaries. Mixing them won't work (if I recall it right) - setMaterials( {dict for materials}, {dict for shader} );
You can see some more examples in Asteroid Storm, CCL_MaterialsFinder, Vector and OXPConfig.
Re: Scripters cove
Posted: Tue Jun 05, 2012 8:49 am
by Capt. Murphy
Thanks Svengali.
I'm trying something now which is an attempt to brighten up the random paint colours on Griff's ships via script. Surprise, surprise it's not working. So I'm using the Griff Cobra III. Its shaders entry from shipdata.plist is....
Code: Select all
shaders = {
"griff_cobra_mk3_mainhull_diffuse_spec.png" = {
"fragment_shader" = "griff_cobra_mk3_player.fragment";
textures = (
"griff_cobra_mk3_mainhull_diffuse_spec.png",
"griff_cobra_mk3_mainhull_normal.png",
"griff_cobra_mk3_mainhull_effects.png",
"griff_player_decal.png"
);
uniforms = {
"Decal1_Rotation" = {
type = float;
value = "-0.73840";
};
"Decal1_Scale_and_Position" = {
type = vector;
value = "0.59 0.2 9.6";
};
PaintColor1 = {
scale = "0.17";
type = randomUnitVector;
};
PaintColor2 = {
scale = "0.17";
type = randomUnitVector;
};
alertlevel = alertCondition;
"damage_amount" = damage;
"engine_power" = speedFactor;
"hull_heat_level" = hullHeatLevel;
uColorMap = {
type = texture;
value = 0;
};
uDecalMap = {
type = texture;
value = 3;
};
uEffectsMap = {
type = texture;
value = 2;
};
uNormalMap = {
type = texture;
value = 1;
};
uTime = universalTime;
};
"vertex_shader" = "griff_normalmap_ships.vertex";
};
};
From a bit of shipdata editing I know that I can increase the value of
scale
for
PaintColor1
and
PaintColour2
to brighten up the random paint job. So to try and do it from the debug console for the player.ship I used...
Code: Select all
player.ship.setShaders({"griff_cobra_mk3_mainhull_diffuse_spec.png":{"fragment_shader": "griff_cobra_mk3_player.fragment",textures:["griff_cobra_mk3_mainhull_diffuse_spec.png","griff_cobra_mk3_mainhull_normal.png","griff_cobra_mk3_mainhull_effects.png","griff_player_decal.png"],uniforms:{"Decal1_Rotation":{type:"float",value:-0.73840},"Decal1_Scale_and_Position":{type:"vector",value:(0.59,0.2,9.6)},"PaintColor1":{scale: 1,type: "randomUnitVector"},"PaintColor2":{scale: 1,type: "randomUnitVector"}, "alertlevel": "alertCondition","damage_amount": "damage", "engine_power": "speedFactor", "hull_heat_level": "hullHeatLevel", "uColorMap":{type:"texture",value:0},"uDecalMap":{type:"texture",value:3},"uEffectsMap":{type:"texture",value:2},"uNormalMap":{type:"texture",value:1},"uTime":"universalTime"},"vertex_shader":"griff_normalmap_ships.vertex"}})
which returns true, but doesn't result in a visible change.....any ideas?
Re: Scripters cove
Posted: Tue Jun 05, 2012 10:33 am
by Wildeblood
How do I re-orient the player ship 180 degrees, so its nose is pointing straight back the way it came from?
Re: Scripters cove
Posted: Tue Jun 05, 2012 10:49 am
by Svengali
Capt. Murphy wrote:which returns true, but doesn't result in a visible change.....any ideas?
I've just tried it with another Griff Cobra and indeed setShaders() doesn't do anything, but setMaterials() works.
There are some things to remember though:
- type vector needs a string -> so (1,2,3) gets "1 2 3"
- additional parameters like repeat_s are booleans -> yes gets true
- alertCondition probably needs the fix described
here
The used example:
Code: Select all
player.ship.setMaterials(
{},
{
"Griff_cobra_mk3_cleaner_mainhull_diffuse_spec.png": {
vertex_shader: "Griff_Cobra_mk3_Mainhull.vertex",
fragment_shader: "Griff_Cobra_mk3_Mainhull_b_decals_cleaner.fragment",
textures: [
"Griff_cobra_mk3_cleaner_mainhull_diffuse_spec.png",
"Griff_cobra_mk3_cleaner_mainhull_normal.png",
"Griff_cobra_mk3_cleaner_mainhull_effects.png",
{name: "griff_decals_set1_flipped_V.png", repeat_s: true}
],
uniforms: {
uColorMap: {type: "texture", value: 0},
uNormalMap: {type: "texture", value: 1},
uEffectsMap: {type: "texture", value: 2},
uDecalMap: {type: "texture", value: 3},
uTime: "universalTime",
nearly_dead: "throwingSparks",
isHostile: "hasHostileTarget",
hull_heat_level: "hullHeatLevel",
engine_power: "speedFactor",
PaintColor1: {type: "vector", value: "1.0 0.0 0.0"},
PaintColor2: {type: "vector", value: "0.0 0.0 1.0"},
DecalColor: {type: "vector", value: "1.0 0.3945 0.0"},
uDecalSelect: {type: "float", value: 0.3}
}
}
}
);