Skip to content

Commit

Permalink
add lodDistance property
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Aug 1, 2024
1 parent e4c36bf commit b341005
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion newmodels_reborn/models/object/1337/big_box/40001.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
txd=object/1337/boxes.txd
txd=object/1337/boxes.txd
lodDistance=300
5 changes: 5 additions & 0 deletions newmodels_reborn/scripts/core/client_logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ local function loadCustomModel(customModel, elementToApply)
end

local disableAutoFree = customInfo.settings.disableAutoFree
local lodDistance = customInfo.settings.lodDistance
if lodDistance then
engineSetModelLODDistance(allocatedModel, lodDistance)
end

-- Set loadedModel info
loadedModels[customModel] = {
Expand Down Expand Up @@ -154,6 +158,7 @@ local function freeAllocatedModelNow(customModel)
if isTimer(loadedModel.freeAllocatedTimer) then
killTimer(loadedModel.freeAllocatedTimer)
end
engineResetModelLODDistance(loadedModel.id)
engineFreeModel(loadedModel.id)

-- Destroy model elements unless used by another loaded model
Expand Down
15 changes: 12 additions & 3 deletions newmodels_reborn/scripts/core/server_logic.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
-- Apologies for the excess if statements, I'll clean this up later.

-- Model .txt settings:
local CUSTOM_MODEL_SETTINGS = {
["disableAutoFree"] = true,
["disableTXDTextureFiltering"] = true,
["enableDFFAlphaTransparency"] = true,
}
-- Additionally, model settings .txt can contain path to txd, dff, and col files.
-- - txd=path
-- - dff=path
-- - col=path
-- - lodDistance=number

local function stringStartswith(str, start)
return str:sub(1, #start) == start
Expand Down Expand Up @@ -69,10 +73,16 @@ local function loadModels()
settingStr = settingStr:gsub("\r", "")
if CUSTOM_MODEL_SETTINGS[settingStr] then
customModelSettings[settingStr] = true
elseif stringStartswith(settingStr, "lodDistance=") then
local lodDistance = tonumber(settingStr:sub(13))
if not lodDistance then
return false, "invalid lodDistance value: " .. settingStr
end
customModelSettings.lodDistance = lodDistance
else
for _, settingModelType in pairs({"txd", "dff", "col"}) do
if stringStartswith(settingStr, settingModelType.."=") then
local settingModelPath = settingStr:sub(5)
local settingModelPath = settingStr:sub(#settingModelType + 2)
local settingModelFullPath = "models/" .. settingModelPath
if not fileExists(settingModelFullPath) then
return false, "setting " .. settingModelType .. " file not found: " .. settingModelPath
Expand Down Expand Up @@ -130,7 +140,6 @@ local function loadModels()
name = info.name or "Unnamed",
settings = info.settings or {},
}
if modelType == "object" then iprint(customModels[customModel]) end
end
end
end
Expand Down

0 comments on commit b341005

Please sign in to comment.