Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by master1114 · Jan 13, 2020 at 02:27 PM · meshmeshescurvebezierroads

Filling the space between bezier curves with a texture,

I want to dynamically draw 2D road segments in Unity with scripts. Each segment is defined by 4 points and the required control points to draw bezier curves. This means a segments outer shape consists of 2 "ends" wich are just simple lines, and 2 bezier curves.

I am using this https://github.com/dbrizov/NaughtyBezierCurves to create the bezier curves. This results into an outer shape of a segment like this:

outer shape

Creating the outer shape of a segment is pretty simple. Now I want to fill the segment with a texture. I dont know how I can create planes or a mesh with the same shape as the outer shape of the segment. This is what I want to achive: alt text I first thought about going along the bezier curves and creating slim splanes all along the curve, but this would lead to overlapping or gaps between them. Plus, I dont know how to orient the planes towards the other curve.

Maybe someone has a simple solution how I can add a texture to the road with a script.

,

bezier.png (12.6 kB)
bezier2.png (13.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by landings · Jan 13, 2020 at 04:22 PM

alt text

Discretize your curves into two point lists. Build the mesh like this (Not tested but should not be too wrong):

 // Discretize the curves
 // You have verticesOnCurve1[n] and verticesOnCurve2[n]
 // float width is your road's width
 
 //// Vertices ////
 List<Vector3> vertexBuffer = new List<Vector3>();
 for (int i = 0; i < n; i++) {
     vertexBuffer.Add(verticesOnCurve1[i]); // Top points
 }
 for (int i = 0; i < n; i++) {
     vertexBuffer.Add(verticesOnCurve2[i]); // Bottom points
 }
 
 //// Indices ////
 List<int> indexBuffer = new List<int>();
 for (int i = 0; i < n - 1; i++) {
     indexBuffer.Add(i);
     indexBuffer.Add(i + 1);
     indexBuffer.Add(n + i);
     indexBuffer.Add(n + i);
     indexBuffer.Add(i + 1);
     indexBuffer.Add(n + i + 1);
 }
 
 //// UVs ////
 List<float> pointMileages = new List<float>(); // Mileages are calculated from the top curve
 pointMileages.Add(0); // Starting point
 for (int i = 1; i < n; i++) {
     var distance = (verticesOnCurve1[i] - verticesOnCurve1[i - 1]).magnitude;
     pointMileages.Add(pointMileages[i - 1] + distance); // Other points
 }
 List<Vector2> uvs = new List<Vector2>();
 for (int i = 0; i < n; i++) {
     uvs.Add(new Vector2(pointMileages[i] / width, 0)); // Top points
 }
 for (int i = 0; i < n; i++) {
     uvs.Add(new Vector2(pointMileages[i] / width, 1)); // Bottom points
 }



ddd.png (22.4 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Curving a cuboid mesh 1 Answer

Curve vertex array 1 Answer

What would be a good mesh designer for Windows? 3 Answers

Triangulation Problems 1 Answer

Missing/Replaced Unity default mesh Assets? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges