Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LOD management functions #3831

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

Fernando-A-Rocha
Copy link
Contributor

@Fernando-A-Rocha Fernando-A-Rocha commented Oct 29, 2024

Important

HLOD = High Level of Detail (normal models the player sees when near)
LLOD = Low Level of Detail (models with less detail the player sees when far)

Details

Adds new clientside model utility & Level-Of-Detail(LOD) management functions

WIP

To be used in conjunction with:

This solves the problem of having to include a Lua LOD_TABLE in every map's script, which has been happening for years (the map editor's LOD table happens to be incomplete as of submitting this PR), providing a simple solution to obtain an object's LLOD model ID in the code.

Related to multitheftauto/mtasa-resources#556

Examples

  • LLOD model of HLOD model ganghous03_LAx (3655) is lodganghous03_lax (3656).

  • Practical code examples:
    WIP

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.h Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/lua/CLuaManager.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.cpp Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.h Outdated Show resolved Hide resolved
@FileEX
Copy link
Contributor

FileEX commented Oct 29, 2024

The lod arrays from the map editor are incomplete, so I assume this function is also incomplete. Therefore, a note should be added on the wiki once this PR is merged

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Oct 29, 2024

The lod arrays from the map editor are incomplete, so I assume this function is also incomplete. Therefore, a note should be added on the wiki once this PR is merged

No. I completed the table. It's good now.
See the mtasa-resources issue I linked where I explain it.

@Fernando-A-Rocha Fernando-A-Rocha changed the title Add getObjectLODModel(int objectModel) Add getObjectLODModel and getObjectModelOfLOD Oct 30, 2024
@Fernando-A-Rocha Fernando-A-Rocha changed the title Add getObjectLODModel and getObjectModelOfLOD Add getObjectLODOfModel and getObjectModelOfLOD Oct 30, 2024
Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.h Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/lua/CLuaManager.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.cpp Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.cpp Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.h Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp Outdated Show resolved Hide resolved
Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/CLodModels.h Outdated Show resolved Hide resolved
@lotsofs
Copy link

lotsofs commented Nov 1, 2024

The provided LOD model list not only is incomplete, it also contains plain incorrections. Examples are the LLODs for HLOD models 10428, 10369, 10439.

@Fernando-A-Rocha
Copy link
Contributor Author

The provided LOD model list not only is incomplete, it also contains plain incorrections. Examples are the LLODs for HLOD models 10428, 10369, 10439.

I'm surprised, I thought the list was generated from the game files not missing anything.

Will you suggest a fix for the array?

@derxgbb
Copy link

derxgbb commented Nov 1, 2024

I'm surprised, I thought the list was generated from the game files not missing anything.

Will you suggest a fix for the array?

Just a note:
Even the game .ipl files are different in other ports (ps2, xbox etc). For example the lanterns and special objects around four dragon casino is only persistent on ps2/xbox. https://imgur.com/MV61hvH
The objects does exist but never used in game.
I don't know if .ide files are different, they shouldn't but who knows.

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 2, 2024

I'm gonna investigate the HLOD => LLOD array. @lotsofs @spooky-spook

I'm surprised, I thought the list was generated from the game files not missing anything.
Will you suggest a fix for the array?

Just a note: Even the game .ipl files are different in other ports (ps2, xbox etc). For example the lanterns and special objects around four dragon casino is only persistent on ps2/xbox. https://imgur.com/MV61hvH The objects does exist but never used in game. I don't know if .ide files are different, they shouldn't but who knows.

It's interesting that PS2 and XBOX versions of the games have different world mapping, but I think this is out of the scope of this LLOD-improvements PR.

https://tcrf.net/Grand_Theft_Auto:_San_Andreas/Version_and_Platform_Differences
There are a large number of objects in Las Venturas missing from the PC version, mainly outside the Four Dragons Casino and The Visage. This seems to be a simple omission from the map as they are still in the game.

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 20, 2024

setObjectCustomLowLODModel() wont change current LLODs for world objects, right? It would be nice to have a function that did that, so you could for example add a LLOD to the palm trees or the street lamps without needing to manually remove and add them one by one as a building / object element.

setObjectCustomLowLODModel(hlod, llod) defines a LLOD ID for a given HLOD ID in a dictionary, for developers to use. That's it.

World object LOD is actually not managed by any Lua functions currently. So, as you said, if you want to customize a palm tree's LLOD, you need to use removeWorldModel to remove both the HLOD and the LLOD of that tree, create a custom object/building with HLOD model there, then create another object/building with the LLOD model, and finally set it as the low lod element of the high lod element.

Or you can do use engineReplaceModel to replace a palm tree Low LOD model, and the result will be seen on all world object palm trees part of the default map.

@PlatinMTA
Copy link
Contributor

setObjectCustomLowLODModel(hlod, llod) defines a LLOD ID for a given HLOD ID in a dictionary, for developers to use. That's it.

World object LOD is actually not managed by any Lua functions currently. So, as you said, if you want to customize a palm tree's LLOD, you need to use removeWorldModel to remove both the HLOD and the LLOD of that tree, and create a custom object/building with HLOD model there, then create another object/building with the LLOD model, and finally set it as the low lod element of the high lod element.

Currently, if you want to replace world object models, you can do with engineReplaceModel. So if you want to replace a palm tree Low LOD model, you can do it, and the result will be seen on all world object palm trees part of the default map.

Yeah but the thing is, palm trees dont have LLODs, thats why I made that question

But I think thats out of the scope of this PR, thanks for the response Fer

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 20, 2024

Someone could want to change CJ's house's LLOD model from lod1carlshou1_lae (17768) to something else, while automatically updating the world/landscape object in Grove Street, without having to mess with the object/building system.

Automatic LLOD creation & assignment is a problem. There are 3 different object types in the world:

  • default/landscape "world objects" that aren't MTA elements, and can be removed with removeWorldModel
  • "object" elements
  • "building" elements

As a developer, I'd love to have a function that automatically creates and assigns a LLOD object to a given or all objects with a certain HLOD model in my server.

We could have a function to do automatic LOD management for world objects.

For object/building elements the way to create and set LLODs is the following:

image

We can think about how we would improve this process.

But I think thats out of the scope of this PR, thanks for the response

Oh I'm always happy to discuss, I think it's related to this topic and we can do lil brainstorming.

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 21, 2024

I can also make setObjectCustomLowLODModel(hlod, llod) automatically the models of the game's LLOD landscape/world "buildings"(objects).

It'd be useful for projects that a lot of LLOD models to objects that don't have LOD in GTA SA, giving the game a new look and feel.

E.g. https://www.mixmods.com.br/2021/12/lod-vegetation-distant-trees/

Opinions?

@TheNormalnij
Copy link
Member

TheNormalnij commented Nov 21, 2024

Opinions?

I would prefer a simple solution with createObjectWithLod and createBuildingWithLod.
And i don't recommend using createObject instead of createBuilding for world models with LODs.
Objects doesn't have lod support in GTA. MTA uses dirty LOD support for objects

#include "CLodModels.h"

constexpr std::size_t OBJ_LOD_MODELS_COUNT = 4289;
constexpr std::pair<std::uint32_t, std::uint32_t> OBJ_LOD_MODELS_ARRAY[] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this array. Just define a hashmap

@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 21, 2024

I would prefer a simple solution with createObjectWithLod and createBuildingWithLod. And i don't recommend using createObject instead of createBuilding for world models with LODs. Objects doesn't have lod support in GTA. MTA uses dirty LOD support for objects

createObjectWithLod and createBuildingWithLod sound good!

I am still in favor of implementing the new LOD ID management functions described the main post. They are useful for getting the LLOD id of an HLOD id, and also setting custom LLOD ids for custom systems.

Also, what do you think about making setObjectCustomLowLODModel(hlod, llod) automatically update the models of the game's LLOD landscape/world "buildings"/"objects" ? @TheNormalnij

@Kinimel
Copy link

Kinimel commented Nov 21, 2024

I can also make setObjectCustomLowLODModel(hlod, llod) automatically the models of the game's LLOD landscape/world "buildings"(objects).

It'd be useful for projects that a lot of LLOD models to objects that don't have LOD in GTA SA, giving the game a new look and feel.

E.g. https://www.mixmods.com.br/2021/12/lod-vegetation-distant-trees/

Opinions?

The new LLOD ID management functions are a big step towards a more robust and adaptable system. The possibility of customizing LLOD IDs for specific systems offers a high degree of control. The setObjectCustomLowLODModel function is particularly interesting. By automatically updating LLOD models, it not only simplifies development, but also helps to avoid visual inconsistencies in the game.

@PlatinMTA
Copy link
Contributor

I can also make setObjectCustomLowLODModel(hlod, llod) automatically the models of the game's LLOD landscape/world "buildings"(objects).

yes that would be nice... although im guessing that function is also useful for custom models. My request was surely really specific so I'm not sure everyone would like that... maybe we could have a third argument that if its true then we can make that function behave like described (changing all lods?).

I'm down to test that change if needed because i think it would be pretty cool. Otherwise the only way to implement loads of LLODs to existing world buildings would be to delete them all (reading IPL files, parsing those) and create new ones. Second option seems to be too problematic/not worth it.

Out of the scope of this PR but maybe we should have a way to retrieve all world objects in some way. Right now if you want to find a world object you need to use processLineOfSight or similar, unless something was added and I didn't notice it. Otherwise you can get your IPL files and parse them yourself.

@Fernando-A-Rocha
Copy link
Contributor Author

I can also make setObjectCustomLowLODModel(hlod, llod) automatically the models of the game's LLOD landscape/world "buildings"(objects).

yes that would be nice... although im guessing that function is also useful for custom models. My request was surely really specific so I'm not sure everyone would like that... maybe we could have a third argument that if its true then we can make that function behave like described (changing all lods?).

I'm down to test that change if needed because i think it would be pretty cool. Otherwise the only way to implement loads of LLODs to existing world buildings would be to delete them all (reading IPL files, parsing those) and create new ones. Second option seems to be too problematic/not worth it.

Out of the scope of this PR but maybe we should have a way to retrieve all world objects in some way. Right now if you want to find a world object you need to use processLineOfSight or similar, unless something was added and I didn't notice it. Otherwise you can get your IPL files and parse them yourself.

Sure, I'd like to add the feature to automatically update world object LLODs.

For finding all world objects, I have parsed all of the game IPLs. This is enough tbh, and you can easily use Lua scripts for your needs.

I put everything here, including the binary ipls I converted to text. https://github.com/Fernando-A-Rocha/mta-binary-ipl-to-text

@Fernando-A-Rocha Fernando-A-Rocha marked this pull request as draft November 25, 2024 14:57
@Fernando-A-Rocha Fernando-A-Rocha changed the title Add object LOD management functions Add LOD management functions Nov 25, 2024
@Fernando-A-Rocha
Copy link
Contributor Author

Fernando-A-Rocha commented Nov 26, 2024

Check it out so far, ive redone some functions. Moved things to model related files. Added isValidModel (general purpose func)

@TheNormalnij I added model id checks, and also made it reset in engineFreeModel and when model manager is unloaded. Is this ok?

CLuaCFunctions::AddFunction(name, func);
}

bool CLuaModelDefs::IsValidModel(std::string modelPurpose, std::uint32_t id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about an enum instead of string?


bool CLuaModelDefs::SetModelLOD(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel)
{
if (!(modelPurpose == "object" || modelPurpose == "building"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(modelPurpose != "object" && modelPurpose != "building")


constexpr std::size_t OBJ_LOD_MODELS_COUNT = 4289;
constexpr std::pair<std::uint32_t, std::uint32_t> OBJ_LOD_MODELS_ARRAY[] = {
{694, 784}, // sm_redwoodgrp => lod_redwoodgrp (countryS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe too much spacing before the comment?
{X, Y}, // comment
instead of
{X, Y}, // comment

Comment on lines 3521 to 4320
{13804, 13808}, // cuntelandf4 => lodcuntelandf4 (LAhills)
{13805, 13807}, // celalandbiv => lodcelalandbiv (LAhills)
{13809, 13811}, // ce_grndpalcst02 => lodcepalcst02 (LAhills)
{13810, 13812}, // ce_grndpalcst05 => lodce_grndpalcst05 (LAhills)
{13813, 13815}, // cegraveblok03e => lodcegraveblok03e (LAhills)
{13814, 13787}, // ceroadn => lodceroadn (LAhills)
{13816, 13877}, // ce_safeground => ce_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need that?

@lynconsix
Copy link

Any other news? This PR is interesting!

@ds1-e
Copy link
Contributor

ds1-e commented Dec 14, 2024

These functions should be shared, like setLowLODElement is. e.g: if you would like to create object on server-side, and get it's LOD model directly.

@lynconsix
Copy link

What is missing for this PR to be completed?

@Nico8340
Copy link
Contributor

Any updates on this? @Fernando-A-Rocha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.