forked from SebLague/Path-Creator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some optimizations, added obj placement example scene, moved everythi…
…ng into assets folder.
- Loading branch information
Showing
93 changed files
with
3,015 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"files.exclude": | ||
{ | ||
"**/.DS_Store":true, | ||
"**/.git":true, | ||
"**/.gitignore":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 | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
206 changes: 73 additions & 133 deletions
206
PathCreator/Core/Editor/PathEditor.cs → PathCreator/Assets/Core/Editor/PathEditor.cs
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
136 changes: 136 additions & 0 deletions
136
PathCreator/Assets/Core/Runtime/Utility/CubicBezierUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace PathCreation.Utility { | ||
|
||
/// Collection of functions related to cubic bezier curves | ||
/// (a curve with a start and end 'anchor' point, and two 'control' points to define the shape of the curve between the anchors) | ||
public static class CubicBezierUtility { | ||
|
||
/// Returns point at time 't' (between 0 and 1) along bezier curve defined by 4 points (anchor_1, control_1, control_2, anchor_2) | ||
public static Vector3 EvaluateCurve (Vector3[] points, float t) { | ||
return EvaluateCurve (points[0], points[1], points[2], points[3], t); | ||
} | ||
|
||
/// Returns point at time 't' (between 0 and 1) along bezier curve defined by 4 points (anchor_1, control_1, control_2, anchor_2) | ||
public static Vector3 EvaluateCurve (Vector3 a1, Vector3 c1, Vector3 c2, Vector3 a2, float t) { | ||
t = Mathf.Clamp01 (t); | ||
return (1 - t) * (1 - t) * (1 - t) * a1 + 3 * (1 - t) * (1 - t) * t * c1 + 3 * (1 - t) * t * t * c2 + t * t * t * a2; | ||
} | ||
|
||
/// Returns a vector tangent to the point at time 't' | ||
/// This is the vector tangent to the curve at that point | ||
public static Vector3 EvaluateCurveDerivative (Vector3[] points, float t) { | ||
return EvaluateCurveDerivative (points[0], points[1], points[2], points[3], t); | ||
} | ||
|
||
/// Calculates the derivative of the curve at time 't' | ||
/// This is the vector tangent to the curve at that point | ||
public static Vector3 EvaluateCurveDerivative (Vector3 a1, Vector3 c1, Vector3 c2, Vector3 a2, float t) { | ||
t = Mathf.Clamp01 (t); | ||
return 3 * (1 - t) * (1 - t) * (c1 - a1) + 6 * (1 - t) * t * (c2 - c1) + 3 * t * t * (a2 - c2); | ||
} | ||
|
||
/// Returns the second derivative of the curve at time 't' | ||
public static Vector3 EvaluateCurveSecondDerivative (Vector3[] points, float t) { | ||
return EvaluateCurveSecondDerivative (points[0], points[1], points[2], points[3], t); | ||
} | ||
|
||
///Returns the second derivative of the curve at time 't' | ||
public static Vector3 EvaluateCurveSecondDerivative (Vector3 a1, Vector3 c1, Vector3 c2, Vector3 a2, float t) { | ||
t = Mathf.Clamp01 (t); | ||
return 6 * (1 - t) * (c2 - 2 * c1 + a1) + 6 * t * (a2 - 2 * c2 + c1); | ||
} | ||
|
||
/// Calculates the normal vector (vector perpendicular to the curve) at specified time | ||
public static Vector3 Normal (Vector3[] points, float t) { | ||
return Normal (points[0], points[1], points[2], points[3], t); | ||
} | ||
|
||
/// Calculates the normal vector (vector perpendicular to the curve) at specified time | ||
public static Vector3 Normal (Vector3 a1, Vector3 c1, Vector3 c2, Vector3 a2, float t) { | ||
Vector3 tangent = EvaluateCurveDerivative (a1, c1, c2, a2, t); | ||
Vector3 nextTangent = EvaluateCurveSecondDerivative (a1, c1, c2, a2, t); | ||
Vector3 c = Vector3.Cross (nextTangent, tangent); | ||
return Vector3.Cross (c, tangent).normalized; | ||
} | ||
|
||
public static Bounds CalculateBounds (Vector3[] points) { | ||
MinMax3D minMax = new MinMax3D (); | ||
minMax.AddValue (points[0]); | ||
minMax.AddValue (points[3]); | ||
|
||
List<float> extremePointTimes = ExtremePointTimes (points[0], points[1], points[2], points[3]); | ||
foreach (float t in extremePointTimes) { | ||
minMax.AddValue (CubicBezierUtility.EvaluateCurve (points, t)); | ||
} | ||
|
||
return new Bounds ((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min); | ||
} | ||
|
||
/// Splits curve into two curves at time t. Returns 2 arrays of 4 points. | ||
public static Vector3[][] SplitCurve (Vector3[] points, float t) { | ||
Vector3 a1 = Vector3.Lerp (points[0], points[1], t); | ||
Vector3 a2 = Vector3.Lerp (points[1], points[2], t); | ||
Vector3 a3 = Vector3.Lerp (points[2], points[3], t); | ||
Vector3 b1 = Vector3.Lerp (a1, a2, t); | ||
Vector3 b2 = Vector3.Lerp (a2, a3, t); | ||
Vector3 pointOnCurve = Vector3.Lerp (b1, b2, t); | ||
|
||
return new Vector3[][] { | ||
new Vector3[] { points[0], a1, b1, pointOnCurve }, | ||
new Vector3[] { pointOnCurve, b2, a3, points[3] } | ||
}; | ||
} | ||
|
||
// Crude, but fast estimation of curve length. | ||
public static float EstimateCurveLength (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) { | ||
float controlNetLength = (p0 - p1).magnitude + (p1 - p2).magnitude + (p2 - p3).magnitude; | ||
float estimatedCurveLength = (p0 - p3).magnitude + controlNetLength / 2f; | ||
return estimatedCurveLength; | ||
} | ||
|
||
/// Times of stationary points on curve (points where derivative is zero on any axis) | ||
public static List<float> ExtremePointTimes (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) { | ||
// coefficients of derivative function | ||
Vector3 a = 3 * (-p0 + 3 * p1 - 3 * p2 + p3); | ||
Vector3 b = 6 * (p0 - 2 * p1 + p2); | ||
Vector3 c = 3 * (p1 - p0); | ||
|
||
List<float> times = new List<float> (); | ||
times.AddRange (StationaryPointTimes (a.x, b.x, c.x)); | ||
times.AddRange (StationaryPointTimes (a.y, b.y, c.y)); | ||
times.AddRange (StationaryPointTimes (a.z, b.z, c.z)); | ||
return times; | ||
} | ||
|
||
// Finds times of stationary points on curve defined by ax^2 + bx + c. | ||
// Only times between 0 and 1 are considered as Bezier only uses values in that range | ||
static IEnumerable<float> StationaryPointTimes (float a, float b, float c) { | ||
List<float> times = new List<float> (); | ||
|
||
// from quadratic equation: y = [-b +- sqrt(b^2 - 4ac)]/2a | ||
if (a != 0) { | ||
float discriminant = b * b - 4 * a * c; | ||
if (discriminant >= 0) { | ||
float s = Mathf.Sqrt (discriminant); | ||
float t1 = (-b + s) / (2 * a); | ||
if (t1 >= 0 && t1 <= 1) { | ||
times.Add (t1); | ||
} | ||
|
||
if (discriminant != 0) { | ||
float t2 = (-b - s) / (2 * a); | ||
|
||
if (t2 >= 0 && t2 <= 1) { | ||
times.Add (t2); | ||
} | ||
} | ||
} | ||
} | ||
return times; | ||
} | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 6 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: Brown | ||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} | ||
m_ShaderKeywords: | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _BumpMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailAlbedoMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailMask: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailNormalMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _EmissionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 10.66} | ||
m_Offset: {x: 0, y: 0} | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 10.66} | ||
m_Offset: {x: 0, y: 0} | ||
- _MetallicGlossMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _OcclusionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _ParallaxMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Floats: | ||
- _BumpScale: 1 | ||
- _Cutoff: 0.5 | ||
- _DetailNormalMapScale: 1 | ||
- _DstBlend: 0 | ||
- _GlossMapScale: 1 | ||
- _Glossiness: 0 | ||
- _GlossyReflections: 1 | ||
- _Metallic: 0 | ||
- _Mode: 0 | ||
- _OcclusionStrength: 1 | ||
- _Parallax: 0.02 | ||
- _SmoothnessTextureChannel: 0 | ||
- _SpecularHighlights: 1 | ||
- _SrcBlend: 1 | ||
- _UVSec: 0 | ||
- _ZWrite: 1 | ||
m_Colors: | ||
- _Color: {r: 0.4528302, g: 0.19663213, b: 0.10466359, a: 1} | ||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.