Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by alexander11 · Sep 11, 2016 at 02:17 AM · c#unity 5mesh3dline

How do i use lines to calculate triangles on mesh??

Hello i would like to know how to code these two things to my catmull code(which is below).

(1). How would i be able to draw lines like this in Pic1(SEG1), and then using those calculations than create a mesh like in Pic1(SEG2), would anyone know how to do do this?

  • -Pic1 alt text


(2). How do i create calculate a point in the center and draw lines to it(and around the circle) like in Pic2(SEG1), then also using those calculations than to create a mesh like in Pic2(SEG2), would anyone know how to do do this?

  • -Pic2 alt text


    Here is my catmull code.

    using UnityEngine; using System.Collections; using System.Collections.Generic;

    [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class CatmullSpline : MonoBehaviour {

       public List<Transform> controlPointsList = new List<Transform>();
     
         public bool isLooping = true;
     
         public int SEGMENT_COUNT;
     
         void OnDrawGizmos()
         {
             for (int i = 0; i < controlPointsList.Count; i++)
             {
     
                 if ((i == 0 || i == controlPointsList.Count - 2 || i == controlPointsList.Count - 1) && !isLooping)
                 {
                     continue;
                 }
     
                 DisplayCatmullRomSpline(i);
             }
             Gizmos.color = Color.white;
     
             for (int i = 0; i < controlPointsList.Count; i++)
             {
                 Gizmos.DrawWireSphere(controlPointsList[i].position, 0.3f);
             }
         }
         Vector3 ReturnCatmullRom(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
         {
             Vector3 a = 0.5f * (2f * p1);
             Vector3 b = 0.5f * (p2 - p0);
             Vector3 c = 0.5f * (2f * p0 - 5f * p1 + 4f * p2 - p3);
             Vector3 d = 0.5f * (-p0 + 3f * p1 - 3f * p2 + p3);
     
             Vector3 pos = a + (b * t) + (c * t * t) + (d * t * t * t);
     
             return pos;
         }
     
         void DisplayCatmullRomSpline(int pos)
         {
     
             Vector3 p0 = controlPointsList[ClampListPos(pos - 1)].position;
             Vector3 p1 = controlPointsList[pos].position;
             Vector3 p2 = controlPointsList[ClampListPos(pos + 1)].position;
             Vector3 p3 = controlPointsList[ClampListPos(pos + 2)].position;
     
             Vector3 lastPos = Vector3.zero;
     
     
             for (float i = 0; i < SEGMENT_COUNT; i++)
             {
                 float t = (float)i / SEGMENT_COUNT;
     
                 Vector3 newPos = ReturnCatmullRom(t, p0, p1, p2, p3);
     
                 if (t == 0)
                 {
                     lastPos = newPos;
                     continue;
                 }
     
                 Gizmos.color = Color.white;
                 Gizmos.DrawLine(lastPos, newPos);
     
                 Gizmos.color = Color.yellow;
                 var tan = ReturnCatmullRomTangent(t, p0, p1, p2, p3);
                 Gizmos.DrawLine(newPos, newPos + tan * 3);
                 Gizmos.DrawSphere(newPos, 0.3f);
                 lastPos = newPos;
             }
     
             Gizmos.DrawLine(lastPos, p2);
         }
     
     
         int ClampListPos(int pos)
         {
             if (pos < 0)
             {
                 pos = controlPointsList.Count - 1;
             }
     
             if (pos > controlPointsList.Count)
             {
                 pos = 1;
             }
             else if (pos > controlPointsList.Count - 1)
             {
                 pos = 0;
             }
     
             return pos;
         }
         public Vector3 ReturnCatmullRomTangent(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
         {
             Vector3 b = 0.5f * (p2 - p0);
             Vector3 c = (2f * p0 - 5f * p1 + 4f * p2 - p3);
             Vector3 d = 1.5f * (-p0 + 3f * p1 - 3f * p2 + p3);
             Vector3 tangent = b + c * t + d * t * t;
             return tangent.normalized;
         }
     }
     
    
      
    
    
    
capture83.png (103.2 kB)
capture84.png (113.2 kB)
Comment
Add comment · Show 2
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
avatar image b1gry4n · Sep 11, 2016 at 02:22 AM 0
Share

the center point would be just taking the position of all the points and getting the average. as for the zig-zag approach youll have to figure out an algorithm that works with your code to reference the nodes you want. You wouldnt create the "lines" or edges of the triangles, youll have to look in to mesh creation tutorials. The best I know of (easy to understand and thoroughly explained) is here: http://catlikecoding.com/unity/tutorials/procedural-grid/

avatar image alexander11 b1gry4n · Sep 11, 2016 at 02:58 AM 0
Share

Well @b1gr4yn i implemented the things in but i am getting an error NullReferenceException: Object reference not set to an instance of an object

Here is what i have done.

catmullSpline.cs

new-text-document.txt (4.7 kB)

0 Replies

· Add your reply
  • Sort: 

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

238 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 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

Hiding part of mesh 0 Answers

Can someone please help me with mesh extrusion 0 Answers

How do i calculate mesh on a spline?? 0 Answers

How do i add lines to end Cubes?? 1 Answer

How to add manual generated color ? 0 Answers


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