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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ExportedObj/
*.pdb
*.opendb
*.VC.db
*.vsconfig

# Unity3D generated meta files
*.pidb.meta
Expand All @@ -41,4 +42,4 @@ sysinfo.txt
*.unitypackage

# Crashlytics generated file
Assets/StreamingAssets/crashlytics-build.properties
Assets/StreamingAssets/crashlytics-build.properties
4 changes: 3 additions & 1 deletion Assets/SplineMesh/Scripts/Bezier/CurveSample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -18,6 +18,7 @@ public struct CurveSample
public readonly float distanceInCurve;
public readonly float timeInCurve;
public readonly CubicBezierCurve curve;
public int index;

private Quaternion rotation;

Expand All @@ -43,6 +44,7 @@ public CurveSample(Vector3 location, Vector3 tangent, Vector3 up, Vector2 scale,
this.distanceInCurve = distanceInCurve;
this.timeInCurve = timeInCurve;
this.curve = curve;
index = -1;
rotation = Quaternion.identity;
}

Expand Down
7 changes: 5 additions & 2 deletions Assets/SplineMesh/Scripts/Bezier/Spline.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -286,17 +286,20 @@ private void EndNodeChanged(object sender, EventArgs e) {
public CurveSample GetProjectionSample(Vector3 pointToProject) {
CurveSample closest = default(CurveSample);
float minSqrDistance = float.MaxValue;
foreach (var curve in curves) {
for (int i = 0; i < curves.Count; i++) {
var curve = curves[i];
var projection = curve.GetProjectionSample(pointToProject);
if (curve == curves[0]) {
closest = projection;
closest.index = i;
minSqrDistance = (projection.location - pointToProject).sqrMagnitude;
continue;
}
var sqrDist = (projection.location - pointToProject).sqrMagnitude;
if (sqrDist < minSqrDistance) {
minSqrDistance = sqrDist;
closest = projection;
closest.index = i;
}
}
return closest;
Expand Down
13 changes: 11 additions & 2 deletions Assets/SplineMesh/Scripts/Editor/SplineExtrusionEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEditor;

Expand All @@ -12,16 +12,22 @@ public class SplineExtrusionEditor : Editor {
private SerializedProperty sampleSpacing;
private SerializedProperty material;
private SerializedProperty vertices;
private SerializedProperty layer;
private SerializedProperty visible;
private SerializedProperty collisionEnabled;

private SplineExtrusion se;
private ExtrusionSegment.Vertex selection = null;

private void OnEnable() {
protected void OnEnable() {
se = (SplineExtrusion)target;
textureScale = serializedObject.FindProperty("textureScale");
sampleSpacing = serializedObject.FindProperty("sampleSpacing");
material = serializedObject.FindProperty("material");
vertices = serializedObject.FindProperty("shapeVertices");
layer = serializedObject.FindProperty("layer");
visible = serializedObject.FindProperty("visible");
collisionEnabled = serializedObject.FindProperty("collisionEnabled");
}

void OnSceneGUI() {
Expand Down Expand Up @@ -156,6 +162,9 @@ public override void OnInspectorGUI() {
}
}
EditorGUI.indentLevel -= 1;
EditorGUILayout.PropertyField(layer, true);
EditorGUILayout.PropertyField(visible, true);
EditorGUILayout.PropertyField(collisionEnabled, true);

serializedObject.ApplyModifiedProperties();
}
Expand Down
18 changes: 15 additions & 3 deletions Assets/SplineMesh/Scripts/MeshProcessing/SplineExtrusion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,6 +32,9 @@ public class SplineExtrusion : MonoBehaviour {
public Material material;
public float textureScale = 1;
public float sampleSpacing = 0.1f;
public string layer;
public bool visible = true;
public bool collisionEnabled = true;

/// <summary>
/// Clear shape vertices, then create three vertices with three normals for the extrusion to be visible
Expand Down Expand Up @@ -65,7 +68,7 @@ private void Update() {
}
}

private void GenerateMesh() {
protected void GenerateMesh() {
UOUtility.DestroyChildren(generated);

int i = 0;
Expand All @@ -77,13 +80,22 @@ private void GenerateMesh() {
typeof(MeshRenderer),
typeof(ExtrusionSegment),
typeof(MeshCollider));
go.GetComponent<MeshRenderer>().material = material;
MeshRenderer goRenderer = go.GetComponent<MeshRenderer>();
goRenderer.material = material;
ExtrusionSegment seg = go.GetComponent<ExtrusionSegment>();
seg.ShapeVertices = shapeVertices;
seg.TextureScale = textureScale;
seg.TextureOffset = textureOffset;
seg.SampleSpacing = sampleSpacing;
seg.SetInterval(curve);
goRenderer.enabled = visible;
if (go.TryGetComponent(out MeshCollider meshCollider)) {
meshCollider.enabled = collisionEnabled;
}
int layerNum = LayerMask.NameToLayer(layer);
if (layerNum > -1) {
go.gameObject.layer = layerNum;
}

textureOffset += curve.Length;
}
Expand Down