Page 1 of 2

material / material override?

Posted: Tue May 19, 2015 3:56 pm
by bongobeat
Hey all,

just want to know what is the difference between the 2 material command line which can be added in the model component

Code: Select all

material = "xxxxx",
and

Code: Select all

materialOverrides = { ["xxxxxx"] = "xxxxxxx",
is there one which should be used in priority?

Re: material / material override?

Posted: Tue May 19, 2015 4:34 pm
by JohnWordsworth
You can use the first to force override the material of a model if there is only 1 material across the entire model. If you have a model with multiple mesh segments and textures (say, a skeleton uses 1 texture and then a separate texture for the sword), then you use the second method to map materials from the name baked in the model file to the one you want to use in your mod.

So, material = "xxxxx", will simply set the material on all parts of your model (I think, not tested with a model with multiple textures) to "xxxxx".

However, materialOverrides = { ["a"] = "X", ["b"] = "Y" } could take a model and change all materials named 'a' on that model to 'X' and then change all materials name 'b' on that model to 'Y'.

Re: material / material override?

Posted: Tue May 19, 2015 5:06 pm
by AdrTru
There is some bug.
If you use materialOverrides = { "a" = "b" } and next materialOverrides = { "b" = "c" } then material c is in, but after save and load is loaded material a.

Re: material / material override?

Posted: Tue May 19, 2015 5:12 pm
by petri
AdrTru wrote:There is some bug.
If you use materialOverrides = { "a" = "b" } and next materialOverrides = { "b" = "c" } then material c is in, but after save and load is loaded material a.
You have to do all overrides in one go, e.g. materialOverrides = { ["a"] = "b", ["b"] = "c" }

I.e. if you set the overrides again, all the previously set overrides are lost.

Re: material / material override?

Posted: Wed May 20, 2015 10:45 am
by bongobeat
thanks for clarification

Re: material / material override?

Posted: Fri May 27, 2016 7:38 pm
by AndakRainor
I just noticed this, using materialOverrides, it seems reflection does not like it at all! Do you get the same result? Is there a solution to avoid this? (Not really a big problem for me since the party should not be that far over water so it will not be seen, but if I ever wanted to put some water in my town that would be terrible!)
SpoilerShow
Image

Re: material / material override?

Posted: Wed Jun 08, 2016 9:48 pm
by bongobeat
I have just try on a blue window that use the material override, and it looks ok:

SpoilerShow
Image
note that the blue windows have a light component, the yellow windows has none.

Code: Select all

		{
			class = "Model",
			model = "mod_assets/sx_town/models/sx_town_window_indoor_snapon_lightrays.fbx",
materialOverrides = { ["sx_town_wood_generic"] = "sx_town_wood_generic", ["sx_town_window"] = "sx_town_window_church", ["sx_town_lightrays"] = "sx_town_lightrays" },
			offset = vec(0, 0.1, 0),
		},
are you using a light in front of the window?

(Oups, I just see that I replace 2 of those textures by the same one, I guess I can remove them, don't know why I did'nt do it when I created this object! I certainly forgot :oops: )

Re: material / material override?

Posted: Wed Jun 08, 2016 10:46 pm
by AndakRainor
here is my window definition:

Code: Select all

defineObject{
  name = "sx_town_window",
  components = {
    {
      class = "Model",
      model = "mod_assets/sx_town/models/sx_town_wall_window_low_snapon.fbx",
      offset = vec(0, 0, 0.05),
    },
    {
    	class = "Light",
      offset = vec(0, 1.75, 0),
    	color = vec(1.5, 1.0, 0.5),
    	brightness = 5,
    	range = 6,
    },
    {
      class = "Timer",
      timerInterval = 0,
      triggerOnStart = true,
      currentLevelOnly = true,
      onActivate = function(self)
        local h,i,light = (GameMode.getTimeOfDay()*12+9)%24,1,true
        while true do
          local n = self.go.data:get(i)
          if not n or h < n then break end
          light = not light
          i = i+1
        end
        if light then
          self.go.light:enable()
          self.go.model:setMaterialOverrides({sx_town_window = "sx_town_window_light"})
        else
          self.go.light:disable()
          self.go.model:setMaterialOverrides({sx_town_window_light = "sx_town_window"})
        end
        self:setTimerInterval(utils.script.timeOfDayRatio*0.01*(1+math.random()))
      end,
    },
    {
      class = "Script",
      name = "data",
      source = [[
        data = {2, 7, 9, 20}
        function get(self,name) return self.data[name] end
        function set(self,name,value) self.data[name] = value end
      ]],      
    },
  },
  placement = "wall",
  editorIcon = 92,
  tags = { "sx_walls" },
}
As you see I start or stop the light and use model:setMaterialOverrides() to change the window texture depending on the day/night cycle. Could the function trigger this bug, but not the static definition you used?

Re: material / material override?

Posted: Thu Jun 09, 2016 11:54 am
by bongobeat
waow! this is an interesting approach, always wonder if that was possible to do! :)
well I don't know if that can interfere with the rendering, perhaps someone more skilled can answers you!

since youre material changing works, maybe you have to do something with the water: removing/disabling the existing water surface when it's night and spawn a new one. Maybe the new water surface will take in count that you have a lighted material.

Re: material / material override?

Posted: Thu Jun 09, 2016 4:06 pm
by AndakRainor
The problem is I used different values for each window, and also a randomized timer interval. The goal is that they don't all switch the light on at the exact same time, I think it is better for immersion (inn's ground floor windows are lit all night for example, but not upstairs after midnight or something). If your static definition works with water reflection, may be I should define 2 models and activate/deactivate them instead of using setMaterialOverrides() on 1 model only. I will try that...