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

Procedural road editing using AngelScript #2976

Merged
merged 11 commits into from Dec 3, 2022

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Nov 28, 2022

This introduces scripting API for full procedural road management and also bundled script "road_editor.as" which allows interactive road editing!

screenshot_2022-11-28_12-26-39_1

To start the editor script, open console and say "loadscript road_editor.as".

Features:

  • add or remove roads
  • add or remove road points
  • move existing points using mouse
  • add new points at character position
  • export a specific range of road points as AI waypoints
  • import a specific range of AI waypoints as road points
  • export roads in the 'editor_out.txt' file
  • road smoothing by specifying number of extra splits
  • Hotkeys: ROAD_EDITOR_{POINT_ADD, POINT_DELETE, POINT_SET_POS, POINT_GOTO, REBUILD_MESH} - all shown in the UI.
  • select road segment type (pillars, borders...)
  • edit all available parameters, see https://docs.rigsofrods.org/terrain-creation/old-terrn-subsystem/#procedural-roads
  • adjustable min height above terrain
  • editable point height above terrain

You can also script custom meshes using addQuad() and addCollisionQuad(). AngelScript API documentation will be available at https://developer.rigsofrods.org/d4/d07/group___script2_game.html once this PR is merged.

CODECHANGES:
* new file ProceduralRoadAngelscript.cpp - binds ProceduralPointClass, ProceduralRoadClass, ProceduralObjectClass, ProceduralManagerClass
* ProceduralRoad.h/cpp - added strong enums RoadType and TextureFit - extracted from class ProceduralRoad
* TerrainAngelscript.cpp - added getter for procedural manager.
* TObjFileFormat: accomodated new pointer type.
rebase and fixup -- factory functions
To start it, open console and say "loadscript road_editor.as"

Existing features:
* add or remove roads
* add or remove road points
* move existing points using mouse
* add new points at character position
* build custom mesh using `addQuad`

Planned features:
* export roads in the 'editor_out.txt' file
* select road segment type (pillars, borders...)
* road smoothing with custom max. seg. length
* adjustable min height above terrain
* editable point height above terrain
@CuriousMike56
Copy link
Collaborator

Very nice! Hopefully later on it'll be possible move road points the same way as other objects, (Character freezes in place, use arrow keys to adjust position + press R to switch rotation axis)

New script API:
* game.addWaypoint(vector3)
@ohlidalp
Copy link
Member Author

@tritonas00 requested an option to export road points as AI waypoints. I added 2 sliders to specify a range, and an export button:
screenshot_2022-11-29_01-07-15_1
While at it, I also implemented an import of AI waypoints as procedural road points, with the same controls:
screenshot_2022-11-29_00-59-10_1

@ohlidalp
Copy link
Member Author

ohlidalp commented Nov 29, 2022

@CuriousMike56 Hopefully later on it'll be possible move road points the same way as other objects

Eventually yes, but not in this PR. That logic is hardcoded and somewhat dirty (reuses existing hotkeys), I don't want to extend it any further.

Note: params rotX and rotZ are unpredictable and the exporter always sets them to zero. Param rotY is anticlockwise yaw around global Y, in degrees.
Old bug, pre-dates the standalone TObjParser
@ohlidalp
Copy link
Member Author

ohlidalp commented Nov 30, 2022

Road smoothing is real!
smoothing!
UPDATE: now supported by the TOBJ file format!
I actually developed this a year ago and it's been collecting dust in my git fork, I'm happy I finally integrated it.

Currently cannot be controlled from TOBJ file format, only from scripting.

New script API:
* ImGui::SetNextItemWidth(float)
* ImGui::InputInt(string, int&)
* int ProceduralObjectClass.smoothing_num_splits
@ohlidalp
Copy link
Member Author

ohlidalp commented Dec 2, 2022

It's complete. Not perfect but helpful.
Hotkeys:

    // Road editing
    {"ROAD_EDITOR_POINT_INSERT",        "Keyboard EXPL+INSERT",         _LC("InputEvent", "insert road point") },
    {"ROAD_EDITOR_POINT_GOTO",            "Keyboard EXPL+G",              _LC("InputEvent", "go to road point") },
    {"ROAD_EDITOR_POINT_SET_POS",      "Keyboard EXPL+M",              _LC("InputEvent", "set road point position") },
    {"ROAD_EDITOR_POINT_DELETE",        "Keyboard EXPL+DELETE",         _LC("InputEvent", "delete road point") },
    {"ROAD_EDITOR_REBUILD_MESH",        "Keyboard EXPL+B",              _LC("InputEvent", "regenerate road mesh") },

finished

@ohlidalp ohlidalp merged commit 69342ea into RigsOfRods:master Dec 3, 2022
@ohlidalp ohlidalp deleted the angelscript-roads branch December 3, 2022 21:44
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.

None yet

3 participants