Przeglądaj źródła

Update spline editor

ShiroSmith 6 lat temu
rodzic
commit
197b3fbb56
2 zmienionych plików z 44 dodań i 6 usunięć
  1. 42 2
      hide/prefab/SplineEditor.hx
  2. 2 4
      hrt/prefab/l3d/Spline.hx

+ 42 - 2
hide/prefab/SplineEditor.hx

@@ -76,9 +76,12 @@ class SplinePointViewer extends h3d.scene.Object {
 
 	var pointViewer : h3d.scene.Mesh;
 	var controlPointsViewer : h3d.scene.Graphics;
+	var indexText : h2d.ObjectFollower;
+	var spline : Spline;
 
-	public function new( sp : SplinePoint ) {
+	public function new( sp : SplinePoint, spline : Spline, ctx : hrt.prefab.Context ) {
 		super(sp);
+		this.spline = spline;
 		name = "SplinePointViewer";
 		pointViewer = new h3d.scene.Mesh(h3d.prim.Sphere.defaultUnitSphere(), null, this);
 		pointViewer.name = "pointViewer";
@@ -95,6 +98,13 @@ class SplinePointViewer extends h3d.scene.Object {
 		controlPointsViewer.clear();
 		controlPointsViewer.moveTo(1, 0, 0);
 		controlPointsViewer.lineTo(-1, 0, 0);
+
+		indexText = new h2d.ObjectFollower(pointViewer,  @:privateAccess ctx.local2d.getScene());
+		var t = new h2d.Text(hxd.res.DefaultFont.get(), indexText);
+		t.textColor = 0xff00ff;
+		t.textAlign = Center;		
+		t.dropShadow = { dx : 0.5, dy : 0.5, color : 0x202020, alpha : 1.0 };
+		t.setScale(2.5);
 	}
 
 	override function sync( ctx : h3d.scene.RenderContext ) {
@@ -106,6 +116,11 @@ class SplinePointViewer extends h3d.scene.Object {
 		var correctionFromParents =  1.0 / getAbsPos().getScale().x;
 		pointViewer.setScale(correctionFromParents * ratio * distToCam * Math.tan(cam.fovY * 0.5 * Math.PI / 180.0));
 		calcAbsPos();
+
+		var t = Std.downcast(indexText.getChildAt(0), h2d.Text);
+		var sp : SplinePoint = cast parent;
+		t.text = "" + spline.points.indexOf(sp);
+
 		super.sync(ctx);
 	}
 
@@ -117,6 +132,11 @@ class SplinePointViewer extends h3d.scene.Object {
 		controlPointsViewer.setColor(color);
 		pointViewer.material.color.setColor(color);
 	}
+
+	override function onRemove() {
+		super.onRemove();
+		indexText.remove();
+	}
 }
 
 @:access(hrt.prefab.l3d.Spline)
@@ -312,7 +332,7 @@ class SplineEditor {
 	function showViewers( ctx : hrt.prefab.Context ) {
 		removeViewers(); // Security, avoid duplication
 		for( sp in prefab.points ) {
-			var spv = new SplinePointViewer(sp);
+			var spv = new SplinePointViewer(sp, prefab, ctx);
 			splinePointViewers.insert(splinePointViewers.length, spv);
 		}
 	}
@@ -528,6 +548,11 @@ class SplineEditor {
 
 		var props = new hide.Element('
 		<div class="spline-editor">
+			<div class="group" name="Utility">
+				<div align="center">
+					<input type="button" value="Reverse" class="reverse"/>
+				</div>
+			</div>
 			<div class="group" name="Description">
 				<div class="description">
 					<i>Ctrl + Left Click</i> Add a point on the spline <br>
@@ -541,6 +566,21 @@ class SplineEditor {
 			</div>
 		</div>');
 
+		var reverseButton = props.find(".reverse");
+		reverseButton.click(function(_) {
+			prefab.points.reverse();
+			for( p in prefab.points ) 
+				p.rotate(0, 0, hxd.Math.degToRad(180));
+
+			undo.change(Custom(function(undo) {
+				prefab.points.reverse();
+				for( p in prefab.points ) 
+					p.rotate(0, 0, hxd.Math.degToRad(180));
+			}));
+			
+			ctx.onChange(prefab, null);
+		});
+
 		var editModeButton = props.find(".editModeButton");
 		editModeButton.toggleClass("editModeEnabled", editMode);
 		editModeButton.click(function(_) {

+ 2 - 4
hrt/prefab/l3d/Spline.hx

@@ -212,7 +212,7 @@ class Spline extends Object3D {
 		var sd = new SplineData();
 		data = sd;
 
-		if( step <= 0 )
+		if( step <= 0 || threshold <= 0 )
 			return;
 
 		if( points == null || points.length <= 1 )
@@ -350,8 +350,6 @@ class Spline extends Object3D {
 		return p1.sub(p0).multiply(3 * (1 - t) * (1 - t)).add(p2.sub(p1).multiply(6 * (1 - t) * t)).add(p3.sub(p2).multiply(3 * t * t)).normalizeFast();
 	}
 
-
-
 	function generateSplineGraph( ctx : hrt.prefab.Context ) {
 
 		if( !showSpline ) {
@@ -397,7 +395,7 @@ class Spline extends Object3D {
 				<dl>
 					<dt>Color</dt><dd><input type="color" alpha="true" field="color"/></dd>
 					<dt>Thickness</dt><dd><input type="range" min="1" max="10" field="lineThickness"/></dd>
-					<dt>Step</dt><dd><input type="range" min="0.1" max="10" field="step"/></dd>
+					<dt>Step</dt><dd><input type="range" min="0.1" max="1" field="step"/></dd>
 					<dt>Threshold</dt><dd><input type="range" min="0.001" max="1" field="threshold"/></dd>
 					<dt>Show Spline</dt><dd><input type="checkbox" field="showSpline"/></dd>
 					<dt>Type</dt>