possibility to let materials spin

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!
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

possibility to let materials spin

Post by THOM »

I know you can move textures. In egsample the magma texture is slowly wandering by using

Code: Select all

self:setTexcoordScaleOffset(0.5, 1, time*0.05, 0)
Question: Can you also let a texture spin around it's middleaxis?
And if you can do this by using setTexcoordScaleOffset - which effect do the four argument-numbers cause?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: possibility to let materials spin

Post by minmay »

First and second arguments are the X and Y scale for the texture. Third and fourth arguments are the X and Y offset for the texture. So you can't rotate it; use the "crystal" shader for that.
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
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: possibility to let materials spin

Post by THOM »

ah - thanks, minmay

but how to use the "crystal" shader? If I just put the commands in my material definition the result is weird. Even after altering. And I can't find any description for that :?: :?:

What I use is

Code: Select all

	shader = "crystal",
	shadeTex = "mod_assets/textures/cauldron_soup.tga",
	shadeTexAngle = 0,
	crystalIntensity = 1,
	onUpdate = function(self, time)
		self:setParam("shadeTexAngle", time*0.01)
	end,
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: possibility to let materials spin

Post by minmay »

It's the shader used for healing crystals among other things, look at the healing_crystal material. I don't think you can use it to just rotate a plain texture even if you're okay with losing lighting.

From the name of the material it sounds like you want to make the texture swirl around the center of a circle or similar shape. Why don't you just rotate the circle itself?
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: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: possibility to let materials spin

Post by Isaac »

minmay wrote:Why don't you just rotate the circle itself?
That's what I had to do for the magic circle [portal] in my ORRR2 room. But now it's easier. The tools exist, one can animate it in Blender more effectively.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: possibility to let materials spin

Post by THOM »

aha....

Again it seems, some day I have to have a look at Blender...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: possibility to let materials spin

Post by Isaac »

THOM wrote:aha....

Again it seems, some day I have to have a look at Blender...
Blender would be best IMO, but it is certainly possible to script a repeated rotation using the built in transformation functions.
SpoilerShow
Image

**Just an example.

Code: Select all

-- Animation script, called by a timer to update position.

x = 0
y = 0


function ersatzAnimator()

	 x=x+0.02%4
	 y=y+0.25%.1

	spinner:setPosition(anim_1.x,anim_1.y,x,(math.sin(y)*0.02+0.1),anim_1.level)

end
All you would really need is to adjust the object's facing as a decimal.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: possibility to let materials spin

Post by THOM »

Hey Isaac - that looks interesting.

But I don't understand, how to use this script. Do I have to copy it into the material-definition? Do I have to replace "anim_1" with something?? I can't see something refering to a texture.dss or a model.

And must it not be named "local x = 0 local y = 0" ??

You see: I'm confuded... :?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: possibility to let materials spin

Post by Isaac »

THOM wrote:Hey Isaac - that looks interesting.

But I don't understand, how to use this script. Do I have to copy it into the material-definition? Do I have to replace "anim_1" with something?? I can't see something refering to a texture.dss or a model.

And must it not be named "local x = 0 local y = 0" ??

You see: I'm confuded... :?
I consider myself a novice at scripting. I started Lua when I started Grimock, so I only have a couple years at it ~part time, as a hobby.

My understanding of [currently] is that defining it local would create a temporary copy of the already defined x & y. The point of defining them outside of [and further up from] the function, is to keep them after the function exits. This way, the next time the function runs, the values for x & y are initially what they were when the function last exit. This incrementally rotates one step from its previous position.

If you are trying to rotate a texture on a [square?] tile, using this concept instead of Blender, you might try using an official floor tile, scaled up in GMT, with your texture applied, and transform it with a similar script that only updates the object's facing with setPosition().
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: possibility to let materials spin

Post by minmay »

You should use world rotation (setWorldRotationAngles) instead of facing.
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