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 bpears · Mar 06, 2016 at 11:19 PM · meshinstancecombinemeshes

change pivot after Mesh.CombineMeshes?

How can I change pivot and delete instances after Mesh.CombineMeshes? I want the pivot to be set by a specific position from another object, which will get the mesh assigned to it in its mesh filter.

Comment
Add comment · Show 3
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 Teravisor · Mar 08, 2016 at 12:02 AM 0
Share

If I understand correctly, to change pivot you'd need to move all vertices of resulting mesh by difference of current pivot and pivot you want. You might want to call Combine$$anonymous$$eshes from mesh that already has pivot point you would need for performance.

By delete instances you mean delete $$anonymous$$eshes that were combined? Then you just call Destroy(...) on them. $$anonymous$$ake sure they are not used anywhere before doing it.

avatar image bpears Teravisor · Mar 08, 2016 at 12:40 AM 0
Share

When I combine the meshes the pivot is way wrong. Both the assigned mesh and the meshes that are instantiated have no parent. Im not sure how I should be setting up this part of the documentation in this case, note that this isnt like my code but it is what I am following:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof($$anonymous$$eshFilter))]
 [RequireComponent(typeof($$anonymous$$eshRenderer))]
 public class ExampleClass : $$anonymous$$onoBehaviour {
     void Start() {
         $$anonymous$$eshFilter[] meshFilters = GetComponentsInChildren<$$anonymous$$eshFilter>();
         CombineInstance[] combine = new CombineInstance[meshFilters.Length];
         int i = 0;
         while (i < meshFilters.Length) {


             combine[i].mesh = meshFilters[i].shared$$anonymous$$esh;//should I use shared mesh or just mesh if I am selectively combining instances?


             combine[i].transform = meshFilters[i].transform.localToWorld$$anonymous$$atrix;//would you still use this in cases where there is no parent object? And is there a way here to change the pivot to a specific Vector3?


             meshFilters[i].gameObject.active = false;
             i++;
         }
         transform.GetComponent<$$anonymous$$eshFilter>().mesh = new $$anonymous$$esh();
         transform.GetComponent<$$anonymous$$eshFilter>().mesh.Combine$$anonymous$$eshes(combine);
         transform.gameObject.active = true;
     }
 }


I am using priciples behind this, to try to offset and move the instance so that it ends up where it was to begin with.

     void Start() {
         mf = GetComponent<$$anonymous$$eshFilter>();
         origVerts = mf.mesh.vertices;
         newVerts = new Vector3[origVerts.Length];
     }
     void Update() {
         Quaternion rotation = Quaternion.Euler(eulerAngles.x, eulerAngles.y, eulerAngles.z);
         $$anonymous$$atrix4x4 m = $$anonymous$$atrix4x4.TRS(translation, rotation, scale);
         int i = 0;
         while (i < origVerts.Length) {
             newVerts[i] = m.$$anonymous$$ultiplyPoint3x4(origVerts[i]);
 //but ins$$anonymous$$d just doing like newVerts[i] += offset
             i++;
         }
         mf.mesh.vertices = newVerts;
     }


But I'm not quite sure how I should be calculating the offset to get it back where it needs to be.

avatar image Teravisor bpears · Mar 09, 2016 at 08:13 AM 0
Share

$$anonymous$$esh.Combine$$anonymous$$eshes applies supplied matrix to coresponding mesh's vertex(it takes only those it needs from sub$$anonymous$$esh you've specified) and writes them into $$anonymous$$esh that called that method.

So, if object that renders resulting mesh is in point (1,0,0) and you add mesh into $$anonymous$$esh.Combine$$anonymous$$eshes using Transform.localToWorld$$anonymous$$atrix of Transform with position (0,0,1) then your resulting vertex positions will be offset by (1,0,1) from (0,0,0) in world space or (0,0,1) from basis of mesh you write to. In that case if initially vertice is (0,1,0) then its ending position will be (1,1,1) in world space or (0,1,1) in local(mesh) space.

If you use that method on objects with different initial position, rotation and scale and need to keep vertex positions in world space (like static batching), you should supply combiningInto.transform.worldToLocal$$anonymous$$atrix*combiningThis.transform.localToWorld$$anonymous$$atrix; as matrix where combiningInto is the GameObject that you will assign mesh to, combiningThis is GameObject which mesh you take into combine.

And as for how much to offset, that depends on what exactly you want. As you're applying rotation and scale too, it's most likely not as simple as "+=offset", you would need to use matrices to move point properly.

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

39 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

Related Questions

skinned mesh renderer, combine meshes can't see the result, what am I doing wrong/ missing? 0 Answers

CombineMeshes doesnt combine properly 0 Answers

Need Help with Dynamically Building a Mesh 0 Answers

Does using the same Mesh variable for multiple Mesh Filters take up more memory? 1 Answer

CombineMeshes Error on Run-time Meshes 2 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