Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tcz8 · Oct 18, 2018 at 04:22 PM · transformskinnedmeshrenderermesh verticesinversetransformpointvertice manipulation

Why is transform.InverseTransformPoint().y offset?

I have this (BAD) code :

 // Were all Skin Mesh Renderers are located (only one is enabled)
 public GameObject meshContainer;
 
 // Get the enabled Skin Mesh Renderer
 SkinnedMeshRenderer skinnedRenderer = meshContainer.GetComponentInChildren<SkinnedMeshRenderer>(false);
 
 public void TestMethod(Vector3 worldPoint) {
     Mesh staticMesh = new Mesh();
     skinnedRenderer.BakeMesh(staticMesh);
     Vector3[] vertices = staticMesh.vertices;
     Vector3 localPoint = transform.InverseTransformPoint(worldPoint);
     Debug.Log(worldPoint + " " + localPoint);
     for (i = 0; i < vertices.Length; i++) {
         DebugExtension.DebugWireSphere(vertices[i], Color.blue, 0.01f, 120, true);
     }
 }


FYI: DebugExtension is a free asset on the store that allows drawing additional debugging gizmos like Debug.Draw. I use it to draw the vertices from the "baked" mesh above and the weird thing is they are drawn at the right X,Z location but Y is bellow the ground!

I checked the hierarchy of the object and everthing is at (0, 0, 0) except the root gameobject which is very near (0, 1.934751e-17, 0) and the scales are all at (1, 1, 1).

Im really lost here, why are the vertices offset like that?

The goal of this is to find which vertex is near the impact position so I can modify their vertex color.

Thank you for any hint, help or trace of a solution you can provide!

Comment
Add comment · Show 5
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 tcz8 · Oct 20, 2018 at 09:52 PM 0
Share

I got this working but since I'm still not 100% sure what is going on I'm not making this an answer.

$$anonymous$$y code is called during FixedUpdate (makes sense since a collision is initiating it) also we are using a full body I$$anonymous$$ solution for hit reactions that may have some play in what is happening.

Whatever the case is, I fixed it with this line:

 localPoint.y = localPoint.y + transform.localPosition.y



The baked mesh's vertices are still underground if drawn as is but with the adjustment everything lines up right at runtime.

avatar image Bunny83 · Oct 20, 2018 at 10:12 PM 0
Share

Sorry but your question is too confusing any is missing some parts in between your snippets. What does the mesh and the skinned mesh renderer has to do with all this? The transform has no relation to the mesh. The transform represents a coordinate space. Note that you use the transform of the object where this script is attached to and not the transform of the object with the skinned mesh renderer (unless they are actually the same). So it's not really clear which local space you're actually using.


$$anonymous$$aybe there is some sort of rotation applied? Are you sure your gizmo mode is local (and not global) and also pivot (and not center)?

avatar image tcz8 Bunny83 · Oct 21, 2018 at 03:50 AM 0
Share

You are absolutely right, I was really confused hahaha. I modified the question above to better reflect what is going on.

I had several issues at the same time, the drifting Y value has been fixed and was my bad but the Y value of the baked mesh is still offset by - transform.localPosition.y is this normal? If I draw the mesh without baking it sits happily above ground. Same code. It's not caused by the gizmos. There are no rotation applied besides whatever the animation clip is doing.

avatar image Bunny83 tcz8 · Oct 23, 2018 at 09:21 AM 0
Share

If you are sure that your local position is offset by transform.localPosition that you just use the wrong transform. That means your local point is actually relative to the parent of your transform. However It's not clear how you actually deter$$anonymous$$e which position is the correct position. For example the wirespheres that you render are rendered in worldspace with localspace positions since the vertices of the mesh are in local space. So those will most likely not represent your actual vertex positions.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

92 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 avatar image avatar image

Related Questions

Find mesh top - Keep gameobject on top of a mesh 0 Answers

Extrapolating float values from Perlin noise? 1 Answer

if I rotate an object, do they vertices of its mesh change? 1 Answer

Imported cube vertex count different than expected 1 Answer

how to decrease vertices number of a sprite 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