Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Frame-Matt · Jul 10, 2020 at 05:58 PM · terrain generationmesh manipulationmesh-deformationbrush

How to use Animation Curves, to evaluate distance across a given radius?

Hellow~

I have this code that is working as I expected to terraform my terrain mesh.

Now recently I found out that I can use Animation Curve to cover for the operation I'm doing in InfluenceFromDist() in a more flexible manner (given Animation Curves customizable properties in the editor), so i'm in a quest to integrate those into my MorphTerrain() but so far I can't manage to make it work... unless i'm missing something important, please check the three comments below modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity * InfluenceFromDist (dist);.

I was wondering if someone can share some insight on this matter.

     // Gets influx within picel diameter, in a 0 to 1 range.
     private float InfluenceFromDist (float _dist)
     {
         return (brushRadius / (brushRadius - (brushRadius * brushHardness))) - (_dist / (brushRadius - 
         (brushRadius * brushHardness)));
     }
 
     // Used to raise and depress terrain
     private void MorphTerrain (Vector3 _selectedPoint, bool _raises)
     {
         Vector3 adaptedSelection = _selectedPoint;
         adaptedSelection.y = 0.0f;
 
         for (int i = 0; i < modifiedVerts.Length; i++)
         {
             Vector3 adaptedPoint = modifiedVerts[i];
             adaptedPoint.y = 0.0f;
 
             var dist = Vector3.Distance(adaptedPoint, adaptedSelection);
 
             if (dist <= brushRadius)
             {
                 modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity * 
                 InfluenceFromDist (dist);

                 // Attemps
                 //modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * brushIntensity * 
                 brushTypes.BrushSelected(curBrushType).Evaluate(dist);
                 //modifiedVerts[i] += (_raises ? Vector3.up : Vector3.down) * 
                  brushTypes.BrushSelected(curBrushType).Evaluate(brushIntensity);
                 //brushTypes.BrushSelected(curBrushType).Evaluate(modifiedVerts[i].y);
                 modifiedVerts[i].y = Mathf.Clamp (modifiedVerts[i].y, worldGen.sowl.worldDepth, 
                 worldGen.sowl.worldHeight);
             }
         }



Also, here is my brushTypes struc, if needed.

 public struct Brushes
 {
     public enum BrushTypesForSelection { LINEAL, CURVED, 
     INVERSEDCURVED, FLAT }
     public BrushTypesForSelection selectedBrush;
 
     public AnimationCurve lineal;
     public AnimationCurve curved;
     public AnimationCurve curvedInv;
     public AnimationCurve flat;
 
 
     public AnimationCurve BrushSelected (BrushTypesForSelection _brushType)
     {
         selectedBrush = _brushType;
 
         switch (selectedBrush)
         {
             case BrushTypesForSelection.LINEAL:
                 return lineal;
             case BrushTypesForSelection.CURVED:
                 return curved;
             case BrushTypesForSelection.INVERSEDCURVED:
                 return curvedInv;
             case BrushTypesForSelection.FLAT:
                 return flat;
         }
 
         return null;
     }
 }

I assign curBrushType from Canvas UI options.

Cheers~

*Sorry for any grammars, non-english speaker here.. ;3!

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

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

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

Related Questions

I need help in "stretching an object like rubber" in Unity3D 0 Answers

How can we get mesh vertices position which has been deformed by the shader graph? 1 Answer

I need your help to make procedural floating islands! 0 Answers

Are there any good 2D prefab brushes? 0 Answers

How to increase the performance of terrain generation? Unity 2017.2.0f3 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