material / material override?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

material / material override?

Post 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?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: material / material override?

Post 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'.
Last edited by JohnWordsworth on Tue May 19, 2015 5:14 pm, edited 1 time in total.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: material / material override?

Post 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.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: material / material override?

Post 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.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: material / material override?

Post by bongobeat »

thanks for clarification
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: material / material override?

Post 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
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: material / material override?

Post 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: )
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: material / material override?

Post 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?
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: material / material override?

Post 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.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: material / material override?

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