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 Noam · Sep 20, 2010 at 02:16 PM · meshgraphicsimportfbx

Change mesh translation for future placements

Hi,

I have an object that I imported with several meshes. Some of them have nontrivial translations, and I would like to bake those translations in. The code I wrote was this :

private static void NormalizeMesh(MeshFilter mf) { Transform transform = mf.transform; if (transform.localPosition != Vector3.zero || transform.localRotation != Quaternion.identity || transform.localScale != Vector3.one) { Vector3[] vertices = mf.sharedMesh.vertices; Vector3[] normals = mf.sharedMesh.normals; for (int i = 0; i < mf.sharedMesh.vertexCount; i++) { vertices[i] = transform.TransformPoint(vertices[i]); normals[i] = transform.TransformDirection(normals[i]); //Tangents? UVs? }

         mf.sharedMesh.vertices = vertices;
         mf.sharedMesh.normals = normals;
         mf.transform.localPosition = Vector3.zero;
         mf.transform.localRotation = Quaternion.identity;
         mf.transform.localScale = Vector3.one;
     }

I want to be able to do this only once per mesh, and that the next time that I add the object to the scene hierarchy it will already be fixed. The code that I wrote takes care of the mesh for good, but it only takes care of the translation for the instance that I added. This is because the sharedMesh gets saved back to the model, but the changes to the mesh filter don't get changed - the next time I will add the model, the vertices will be baked but the transform will remain the original one.

Is there a way to modify the mesh's transform for future insertions into the scene?

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

2 Replies

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

Answer by Paulius-Liekis · Sep 21, 2010 at 07:12 AM

Call your function in AssetPostprocessor.OnPostprocessModel and modify the shared mesh.

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 Noam · Oct 03, 2010 at 01:24 PM 0
Share

This sounds useful. Where is this documented?

avatar image Paulius-Liekis · Oct 18, 2010 at 02:51 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/AssetPostprocessor.html

avatar image
0

Answer by StephanK · Sep 20, 2010 at 04:06 PM

You could save it as a prefab at the end of your script.

Comment
Add comment · Show 1 · 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 Noam · Sep 21, 2010 at 11:08 AM 0
Share

The problem with that is that it is still possible to add the normalized mesh with the un-zeroed transformed afterwards, and the script will run again and transform the already transformed vertices.

If what I want to do is impossible, I'll try to solve the issue in the exporting software ins$$anonymous$$d.

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

Apply materials to imported meshes 0 Answers

Assigning imported mesh from script 1 Answer

Terrain detail meshes have wrong orientation 0 Answers

"Mesh indices out of range" when using ObjExporter 0 Answers

FBX import scale factor issue 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