• 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
Question by Kaz_Yamof · May 21, 2014 at 04:20 PM · line drawingwireframeborders

Draw borders cube

Hi I need to draw the borders of a cube/rectangle, as a wireframe. But I don't want to draw the lines forming a triangle, just the borders. Any ideias?

Comment

People who like this

0 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 robertbu · May 21, 2014 at 04:21 PM 0
Share

When run in the editor or does it have to work for a build? What line drawing solution were you doing to use?

avatar image Kaz_Yamof · May 21, 2014 at 04:33 PM 0
Share

Run: I need to draw when run in game, not editor. Solution: anything that works. GL, LineRenderer... But with Unity free.

4 Replies

  • Sort: 
avatar image
Best Answer

Answer by Kaz_Yamof · May 22, 2014 at 04:48 PM

Thanks @Cherno, I will take a look at this later.

I solved using the BoundBox script at the asset store. It's free, and use GL too.

Thanks everybody.

Comment
samana1407

People who like this

1 Show 0 · 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
avatar image

Answer by robertbu · May 21, 2014 at 04:35 PM

There is a answer that draws the bounds using Debug.DrawLine(). Substitute your favorite line drawing solution:

http://answers.unity3d.com/questions/461588/drawing-a-bounding-box-similar-to-box-collider.html

Comment

People who like this

0 Show 0 · 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
avatar image

Answer by Kaz_Yamof · May 21, 2014 at 04:49 PM

Actually I already tried this solution. Works perfectly in editor, but I didn't figure out how to convert this to GL. Here my attempt:

 //Attached to objects (cubes) 
 public class ShowMeshBounds : MonoBehaviour
 {
     private Vector3 v3FrontTopLeft;
     private Vector3 v3FrontTopRight;
     private Vector3 v3FrontBottomLeft;
     private Vector3 v3FrontBottomRight;
     private Vector3 v3BackTopLeft;
     private Vector3 v3BackTopRight;
     private Vector3 v3BackBottomLeft;
     private Vector3 v3BackBottomRight;
 
     private Vector3[] list = null;
 
 
     void Update()
     {
         CalcPositons();
     }
 
     void CalcPositons()
     {            
         if (list == null)
         {
             list = new Vector3[24];
 
             Bounds bounds;
             BoxCollider bc = GetComponent<BoxCollider>();
             if (bc != null)
                 bounds = bc.bounds;
             else
                 return;
 
             Vector3 v3Center = bounds.center;
             Vector3 v3Extents = bounds.extents;
 
             v3FrontTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  
             v3FrontTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  
             v3FrontBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  
             v3FrontBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);                  v3BackTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top left corner
             v3BackTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  
             v3BackBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  
             v3BackBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  
   
             list[0] = (v3FrontTopLeft);
             list[1] = (v3FrontTopRight);   
             list[2] = (v3FrontTopRight);
             list[3] = (v3FrontBottomRight);    
             list[4] = (v3FrontBottomRight);
             list[5] = (v3FrontBottomLeft);
             list[6] = (v3FrontBottomLeft);
             list[7] = (v3FrontTopLeft);
             list[8] = (v3BackTopLeft);
             list[9] = (v3BackTopRight);
             list[10] = (v3BackTopRight);
             list[11] = (v3BackBottomRight);
             list[12] = (v3BackBottomRight);
             list[13] = (v3BackBottomLeft);
             list[14] = (v3BackBottomLeft);
             list[15] = (v3BackTopLeft);
             list[16] = (v3FrontTopLeft);
             list[17] = (v3BackTopLeft);    
             list[18] = (v3FrontTopRight);
             list[19] = (v3BackTopRight);
             list[20] = (v3FrontBottomRight);
             list[21] = (v3BackBottomRight);
             list[22] = (v3FrontBottomLeft);
             list[23] = (v3BackBottomLeft);
             Camera.mainCamera.GetComponent<DrawLineBounds>().cubes.Add(list);
         }
     }
 }

 //Attached to Camera main
     public class DrawLineBounds : MonoBehaviour
     {
         public List<Vector3[]> cubes = new List<Vector3[]>();
         void OnPostRender()
         {
             GL.PushMatrix();
             GL.Begin(GL.LINES);
             GL.Color(Color.blue);
                 foreach (Vector3[] lista in cubes)
             {            
                 for (int i = 1; i < lista.Length; i++)
                 {
                     GL.Vertex(lista[i - 1]);
                     GL.Vertex(lista[i]);
                 }
             }
             GL.End();
             GL.PopMatrix();
         }
     }
Comment

People who like this

0 Show 3 · 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
avatar image Kaz_Yamof · May 21, 2014 at 04:53 PM 0
Share

I try to manage a list of Vector3[] on camera main, every cube sending his 'vertices' to there, and rendering that list of vectors 3 with GL lines.

avatar image robertbu · May 21, 2014 at 08:50 PM 0
Share

I have little experience with GL. Early on I purchased Vectorosity and use it for all my line drawing.

avatar image Kaz_Yamof · May 22, 2014 at 05:22 PM 0
Share

Vectrosity is really amazing, but I need to use free resources... For my own learning...

avatar image

Answer by Cherno · May 22, 2014 at 03:43 AM

There is a nice grid-drawing script here on Answers, I used it myself with some customizing. You can use it to draw a whole 3d grid, 2d grid, single slice of a 3d grid, or even a single cube, you just need to dive into the code and change the coordinates :)

http://answers.unity3d.com/questions/482128/draw-grid-lines-in-game-view.html

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

how can i build a spherical wireframe grid in unity? 1 Answer

Missing shaded wireframe option in unity 2019.1.3f,shaded wireframe not showing(LWRP) unity 2019.1.3f 1 Answer

Is there any option to put objects together? 0 Answers

Convert Line Render to 3d Mesh with Collider 0 Answers

How to fix skybox lines? 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