Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Introducing: Volume Brushes #149

Merged
merged 44 commits into from
Jun 18, 2018
Merged

Introducing: Volume Brushes #149

merged 44 commits into from
Jun 18, 2018

Conversation

Henry00IS
Copy link
Collaborator

@Henry00IS Henry00IS commented Jun 11, 2018

SabreCSG Volumes

Brushes can now be turned into Volumes. For example a trigger, a body of water or an area with a strong wind. It's easy to customize and add new volume types through C# that are automatically detected in your project and integrated into SabreCSG's editor.

A collaboration between myself and @kerfuffles.

image

How do I use it?

Select a primitive brush like a "Cube Brush (2 x 2 x2)" and in the mode of "Add" or "Subtract" set the brush to "Volume". You will see a new section in the inspector where you can select and configure the volume type, for example the "TriggerVolume". Hit the rebuild button and it works out of the box! No further changes are necessary, this workflow makes it incredibly simple to create new volumes in any shape or size.

You can change the brush mode back to "Add" or "Subtract", you can clip volumes in half, it all works like you'd expect.

How does it work?

Primitive brushes are convex. Unity's mesh collider with "Is Trigger" requires meshes to be convex. This shared rule makes brushes a perfect candidate to define areas of space. When you rebuild the volume brushes they generate a game object with a mesh collider trigger using the convex brush mesh.

Each volume type comes in two parts, an editor script that contains a custom inspector and code to add required components to the built volume game objects (e.g. "TriggerVolume", inherits from "Volume").

The second part is the component itself that will be active during play (e.g. "TriggerVolumeComponent" or something else from your project) which is an ordinary MonoBehaviour that receives OnTriggerEnter events by Unity because there is a mesh collider trigger.

How was this implemented (@sabresaurus edition)?

I wanted to implement this new feature with as minimal changes to SabreCSG's core as possible.

First I decided to add a new CSGMode as that made the most sense, there are no subtractive volumes, they aren't additive brushes, they can't be NoCSG, collision is always on but they are triggers so there is no physical collision and they are never visible, so adding another state button like NoCSG made little sense. Even NoCSG could technically be a CSGMode as they can't be subtractive.

BrushBase now has a property called Volume (usually null). This means I can expand the concept and have compound brushes be volumes in the future. Volume is a ScriptableObject that people can inherit from to build their own custom volume types.

In my first attempts I created all volume game objects under the MeshGroup as VolumeMeshes but quickly found that they were deleted on every rebuild just like MaterialMesh and CollisionMesh. When I made a VolumeGroup instead to prevent this I found that Auto Rebuild is unable to keep track of them anyway and I would have to iterate through all built volumes to try and see if it already exists, meaning for 400 volumes I would have to iterate through 400 built volumes leading up to 160,000 iterations and a bunch of checks and additional components that were unnecessary during play just to associate them, it was all a big mess and too slow.

Then I realized I could parent the built volume objects to their volume brushes. In Auto-Rebuild I have the brush transforms that need to be rebuilt, it's a quick single .Find() check to find any existing built volumes. I opted to use this approach. I used a very unique name "SabreCSG: Volume Component (67173f4f-868c-4c70-ae40-335550c8354f)" for the game objects so there's never going to be a conflict. Then I decided to hide them from the hierarchy. I added a checkbox in the SabreCSG preferences so you can manually show them if needed for development purposes. When the brush is no longer a volume I simply delete the volume object and set the Volume property back to null on rebuild.

Once play mode starts I put these volume objects under the MeshGroup, make them visible and editable for the user and they inherit the parent brush name + " (Volume)" so it's quite easy to find them again.

It's incredibly clean, the hierarchy is identical to all previous SabreCSG versions and it's extremely simple to make volumes, this workflow feels amazing and I clean up after myself, there's no invisible garbage. ;)

Important

We are working on some finishing touches. Do not use this in production projects or levels yet as we may introduce some breaking changes to the volume classes! Feedback is very welcome!

Fixes #116.

Henry00IS and others added 30 commits June 10, 2018 02:57
… Can associate a volume type in the inspector.
…kes them identifiable as volumes. Instead the custom material should be more than enough to customize it.
…nvisible game objects parented to brushes (can be shown through the SabreCSG preferences for development purposes).
* Introducing new primitive type: Capsule! And code cleanup.

* Add ReflectionProbeUsage settings

Feature addition in reference to sabresaurus#82
+ Added a group to CSGModelInspector "Common Fixes"
+ Added a toggle + enum to change ReflectionProbeUsage for the entire CSGModel

* The checkbox will reset the reflection probes to Blend Probes at every rebuild, so I decided to remove it and just have this enum as the default way to manage it.
Generic code cleanup of CSGBuildSettings and MeshGroupManager (sorry, I know that makes it hard to read, it was an accident!).

* Disabled CSG Models will no longer enable their MeshGroup during play. Fixes sabresaurus#131.

* Now only looks at the CSG Model enabled checkbox so it works like a traditional game object where only a parent could be disabled yet the children are enabled.

* Add Hollow Box Brush

+ Add HollowBoxBrush
+ Add HollowBoxBrushInspector

Simple compound brush for generating a hollow cube/box with wall thickness.

* Fix CS0252

Fix for CS0252 "Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'type' " in Toolbar.cs on .NET backend 4.5 Equivalent on unity 2017 and above.

* 2D Shape Editor can now extrude segments.

* use #if NET_4_6 to detect if the project is on the .net 4.x backend

* Now using (compoundBrushType is Type) check as discussed.

* Created a new icon for the Capsule. Added BeautifulBrushName.

* MathHelper.cs PlaneEqualsLooserWithFlip is now even looser (less precise, allowing for more floating point errors and causing less false positives).

* Increased the floats slightly which took care of a lot of artifacts I was still able to create.

* Additional fine-tuning to deal with extremely complex subtractive brushes.

* Faster and more accurate material searches for VMF and T3D. Fixed all runtime CSG game build compile errors.

* Add BrushSize feature.

* Removed unused namespaces.

* Allow individual dimention size setting for XYZ axis

* 2DSE: Fixed inverted extrude direction on flipped projects.

* Code Cleanup + bugfix

- Removed unused usings.
- Removed redundant code
- Removed scale setting feature. Possible addition to compound brush later.
* Fixed brush not being manually scalable.
* Made checking brush size easier. Now can simply use IsBrushXYZTooSmall to check the size of the brush.

* Updated SabreCSG version to 1.7.0.

* Fixed HollowBoxBrush compilation errors.

* Updated SabreCSG version to 1.7.1.

* Optimize Geometry has been demoted and is now off by default.

* Fixed HollowBoxBrush inspector compilation errors.

* Updated SabreCSG version to 1.7.2.

* Initial work on Volumes. Can now turn Primitive Brushes into Volumes. Can associate a volume type in the inspector.

* Finished the implementation of Volumes.

* Forgot to delete a couple test volumes from the branch.

* Decided against custom wireframe colors for volume brushes as that makes them identifiable as volumes. Instead the custom material should be more than enough to customize it.

* Volumes had the wrong rotation.

* Auto Rebuild is now extremely fast at building volumes. Volumes are invisible game objects parented to brushes (can be shown through the SabreCSG preferences for development purposes).

* The inspector-hidden volumes are now shown during play.
* Introducing new primitive type: Capsule! And code cleanup.

* Add ReflectionProbeUsage settings

Feature addition in reference to sabresaurus#82
+ Added a group to CSGModelInspector "Common Fixes"
+ Added a toggle + enum to change ReflectionProbeUsage for the entire CSGModel

* The checkbox will reset the reflection probes to Blend Probes at every rebuild, so I decided to remove it and just have this enum as the default way to manage it.
Generic code cleanup of CSGBuildSettings and MeshGroupManager (sorry, I know that makes it hard to read, it was an accident!).

* Disabled CSG Models will no longer enable their MeshGroup during play. Fixes sabresaurus#131.

* Now only looks at the CSG Model enabled checkbox so it works like a traditional game object where only a parent could be disabled yet the children are enabled.

* Add Hollow Box Brush

+ Add HollowBoxBrush
+ Add HollowBoxBrushInspector

Simple compound brush for generating a hollow cube/box with wall thickness.

* Fix CS0252

Fix for CS0252 "Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'type' " in Toolbar.cs on .NET backend 4.5 Equivalent on unity 2017 and above.

* 2D Shape Editor can now extrude segments.

* use #if NET_4_6 to detect if the project is on the .net 4.x backend

* Now using (compoundBrushType is Type) check as discussed.

* Created a new icon for the Capsule. Added BeautifulBrushName.

* MathHelper.cs PlaneEqualsLooserWithFlip is now even looser (less precise, allowing for more floating point errors and causing less false positives).

* Increased the floats slightly which took care of a lot of artifacts I was still able to create.

* Additional fine-tuning to deal with extremely complex subtractive brushes.

* Faster and more accurate material searches for VMF and T3D. Fixed all runtime CSG game build compile errors.

* Add BrushSize feature.

* Removed unused namespaces.

* Allow individual dimention size setting for XYZ axis

* 2DSE: Fixed inverted extrude direction on flipped projects.

* Code Cleanup + bugfix

- Removed unused usings.
- Removed redundant code
- Removed scale setting feature. Possible addition to compound brush later.
* Fixed brush not being manually scalable.
* Made checking brush size easier. Now can simply use IsBrushXYZTooSmall to check the size of the brush.

* Updated SabreCSG version to 1.7.0.

* Fixed HollowBoxBrush compilation errors.

* Updated SabreCSG version to 1.7.1.

* Optimize Geometry has been demoted and is now off by default.

* Fixed HollowBoxBrush inspector compilation errors.

* Updated SabreCSG version to 1.7.2.
+ Add TriggerVolume
+ Add TriggerVolumeComponent
+ Add TriggerVolumeEvent
* Modifed Volume and added "Volume Options" section for any additional settings in the base class.
* Modified Volume and added ChangeCheck() which is used to modify changed settings to the brush.
…ations

# Conflicts:
#	Scripts/Brushes/Volumes/Tests/WaterVolume.cs
#	Scripts/Brushes/Volumes/Volume.cs
#	Scripts/Editor/Inspectors/BrushBaseInspector.cs
…CSG Volume Component once leaving play mode with it selected. The inspector will be disabled.
…selecting different types would reset all of them to the primary selected brush type.
* Introducing new primitive type: Capsule! And code cleanup.

* Add ReflectionProbeUsage settings

Feature addition in reference to sabresaurus#82
+ Added a group to CSGModelInspector "Common Fixes"
+ Added a toggle + enum to change ReflectionProbeUsage for the entire CSGModel

* The checkbox will reset the reflection probes to Blend Probes at every rebuild, so I decided to remove it and just have this enum as the default way to manage it.
Generic code cleanup of CSGBuildSettings and MeshGroupManager (sorry, I know that makes it hard to read, it was an accident!).

* Disabled CSG Models will no longer enable their MeshGroup during play. Fixes sabresaurus#131.

* Now only looks at the CSG Model enabled checkbox so it works like a traditional game object where only a parent could be disabled yet the children are enabled.

* Add Hollow Box Brush

+ Add HollowBoxBrush
+ Add HollowBoxBrushInspector

Simple compound brush for generating a hollow cube/box with wall thickness.

* Fix CS0252

Fix for CS0252 "Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'type' " in Toolbar.cs on .NET backend 4.5 Equivalent on unity 2017 and above.

* 2D Shape Editor can now extrude segments.

* use #if NET_4_6 to detect if the project is on the .net 4.x backend

* Now using (compoundBrushType is Type) check as discussed.

* Created a new icon for the Capsule. Added BeautifulBrushName.

* MathHelper.cs PlaneEqualsLooserWithFlip is now even looser (less precise, allowing for more floating point errors and causing less false positives).

* Increased the floats slightly which took care of a lot of artifacts I was still able to create.

* Additional fine-tuning to deal with extremely complex subtractive brushes.

* Faster and more accurate material searches for VMF and T3D. Fixed all runtime CSG game build compile errors.

* Add BrushSize feature.

* Removed unused namespaces.

* Allow individual dimention size setting for XYZ axis

* 2DSE: Fixed inverted extrude direction on flipped projects.

* Code Cleanup + bugfix

- Removed unused usings.
- Removed redundant code
- Removed scale setting feature. Possible addition to compound brush later.
* Fixed brush not being manually scalable.
* Made checking brush size easier. Now can simply use IsBrushXYZTooSmall to check the size of the brush.

* Updated SabreCSG version to 1.7.0.

* Fixed HollowBoxBrush compilation errors.

* Updated SabreCSG version to 1.7.1.

* Optimize Geometry has been demoted and is now off by default.

* Fixed HollowBoxBrush inspector compilation errors.

* Updated SabreCSG version to 1.7.2.

* Initial work on Volumes. Can now turn Primitive Brushes into Volumes. Can associate a volume type in the inspector.

* Finished the implementation of Volumes.

* Forgot to delete a couple test volumes from the branch.

* Decided against custom wireframe colors for volume brushes as that makes them identifiable as volumes. Instead the custom material should be more than enough to customize it.

* Volumes had the wrong rotation.

* Auto Rebuild is now extremely fast at building volumes. Volumes are invisible game objects parented to brushes (can be shown through the SabreCSG preferences for development purposes).

* The inspector-hidden volumes are now shown during play.

* More aggressive editor code stripping for Runtime CSG. Added namespace to the volume types.

* Removed invalid .meta file

* Added a PhysicsVolume that manipulates the rigid bodies that enter it.

* Made it impossible for the user to accidentally edit the hidden SabreCSG Volume Component once leaving play mode with it selected. The inspector will be disabled.

* Fixed build errors and removed test code.

* Removed some redundant code in the CSGFactory.

* Renamed ShowHiddenGameObjectsInInspector to ShowHiddenGameObjectsInHierarchy.

* Added multi-editing support for volumes (and prevented the bug where selecting different types would reset all of them to the primary selected brush type.

* Fixed black volume gizmo sprite in Unity 5.3.

* Added the nasty hack to set event values in pre-Unity 2018 versions.
+ Add SendMessage() option to trigger volumes
* TriggerVolumeComponent now accounts for both triggerMode and triggerEventType

! Known issues !
- SendMessageEvent does not correctly serialize in the inspector, and does not update the value parameter like it should.
- UnityEvent does not properly serialize on versions previous to Unity 2018. This is an internal unity bug.
…for older Unity versions.

Problem with the original one is that it can't save in our volumes due to a bug.
Specifically:
Editor: Fixed bug where UnityEvent drawer would not synchronize correctly when displayed using multiple different serialized data streams, such as when displayed in two different windows at once. (974069)
# Conflicts:
#	Scripts/Brushes/Volumes/TriggerVolume/TriggerVolume.cs
#	Scripts/Brushes/Volumes/TriggerVolume/TriggerVolumeEventType.cs
#	Scripts/Compatibility/Editor.meta
…umes. Renamed SendMessageEvent to TriggerVolumeSendMessageEvent.
@sabresaurus
Copy link
Owner

Hi, fantastic PR. I've given it a try and I have some thoughts:

  • Parenting in the brush is inconsistent with MeshGroups, that seems like a fixable problem. It's somewhat confusing to have hidden objects in this way.
  • It's a little unclear what volumes are, maybe there should be more of a description on the actual component.
  • Force directions should be applied local to the brush, i.e. if you rotate the brush 90 degrees the force direction should be rotated
  • If a setting isn't active it should be hidden, e.g. force, etc. Like you do with filter tag
  • "Even NoCSG could technically be a CSGMode as they can't be subtractive" - beyond the scope of this PR, but that seems like a great idea!

@Henry00IS
Copy link
Collaborator Author

Most of your notes have been implemented now (as well as what we discussed). I believe inline documentation is beyond the scope of this PR because we should develop a generic system that doesn't get in the way. But I will add a wiki page on Volumes to explain what it is all about, how it works and how to build your own volume types.

… " Brush " with " Volume " instead of appending " (Volume)". This will let users give volumes a unique name so they can find it during play without us affecting their names (as they will likely not use the word Brush with spaces for these).
@Henry00IS Henry00IS merged commit bdf43f2 into sabresaurus:master Jun 18, 2018
@Henry00IS Henry00IS deleted the Volumes branch June 18, 2018 22:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants