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 /
  • Help Room /
avatar image
0
Question by awesomedata · Feb 06, 2017 at 11:27 PM · editorscalingvisualization

Drawing a cube volume at a particular start/end point - best approach?

I want to create a realtime updated selection visualization in the form of a 3D cube volume to partition sections of the world defined by mouse click to set start point+drag to set size. The mouse handling is done, however the visualization part is what is causing me trouble. Essentially, I need to draw a 3D cube volume (w/an arbitrary height on the y axis) stretched between 2 corner points across the x/z axis, drawn with the mouse (from a top-down perspective).

I'm currently scaling a cube to try to simulate this effect, but the problem is the cube is stretching from its center point instead of the corners of the click/drag operation.

I apologize if this is ridiculously easy to do, but math (even in its simplest form) is not my strong point, and even if it was, I don't want to have to deal with the Unity quirks of constantly offsetting the position of the default cube while I scale it with my mouse if I can avoid it. Is there an easier way to setup the visualization of the cube volume, such as simply drawing a basic cube from a start/end corners directly, kind of like a gizmo?

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
1
Best Answer

Answer by awesomedata · Feb 07, 2017 at 10:14 PM

Sucks nobody could point me in the right direction on this... I don't mind answering my own question, but I would have thought there would be more knowledgeable people out there willing to share a few moments... :(


Anyway, for those like me looking for the right way to go about something like this, it turns out that using procedural meshes works great for stuff like this.

If you're new to procedural meshes, to start with, remember to use the "meshFilter.sharedMesh" instead of the "meshFilter.mesh" to display your new mesh in the scene view when the game is NOT running, otherwise you'll get leaks. Also, be sure to create a new mesh first, otherwise you'll end up replacing the mesh on the meshFilter or simply get a null value.

To get something like what I was after, you draw a few faces, then simply offset all the individual vertices on those faces however you need to.

When you're done defining everything, you call this stuff:

         mesh.vertices = vertices;
         mesh.normals = normals;
         mesh.uv = uvs;
         mesh.triangles = triangles;
 
         mesh.RecalculateBounds();
         mesh.Optimize();

When that's done, you're good to go, as your mesh filter will update automagically with your new verts, triangles, normals, etc., and your mesh will represent their new settings!

Procedural meshes -- demystified. :)

Comment
Add comment · Show 1 · 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 notaspyaraceku · Apr 30, 2021 at 06:07 PM 0
Share

This is 4 years later, but Thank you!! :)

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

90 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

Related Questions

Have to remake PolygonCollider2D after changing sprite 0 Answers

Canvas is scaling in the editor but not in the build 1 Answer

Hierarchy disappears in Unity 5.2 from 4.6.8 1 Answer

How to save a two-dimensional array, as part of the variable inspector? 0 Answers

Change 3rd person controller jump 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