Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New free asset: Converter For Unity Splines
#11
Converter 1.2.0 is now available. Here is the release notes:

Code:
### Added

- Conversion from Curvy splines to Unity splines.

- Messages window, available at Window -> Converter -> Messages.

- Menu item to open the asset's publisher's page.

### Changed

- Converter now compiles even if Curvy Splines is missing.

- Minimum Curvy Splines compatible version is now 8.9.1.

### Fixed

- Newly created splines are not converted automatically.

- Converting a Unity spline removes all its children.

Currently, there are some limitations regarding converting Curvy Splines to Unity Splines. I aim to lift these limitations in the future:
  1. You can't convert B Splines and TCB splines.
  2. The converted Catmull-Rom splines can be different from the source spline. This is due to a bug in Unity's splines package. Here is a scene with a spline made to make the difference very visible:


    .unity   Unity vs Curvy.unity (Size: 31.27 KB / Downloads: 1)

       

    And here is a reference implementation in python. You can see that Unity's implementation (yellow spline) does not match the reference implementation.

       

    Code:
    import numpy as np
    import matplotlib.pyplot as plt

    def catmull_rom_spline(P0, P1, P2, P3, n_points=100):
        t = np.linspace(0, 1, n_points)
        t2 = t**2
        t3 = t**3
       
        # Catmull-Rom matrix
        M = np.array([
            [-0.5,  1.5, -1.5,  0.5],
            [ 1.0, -2.5,  2.0, -0.5],
            [-0.5,  0.0,  0.5,  0.0],
            [ 0.0,  1.0,  0.0,  0.0]
        ])
       
        # Geometry vector
        Gx = np.array([P0[0], P1[0], P2[0], P3[0]])
        Gz = np.array([P0[1], P1[1], P2[1], P3[1]])
       
        # Calculate the spline points
        T = np.array([t3, t2, t, np.ones_like(t)])
        X = np.dot(M, Gx)
        Z = np.dot(M, Gz)
       
        x = np.dot(X, T)
        z = np.dot(Z, T)
       
        return x, z

    # Control points
    control_points = [
        (-6.291999816894531, -0.13099999725818635),
        (-6.291999816894531, -0.13099999725818635),
        (2.308000087738037, 2.569000005722046),
        (2.388000011444092, 0.14899998903274537),
        (3.138000011444092, 0.0989999920129776),
        (-0.07699990272521973, -1.3380000591278077),
        (-0.42200005054473879, -0.23100002110004426),
        (-0.42200005054473879, -0.23100002110004426)
    ]

    # Plot the control points
    x_control = [p[0] for p in control_points]
    z_control = [p[1] for p in control_points]

    # Calculate spline segments
    x_spline = []
    z_spline = []
    for i in range(len(control_points) - 3):
        x, z = catmull_rom_spline(control_points[i], control_points[i+1], control_points[i+2], control_points[i+3])
        x_spline.extend(x)
        z_spline.extend(z)

    # Plotting
    plt.figure(figsize=(10, 6))
    plt.plot(x_spline, z_spline, label='Catmull-Rom Spline')
    plt.scatter(x_control, z_control, color='red', label='Control Points', s=100)
    plt.legend()
    plt.xlabel('X')
    plt.ylabel('Z')
    plt.title('Catmull-Rom Spline')
    plt.grid(True)
    plt.gca().set_aspect('equal', adjustable='box')
    # Setting 1x1 grid with round values
    x_min, x_max = np.floor(min(x_control)), np.ceil(max(x_control))
    z_min, z_max = np.floor(min(z_control)), np.ceil(max(z_control))

    plt.xticks(np.arange(x_min, x_max + 1, 1))
    plt.yticks(np.arange(z_min, z_max + 1, 1))
    plt.show()
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#12
I posted a twitter thread about this last point: https://x.com/Tool_Buddy/status/1793644301098094938
If you have a twitter account (I call it twitter because I still listen to music on Winamp Big Grin), feel free to follow me there.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#13
Thank you for the update! I don't see anything happening when I try to convert from Curvy to Unity. Are the steps different than doing Unity to Curvy?
Reply
#14
You are welcome.
Steps should be the same, except of course setting the conversion type from "Unity To Curvy" to "Curvy To Unity".
Do you have any errors in the console or the asset's Messages window? (Window->Converter->Messages)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#15
Where do I change the conversion type? I am not getting any messages in the console or converter messages window.
Reply
#16
First open the Converter overlay

[Image: d5d4deea-c910-461c-ac75-d94b20bddd36.webp]


Then click on the conversion type selector

[Image: 7cea0c1b-d460-4bb0-b69c-fb1156f80de6.webp]


Did this help?
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
  Twisting Splines ZiggZagg 6 11 05-14-2024, 04:48 PM
Last Post: _Aka_
  Help with procedural roads and splines ramiroflores 1 6 05-07-2024, 08:57 AM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: