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 dorpeleg · Jun 16, 2014 at 02:24 PM · meshverticescustom editorhandlesmesh-deformation

Handles does not modify mesh...

Hello everyone,

I'm trying to make a simple custom editor so I'm able to modify a mesh.

Here's the code:

 [CustomEditor(typeof(MeshFilter))]
 public class MeshEditor : Editor
 {
     private MeshFilter _meshF;
     private Mesh _mesh;
     private GameObject _obj;
 
     private Vector3 meshPos;
 
     void Awake()
     {
         _meshF = (MeshFilter)target;
         _obj = _meshF.gameObject;
         _mesh = _meshF.sharedMesh;
         meshPos = _obj.transform.TransformPoint(_mesh.vertices[0]);
     }
 
     void OnSceneGUI()
     {
         Handles.Label(_obj.transform.position + Vector3.up * 2, "Verts: " + _mesh.vertexCount + " Tris: " + _mesh.triangles.Length);
 
         //for (var i = 0; i < mesh.vertexCount; i++)
         //{
         //    mesh.vertices[i] = Handles.PositionHandle(obj.transform.TransformPoint(mesh.vertices[i]), Quaternion.identity);
         //}
 
         meshPos = Handles.PositionHandle(meshPos, Quaternion.identity);
 
         if (GUI.changed)
         {
             _mesh.vertices[0] = meshPos;
             EditorUtility.SetDirty(target);
         }
     }
 }

I can move the handle but the mesh is not changing... any ideas?

Thanks

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 Aram-Azhari · Jun 22, 2014 at 06:16 AM

I have asked the exact question in the forums. My answer according to Here:

Update the whole vertex array instead just updating an element of it.

So add

 private Vector3[] _verts;

In Awake() add:

 _verts = _mesh.vertices;

And in OnSceneGUI() modify the line:

 _mesh.vertices[0] = meshPos;

to

 _verts[0] = meshPos;
 _mesh.vertices = verts;


:)

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 dorpeleg · Jun 22, 2014 at 08:28 AM 0
Share

Thanks! works like a charm.

I'm having another issue tho, maybe you can help me.

It seems that the vert positions are effected by my objects position in a weird way.

If the object's position is at (0,0,0) then it works perfectly, but but if the position is different, the mesh jumps off as soon as i move any of the handles.

Any ideas?

avatar image AlucardJay · Jun 22, 2014 at 01:54 PM 2
Share

You'll need to use Transform.TransformPoint and Transform.InverseTransformPoint to find the vertex position in world space, modify it, then convert back to local space

avatar image dorpeleg · Jun 25, 2014 at 09:30 AM 0
Share

Thanks @alucardj.

I've managed to solve both position and scaling issues I had.

But now I'm facing an issue that is beyond my math skills.

It is basically the same issue like in position and scale.

If the value is not 0, the vertices are being added the value.

For example: if my starting rotation is 45, my object jumps so its now 90.

So I need to somehow inverse the rotation, but quaternions is something I'm clueless about.

Any help will be appreciated.

avatar image dorpeleg · Jun 25, 2014 at 12:47 PM 0
Share

@alucardj, looks like InverseTransformPoint fixes the rotation too.

I solved it differently before seeing your answer, but then decided to check your suggestion.

  • from me :)

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

22 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

Related Questions

Flattening a mesh by deforming it 0 Answers

How do you bend a cylindrical gameobject? 1 Answer

Mesh deformation simulating a fire 0 Answers

Mesh Deformation 2 Answers

Expanding mesh animation 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