Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"files.exclude":
{
"**/.DS_Store":true,
"**/.git":true,
"**/.gitmodules":true,
"**/*.booproj":true,
"**/*.pidb":true,
"**/*.suo":true,
"**/*.user":true,
"**/*.userprefs":true,
"**/*.unityproj":true,
"**/*.dll":true,
"**/*.exe":true,
"**/*.pdf":true,
"**/*.mid":true,
"**/*.midi":true,
"**/*.wav":true,
"**/*.gif":true,
"**/*.ico":true,
"**/*.jpg":true,
"**/*.jpeg":true,
"**/*.png":true,
"**/*.psd":true,
"**/*.tga":true,
"**/*.tif":true,
"**/*.tiff":true,
"**/*.3ds":true,
"**/*.3DS":true,
"**/*.fbx":true,
"**/*.FBX":true,
"**/*.lxo":true,
"**/*.LXO":true,
"**/*.ma":true,
"**/*.MA":true,
"**/*.obj":true,
"**/*.OBJ":true,
"**/*.asset":true,
"**/*.cubemap":true,
"**/*.flare":true,
"**/*.mat":true,
"**/*.meta":true,
"**/*.prefab":true,
"**/*.unity":true,
"build/":true,
"Build/":true,
"Library/":true,
"library/":true,
"obj/":true,
"Obj/":true,
"ProjectSettings/":true,
"temp/":true,
"Temp/":true
}
}
8 changes: 8 additions & 0 deletions Assets/Resources.meta

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

1 change: 1 addition & 0 deletions Assets/Resources/BillingMode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"androidStore":"GooglePlay"}
7 changes: 7 additions & 0 deletions Assets/Resources/BillingMode.json.meta

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

7 changes: 6 additions & 1 deletion Assets/SplineMesh/Doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SplineMesh documentation *

// What is it?
A spline is a set of nodes connected by bezier curves. Each node is defined by a position and a direction.
A spline is a set of nodes connected by bezier curves. Each node is defined by a position, a direction, and if set as a corner node, a second direction.
The MeshBender component create a mesh from a source mesh by moving its vertices accordingly to a bezier curve.

// How to create a spline object?
Expand All @@ -19,6 +19,11 @@
hold alt key and drag a node to duplicate it
use delete button in the inspector to delete selected node (you can't have less than two nodes)

// How to draw a corner?
select an object with Spline component (and make sure the component is opened)
change the Handle type to Corner
when a node is selected, the two directions can be moved separately.

// How to bend a mesh?
you will probably need a script to create the GameObjects holding curved meshes
every usecase is unique and you will have to create your own script to suit you specific needs
Expand Down
3 changes: 3 additions & 0 deletions Assets/SplineMesh/Scripts/Bezier/CubicBezierCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public void ConnectEnd(SplineNode n2) {
/// </summary>
/// <returns></returns>
public Vector3 GetInverseDirection() {
if (n2.HandleType == Spline.HandleType.Corner)
return n2.Direction2;

return (2 * n2.Position) - n2.Direction;
}

Expand Down
19 changes: 19 additions & 0 deletions Assets/SplineMesh/Scripts/Bezier/Spline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace SplineMesh {
[ExecuteInEditMode]
[SelectionBaseAttribute]
public class Spline : MonoBehaviour {

public enum HandleType {
Symmetric,
Corner
}


#if UNITY_EDITOR
/// <summary>
/// Used by SplineEditor to know which node was last selected for this Spline.
Expand All @@ -42,6 +49,9 @@ public class Spline : MonoBehaviour {
/// </summary>
public float Length;

[SerializeField]
private HandleType handleType = HandleType.Symmetric;

[SerializeField]
private bool isLoop;

Expand All @@ -53,6 +63,13 @@ public bool IsLoop {
}
}

public HandleType Handle {
get { return handleType; }
set {
handleType = value;
}
}

/// <summary>
/// Event raised when the node collection changes
/// </summary>
Expand Down Expand Up @@ -138,6 +155,8 @@ public void RefreshCurves() {
for (int i = 0; i < nodes.Count - 1; i++) {
SplineNode n = nodes[i];
SplineNode next = nodes[i + 1];
n.HandleType = handleType;
next.HandleType = handleType;

CubicBezierCurve curve = new CubicBezierCurve(n, next);
curve.Changed.AddListener(UpdateAfterCurveChanged);
Expand Down
34 changes: 34 additions & 0 deletions Assets/SplineMesh/Scripts/Bezier/SplineNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ public Vector3 Direction {
[SerializeField]
private Vector3 direction;

public Vector3 InverseDirection {
get {
// TODO esto est mal
return this.position - (this.position - this.direction).Abs();
}
}

/// <summary>
/// Node direction at the end point. Used if handle type is set to corner
/// </summary>
public Vector3 Direction2 {
get { return direction2; }
set {
if (direction2.Equals(value)) return;
direction2.x = value.x;
direction2.y = value.y;
direction2.z = value.z;
if (Changed != null) Changed(this, EventArgs.Empty);
}
}
[SerializeField]
private Vector3 direction2;

/// <summary>
/// Up vector to apply at this node.
/// Usefull to specify the orientation when the tangent blend with the world UP (gimball lock)
Expand Down Expand Up @@ -93,6 +116,17 @@ public float Roll {
[SerializeField]
private float roll;

public Spline.HandleType HandleType {
get { return handleType; }
set {
if (handleType == value) return;
handleType = value;
if (Changed != null) Changed(this, EventArgs.Empty);
}
}

[SerializeField]
private Spline.HandleType handleType;
public SplineNode(Vector3 position, Vector3 direction) {
Position = position;
Direction = direction;
Expand Down
43 changes: 36 additions & 7 deletions Assets/SplineMesh/Scripts/Editor/SplineEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ void OnSceneGUI() {
selectionIndex = spline.selectedNodeIndex;
spline.selectedNodeIndex = spline.nodes.IndexOf(selection);
selection.Direction += newPosition - selection.Position;
selection.Direction2 = selection.InverseDirection;
selection.Position = newPosition;
} else {
Undo.RecordObject(target, $"Moved node {selectionIndex} of {spline.name}");
selection.Direction += newPosition - selection.Position;
selection.Direction2 = selection.InverseDirection;
selection.Position = newPosition;
}
}
Expand All @@ -138,15 +140,27 @@ void OnSceneGUI() {
if (localResult != selection.Direction) {
Undo.RecordObject(target, $"Changed direction of node {selectionIndex} in {spline.name}");
selection.Direction = localResult;
if (selection.HandleType == Spline.HandleType.Symmetric) {
selection.Direction2 = selection.InverseDirection;
}
}
break;
}
case SelectionType.InverseDirection: {
var result = Handles.PositionHandle(2 * spline.transform.TransformPoint(selection.Position) - spline.transform.TransformPoint(selection.Direction), Quaternion.identity);
var localResult = 2 * selection.Position - spline.transform.InverseTransformPoint(result);
if (localResult != selection.Direction) {
Undo.RecordObject(target, $"Changed inverse-direction of node {selectionIndex} in {spline.name}");
selection.Direction = localResult;
if (selection.HandleType == Spline.HandleType.Symmetric){
var result = Handles.PositionHandle(2 * spline.transform.TransformPoint(selection.Position) - spline.transform.TransformPoint(selection.Direction), Quaternion.identity);
var localResult = 2 * selection.Position - spline.transform.InverseTransformPoint(result);
if (localResult != selection.Direction) {
Undo.RecordObject(target, $"Changed inverse-direction of node {selectionIndex} in {spline.name}");
selection.Direction = localResult;
}
} else if (selection.HandleType == Spline.HandleType.Corner) {
var result = Handles.PositionHandle(spline.transform.TransformPoint(selection.Direction2), Quaternion.identity);
var localResult = spline.transform.InverseTransformPoint(result);
if (localResult != selection.Direction) {
Undo.RecordObject(target, $"Changed direction of node {selectionIndex} in {spline.name}");
selection.Direction2 = localResult;
}
}
break;
}
Expand All @@ -168,8 +182,9 @@ void OnSceneGUI() {
++nIdx;
var dir = spline.transform.TransformPoint(n.Direction);
var pos = spline.transform.TransformPoint(n.Position);
var invDir = spline.transform.TransformPoint(2 * n.Position - n.Direction);
var invDir = spline.Handle == Spline.HandleType.Symmetric ? spline.transform.TransformPoint(2 * n.Position - n.Direction) : spline.transform.TransformPoint(n.Direction2);
var up = spline.transform.TransformPoint(n.Position + n.Up);
var dir2 = spline.transform.TransformPoint(n.Direction2);
// first we check if at least one thing is in the camera field of view
if (!(CameraUtility.IsOnScreen(pos) ||
CameraUtility.IsOnScreen(dir) ||
Expand All @@ -186,7 +201,9 @@ void OnSceneGUI() {

// for the selected node, we also draw a line and place two buttons for directions
Handles.color = DIRECTION_COLOR;
Handles.DrawLine(guiDir, guiInvDir);
Handles.DrawLine(guiDir, guiPos);
Handles.DrawLine(guiPos, guiInvDir);
Handles.DrawWireCube(dir2, Vector3.one * 5);

// draw quads direction and inverse direction if they are not selected
if (selectionType != SelectionType.Node) {
Expand Down Expand Up @@ -277,6 +294,13 @@ public override void OnInspectorGUI() {
}
GUI.enabled = true;

Spline.HandleType newHandle = (Spline.HandleType)EditorGUILayout.EnumPopup("Handle type", spline.Handle);
if (newHandle != spline.Handle) {
spline.Handle = newHandle;
foreach (var node in spline.nodes) {
node.HandleType = newHandle;
}
}
showUpVector = GUILayout.Toggle(showUpVector, "Show up vector");
spline.IsLoop = GUILayout.Toggle(spline.IsLoop, "Is loop");

Expand All @@ -301,20 +325,25 @@ public override void OnInspectorGUI() {
private void DrawNodeData(SerializedProperty nodeProperty, SplineNode node) {
var positionProp = nodeProperty.FindPropertyRelative("position");
var directionProp = nodeProperty.FindPropertyRelative("direction");
var direction2Prop = nodeProperty.FindPropertyRelative("direction2");
var upProp = nodeProperty.FindPropertyRelative("up");
var scaleProp = nodeProperty.FindPropertyRelative("scale");
var rollProp = nodeProperty.FindPropertyRelative("roll");

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(positionProp, new GUIContent("Position"));
EditorGUILayout.PropertyField(directionProp, new GUIContent("Direction"));
if (node.HandleType == Spline.HandleType.Corner)
EditorGUILayout.PropertyField(direction2Prop, new GUIContent("Direction2"));
EditorGUILayout.PropertyField(upProp, new GUIContent("Up"));
EditorGUILayout.PropertyField(scaleProp, new GUIContent("Scale"));
EditorGUILayout.PropertyField(rollProp, new GUIContent("Roll"));

if (EditorGUI.EndChangeCheck()) {
node.Position = positionProp.vector3Value;
node.Direction = directionProp.vector3Value;
if (node.HandleType == Spline.HandleType.Corner)
node.Direction2 = direction2Prop.vector3Value;
node.Up = upProp.vector3Value;
node.Scale = scaleProp.vector2Value;
node.Roll = rollProp.floatValue;
Expand Down
4 changes: 4 additions & 0 deletions Assets/SplineMesh/Scripts/MeshProcessing/SplineMeshTiling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ private void Update() {

public void CreateMeshes() {
#if UNITY_EDITOR
#if UNITY_2021_3_OR_NEWER
if (UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null) return;
#else
// we don't update if we are in prefab mode
if (PrefabStageUtility.GetCurrentPrefabStage() != null) return;
#endif
#endif
var used = new List<GameObject>();

Expand Down
8 changes: 8 additions & 0 deletions Assets/SplineMesh/Scripts/Utils/UOUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ public static void DestroyChildren(GameObject go) {
Destroy(childTransform.gameObject);
}
}

public static Vector3 Abs(this Vector3 v) {
return new Vector3(
Mathf.Abs(v.x),
Mathf.Abs(v.y),
Mathf.Abs(v.z)
);
}
}
}
Loading