Skip to content

Commit 362f23c

Browse files
authored
[editor_gui] Improved object preview (#692)
* [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 * Added doublesided button, better preview centering and zooming
1 parent 604c05e commit 362f23c

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ function createBrowser()
2020
browserGUI.window = guiCreateWindow ( 0, 0, 0.25, 1, "Browse...", true )
2121
guiSetVisible ( browserGUI.window, false )
2222
browserGUI.dropdown = editingControl.dropdown:create{["x"]=12,["y"]=25,["width"]=screenX*0.25,["height"]=20,["dropWidth"]=screenX*0.25,["dropHeight"]=200,["relative"]=false,["parent"]=browserGUI.window,["rows"]={"All categories", "Favourites"}}
23-
browserGUI.list = browserList:create( 12, 85, screenX*0.25, screenY*1-112, { {["Element"]=0.95-(60/(screenX*0.25))},{["[ID]"]=40/(screenX*0.25)}},false, browserGUI.window )
23+
browserGUI.list = browserList:create( 12, 85, screenX*0.25, screenY*1-140, { {["Element"]=0.95-(60/(screenX*0.25))},{["[ID]"]=40/(screenX*0.25)}},false, browserGUI.window )
2424
browserGUI.search = guiCreateEdit ( 12, 50, screenX*0.25, 30, "Search...", false, browserGUI.window )
2525
browserGUI.ok = guiCreateButton ( 12, screenY-24, screenX*0.125 - 2, 40, "OK", false, browserGUI.window )
2626
browserGUI.cancel = guiCreateButton ( screenX*0.125 + 12 + 2, screenY-24, screenX*0.125 - 2, 40, "Cancel", false, browserGUI.window )
2727
browserGUI.searchProgress = guiCreateLabel ( 0, 0, 1, 0.1, "", true )
2828
browserGUI.searchModel = guiCreateLabel ( 0, 0, 1, 0.1, "", true )
29+
browserGUI.doubleside = guiCreateCheckBox ( 12, screenY-50, 110, 20, "Set doublesided", false, false, browserGUI.window )
2930
guiSetVisible ( browserGUI.searchProgress, false )
3031
guiSetVisible ( browserGUI.searchModel, false )
3132
guiLabelSetColor ( browserGUI.searchProgress,0,0,0 )
@@ -37,6 +38,7 @@ function createBrowser()
3738

3839
addEventHandler ("onClientGUIClick",browserGUI.ok,browser.browserSelected,false)
3940
addEventHandler ("onClientGUIClick",browserGUI.cancel,browser.browserCancelled,false)
41+
addEventHandler ("onClientGUIClick",browserGUI.doubleside,browser.setDoublesided,false)
4042
end
4143

4244
function browser.initiate ( theType, initialCat, initialModel )
@@ -67,6 +69,8 @@ function browser.initiate ( theType, initialCat, initialModel )
6769
setPlayerHudComponentVisible ( "radar", false )
6870
setSkyGradient(112,112,112,112,112,112)
6971
setCameraInterior ( 14 )
72+
setFarClipDistance(700)
73+
setFogDistance(700)
7074
guiSetVisible ( browserGUI.window, true )
7175
--Output a default search
7276
local results = elementSearch ( catNodes[initialCat],"" )
@@ -135,6 +139,8 @@ function browser.close()
135139
removeEventHandler ( "onClientRender", root, rotateMesh )
136140
setCameraInterior ( returnInterior )
137141
resetSkyGradient()
142+
resetFarClipDistance()
143+
resetFogDistance()
138144
setPlayerHudComponentVisible ( "radar", true )
139145
if isElement ( browser.mainElement ) then
140146
setElementAlpha(browser.mainElement, 255)
@@ -330,6 +336,11 @@ function browser.browserCancelled(button)
330336
browser.close()
331337
end
332338

339+
function browser.setDoublesided(button)
340+
if button ~= "left" then return end
341+
setElementDoubleSided(browser.mainElement, guiCheckBoxGetSelected(browserGUI.doubleside))
342+
end
343+
333344
function setProgressText ( text )
334345
guiSetText ( browserGUI.searchProgress, text )
335346
local length = guiLabelGetTextExtent ( browserGUI.searchProgress )

[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: 34 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
@@ -23,6 +23,7 @@ function browserSetElementModel ( elemID, model )
2323
setModel[elemID](model)
2424
end
2525
end
26+
2627
function setModel.vehicleID ( model )
2728
local randomOffset = ((getTickCount() % 20) / 100) + 0.001
2829

@@ -60,26 +61,31 @@ function setModel.vehicleID ( model )
6061
setCameraMatrix ( tx - realDistance, ty, tz + elevation + randomOffset,
6162
tx, ty + moveLeft, tz + randomOffset)
6263
end
64+
6365
function setModel.objectID ( model )
6466
local randomOffset = ((getTickCount() % 20) / 100) + 0.001
6567

6668
if not browser.mainElement then
67-
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz)
69+
browser.mainElement = createObject(model, tx, ty, tz, 0, 0, rz, true)
70+
setElementDoubleSided(browser.mainElement, guiCheckBoxGetSelected(browserGUI.doubleside))
6871
setElementDimension ( browser.mainElement, BROWSER_DIMENSION )
6972
setElementInterior(browser.mainElement, 14)
7073
else
7174
setElementModel(browser.mainElement, model)
7275
end
7376

74-
setElementPosition(browser.mainElement, tx, ty, tz + randomOffset)
77+
setElementPosition(browser.mainElement, tx, ty, tz)
7578
setElementAlpha(browser.mainElement, 255)
7679

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)
80+
local a,b,c,d,e,f = getElementBoundingBox(browser.mainElement)
81+
local radius = math.max(7, getElementRadius(browser.mainElement)*2.1)
82+
radius = math.max(radius, math.sqrt((c*c)+(f*f))*2)
83+
browserElementLookOptions.distance = radius
84+
local offset = radius * 0.2
85+
setCameraMatrix ( tx - radius - offset, ty + offset, tz + radius * 0.25,
86+
tx - offset, ty + offset, tz)
8287
end
88+
8389
function setModel.skinID ( model )
8490
local randomOffset = (getTickCount() % 20) / 100
8591

@@ -108,9 +114,27 @@ function rotateMesh ()
108114
if ( initiatedType ) == "vehicleID" then
109115
setElementRotation ( browser.mainElement,0,0,newRotation)
110116
elseif ( initiatedType ) == "objectID" then
111-
setElementRotation ( browser.mainElement,0,0,newRotation)
117+
_previewRotate ( browser.mainElement,newRotation)
112118
elseif ( initiatedType ) == "skinID" then
113-
setPedRotation ( browser.mainElement,newRotation )
119+
setPedRotation ( browser.mainElement,newRotation)
114120
end
115121
end
116122

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

0 commit comments

Comments
 (0)