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
0
Question by ina · Dec 29, 2010 at 07:25 AM · proceduralverticescoordinatesnormalradius

Finding Radius or Scale from Mesh Vertices Data

I am having trouble visualizing how the vertices relate to quantitative aspects of the geometry of the sphere or object it defines (such as radius, localscale, world coordinates, etc) @ http://unity3d.com/support/documentation/ScriptReference/Mesh.html.

Here is the snippet from the manual:

function Update () { var mesh : Mesh = GetComponent(MeshFilter).mesh; var vertices : Vector3[] = mesh.vertices; var normals : Vector3[] = mesh.normals;

 for (var i = 0; i < vertices.Length; i++)
     vertices[i] += normals[i] * Mathf.Sin(Time.time);

 mesh.vertices = vertices;

}

I understand that this is applying a sinusoidal transformation on the sphere (or other object that it's in). Basically, the object would start at whatever its preset scale is, and then get bigger, and back to the same size again, etc. It would be nice if Unity Inspector could track the instantaneous radius of this procedural manipuulation, but it seems to only track the actual localScale of the sphere, rather than the new scale created by vertices.

How do you track the radius or world coordinate dimensions of a shape given only vertices, like in the example above?


From geometry, I have an idea of how to do this, but it is very expensive in terms of computation - basically collide a plane with the sphere (crossing origin), and the intersection will be the instantaneous circle and fetch the radius from circumference c = 2 \pi r - is there a more direct way to get these quantities from vertices?

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
0

Answer by Jesse Anders · Dec 29, 2010 at 08:29 PM

It would be nice if Unity Inspector could track the instantaneous radius of this procedural manipuulation, but it seems to only track the actual localScale of the sphere, rather than the new scale created by vertices.

You're confusing scale with mesh geometry. The local scale of a game object is completely separate from any geometry associated with it or with the bounds of that geometry, so there's no reason that the former should reflect the latter.

What it sounds like you're looking for is the bounds of the mesh geometry itself. If you need that information, the Mesh class has a function (IIRC) that will recompute the bounds given the current state of the geometry. If you call this function after changing the vertex positions, the bounds should then reflect the updated positions. (There may be some expense involved in recomputing the bounds frequently, but you'll probably just have to factor that in.)

Unity represents the bounds using a box, I think. You can derive a bounding sphere from this box, but if you need a more optimal bounding sphere, you may have to compute it yourself. Computing an approximate bounding sphere is pretty straightforward; computing an optimal or near-optimal bounding sphere isn't necessarily as straightforward. In either case though, it shouldn't require an intersection test (like you described in your post).

Comment
Add comment · Show 2 · 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 HarvesteR · Apr 05, 2011 at 10:10 PM 0
Share

It's not so much that they're unrelated, it's that the object's Transform (translation, rotation, scale) are ABOVE the mesh itself...

vertices in unity are but an array of vectors defining their positions in local space. that is before any transform is applied to them. So, by itself, the mesh doesn't really know much about it's own bounds in world-space.

You can calculate the actual size of an object, though, by going like this:

GetComponent($$anonymous$$eshFilter).shared$$anonymous$$esh.bounds.size * transform.localScale

this way you can get the actual size of your mesh.

Cheers

avatar image Jesse Anders · Apr 05, 2011 at 10:40 PM 0
Share

Hm, this was a while ago! Anyway, you said 'it's not so much that they're unrelated', but then went on to articulate exactly what I meant when I said they're unrelated :) So, it seems we're in agreement, more or less ;)

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

No one has followed this question yet.

Related Questions

Procedural Mesh Generation - Split Arrays into sections 1 Answer

Procedural cube code 0 Answers

Procedural heightmap shader - Normals and tangents 0 Answers

Modifying a procedural mesh using Lists is slow, what else can I use? 1 Answer

Creating a mesh out of a linerenderer - how do you convert revolved vertices set to triangles and uv's 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