GetSurface Problem

Blitz3D Forums/Blitz3D Programming/GetSurface Problem

Rob Farley(Posted 2005) [#1]
I have a tank mesh with 2 surfaces.

One Surface is the basic paint job, the other is the texture for the tracks.
Function NewTank(x#,z#)
	t.Tank = New Tank
	t\id = GetNextID("Tank")
	t\Mesh = LoadAnimMesh("models\tank.b3d")
	t\w1 = FindChild(t\mesh,"W1")
	t\w2 = FindChild(t\mesh,"W2")
	t\w3 = FindChild(t\mesh,"W3")
	t\w4 = FindChild(t\mesh,"W4")
	t\w5 = FindChild(t\mesh,"W5")
	t\w6 = FindChild(t\mesh,"W6")
	t\w7 = FindChild(t\mesh,"W7")
	t\Turret = FindChild(t\mesh,"Turret")
	t\Barrel = FindChild(t\mesh,"Barrel")
	t\Aimer = CreatePivot(t\mesh)
	t\LastAim = CreatePivot(t\mesh)
	PositionEntity t\Aimer,EntityX(t\Barrel,True),EntityY(t\Barrel,True),EntityZ(t\Barrel,True)
	t\Track = GetSurface(t\Mesh,1)
	t\TrackTex = LoadTexture("models\track.png")
	t\TrackBrush = CreateBrush()
	BrushTexture t\TrackBrush,t\TrackTex
	PaintSurface t\Track,t\trackBrush
	PositionEntityOnGround(t\Mesh,x,z)
	t\EngineSound = EmitSound(snd_Tank,t\Mesh)
	t\EnginePitch = 11025
	t\EngineVolume = 0
	ChannelVolume t\EngineSound,0
End Function
This loads up the tank mesh, paints the track with the track texture. Then with the handle of the track texture per tank I can then move the texture to give the impression of the tracks rolling forward.

This works fine.

The problem however is on this line:
t\Track = GetSurface(t\mesh,1)

It seems for no good reason at all sometimes surface index 1 is the track and other times it's the paint job, there seems to be no rhyme or reason for this to suddenly swap. So I'll run the program once and everything looks fine, I'll run it again and the paint job is now a track texture moving all over it.

Is there any way to find the surface by name or something similar. This is doing my head in!


BlackJumper(Posted 2005) [#2]
Have you tried GetSurfaceBrush combined with GetBrushTexture and TextureName ?


GetSurfaceBrush(surface)
Parameters
surface - surface handle

Description
Returns a brush with the same properties as is applied to the specified mesh surface.

If this command does not appear to be returning a valid brush, try using GetEntityBrush instead.

Remember, GetSurfaceBrush actually creates a new brush so don't forget to free it afterwards using FreeBrush to prevent memory leaks.

Once you have got the brush handle from a surface, you can use GetBrushTexture and TextureName to get the details of what texture(s) are applied to the brush.



Rob Farley(Posted 2005) [#3]
Cool... That sounds like it might do the trick... I'll look into it.


jfk EO-11110(Posted 2005) [#4]
Note: GetSurfaceBrush and GetBrushTexture will create a copy of the original brush and texture, so after tracking down the surfaces you need to free them. See also the SaveB3D example in the archives.