"Surface Index out of range" (z-sorting!)

Blitz3D Forums/Blitz3D Beginners Area/"Surface Index out of range" (z-sorting!)

Dock(Posted 2006) [#1]
I'm trying to use Beaker's (+fredborg's) Alpha z-sorting code to fix the alpha on a 3000 triangle character. She's not yet animated, but she still causes problems for the systems.

The code I'm using is here:
http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=850

When I run the code on my loaded .b3d model I get "Surface Index out of range".

Does anyone have any idea what is going wrong?

I would really like to be able to enable alpha sorting on my characters to allow use of alpha in the costume design, and I'm starting to think this will be impossible if I stick with blitz. :(


t3K|Mac(Posted 2006) [#2]
i *think* its because your model has pivots and meshes mixed. be sure just to touch the meshes with z-ordering (filterung out pivots). but i am not 100% sure...


Dock(Posted 2006) [#3]
I tried combining the model into a single mesh and it still gives the same error. I don't know how to get it to cope with pivots.


t3K|Mac(Posted 2006) [#4]
http://www.blitzbasic.com/codearcs/codearcs.php?code=850#comments

read this thread, i had the same problem some time ago... but i didn't fix it yet.


Beaker(Posted 2006) [#5]
Try the new version I posted here:
http://www.blitzbasic.com/codearcs/codearcs.php?code=850

You will need to find the surface you want to sort and pass that to the init function, like this:
ZOrder_Init(mesh, surf)


Beaker(Posted 2006) [#6]
Also, some advice about finding the correct surface. Use this:
FindSurfWithTex(texfilename$,mesh,exactmatch=True)
Graphics3D 640,480

myMesh = LoadAnimMesh("dwarf.b3d")

DebugLog FindSurfWithTex("axe",myMesh,False)
DebugLog FindSurfWithTex("dwarf.jpg",myMesh)
Stop
End

Function FindSurfWithTex(texfilename$,mesh,exactmatch=True)
	Local surf,br,tex,texname$

	Local ent = mesh
	While ent
		If EntityClass(ent) = "Mesh"
			For surfcnt = 1 To CountSurfaces(ent)
				surf = GetSurface(ent,surfcnt)
				br = GetSurfaceBrush(surf)
				tex = GetBrushTexture(br)
				texname = StripDir(TextureName(tex))
				If (exactmatch = True And texname = texfilename) Or (exactmatch = False And Instr(texname,texfilename))
					FreeBrush br
					FreeTexture tex
					Return surf
				EndIf
			Next
		EndIf
		ent = NextChild(ent)
	Wend

	Return 0
End Function

Function StripDir$(longpath$)
	While Instr(longpath,"\")
		longpath = Right(longpath,Len(longpath)-Instr(longpath,"\"))
	Wend
	Return longpath
End Function

		
Function NextChild(ent)
	If CountChildren(ent)>0
		Return GetChild(ent,1)
	EndIf

	Local foundunused=False
	Local foundent = 0, parent,sibling
	While foundunused=False And ent<>0
		parent = GetParent(ent)
		If parent<>0
			If CountChildren(parent)>1
				If GetChild(parent,CountChildren(parent))<>ent
					For siblingcnt = 1 To CountChildren(parent)
						sibling = GetChild(parent,siblingcnt)
						If sibling=ent
							foundunused = True
							foundent = GetChild(parent,siblingcnt+1)
						EndIf
					Next
				EndIf
			EndIf
		EndIf
		ent = parent
	Wend
	Return foundent
End Function



Beaker(Posted 2006) [#7]
This is still very limited of course. It doesn't actually take account of animated vertices (using bones), and you will still get instances where the alpha surface draws on top of non-alpha'd stuff (when it shouldn't). But it is an improvement on the current situation.

[EDIT: also this problem isn't unique to Blitz, as its a problem that plagues all realtime rendering systems (DX and GL included). The only way round it is to write code that handles your *particular* game/visuals as best as it can.]