Skip to content

Commit

Permalink
Volumes (#3)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kerfuffles authored Jun 12, 2018
1 parent 73f3f46 commit a687bb5
Show file tree
Hide file tree
Showing 23 changed files with 803 additions and 368 deletions.
54 changes: 12 additions & 42 deletions Gizmos/Volume.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions Scripts/Brushes/Volumes/Editor.meta

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

240 changes: 240 additions & 0 deletions Scripts/Brushes/Volumes/PhysicsVolume/PhysicsVolume.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
#if UNITY_EDITOR || RUNTIME_CSG

using System;
using System.Linq;
using UnityEngine;

namespace Sabresaurus.SabreCSG
{
/// <summary>
/// Applies forces to rigid bodies inside of the volume.
/// </summary>
/// <seealso cref="Sabresaurus.SabreCSG.Volume"/>
[Serializable]
public class PhysicsVolume : Volume
{
/// <summary>
/// The force mode applied to rigid bodies.
/// </summary>
[SerializeField]
public PhysicsVolumeForceMode forceMode = PhysicsVolumeForceMode.Force;

/// <summary>
/// The force applied to rigid bodies.
/// </summary>
[SerializeField]
public Vector3 force = new Vector3(0.0f, 10.0f, 0.0f);

/// <summary>
/// The relative force mode applied to rigid bodies.
/// </summary>
[SerializeField]
public PhysicsVolumeForceMode relativeForceMode = PhysicsVolumeForceMode.None;

/// <summary>
/// The relative force applied to rigid bodies.
/// </summary>
[SerializeField]
public Vector3 relativeForce = new Vector3(0.0f, 0.0f, 0.0f);

/// <summary>
/// The torque force mode applied to rigid bodies.
/// </summary>
[SerializeField]
public PhysicsVolumeForceMode torqueForceMode = PhysicsVolumeForceMode.None;

/// <summary>
/// The torque applied to rigid bodies.
/// </summary>
[SerializeField]
public Vector3 torque = new Vector3(0.0f, 0.0f, 0.0f);

/// <summary>
/// The relative torque force mode applied to rigid bodies.
/// </summary>
[SerializeField]
public PhysicsVolumeForceMode relativeTorqueForceMode = PhysicsVolumeForceMode.None;

/// <summary>
/// The relative torque applied to rigid bodies.
/// </summary>
[SerializeField]
public Vector3 relativeTorque = new Vector3(0.0f, 0.0f, 0.0f);

#if UNITY_EDITOR

/// <summary>
/// Called when the inspector GUI is drawn in the editor.
/// </summary>
/// <param name="selectedVolumes">The selected volumes in the editor (for multi-editing).</param>
/// <returns>True if a property changed or else false.</returns>
public override bool OnInspectorGUI(Volume[] selectedVolumes)
{
var physicsVolumes = selectedVolumes.Cast<PhysicsVolume>();
bool invalidate = false;

// global force:

GUILayout.BeginVertical("Box");
{
UnityEditor.EditorGUILayout.LabelField("Force Options", UnityEditor.EditorStyles.boldLabel);
GUILayout.Space(4);

UnityEditor.EditorGUI.indentLevel = 1;
GUILayout.BeginVertical();
{
PhysicsVolumeForceMode previousPhysicsVolumeForceMode;
forceMode = (PhysicsVolumeForceMode)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Force Mode", "The force mode."), previousPhysicsVolumeForceMode = forceMode);
if (previousPhysicsVolumeForceMode != forceMode)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.forceMode = forceMode;
invalidate = true;
}

Vector3 previousVector3;
UnityEditor.EditorGUIUtility.wideMode = true;
force = UnityEditor.EditorGUILayout.Vector3Field(new GUIContent("Force", "The amount of force."), previousVector3 = force);
UnityEditor.EditorGUIUtility.wideMode = false;
if (previousVector3 != force)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.force = force;
invalidate = true;
}
}
GUILayout.EndVertical();
UnityEditor.EditorGUI.indentLevel = 0;
}
GUILayout.EndVertical();

// relative force:

GUILayout.BeginVertical("Box");
{
UnityEditor.EditorGUILayout.LabelField("Relative Force Options", UnityEditor.EditorStyles.boldLabel);
GUILayout.Space(4);

UnityEditor.EditorGUI.indentLevel = 1;
GUILayout.BeginVertical();
{
PhysicsVolumeForceMode previousPhysicsVolumeRelativeForceMode;
relativeForceMode = (PhysicsVolumeForceMode)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Force Mode", "The relative force mode."), previousPhysicsVolumeRelativeForceMode = relativeForceMode);
if (previousPhysicsVolumeRelativeForceMode != relativeForceMode)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.relativeForceMode = relativeForceMode;
invalidate = true;
}

Vector3 previousVector3;
UnityEditor.EditorGUIUtility.wideMode = true;
relativeForce = UnityEditor.EditorGUILayout.Vector3Field(new GUIContent("Force", "The amount of relative force."), previousVector3 = relativeForce);
UnityEditor.EditorGUIUtility.wideMode = false;
if (previousVector3 != relativeForce)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.relativeForce = relativeForce;
invalidate = true;
}
}
GUILayout.EndVertical();
UnityEditor.EditorGUI.indentLevel = 0;
}
GUILayout.EndVertical();

// global torque:

GUILayout.BeginVertical("Box");
{
UnityEditor.EditorGUILayout.LabelField("Torque Options", UnityEditor.EditorStyles.boldLabel);
GUILayout.Space(4);

UnityEditor.EditorGUI.indentLevel = 1;
GUILayout.BeginVertical();
{
PhysicsVolumeForceMode previousPhysicsVolumeTorqueForceMode;
torqueForceMode = (PhysicsVolumeForceMode)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Force Mode", "The torque force mode."), previousPhysicsVolumeTorqueForceMode = torqueForceMode);
if (previousPhysicsVolumeTorqueForceMode != torqueForceMode)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.torqueForceMode = torqueForceMode;
invalidate = true;
}

Vector3 previousVector3;
UnityEditor.EditorGUIUtility.wideMode = true;
torque = UnityEditor.EditorGUILayout.Vector3Field(new GUIContent("Force", "The amount of torque force."), previousVector3 = torque);
UnityEditor.EditorGUIUtility.wideMode = false;
if (previousVector3 != torque)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.torque = torque;
invalidate = true;
}
}
GUILayout.EndVertical();
UnityEditor.EditorGUI.indentLevel = 0;
}
GUILayout.EndVertical();

// relative torque:

GUILayout.BeginVertical("Box");
{
UnityEditor.EditorGUILayout.LabelField("Relative Torque Options", UnityEditor.EditorStyles.boldLabel);
GUILayout.Space(4);

UnityEditor.EditorGUI.indentLevel = 1;
GUILayout.BeginVertical();
{
PhysicsVolumeForceMode previousPhysicsVolumeRelativeTorqueForceMode;
relativeTorqueForceMode = (PhysicsVolumeForceMode)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Force Mode", "The relative torque force mode."), previousPhysicsVolumeRelativeTorqueForceMode = relativeTorqueForceMode);
if (previousPhysicsVolumeRelativeTorqueForceMode != relativeTorqueForceMode)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.relativeTorqueForceMode = relativeTorqueForceMode;
invalidate = true;
}

Vector3 previousVector3;
UnityEditor.EditorGUIUtility.wideMode = true;
relativeTorque = UnityEditor.EditorGUILayout.Vector3Field(new GUIContent("Force", "The amount of relative torque force."), previousVector3 = relativeTorque);
UnityEditor.EditorGUIUtility.wideMode = false;
if (previousVector3 != relativeTorque)
{
foreach (PhysicsVolume volume in physicsVolumes)
volume.relativeTorque = relativeTorque;
invalidate = true;
}
}
GUILayout.EndVertical();
UnityEditor.EditorGUI.indentLevel = 0;
}
GUILayout.EndVertical();

return invalidate; // true when a property changed, the brush invalidates and stores all changes.
}

#endif

/// <summary>
/// Called when the volume is created in the editor.
/// </summary>
/// <param name="volume">The generated volume game object.</param>
public override void OnCreateVolume(GameObject volume)
{
PhysicsVolumeComponent component = volume.AddComponent<PhysicsVolumeComponent>();
component.forceMode = forceMode;
component.force = force;
component.relativeForceMode = relativeForceMode;
component.relativeForce = relativeForce;
component.torqueForceMode = torqueForceMode;
component.torque = torque;
component.relativeTorqueForceMode = relativeTorqueForceMode;
component.relativeTorque = relativeTorque;
}
}
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a687bb5

Please sign in to comment.