Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 hotovec · Jul 24, 2010 at 12:05 AM · camerameshrendererlinefacing

Mesh line renderer - line segments camera align

I have simple line renderer, that create line as mesh. That generate separated line segments (line segment = 1 quad = 2 triangle faces). The inputs are two Vector3 points.

Here is part of code which generates verticies for final segment mesh:

Vector3[] MakeQuad(Vector3 s, Vector3 e, float w) { // s ... start point // e ... endpoint // w ... width of line segment w = w / 2; Vector3[] q = new Vector3[4];

 Vector3 n = Vector3.Cross(s, e);
 Vector3 l = Vector3.Cross(n, e-s);

 l.Normalize();

 q[0] = transform.InverseTransformPoint(s + l * w);
 q[1] = transform.InverseTransformPoint(s + l * -w);
 q[2] = transform.InverseTransformPoint(e + l * w);
 q[3] = transform.InverseTransformPoint(e + l * -w);

 // here need rotate short sides of segment and align vericies
 // parallel with camera.Up (billboarding)


 return q;

}

I need generate q[0..3] to be rotated facing to camera (like particle billboarding). I need some mesh modifier, that provide calculation. I need rotate verticies on left side of the line according to start point and rotate them. The right side verticies must be rotatet around end point.

Anchor point are start ponint and endpoint. I know there will be some perspective distortion, but will be better than native Line Renderer .

I cant use LookAt and similar functions, becouse that functions rotate whole object. I cant use that becouse need to align every single segment of line.

I need help with rotation of verticies, becouse Im not math guru. Can anybody help me?

Comment
Add comment · Show 1
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 Aram-Azhari · May 17, 2013 at 03:01 PM 0
Share

I've been looking for this very quad generation for days. Thank you.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by hotovec · Jul 30, 2010 at 03:29 PM

Solved myself. Simply add camera reference to the class

public Camera cam;

and here is final method:

Vector3[] MakeQuad(Vector3 s, Vector3 e, float w) { w = w / 2; Vector3[] q = new Vector3[4];

 //standard normal based on points
 //Vector3 n = Vector3.Cross(s, e);
 //Vector3 l = Vector3.Cross(n, e-s);

 //camera forward based normal
 Vector3 l = Vector3.Cross(cam.transform.forward, e-s);

 l.Normalize();
 q[0] = transform.InverseTransformPoint(s + l * w );
 q[1] = transform.InverseTransformPoint(s + l * -w);
 q[2] = transform.InverseTransformPoint(e + l * w);
 q[3] = transform.InverseTransformPoint(e + l * -w);

 return q;

}

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

1 Person is following this question.

avatar image

Related Questions

GameObject invisible at certain camera angles 0 Answers

how to turn of the mesh renderer when the player isn't looking 3 Answers

Mesh Goes Invisible At Particular Angles 1 Answer

Passing Underneath Section of a Mesh 0 Answers

Camera distance from mesh not center 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