Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syncing UI Spline and Regular 3D Spline
#1
Hi, I would like to know how to synchronize the shapes of two splines to be exactly the same?

I briefly went through the docs, but cannot wrap my head around it for my purposes.

In the attached picture, I have pointed out the two spline and where they are. The smaller UI Spline on the right is on a canvas and is user modifiable. The larger 3D spline is positioned as a gameobject on a movable 3D land object to represent the previous UI spline on the 3D model.

I want to do two things with them :

1. The UI Spline can be modified in shape by the user dragging on any of the pink outlined points.
2. The 3D Spline must replicate the shape of the UI Slime once the user has finished dragging the UI spline points.

Questions :

1. What's the best way to sync both the splines? I could easily sync positions of spline waypoints if both were in world space or both in UI space, but here both the splines are in different spaces, one in canvas, one in world space. Hence, I'm unable to comprehend an easy way to translate the positional changes of the waypoints of UI Slime to the 3D slime.

2. How do I go about actually setting up the waypoints to be interactable in the UI Spline on canvas in runtime?

3. Can you point me to the right direction in terms of making the 3D spline look like a coloured tube? Basically the second spline is a 3D tube going underground and needs to look that way. Will I be able to represent the red curve part as well exactly as the UI spline? This means the spline will have blue coloured mesh, then red coloured mesh from the next way point, then a blue coloured mesh again till the end point.

Please assist me on this.


Attached Files Image(s)
   
Reply
#2
Hi,

1- Splines' control points coordinates are in the local space of the spline. So by using the same local position, and changing the spline's transform, you can have synchronized splines with different scales, rotations and positions. I attached a scene and script doing this. In my script I synchronize only the the control point's positions. I assume that both your splines have already the right setup (the same interpolation type for example), and that you don't modify the handles. If that assumption is false, you can easily add to my script the code that will synchronize the needed properties.

2- You will need to write the code for a simplified runtime editor. I bet there are on the store some assets that already do that. Control points being GameObjects, anything on the store that allows you to move game objects at runtime will do the trick here.

3- Yes, you can have multiple meshes with multiple materials on the same spline. I added to the attached scene a "TubeSetuper" that does that with two materials. You can then enhance that script to handle whatever number of tubes you need.

Keep in mind that both the scripts are just proof of concept, so they are definitely not be the most optimized and error resilient scripts you can get.

Let me know if you still have any other question
Have a nice day


Attached Files
.zip   OilDrilling.zip (Size: 7.97 KB / Downloads: 2)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(03-12-2019, 12:00 PM)_Aka_ Wrote: Hi,

1- Splines' control points coordinates are in the local space of the spline. So by using the same local position, and changing the spline's transform, you can have synchronized splines with different scales, rotations and positions. I attached a scene and script doing this. In my script I synchronize only the the control point's positions. I assume that both your splines have already the right setup (the same interpolation type for example), and that you don't modify the handles. If that assumption is false, you can easily add to my script the code that will synchronize the needed properties.

2- You will need to write the code for a simplified runtime editor. I bet there are on the store some assets that already do that. Control points being GameObjects, anything on the store that allows you to move game objects at runtime will do the trick here.

3- Yes, you can have multiple meshes with multiple materials on the same spline. I added to the attached scene a "TubeSetuper" that does that with two materials. You can then enhance that script to handle whatever number of tubes you need.

Keep in mind that both the scripts are just proof of concept, so they are definitely not be the most optimized and error resilient scripts you can get.

Let me know if you still have any other question
Have a nice day

Hi,

Thankyou so much for providing a sample as well. It was very helpful.

Is there a way I can control the sections of the UI spline in a particular way?

For example, as you can see in the previous attached image, the UI spline section needs to be in a particular shape.

The blue initial section of line representing distance "D1" should be straight at all times and angle should be 90 degrees no matter how the length would be changed.

The next section that is the red curve should be governed by the angle "θ". θ will start from line "r1" and extend till a particular angle, which will govern the length of the red curve till point D3. 

The last blue section should be straight at all times and it's length will depend on the value of "XT" found by equations and the red curve, together.

I know my question is a bit complex, but basically is there any way to govern the angle and length of a curve using an angle? And secondly how do I keep the blue curve section straight at all times and only let their lengths be altered at run time?


Reply
#4
Hi

You will need to define the positions and tangents of the curve at the relevant points based on your constraints, and then transpose those positions and tangents to the spline. To do that, the best solution I think is to use splines with interpolation type set to Bezier. With Bezier splines, you can set the handles of each control points, which are the tangents of the curve at that point.

Here are some links that helped me figure out the mathematics behind approximating circular arcs with Bezier splines
https://www.researchgate.net/publication...vice_versa
http://hansmuller-flex.blogspot.com/2011...cubic.html
http://hansmuller-flex.blogspot.com/2011...-arcs.html

I hope this helped
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Hi, thanks again for your response. Your spline syncing works well.

Likewise, I'm trying to render the UI Spline on the canvas, but can't find any documentation or indicator on this. How do we actually go about displaying the UI Spline in game view canvas? I'm using an overlay canvas.
Reply
#6
You will need to use a Curvy Line Renderer component. You can see an example of its usage in the scene 04_PaintSpline
Here is it's API documentation (nothing much):
https://api.curvyeditor.com/520/class_fl...derer.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
(03-19-2019, 06:21 PM)_Aka_ Wrote: You will need to use a Curvy Line Renderer component. You can see an example of its usage in the scene 04_PaintSpline
Here is it's API documentation (nothing much):
https://api.curvyeditor.com/520/class_fl...derer.html
I understand.

1. Is there no way to make this work on screen space overlay canvas? The example scene works with camera space canvas.

2. How do I make curvy line renderer color different for each segment of the UI spline as shown above? Basically I'm trying to divide the spline into Blue-Red-Blue colours between four points.

3. How do I get/set the lengths of each segment (line between two points) in a spline?
Reply
#8
1. I will take a look at this tomorrow

2.You can do that using the Color in the LineRenderer, and setting the right colors at the right distances
https://docs.unity3d.com/Manual/class-LineRenderer.html

3. spline[segmentIndex].Length
https://api.curvyeditor.com/520/class_fl...becef0755e
To modifiy the length, modify the position of the CP ending that segment
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
1. Unfortunately, in the current state of things, there is no option to render a spline in screen space overlay canvas. What you can do to achieve a similar effect is to move the line renderer vertices each frame so it is always at the same position relatively to the camera.

The UI Splines were meant to be used to move UI elements along them, and not to be rendered as UI elements. This is the reason why there is no option to render them in screen space overlay canvas. I am adding this feature to the backlog, but do not expect it to be implemented in the near future.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Spawn object on Curvy Spline. ktpttd 3 26 Yesterday, 01:38 PM
Last Post: _Aka_
  Dummy spline points hnngaf 1 30 11-17-2019, 06:01 PM
Last Post: _Aka_
  Refresh spline doesn't seem to be working dazz777 4 71 11-13-2019, 11:13 PM
Last Post: _Aka_
  Same Spline Extrusion with variable width MarioBag 5 689 11-04-2019, 01:56 PM
Last Post: _Aka_

Forum Jump: