[Tree Feller] Drawing features from Lua

[Tree Feller] Drawing features from Lua

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

[Tree Feller] Drawing features from Lua

Post by Beherith »

I would like to draw falling trees, but I cant get the texture blending right. Depending on which textures I bind, the feature is either completely opaque, or its color is totally black.

Code:

Code: Select all

	function gadget:DrawWorldPreUnit()
		gf=Spring.GetGameFrame()

		for featureID, featureinfo in pairs(treesdying) do
			local x, y, z = featureinfo.posx, featureinfo.posy, featureinfo.posz
			--Spring.Echo('drawing tree:', featureID, featureinfo.frame, gf,'defid',featureinfo.fDefID)
			--local _, b, _ = spGetPositionLosState(x, y, z)
			if (featureinfo.frame +90 < gf) then
				treesdying[featureID]=nil
			else 
				local losState = true
				if ( losState == true ) then
					--glow effect?
					glColor(1.0, 1.0, 1.0, 0.8 )

					
					glTexture(0,"%-" .. featureinfo.fDefID .. ":0 ")
					glTexture(1,"%-" .. featureinfo.fDefID .. ":1 ")

					glTexEnv( GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, 0x8570 ) --GL_COMBINE_RGB
					glPushMatrix()
					glTranslate(x, y, z)
					glRotate(featureinfo.angle,0,y,0)
					
					glRotate((gf-featureinfo.frame)*1,x,0,0)
					Spring.Echo('drawing', featureID,featureinfo.fDefID, x,y,z,"%-" .. featureinfo.fDefID .. ":0 ")
					glFeatureShape(featureinfo.fDefID, gaiaTeamID)
					  
					glPopMatrix()
				end
			end
		end
	end
Screenshot:
Image
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Drawing features from Lua

Post by jK »

likely not possible, you need to patch engine

gl.FeatureShape is not as gl.UnitShape and changes a lot gl states and you can't stop it doing so atm.

So engine needs patched.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Drawing features from Lua

Post by Beherith »

Thanks for clarifying this jK, I got the tree feller to work through intercepting dying trees in FeaturePreDamaged then using SetFeatureDirection.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Drawing features from Lua

Post by FLOZi »

Beherith wrote:Thanks for clarifying this jK, I got the tree feller to work through intercepting dying trees in FeaturePreDamaged then using SetFeatureDirection.
Arguably the more sensible approach :P Do you detect the direction of the collision and fall accordingly? knorke wrote such a system before but iirc it was just random direction.

Has long been on my todo list for S44 to write a feature destruction gadget to mimic some of the effects in world of tanks but one of those things I never got around to.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Drawing features from Lua

Post by knorke »

Do you detect the direction of the collision and fall accordingly? knorke wrote such a system before but iirc it was just random direction.
Yes, mine is random. Getting the direction from unit&feature position should be possible though.
Did not bother with it because falling trees was only one use..
Only works different so not sure how relevant it is...
The crushed feature is replaced by unit for the animation..gives bit more flexibilty than just falling over.
For example in spring tanks the trees "explode" when tanks drive into them. Or wall falls over then shatters http://www.youtube.com/watch?v=ogjf7h5gD8w
Or like this:
Image
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: [Tree Feller] Drawing features from Lua

Post by Beherith »

Here it is guys:

http://imolarpg.dyndns.org/trac/balates ... feller.lua

I also didnt do the directional falling, just random, because the feature rotations are calculated in a wierd way.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Drawing features from Lua

Post by gajop »

jK wrote:likely not possible, you need to patch engine

gl.FeatureShape is not as gl.UnitShape and changes a lot gl states and you can't stop it doing so atm.

So engine needs patched.
Could you please clarify that (so even stupids like myself can understand it), what can't be done exactly? I tried drawing features (with textures) in my scenario editor, but they were always black (with some level of transparency)< where I could always draw units with textures normally.

(Sorry if it feels like I'm hijacking the thread, but I think the question is still on topic)
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: [Tree Feller] Drawing features from Lua

Post by Beherith »

As far as i can see, you cant draw feature with that because the textruing and lighting and shadows states are not set up, and because the depth testing wont work properly. couldnt you just use createfeature in your editor?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: [Tree Feller] Drawing features from Lua

Post by gajop »

Beherith wrote:As far as i can see, you cant draw feature with that because the textruing and lighting and shadows states are not set up, and because the depth testing wont work properly. couldnt you just use createfeature in your editor?
I was drawing them while they still weren't placed on the map, and would like to avoid creating them because it messes with the state (especially multi-"player" editing), as one would need to remove them if they aren't added eventually.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: [Tree Feller] Drawing features from Lua

Post by FLOZi »

For the purposes of pre-placement, does accurate texture representation really matter?

@knorke; Cool water tower. I have wondered if per-featuredef is the best way or if a generic piece projectile spawning unit might be reasonable.
Post Reply

Return to “Lua Scripts”