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
4
Question by code-blep · Aug 24, 2013 at 04:12 PM · meshruntimeresizevectrosity

Change size of Mesh at runtime

Hi,

I've spent the last few hours trying to see if there is a way to change the size of a mesh at runtime. Changing the transform scale is not an option for what I am trying to achieve (I am trying to fix a small Vectrosity issue). I can't seem to find anyway of doing this. Any pointers would be most welcome at this stage!

Thanks!

Comment
Add comment · Show 11
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 robertbu · Aug 24, 2013 at 04:19 PM 0
Share

I'm not sure what you are asking here. You can modify the vertices of the mesh directly. But if Transform.localScale does not solve the issue, I'm not sure how modifying the mesh will help.

avatar image meat5000 ♦ · Aug 24, 2013 at 04:21 PM 1
Share

Check the Procedural Examples Tutorial on the asset store

avatar image code-blep · Aug 24, 2013 at 04:22 PM 0
Share

Here is a link to the problem discussion robertbu: http://forum.unity3d.com/threads/49941-Vectrosity-fast-and-easy-line-drawing/page101?p=1337945&posted=1#post1338289

I am starting to wonder if I have grabbed the wrong end of the stick ;)

avatar image code-blep · Aug 24, 2013 at 04:29 PM 0
Share

Ahhh, Thanks meat5000, very interesting got it working with a modified version of crumpled mesh! For anyone else:

 #pragma strict
 
 // This script is placed in public domain. The author takes no responsibility for any possible harm.
 
 var scale = 1.0;
 var recalculateNormals = false;
 
 private var baseVertices : Vector3[];
 
 
 function Update () {
     var mesh : $$anonymous$$esh = GetComponent($$anonymous$$eshFilter).mesh;
     
     if (baseVertices == null)
         baseVertices = mesh.vertices;
         
     var vertices = new Vector3[baseVertices.Length];
     
     for (var i=0;i<vertices.Length;i++)
     {
         var vertex = baseVertices[i];
                 
         vertex.x += scale;
         vertex.y += scale;
         vertex.z += scale;
         
         vertices[i] = vertex;
     }
     
     mesh.vertices = vertices;
     
     if (recalculateNormals)    
         mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }
avatar image meat5000 ♦ · Aug 24, 2013 at 04:38 PM 0
Share

No problem. Glad to point you in the right direction and moreso that you got results!

Show more comments

3 Replies

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

Answer by code-blep · Aug 24, 2013 at 05:31 PM

Fixed Version:

 #pragma strict
 
 // This script is placed in public domain. The author takes no responsibility for any possible harm.
 
 var scale = 1.0;
 var recalculateNormals = false;
 
 private var baseVertices : Vector3[];
 
 
 function Update () {
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
 
     if (baseVertices == null)
        baseVertices = mesh.vertices;
 
     var vertices = new Vector3[baseVertices.Length];
 
     for (var i=0;i<vertices.Length;i++)
     {
     var vertex = baseVertices[i];
     vertex.x = vertex.x * scale;
     vertex.y = vertex.y * scale;
     vertex.z = vertex.z * scale;
 
        vertices[i] = vertex;
     }
 
     mesh.vertices = vertices;
 
     if (recalculateNormals)    
        mesh.RecalculateNormals();
     mesh.RecalculateBounds();
 }
Comment
Add comment · Show 3 · 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 meat5000 ♦ · Aug 24, 2013 at 06:16 PM 1
Share

Up voted for meticulous problem solving when presented with a shred of a lead. Good job.

avatar image code-blep · Aug 24, 2013 at 06:20 PM 1
Share

Ha! Brilliant. Thanks meat5000 ;)

avatar image TonicMind · May 15, 2021 at 02:47 AM -1
Share

Hey this will DESTROY your art. Do not use it. You've been warned.

avatar image
4

Answer by tapticc · Dec 19, 2016 at 06:27 PM

Found this useful thanks, here's a C# version:

public class Scaler : MonoBehaviour {

 public float ScaleX = 1.0f;
 public float ScaleY = 1.0f;
 public float ScaleZ = 1.0f;
 public bool RecalculateNormals = false;

 private Vector3[] _baseVertices;

 public void Update()
 {
     var mesh = GetComponent<MeshFilter>().mesh;

     if (_baseVertices == null)
         _baseVertices = mesh.vertices;

     var vertices = new Vector3[_baseVertices.Length];

     for (var i = 0; i < vertices.Length; i++)
     {
         var vertex = _baseVertices[i];
         vertex.x = vertex.x * ScaleX;
         vertex.y = vertex.y * ScaleY;
         vertex.z = vertex.z * ScaleZ;

         vertices[i] = vertex;
     }

     mesh.vertices = vertices;

     if (RecalculateNormals)
         mesh.RecalculateNormals();

     mesh.RecalculateBounds();
 }

}

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

Answer by Deaymon · Mar 31, 2019 at 10:33 PM

No one seemed to mention the simpler solution, so I thought I may add it just in case: Put the mesh into a child of that GameObject and scale that child's Transform...

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 Sharlatan · Apr 21, 2019 at 06:33 AM 0
Share

Very simple, straight forward and easy as pie! So simple in fact, I might not even have thought about it. But it works like a charm, thanks very much!

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

21 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

Related Questions

Resize single face of a primitive object like a cube 0 Answers

Dynamic mesh positioning with Raycast intersection... 0 Answers

Generated mesh render order 0 Answers

Creating Irregular 2D Shapes in Runtime 0 Answers

disabling Mesh renderer on runtime. 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