Can't redefine a material?

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!
Post Reply
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Can't redefine a material?

Post by gambit37 »

Hi all, I'm back into Grimrock tinkering after a couple of years away...!

I'm trying to redefine some dungeon materials, but my changes are never reflected in the dungeon. I have added a copy of an original material definition to my own materials.lua, and just changed the paths/filenames, like this:

Code: Select all

defineMaterial{
	name = "dungeon_wall_01",
	diffuseMap = "mod_assets/textures/env/mytexture_dif.tga",
	specularMap = "mod_assets/textures/env/mytexture_spec.tga",
	normalMap = "mod_assets/textures/env/mytexture_normal.tga",
	doubleSided = false,
	lighting = true,
	alphaTest = false,
	blendMode = "Opaque",
	textureAddressMode = "Wrap",
	glossiness = 25,
	depthBias = 0,
}
I thought this would just update the texture acrosss all models that use it, but I never see the changes, I still get the old material.

I've tried it by completely reloading the game, and the editor, and no change.

What am I doing wrong?
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Can't redefine a material?

Post by bongobeat »

hey

I don't know why you have this error, but try something else then:

go in the asset pack directory : assets/scripts/materials/dungeon.lua

copy the dungeon.lua in the same directory, then rename it

Code: Select all

dungeon_materials.lua
(its an example)

then copy/paste the dungeon_materials.lua into your mod_assets/scripts/

paste this into you init.lua, at the very first line

Code: Select all

import "mod_assets/scripts/dungeon_materials.lua"
now all materials for dungeon tileset are loaded within your mod. Then try to modify/replace directly your new material into the dungeon_matereials.lua
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Can't redefine a material?

Post by akroma222 »

Hey Gambit37,
The only material replacing for wall sets Ive done has been a few floor tiles....
Double checking.... have you:

1. added the import line to your init.lua? EG -

Code: Select all

import "mod_assets/scripts/materials.lua"
2. Checked that you havent imported the asset pack materials.lua OR all standard assets AFTER you have listed
the line (^^as above) importing your mod_asset materials.lua (from init.lua) ? If you have done this then
the material defs will have been redefined again as the asset pack versions :(

3. Tried renaming your mod_asset material definitions to something different??
(by rights this shouldn't actually matter but it may shine light on the problem...)

4. Have you tried wrapping the new material around the relevant models
in Blender or the Grimrock Model Toolkit (then saving these newly textured models into your mod_assets/models folder??
You shouldnt need to do this as an objects models textures can be changed via the ModelComponent dynamically:

Code: Select all

object_name.go.model:setMaterialOverrides(  tab  )
(tab = {old_material_name1 = "new_material_name1", old_material_name2 = "new_material_name2" }
OR changed with either the 'material' or 'materialOverrides' fields of the ModelComponent in your object definition:

Code: Select all

{
	class = "Model",
	model = "mod_assets/gambit37_assets/models/new_dungeon_wall.fbx",
	material = "gambit37_dungeon_wall_1",
	materialOverrides = {	old_material_name1 = "gambit37_dungeon_wall_1", 
							old_material_name2 = "gambit37_dungeon_wall_2", 	},
}
5. If none of this is of any help ... post up your wall set object's definitions maybe?? :)

Akroma
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Can't redefine a material?

Post by akroma222 »

A working EG from me....

NOTE** - I have not added the line: import "assets/scripts/standard_assets.lua" to my init.lua ....
Instead - I have added the various import lines from standard_assets.lua as required or not, EG -
SpoilerShow

Code: Select all

import "assets/scripts/materials/generic.lua"
import "assets/scripts/materials/dungeon.lua"
import "assets/scripts/materials/tomb.lua"
import "assets/scripts/materials/mine.lua"
import "assets/scripts/materials/forest.lua"
import "assets/scripts/materials/castle.lua"
import "assets/scripts/materials/beach.lua"
import "assets/scripts/materials/items.lua"
import "assets/scripts/materials/monsters.lua"
import "assets/scripts/materials/swamp.lua"
import "assets/scripts/materials/cemetery.lua"

Then Ive added these lines afterwards (init.lua):
SpoilerShow

Code: Select all

import "mod_assets/scripts/materials/item_materials.lua"
import "mod_assets/scripts/materials/misc_materials.lua"
import "mod_assets/scripts/materials/monster_materials.lua"
import "mod_assets/scripts/materials/object_materials.lua"
import "mod_assets/scripts/materials/alchemy_materials.lua"
in my object_materials.lua ....
SpoilerShow

Code: Select all

defineMaterial{
	name = "akr_pearlstone_inside_floor1",
	diffuseMap = "mod_assets/textures/env/pearlstone/pearlstone_inside_floor1_diff.tga",
	specularMap = "assets/textures/env/castle_inside_floor_spec.tga",
	normalMap = "assets/textures/env/castle_inside_floor_normal.tga",
	doubleSided = false,
	lighting = true,
	alphaTest = false,
	blendMode = "Opaque",
	textureAddressMode = "Wrap",
	glossiness = 75,
	depthBias = 0,
}
and then used the same procedure as above, with objects.lua files....
(I wont list them as Im sure you get the idea...)

In my mod_assets/scripts/objects/ceilings_floors.lua...
SpoilerShow

Code: Select all

defineObject{
	name = "akr_pearlstone_floor_01",
	baseObject = "base_floor",
	components = {
		{
			class = "Model",
			model = "assets/models/env/castle_floor_01.fbx",
			staticShadow = true,
			--material = "akr_pearlstone_inside_floor1",
			materialOverrides = { castle_inside_floor = "akr_pearlstone_inside_floor1" }
		},
		{
			class = "Occluder",
			model = "assets/models/env/dungeon_floor_01_occluder.fbx",
		},
	},
	minimalSaveState = true,
}
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: Can't redefine a material?

Post by gambit37 »

Thanks for the help guys. I solved it.

I had two other assets sets being loaded in my initi.lua, and these were both re-loading the standard assets AFTER my own definitions. So all my stuff was getting reset.

I removed those extra lines and it's all good now. :)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Can't redefine a material?

Post by akroma222 »

Good news! And welcome back ;)
Post Reply