Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 inmotionvr · Jun 10, 2011 at 07:41 AM · textureterrainchangeterraindataselect

How to change texture on parts of terrain

We are developing a game in which we have a terrain. And in that terrain we have natural borders like a small creek and a road. Essentially dividing the map into various areas/parts. On these areas we have characters. Small areas may only have one character, larger areas have 2 or 3 characters. Now we are searching for the best way to be able to select one of the ground areas and change the texture of that area. In the end, the player can have a terrain with different types of ground, depending on what they want.

Because of the ease of editing a terrain in Unity itself we would love to use that tool. But we can only see how this can be done by using an external model with separate meshes for the different ground parts. But this makes editing the terrain a lot less flexible.

Any thoughts on what would be the best way to tackle this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by save · Jun 10, 2011 at 11:25 AM

Vertex paint is coming to Unity in a near future. http://lesterbanks.com/2011/03/vertex-color-painting-directly-in-unity-3d/

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 inmotionvr · Jun 10, 2011 at 12:56 PM 0
Share

That looks very promising. I couldn't make up from the post if this means it will be accessible from code. And if you can detect (through a vertex ID perhaps) what the user clicked. In my game I need an easy way to detect if you have clicked sand, grass, rock, mud etc.

The idea is that you can click a muddy area, and then have the option to upgrade it to grass for example.

avatar image save · Jun 10, 2011 at 02:25 PM 1
Share

Sounds like a cool feature in your game. I'm not sure either if it's realtime "reversible", that would be neat. You could check out this question to see if the answer fit your needs: http://answers.unity3d.com/questions/124670/need-a-clever-idea-for-deter$$anonymous$$ing-collision-surfa.html

If not then perhaps you could use decals or a projector camera + trigger areas.

avatar image inmotionvr · Jun 10, 2011 at 03:16 PM 0
Share

Thanks for the link. They discuss some of they ideas I also have in $$anonymous$$d. But it seems there is no quick way to achieve it. Currently I am thinking about cutting up the terrain mesh in several parts. And simply tagging the separate meshes. Detecting the tag of the mesh underneath the cursor and changing the material on it accordingly.

But the idea of using a projector camera might also work. Will certainly check that out.

avatar image
0

Answer by pietothemax · Jun 10, 2011 at 07:48 AM

I am looking for help on the same thing are you wanting to change the texture live in game?

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 inmotionvr · Jun 10, 2011 at 11:17 AM 0
Share

Yes. And I have looked into using decals of some sort. But that is not accurate enough. It would be fantastic if there is some way to vertex paint the terrain with different colors/ID's so that, when clicked, you can make out on what part of the terrain was clicked. And that you can set the texture for it. And that the texture would nicely fade at edges so it mixes with the surrounding texture.

avatar image
0

Answer by Owen-Reynolds · Jun 10, 2011 at 04:19 PM

This is how to lookup a terrain texture. Most of the work is converting the world position to the indexes in the terrain texture map. To set instead, build TerrCntrl[1,1,4], set TerrCntrl[0,0,texNum] and use SetAlphaMaps, in TerrainData, in the Unity manual:

 // public so we can see them in the Inspector and double-check:
 public Vector3 TS; // terrain grid-space size
 public Vector2 AS; // control texture size

 TS = Terrain.activeTerrain.terrainData.size;
 AS.x = Terrain.activeTerrain.terrainData.alphamapWidth;
 AS.y = Terrain.activeTerrain.terrainData.alphamapHeight;

 // World position of what I'm looking up is puffPos:
 // get (AX, AY) indexes into terrain array:
 int AX = (int)((puffPos.x/TS.x)*AS.x+0.5f);
 int AY = (int)((puffPos.z/TS.z)*AS.y+0.5f);
 // Get the (1 by 1 by #terrainTextures) array of texture weights at our position:
 float[,,] TerrCntrl = Terrain.activeTerrain.terrainData.GetAlphamaps(AX, AY,1 ,1);
 // NOTE: say there are 5 terrain textures. the last slot of TC goes from 0-4 and
 //       TC[0,0, 0-4] add to 1

 // In my case, I wanted the 5th terrain texture:
 float c1=TerrCntrl[0,0,4];
 if(c1>0.5f) // standing on grass
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I use SetAlphamaps and apply texture to the rail? 0 Answers

animating terrain texture question 1 Answer

Terrain.SetAlphamaps Question 1 Answer

change terrain texture and tree at runtime 1 Answer

Changing the color/look of a grass textures/grass. Making it look clean. 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