public void EditEnd(Vector3 point) { Vector3 pointOnLine = FindClosestIntersect.Search(points, point, out editEndIndex); editPoints.Add(pointOnLine); if (editStartIndex > editEndIndex) { int temp = editStartIndex; editStartIndex = editEndIndex; editEndIndex = temp; editPoints.Reverse(); } List <RotationPoint> newRotPointList = new List <RotationPoint>(); foreach (RotationPoint rotPoint in rotationPoints) { if (rotPoint.index < editStartIndex || rotPoint.index > editEndIndex) { newRotPointList.Add(rotPoint); } } rotationPoints = newRotPointList; points.RemoveRange(editStartIndex, editEndIndex - editStartIndex + 1); points.InsertRange(editStartIndex, editPoints); editingLOA = false; editPoints.Clear(); }
public void AddRotationPoint(Vector3 mouseLocation) { int index; if (rotationPoints == null) { rotationPoints = new List <RotationPoint>(); } Vector3 closestPoint = FindClosestIntersect.Search(points, mouseLocation, out index); // The new point should at the middle of the 2 points. index++; RotationPoint rotationPoint = new RotationPoint(); rotationPoint.position = closestPoint; rotationPoint.rotation = Quaternion.identity; rotationPoint.index = index; rotationPoint.range = mutatorStrength; rotationPoints.Add(rotationPoint); points.Insert(index, closestPoint); addingRotationPoint = false; foreach (RotationPoint rotPoint in rotationPoints) { if (rotPoint.index > index) { rotPoint.index++; } } GenerateAnimation(); }
public static ModelData CreateModelData(Transform model, List <Vector3> controlPoints, List <RotationPoint> rotationPoints, List <List <Vector3> > detailLoaPoints, int strength) { ModelData modelData = new ModelData(); modelData.model = GenerateNode(model); //PrintAllNodes(modelData.model, "-"); foreach (Vector3 point in controlPoints) { modelData.controlPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } foreach (List <Vector3> layer in detailLoaPoints) { // Find closest index int index; FindClosestIntersect.Search(controlPoints, layer [layer.Count / 2], out index); AnimationLayer animationLayer = new AnimationLayer() { startFrame = Math.Min(strength, index + 1), numFrames = Math.Max(index - strength, 0) }; foreach (Vector3 point in layer) { animationLayer.layerPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } modelData.animationLayers.Add(animationLayer); } if (rotationPoints != null) { foreach (RotationPoint rotPoint in rotationPoints) { swellanimations.RotationPoint nrp = new swellanimations.RotationPoint() { Rotation = new Vector() { x = rotPoint.rotation.eulerAngles.x, y = rotPoint.rotation.eulerAngles.y, z = rotPoint.rotation.eulerAngles.z } }; nrp.numFrames = Math.Min(strength, rotPoint.index + 1); nrp.startFrame = Math.Max(rotPoint.index - strength, 0); modelData.rotationpoints.Add(nrp); } } return(modelData); }
public void testIntersectPoint() { int index; Vector3 testPoint = new Vector3(4, 2, 0); Vector3 closestPoint = FindClosestIntersect.Search(createCurve(), testPoint, out index); Assert.That(closestPoint, Is.Not.Null); Assert.That(closestPoint, Is.EqualTo(testPoint)); Assert.That(index, Is.EqualTo(2)); }
public void testFarPoint() { int index; Vector3 testPoint = new Vector3(5, 13, 0); Vector3 closestPoint = FindClosestIntersect.Search(createCurve(), testPoint, out index); Assert.That(closestPoint, Is.Not.Null); Assert.That(Vector3.Distance(closestPoint, testPoint), Is.GreaterThanOrEqualTo(10)); Assert.That(index, Is.EqualTo(2)); }
public void testClosePoint() { int index; Vector3 testPoint = new Vector3(4, 2.1f, 0); Vector3 closestPoint = FindClosestIntersect.Search(createCurve(), testPoint, out index); Assert.That(closestPoint, Is.Not.Null); Assert.That(Vector3.Distance(closestPoint, testPoint), Is.LessThanOrEqualTo(0.1f)); Assert.That(index, Is.EqualTo(2)); }
public void EditStart(Vector3 point) { if (points.Count > 0) { editPoints.Clear(); Vector3 pointOnLine = FindClosestIntersect.Search(points, point, out editStartIndex); if (Vector3.Distance(pointOnLine, point) < SELECT_RANGE) { editPoints.Add(pointOnLine); } else { editingLOA = false; } } else { editingLOA = false; } }
public static ModelData CreateModelData( Transform model, List <Vector3> controlPoints, List <RotationPoint> rotationPoints, List <List <Vector3> > detailLoaPoints, int numberOfFrames, int strength) { ModelData modelData = new ModelData(); modelData.numberOfFrames = numberOfFrames; modelData.model = GenerateNode(model); //PrintAllNodes(modelData.model, "-"); List <Vector3> interpolatedPoints = new List <Vector3>(); if (controlPoints.Count > 0) { // TODO: Implement this in c++ side. // TODO: Restore original speed after calculation. Vector3 previous = controlPoints[0]; foreach (Vector3 point in controlPoints) { float distance = Vector3.Distance(previous, point); // Add interpolate points for every step distance. float step = 0.01f; int extraPoints = (int)(distance / step); for (int i = 1; i <= extraPoints; i++) { Vector3 extra = Vector3.Lerp( previous, point, i / (float)extraPoints); interpolatedPoints.Add(extra); modelData.controlPoints.Add(new Vector() { x = extra.x, y = extra.y, z = extra.z }); } //Debug.Log(distance + " " + extraPoints); previous = point; // Add the current point. interpolatedPoints.Add(point); modelData.controlPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } } foreach (List <Vector3> layer in detailLoaPoints) { // Find closest index int index; FindClosestIntersect.Search(controlPoints, layer[layer.Count / 2], out index); AnimationLayer animationLayer = new AnimationLayer() { startFrame = Math.Min(strength, index + 1), numFrames = Math.Max(index - strength, 0) }; foreach (Vector3 point in layer) { animationLayer.layerPoints.Add(new Vector() { x = point.x, y = point.y, z = point.z }); } modelData.animationLayers.Add(animationLayer); } if (rotationPoints != null) { foreach (RotationPoint rotPoint in rotationPoints) { swellanimations.RotationPoint nrp = new swellanimations.RotationPoint() { Rotation = new Vector() { x = rotPoint.rotation.eulerAngles.x, y = rotPoint.rotation.eulerAngles.y, z = rotPoint.rotation.eulerAngles.z } }; //Debug.Log(rotPoint.rotation.eulerAngles.ToString()); int pointIndex = interpolatedPoints.IndexOf(rotPoint.position); int frameIndex = (int)(pointIndex / (float)interpolatedPoints.Count * numberOfFrames); nrp.numFrames = Math.Min(strength, frameIndex + 1); nrp.startFrame = Math.Max(frameIndex - strength, 0); modelData.rotationpoints.Add(nrp); } } return(modelData); }