LUADOC - Farming Simulator 22

DebugUtil

Functions

debugTableToString

Description
useless on large tables
Definition
debugTableToString()
Code
470function DebugUtil.debugTableToString(inputTable, inputIndent, depth, maxDepth)
471 inputIndent = inputIndent or " "
472 depth = depth or 0
473 maxDepth = maxDepth or 2
474 if depth > maxDepth then
475 return nil
476 end
477 local string1 = ""
478 for i,j in pairs(inputTable) do
479 string1 = string1 .. string.format("\n%s %s :: %s", inputIndent, tostring(i), tostring(j))
480
481 if type(j) == "table" then
482 local string2 = DebugUtil.debugTableToString(j, inputIndent .. " ", depth+1, maxDepth)
483 if string2 ~= nil then
484 string1 = string1 .. string2
485 end
486 end
487 end
488 return string1
489end

drawArea

Description
Definition
drawArea()
Code
431function DebugUtil.drawArea(area, r, g, b, a)
432 local x0,_,z0 = getWorldTranslation(area.start)
433 local x1,_,z1 = getWorldTranslation(area.width)
434 local x2,_,z2 = getWorldTranslation(area.height)
435 local x,z, widthX,widthZ, heightX,heightZ = MathUtil.getXZWidthAndHeight(x0, z0, x1, z1, x2, z2)
436 DebugUtil.drawDebugParallelogram(x,z, widthX,widthZ, heightX,heightZ, r, g, b, a)
437end

drawDebugArea

Description
Definition
drawDebugArea()
Code
52function DebugUtil.drawDebugArea(start, width, height, r,g,b, alignToGround, drawNodes, drawCircle, offsetY)
53 offsetY = offsetY or 0
54 local x,y,z = getWorldTranslation(start)
55 local x1,y1,z1 = getWorldTranslation(width)
56 local x2,y2,z2 = getWorldTranslation(height)
57
58 y = y + offsetY
59 y1 = y1 + offsetY
60 y2 = y2 + offsetY
61
62 DebugUtil.drawDebugAreaRectangle(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b)
63
64 if drawNodes == nil or drawNodes then
65 DebugUtil.drawDebugNode(start, getName(start), alignToGround, offsetY)
66 DebugUtil.drawDebugNode(width, getName(width), alignToGround, offsetY)
67 DebugUtil.drawDebugNode(height, getName(height), alignToGround, offsetY)
68 end
69
70 local lsx, lsy, lsz, lex, ley, lez, radius = DensityMapHeightUtil.getLineByArea(start, width, height, 0.5)
71
72 lsy = lsy + offsetY
73 ley = ley + offsetY
74
75 if alignToGround then
76 lsy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lsx,0,lsz)+0.1
77 ley = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lex,0,lez)+0.1
78 end
79
80 if drawCircle == nil or drawCircle then
81 drawDebugLine(lsx, lsy, lsz, 1,1,1, lex, ley, lez, 1,1,1)
82 DebugUtil.drawDebugCircle((lsx+lex)*0.5, (lsy+ley)*0.5, (lsz+lez)*0.5, radius, 20, nil)
83 end
84end

drawDebugAreaRectangle

Description
Definition
drawDebugAreaRectangle()
Code
109function DebugUtil.drawDebugAreaRectangle(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b)
110 if alignToGround then
111 y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1
112 y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1
113 y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1
114 end
115
116 drawDebugLine(x,y,z, r,g,b, x1, y1, z1, r,g,b)
117 drawDebugLine(x,y,z, r,g,b, x2, y2, z2, r,g,b)
118
119 local dirX1, dirY1, dirZ1 = x1-x, y1-y, z1-z
120 local dirX2, dirY2, dirZ2 = x2-x, y2-y, z2-z
121
122 drawDebugLine(x2,y2,z2, r,g,b, x2+dirX1, y2+dirY1, z2+dirZ1, r,g,b)
123 drawDebugLine(x1,y1,z1, r,g,b, x1+dirX2, y1+dirY2, z1+dirZ2, r,g,b)
124end

drawDebugAreaRectangleFilled

Description
Definition
drawDebugAreaRectangleFilled()
Code
128function DebugUtil.drawDebugAreaRectangleFilled(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b,a)
129 local x3, y3, z3 = x1, (y1+y2)/2, z2
130
131 if alignToGround then
132 y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1
133 y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1
134 y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1
135 y3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,0,z3)+0.1
136 end
137
138 drawDebugTriangle(x,y,z, x2,y2,z2, x1,y1,z1, r,g,b,a, false)
139 drawDebugTriangle(x1,y1,z1, x2,y2,z2, x3,y3,z3, r,g,b,a, false)
140end

drawDebugCircle

Description
Draw debug circle
Definition
drawDebugCircle(float x, float y, float z, float radius, integer steps, table color)
Arguments
floatxworld x position
floatyworld y position
floatzworld z position
floatradiusradius
integerstepssteps
tablecolorcolor [r, g, b, a]
Code
165function DebugUtil.drawDebugCircle(x,y,z, radius, steps, color, alignToTerrain, filled)
166 local r, g, b = 1, 0, 0
167 if color ~= nil then
168 r, g, b = color[1], color[2], color[3]
169 end
170 local terrainNode = g_currentMission.terrainRootNode
171
172 for i=1,steps do
173 local a1 = ((i-1)/steps)*2*math.pi
174 local a2 = ((i)/steps)*2*math.pi
175
176 local c = math.cos(a1) * radius
177 local s = math.sin(a1) * radius
178 local x1, y1, z1 = x+c, y, z+s
179
180 c = math.cos(a2) * radius
181 s = math.sin(a2) * radius
182 local x2, y2, z2 = x+c, y, z+s
183
184 if alignToTerrain then
185 y = getTerrainHeightAtWorldPos(terrainNode, x, y, z) + 0.25
186 y1 = getTerrainHeightAtWorldPos(terrainNode, x1, y, z1) + 0.25
187 y2 = getTerrainHeightAtWorldPos(terrainNode, x2, y, z2) + 0.25
188 end
189
190 drawDebugLine(x1, y1, z1, r, g, b, x2, y2, z2, r, g, b)
191
192 if filled then
193 drawDebugTriangle(x, y, z, x2, y2, z2, x1, y1, z1, r, g, b, 0.3, true)
194 end
195 end
196end

drawDebugCircleAtNode

Description
Draw debug circle at node position
Definition
drawDebugCircleAtNode(integer node, float radius, integer steps, table color, bool vertical, table offset)
Arguments
integernodenode
floatradiusradius
integerstepssteps
tablecolorcolor [r, g, b, a]
boolverticalcircle is drawed vertically
tableoffsetoffset from node to center [x, y, z]
Code
206function DebugUtil.drawDebugCircleAtNode(node, radius, steps, color, vertical, offset)
207 local ox, oy, oz = 0, 0, 0
208 if offset ~= nil then
209 ox, oy, oz = offset[1], offset[2], offset[3]
210 end
211
212 for i=1,steps do
213 local a1 = ((i-1)/steps)*2*math.pi
214 local a2 = ((i)/steps)*2*math.pi
215
216 local c = math.cos(a1) * radius
217 local s = math.sin(a1) * radius
218 local x1, y1, z1
219 if vertical then
220 x1, y1, z1 = localToWorld(node, ox + 0, oy + c, oz + s)
221 else
222 x1, y1, z1 = localToWorld(node, ox + c, oy + 0, oz + s)
223 end
224
225 c = math.cos(a2) * radius
226 s = math.sin(a2) * radius
227 local x2, y2, z2
228 if vertical then
229 x2, y2, z2 = localToWorld(node, ox + 0, oy + c, oz + s)
230 else
231 x2, y2, z2 = localToWorld(node, ox + c, oy + 0, oz + s)
232 end
233
234 if color == nil then
235 drawDebugLine(x1,y1,z1, 1,0,0, x2,y2,z2, 1,0,0)
236 else
237 drawDebugLine(x1,y1,z1, color[1],color[2],color[3], x2,y2,z2, color[1],color[2],color[3])
238 end
239 end
240end

drawDebugCube

Description
Draw debug cube at given node
Definition
drawDebugCube(integer id, float sizeX, float sizeY, float sizeZ, float r, float g, float b)
Arguments
integeridnode id
floatsizeXx size
floatsizeYy size
floatsizeZz size
floatrred value
floatggreen value
floatbblue value
Code
288function DebugUtil.drawDebugCube(node, sizeX, sizeY, sizeZ, r, g, b, offsetX, offsetY, offsetZ)
289 sizeX, sizeY, sizeZ = sizeX * 0.5, sizeY * 0.5, sizeZ * 0.5
290 r = r or 1
291 g = g or 1
292 b = b or 1
293
294 local x, y, z = localToWorld(node, offsetX or 0, offsetY or 0, offsetZ or 0)
295 local up1X, up1Y, up1Z = localDirectionToWorld(node, 1, 0, 0)
296 local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0)
297 local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1)
298
299 up1X, up1Y, up1Z = up1X*sizeX, up1Y*sizeX, up1Z*sizeX
300 upX, upY, upZ = upX*sizeY, upY*sizeY, upZ*sizeY
301 dirX, dirY, dirZ = dirX*sizeZ, dirY*sizeZ, dirZ*sizeZ
302
303 drawDebugLine(x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b, x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b)
304 drawDebugLine(x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b, x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b)
305 drawDebugLine(x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b, x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b)
306 drawDebugLine(x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b, x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b)
307
308 drawDebugLine(x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b, x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b)
309 drawDebugLine(x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b, x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b)
310 drawDebugLine(x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b, x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b)
311 drawDebugLine(x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b, x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b)
312
313 drawDebugLine(x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b, x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b)
314 drawDebugLine(x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b, x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b)
315 drawDebugLine(x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b, x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b)
316 drawDebugLine(x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b, x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b)
317end

drawDebugCubeAtWorldPos

Description
Draw debug cube at world position
Definition
drawDebugCubeAtWorldPos(float x, float y, float z, float dirX, float dirY, float dirZ, float upX, float upY, float upZ, float sizeX, float sizeY, float sizeZ, float r, float g, float b)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatdirXx direction
floatdirYy direction
floatdirZz direction
floatupXx up of vector
floatupYy up of vector
floatupZz up of vector
floatsizeXx size
floatsizeYy size
floatsizeZz size
floatrred value
floatggreen value
floatbblue value
Code
259function DebugUtil.drawDebugCubeAtWorldPos(x, y, z, dirX, dirY, dirZ, upX, upY, upZ, sizeX, sizeY, sizeZ, r, g, b)
260 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
261 link(getRootNode(), temp)
262 setTranslation(temp, x, y, z)
263 setDirection(temp, dirX, dirY, dirZ, upX, upY, upZ)
264 DebugUtil.drawDebugCube(temp, sizeX, sizeY, sizeZ, r, g, b)
265 delete(temp)
266end

drawDebugGizmoAtWorldPos

Description
Definition
drawDebugGizmoAtWorldPos()
Code
34function DebugUtil.drawDebugGizmoAtWorldPos(x,y,z, dirX, dirY, dirZ, upX, upY, upZ, text, alignToGround, color)
35 local sideX, sideY, sideZ = MathUtil.crossProduct(upX, upY, upZ, dirX, dirY, dirZ)
36
37 if alignToGround then
38 y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1
39 end
40
41 drawDebugLine(x,y,z,1,0,0, x+sideX*0.3,y+sideY*0.3,z+sideZ*0.3, 1,0,0)
42 drawDebugLine(x,y,z,0,1,0, x+upX*0.3, y+upY*0.3, z+upZ*0.3, 0,1,0)
43 drawDebugLine(x,y,z,0,0,1, x+dirX*0.3, y+dirY*0.3, z+dirZ*0.3, 0,0,1)
44
45 if text ~= nil then
46 Utils.renderTextAtWorldPosition(x,y,z, tostring(text), getCorrectTextSize(0.012), 0, color)
47 end
48end

drawDebugLine

Description
Definition
drawDebugLine()
Code
88function DebugUtil.drawDebugLine(x1, y1, z1, x2, y2, z2, r, g, b, radius, alignToGround)
89 y1 = y1 or 0
90 y2 = y2 or 0
91 if alignToGround then
92 y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1
93 y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1
94 end
95
96 r = r or 1
97 g = g or 1
98 b = b or 1
99 drawDebugLine(x1, y1, z1, r, g, b, x2, y2, z2, r, g, b)
100
101 if radius ~= nil then
102 DebugUtil.drawDebugCircle(x1, y1, z1, radius, 20, nil)
103 DebugUtil.drawDebugCircle(x2, y2, z2, radius, 20, nil)
104 end
105end

drawDebugNode

Description
Draws a debug node and optional a text at world position of given node
Definition
drawDebugNode(integer id, string text)
Arguments
integeridnode id
stringtexttext
Code
24function DebugUtil.drawDebugNode(node, text, alignToGround, offsetY)
25 offsetY = offsetY or 0
26 local x, y, z = getWorldTranslation(node)
27 local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0)
28 local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1)
29 DebugUtil.drawDebugGizmoAtWorldPos(x,y + offsetY,z, dirX, dirY, dirZ, upX, upY, upZ, text, alignToGround)
30end

drawDebugParallelogram

Description
Draw debug parallelogram
Definition
drawDebugParallelogram(float x, float z, float widthX, float widthZ, float heightX, float heightZ, float heightOffset, float r, float g, float b, float a)
Arguments
floatxworld x center position
floatzworld z center position
floatwidthXwidthX
floatwidthZwidthZ
floatheightXheightX
floatheightZheightZ
floatheightOffsetheightOffset
floatrred
floatggreen
floatbblue
floataalpha
Code
393function DebugUtil.drawDebugParallelogram(x,z, widthX,widthZ, heightX,heightZ, heightOffset, r,g,b,a, fixedHeight)
394
395 local x0, z0 = x, z
396 local y0 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x0,0,z0) + heightOffset
397
398 local x1 = x0 + widthX
399 local z1 = z0 + widthZ
400 local y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1) + heightOffset
401
402 local x2 = x0 + heightX
403 local z2 = z0 + heightZ
404 local y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2) + heightOffset
405
406 local x3 = x0 + widthX + heightX
407 local z3 = z0 + widthZ + heightZ
408 local y3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,0,z3) + heightOffset
409
410 if fixedHeight then
411 y0, y1, y2, y3 = heightOffset, heightOffset, heightOffset, heightOffset
412 end
413
414 drawDebugTriangle(x0,y0,z0, x1,y1,z1, x2,y2,z2, r,g,b,a, false)
415 drawDebugTriangle(x1,y1,z1, x3,y3,z3, x2,y2,z2, r,g,b,a, false)
416 -- and reverse order
417 drawDebugTriangle(x0,y0,z0, x2,y2,z2, x1,y1,z1, r,g,b,a, false)
418 drawDebugTriangle(x2,y2,z2, x3,y3,z3, x1,y1,z1, r,g,b,a, false)
419
420 drawDebugLine(x0,y0,z0, r,g,b, x1,y1,z1, r,g,b)
421 drawDebugLine(x1,y1,z1, r,g,b, x2,y2,z2, r,g,b)
422 drawDebugLine(x2,y2,z2, r,g,b, x0,y0,z0, r,g,b)
423
424 drawDebugLine(x1,y1,z1, r,g,b, x3,y3,z3, r,g,b)
425 drawDebugLine(x3,y3,z3, r,g,b, x2,y2,z2, r,g,b)
426
427end

drawDebugRectangle

Description
Definition
drawDebugRectangle()
Code
144function DebugUtil.drawDebugRectangle(node, minX, maxX, minZ, maxZ, yOffset, r, g, b)
145 local leftFrontX, leftFrontY, leftFrontZ = localToWorld(node, minX, yOffset, maxZ)
146 local rightFrontX, rightFrontY, rightFrontZ = localToWorld(node, maxX, yOffset, maxZ)
147
148 local leftBackX, leftBackY, leftBackZ = localToWorld(node, minX, yOffset, minZ)
149 local rightBackX, rightBackY, rightBackZ = localToWorld(node, maxX, yOffset, minZ)
150
151 drawDebugLine(leftFrontX, leftFrontY, leftFrontZ, r,g,b, rightFrontX, rightFrontY, rightFrontZ, r,g,b)
152 drawDebugLine(rightFrontX, rightFrontY, rightFrontZ, r,g,b, rightBackX, rightBackY, rightBackZ, r,g,b)
153 drawDebugLine(rightBackX, rightBackY, rightBackZ, r,g,b, leftBackX, leftBackY, leftBackZ, r,g,b)
154 drawDebugLine(leftBackX, leftBackY, leftBackZ, r,g,b, leftFrontX, leftFrontY, leftFrontZ, r,g,b)
155end

drawDebugReferenceAxis

Description
Draw debug reference axis
Definition
drawDebugReferenceAxis(float x, float y, float z, float up, float up, float up, float direction, float direction, float direction)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatupx
floatupy
floatupz
floatdirectionx
floatdirectiony
floatdirectionz
Code
371function DebugUtil.drawDebugReferenceAxis(posX, posY, posZ, upX, upY, upZ, dirX, dirY, dirZ )
372 local sideX, sideY, sideZ = MathUtil.crossProduct(upX, upY, upZ, dirX, dirY, dirZ)
373 local length = 0.2
374
375 drawDebugLine((posX - sideX * length), (posY - sideY * length), (posZ - sideZ * length), 1, 1, 1, (posX + sideX * length), (posY + sideY * length), (posZ + sideZ * length), 1, 0, 0)
376 drawDebugLine((posX - upX * length), (posY - upY * length), (posZ - upZ * length), 1, 1, 1, (posX + upX * length), (posY + upY * length), (posZ + upZ * length), 0, 1, 0)
377 drawDebugLine((posX - dirX * length), (posY - dirY * length), (posZ - dirZ * length), 1, 1, 1, (posX + dirX * length), (posY + dirY * length), (posZ + dirZ * length), 0, 0, 1)
378end

drawDebugReferenceAxisFromNode

Description
Draw debug reference axis fom Node
Definition
drawDebugReferenceAxisFromNode(node to)
Arguments
nodetodraw a reference axis from
Code
350function DebugUtil.drawDebugReferenceAxisFromNode(node)
351 if node ~= nil then
352 local x, y, z = getWorldTranslation(node)
353 local yx, yy, yz = localDirectionToWorld(node, 0,1,0) -- up
354 local zx, zy, zz = localDirectionToWorld(node, 0,0,1) -- direction
355
356 DebugUtil.drawDebugReferenceAxis(x, y, z, yx, yy, yz, zx, zy, zz )
357 end
358end

drawOverlapBox

Description
Definition
drawOverlapBox()
Code
270function DebugUtil.drawOverlapBox(x, y, z, rotX, rotY, rotZ, extendX, extendY, extendZ, r, g, b)
271 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
272 link(getRootNode(), temp)
273 setTranslation(temp, x, y, z)
274 setRotation(temp, rotX, rotY, rotZ)
275 DebugUtil.drawDebugCube(temp, extendX*2, extendY*2, extendZ*2, r, g, b)
276 delete(temp)
277end

drawSimpleDebugCube

Description
Draw debug cube
Definition
drawSimpleDebugCube(float x, float y, float z, float width, float red, float green, float blue)
Arguments
floatxworld x center position
floatyworld y center position
floatzworld z center position
floatwidth
floatred
floatgreen
floatblue
Code
328function DebugUtil.drawSimpleDebugCube(x, y, z, width, r, g, b)
329 local halfWidth = width * 0.5
330
331 drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y - halfWidth, z - halfWidth, r, g, b)
332 drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x - halfWidth, y + halfWidth, z - halfWidth, r, g, b)
333 drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x - halfWidth, y - halfWidth, z + halfWidth, r, g, b)
334 drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b)
335 drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b)
336 drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b)
337 drawDebugLine(x - halfWidth, y - halfWidth, z + halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b)
338 drawDebugLine(x - halfWidth, y - halfWidth, z + halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b)
339 drawDebugLine(x - halfWidth, y + halfWidth, z - halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b)
340 drawDebugLine(x - halfWidth, y + halfWidth, z - halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b)
341 drawDebugLine(x + halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b)
342 drawDebugLine(x + halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b)
343 drawDebugPoint(x, y, z, r, g, b, 1)
344end

printCallingFunctionLocation

Description
Print the script call location of a function call which uses this function.
Definition
printCallingFunctionLocation()
Code
532function DebugUtil.printCallingFunctionLocation()
533 local stackLevel = 3 -- = <this>() + <warning / debug code> + <calling function>
534 local location = debug.getinfo(stackLevel, "Sl")
535 local callerScript = location.source
536 local callerLine = location.currentline
537
538 print(string.format("%s, line %d", tostring(callerScript), callerLine))
539end

printNodeHierarchy

Description
Definition
printNodeHierarchy()
Code
522function DebugUtil.printNodeHierarchy(node, offset)
523 offset = offset or ""
524 log(offset..getName(node))
525 for i=0, getNumOfChildren(node)-1 do
526 DebugUtil.printNodeHierarchy(getChildAt(node, i), offset.." ")
527 end
528end

printTableRecursively

Description
Print a table recursively
Definition
printTableRecursively(table inputTable, string inputIndent, integer depth, integer maxDepth)
Arguments
tableinputTabletable to print
stringinputIndentinput indent
integerdepthcurrent depth
integermaxDepthmax depth
Code
445function DebugUtil.printTableRecursively(inputTable, inputIndent, depth, maxDepth)
446 inputIndent = inputIndent or " "
447 depth = depth or 0
448 maxDepth = maxDepth or 3
449 if depth > maxDepth then
450 return
451 end
452 local debugString = ""
453 for i,j in pairs(inputTable) do
454 print(inputIndent..tostring(i).." :: "..tostring(j))
455 --debugString = debugString .. string.format("%s %s :: %s\n", inputIndent, tostring(i), tostring(j))
456 if type(j) == "table" then
457 DebugUtil.printTableRecursively(j, inputIndent.." ", depth+1, maxDepth)
458 --local string2 = DebugUtil.printTableRecursively(j, inputIndent.." ", depth+1, maxDepth)
459 --if string2 ~= nil then
460 -- debugString = debugString .. string2
461 --end
462 end
463 end
464 return debugString
465end

renderTable

Description
Definition
renderTable()
Code
493function DebugUtil.renderTable(posX, posY, textSize, data, nextColumnOffset)
494 local i = 0
495 setTextColor(1,1,1,1)
496 setTextBold(false)
497 textSize = getCorrectTextSize(textSize)
498 for _, valuePair in ipairs(data) do
499 if valuePair.name ~= "" then
500 local offset = i*textSize*1.05
501 setTextAlignment(RenderText.ALIGN_RIGHT)
502 renderText(posX, posY-offset, textSize, tostring(valuePair.name) .. ":")
503 setTextAlignment(RenderText.ALIGN_LEFT)
504 if type(valuePair.value) == "number" then
505 renderText(posX, posY-offset, textSize, " " ..string.format("%.4f", valuePair.value))
506 else
507 renderText(posX, posY-offset, textSize, " " ..tostring(valuePair.value))
508 end
509 end
510
511 i = i + 1
512
513 if valuePair.newColumn or valuePair.columnOffset then
514 i = 0
515 posX = posX + (valuePair.columnOffset or nextColumnOffset)
516 end
517 end
518end