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 user1337 · Nov 11, 2012 at 05:39 AM · meshboundspivot

Imported mesh bounds size is alwasy too big and pivot point is not aligned

Hi,

I'm having a bit of difficulty with importing custom meshes to Unity. I"m trying to create a custom mesh with vertices being drawn in screen coordinates. I've created an OBJ file with the stored mesh vertices and imported that into Unity and attached it to a game object. The mesh appears correctly however the mesh/render bounds are far too big and my pivot point is off in space somewhere and not connected to the mesh.

After some reading Ive become aware that Unity has a limitation with being able to change the pivot point of a mesh. I've tried offsets but because I have different meshes/sizes this wont work every time.

I'm wondering if someone knows why Unity draws the mesh a certain size (visually) but the entire game object size is so much bigger? This is making it difficult for me to draw the mesh at the appropriate space. Does anyone have any ideas?

EDIT: I've been able to offset the pivot point using the mesh bounds however, now the problem seems that the bounds are actually bigger than the mesh itself. I've drawn a debug line from the bounds min/max points and it appears that the line is in 3d space going through the center of the mesh (extending into Z).

Is there anyway to create a 2D mesh in unity? simply a plane that always faces towards the camera and whose bounds reflect the mesh vertices instead of some world points? I'm working in 2D and so far have found Unity quite difficult to work with on account of trying to convert everything from 3D to a 2D application of it.

Thanks

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 phodges · Nov 11, 2012 at 08:05 AM 0
Share

Setting up sprites is not so difficult. How is your camera set up? I'm assu$$anonymous$$g an orthographic setup, but your requirements may differ.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Fattie · Nov 11, 2012 at 09:18 AM

Firstly I'm not sure if you should be doing anything at all with meshes in relation to what you're trying to achieve, see below. But re your specific question, two possibilities come to mind (A) a stray vert (B) recalculating the bounds.

"The mesh appears correctly however the mesh/render bounds are far too big"

are you ABSOLUTELY SURE you do not have any stray verts? one will do it, an easy mistake to make! use this simple technique:

http://answers.unity3d.com/questions/307429/simply-display-or-highlight-empty-game-objects-in.html

to run through your vertices array and draw a big red ball at every single one. you'll soon see if there's an error.

(PS if you are new to working w/ mesh in unity is always worth remembering that the .vertices call CREATES A COPY of the verts, in distinction from all other properties in Unity.

http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html http://docs.unity3d.com/Documentation/ScriptReference/Mesh-vertices.html

 function showAllMyBallsClearly()
     {
     var copyOfVerts : Vector3[] = GetComponent(MeshFilter).mesh;
 
     for (var i = 0; i < copyOfVerts.Length; i++)
       .. draw a ball there
     }

also...

did you know about this function,

http://docs.unity3d.com/Documentation/ScriptReference/Mesh.RecalculateBounds.html

maybe that's the secret here.

regarding 2D ...

you ask a separate question about 2D. Realistically for 2D in Unity you need to grab "2DToolkit" (asset store)

there;s no other realistic way to do 2D in Unity -- the time saving is staggering. you just drop all your sprites in the 2DTK system, and it completely handles everything for you, from packing atlases to completely handling "flat meshes" as you say, to animations, to doing everything in one draw call.

Comment
Add comment · Show 4 · 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 user1337 · Nov 12, 2012 at 08:24 PM 0
Share

Fattie,

Thanks a lot for the reply.

I'm actually using 2Dtoolkit but what I"m trying to do is not simply render a sprite to the screen. I actually am trying to render custom sized meshes for nav purposes. I'm using a tool that outputs the verts in screen coordinates so that is why I am using the screenToWorldPoint function to convert the vertices of the raw mesh I've imported as an asset. I also wasn't aware that calling the mesh.vertices property duplicates it, so thanks for that, I've made a temp variable ins$$anonymous$$d of calling it in the loop.

I've also implemented your idea of using the Gizmo balls to adorn the vertices and it works great! there aren't any stray verts but still something seems off.

Here is where I'm at:

alt text

I've drawn the mesh in blue for visibility purposes.

The yellow balls are the Gizmos that mark the mesh verts. The red rectangle is supposed a cube drawn around the mesh collider using:

 Gizmos.DrawWireCube(mc.bounds.center, mc.bounds.size)

And the pink line is a debug line drawn from mesh collider's $$anonymous$$ to max points.

As you can see the line is drawn right through the center of the mesh to the bounding box's corners. I was under the impression that the mesh collider was suposed to be exact to the shape of the mesh itself, but here it shows up as equivalent to a box collider. Is there something that I'm missing about how mesh colliders work?

Thanks

untitled.png (74.4 kB)
avatar image Fattie user1337 · Nov 12, 2012 at 08:29 PM 0
Share

hola! it's very possible you have not actually set the mesh collider! it's separate from the render mesh.

SECONDLY -- just TBC, you are aware that bounding boxes IN FACT WOR$$anonymous$$ LI$$anonymous$$E THAT. they are like a $$anonymous$$/max ON THE NATURAL AXIS of the universe.

check out AABB bounding box examples on the internet

(sorry if you know all this already - it's impossible to know if someone's a 70 yr old expert or a new chum on this site)

what do you mean by the "mesh collider's $$anonymous$$ to max points" what call are you using there?

hopefuly these quick notes bring a solution, if not more tomorrow!!!! :)

I'm exceptionally proud you were able to use two of my mentions! :)

avatar image user1337 user1337 · Nov 20, 2012 at 09:23 PM 0
Share

Thanks for the information. I've been playing around a bit more and reading the documentaion and it clarified a few things. It seems I was confused between the actual mesh bounds and the bounding box. the mesh collider/renderer seems to detect the "actual" bounds of the mesh; that is the blue polygon. But the rectangle and the $$anonymous$$/max points are drawn I'm guessing to the AABB bounds.

Regardless I've managed to get the offset and pivot point correct using the mesh vertices and I can detect the correct bounds of the actual polygon mesh so it seems to be working. I haven't been able to finalize my solution as of yet but I'm getting close. I've closed out the question however as it has been answered; thanks for all the help.

avatar image Fattie · Nov 17, 2012 at 07:08 AM 0
Share

hola @user1337

is there something else you need on this?

could you CLOSE OUT the questin please .. TIC$$anonymous$$ any useful answer Cheees

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

11 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

Related Questions

Bounds of dynamic mesh not updating 1 Answer

Constraining GameObject Movement Inside a Mesh Volume 0 Answers

Unity View frustum giving me issues 4 Answers

not working- GameObject.GetComponent(MeshFilter).mesh; 1 Answer

Problem with checking for intersection between two rotated objects 3 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