| None. |
|
Returns why the last ExportColliderData or SetColliderOverride failed, or "" when it worked. Show it to the user when a collider could not be saved or kept: a triangle that names a point the bank does not have, a file that is already there or that someone else changed, a folder you cannot write to. Each call to ExportColliderData or SetColliderOverride clears it first, so read it straight after the call that failed. See also: ExportColliderData, SetColliderOverride, TerrainResourceError. |
; ExportColliderData Example
; --------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,1,-5
light=CreateLight()
RotateEntity light,50,-30,0
; A lumpy rock: a sphere with its points pushed in and out
rock=CreateSphere(12)
surface=GetSurface(rock,1)
For v=0 To CountVertices(surface)-1
x#=VertexX(surface,v):y#=VertexY(surface,v):z#=VertexZ(surface,v)
lump#=1+Sin(x*170+y*60)*Cos(z*130)*0.2
VertexCoords surface,v,x*lump,y*lump,z*lump
Next
UpdateNormals rock
EntityColor rock,150,140,130
; Its points, then its triangles, 12 bytes each
points=CountVertices(surface):triangles=CountTriangles(surface)
bank=CreateBank(points*12+triangles*12)
For v=0 To points-1
PokeFloat bank,v*12,VertexX(surface,v)
PokeFloat bank,v*12+4,VertexY(surface,v)
PokeFloat bank,v*12+8,VertexZ(surface,v)
Next
For t=0 To triangles-1
For corner=0 To 2
PokeInt bank,points*12+t*12+corner*4,TriangleVertex(surface,t,corner)
Next
Next
file$="demo_rock.b3collider"
message$="S writes the rock's collider to "+file
While Not KeyDown(1)
; S writes a new file: it never writes over one that is there
If KeyHit(31) Then
If ExportColliderData(file,bank,points,triangles) Then
message="Wrote "+file+": "+FileSize(file)+" bytes"
Else
message="Not written: "+ColliderDataError()
EndIf
EndIf
; R replaces the file, given the SHA-256 it had when it was read
If KeyHit(19) And FileType(file)=1 Then
If ExportColliderData(file,bank,points,triangles,Sha256File(file)) Then
message="Replaced "+file+": "+points+" points and "+triangles+" triangles"
Else
message="Not replaced: "+ColliderDataError()
EndIf
EndIf
TurnEntity rock,0.2,0.4,0
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"S: write the collider file R: replace it Esc: exit"
Text 0,20,message
Flip
Wend
FreeBank bank
End