15_Navigation.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. -- Navigation example.
  2. -- This sample demonstrates:
  3. -- - Generating a navigation mesh into the scene
  4. -- - Performing path queries to the navigation mesh
  5. -- - Rebuilding the navigation mesh partially when adding or removing objects
  6. -- - Visualizing custom debug geometry
  7. -- - Raycasting drawable components
  8. -- - Making a node follow the Detour path
  9. require "LuaScripts/Utilities/Sample"
  10. local endPos = nil
  11. local currentPath = {}
  12. local useStreaming = false
  13. local streamingDistance = 2
  14. local navigationTiles = {}
  15. local addedTiles = {}
  16. function Start()
  17. -- Execute the common startup for samples
  18. SampleStart()
  19. -- Create the scene content
  20. CreateScene()
  21. -- Create the UI content
  22. CreateUI()
  23. -- Setup the viewport for displaying the scene
  24. SetupViewport()
  25. -- Set the mouse mode to use in the sample
  26. SampleInitMouseMode(MM_RELATIVE)
  27. -- Hook up to the frame update and render post-update events
  28. SubscribeToEvents()
  29. end
  30. function CreateScene()
  31. scene_ = Scene()
  32. -- Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
  33. -- Also create a DebugRenderer component so that we can draw debug geometry
  34. scene_:CreateComponent("Octree")
  35. scene_:CreateComponent("DebugRenderer")
  36. -- Create scene node & StaticModel component for showing a static plane
  37. local planeNode = scene_:CreateChild("Plane")
  38. planeNode.scale = Vector3(100.0, 1.0, 100.0)
  39. local planeObject = planeNode:CreateComponent("StaticModel")
  40. planeObject.model = cache:GetResource("Model", "Models/Plane.mdl")
  41. planeObject.material = cache:GetResource("Material", "Materials/StoneTiled.xml")
  42. -- Create a Zone component for ambient lighting & fog control
  43. local zoneNode = scene_:CreateChild("Zone")
  44. local zone = zoneNode:CreateComponent("Zone")
  45. zone.boundingBox = BoundingBox(-1000.0, 1000.0)
  46. zone.ambientColor = Color(0.15, 0.15, 0.15)
  47. zone.fogColor = Color(0.5, 0.5, 0.7)
  48. zone.fogStart = 100.0
  49. zone.fogEnd = 300.0
  50. -- Create a directional light to the world. Enable cascaded shadows on it
  51. local lightNode = scene_:CreateChild("DirectionalLight")
  52. lightNode.direction = Vector3(0.6, -1.0, 0.8)
  53. local light = lightNode:CreateComponent("Light")
  54. light.lightType = LIGHT_DIRECTIONAL
  55. light.castShadows = true
  56. light.shadowBias = BiasParameters(0.00025, 0.5)
  57. -- Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
  58. light.shadowCascade = CascadeParameters(10.0, 50.0, 200.0, 0.0, 0.8)
  59. -- Create some mushrooms
  60. local NUM_MUSHROOMS = 100
  61. for i = 1, NUM_MUSHROOMS do
  62. CreateMushroom(Vector3(Random(90.0) - 45.0, 0.0, Random(90.0) - 45.0))
  63. end
  64. -- Create randomly sized boxes. If boxes are big enough, make them occluders. Occluders will be software rasterized before
  65. -- rendering to a low-resolution depth-only buffer to test the objects in the view frustum for visibility
  66. local NUM_BOXES = 20
  67. for i = 1, NUM_BOXES do
  68. local boxNode = scene_:CreateChild("Box")
  69. local size = 1.0 + Random(10.0)
  70. boxNode.position = Vector3(Random(80.0) - 40.0, size * 0.5, Random(80.0) - 40.0)
  71. boxNode:SetScale(size)
  72. local boxObject = boxNode:CreateComponent("StaticModel")
  73. boxObject.model = cache:GetResource("Model", "Models/Box.mdl")
  74. boxObject.material = cache:GetResource("Material", "Materials/Stone.xml")
  75. boxObject.castShadows = true
  76. if size >= 3.0 then
  77. boxObject.occluder = true
  78. end
  79. end
  80. -- Create Jack node that will follow the path
  81. jackNode = scene_:CreateChild("Jack")
  82. jackNode.position = Vector3(-5, 0, 20)
  83. local modelObject = jackNode:CreateComponent("AnimatedModel")
  84. modelObject.model = cache:GetResource("Model", "Models/Jack.mdl")
  85. modelObject.material = cache:GetResource("Material", "Materials/Jack.xml")
  86. modelObject.castShadows = true
  87. -- Create a NavigationMesh component to the scene root
  88. local navMesh = scene_:CreateComponent("NavigationMesh")
  89. -- Set small tiles to show navigation mesh streaming
  90. navMesh.tileSize = 32
  91. -- Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
  92. -- navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
  93. scene_:CreateComponent("Navigable")
  94. -- Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
  95. -- in the scene and still update the mesh correctly
  96. navMesh.padding = Vector3(0.0, 10.0, 0.0)
  97. -- Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
  98. -- physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
  99. -- it will use renderable geometry instead
  100. navMesh:Build()
  101. -- Create the camera. Limit far clip distance to match the fog
  102. cameraNode = scene_:CreateChild("Camera")
  103. local camera = cameraNode:CreateComponent("Camera")
  104. camera.farClip = 300.0
  105. -- Set an initial position for the camera scene node above the plane and looking down
  106. cameraNode.position = Vector3(0.0, 50.0, 0.0)
  107. pitch = 80.0
  108. cameraNode.rotation = Quaternion(pitch, yaw, 0.0)
  109. end
  110. function CreateUI()
  111. -- Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
  112. -- control the camera, and when visible, it will point the raycast target
  113. local style = cache:GetResource("XMLFile", "UI/DefaultStyle.xml")
  114. local cursor = Cursor:new()
  115. cursor:SetStyleAuto(style)
  116. ui.cursor = cursor
  117. -- Set starting position of the cursor at the rendering window center
  118. cursor:SetPosition(graphics.width / 2, graphics.height / 2)
  119. -- Construct new Text object, set string to display and font to use
  120. local instructionText = ui.root:CreateChild("Text")
  121. instructionText.text = "Use WASD keys to move, RMB to rotate view\n"..
  122. "LMB to set destination, SHIFT+LMB to teleport\n"..
  123. "MMB or O key to add or remove obstacles\n"..
  124. "Tab to toggle navigation mesh streaming\n"..
  125. "Space to toggle debug geometry"
  126. instructionText:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
  127. -- The text has multiple rows. Center them in relation to each other
  128. instructionText.textAlignment = HA_CENTER
  129. -- Position the text relative to the screen center
  130. instructionText.horizontalAlignment = HA_CENTER
  131. instructionText.verticalAlignment = VA_CENTER
  132. instructionText:SetPosition(0, ui.root.height / 4)
  133. end
  134. function SetupViewport()
  135. -- Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
  136. local viewport = Viewport:new(scene_, cameraNode:GetComponent("Camera"))
  137. renderer:SetViewport(0, viewport)
  138. end
  139. function SubscribeToEvents()
  140. -- Subscribe HandleUpdate() function for processing update events
  141. SubscribeToEvent("Update", "HandleUpdate")
  142. -- Subscribe HandlePostRenderUpdate() function for processing the post-render update event, during which we request
  143. -- debug geometry
  144. SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate")
  145. end
  146. function MoveCamera(timeStep)
  147. input.mouseVisible = input.mouseMode ~= MM_RELATIVE
  148. mouseDown = input:GetMouseButtonDown(MOUSEB_RIGHT)
  149. -- Override the MM_RELATIVE mouse grabbed settings, to allow interaction with UI
  150. input.mouseGrabbed = mouseDown
  151. -- Right mouse button controls mouse cursor visibility: hide when pressed
  152. ui.cursor.visible = not mouseDown
  153. -- Do not move if the UI has a focused element (the console)
  154. if ui.focusElement ~= nil then
  155. return
  156. end
  157. -- Movement speed as world units per second
  158. local MOVE_SPEED = 20.0
  159. -- Mouse sensitivity as degrees per pixel
  160. local MOUSE_SENSITIVITY = 0.1
  161. -- Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
  162. -- Only move the camera when the cursor is hidden
  163. if not ui.cursor.visible then
  164. local mouseMove = input.mouseMove
  165. yaw = yaw + MOUSE_SENSITIVITY * mouseMove.x
  166. pitch = pitch + MOUSE_SENSITIVITY * mouseMove.y
  167. pitch = Clamp(pitch, -90.0, 90.0)
  168. -- Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
  169. cameraNode.rotation = Quaternion(pitch, yaw, 0.0)
  170. end
  171. -- Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
  172. if input:GetKeyDown(KEY_W) then
  173. cameraNode:Translate(Vector3(0.0, 0.0, 1.0) * MOVE_SPEED * timeStep)
  174. end
  175. if input:GetKeyDown(KEY_S) then
  176. cameraNode:Translate(Vector3(0.0, 0.0, -1.0) * MOVE_SPEED * timeStep)
  177. end
  178. if input:GetKeyDown(KEY_A) then
  179. cameraNode:Translate(Vector3(-1.0, 0.0, 0.0) * MOVE_SPEED * timeStep)
  180. end
  181. if input:GetKeyDown(KEY_D) then
  182. cameraNode:Translate(Vector3(1.0, 0.0, 0.0) * MOVE_SPEED * timeStep)
  183. end
  184. -- Set destination or teleport with left mouse button
  185. if input:GetMouseButtonPress(MOUSEB_LEFT) then
  186. SetPathPoint()
  187. end
  188. -- Add or remove objects with middle mouse button, then rebuild navigation mesh partially
  189. if input:GetMouseButtonPress(MOUSEB_MIDDLE) or input:GetKeyPress(KEY_O) then
  190. AddOrRemoveObject()
  191. end
  192. -- Toggle debug geometry with space
  193. if input:GetKeyPress(KEY_SPACE) then
  194. drawDebug = not drawDebug
  195. end
  196. end
  197. function SetPathPoint()
  198. local hitPos, hitDrawable = Raycast(250.0)
  199. local navMesh = scene_:GetComponent("NavigationMesh")
  200. if hitPos then
  201. local pathPos = navMesh:FindNearestPoint(hitPos, Vector3.ONE)
  202. if input:GetQualifierDown(QUAL_SHIFT) then
  203. -- Teleport
  204. currentPath = {}
  205. jackNode:LookAt(Vector3(pathPos.x, jackNode.position.y, pathPos.z), Vector3(0.0, 1.0, 0.0))
  206. jackNode.position = pathPos
  207. else
  208. -- Calculate path from Jack's current position to the end point
  209. endPos = pathPos
  210. currentPath = navMesh:FindPath(jackNode.position, endPos)
  211. end
  212. end
  213. end
  214. function AddOrRemoveObject()
  215. -- Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
  216. local hitPos, hitDrawable = Raycast(250.0)
  217. if not useStreaming and hitDrawable then
  218. -- The part of the navigation mesh we must update, which is the world bounding box of the associated
  219. -- drawable component
  220. local updateBox = nil
  221. local hitNode = hitDrawable.node
  222. if hitNode.name == "Mushroom" then
  223. updateBox = hitDrawable.worldBoundingBox
  224. hitNode:Remove()
  225. else
  226. local newNode = CreateMushroom(hitPos)
  227. local newObject = newNode:GetComponent("StaticModel")
  228. updateBox = newObject.worldBoundingBox
  229. end
  230. -- Rebuild part of the navigation mesh, then recalculate path if applicable
  231. local navMesh = scene_:GetComponent("NavigationMesh")
  232. navMesh:Build(updateBox)
  233. if table.maxn(currentPath) > 0 then
  234. currentPath = navMesh:FindPath(jackNode.position, endPos)
  235. end
  236. end
  237. end
  238. function CreateMushroom(pos)
  239. local mushroomNode = scene_:CreateChild("Mushroom")
  240. mushroomNode.position = pos
  241. mushroomNode.rotation = Quaternion(0.0, Random(360.0), 0.0)
  242. mushroomNode:SetScale(2.0 + Random(0.5))
  243. local mushroomObject = mushroomNode:CreateComponent("StaticModel")
  244. mushroomObject.model = cache:GetResource("Model", "Models/Mushroom.mdl")
  245. mushroomObject.material = cache:GetResource("Material", "Materials/Mushroom.xml")
  246. mushroomObject.castShadows = true
  247. return mushroomNode
  248. end
  249. function Raycast(maxDistance)
  250. local pos = ui.cursorPosition
  251. -- Check the cursor is visible and there is no UI element in front of the cursor
  252. if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
  253. return nil, nil
  254. end
  255. local camera = cameraNode:GetComponent("Camera")
  256. local cameraRay = camera:GetScreenRay(pos.x / graphics.width, pos.y / graphics.height)
  257. -- Pick only geometry objects, not eg. zones or lights, only get the first (closest) hit
  258. local octree = scene_:GetComponent("Octree")
  259. local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
  260. if result.drawable ~= nil then
  261. return result.position, result.drawable
  262. end
  263. return nil, nil
  264. end
  265. function ToggleStreaming(enabled)
  266. local navMesh = scene_:GetComponent("NavigationMesh")
  267. if enabled then
  268. local maxTiles = (2 * streamingDistance + 1) * (2 * streamingDistance + 1)
  269. local boundingBox = BoundingBox(navMesh.boundingBox)
  270. SaveNavigationData()
  271. navMesh:Allocate(boundingBox, maxTiles)
  272. else
  273. navMesh:Build()
  274. end
  275. end
  276. function UpdateStreaming()
  277. local navMesh = scene_:GetComponent("NavigationMesh")
  278. -- Center the navigation mesh at the jack
  279. local jackTile = navMesh:GetTileIndex(jackNode.worldPosition)
  280. local beginTile = VectorMax(IntVector2(0, 0), jackTile - IntVector2(1, 1) * streamingDistance)
  281. local endTile = VectorMin(jackTile + IntVector2(1, 1) * streamingDistance, navMesh.numTiles - IntVector2(1, 1))
  282. -- Remove tiles
  283. local numTiles = navMesh.numTiles
  284. for i,tileIdx in pairs(addedTiles) do
  285. if not (beginTile.x <= tileIdx.x and tileIdx.x <= endTile.x and beginTile.y <= tileIdx.y and tileIdx.y <= endTile.y) then
  286. addedTiles[i] = nil
  287. navMesh:RemoveTile(tileIdx)
  288. end
  289. end
  290. -- Add tiles
  291. for z = beginTile.y, endTile.y do
  292. for x = beginTile.x, endTile.x do
  293. local i = z * numTiles.x + x
  294. if not navMesh:HasTile(IntVector2(x, z)) and navigationTiles[i] then
  295. addedTiles[i] = IntVector2(x, z)
  296. navMesh:AddTile(navigationTiles[i])
  297. end
  298. end
  299. end
  300. end
  301. function SaveNavigationData()
  302. local navMesh = scene_:GetComponent("NavigationMesh")
  303. navigationTiles = {}
  304. addedTiles = {}
  305. local numTiles = navMesh.numTiles
  306. for z = 0, numTiles.y - 1 do
  307. for x = 0, numTiles.x - 1 do
  308. local i = z * numTiles.x + x
  309. navigationTiles[i] = navMesh:GetTileData(IntVector2(x, z))
  310. end
  311. end
  312. end
  313. function HandleUpdate(eventType, eventData)
  314. -- Take the frame time step, which is stored as a float
  315. local timeStep = eventData["TimeStep"]:GetFloat()
  316. -- Move the camera, scale movement with time step
  317. MoveCamera(timeStep)
  318. -- Make Jack follow the Detour path
  319. FollowPath(timeStep)
  320. -- Update streaming
  321. if input:GetKeyPress(KEY_TAB) then
  322. useStreaming = not useStreaming
  323. ToggleStreaming(useStreaming)
  324. end
  325. if useStreaming then
  326. UpdateStreaming()
  327. end
  328. end
  329. function FollowPath(timeStep)
  330. if table.maxn(currentPath) > 0 then
  331. local nextWaypoint = currentPath[1] -- NB: currentPath[1] is the next waypoint in order
  332. -- Rotate Jack toward next waypoint to reach and move. Check for not overshooting the target
  333. local move = 5 * timeStep
  334. local distance = (jackNode.position - nextWaypoint):Length()
  335. if move > distance then
  336. move = distance
  337. end
  338. jackNode:LookAt(nextWaypoint, Vector3(0.0, 1.0, 0.0))
  339. jackNode:Translate(Vector3(0.0, 0.0, 1.0) * move)
  340. -- Remove waypoint if reached it
  341. if distance < 0.1 then
  342. table.remove(currentPath, 1)
  343. end
  344. end
  345. end
  346. function HandlePostRenderUpdate(eventType, eventData)
  347. -- If draw debug mode is enabled, draw navigation mesh debug geometry
  348. if drawDebug then
  349. local navMesh = scene_:GetComponent("NavigationMesh")
  350. navMesh:DrawDebugGeometry(true)
  351. end
  352. -- Visualize the start and end points and the last calculated path
  353. local size = table.maxn(currentPath)
  354. if size > 0 then
  355. local debug = scene_:GetComponent("DebugRenderer")
  356. debug:AddBoundingBox(BoundingBox(endPos - Vector3(0.1, 0.1, 0.1), endPos + Vector3(0.1, 0.1, 0.1)), Color(1.0, 1.0, 1.0))
  357. -- Draw the path with a small upward bias so that it does not clip into the surfaces
  358. local bias = Vector3(0.0, 0.05, 0.0)
  359. debug:AddLine(jackNode.position + bias, currentPath[1] + bias, Color(1.0, 1.0, 1.0))
  360. if size > 1 then
  361. for i = 1, size - 1 do
  362. debug:AddLine(currentPath[i] + bias, currentPath[i + 1] + bias, Color(1.0, 1.0, 1.0))
  363. end
  364. end
  365. end
  366. end
  367. -- Create XML patch instructions for screen joystick layout specific to this sample app
  368. function GetScreenJoystickPatchString()
  369. return
  370. "<patch>" ..
  371. " <add sel=\"/element\">" ..
  372. " <element type=\"Button\">" ..
  373. " <attribute name=\"Name\" value=\"Button3\" />" ..
  374. " <attribute name=\"Position\" value=\"-120 -120\" />" ..
  375. " <attribute name=\"Size\" value=\"96 96\" />" ..
  376. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" ..
  377. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" ..
  378. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" ..
  379. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" ..
  380. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" ..
  381. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" ..
  382. " <element type=\"Text\">" ..
  383. " <attribute name=\"Name\" value=\"Label\" />" ..
  384. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" ..
  385. " <attribute name=\"Vert Alignment\" value=\"Center\" />" ..
  386. " <attribute name=\"Color\" value=\"0 0 0 1\" />" ..
  387. " <attribute name=\"Text\" value=\"Teleport\" />" ..
  388. " </element>" ..
  389. " <element type=\"Text\">" ..
  390. " <attribute name=\"Name\" value=\"KeyBinding\" />" ..
  391. " <attribute name=\"Text\" value=\"LSHIFT\" />" ..
  392. " </element>" ..
  393. " <element type=\"Text\">" ..
  394. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  395. " <attribute name=\"Text\" value=\"LEFT\" />" ..
  396. " </element>" ..
  397. " </element>" ..
  398. " <element type=\"Button\">" ..
  399. " <attribute name=\"Name\" value=\"Button4\" />" ..
  400. " <attribute name=\"Position\" value=\"-120 -12\" />" ..
  401. " <attribute name=\"Size\" value=\"96 96\" />" ..
  402. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" ..
  403. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" ..
  404. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" ..
  405. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" ..
  406. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" ..
  407. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" ..
  408. " <element type=\"Text\">" ..
  409. " <attribute name=\"Name\" value=\"Label\" />" ..
  410. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" ..
  411. " <attribute name=\"Vert Alignment\" value=\"Center\" />" ..
  412. " <attribute name=\"Color\" value=\"0 0 0 1\" />" ..
  413. " <attribute name=\"Text\" value=\"Obstacles\" />" ..
  414. " </element>" ..
  415. " <element type=\"Text\">" ..
  416. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  417. " <attribute name=\"Text\" value=\"MIDDLE\" />" ..
  418. " </element>" ..
  419. " </element>" ..
  420. " </add>" ..
  421. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />" ..
  422. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Set</replace>" ..
  423. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">" ..
  424. " <element type=\"Text\">" ..
  425. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" ..
  426. " <attribute name=\"Text\" value=\"LEFT\" />" ..
  427. " </element>" ..
  428. " </add>" ..
  429. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />" ..
  430. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>" ..
  431. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">" ..
  432. " <element type=\"Text\">" ..
  433. " <attribute name=\"Name\" value=\"KeyBinding\" />" ..
  434. " <attribute name=\"Text\" value=\"SPACE\" />" ..
  435. " </element>" ..
  436. " </add>" ..
  437. "</patch>"
  438. end