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 /
  • Help Room /
avatar image
1
Question by Facu4060 · Nov 28, 2016 at 07:17 PM · meshespivotcentermergeshapes

Object Pivot After Mesh Merge is not centered.

Hi All,

Was wondering why is this happening, here is the case: i've a "mesh combiner" attached to an object, within there're 3 mesh creators (i set faces amount and a width to create different shapes ie: triangles with 3, cube 4, circle 50).

In this example i've 3 meshes with 4 faces forming 3 cubes, so i need to combine their meshes on a single one, to create a "L" shape, here is the code:

     public void combineMeshes() {
         //save old position
         Vector3 transformPosition = gameObject.transform.localPosition;    

        //set it to 0, or transform will be a mess.
         gameObject.transform.localPosition = Vector3.zero;    
         Mesh mesh = GetComponent<MeshFilter>().sharedMesh;

         //clean the mesh.
         if (mesh == null)
         {
             mesh = new Mesh();
         }
         else
         {
             mesh.Clear();
         }
 
         Mesh finalMesh = new Mesh();
 
         MeshFilter[] filters = GetComponentsInChildren<MeshFilter>(true);
 
         CombineInstance[] combInstance = new CombineInstance[filters.Length-1];
 
         for (int i = 0; i < filters.Length; i++)
         {
 
             if (filters[i].sharedMesh != gameObject.GetComponent<MeshFilter>().sharedMesh)
             {
                 combInstance[i-1].subMeshIndex = 0;
                 combInstance[i-1].mesh = filters[i].sharedMesh;
                 combInstance[i-1].transform = filters[i].transform.localToWorldMatrix * transform.worldToLocalMatrix;
             }
         }
         finalMesh.CombineMeshes(combInstance);
         finalMesh.name = "final mesh";
         GetComponent<MeshFilter>().sharedMesh = finalMesh;
         gameObject.transform.localPosition = transformPosition;
     }


here is the thing. the merge is done correctly, also editor reference axis is setted coorectly, BUT when i move the object within the scene there's an offset in the "mesh" pivot that makes me place the object in the wrong position. anyone know what im doing wrong?. Thx!

alt text

somwhere i read to set the object within a new one and use that collider, but the offset is still there... and is a little tricky for future use on my game. Here you can see the collider "centered" and obiously all positions are setted to "0" (selected go, and child go, not shape ones, because they need to be at custom pos to merge them).

holly.jpg (178.8 kB)
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 Facu4060 · Nov 29, 2016 at 04:16 AM

Just figured out my error, was setting position to 0,0,0 to not mess it with matrix conversion, but childs where not positioned with 0,0,0 parent. i was placing them with the "L " figure, somewhere in the worldspace, so when i merged the meshes that pivot was based on childs position, not parent position which make sense.

should place the parent at the center position before mergin.

Comment
Add comment · 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

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

76 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

Related Questions

Y position of objects in Unity 1 Answer

Can I use subtractive shapes? 4 Answers

Imported my model from Blender, now the parts rotate along the wrong points? 2 Answers

Having trouble animating sine wave out of child objects 0 Answers

Merging two Gameobjets into one! 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