Skip to content

Commit 443fddd

Browse files
committed
[editor] Improved object preview
fixes: - fixed object not appearing when selecting certain model ids - object rotation in viewport is centered - removed zoom out limit - added doublesided property to previewed element
1 parent 604c05e commit 443fddd

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

[editor]/editor_gui/client/browser/browser.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function browser.initiate ( theType, initialCat, initialModel )
6767
setPlayerHudComponentVisible ( "radar", false )
6868
setSkyGradient(112,112,112,112,112,112)
6969
setCameraInterior ( 14 )
70+
setFarClipDistance(700)
71+
setFogDistance(700)
7072
guiSetVisible ( browserGUI.window, true )
7173
--Output a default search
7274
local results = elementSearch ( catNodes[initialCat],"" )
@@ -135,6 +137,8 @@ function browser.close()
135137
removeEventHandler ( "onClientRender", root, rotateMesh )
136138
setCameraInterior ( returnInterior )
137139
resetSkyGradient()
140+
resetFarClipDistance()
141+
resetFogDistance()
138142
setPlayerHudComponentVisible ( "radar", true )
139143
if isElement ( browser.mainElement ) then
140144
setElementAlpha(browser.mainElement, 255)

[editor]/editor_gui/client/browser/freelook.lua

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ browserElementLookOptions = {
1919
distance = 4,
2020
minDistance = 2,
2121
maxDistance = 40,
22-
scrollUnits = 2,
22+
scrollUnits = 5,
2323
scrollSpeed = 0.1,
2424
up = "mouse_wheel_up",
2525
down = "mouse_wheel_down",
@@ -40,8 +40,8 @@ function elementLookFrame ()
4040
local camAngleY = browserElementLookOptions.invertedY * rotY / 120
4141

4242
-- get the position of the target
43-
local camTargetX, camTargetY, camTargetZ = getElementPosition ( browserElementLookOptions.target ) -- tx, ty, tz
44-
camTargetZ = camTargetZ + browserElementLookOptions.camZOffset
43+
local camTargetX, camTargetY, camTargetZ = tx, ty, tz
44+
4545
-- calculate a new positions for the camera
4646
local distX = math.cos ( camAngleY ) * cameraDistance
4747
local camPosX = camTargetX + ( ( math.cos ( camAngleX ) ) * distX )
@@ -86,11 +86,9 @@ function resetCamDist()
8686
if cameraDistance < browserElementLookOptions.distance then
8787
if cameraDistance + newDistance < browserElementLookOptions.distance then
8888
cameraDistance = cameraDistance + newDistance
89-
else cameraDistance = browserElementLookOptions.distance
9089
end
9190
elseif cameraDistance - newDistance > browserElementLookOptions.distance then
92-
cameraDistance = cameraDistance - newDistance
93-
else cameraDistance = browserElementLookOptions.distance
91+
cameraDistance = cameraDistance - newDistance
9492
end
9593
end
9694

@@ -120,10 +118,7 @@ function math.round ( value )
120118
end
121119

122120
function scrollDown()
123-
if browserElementLookOptions.distance + browserElementLookOptions.scrollUnits < browserElementLookOptions.maxDistance
124-
then browserElementLookOptions.distance = browserElementLookOptions.distance + browserElementLookOptions.scrollUnits
125-
else browserElementLookOptions.distance = browserElementLookOptions.maxDistance
126-
end
121+
browserElementLookOptions.distance = browserElementLookOptions.distance + browserElementLookOptions.scrollUnits
127122
end
128123

129124
function scrollUp()

[editor]/editor_gui/client/browser/previewelement.lua

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tx,ty,tz = 91,100,502 --The position of the element
1+
tx,ty,tz = 100,100,15000 --The position of the element
22
local hideX,hideY,hideZ = 0,0,0 --where to hide the local player
33
local rz = 0 -- The current rotation
44
local maxRadius = 5
@@ -64,21 +64,21 @@ function setModel.objectID ( model )
6464
local randomOffset = ((getTickCount() % 20) / 100) + 0.001
6565

6666
if not browser.mainElement then
67-
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz)
67+
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz, true)
68+
setElementDoubleSided(browser.mainElement, true)
6869
setElementDimension ( browser.mainElement, BROWSER_DIMENSION )
6970
setElementInterior(browser.mainElement, 14)
7071
else
7172
setElementModel(browser.mainElement, model)
7273
end
7374

74-
setElementPosition(browser.mainElement, tx, ty, tz + randomOffset)
75+
setElementPosition(browser.mainElement, tx, ty, tz)
7576
setElementAlpha(browser.mainElement, 255)
7677

77-
local radius = getElementRadius(browser.mainElement)
78-
browserElementLookOptions.distance = 14
79-
setObjectScale ( browser.mainElement, maxRadius / radius )
80-
setCameraMatrix ( tx - 17, ty, tz + 3 + randomOffset,
81-
tx, ty + 2, tz + randomOffset)
78+
local radius = math.max(7, getElementRadius(browser.mainElement)*2.1)
79+
browserElementLookOptions.distance = radius
80+
setCameraMatrix ( tx - radius - 1, ty + 1, tz + radius/4,
81+
tx - 1, ty + 1, tz)
8282
end
8383
function setModel.skinID ( model )
8484
local randomOffset = (getTickCount() % 20) / 100
@@ -108,9 +108,28 @@ function rotateMesh ()
108108
if ( initiatedType ) == "vehicleID" then
109109
setElementRotation ( browser.mainElement,0,0,newRotation)
110110
elseif ( initiatedType ) == "objectID" then
111-
setElementRotation ( browser.mainElement,0,0,newRotation)
111+
_previewRotate ( browser.mainElement,newRotation)
112112
elseif ( initiatedType ) == "skinID" then
113-
setPedRotation ( browser.mainElement,newRotation )
113+
setPedRotation ( browser.mainElement,newRotation)
114114
end
115115
end
116116

117+
118+
function _previewRotate(object, rotation)
119+
-- https://github.com/multitheftauto/mtasa-resources/commit/117759a6df540c21515d2666794e05dcf9c76254
120+
local a,b,c,d,e,f = getElementBoundingBox(object)
121+
122+
local halfCenterX = (a + d) * 0.25
123+
local halfCenterY = (b + e) * 0.25
124+
local halfCenterZ = (c + f) * 0.25
125+
126+
local rad = math.rad(rotation)
127+
local cZ, sZ = math.cos(rad), math.sin(rad)
128+
129+
local oX = halfCenterX*cZ - halfCenterY*sZ
130+
local oY = halfCenterX*sZ + halfCenterY*cZ
131+
local oZ = halfCenterZ
132+
133+
setElementPosition(object, tx - oX, ty - oY, tz - oZ)
134+
setElementRotation(object, 0, 0, rotation)
135+
end

0 commit comments

Comments
 (0)