lugi.bmx: * Fixed bug where InitWithTypeID would crash for all types because it was trying to access a null member of the LExposedType instance.

SuperStrict

Import "field.bmx"
Import "method.bmx"
Import "metadata.bmx"

Import Brl.LinkedList

Private

Global _exposedTypes:TList = New TList

Public

Type LExposedType
	Field exposed%
	Field static%
	Field noclass%
	Field hidefields%
	Field nonew%

	Field typeid:TTypeId
	Field methods:TList			' TList<LExposedMethod>
	Field fields:TList			' TList<LExposedField>
	Field constructor$
	Field name$

	' Returns an LExposedType for a typeid - recommended to use this instead of creating a new LExposedType and initializing it
	Function ForType:LExposedType(typeid:TTypeId)
		If typeid = ObjectTypeId Or typeid = StringTypeId Or typeid._class = ArrayTypeId._class Then
			Return Null
		EndIf

		Local link:TLink = _exposedTypes.FindLink(typeid)
		If link Then
			Return LExposedType(link.Value())
		EndIf
		Return New LExposedType.InitWithTypeID(typeid)
	End Function

	' Compares LExposedTypes based on the TTypeId associated with each LExposedType
	Method Compare:Int(other:Object)
		Local ot:LExposedType = LExposedType(other)
		If other = Null Then
			Return 1
		ElseIf TTypeId(other) Then
			Return typeid.Compare(other)
		ElseIf other And Not ot Then
			Throw "Invalid type to compare LExposedType against"
		Else
			Return typeid.Compare(ot.typeid)
		EndIf
	End Method

	' Returns a list of exposed types to iterate over
	Function EnumTypes:TList()
		Return _exposedTypes.Copy()
	End Function

	' Initializes an LExposedType with information for the type passed
	' The object returned may not be the one you originally sent the initialize message to
	' If there is already an instance for this type, that instance will be returned instead
	' of proceeding with intialization
	Method InitWithTypeID:LExposedType(tid:TTypeId)
		If tid = ObjectTypeId Or tid = StringTypeId Or tid._class = ArrayTypeId._class Then
			Return Null
		EndIf

		Local lnk:TLink = _exposedTypes.FindLink(tid)
		If lnk Then
			Return LExposedType(lnk.Value())
		EndIf

		exposed = typeid.Metadata(LUGI_META_EXPOSE).ToInt()>0
		static = typeid.Metadata(LUGI_META_STATIC).ToInt()>0
		noclass = typeid.Metadata(LUGI_META_NOCLASS).ToInt()>0
		hidefields = typeid.Metadata(LUGI_META_HIDEFIELDS).ToInt()>0
		nonew = typeid.Metadata(LUGI_META_DISABLECONSTRUCTOR).ToInt()>0

		name = typeid.Metadata(LUGI_META_RENAME).Trim()
		If Not name Then
			name = typeid.Name()
		EndIf

		If Not (nonew Or (static and noclass)) Then
			constructor = typeid.Metadata(LUGI_META_CONSTRUCTOR).Trim()
			If Not constructor Then
				' Force New[A-Z_].* as default
				constructor = "New"+name[0..1].ToUpper()+name[1..]
			EndIf
		EndIf

		__initMethods
		__initFields

		_exposedTypes.AddLast(Self)

		Return Self
	End Method

	Method PreInitBlock:String()
		Local outs$=""

		If Not (static And noclass) Then
			For Local m:LExposedMethod = EachIn methods
				Local initString$ = m.PreInitBlock()
				If initString Then
					outs :+ "~t" + initString + "~n"
				EndIf
			Next
		EndIf

		If Not noclass Then
			For Local f:LExposedField = EachIn fields
				Local initString$ = f.PreInitBlock()
				If initString Then
					outs :+ "~t" + initString + "~n"
				EndIf
			Next
		EndIf

		Return outs
	End Method

	Method PostInitBlock:String()
		If Not (nonew Or (static And noclass)) Then
			Return 	"~tlua_pushlightuserdata lua_vm, Byte Ptr(TTypeId.ForName(~q" + typeid.Name() + "~q)._class)" + ..
					"~tlua_pushcclosure lua_vm, p_lugi_new_object, 1"
		ElseIf static And Not noclass Then
			Return	"~t"
		EndIf
	End Method

	Method MethodImplementations:String()
		Local m:LExposedMethod
		Local outs$
		Local instMethod% = Not (static And noclass)
		Local block$

		For m = EachIn methods
			block = m.Implementation(instMethod)
			If block Then
				outs :+ "~n~n"+block
			EndIf
		Next

		Return outs
	End Method

	Method _exposedInParent:Int(m:TMethod)
		Local name$ = m.Name().ToLower()

		Local typ:TTypeId = typeid.SuperType()
		While typ

		Wend
	End Method

	Method __initMethods()
		methods = New TList

		If Not exposed Then
			Return
		EndIf

		' Build list of exposed methods
		For Local m:TMethod = EachIn typeid.Methods()

		Next
	End Method

	Method __initFields()
		fields = New TList

		If Not exposed Or hidefields Then
			Return
		EndIf

		For Local f:TField = EachIn typeid.Fields()

		Next
	End Method
End Type

' Builds up the information for all types
Function BuildTypeInfo()
End Function

Private

' Recursively creates the information for types
Function _buildTypeInfo(types:TList)
	' Iterate over types and load data for them
	For Local tid:TTypeId = EachIn types
		New LExposedType.InitWithTypeID(tid)
		_buildTypeInfo(tid.DerivedTypes())
	Next
End Function

SuperStrict

Import "field.bmx"
Import "method.bmx"
Import "metadata.bmx"

Import Brl.LinkedList

Private

Global _exposedTypes:TList = New TList

Public

Type LExposedType
	Field exposed%
	Field static%
	Field noclass%
	Field hidefields%
	Field nonew%

	Field typeid:TTypeId
	Field methods:TList			' TList<LExposedMethod>
	Field fields:TList			' TList<LExposedField>
	Field constructor$
	Field name$

	' Returns an LExposedType for a typeid - recommended to use this instead of creating a new LExposedType and initializing it
	Function ForType:LExposedType(typeid:TTypeId)
		If typeid = ObjectTypeId Or typeid = StringTypeId Or typeid._class = ArrayTypeId._class Then
			Return Null
		EndIf

		Local link:TLink = _exposedTypes.FindLink(typeid)
		If link Then
			Return LExposedType(link.Value())
		EndIf
		Return New LExposedType.InitWithTypeID(typeid)
	End Function

	' Compares LExposedTypes based on the TTypeId associated with each LExposedType
	Method Compare:Int(other:Object)
		Local ot:LExposedType = LExposedType(other)
		If other = Null Then
			Return 1
		ElseIf TTypeId(other) Then
			Return typeid.Compare(other)
		ElseIf other And Not ot Then
			Throw "Invalid type to compare LExposedType against"
		Else
			Return typeid.Compare(ot.typeid)
		EndIf
	End Method

	' Returns a list of exposed types to iterate over
	Function EnumTypes:TList()
		Return _exposedTypes.Copy()
	End Function

	' Initializes an LExposedType with information for the type passed
	' The object returned may not be the one you originally sent the initialize message to
	' If there is already an instance for this type, that instance will be returned instead
	' of proceeding with intialization
	Method InitWithTypeID:LExposedType(tid:TTypeId)
		If tid = ObjectTypeId Or typeid = StringTypeId Or typeid._class = ArrayTypeId._class Then
			Return Null
		EndIf

		Local lnk:TLink = _exposedTypes.FindLink(tid)
		If lnk Then
			Return LExposedType(lnk.Value())
		EndIf

		exposed = typeid.Metadata(LUGI_META_EXPOSE).ToInt()>0
		static = typeid.Metadata(LUGI_META_STATIC).ToInt()>0
		noclass = typeid.Metadata(LUGI_META_NOCLASS).ToInt()>0
		hidefields = typeid.Metadata(LUGI_META_HIDEFIELDS).ToInt()>0
		nonew = typeid.Metadata(LUGI_META_DISABLECONSTRUCTOR).ToInt()>0

		name = typeid.Metadata(LUGI_META_RENAME).Trim()
		If Not name Then
			name = typeid.Name()
		EndIf

		If Not (nonew Or (static and noclass)) Then
			constructor = typeid.Metadata(LUGI_META_CONSTRUCTOR).Trim()
			If Not constructor Then
				' Force New[A-Z_].* as default
				constructor = "New"+name[0..1].ToUpper()+name[1..]
			EndIf
		EndIf

		__initMethods
		__initFields

		_exposedTypes.AddLast(Self)

		Return Self
	End Method

	Method PreInitBlock:String()
		Local outs$=""

		If Not (static And noclass) Then
			For Local m:LExposedMethod = EachIn methods
				Local initString$ = m.PreInitBlock()
				If initString Then
					outs :+ "~t" + initString + "~n"
				EndIf
			Next
		EndIf

		If Not noclass Then
			For Local f:LExposedField = EachIn fields
				Local initString$ = f.PreInitBlock()
				If initString Then
					outs :+ "~t" + initString + "~n"
				EndIf
			Next
		EndIf

		Return outs
	End Method

	Method PostInitBlock:String()
		If Not (nonew Or (static And noclass)) Then
			Return 	"~tlua_pushlightuserdata lua_vm, Byte Ptr(TTypeId.ForName(~q" + typeid.Name() + "~q)._class)" + ..
					"~tlua_pushcclosure lua_vm, p_lugi_new_object, 1"
		ElseIf static And Not noclass Then
			Return	"~t"
		EndIf
	End Method

	Method MethodImplementations:String()
		Local m:LExposedMethod
		Local outs$
		Local instMethod% = Not (static And noclass)
		Local block$

		For m = EachIn methods
			block = m.Implementation(instMethod)
			If block Then
				outs :+ "~n~n"+block
			EndIf
		Next

		Return outs
	End Method

	Method _exposedInParent:Int(m:TMethod)
		Local name$ = m.Name().ToLower()

		Local typ:TTypeId = typeid.SuperType()
		While typ

		Wend
	End Method

	Method __initMethods()
		methods = New TList

		If Not exposed Then
			Return
		EndIf

		' Build list of exposed methods
		For Local m:TMethod = EachIn typeid.Methods()

		Next
	End Method

	Method __initFields()
		fields = New TList

		If Not exposed Or hidefields Then
			Return
		EndIf

		For Local f:TField = EachIn typeid.Fields()

		Next
	End Method
End Type

' Builds up the information for all types
Function BuildTypeInfo()
End Function

Private

' Recursively creates the information for types
Function _buildTypeInfo(types:TList)
	' Iterate over types and load data for them
	For Local tid:TTypeId = EachIn types
		New LExposedType.InitWithTypeID(tid)
		_buildTypeInfo(tid.DerivedTypes())
	Next
End Function


Updated xmlrpc.mod version

Updated xmlrpc.mod version

SuperStrict

Rem
	bbdoc: htbaapub.xmlrpc
	about:
EndRem
Module htbaapub.xmlrpc
ModuleInfo "Name: htbaapub.xmlrpc"
ModuleInfo "Version: 0.5"
ModuleInfo "Author: Christiaan Kras"

Import brl.blitz
Import brl.basic
Import brl.map
Import brl.reflection
Import brl.socket

Import "src/expat-2.0.1/src/*.h"
ModuleInfo "CC_OPTS: -DHAVE_EXPAT_CONFIG_H"
?ppc
	ModuleInfo "CC_OPTS: -DWORDS_BIGENDIAN"
?

Import "src/expat-2.0.1/src/xmlparse.c"
Import "src/expat-2.0.1/src/xmlrole.c"
Import "src/expat-2.0.1/src/xmltok.c"
Import "src/expat-2.0.1/src/xmltok_impl.c"
Import "src/expat-2.0.1/src/xmltok_ns.c"

Import "src/xmlrpc-epi-0.54/src/*.h"
Import "glue.cpp"

?Win32
	Import "win32.cpp"
	ModuleInfo "LD_OPTS: -L%PWD%/src/iconv-1.9.2.win32/lib"
	Import "src/iconv-1.9.2.win32/include/*.h"	'http://www.zlatkovic.com/pub/libxml
?

Import "-liconv"

Import "src/xmlrpc-epi-0.54/src/xmlrpc.c"
Import "src/xmlrpc-epi-0.54/src/base64.c"
Import "src/xmlrpc-epi-0.54/src/encodings.c"
Import "src/xmlrpc-epi-0.54/src/queue.c"
Import "src/xmlrpc-epi-0.54/src/simplestring.c"
Import "src/xmlrpc-epi-0.54/src/system_methods.c"
Import "src/xmlrpc-epi-0.54/src/xml_element.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_dandarpc.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_soap.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_xmlrpc.c"
Import "src/xmlrpc-epi-0.54/src/xmlrpc_introspection.c"

Include "wrapper.bmx"
Include "datatypes.bmx"
Include "response.bmx"
Include "transport.bmx"
Include "client.bmx"
Include "server.bmx"

Rem
	bbdoc:
End Rem
Type TXMLRPC_Exception
	Field message:String
	Rem
		bbdoc:
	End Rem
	Method Create:TXMLRPC_Exception(message:String)
		Self.message = message
	End Method

	Rem
		bbdoc:
	End Rem
	Method ToString:String()
		Return Self.message
	End Method
End Type

Rem
	bbdoc:
End Rem
Type TXMLRPC_Call_Parameters
	Field vector:Byte Ptr

	Rem
		bbdoc:
	End Rem
	Function Create:TXMLRPC_Call_Parameters(vectorType:Int = xmlrpc_vector_mixed)
		Local parameters:TXMLRPC_Call_Parameters = New TXMLRPC_Call_Parameters
		parameters.vector = XMLRPC_CreateVector(Null, vectorType)
		Return parameters
	End Function

	Rem
		bbdoc:
	End Rem
	Method AppendString:Int(id:String, s:String)
		Return XMLRPC_VectorAppendString(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendBase64:Int(id:String, s:String)
		Return XMLRPC_VectorAppendBase64(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDateTime:Int(id:String, time:Long)
		Return XMLRPC_VectorAppendDateTime(Self.vector, id, time)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDateTime_ISO8601:Int(id:String, s:String)
		Return XMLRPC_VectorAppendDateTime_ISO8601(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDouble:Int(id:String, f:Double)
		Return XMLRPC_VectorAppendDouble(Self.vector, id, f)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendInt:Int(id:String, i:Int)
		Return XMLRPC_VectorAppendInt(Self.vector, id, i)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendBoolean:Int(id:String, i:Byte)
		Return XMLRPC_VectorAppendBoolean(Self.vector, id, i)
	End Method
End Type

SuperStrict

Rem
	bbdoc: htbaapub.xmlrpc
	about:
EndRem
Module htbaapub.xmlrpc
ModuleInfo "Name: htbaapub.xmlrpc"
ModuleInfo "Version: 0.1"
ModuleInfo "Author: Christiaan Kras"

Import brl.blitz
Import brl.basic
Import brl.map
Import brl.reflection
Import brl.socket

Import "src/expat-2.0.1/src/*.h"
ModuleInfo "CC_OPTS: -DHAVE_EXPAT_CONFIG_H"
?ppc
	ModuleInfo "CC_OPTS: -DWORDS_BIGENDIAN"
?

Import "src/expat-2.0.1/src/xmlparse.c"
Import "src/expat-2.0.1/src/xmlrole.c"
Import "src/expat-2.0.1/src/xmltok.c"
Import "src/expat-2.0.1/src/xmltok_impl.c"
Import "src/expat-2.0.1/src/xmltok_ns.c"

Import "src/xmlrpc-epi-0.54/src/*.h"
Import "glue.cpp"

?Win32
	Import "win32.cpp"
	ModuleInfo "LD_OPTS: -L%PWD%/src/iconv-1.9.2.win32/lib"
	Import "src/iconv-1.9.2.win32/include/*.h"	'http://www.zlatkovic.com/pub/libxml
?

Import "-liconv"

Import "src/xmlrpc-epi-0.54/src/xmlrpc.c"
Import "src/xmlrpc-epi-0.54/src/base64.c"
Import "src/xmlrpc-epi-0.54/src/encodings.c"
Import "src/xmlrpc-epi-0.54/src/queue.c"
Import "src/xmlrpc-epi-0.54/src/simplestring.c"
Import "src/xmlrpc-epi-0.54/src/system_methods.c"
Import "src/xmlrpc-epi-0.54/src/xml_element.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_dandarpc.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_soap.c"
Import "src/xmlrpc-epi-0.54/src/xml_to_xmlrpc.c"
Import "src/xmlrpc-epi-0.54/src/xmlrpc_introspection.c"

Include "wrapper.bmx"
Include "datatypes.bmx"
Include "response.bmx"
Include "transport.bmx"
Include "client.bmx"
Include "server.bmx"

Rem
	bbdoc:
End Rem
Type TXMLRPC_Exception
	Field message:String
	Rem
		bbdoc:
	End Rem
	Method Create:TXMLRPC_Exception(message:String)
		Self.message = message
	End Method

	Rem
		bbdoc:
	End Rem
	Method ToString:String()
		Return Self.message
	End Method
End Type

Rem
	bbdoc:
End Rem
Type TXMLRPC_Call_Parameters
	Field vector:Byte Ptr

	Rem
		bbdoc:
	End Rem
	Function Create:TXMLRPC_Call_Parameters(vectorType:Int = xmlrpc_vector_mixed)
		Local parameters:TXMLRPC_Call_Parameters = New TXMLRPC_Call_Parameters
		parameters.vector = XMLRPC_CreateVector(Null, vectorType)
		Return parameters
	End Function

	Rem
		bbdoc:
	End Rem
	Method AppendString:Int(id:String, s:String)
		Return XMLRPC_VectorAppendString(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendBase64:Int(id:String, s:String)
		Return XMLRPC_VectorAppendBase64(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDateTime:Int(id:String, time:Long)
		Return XMLRPC_VectorAppendDateTime(Self.vector, id, time)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDateTime_ISO8601:Int(id:String, s:String)
		Return XMLRPC_VectorAppendDateTime_ISO8601(Self.vector, id, s)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendDouble:Int(id:String, f:Double)
		Return XMLRPC_VectorAppendDouble(Self.vector, id, f)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendInt:Int(id:String, i:Int)
		Return XMLRPC_VectorAppendInt(Self.vector, id, i)
	End Method

	Rem
		bbdoc:
	End Rem
	Method AppendBoolean:Int(id:String, i:Byte)
		Return XMLRPC_VectorAppendBoolean(Self.vector, id, i)
	End Method
End Type


Adding picking functions

Adding picking functions

Strict

Rem
	bbdoc: MaxB3D procedural functions
End Rem
Module MaxB3D.Functions
ModuleInfo "Author: Kevin Primm"
ModuleInfo "License: MIT"

Import MaxB3D.Core

Rem
	bbdoc: Draws the world in its current state.
	about: Tweening is not yet implemented.
End Rem
Function RenderWorld:TRenderInfo(tween#=1.0)
	Return CurrentWorld().Render(tween)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function RenderCamera:TRenderInfo(camera:TCamera)
	Return CurrentWorld().RenderCamera(camera)
End Function
Rem
	bbdoc: Advances all animations and updates collision/physics.
End Rem
Function UpdateWorld(speed#=1.0)
	Return CurrentWorld().Update(speed)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCollisions(src,dest,methd,response)
	Return CurrentWorld().SetCollisions(src,dest,methd,response)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetAmbientLight(red Var,green Var,blue Var)
	Return CurrentWorld().GetAmbientLight(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetAmbientLight(red,green,blue)
	Return CurrentWorld().SetAmbientLight(red,green,blue)
End Function
Rem
	returns: Wireframe rendering state, see #SetWireframe
End Rem
Function GetWireFrame()
	Return CurrentWorld().GetWireFrame()
End Function
Rem
	bbdoc: Enable/disable global wireframe rendering.
	about: @SetWireframe can enable wireframe rendering for the entire scene. Alternatively, calling #SetEntityFX with @FX_WIREFRAME will cause only
			a single entity's wireframe to be rendered.
End Rem
Function SetWireFrame(enable)
	Return CurrentWorld().SetWireFrame(enable)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetDither()
	Return CurrentWorld().GetDither()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetDither(enable)
	Return CurrentWorld().SetDither(enable)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function WorldPick:TPick[](src:Object, target:Object, sort = False)
	Return CurrentWorld().Pick(src,target, sort)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ClearTextureFilters()
	Return CurrentWorld().ClearTextureFilters()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddTextureFilter(text$, flags)
	Return CurrentWorld().AddTextureFilter(text, flags)
End Function

'Bodies
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateBody:TBody()
	Return CurrentWorld().AddBody()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBodyMass#(body:TBody)
	Return body.GetMass()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBodyMass(body:TBody,mass#)
	Return body.SetMass(mass)
End Function

'Brushes
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateBrush:TBrush(url:Object=Null)
	Return CurrentWorld().AddBrush(url)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CopyBrush:TBrush(brush:TBrush)
	Return brush.Copy()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushColor(brush:TBrush,red Var,green Var,blue Var)
	Return brush.GetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushColor(brush:TBrush,red,green,blue)
	Return brush.SetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushAlpha#(brush:TBrush)
	Return brush.GetAlpha()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushAlpha(brush:TBrush,alpha#)
	Return brush.SetAlpha(alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushShine#(brush:TBrush)
	Return brush.GetShine()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushShine(brush:TBrush,shine#)
	Return brush.SetShine(shine)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushTexture:TTexture(brush:TBrush,index=0)
	Return brush.GetTexture(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushTexture(brush:TBrush,texture:TTexture,index=0,frame=0)
	Return brush.SetTexture(texture,index,frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushFrame(brush:TBrush,index=0)
	Return brush.GetFrame(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushFrame(brush:TBrush,frame,index=0)
	Return brush.SetFrame(frame,index)
End Function
Rem
	bbdoc: Get brush effects.
End Rem
Function GetBrushFX(brush:TBrush)
	Return brush.GetFX()
End Function
Rem
	bbdoc: Set various rendering effects for a brush.
	about:
End Rem
Function SetBrushFX(brush:TBrush,fx)
	Return brush.SetFX(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushBlend(brush:TBrush)
	Return brush.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushBlend(brush:TBrush,fx)
	Return brush.SetBlend(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushShader:TShader(brush:TBrush)
	Return brush.GetShader()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushShader(brush:TBrush,shader:TShader)
	Return brush.SetShader(shader)
End Function

'Cameras
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateCamera:TCamera(parent:TEntity=Null)
	Return CurrentWorld().AddCamera(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraMode(camera:TCamera)
	Return camera.GetMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraMode(camera:TCamera,mode)
	Return camera.SetMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogMode(camera:TCamera)
	Return camera.GetFogMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogMode(camera:TCamera,mode)
	Return camera.SetFogMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogColor(camera:TCamera,red Var,green Var,blue Var)
	Return camera.GetFogColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogColor(camera:TCamera,red,green,blue)
	Return camera.SetFogColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogRange(camera:TCamera,near# Var,far# Var)
	Return camera.GetFogRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogRange(camera:TCamera,near#,far#)
	Return camera.SetFogRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraViewport(camera:TCamera,x Var,y Var,width Var,height Var)
	Return camera.GetViewport(x,y,width,height)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraViewport(camera:TCamera,x,y,width,height)
	Return camera.SetViewport(x,y,width,height)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraClsMode(camera:TCamera)
	Return camera.GetClsMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraClsMode(camera:TCamera,mode)
	Return camera.SetClsMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraRange(camera:TCamera,near# Var,far# Var)
	Return camera.GetRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraRange(camera:TCamera,near#,far#)
	Return camera.SetRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraZoom#(camera:TCamera)
	Return camera.GetZoom()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraZoom(camera:TCamera,zoom#)
	Return camera.SetZoom(zoom)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFOV#(camera:TCamera)
	Return camera.GetFOV()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFOV(camera:TCamera,angle#)
	Return camera.SetFOV(angle)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraInView#(camera:TCamera,target:Object)
	Return camera.InView(target)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraProject(camera:TCamera,target:Object,x# Var,y# Var, offset#[] = Null)
	Return camera.Project(target,x,y,offset)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraUnproject(camera:TCamera,wx#,wy#,wz#,x# Var,y# Var,z# Var)
	Return camera.Unproject(wx,wy,wz,x,y,z)
End Function

'Entities
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CopyEntity:TEntity(entity:TEntity,parent:TEntity=Null)
	Return entity.Copy(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FreeEntity(entity:TEntity)
	Return entity.Free()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityParent:TEntity(entity:TEntity)
	Return entity.GetParent()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityParent(entity:TEntity,parent:TEntity)
	Return entity.SetParent(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountEntityChildren(entity:TEntity,recursive=False)
	Return entity.CountChildren(recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FindEntityChild:TEntity(entity:TEntity, name$, recursive = False)
	Return entity.FindChild(name, recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityVisible(entity:TEntity)
	Return entity.GetVisible()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityVisible(entity:TEntity,visible)
	Return entity.SetVisible(visible)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityOrder(entity:TEntity)
	Return entity.GetOrder()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityOrder(entity:TEntity,order)
	Return entity.SetOrder(order)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityName$(entity:TEntity)
	Return entity.GetName()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityName(entity:TEntity,name$)
	Return entity.SetName(name)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBrush:TBrush(entity:TEntity)
	Return entity.GetBrush()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBrush(entity:TEntity,brush:TBrush)
	Return entity.SetBrush(brush)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityColor(entity:TEntity,red Var,green Var,blue Var)
	Return entity.GetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityColor(entity:TEntity,red,green,blue)
	Return entity.SetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityAlpha#(entity:TEntity)
	Return entity.GetAlpha()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityAlpha(entity:TEntity,alpha#)
	Return entity.SetAlpha(alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityShine#(entity:TEntity)
	Return entity.GetShine()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityShine(entity:TEntity,shine#)
	Return entity.SetShine(shine)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityTexture:TTexture(entity:TEntity,index=0)
	Return entity.GetTexture(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityTexture(entity:TEntity,texture:TTexture,index=0,frame=0)
	Return entity.SetTexture(texture,index,frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityFX(entity:TEntity)
	Return entity.GetFX()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityFX(entity:TEntity,fx)
	Return entity.SetFX(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBlend(entity:TEntity)
	Return entity.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBlend(entity:TEntity,blend)
	Return entity.SetBlend(blend)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityShader:TShader(entity:TEntity)
	Return entity.GetShader()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityShader(entity:TEntity,shader:TShader)
	Return entity.SetShader(shader)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TurnEntity(entity:TEntity,pitch#,yaw#,roll#,glob=False)
	Return entity.Turn(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function PointEntity(entity:TEntity,target:Object,roll#=0.0)
	Return entity.Point(target,roll)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function MoveEntity(entity:TEntity,x#,y#,z#)
	Return entity.Move(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TranslateEntity(entity:TEntity,x#,y#,z#,glob=True)
	Return entity.Translate(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityScale(entity:TEntity,x# Var,y# Var,z# Var,glob=False)
	Return entity.GetScale(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityScale(entity:TEntity,x#,y#,z#,glob=False)
	Return entity.SetScale(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityRotation(entity:TEntity,pitch# Var,yaw# Var,roll# Var,glob=False)
	Return entity.GetRotation(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityRotation(entity:TEntity,pitch#,yaw#,roll#,glob=False)
	Return entity.SetRotation(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityPosition(entity:TEntity,x# Var,y# Var,z# Var,glob=False)
	Return entity.GetPosition(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityPosition(entity:TEntity,x#,y#,z#,glob=False)
	Return entity.SetPosition(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TransformEntity(entity:TEntity,matrix:TMatrix,glob=False)
	Return entity.Transform(matrix,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityCollisions:TCollision[](entity:TEntity)
	Return entity.GetCollisions()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBox(entity:TEntity,x# Var,y# Var,z# Var,width# Var,height# Var,depth# Var)
	Return entity.GetBox(x,y,z,width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBox(entity:TEntity,x#,y#,z#,width#,height#,depth#)
	Return entity.SetBox(x,y,z,width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityRadius(entity:TEntity,x# Var,y# Var)
	Return entity.GetRadius(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityRadius(entity:TEntity,x#,y#=-1)
	Return entity.SetRadius(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityType(entity:TEntity)
	Return entity.GetType()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityType(entity:TEntity,typ,recursive=False)
	Return entity.SetType(typ,recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ResetEntity(entity:TEntity)
	Return entity.Reset()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityPickMode(entity:TEntity, mode Var, obscurer Var)
	Return entity.GetPickMode(mode, obscurer)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityPickMode(entity:TEntity, mode, obscurer = True)
	Return entity.SetPickMode(mode, obscurer)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityCullRadius#(entity:TEntity)
	Return entity.GetCullRadius()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityCullRadius#(entity:TEntity,radius#)
	Return entity.SetCullRadius(radius)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityDistance#(entity:TEntity,target:Object)
	Return entity.GetDistance(target)
End Function

'Lights
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateLight:TLight(typ=LIGHT_DIRECTIONAL,parent:TEntity=Null)
	Return CurrentWorld().AddLight(typ,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetLightRange#(light:TLight)
	Return light.GetRange()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetLightRange(light:TLight,range#)
	Return light.SetRange(range)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetLightAngles(light:TLight,inner# Var,outer# Var)
	Return light.GetAngles(inner,outer)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetLightAngles(light:TLight,inner#,outer#)
	Return light.SetAngles(inner,outer)
End Function

'Meshes
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateMesh:TMesh(parent:TEntity=Null)
	Return CurrentWorld().AddMesh("//empty",parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadMesh:TMesh(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddMesh(url,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshSurface:TSurface(mesh:TMesh,index)
	Return mesh.GetSurface(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddMeshSurface:TSurface(mesh:TMesh,brush:TBrush=Null,vertexcount=0,trianglecount=0)
	Return mesh.AddSurface(brush,vertexcount,trianglecount)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SwapMeshSurface(mesh:TMesh,surface:TSurface,new_surface:TSurface)
	Return mesh.SwapSurface(surface,new_surface)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CloneMesh:TMesh(mesh:TMesh,parent:TEntity=Null)
	Return mesh.Clone(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TranslateMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Translate(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ScaleMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Scale(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function RotateMesh(mesh:TMesh,pitch#,yaw#,roll#)
	Return mesh.Rotate(pitch,yaw,roll)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function PositionMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Position(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CenterMesh(mesh:TMesh)
	Return mesh.Center()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshSize(mesh:TMesh,width# Var,height# Var,depth# Var)
	Return mesh.GetSize(width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FitMesh(mesh:TMesh,x#,y#,z#,width#,height#,depth#,uniform=False)
	Return mesh.Fit(x,y,z,width,height,depth,uniform)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FlipMesh(mesh:TMesh)
	Return mesh.Flip()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UpdateMeshNormals(mesh:TMesh,smoothing=True)
	Return mesh.UpdateNormals(smoothing)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnim(mesh:TMesh,seq:TAnimSeq,mode=ANIMATION_LOOP,speed#=1.0)
	Return mesh.SetAnim(seq,mode,speed)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddMeshAnimSeq:TAnimSeq(mesh:TMesh)
	Return mesh.AddAnimSeq(0,0)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ExtractMeshAnimSeq:TAnimSeq(mesh:TMesh,start_frame,end_frame)
	Return mesh.ExtractAnimSeq(start_frame,end_frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimSeq:TAnimSeq(mesh:TMesh)
	Return mesh.GetAnimSeq()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimSeq(mesh:TMesh,seq:TAnimSeq)
	Return mesh.SetAnimSeq(seq)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimMode(mesh:TMesh)
	Return mesh.GetAnimMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimMode(mesh:TMesh,mode)
	Return mesh.SetAnimMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimSpeed#(mesh:TMesh)
	Return mesh.GetAnimSpeed()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimSpeed(mesh:TMesh,speed#)
	Return mesh.SetAnimSpeed(speed)
End Function

'Animation
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateAnimSeq:TAnimSeq(first,last,name$="")
	Return TAnimSeq.Create(first,last,name)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetAnimSeqName$(seq:TAnimSeq)
	Return seq.GetName()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetAnimSeqName(seq:TAnimSeq,name$)
	Return seq.SetName(name)
End Function

'Pivots
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreatePivot:TPivot(parent:TEntity=Null)
	Return CurrentWorld().AddPivot(parent)
End Function

'Flats (plane)
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateFlat:TFlat(parent:TEntity=Null)
	Return CurrentWorld().AddFlat(parent)
End Function

'Sprite
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateSprite:TSprite(parent:TEntity=Null)
	Return CurrentWorld().AddSprite(Null,TEXTURE_DEFAULT,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadSprite:TSprite(url:Object,flags=TEXTURE_DEFAULT,parent:TEntity=Null)
	Return CurrentWorld().AddSprite(url,flags,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteAngle#(sprite:TSprite)
	Return sprite.GetAngle()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSpriteAngle(sprite:TSprite,angle#)
	Return sprite.SetAngle(angle)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteHandle(sprite:TSprite,x# Var,y# Var)
	Return sprite.GetHandle(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End RemS
Function SetSpriteHandle(sprite:TSprite,x#,y#)
	Return sprite.SetHandle(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteViewMode(sprite:TSprite)
	Return sprite.GetViewMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSpriteViewMode(sprite:TSprite,mode)
	Return sprite.SetViewMode(mode)
End Function

'Surfaces
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountSurfaceVertices(surface:TSurface)
	Return surface.CountVertices()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountSurfaceTriangles(surface:TSurface)
	Return surface.CountTriangles()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UpdateSurfaceNormals(surface:TSurface,smoothing=True)
	Return surface.UpdateNormals(smoothing)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ResizeSurface(surface:TSurface,vertex_count,triangle_count)
	Return surface.Resize(vertex_count,triangle_count)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddSurfaceVertex(surface:TSurface,x#,y#,z#,u#=0.0,v#=0.0)
	Return surface.AddVertex(x,y,z,u,v)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceCoords(surface:TSurface,index,x# Var,y# Var,z# Var)
	Return surface.GetCoords(index,x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceCoords(surface:TSurface,index,x#,y#,z#)
	Return surface.SetCoords(index,x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceColor(surface:TSurface,index,red Var,green Var,blue Var,alpha# Var)
	Return surface.GetColor(index,red,green,blue,alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceColor(surface:TSurface,index,red,green,blue,alpha#)
	Return surface.SetColor(index,red,green,blue,alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceNormal(surface:TSurface,index,nx# Var,ny# Var,nz# Var)
	Return surface.GetNormal(index,nx,ny,nz)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceNormal(surface:TSurface,index,nx#,ny#,nz#)
	Return surface.SetNormal(index,nx,ny,nz)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceTexCoords(surface:TSurface,index,u# Var,v# Var,set=0)
	Return surface.GetTexCoords(index,u,v,set)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceTexCoords(surface:TSurface,index,u#,v#,set=0)
	Return surface.SetTexCoords(index,u,v,set)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddSurfaceTriangle(surface:TSurface,v0,v1,v2)
	Return surface.AddTriangle(v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceTriangle(surface:TSurface,index,v0 Var,v1 Var,v2 Var)
	Return surface.GetTriangle(index,v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceTriangle(surface:TSurface,index,v0,v1,v2)
	Return surface.SetTriangle(index,v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceBrush:TBrush(surface:TSurface)
	Return surface.GetBrush()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceBrush(surface:TSurface,brush:TBrush)
	Return surface.SetBrush(brush)
End Function

'Terrains
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateTerrain:TTerrain(size,parent:TEntity=Null)
	Return CurrentWorld().AddTerrain([size],parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadTerrain:TTerrain(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddTerrain(url,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTerrainDetail(terrain:TTerrain,lmax,max_tris,clmax=-1)
	Return terrain.SetDetail(lmax,max_tris,clmax)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTerrainHeight#(terrain:TTerrain,x,z)
	Return terrain.GetHeight(x,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTerrainHeight(terrain:TTerrain,height#,x,z)
	Return terrain.SetHeight(height,x,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTerrainSize(terrain:TTerrain)
	Return terrain.GetSize()
End Function

'Textures
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateTexture:TTexture(width,height,flags=TEXTURE_COLOR|TEXTURE_MIPMAP,frames=1)
	Local texture:TTexture=CurrentWorld().AddTexture([width,height,frames],flags)
	texture.SetPixmap(CreatePixmap(width,height,PF_RGBA8888))
	Return texture
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadTexture:TTexture(url:Object,flags=TEXTURE_COLOR|TEXTURE_MIPMAP)
	Return CurrentWorld().AddTexture(url,flags)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LockTexture:TPixmap(texture:TTexture)
	Return texture.Lock()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UnlockTexture(texture:TTexture)
	Return texture.Unlock()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureFlags(texture:TTexture)
	Return texture.GetFlags()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureFlags(texture:TTexture,flags)
	Return texture.SetFlags(flags)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureBlend(texture:TTexture)
	Return texture.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureBlend(texture:TTexture,blend)
	Return texture.SetBlend(blend)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureCoords(texture:TTexture)
	Return texture.GetCoords()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureCoords(texture:TTexture,coords)
	Return texture.SetCoords(coords)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureScale(texture:TTexture,x# Var,y# Var)
	Return texture.GetScale(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureScale(texture:TTexture,x#,y#)
	Return texture.SetScale(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureRotation#(texture:TTexture)
	Return texture.GetRotation()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureRotation(texture:TTexture,rotation#)
	Return texture.SetRotation(rotation)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTexturePosition(texture:TTexture,x# Var,y# Var)
	Return texture.GetPosition(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTexturePosition(texture:TTexture,x#,y#)
	Return texture.SetPosition(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureSize(texture:TTexture,width Var,height Var)
	Return texture.GetSize(width,height)
End Function

'BSP
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadBSPModel:TBSPModel(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddBSPModel(url,parent)
End Function

SetWorld CreateWorld()

Strict

Rem
	bbdoc: MaxB3D procedural functions
End Rem
Module MaxB3D.Functions
ModuleInfo "Author: Kevin Primm"
ModuleInfo "License: MIT"

Import MaxB3D.Core

Rem
	bbdoc: Draws the world in its current state.
	about: Tweening is not yet implemented.
End Rem
Function RenderWorld:TRenderInfo(tween#=1.0)
	Return CurrentWorld().Render(tween)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function RenderCamera:TRenderInfo(camera:TCamera)
	Return CurrentWorld().RenderCamera(camera)
End Function
Rem
	bbdoc: Advances all animations and updates collision/physics.
End Rem
Function UpdateWorld(speed#=1.0)
	Return CurrentWorld().Update(speed)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCollisions(src,dest,methd,response)
	Return CurrentWorld().SetCollisions(src,dest,methd,response)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetAmbientLight(red Var,green Var,blue Var)
	Return CurrentWorld().GetAmbientLight(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetAmbientLight(red,green,blue)
	Return CurrentWorld().SetAmbientLight(red,green,blue)
End Function
Rem
	returns: Wireframe rendering state, see #SetWireframe
End Rem
Function GetWireFrame()
	Return CurrentWorld().GetWireFrame()
End Function
Rem
	bbdoc: Enable/disable global wireframe rendering.
	about: @SetWireframe can enable wireframe rendering for the entire scene. Alternatively, calling #SetEntityFX with @FX_WIREFRAME will cause only
			a single entity's wireframe to be rendered.
End Rem
Function SetWireFrame(enable)
	Return CurrentWorld().SetWireFrame(enable)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetDither()
	Return CurrentWorld().GetDither()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetDither(enable)
	Return CurrentWorld().SetDither(enable)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function WorldPick:TPick[](src:Object, target:Object, sort = False)
	Return CurrentWorld().Pick(src,target, sort)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ClearTextureFilters()
	Return CurrentWorld().ClearTextureFilters()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddTextureFilter(text$, flags)
	Return CurrentWorld().AddTextureFilter(text, flags)
End Function

'Bodies
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateBody:TBody()
	Return CurrentWorld().AddBody()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBodyMass#(body:TBody)
	Return body.GetMass()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBodyMass(body:TBody,mass#)
	Return body.SetMass(mass)
End Function

'Brushes
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateBrush:TBrush(url:Object=Null)
	Return CurrentWorld().AddBrush(url)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CopyBrush:TBrush(brush:TBrush)
	Return brush.Copy()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushColor(brush:TBrush,red Var,green Var,blue Var)
	Return brush.GetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushColor(brush:TBrush,red,green,blue)
	Return brush.SetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushAlpha#(brush:TBrush)
	Return brush.GetAlpha()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushAlpha(brush:TBrush,alpha#)
	Return brush.SetAlpha(alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushShine#(brush:TBrush)
	Return brush.GetShine()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushShine(brush:TBrush,shine#)
	Return brush.SetShine(shine)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushTexture:TTexture(brush:TBrush,index=0)
	Return brush.GetTexture(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushTexture(brush:TBrush,texture:TTexture,index=0,frame=0)
	Return brush.SetTexture(texture,index,frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushFrame(brush:TBrush,index=0)
	Return brush.GetFrame(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushFrame(brush:TBrush,frame,index=0)
	Return brush.SetFrame(frame,index)
End Function
Rem
	bbdoc: Get brush effects.
End Rem
Function GetBrushFX(brush:TBrush)
	Return brush.GetFX()
End Function
Rem
	bbdoc: Set various rendering effects for a brush.
	about:
End Rem
Function SetBrushFX(brush:TBrush,fx)
	Return brush.SetFX(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushBlend(brush:TBrush)
	Return brush.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushBlend(brush:TBrush,fx)
	Return brush.SetBlend(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetBrushShader:TShader(brush:TBrush)
	Return brush.GetShader()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetBrushShader(brush:TBrush,shader:TShader)
	Return brush.SetShader(shader)
End Function

'Cameras
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateCamera:TCamera(parent:TEntity=Null)
	Return CurrentWorld().AddCamera(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraMode(camera:TCamera)
	Return camera.GetMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraMode(camera:TCamera,mode)
	Return camera.SetMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogMode(camera:TCamera)
	Return camera.GetFogMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogMode(camera:TCamera,mode)
	Return camera.SetFogMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogColor(camera:TCamera,red Var,green Var,blue Var)
	Return camera.GetFogColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogColor(camera:TCamera,red,green,blue)
	Return camera.SetFogColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFogRange(camera:TCamera,near# Var,far# Var)
	Return camera.GetFogRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFogRange(camera:TCamera,near#,far#)
	Return camera.SetFogRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraViewport(camera:TCamera,x Var,y Var,width Var,height Var)
	Return camera.GetViewport(x,y,width,height)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraViewport(camera:TCamera,x,y,width,height)
	Return camera.SetViewport(x,y,width,height)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraClsMode(camera:TCamera)
	Return camera.GetClsMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraClsMode(camera:TCamera,mode)
	Return camera.SetClsMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraRange(camera:TCamera,near# Var,far# Var)
	Return camera.GetRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraRange(camera:TCamera,near#,far#)
	Return camera.SetRange(near,far)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraZoom#(camera:TCamera)
	Return camera.GetZoom()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraZoom(camera:TCamera,zoom#)
	Return camera.SetZoom(zoom)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetCameraFOV#(camera:TCamera)
	Return camera.GetFOV()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetCameraFOV(camera:TCamera,angle#)
	Return camera.SetFOV(angle)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraInView#(camera:TCamera,target:Object)
	Return camera.InView(target)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraProject(camera:TCamera,target:Object,x# Var,y# Var, offset#[] = Null)
	Return camera.Project(target,x,y,offset)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CameraUnproject(camera:TCamera,wx#,wy#,wz#,x# Var,y# Var,z# Var)
	Return camera.Unproject(wx,wy,wz,x,y,z)
End Function

'Entities
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CopyEntity:TEntity(entity:TEntity,parent:TEntity=Null)
	Return entity.Copy(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FreeEntity(entity:TEntity)
	Return entity.Free()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityParent:TEntity(entity:TEntity)
	Return entity.GetParent()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityParent(entity:TEntity,parent:TEntity)
	Return entity.SetParent(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountEntityChildren(entity:TEntity,recursive=False)
	Return entity.CountChildren(recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FindEntityChild:TEntity(entity:TEntity, name$, recursive = False)
	Return entity.FindChild(name, recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityVisible(entity:TEntity)
	Return entity.GetVisible()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityVisible(entity:TEntity,visible)
	Return entity.SetVisible(visible)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityOrder(entity:TEntity)
	Return entity.GetOrder()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityOrder(entity:TEntity,order)
	Return entity.SetOrder(order)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityName$(entity:TEntity)
	Return entity.GetName()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityName(entity:TEntity,name$)
	Return entity.SetName(name)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBrush:TBrush(entity:TEntity)
	Return entity.GetBrush()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBrush(entity:TEntity,brush:TBrush)
	Return entity.SetBrush(brush)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityColor(entity:TEntity,red Var,green Var,blue Var)
	Return entity.GetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityColor(entity:TEntity,red,green,blue)
	Return entity.SetColor(red,green,blue)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityAlpha#(entity:TEntity)
	Return entity.GetAlpha()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityAlpha(entity:TEntity,alpha#)
	Return entity.SetAlpha(alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityShine#(entity:TEntity)
	Return entity.GetShine()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityShine(entity:TEntity,shine#)
	Return entity.SetShine(shine)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityTexture:TTexture(entity:TEntity,index=0)
	Return entity.GetTexture(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityTexture(entity:TEntity,texture:TTexture,index=0,frame=0)
	Return entity.SetTexture(texture,index,frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityFX(entity:TEntity)
	Return entity.GetFX()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityFX(entity:TEntity,fx)
	Return entity.SetFX(fx)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBlend(entity:TEntity)
	Return entity.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBlend(entity:TEntity,blend)
	Return entity.SetBlend(blend)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityShader:TShader(entity:TEntity)
	Return entity.GetShader()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityShader(entity:TEntity,shader:TShader)
	Return entity.SetShader(shader)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TurnEntity(entity:TEntity,pitch#,yaw#,roll#,glob=False)
	Return entity.Turn(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function PointEntity(entity:TEntity,target:Object,roll#=0.0)
	Return entity.Point(target,roll)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function MoveEntity(entity:TEntity,x#,y#,z#)
	Return entity.Move(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TranslateEntity(entity:TEntity,x#,y#,z#,glob=True)
	Return entity.Translate(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityScale(entity:TEntity,x# Var,y# Var,z# Var,glob=False)
	Return entity.GetScale(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityScale(entity:TEntity,x#,y#,z#,glob=False)
	Return entity.SetScale(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityRotation(entity:TEntity,pitch# Var,yaw# Var,roll# Var,glob=False)
	Return entity.GetRotation(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityRotation(entity:TEntity,pitch#,yaw#,roll#,glob=False)
	Return entity.SetRotation(pitch,yaw,roll,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityPosition(entity:TEntity,x# Var,y# Var,z# Var,glob=False)
	Return entity.GetPosition(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityPosition(entity:TEntity,x#,y#,z#,glob=False)
	Return entity.SetPosition(x,y,z,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TransformEntity(entity:TEntity,matrix:TMatrix,glob=False)
	Return entity.Transform(matrix,glob)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityCollisions:TCollision[](entity:TEntity)
	Return entity.GetCollisions()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityBox(entity:TEntity,x# Var,y# Var,z# Var,width# Var,height# Var,depth# Var)
	Return entity.GetBox(x,y,z,width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityBox(entity:TEntity,x#,y#,z#,width#,height#,depth#)
	Return entity.SetBox(x,y,z,width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityRadius(entity:TEntity,x# Var,y# Var)
	Return entity.GetRadius(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityRadius(entity:TEntity,x#,y#=-1)
	Return entity.SetRadius(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityType(entity:TEntity)
	Return entity.GetType()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityType(entity:TEntity,typ,recursive=False)
	Return entity.SetType(typ,recursive)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ResetEntity(entity:TEntity)
	Return entity.Reset()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityCullRadius#(entity:TEntity)
	Return entity.GetCullRadius()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetEntityCullRadius#(entity:TEntity,radius#)
	Return entity.SetCullRadius(radius)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetEntityDistance#(entity:TEntity,target:Object)
	Return entity.GetDistance(target)
End Function

'Lights
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateLight:TLight(typ=LIGHT_DIRECTIONAL,parent:TEntity=Null)
	Return CurrentWorld().AddLight(typ,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetLightRange#(light:TLight)
	Return light.GetRange()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetLightRange(light:TLight,range#)
	Return light.SetRange(range)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetLightAngles(light:TLight,inner# Var,outer# Var)
	Return light.GetAngles(inner,outer)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetLightAngles(light:TLight,inner#,outer#)
	Return light.SetAngles(inner,outer)
End Function

'Meshes
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateMesh:TMesh(parent:TEntity=Null)
	Return CurrentWorld().AddMesh("//empty",parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadMesh:TMesh(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddMesh(url,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshSurface:TSurface(mesh:TMesh,index)
	Return mesh.GetSurface(index)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddMeshSurface:TSurface(mesh:TMesh,brush:TBrush=Null,vertexcount=0,trianglecount=0)
	Return mesh.AddSurface(brush,vertexcount,trianglecount)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SwapMeshSurface(mesh:TMesh,surface:TSurface,new_surface:TSurface)
	Return mesh.SwapSurface(surface,new_surface)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CloneMesh:TMesh(mesh:TMesh,parent:TEntity=Null)
	Return mesh.Clone(parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function TranslateMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Translate(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ScaleMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Scale(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function RotateMesh(mesh:TMesh,pitch#,yaw#,roll#)
	Return mesh.Rotate(pitch,yaw,roll)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function PositionMesh(mesh:TMesh,x#,y#,z#)
	Return mesh.Position(x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CenterMesh(mesh:TMesh)
	Return mesh.Center()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshSize(mesh:TMesh,width# Var,height# Var,depth# Var)
	Return mesh.GetSize(width,height,depth)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FitMesh(mesh:TMesh,x#,y#,z#,width#,height#,depth#,uniform=False)
	Return mesh.Fit(x,y,z,width,height,depth,uniform)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function FlipMesh(mesh:TMesh)
	Return mesh.Flip()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UpdateMeshNormals(mesh:TMesh,smoothing=True)
	Return mesh.UpdateNormals(smoothing)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnim(mesh:TMesh,seq:TAnimSeq,mode=ANIMATION_LOOP,speed#=1.0)
	Return mesh.SetAnim(seq,mode,speed)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddMeshAnimSeq:TAnimSeq(mesh:TMesh)
	Return mesh.AddAnimSeq(0,0)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ExtractMeshAnimSeq:TAnimSeq(mesh:TMesh,start_frame,end_frame)
	Return mesh.ExtractAnimSeq(start_frame,end_frame)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimSeq:TAnimSeq(mesh:TMesh)
	Return mesh.GetAnimSeq()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimSeq(mesh:TMesh,seq:TAnimSeq)
	Return mesh.SetAnimSeq(seq)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimMode(mesh:TMesh)
	Return mesh.GetAnimMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimMode(mesh:TMesh,mode)
	Return mesh.SetAnimMode(mode)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetMeshAnimSpeed#(mesh:TMesh)
	Return mesh.GetAnimSpeed()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetMeshAnimSpeed(mesh:TMesh,speed#)
	Return mesh.SetAnimSpeed(speed)
End Function

'Animation
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateAnimSeq:TAnimSeq(first,last,name$="")
	Return TAnimSeq.Create(first,last,name)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetAnimSeqName$(seq:TAnimSeq)
	Return seq.GetName()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetAnimSeqName(seq:TAnimSeq,name$)
	Return seq.SetName(name)
End Function

'Pivots
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreatePivot:TPivot(parent:TEntity=Null)
	Return CurrentWorld().AddPivot(parent)
End Function

'Flats (plane)
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateFlat:TFlat(parent:TEntity=Null)
	Return CurrentWorld().AddFlat(parent)
End Function

'Sprite
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateSprite:TSprite(parent:TEntity=Null)
	Return CurrentWorld().AddSprite(Null,TEXTURE_DEFAULT,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadSprite:TSprite(url:Object,flags=TEXTURE_DEFAULT,parent:TEntity=Null)
	Return CurrentWorld().AddSprite(url,flags,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteAngle#(sprite:TSprite)
	Return sprite.GetAngle()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSpriteAngle(sprite:TSprite,angle#)
	Return sprite.SetAngle(angle)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteHandle(sprite:TSprite,x# Var,y# Var)
	Return sprite.GetHandle(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End RemS
Function SetSpriteHandle(sprite:TSprite,x#,y#)
	Return sprite.SetHandle(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSpriteViewMode(sprite:TSprite)
	Return sprite.GetViewMode()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSpriteViewMode(sprite:TSprite,mode)
	Return sprite.SetViewMode(mode)
End Function

'Surfaces
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountSurfaceVertices(surface:TSurface)
	Return surface.CountVertices()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CountSurfaceTriangles(surface:TSurface)
	Return surface.CountTriangles()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UpdateSurfaceNormals(surface:TSurface,smoothing=True)
	Return surface.UpdateNormals(smoothing)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function ResizeSurface(surface:TSurface,vertex_count,triangle_count)
	Return surface.Resize(vertex_count,triangle_count)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddSurfaceVertex(surface:TSurface,x#,y#,z#,u#=0.0,v#=0.0)
	Return surface.AddVertex(x,y,z,u,v)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceCoords(surface:TSurface,index,x# Var,y# Var,z# Var)
	Return surface.GetCoords(index,x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceCoords(surface:TSurface,index,x#,y#,z#)
	Return surface.SetCoords(index,x,y,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceColor(surface:TSurface,index,red Var,green Var,blue Var,alpha# Var)
	Return surface.GetColor(index,red,green,blue,alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceColor(surface:TSurface,index,red,green,blue,alpha#)
	Return surface.SetColor(index,red,green,blue,alpha)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceNormal(surface:TSurface,index,nx# Var,ny# Var,nz# Var)
	Return surface.GetNormal(index,nx,ny,nz)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceNormal(surface:TSurface,index,nx#,ny#,nz#)
	Return surface.SetNormal(index,nx,ny,nz)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceTexCoords(surface:TSurface,index,u# Var,v# Var,set=0)
	Return surface.GetTexCoords(index,u,v,set)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceTexCoords(surface:TSurface,index,u#,v#,set=0)
	Return surface.SetTexCoords(index,u,v,set)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function AddSurfaceTriangle(surface:TSurface,v0,v1,v2)
	Return surface.AddTriangle(v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceTriangle(surface:TSurface,index,v0 Var,v1 Var,v2 Var)
	Return surface.GetTriangle(index,v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceTriangle(surface:TSurface,index,v0,v1,v2)
	Return surface.SetTriangle(index,v0,v1,v2)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetSurfaceBrush:TBrush(surface:TSurface)
	Return surface.GetBrush()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetSurfaceBrush(surface:TSurface,brush:TBrush)
	Return surface.SetBrush(brush)
End Function

'Terrains
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateTerrain:TTerrain(size,parent:TEntity=Null)
	Return CurrentWorld().AddTerrain([size],parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadTerrain:TTerrain(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddTerrain(url,parent)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTerrainDetail(terrain:TTerrain,lmax,max_tris,clmax=-1)
	Return terrain.SetDetail(lmax,max_tris,clmax)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTerrainHeight#(terrain:TTerrain,x,z)
	Return terrain.GetHeight(x,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTerrainHeight(terrain:TTerrain,height#,x,z)
	Return terrain.SetHeight(height,x,z)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTerrainSize(terrain:TTerrain)
	Return terrain.GetSize()
End Function

'Textures
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function CreateTexture:TTexture(width,height,flags=TEXTURE_COLOR|TEXTURE_MIPMAP,frames=1)
	Local texture:TTexture=CurrentWorld().AddTexture([width,height,frames],flags)
	texture.SetPixmap(CreatePixmap(width,height,PF_RGBA8888))
	Return texture
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadTexture:TTexture(url:Object,flags=TEXTURE_COLOR|TEXTURE_MIPMAP)
	Return CurrentWorld().AddTexture(url,flags)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LockTexture:TPixmap(texture:TTexture)
	Return texture.Lock()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function UnlockTexture(texture:TTexture)
	Return texture.Unlock()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureFlags(texture:TTexture)
	Return texture.GetFlags()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureFlags(texture:TTexture,flags)
	Return texture.SetFlags(flags)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureBlend(texture:TTexture)
	Return texture.GetBlend()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureBlend(texture:TTexture,blend)
	Return texture.SetBlend(blend)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureCoords(texture:TTexture)
	Return texture.GetCoords()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureCoords(texture:TTexture,coords)
	Return texture.SetCoords(coords)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureScale(texture:TTexture,x# Var,y# Var)
	Return texture.GetScale(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureScale(texture:TTexture,x#,y#)
	Return texture.SetScale(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureRotation#(texture:TTexture)
	Return texture.GetRotation()
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTextureRotation(texture:TTexture,rotation#)
	Return texture.SetRotation(rotation)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTexturePosition(texture:TTexture,x# Var,y# Var)
	Return texture.GetPosition(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function SetTexturePosition(texture:TTexture,x#,y#)
	Return texture.SetPosition(x,y)
End Function
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function GetTextureSize(texture:TTexture,width Var,height Var)
	Return texture.GetSize(width,height)
End Function

'BSP
Rem
	bbdoc: Needs documentation. #TODO
End Rem
Function LoadBSPModel:TBSPModel(url:Object,parent:TEntity=Null)
	Return CurrentWorld().AddBSPModel(url,parent)
End Function

SetWorld CreateWorld()


method.bmx: * Implemented LExposedMethod#PreInitBlock

Strict

Import "metadata.bmx"

Private

Const METH_PREFIX$="_lugi_glue"	' An _ will always follow this

Public

Type LExposedMethod
	Field methodid:TMethod
	Field owner:TTypeId
	Field name$
	Field hidden%
	Field tag$

	Method New()
		Const TAGCHARS$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

		' generate a short tag to follow the method name, just to reduce the chance of conflicts
		Local tagbuff:Short[7]
		tagbuff[0] = 95 ' underscore
		For Local i:Int = 1 Until tagbuff.Length
			tagbuff[i] = TAGCHARS[Rand(0,62)]
		Next
		tag = String.FromShorts(tagbuff, tagbuff.Length)
	End Method

	Method InitWithMethod:LExposedMethod(meth:TMethod, owner:TTypeId)
		methodid = meth
		Self.owner = owner

		' get metadata
		hidden = methodid.Metadata(LUGI_META_HIDDEN).ToInt()>0

		name = methodid.Metadata(LUGI_META_RENAME).Trim()
		If Not name Then
			name = methodid.Name()
		EndIf

		Return Self
	End Method

	Method PreInitBlock:String()
		If hidden Then
			Return Null
		EndIf

		Return "p_lugi_register_method " + ImplementationName() + ", " + name + ", Byte Ptr(TTypeId.ForName(~q" + owner.Name() + "~q)._class)"
	End Method

	Method PostInitBlock:String()
	End Method

	Method ImplementationName$()
		Return METH_PREFIX+"_"+owner.Name()+"_"+name+tag
	End Method

	Method Implementation:String( instanceMethod:Int )
		If hidden Then
			Return Null
		EndIf

		Local head$ = "Function "+ImplementationName()+"(lua_vm:Byte Ptr)~n"
		Local tail$ = "End Function~n"

		If instanceMethod Then
			Return head+__instanceImp()+tail
		Else
			Return head+__noclassImp()+tail
		EndIf
	End Method

	' Implementation for instances/static types
	Method __instanceImp:String()
	End Method

	' Implementation for types without classes
	Method __noclassImp:String()

	End Method
End Type

Strict

Import "metadata.bmx"

Private

Const METH_PREFIX$="_lugi_glue"	' An _ will always follow this

Public

Type LExposedMethod
	Field methodid:TMethod
	Field owner:TTypeId
	Field name$
	Field hidden%
	Field tag$

	Method New()
		Const TAGCHARS$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"

		' generate a short tag to follow the method name, just to reduce the chance of conflicts
		Local tagbuff:Short[7]
		tagbuff[0] = 95 ' underscore
		For Local i:Int = 1 Until tagbuff.Length
			tagbuff[i] = TAGCHARS[Rand(0,62)]
		Next
		tag = String.FromShorts(tagbuff, tagbuff.Length)
	End Method

	Method InitWithMethod:LExposedMethod(meth:TMethod, owner:TTypeId)
		methodid = meth
		Self.owner = owner

		' get metadata
		hidden = methodid.Metadata(LUGI_META_HIDDEN).ToInt()>0

		name = methodid.Metadata(LUGI_META_RENAME).Trim()
		If Not name Then
			name = methodid.Name()
		EndIf

		Return Self
	End Method

	Method PreInitBlock:String()
	End Method

	Method PostInitBlock:String()
	End Method

	Method ImplementationName$()
		Return METH_PREFIX+"_"+owner.Name()+"_"+name+tag
	End Method

	Method Implementation:String( instanceMethod:Int )
		If hidden Then
			Return Null
		EndIf

		Local head$ = "Function "+ImplementationName()+"(lua_vm:Byte Ptr)~n"
		Local tail$ = "End Function~n"

		If instanceMethod Then
			Return head+__instanceImp()+tail
		Else
			Return head+__noclassImp()+tail
		EndIf
	End Method

	' Implementation for instances/static types
	Method __instanceImp:String()
	End Method

	' Implementation for types without classes
	Method __noclassImp:String()

	End Method
End Type