*Solved* Object Retexturing Help

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
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

*Solved* Object Retexturing Help

Post by Echoplex »

Hello community. I'm throwing my hat in the ring trying to learn how to re texture an object. Currently i'm experimenting with creating a dark version of a healing crystal I.e red however I cannot get the custom crystal diffuse map to apply to the custom object created for this purpose dubbed dark_healing_crystal. I can only get it to apply to the main healing crystal which is not desired. I have created a custom model using the Grimrock Model Toolkit and placed the model inside the mod_assets/models/env/ folder and also have placed the new diffuse map in the mod_assets/textures/env/ folder. Disregarding the color vectors, here is what I have in the lua scripts:

Object lua

Code: Select all

defineObject{
	name = "dark_healing_crystal",
	components = {
		{
			class = "Model",
			model = "mod_assets/models/env/dark_healing_crystal.fbx",
			castShadow = false,
		},
		{
			class = "Particle",
			particleSystem = "crystal",
		},
		{
			class = "Light",
			offset = vec(1,0,0),
			color = vec(1/255, 1/255, 255/255),
			range = 7,
			shadowMapSize = 128,
			castShadow = true,
			staticShadows = true,
		},
		{
			class = "Sound",
			offset = vec(0, 1.5, 0),
			sound = "crystal_ambient",
		},
		{
			class = "Animation",
			animations = {
				spin = "assets/animations/env/healing_crystal_spin.fbx",
			},
		},
		{
			class = "Clickable",
			offset = vec(0, 1.5, 0),
			size = vec(1.6, 2, 1.6),
			maxDistance = 1,
		},
		{
			class = "Obstacle",
		},
		{
			class = "ProjectileCollider",
		},
		{
			class = "Crystal",
			cooldown = 480,
		},
	},
	placement = "floor",
	editorIcon = 60,
	automapIcon = 104,
	automapIconLayer = 1,
}
Material Lua

Code: Select all

defineMaterial{
	name = "dark_healing_crystal",
	diffuseMap = "mod_assets/textures/env/dark_healing_crystal_dif.tga",
	specularMap = "assets/textures/env/healing_crystal_dif.tga",
	normalMap = "mod_assets/textures/env/dark_healing_crystal_normal.tga",
	doubleSided = false,
	lighting = true,
	ambientOcclusion = false,
	alphaTest = false,
	blendMode = "Opaque",
	textureAddressMode = "Wrap",
	glossiness = 20,
	depthBias = 0,
	
	-- custom shader
	shader = "crystal",
	shadeTex = "mod_assets/textures/env/dark_healing_crystal_shadetex.tga",
	shadeTexAngle = 0,
	crystalIntensity = 3,
	onUpdate = function(self, time)
		self:setParam("shadeTexAngle", time*0.8)
	end,
}
I tried following the "Fire Lizard" Tutorial however again the diffuse map will not stick to the new object created. I can only get it to work with the normal healing crystal. When I pull the model up through the model viewer it looks correct. What am I missing? Thanks

*Edit* I have been successful in recoloring the ice lizard. The crystal however still won't work.
Last edited by Echoplex on Mon May 02, 2016 1:38 am, edited 1 time in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Object Retexturing Help

Post by minmay »

CrystalComponent only works properly if the model's material is named "healing_crystal" and it also applies a blue tinge to the material. You may have better luck using ModelComponent's emissiveColor feature to change the crystal's color. You can adjust it with the crystal's fading progress like this:

Code: Select all

		{
			class = "Light",
			offset = vec(0,1,0),
			color = vec(1, 0.1, 0.1),
			range = 7,
			shadowMapSize = 128,
			castShadow = true,
			staticShadows = true,
			onUpdate = function(self)
				local progress = math.max(math.min(1,self.go.sound:getVolume()*2),0)
				self.go.model:setEmissiveColor(vec(progress*0.1,-0.8,-1.6))
			end,
		},
By the way, if your "custom model" is only a material change, you should just use the original model and the "material" or "materialOverrides" field instead:

Code: Select all

{
  class = "Model",
  model = "assets/models/env/healing_crystal.fbx",
  material = "dark_healing_crystal",
  castShadow = false,
},
Last edited by minmay on Mon May 02, 2016 12:47 am, edited 1 time in total.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: Object Retexturing Help

Post by Echoplex »

Hey Minmay. Agreed setting the materials is a lot easier and efficient, thank you. Regarding the emissiveColor suggestion, the below code gives an error.


mod_assets/scripts/objects.lua: attempt to perform arithmetic on global 'v' (a nil value)


Now this is supposed to be just an aesthetic change and not a usable crystal. Are you saying you cannot clone the crystal and give it a new diffuse map without the material "healing_crystal"? I was also going to give changing the teleportor colors a shot. Anything I should be aware of with those?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Object Retexturing Help

Post by minmay »

Sorry, bad copy-paste job. Fixed it.
Echoplex wrote:Now this is supposed to be just an aesthetic change and not a usable crystal. Are you saying you cannot clone the crystal and give it a new diffuse map without the material "healing_crystal"?
CrystalComponent has special visual effects that ONLY apply to the material named "healing_crystal". If you are not using CrystalComponent, then the material name is irrelevant. If you want CrystalComponent's visual effects on a material, then you MUST name the material "healing_crystal", end of story.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: Object Retexturing Help

Post by Echoplex »

Got it working finally with updated particles. Thanks a lot Min.
Post Reply