@@ -125,11 +125,159 @@ function drawXYZLines()
125125 drawLine ({x ,y ,z },{zx ,zy ,zz },tocolor (0 ,0 ,200 ,200 ),thickness )
126126end
127127
128+ --[[
129+ Draws the where the object will be moved to.
130+ ]]
131+ function drawObjectMoveLines ()
132+ if not isElement (attachedToElement ) then return end
133+ if getElementType (attachedToElement ) ~= " object" then return end
134+ if getElementDimension (attachedToElement ) ~= getElementDimension (localPlayer ) then return end
135+ local x ,y ,z = edf .edfGetElementPosition (attachedToElement )
136+ if not x then return end
137+
138+ local offsetX = edf .edfGetElementProperty (attachedToElement , " moveX" )
139+ local offsetY = edf .edfGetElementProperty (attachedToElement , " moveY" )
140+ local offsetZ = edf .edfGetElementProperty (attachedToElement , " moveZ" )
141+
142+ if offsetX and math.abs (offsetX ) > 0 or offsetY and math.abs (offsetY ) > 0 or offsetZ and math.abs (offsetZ ) > 0 then
143+ if not offsetX then offsetX = 0 end
144+ if not offsetY then offsetY = 0 end
145+ if not offsetZ then offsetZ = 0 end
146+
147+ local speed = tonumber (edf .edfGetElementProperty (attachedToElement , " moveSpeed" ))
148+ if not speed then speed = 1 end
149+ local delay = tonumber (edf .edfGetElementProperty (attachedToElement , " moveDelay" ))
150+ if not delay then delay = 0 end
151+ local time = getDistanceBetweenPoints3D (x ,y ,z ,x + offsetX ,y + offsetY ,z + offsetZ ) / speed * 1000
152+ local lineStartPos = {x ,y ,z }
153+ local lineEndPos = {x + offsetX ,y + offsetY ,z + offsetZ }
154+ local timeNow = getTickCount ()
155+
156+ local fullCycle = 2 * time + 2 * delay
157+ local cyclePos = timeNow % fullCycle
158+ local progress
159+ if cyclePos < delay then
160+ -- Delay at 0
161+ progress = 0
162+ elseif cyclePos < delay + time then
163+ -- Forward: 0 to 1 over 'time' milliseconds
164+ progress = (cyclePos - delay ) / time
165+ elseif cyclePos < delay + time + delay then
166+ -- Delay at 1
167+ progress = 1
168+ else
169+ -- Backward: 1 to 0 over 'time' milliseconds
170+ progress = 1 - (cyclePos - delay - time - delay ) / time
171+ end
172+
173+ local movementAnimationOffset = {
174+ (lineEndPos [1 ] - lineStartPos [1 ]) * progress ,
175+ (lineEndPos [2 ] - lineStartPos [2 ]) * progress ,
176+ (lineEndPos [3 ] - lineStartPos [3 ]) * progress
177+ }
178+
179+
180+ local minX ,minY ,minZ ,maxX ,maxY ,maxZ = edf .edfGetElementBoundingBox ( attachedToElement )
181+ if not minX then
182+ local radius = edf .edfGetElementRadius ( attachedToElement )
183+ if radius then
184+ minX ,minY ,minZ ,maxX ,maxY ,maxZ = - radius ,- radius ,- radius ,radius ,radius ,radius
185+ end
186+ end
187+
188+ if minX and minY and minZ and maxX and maxY and maxZ then
189+ local halfCenterX = (minX + maxX ) * 0.25
190+ local halfCenterY = (minY + maxY ) * 0.25
191+ local halfCenterZ = (minZ + maxZ ) * 0.25
192+
193+ -- subtracting half center
194+ minX = minX - halfCenterX
195+ minY = minY - halfCenterY
196+ minZ = minZ - halfCenterZ
197+ maxX = maxX - halfCenterX
198+ maxY = maxY - halfCenterY
199+ maxZ = maxZ - halfCenterZ
200+
201+ -- Define the 8 corners in relative coordinates
202+ local relativeCorners = {
203+ {minX , minY , minZ }, -- 1: min corner
204+ {maxX , minY , minZ }, -- 2
205+ {maxX , maxY , minZ }, -- 3
206+ {minX , maxY , minZ }, -- 4
207+ {minX , minY , maxZ }, -- 5
208+ {maxX , minY , maxZ }, -- 6
209+ {maxX , maxY , maxZ }, -- 7
210+ {minX , maxY , maxZ } -- 8: max corner
211+ }
212+
213+ -- Draw the bounding box moving to the destination position
214+ do
215+ local corners = {}
216+ for i , relCorner in ipairs (relativeCorners ) do
217+ local worldX , worldY , worldZ = getPositionFromElementAtOffset (attachedToElement , relCorner [1 ], relCorner [2 ], relCorner [3 ])
218+ corners [i ] = {worldX + movementAnimationOffset [1 ], worldY + movementAnimationOffset [2 ], worldZ + movementAnimationOffset [3 ]}
219+ end
220+
221+ local boxColor = tocolor (255 , 255 , 255 , 100 )
222+ local lineWidth = 2
223+
224+ -- Bottom face (z = minZ)
225+ dxDrawLine3D (corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], boxColor , lineWidth )
226+ dxDrawLine3D (corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], boxColor , lineWidth )
227+ dxDrawLine3D (corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], boxColor , lineWidth )
228+ dxDrawLine3D (corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], boxColor , lineWidth )
229+
230+ -- Top face (z = maxZ)
231+ dxDrawLine3D (corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], boxColor , lineWidth )
232+ dxDrawLine3D (corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], boxColor , lineWidth )
233+ dxDrawLine3D (corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], boxColor , lineWidth )
234+ dxDrawLine3D (corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], boxColor , lineWidth )
235+
236+ -- Vertical edges connecting bottom to top
237+ dxDrawLine3D (corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], boxColor , lineWidth )
238+ dxDrawLine3D (corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], boxColor , lineWidth )
239+ dxDrawLine3D (corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], boxColor , lineWidth )
240+ dxDrawLine3D (corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], boxColor , lineWidth )
241+ end
242+
243+ -- Draw the bounding box at the destination position
244+ do
245+ local corners = {}
246+ for i , relCorner in ipairs (relativeCorners ) do
247+ local worldX , worldY , worldZ = getPositionFromElementAtOffset (attachedToElement , relCorner [1 ], relCorner [2 ], relCorner [3 ])
248+ corners [i ] = {worldX + offsetX , worldY + offsetY , worldZ + offsetZ }
249+ end
250+
251+ local boxColor = tocolor (255 , 255 , 0 , 200 )
252+ local lineWidth = 2
253+
254+ -- Bottom face (z = minZ)
255+ dxDrawLine3D (corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], boxColor , lineWidth )
256+ dxDrawLine3D (corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], boxColor , lineWidth )
257+ dxDrawLine3D (corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], boxColor , lineWidth )
258+ dxDrawLine3D (corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], boxColor , lineWidth )
259+
260+ -- Top face (z = maxZ)
261+ dxDrawLine3D (corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], boxColor , lineWidth )
262+ dxDrawLine3D (corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], boxColor , lineWidth )
263+ dxDrawLine3D (corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], boxColor , lineWidth )
264+ dxDrawLine3D (corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], boxColor , lineWidth )
265+
266+ -- Vertical edges connecting bottom to top
267+ dxDrawLine3D (corners [1 ][1 ], corners [1 ][2 ], corners [1 ][3 ], corners [5 ][1 ], corners [5 ][2 ], corners [5 ][3 ], boxColor , lineWidth )
268+ dxDrawLine3D (corners [2 ][1 ], corners [2 ][2 ], corners [2 ][3 ], corners [6 ][1 ], corners [6 ][2 ], corners [6 ][3 ], boxColor , lineWidth )
269+ dxDrawLine3D (corners [3 ][1 ], corners [3 ][2 ], corners [3 ][3 ], corners [7 ][1 ], corners [7 ][2 ], corners [7 ][3 ], boxColor , lineWidth )
270+ dxDrawLine3D (corners [4 ][1 ], corners [4 ][2 ], corners [4 ][3 ], corners [8 ][1 ], corners [8 ][2 ], corners [8 ][3 ], boxColor , lineWidth )
271+ end
272+ end
273+ end
274+ end
275+
128276function doBasicElementRenders ()
129277 if not isElement (attachedToElement ) then return end
130278 if exports [" editor_gui" ]:sx_getOptionData (" enableBox" ) then renderGridlines () end
131279 if exports [" editor_gui" ]:sx_getOptionData (" enableXYZlines" ) then drawXYZLines () end
132-
280+ drawObjectMoveLines ()
133281end
134282addEventHandler ( " onClientRender" , root , doBasicElementRenders )
135283
0 commit comments