TOKSIM_SetStaticMesh(Vertices%,VertexCount%,Triangles%,TriangleCount%)
Parameters:
Vertices% = A pointer to a bank containing all the vertice coordinates. Each vertice is 16 bytes. The first 12 are 3 floats representing X,Y,Z.
VertexCount% = The number of vertices in the bank.
Triangles% = A pointer to a bank containing the triangles. Each triangle is 24 bytes. The first 12 are 3 integers representing the 3 corners. The next integer is the material index.
TriangleCount% = The number of triangles in the bank.
Return value:
None
Description:
Sets a static collision mesh.

The functions in the example (by me,Bot Builder) allow you to do this alot easier.

If you want to associate textures with materials, then first you must call TOK_SetTextureMaterial along with the texture's filaname, and the material index.

Call TOK_AddMesh to add a mesh to the tokamak collisions. Set the recurse variable to true to also make the entity's children collidable. Set mat to a value greater than -1 and texture assotiations are ignored, and the value of mat is used for the whole mesh. A value for mat of -2 and down means that the material will be used if a texture assotiations doesn't exist. The material that will be used in this case is -2-mat. So if mat is -5, and surface 1 doesn't have a material associated texture, the material index will be 3. Set Texture index to set which exture in a multi-textured mesh will determine the material properties.
Call TOK_SetMesh after you're done adding everything. This will pass the meshs and all other properties onward to tokamak.
Call TOK_ReInitializeBanks if at some point or another you would like to restart the mesh-adding process. You would probably do this when switching levels of a game.
Some handy functions I wrote that makes usage alot easier
Global vertices=CreateBank(0),triangles=CreateBank(0)
Global offsett,offsetv,tric,ttlvert,ttltris

Dim tname$(20),tMindex(20)
Global cur=0

Function TOK_SetTextureMaterial(fil$,Mindex)
tname$(cur)=fil$
tMindex(cur)=Mindex
cur=cur+1
End Function

Function TOK_AddMesh(mesh,recurse=0,mat=-1,textureindex=0)
scount=CountSurfaces(mesh)
For ind=1 To scount
  surface=GetSurface(mesh,ind)
  ttltris=ttltris+CountTriangles(surface)
  ttlvert=ttlvert+CountVertices(surface)
Next
ResizeBank triangles,ttltris*24
ResizeBank vertices,ttlvert*16
For ind=1 To scount
  surface = GetSurface(mesh,ind)
  bru=GetSurfaceBrush(surface)
  tex=GetBrushTexture(bru,textureindex)
  nam$=strippath$(TextureName$(tex))
  fo=0
  For a=0 To cur-1
   If tname$(a)=nam$ Then mindex=tMindex(a):fo=1:Exit
  Next
  If fo=0 Then mindex=0
  FreeBrush bru
  ctr=CountTriangles(surface)
  tric=tric+cvt
  cvt=CountVertices(surface)
  ;add vertices to bank
  For v=0 To cvt-1
   TFormPoint VertexX#(surface,v),VertexY#(surface,v),VertexZ#(surface,v),mesh,0
   PokeFloat vertices,offsetv,TFormedX()
   PokeFloat vertices,offsetv+4,TFormedY()
   PokeFloat vertices,offsetv+8,TFormedZ()
   PokeFloat vertices,offsetv+12,0.0
   offsetv=offsetv+16
  Next
  ;fill bank with triangles
  For v=0 To ctr-1
   PokeInt triangles,offsett,tric+TriangleVertex(surface,v,0)
   PokeInt triangles,offsett+4,tric+TriangleVertex(surface,v,1)
   PokeInt triangles,offsett+8,tric+TriangleVertex(surface,v,2)
   If mat=-1 Then PokeInt triangles,offsett+12,mindex Else PokeInt triangles,offsett+12,mat
   PokeInt triangles,offsett+16,0
   PokeInt triangles,offsett+20,0
   offsett=offsett+24
  Next
Next
If recurse Then
  children=CountChildren(mesh)
  If children>0 Then
   For childcount = 1 To children
    child = GetChild(entity,childcount)
    TOK_AddMesh child,recurse,mat  
   Next
  EndIf
EndIf
End Function

Function TOK_SetMesh()
;Hand over the terrain data to Tokamak
TOKSIM_SetStaticMesh vertices,ttlvert,triangles,ttltris
; Now we can free the banks as Tokamak has copied all data
FreeBank vertices
FreeBank triangles
End Function

Function StripPath$(file$)
If Len(file$)>0
  For i=Len(file$) To 1 Step -1
   mi$=Mid$(file$,i,1)
   If mi$="\" Or mi$="/" Then Return name$ Else name$=mi$+name$
  Next
EndIf
Return name$
End Function

Function TOK_ReInitializeBanks()
vertices=CreateBank(0)
triangles=CreateBank(0)
offsett=0
offsetv=0
tric=0
ttlvert=0
ttltris=0
End Function



Documentation generated by Cod2Doc on 20 Jun 2004.