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

WIP: Add foliage instancer #340

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

WIP: Add foliage instancer #340

wants to merge 19 commits into from

Conversation

TokisanGames
Copy link
Owner

@TokisanGames TokisanGames commented Mar 24, 2024

Fixes #43
Partially addresses #368

This PR extends the asset dock to include mesh assets.
A PackedScene can be dropped in, meaning a .glb, .fbx asset, or a .tscn. It will search the scene for all MeshInstance3Ds and currently selects the first one found.

General Changes Done

  • Opacity renamed to strength, and >100 is allowed for all tools (merged)
  • Tool settings are now shown instead of hidden, including brush selector (merged)
  • CTRL Key negative input for Enable(merged)
  • Redesign flexible asset dock that can move to all positions and save settings in EditorSettings
  • Rename Terrain3DTexture -> Terrain3DTextureAsset
  • Rename Terrain3DTextureList -> Terrain3DAssets

Foliage Instancer Done

  • Quadmesh populates where painted into an MMI, with correct height and normal
  • Restrict foliage brush to ring
  • Instancing evenly distributed within circle indicator, fix square placement
  • Remove MM instances (with CTRL, or Enable unchecked)
  • Create an Instancer resource class that can be saved
  • Create UI for mesh assets and textures
  • Create instanceable mesh object
  • Create MMIs in chunks
  • Move data to Storage
  • Create instanced object settings for:
    • Height offset (adjust origin)
    • Quad mesh w/ texture and/or material
    • Custom mesh

image

To Do

  • Tool settings toggle for applying ground normal, height offset
  • Improve generated grass: vertex count, pointy, bend
  • Smaller MMI chunks 32-64/region
  • Undo/redo
  • Document
  • Check default asset dock position w/ default settings

Pushed to future PRs

  • Improve generated grass: Meshless, gradient, wind
  • Create & destroy small MMI segments dynamically. Waiting on Make collision generation dynamic #278
  • Collision generation
  • LODs, except what is provided by MMI and autolod

@TokisanGames TokisanGames marked this pull request as draft March 24, 2024 08:30
@TokisanGames TokisanGames force-pushed the foliage-instancer branch 2 times, most recently from 1815d8b to 1ab45f0 Compare March 25, 2024 09:15
@Saul2022
Copy link

Looking great as far as i tested(ik it pretty early , but couldn't wait to check it out) even with shadows seem's like performance increase a bit as it hiding the terrain mesh, though something i notice is that using transform in terrain changes the grass location

@TokisanGames
Copy link
Owner Author

Alright, I have disabled transforms.

@TokisanGames
Copy link
Owner Author

TokisanGames commented Apr 7, 2024

I did a major overhaul on the asset dock and need testers. I'll merge this commit into the main tree once it's polished, before this foliage PR is finished.

image

What should work and needs testing:

  • Move asset dock to bottom or any sidebar position
  • Resize icons
  • Texture selection/adding/removing/editing settings should still work like normal
  • Switching between scenes w/ separate Terrain3D instances open the texture list should update
  • Save the layout settings and reload them on restart - Note you must save your project before this will work, as this configuration is saved in Project Settings
  • Popout to a window w/ following behavior:
    • Pin that window so its always on top or not
    • Saving the project (CTRL+S) while the window is focused
    • Window Focus follows the mouse between godot and asset dock so that the mouse cursor and painting works fine in the viewport

Using these options do work, but they don't fire any signals that I can detect without hacks
image

But I made my own buttons which should be used for moving position or popping out
image

Other notes:

  • Mesh/Texture buttons do nothing, but will act like tabs
  • Needs to be cleaned up and prints a lot of troubleshooting to the console.

This binary can be tested:
https://github.com/TokisanGames/Terrain3D/actions/runs/8587341009

@Saul2022
Copy link

Saul2022 commented Apr 17, 2024

Testing:

1 Moving the dock on every sidebar or bottom seem´s to work well through when the terrain 3d node is selected and the asset dock is at the bottom it not possible to see the other tabs, meanwhile when you diselect the node and click on the tab it works well without overlapping the other docks. ( althought that is fixed when you make the editor fullscreen.

editor_screenshot_2024-04-17T184339
editor_screenshot_2024-04-17T184550
editor_screenshot_2024-04-17T184651

2 Resizing works but when you make it way too big it not possible to edit the corresponding texture as you can´t acces the three dots or delete.

editor_screenshot_2024-04-17T184847

3 Works as usual

4 I am not sure what you mean, but as far as i tried having two scenes with the same textures/ material list save to save, for example i add one new material to a scene, then save and then on the other scene the textures remain as positioned and the same as the one i recently saved.

5 Don´t have layout.

6not sure if it fine or made something wrong but sseems that when pinned it stays on screen within other tabs and when saving it stays on the same position it was put before saving, though when minimizing the godot app the screen stays in other programs unless you minimize it too, so maybe when minimizing godot you could make it so the pinned dock is also minimized, same when you open it again.

@TokisanGames
Copy link
Owner Author

Thanks for testing @Saul2022 .

  1. when the terrain 3d node is selected and the asset dock is at the bottom it not possible to see the other tabs,

This when Godot is in a window, or maybe a narrow height screen resolution? This is due to the minimum height of the panel. The other bottom tabs do the same thing. Especially click Audio, which has a very tall minimum height. The bar drops way below.

2 Resizing works but when you make it way too big it not possible to edit the corresponding texture as you can´t acces the three dots or delete.

You can right-click to edit or middle click to clear/delete.

4 I am not sure what you mean,

Two scenes open: Demo and imported. Each has a copy of Terrain3D, with different storage and asset dock. Switching back and forth between the scenes, the asset dock should populate with their respective textures, at least if Terrain3D is selected.

5 Don´t have layout.

Layout is the dock position, size, pinned. This is saved to project settings so should be retained when you restart godot, as long as it doesn't crash.

6 not sure if it fine or made something wrong but sseems that when pinned it stays on screen within other tabs

The pin means always on top. It should stay on screen.

and when saving it stays on the same position it was put before saving,

The dock should stay at the position it was in before you saved. I don't understand. You move the doc to bottom right, then save it, it should stay at the bottom right.

so maybe when minimizing godot you could make it so the pinned dock is also minimized, same when you open it again.

That's a good idea. I don't know if I have access to detect that, though.

@TokisanGames
Copy link
Owner Author

Updates:

  • Reduced maximum size of tiles so the delete/edit buttons don't slide off the sidebar
  • Windowed asset dock now hides when Godot is minimized
  • Window focusing much more subtle and effective

Bottom bar disappearing I'll ignore for now as I think it's a godot issue, as they all do it.

@TokisanGames TokisanGames force-pushed the foliage-instancer branch 3 times, most recently from e5d450f to 5e1855b Compare April 26, 2024 03:46
@darrylryan
Copy link

I see no reason why you couldn't also paint trees and bushes using this same system. The only differences would be:

  1. The spacing would need to be calculated from the AABB of the mesh
  2. The density would need to be capped much lower for large meshes.
  3. We couldn't draw complex meshes into the far distance and far away chunks couldn't just "disappear" for items large enough to be seen from miles away or it would look weird. A good solution would be to use this: https://github.com/zhangjt93/godot-imposter to generate an impostor for each mesh and then set the MM to the real tree for closest chunk and all the further away chunks could just be impostors (which in effect work much like the current grass system).

@TokisanGames TokisanGames force-pushed the foliage-instancer branch 3 times, most recently from 2167432 to e7d2212 Compare April 28, 2024 13:45
@TokisanGames
Copy link
Owner Author

TokisanGames commented May 3, 2024

Update:

  • The asset dock can now load packed scenes for meshes. It will automatically locate the first mesh to use for instancing.
  • There's an option for generated grass, which is currently just the basic green quad.
  • Multiple MMIs are created or destroyed when painting, based on location and mesh id. Currently this breaks down by region, but will be smaller segments later. This is saveable.

image

@Saul2022
Copy link

Saul2022 commented May 9, 2024

Tested on latest action and seems like when deleting an mesh instance, engine crashes inmediatly.

Also modifying the new properties like color, height etc,seems to not work with neither the generated blade nor a custom mesh.

Furthermore when you try replace the terrain plugin folder on an existing project that had it already(which in this case was the one used to test last weeks grass project) it made the scene corrupted for some reason.

And grass keeps dissapearing whenever i switch between scenes ( in this case a custom billboarder scene)

@TokisanGames
Copy link
Owner Author

Tested on latest action and seems like when deleting an mesh instance, engine crashes inmediatly.

Ok, I see, thanks. You mean removing a MeshAsset from the asset dock, not removing an instance with CTRL.

Also modifying the new properties like color, height etc,seems to not work with neither the generated blade nor a custom mesh.

Only the UI elements for the tool settings are there. The functionality hasn't been implemented yet.

Furthermore when you try replace the terrain plugin folder on an existing project that had it already(which in this case was the one used to test last weeks grass project) it made the scene corrupted for some reason.

Not "corrupted", just unparseable because you saved a resource with a different name inside. Easily fixable by editing the file to the new resource name.

Whatever you tested on last week is incompatible. Assuming you're using the demo, reset the project back to the main branch. If using your own project, that's dangerous. Reset your terrain3D resource files.

And grass keeps dissapearing whenever i switch between scenes ( in this case a custom billboarder scene)

Ok, I see.

Thanks for the reports.

@Saul2022
Copy link

Saul2022 commented May 9, 2024

Tested on latest action and seems like when deleting an mesh instance, engine crashes inmediatly.

Ok, I see, thanks. You mean removing a MeshAsset from the asset dock, not removing an instance with CTRL.

The first yea

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.

Implement foliage instancing
3 participants