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
2
Question by Vidar · Feb 16, 2011 at 01:42 PM · textureterrain

Paint texture on terrain with scripting

Hey Guys,

I have finally accomplished it that i can paint textures on certain places of my terrain at runtime. The Problem is that on the places that i don't want to paint a new texture, must be painted again with the old texture. To make it clearer here is my code:

public class TerrainPaint : MonoBehaviour {

public void Paint () {

 TerrainData td = Terrain.activeTerrain.terrainData;

 float[,,] splatmapData = new float[td.alphamapWidth, td.alphamapHeight, td.alphamapLayers];

 for (int y = 0; y < td.alphamapHeight; y++)
 {
     for (int x = 0; x < td.alphamapWidth; x++)
     {

     float[] tex = getmethatcrapmap(x, y);
     Vector4 splat = new Vector4(tex[0], tex[1], tex[2], tex[3]);

     if(y % 20 == 0)
     {
         splat = new Vector4(1, 0, 0, 0);
     }

     // now assign the values to the correct location in the array
     splat.Normalize();
     splatmapData[x, y, 0] = splat.x;
     splatmapData[x, y, 1] = splat.y;
     splatmapData[x, y, 2] = splat.z;
     splatmapData[x, y, 3] = splat.w;
     }
 }

 // and finally assign the new splatmap to the terrainData:
 td.SetAlphamaps(0, 0, splatmapData);

}

public float[] getmethatcrapmap(int x, int y) {

 TerrainData td = Terrain.activeTerrain.terrainData;
 float[,,] splatmapData = td.GetAlphamaps(y, x, 1, 1);

 float[] cellMix = new float[splatmapData.GetUpperBound(2)+1];

 for(int n=0; n < cellMix.Length; ++n)
 {
     cellMix[n] = splatmapData[0,0,n];
 }

 return cellMix;

}

}

This only places a new texture every 20th x position. Now if i want to paint a texture at ,for example, 50 coordinates, it's I guess a lot of work, if the whole terrain is painted again.

So my question is, is there a way to paint a texture on a certain position without drawing the whole terrain again?

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 Vidar · Feb 16, 2011 at 04:16 PM

ok i've made it^^

is this only happening to me or someone else that sometime after you decide to ask something you come to a solution yourself^^

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 AR_Rizvi · Aug 22, 2013 at 11:34 AM 1
Share

can u show me how u did it because im tryng to do the same thing and in serching i find ur post so can u plz tell ne how u did it it wud b very helpfull

avatar image chubsteroonskii · Dec 28, 2013 at 02:17 AM 0
Share

I am also trying to do the same thing can I see the solution code please?

avatar image MrScrumbles001 · Mar 30, 2014 at 10:41 AM 0
Share

Just going to bump this. If you have a solution can you please share with everyone? Would be a lot of help as I know a lot of people would be interested in seeing how you managed to do it.

Thanks in advance

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to automatically apply different textures on terrain based on height? 5 Answers

How can I automatically place grass and other details on my terrain to correspond with the splatmap? 5 Answers

Positioning textures on terrain 0 Answers

Can i change the Texture of terrain 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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