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

Terrain editor now edits *.tobj files in place #3199

Merged
merged 46 commits into from
Jan 6, 2025

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Nov 17, 2024

Major changes

  1. The terrain editor mode now edits `*.tobj`` files directly. The 'logs/editor_out.log' file is history. Just enter/exit the terrain editor mode and changes will persist. Note this works only if the terrain is unzipped in a directory (= a project), otherwise game will show a console/chatbox warning "cannot export - not a project".
  2. The game has integrated project importer script - just enter terrain editor on Zipped terrain and it will pop up. Closing the script will exit terrain editor and vice versa.
  3. Experimental: new [Races] section in terrn2, processed by the race system. Converting the classic races defined in scripts is done automatically by the importer. Under [Races], there is 1 file per race. I tested this on Auriga Proving Grounds.
  4. Road editor now has overhead camera It's called EditorCam and it's a standard top-down camera like in RTS games, you can disable it via checkbox. Also, road gizmos were updated - you can now move road points by dragging them with mouse - previously you had to use the M hotkey
  5. Terrain editor now also edits preloaded actors - selecting, moving and rotating works identically to a static object. Spawning and destroying via console isn't integrated yet, that only works with static object now.

Notes to code reviewers:

  • I did a roundup of file format handlers -> a lot of find&replace hapenned, see individual commit descriptions.
  • For convenience this branch builds on top of Script updates and fixes #3197 - when that is merged, it will become much leaner.

@ohlidalp ohlidalp force-pushed the terrn_export branch 3 times, most recently from 341bc52 to 3a02667 Compare November 30, 2024 20:26
@ohlidalp ohlidalp force-pushed the terrn_export branch 2 times, most recently from d5aeb16 to 371c19f Compare December 12, 2024 00:33
@ohlidalp ohlidalp marked this pull request as ready for review December 25, 2024 22:40
@ohlidalp

This comment was marked as outdated.

@ohlidalp ohlidalp requested a review from Zentro December 25, 2024 23:03
@ohlidalp ohlidalp force-pushed the terrn_export branch 2 times, most recently from 59c9ae3 to 2d3f7e8 Compare December 27, 2024 00:37
CuriousMike56

This comment was marked as resolved.

ohlidalp added a commit to ohlidalp/rigs-of-rods that referenced this pull request Dec 29, 2024
The import wizzard doesn't pop up automatically anymore.

Requested by Mike on GitHub: RigsOfRods#3199 (review) at the bottom.
@ohlidalp
Copy link
Member Author

@CuriousMike56 I added a button to launch the import wizzard.
image

I'll tackle the rotations next.

@ohlidalp
Copy link
Member Author

@CuriousMike56 Rotations should be good now. I haven't tested RaceMax though, I channeled all energy into further evolving the editor mode.

@CuriousMike56

This comment was marked as resolved.

Consistency++; Until now some document objects were named `^Document` (RigDef, GenericDocument), some `^File` (Odef, TObj) and some `^Def` (skin).

Principal changes are in file 'ForwardDeclarations.h' - all document types and smart pointer typedefs are now here. The rest is pretty much all find&replace.
The 'logs/editor_out.log' file is history. The game now edits *.tobj files directly, but only if the terrain is unzipped in a directory (= a project). Exiting terrain editor at a zipped terrain will show a console warning "cannot export - not a project".

Known issues:
* preloaded actors rotations are off
* procedural road bridge types are not preserved.
* The "Terrain editor mode" doesn't inform about projects. TBD: add a button to import zipped terrain as project (internals already exist, only UI needs to be updated).
In this mode, the road will automatically switch between solid base and bridge depending on current height above ground.
Internally, this mode already existed, but was only activated when importing legacy blocky-road into procedural road.

This fixes the new TOBJ export from terrain editor.
* 'terrain_project_importer.as' - Launched automatically with terrain-editor mode with a read-only (ZIPped) terrain, provides info and import controls.
How I could trigger it:
1. enter simple test Terrain (zipped)
2. load 'script_editor.as' script.
3. enter terrain-editor mode --> game launches 'terrain_project_importer.as' --> boom.

May be related: There are 2 messages "cannot run function with ID -1" that seem to appear when the terrain import script starts, I dont know where they come from.
There are 2 new methods in AngelScript `ProceduralManagerClass`:
* `void rebuildObjectMesh(ProceduralObjectClassPtr@)` - previously private `updateObject()`
* `void deleteObjectMesh(ProceduralObjectClassPtr@)` - previously private `deleteObject()`

script 'road_editor.as' updated to use this.
Only works for:
* static object lines
* procedural points
* procedural points imported from old-style (rortoolkit) roads.
Codechanges:
* the EditorObject struct was converted to RefCountingObject<TerrainEditorObject>
* Code setting position+rotation was moved from UpdateInputEvents() to member funcs setPosition()/setRotation() which will be exported to script.
* a lot of find&replace (replacing operator. with operator->)
This lets script enumerate all static objects currently on terrain. Docs+Example script included.
The object can be moved and rotated, just like in the builtin terrain-editor mode.
Previously objects spawned via TOBJ file mostly didn't have instance names (optional), so this script function couldn't be used with them.
Now, all objects without custom instancename get one generated, as "auto^filename.tobj(line#)".
These auto^ names are not saved when exporting TOBJ from terrain editor.

The 'example_terrn_editorObjects.as' file was updated to showcase this.
Problem1: removing object while being active in terrain editor caused glitches, as the editor just jumped to the next object (and would probably crash if last object was active).
Fix1: Properly reset terrain editor mode on object removal.

Problem2: moving object via `game.moveObjectVisuals` wouldn't update the editor object.
Fix2: remove `struct StaticObject` altogether, use just TerrainEditorObject to track static objects.
Positive side effect: destroyed objects are now really removed, instead of just setting `enabled = false`.

Additional code change: TerrainObjectManager funcs renamed to match those in script API.
The import wizzard doesn't pop up automatically anymore.

Requested by Mike on GitHub: RigsOfRods#3199 (review) at the bottom.
The predefined actors on terrain (types 'truck/load/boat/machine/truck2') are now included in the 'editor objects' array, which means:
* they are included in angelscript function `game.getTerrainEditorObjects()`
* TBD: `game.spawnObject()` or `game.destroyObject()` is not integrated yet.
* The classic editor mode will pick them like any other object, you can move/rotate it and the changes will be saved.
* TBD  movement and rotation is not visually updated yet.
* The position+rotation is now written out to TOBJ precisely how it was read (it's not being reconstructed from actual actor position) - this eliminates any subtle shifts observed with the previous solution.

Code changes:
* TerrainObjectManager: `struct PredefinedActor` was eliminated - it's role was substituted by `TerrainEditorObject`.
* Application: enum SpecialObject was moved from TObjFileFormat.h to reduce header dependencies.
* TerrainAngelscript: enum SpecialObject was registered, TerrainEditorObjectClass was extended with SpecialObject get/set funcs.
* TerrainEditor: also reconstruct TOBJ predefined actors.
Major changes:
* ActorSpawnRequest can now contain pre-obtained actorInstanceID, the same way as FreeForce request can have pre-obtained ID, the functions are named the same.
* TerrainEditorObject can now reference a live actor instance - used for visualization in editor mode.
* Initial visualization logic for preloaded actors - The visualization still doesn't work for some reason, I tried `RESET_ON_SPOT` paired with `requestTranslation()` but that was created for LiveRepair (aka interactive reset) and doesn't work as needed.

Time:
* This stretched to 2 hours instead of expected 1 and didn't even get the job done.
Rotating still TBD.

To do this, 2 new 'types' had to be added to `MSG_SIM_MODIFY_ACTOR_REQUESTED`:
* SOFT_RESPAWN, //!< Like hard reset, but positions the actor like spawn process does - using the relative positions from rig-def file (respecting Tuning system tweaks).
* REFRESH_VISUALS //!< Forces a synchronous update of visuals from any context - i.e. from terrain editor mode or with sleeping/physicspaused actor.

Time spent: 90min
TerrainEditor.h - fixed comments, variables moved for clarity, renamed `node` to static_object_node
TerrainEditor.cpp - fixed direct manipulations with `node` (caused crash when pressing middle mouse button in editor)
TerrainObjectManager.cpp - `destroyObject()` - handle preloaded actors correctly
@ohlidalp
Copy link
Member Author

ohlidalp commented Jan 6, 2025

Terrain editor is done. Not perfect - preloaded actor is visually off-center when moving/rotating, so what you see is not what you get, but I can fix that in later PR. Crash on MMB is fixed.

@ohlidalp ohlidalp requested a review from CuriousMike56 January 6, 2025 21:06
@ohlidalp ohlidalp merged commit 81c550c into RigsOfRods:master Jan 6, 2025
2 checks passed
ohlidalp added a commit that referenced this pull request Jan 6, 2025
The import wizzard doesn't pop up automatically anymore.

Requested by Mike on GitHub: #3199 (review) at the bottom.
@ohlidalp ohlidalp deleted the terrn_export branch January 6, 2025 21:18
@ohlidalp ohlidalp requested review from AnotherFoxGuy and removed request for Zentro, CuriousMike56 and AnotherFoxGuy January 6, 2025 21:18
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.

3 participants