Question on animation textures

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!
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Question on animation textures

Post by MrChoke »

Hello. After months of not touching modding for Grimrock, I am back at it.

I have a question about animations. Do they have a texture that I can override somehow? I am talking something like what we can do for models. Example:

materialOverrides = { healing_crystal = "healing_crystal_black" }

The above gives it away. I want to have a different colored healing crystal. I set the above materialOverride on the crystal's model and it does nothing. This is obviously because the healing crystal has an animation too. But what good is having a model at all if all of the information is seemingly in the animation file?

If my only option is to update the animation file to update the texture, any idea how to do that? The Grimrock model toolkit can't read a .animation file.

Thanks
minmay
Posts: 2788
Joined: Mon Sep 23, 2013 2:24 am

Re: Question on animation textures

Post by minmay »

MrChoke wrote:I want to have a different colored healing crystal. I set the above materialOverride on the crystal's model and it does nothing. This is obviously because the healing crystal has an animation too.
this is obviously wrong, animations have nothing to do with it whatsoever and contain no texture or material data whatsoever

probably the reason the override doesn't seem to do anything is that CrystalComponent controls the texture, i know it worked this way in grimrock 1 but haven't studied the grimrock 2 behaviour
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.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Question on animation textures

Post by MrChoke »

minmay wrote:
MrChoke wrote:I want to have a different colored healing crystal. I set the above materialOverride on the crystal's model and it does nothing. This is obviously because the healing crystal has an animation too.
this is obviously wrong, animations have nothing to do with it whatsoever and contain no texture or material data whatsoever

probably the reason the override doesn't seem to do anything is that CrystalComponent controls the texture, i know it worked this way in grimrock 1 but haven't studied the grimrock 2 behaviour
Yeah, I didn't think animation files had textures but it makes just as little sense to me that the crystal component would control the textures. So that means its hard coded "healing_crysal" texture, have a nice day, do something else. Does that sum it up?

UPDATE:

Removing the crystal component does reveal the new texture so yeah that's it. Removing the crystal also stops the animation and everything else that makes it a healing crystal. It becomes just a model but yeah, its black now.

UPDATE2: Got the spin going by just valuing the "spion" animation. Hmmmm, maybe I can get this going after all. I need the click sound yet and the healing itself. That's easy. But how about the change in model color when de-activiated?
minmay
Posts: 2788
Joined: Mon Sep 23, 2013 2:24 am

Re: Question on animation textures

Post by minmay »

it might be easier to redefine the healing_crystal material instead
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.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Question on animation textures

Post by Isaac »

It is; but that applies to all of them.

Unfortunately, [oddly] the crystal object does not return a material from :getMaterial() unless you first assign it one with setMaterial(). I had thought to check the current material, and set it back if it ever changed, but it doesn't change ~it's just ignored after a reload.

Update: This seems to work without the per frame check; but with the obvious caveat that reloading reavtivates the crystal. :(

Code: Select all

defineObject{
	name = "healing_crystal_black",
	baseObject = "healing_crystal",
	minimalSaveState = true,
	components = {
			{
				class = "Crystal",
				cooldown = 120,
				onInit = function(self) self.go.model:setMaterial("healing_crystal_black") end
			},
		},
}
I think the best option is to detect a reload and reset the material. Minmay has experience with this; though I'm looking into it.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Question on animation textures

Post by MrChoke »

Isaac wrote:It is; but that applies to all of them.

Unfortunately, [oddly] the crystal object does not return a material from :getMaterial() unless you first assign it one with setMaterial(). I had thought to check the current material, and set it back if it ever changed, but it doesn't change ~it's just ignored after a reload.

Update: This seems to work without the per frame check; but with the obvious caveat that reloading reavtivates the crystal. :(

Code: Select all

defineObject{
	name = "healing_crystal_black",
	baseObject = "healing_crystal",
	minimalSaveState = true,
	components = {
			{
				class = "Crystal",
				cooldown = 120,
				onInit = function(self) self.go.model:setMaterial("healing_crystal_black") end
			},
		},
}
I think the best option is to detect a reload and reset the material. Minmay has experience with this; though I'm looking into it.
Thanks for your reply. Setting the material in oninit() worked as you point out. Funny how sometimes that is the case where things only take effect during onInit() and not in asset definitions.

You see a problem though when a saved game is reloaded? I will try this to confirm this as well. I have no idea how to reload and reset materials but hopefully its no big deal.

One other thing with how this is working though is when the crystal is de-activated, the texture doesn't change, only light, particle and sound is disabled. Do you know how the variation in texture is being done? I am referring to how a disabled crystal looks "dull". I think it even rotates slower, though that is working as well. Only the dulling of the crystal is not.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Question on animation textures

Post by Isaac »

Here is a quick-fix that darkens the crystal when clicked: (You must define the regular and dark materials.)
SpoilerShow

Code: Select all

defineObject{
	name = "healing_crystal_black",
	baseObject = "healing_crystal",
	components = {
			{
				class = "Crystal",
				cooldown = 5, --normally 120
				onInit = function(self)  
								self.go.controller:activate()
							end,				
			},
			{class = "Controller",
				onActivate = function (self) self.go.model:setMaterial("healing_crystal_black")  end,
				onDeactivate = function (self) self.go.model:setMaterial("healing_crystal_black_dark")  end,
				
			},
				{
					class = "Clickable",
					offset = vec(0, 1.5, 0),
					size = vec(1.6, 2, 1.6),
					maxDistance = 1,
					onClick = function(self)
								self.go.controller:deactivate()
								delayedCall(self.go.id, self.go.crystal:getCooldown() ,'activate')
							end,
				},
		},
}
Here is an alternate version that [crudely] supports a three stage fade out; but it requires three progressively darker textures; that's an extra 2048k added to your mod for a rough fade. :?
SpoilerShow

Code: Select all

-- This file has been generated by Dungeon Editor 2.2.4

-- TODO: place your custom dungeon object definitions here
defineObject{
	name = "healing_crystal_black",
	baseObject = "healing_crystal",
	components = {
			{
				class = "Crystal",
				cooldown = 5,
				onInit = function(self)  
								self.go.controller:activate()
							end,				
			},
			{class = "Controller",
				onActivate = function (self) self.go.model:setMaterial("healing_crystal_black1")  end,
				onIncrement = function (self)
							local digit = tonumber(string.match(self.go.model:getMaterial(), "%d"))
							if digit <4 then
								self.go.model:setMaterial("healing_crystal_black"..digit + 1) 
							 else return	
							end
							delayedCall(self.go.id, self.go.crystal:getCooldown() ,'decrement')
							for x = .2, .6, .2 do
								delayedCall(self.go.id, x ,'increment')
							end
						end,
				onDecrement = function (self)
							local digit = tonumber(string.match(self.go.model:getMaterial(), "%d"))
							if digit >1 then
								self.go.model:setMaterial("healing_crystal_black"..digit - 1) 
							 else return	
							end
							for x = .2, .6, .2 do
								delayedCall(self.go.id, x ,'decrement')
							end
						end
			},
				{
					class = "Clickable",
					offset = vec(0, 1.5, 0),
					size = vec(1.6, 2, 1.6),
					maxDistance = 1,
					onClick = function(self)
								self.go.controller:increment()
							end,
				},
		},
}
}
Video: https://www.dropbox.com/s/pflyc05j4opd1 ... 2.avi?dl=0

I haven't had a chance to look into the persistent crystal state ~via reload check yet.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Question on animation textures

Post by MrChoke »

UPDATE:

I can get model material changes to stay after a game reload. I do this by doing removeComponet() on trhe model and then re-creating it. It re-renders and holds the new model I set after a save.

HOWEVER, the animations no longer work after I recreate the model. And I don't think I can dynamically create an animation component. So I get one thing working only for another to fail.

There are a few reasons why I took months off of modding this game. Crap like this one of the reasons.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Question on animation textures

Post by Isaac »

Crystals are special objects; (I don't claim to know all the ways), but in the single-save ironman mode, the player cannot save their game except at a crystal. I'd think that any changes to the crystal components should be well tested before used. An error could prevent the player from saving; and potentially lose the whole session.

*But that's a neat idea with removing the component temporarily.
minmay
Posts: 2788
Joined: Mon Sep 23, 2013 2:24 am

Re: Question on animation textures

Post by minmay »

Isaac, if you only want differing colours, why are you messing with a bunch of hacks and different materials when you could just use one greyscale texture and ModelComponent:setEmissiveColor()?
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.
Post Reply