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 /
This question was closed Dec 17, 2012 at 08:21 AM by Fattie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by MountDoomTeam · Dec 16, 2012 at 05:13 PM · meshfiltertransformpoint

TransformPoint trouble

I have 2 scripts, one that is added straight to the GameObject to change its mesh,and the same script in a function and it changes the mesh of other game objects. the 2nd code changes the mesh but it seems to ignore the transform.transformpoint function.


This one works:

 private var org = Vector3.zero; 
 var basescale =3;
 //var currentobject = gameObject;
 
 private var vtxArray : Vector3[];
 var radius = 100;
 var transition = 50;
 
 function Start () {
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     var scale = basescale;
     if (vtxArray == null)
         vtxArray = mesh.vertices;
     var objectscale = (gameObject.transform.localScale);
             
     var vertices = new Vector3[vtxArray.Length];
     for (var i=0;i<vertices.Length;i++)
     {
         //var vertex = vtxArray[i];
         vtxArray[i] =  transform.TransformPoint(vtxArray[i]);
         var vertex = vtxArray[i];
         var dist = Vector3.Distance(org, vtxArray[i]);//lines that set mutation in a bubble and smooth edges
         if (  dist > radius ){ scale = 0*basescale;} 
         if (  dist <= radius && dist >= radius-transition) {scale = ((radius-dist)/transition)*basescale;} 
         if (  dist < radius-transition ){ scale = 1*basescale;} 
         vertex.x += Mathf.Sin(vtxArray[i].y*.1 + vtxArray[i].z*.1) * scale;
         vertex.y += Mathf.Sin(vtxArray[i].z*.1 + vtxArray[i].x*.1) * scale;
         vertex.z += Mathf.Sin(vtxArray[i].x*.1 + vtxArray[i].y*.1) * scale;
 
         vertices[i] = transform.InverseTransformPoint(vertex);
         //Debug.Log (vtxArray[i]);
     }
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     DestroyImmediate(collider);
     gameObject.AddComponent("MeshCollider");
     //gameObject.GetComponent(MeshCollider).sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
 }


this one doesn't work:

 function  sinus1  ( multiplier:int  ){//this function takes mesh objects and changes their vertices in XY and Z into mountains
 
         //var process  : Collider[] = Physics.OverlapSphere(selzone.transform.position, selzone.transform.localScale*1.1;);    
     var mymeshfilters : MeshFilter[] = FindObjectsOfType(MeshFilter) as MeshFilter[];
 
     for (var mymeshfilter in mymeshfilters) {
         var mydistance = Vector3.Distance(selzone.transform.position, mymeshfilter.transform.position);
         //print( mydistance );
         if ( mydistance  < selzone.transform.localScale.x * .5 && mydistance!= 0){ 
         //mymeshfilter.gameObject.AddComponent ("noisemesh");
         
     var org = selzone.transform.position; 
     var basescale =3;
     //var currentobject = gameObject;
 
     var vtxArray : Vector3[];
     var radius = transform.localScale.x * .5;
     var transition = transform.localScale.x * .25;
 
         
     var mesh : Mesh = mymeshfilter.mesh;
 print(  mesh.vertices.length );
     var scale = basescale;
     if (vtxArray == null)
         vtxArray = mesh.vertices;
     var objectscale = (gameObject.transform.localScale);
             
     var vertices = new Vector3[vtxArray.Length];
     for (var i=0;i<vertices.Length;i++)
     {
         //var vertex = vtxArray[i];
         vtxArray[i] =  transform.TransformPoint(vtxArray[i]);
         var vertex = vtxArray[i];
         var dist = Vector3.Distance(org, vtxArray[i]);//lines that set mutation in a bubble and smooth edges
         if (  dist > radius ){ scale = 0*basescale;} 
         if (  dist <= radius && dist >= radius-transition) {scale = ((radius-dist)/transition)*basescale;} 
         if (  dist < radius-transition ){ scale = 1*basescale;} 
         vertex.x += Mathf.Sin(vtxArray[i].y*.1 + vtxArray[i].z*.1) * scale;
         vertex.y += Mathf.Sin(vtxArray[i].z*.1 + vtxArray[i].x*.1) * scale;
         vertex.z += Mathf.Sin(vtxArray[i].x*.1 + vtxArray[i].y*.1) * scale;
 
         vertices[i] = transform.InverseTransformPoint(vertex);
         //Debug.Log (vtxArray[i]);
     }
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     DestroyImmediate(collider);
     gameObject.AddComponent("MeshCollider");
     //gameObject.GetComponent(MeshCollider).sharedMesh = gameObject.GetComponent(MeshFilter).mesh;
         }
     }
 }
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

  • Sort: 
avatar image
0

Answer by MountDoomTeam · Dec 17, 2012 at 04:21 AM

  vertices[i] = transform.InverseTransformPoint(vertex);
  vertices[i] = transform.TransformPoint(vertex);

the above 2 lines have the error, I didn't specify from what objects to calculate the transform point, if I am messing with a 3rd party GameObject I should be writing

  vertices[i] = 3rdpartyobject.transform.InverseTransformPoint(vertex);
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

Follow this Question

Answers Answers and Comments

10 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

Related Questions

MeshFilter, World & Local Coordinates and InverseTransformPoint() 9 Answers

Transform coordinates to local space with quaternion 1 Answer

How can I modify the mesh in OnPostprocessModel? 2 Answers

'mesh' is not a member of UnityEngine.Component - Explicit Typecasting for Android 1 Answer

Is there any way to reset the default meshes? 3 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