Jump to content

Customize Generated Road


SkullAndSmile
Go to solution Solved by Clyde,

Recommended Posts

Good Evening, 

I finally finished satisfied and have test driven a number of times, but there is one element that is bothering me. I want to edit the mesh of the road that gets generated. Capture.PNG.79802d0fc741e5994c8d1523396319a3.PNG

Capture1.PNG.aa5689a6f60c09b4caafd9cb37aa67e6.PNGCapture2.PNG.58f1719095c292537c36631c01bb942d.PNG

For this, particular road, I don't want to use Extrusion Pro because the junction for the normal roads looks better than the hard junction that Extrusion Pro produces. But I actually like the mesh for the road that I can configure in extrusion pro much more than the fix road mesh. Is there a way to get the best from both worlds? 😄 

 

Sincerely,

Felix Schmidt

Link to comment
Share on other sites

I don't wish to bump my post, but I would just love to hear if my post is still on the radar. 🙂
Did I just simply miss a feature, or is there currently no way of achieving that result? 

Link to comment
Share on other sites

Currently, there is no interface for changing the cross section that the Road Extension uses, other than the option for 'Use Sloped Cross Section' for a smooth edged cross section.

The code that generates the road mesh can take a cross section, which is not as complicated as the Extrusion Pro cross section.  The road cross section is simply a list of points and a list of normals, which are assumed to be in order of left to right, from -0.5x to 0.5x. 

Without coding up an editor for the simpler cross section for the roads, perhaps a hand edited set of values for the points and normals could be exposed to create a RoadCrossSection (already a public class) from in the Road Extension and passed down to the road mesh creation code.  We could add an 'advanced cross section' option that exposes 2 lists of Vector2's to allow for entering the cross section information.  It would not be elegant, but would be workable for advanced users.

This is what the default road cross section is defined as.

        private static readonly Vector2[] _standardRoadCrossSectionPoints = new Vector2[]
        {
            new Vector2(-0.5f, -0.02f),
            new Vector2(-0.5f, 0.015f),
            new Vector2(-0.49f, 0.025f),
            new Vector2(-0.38f, 0.025f),
            new Vector2(0.38f, 0.025f),
            new Vector2(0.49f, 0.025f),
            new Vector2(0.5f, 0.015f),
            new Vector2(0.5f, -0.02f)
        };
        private static readonly Vector2[] _standardRoadCrossSectionNormals = new Vector2[]
        {
            new Vector2(-1.0f, 0.0f),
            new Vector2(-0.707f, 0.707f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.707f, 0.707f),
            new Vector2(1.0f, 0.0f)
          };
 

What do you think about that?

Link to comment
Share on other sites

It would be really help to customize that part. For the arrays of points and normals, that would work fine. Just to make sure that I understood you correct, I could override these by writing my own editor or hard-code an array in the editor and set these and in the build and play mode it would use my collection of vectors and not the default once? 

That would sounds like a good workaround and would help me a lot :). 

Link to comment
Share on other sites

Yes, you undestand correctly.

Perhaps I could allow you to create a RoadCrossSection instance in a component to just add to the spline and it would use that one.

I'll find out when I can be allotted time to get that done.  I'm currently knee deep in another project.

Link to comment
Share on other sites

@SkullAndSmile, something like this should do it:

We will release a new version of GeNa Pro that will support the following scenario:

using UnityEngine;
using GeNa.Core;
public class RoadCrossSectionOverrideExample : RoadCrossSectionOverride
{
    RoadCrossSection roadCrossSection = new RoadCrossSection(_points, _normals);

    private static readonly Vector2[] _points = new Vector2[]
    {
            new Vector2(-0.5f, 0.04f),
            new Vector2(-0.48f, 0.04f),
            new Vector2(-0.47f, 0.026f),
            new Vector2(-0.4f, 0.025f),
            new Vector2(0.4f, 0.025f),
            new Vector2(0.47f, 0.026f),
            new Vector2(0.48f, 0.04f),
            new Vector2(0.5f, 0.04f)
    };
    private static readonly Vector2[] _normals = new Vector2[]
    {
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.707f, 0.707f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f),
            new Vector2(-0.707f, 0.707f),
            new Vector2(0.0f, 1.0f),
            new Vector2(0.0f, 1.0f)
    };


    public override RoadCrossSection GetRoadCrossSection()
    {
        return roadCrossSection;
    }
}

Just place a component derived from RoadCrossSectonOverride into your Road Spline Object.  Be sure to uncheck (disable) "Use Slopped Cross Section".  The number of points/normals must be even.

Note that you will need to modify the spline or some parameter on it or one of it's extensions to cause the road mesh to be rebuilt, then you will see the change.

RoadCrossSectionOverrideExample_01.png

  • Like 1
Link to comment
Share on other sites

  • Solution

One change that I did make at the last minute:
Added an Object field called Cross Section Override to the Road Extension inspector.

So, you will attach your override component to the spline object, and then drag it into that new field.

I did this because some users have attached more than one Road Extension to a single Spline Object.  This allows them to assign, or not, an override to a specific instance of the Road Extension.

Note that you can disregard the comment from my previous comment about changing something on the spline to see changes reflected in the mesh for the override. This is taken care of now.

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Thank you for your time and changes. The patch is not yet available over the asset store, is it? 

I am really looking forward to the changes 🙂

Link to comment
Share on other sites

  • 2 weeks later...

@SkullAndSmile, GeNa Pro v3.3.21 is released.  You can now customize the road cross section, and also separate the Y scale from the width scale.

There is an example  at \Assets\Procedural Worlds\GeNa\Asset Samples\Script Examples\Scripts\RoadCrossSectionOverrideExample.cs.

To see it in action, add this script to the Road Spline, then in the Road Extension, drag the instance to the field "Road Cross Section Override".

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...