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 /
avatar image
0
Question by newborne · Jul 29, 2012 at 04:59 PM · textureuvtileoffsetset

change uv of a plane so it takes a portion of texture

Hi!

I want to make 3x3 table with nine pieces, with one big texture so that all pieces share the same texture but every piece to have its portion displayed, like a puzzle.

i tried with tiling and offset of the material. here is what i have found: -texture is inverted (making tiling x and y = -1 fixes orientation) -setting tile x = -0.33 and y = -0.33 shows upper right third of the texture -setting offset x = 1.33 sets texture to upper left piece..

i know there is a rule for programming this, i want to generalize so it works for more pieces.

any help appreciated! thans!

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
4
Best Answer

Answer by ScroodgeM · Jul 29, 2012 at 05:32 PM

if your texture contains 3x3 fragments then:

  • set tiling to x=0.3333 y=0.3333 - this will crop one fragment only

  • set offset to x=0 or 0.3333 or 0.6666, y=0 or 0.3333 or 0.6666 for fragment you need

if you need to turn fragment, you can make negative tiling settings, but more correct will be to change mapping or object orientation. to save some unneeded drawcalls, use geometry UV sets instead of material's settings

bonus: MeshGeneratorPlanes3x3.cs

attach this script to any gameObject and assign a material you want to split to 3x3 tiles. after running game you'll got 9 separated tiles with same material

using UnityEngine;
using System.Collections;
public class MeshGeneratorPlanes3x3 : MonoBehaviour
{
    public Material TileSet;
    void Start()
    {
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                GameObject tile = new GameObject();
                MeshFilter mf = tile.AddComponent<MeshFilter>();
                MeshRenderer mr = tile.AddComponent<MeshRenderer>();
                tile.name = string.Format("tile_x{0}_y{1}", x, y);
                mr.material = TileSet;
                Mesh mesh = new Mesh();
                mesh.vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, 0f), new Vector3(+0.5f, -0.5f, 0f), new Vector3(-0.5f, +0.5f, 0f), new Vector3(+0.5f, +0.5f, 0f) };
                mesh.normals = new Vector3[] { new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 1f) };
                float th=1f/3f;
                Vector2 tileOffset = new Vector2((float)x, (float)y) * th;
                mesh.uv = new Vector2[] { new Vector2(0f, 0f) + tileOffset, new Vector2(th, 0f) + tileOffset, new Vector2(0f, th) + tileOffset, new Vector2(th, th) + tileOffset };
                mesh.triangles = new int[] { 0,1,2,1,3,2 };
                mf.mesh = mesh;
                tile.transform.position = tileOffset * 4f;
            }
        }
    }
}

alt text


bouns.jpg (49.2 kB)
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 newborne · Jul 29, 2012 at 06:16 PM 0
Share

ok, i would if i knew how to access uv sets i used simple plane.

avatar image ScroodgeM · Jul 29, 2012 at 06:51 PM 0
Share

you spent your first wish. see answer.

avatar image newborne · Jul 30, 2012 at 01:50 PM 0
Share

thanks! i managed to adopt this to my needs and learn a lot in the process! thank you again

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Rpg maker XP Tiles (2D Tile System) 2 Answers

Assigning UV Map to model at runtime 0 Answers

How can I create a UV move tool? 1 Answer

Tile and offset a Texture2D? 2 Answers

Remove annoying texture offset on custom mesh 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