Smivs wrote:setmaterials will change all the materials used for any given ship, so if you change the diffuse map, you also have to tell it to change the ships' other materials as well (emission, normal maps etc) otherwise it just ignores them. In other words if you have a simple material set (say just a diffuse and emission map) and change the diffuse map, the emission map will be removed on setMaterials. It needs to be specified in the setMaterials list if you want it to stay in place after setMaterials has done its stuff. You have to re-set it.
I recently had no end of fun with the Python Class Cruiser as this has three diffuse maps, so when I wanted to change something I had to set all three materials, each of which has three maps - diffuse, emission and a combined normal and specular map.
Hmm. That's what I intuitively expected, and that's why I try to read the complete set, change it, and rewrite it. But I don't know how to address the different parts (or sub-objects), and part of my problem is probably that the JavaScript syntax for defining the object (or list) is new to me.
So far I've only seen one example doing something like this, the Station Ads OXP, and there it says
Code: Select all
... .setMaterials({"yah_griff_no_shader_screen.png": {diffuse_map: newAd, emission_map: newAd}});
where newAd is a string containing the new texture file name. The shipdata is quite simple in this case:
Code: Select all
materials = {
"yah_griff_no_shader_screen.png" = {
diffuse_map = "station_ads_dock_frame.png";
};
};
"yah_griff_no_shader_screen.png" is, as I understand it, not a filename but kind of a key, corresponding to "Hull" and "Engines" in the core shipdata.plist. But in this case, there aren't any properties that remain unchanged, so it isn't necessary to read the material list before changing it.
So my thinking is that I have to read the existing material list with ship.getMaterials(), store it in a object variable, then change the parts of the object I need to change, and then rewrite the complete object with ship.setMaterials(). But how is the syntax for making these changes?
Another solution would be to hard-code the parts that remain unchanged. But why is there something like getMaterials() if it can't be used?