فهرست منبع

samples: fixed placement of objects when snap-to-grid was enabled

Daniele Bartolini 5 سال پیش
والد
کامیت
1382df78ce
2فایلهای تغییر یافته به همراه20 افزوده شده و 6 حذف شده
  1. 1 0
      docs/changelog.rst
  2. 19 6
      samples/core/editors/level_editor/level_editor.lua

+ 1 - 0
docs/changelog.rst

@@ -17,6 +17,7 @@ Changelog
 * Added icons to the Level Tree View.
 * Updated the meshes for Sound, Camera and Light units.
 * Added a button to the Resource Chooser to "reveal" the selected resource in the Project Browser.
+* Fixed placement of objects when snap-to-grid was enabled.
 
 **Runtime**
 

+ 19 - 6
samples/core/editors/level_editor/level_editor.lua

@@ -671,6 +671,8 @@ function PlaceTool:init()
 	self._placeable_type = nil
 	self._placeable_name = nil
 	self._placeable_id   = nil
+	self._spawn_height       = 0 -- The spawn height at the time of "idle" -> "placing" transition.
+	self._spawn_point_height = 0 -- The spawn point height at the time of "idle" -> "placing" transition.
 
 	self:set_state("idle")
 end
@@ -738,18 +740,29 @@ end
 
 function PlaceTool:mouse_move(x, y)
 	if self:is_idle() then
-		local target = LevelEditor:find_spawn_point(x, y)
-		self:set_position(target)
+		local spawn_point = LevelEditor:find_spawn_point(x, y)
+		self._spawn_height = LevelEditor._spawn_height
+		self._spawn_point_height = spawn_point.y
+		self:set_position(spawn_point)
 	elseif self:is_placing() then
 		local pos, dir = LevelEditor:camera():camera_ray(x, y)
-		local point = self:position()
+		local gizmo_pos = self:position()
+		local point = Vector3(gizmo_pos.x, self._spawn_height, gizmo_pos.y)
 		local normal = Vector3.up()
 
 		local t = Math.ray_plane_intersection(pos, dir, point, normal)
 		if t ~= -1.0 then
-			local target = pos + dir * t
-			target = LevelEditor:snap(Matrix4x4.identity(), target) or target
-			self:set_position(target)
+			local spawn_point = pos + dir * t
+			spawn_point = LevelEditor:snap(Matrix4x4.identity(), spawn_point) or spawn_point
+			spawn_point.y = self._spawn_point_height
+			if LevelEditor.debug then
+				DebugLine.add_sphere(LevelEditor._lines_no_depth
+					, spawn_point
+					, 0.1
+					, Color4.blue()
+					)
+			end
+			self:set_position(spawn_point)
 		end
 	end
 end