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
0
Question by douglasg14b · Apr 27, 2015 at 03:52 PM · meshmaterialprocedural meshuv mapping

Whats causing this weird texture stretching on my mesh?

Making this mesh via code and the texture seems to only tile on the sides, but not on the top. Any idea whats going on? alt text alt text

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System;
  
 public class CoreMeshCreator : MonoBehaviour
 {
     //Initialization
     public void Start()
     {
         MeshFilter meshFilter = this.GetComponent<MeshFilter>();
         MeshCollider meshCollider = this.GetComponent<MeshCollider>();
         Mesh mesh = new Mesh();
         meshFilter.mesh = Generate();
         meshCollider.sharedMesh = meshFilter.mesh;
     }
  
     public Mesh Generate()
     {
         Mesh mesh = new Mesh();
         float sqrt = (Mathf.Sqrt(3) / 2);
  
         Vector3 v0 = new Vector3(0, -1, 0);
         Vector3 v1 = new Vector3(-4, -1, 0);
         Vector3 v2 = new Vector3(-5, -1, sqrt * 2);
         Vector3 v3 = new Vector3(-4, -1, sqrt * 4);
         Vector3 v4 = new Vector3(-2, -1, sqrt * 4);
         Vector3 v5 = new Vector3(-1, -1, sqrt * 6);
         Vector3 v6 = new Vector3(1, -1, sqrt * 6);
         Vector3 v7 = new Vector3(2, -1, sqrt * 4);
         Vector3 v8 = new Vector3(4, -1, sqrt * 4);
         Vector3 v9 = new Vector3(5, -1, sqrt * 2);
         Vector3 v10 = new Vector3(4, -1, 0);
         Vector3 v11 = new Vector3(5, -1, -sqrt * 2);
         Vector3 v12 = new Vector3(4, -1, -sqrt * 4);
         Vector3 v13 = new Vector3(2, -1, -sqrt * 4);
         Vector3 v14 = new Vector3(1, -1, -sqrt * 6);
         Vector3 v15 = new Vector3(-1, -1, -sqrt * 6);
         Vector3 v16 = new Vector3(-2, -1, -sqrt * 4);
         Vector3 v17 = new Vector3(-4, -1, -sqrt * 4);
         Vector3 v18 = new Vector3(-5, -1, -sqrt * 2);
         Vector3 v19 = new Vector3(-4, 1, 0);
         Vector3 v20 = new Vector3(-5, 1, sqrt*2);
         Vector3 v21 = new Vector3(-4, 1, sqrt*4);
         Vector3 v22 = new Vector3(-2, 1, sqrt * 4);
         Vector3 v23 = new Vector3(-1, 1, sqrt * 6);
         Vector3 v24 = new Vector3(1, 1, sqrt * 6);
         Vector3 v25 = new Vector3(2, 1, sqrt * 4);
         Vector3 v26 = new Vector3(4, 1, sqrt * 4);
         Vector3 v27 = new Vector3(5, 1, sqrt * 2);
         Vector3 v28 = new Vector3(4, 1, 0);
         Vector3 v29 = new Vector3(5, 1, -sqrt * 2);
         Vector3 v30 = new Vector3(4, 1, -sqrt * 4);
         Vector3 v31 = new Vector3(2, 1, -sqrt * 4);
         Vector3 v32 = new Vector3(1, 1, -sqrt * 6);
         Vector3 v33 = new Vector3(-1, 1, -sqrt * 6);
         Vector3 v34 = new Vector3(-2, 1, -sqrt * 4);
         Vector3 v35 = new Vector3(-4, 1, -sqrt * 4);
         Vector3 v36 = new Vector3(-5, 1, -sqrt * 2);
         Vector3 v37 = new Vector3(0, 1, 0);
  
         mesh.vertices = new Vector3[]
         {
             v0,
             v1, v2,
             v3, v4,
             v5, v6,
             v7, v8,
             v9, v10,
             v11, v12,
             v13, v14,
             v15, v16,
             v17, v18,
             v19, v20,
             v21, v22,
             v23, v24,
             v25, v26,
             v27, v28,
             v29, v30,
             v31, v32,
             v33, v34,
             v35, v36,
             v37,
         };
  
         mesh.triangles = new int[]
         {
             //top
             1,0,2,
             2,0,3,
             3,0,4,
             4,0,5,
             5,0,6,
             6,0,7,
             7,0,8,
             8,0,9,
             9,0,10,
             10,0,11,
             11,0,12,
             12,0,13,
             13,0,14,
             14,0,15,
             15,0,16,
             16,0,17,
             17,0,18,
             18,0,1,
             //Bottom
             20,37,19,
             21,37,20,
             22,37,21,
             23,37,22,
             24,37,23,
             25,37,24,
             26,37,25,
             27,37,26,
             28,37,27,
             29,37,28,
             30,37,29,
             31,37,30,
             32,37,31,
             33,37,32,
             34,37,33,
             35,37,34,
             36,37,35,
             19,37,36,
             //Sides
             23,5,6,
             23,6,24,
             24,6,7,
             24,7,25,
             25,7,8,
             25,8,26,
             26,8,9,
             26,9,27,
             9,10,27,
             27,10,28,
             28,10,11,
             28,11,29,
             11,12,29,
             12,30,29,
             13,30,12,
             30,13,31,
             31,13,14,
             31,14,32,
             15,32,14,
             15,33,32,
             33,15,16,
             33,16,34,
             34,16,17,
             34,17,35,
             17,18,35,
             35,18,36,
             18,1,36,
             36,1,19,
             19,1,2,
             19,2,20,
             20,2,3,
             20,3,21,
             21,3,4,
             21,4,22,
             22,4,5,
             22,5,23
         };
  
         mesh.RecalculateNormals();
  
         return 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

· Add your reply
  • Sort: 
avatar image
1

Answer by mikelortega · Apr 27, 2015 at 04:37 PM

You have to set your mesh's UV map. It's an array of Vector2 elements, one for each vertex. The letters U and V go from 0 to 1, they indicate the axes of the texture.

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

20 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

Related Questions

Normal maps not applying to certain faces of a mesh 2 Answers

Generate mesh based on 3d array. 1 Answer

How to combine several Materials into one? 0 Answers

Can I Assign Different Material To Each Quad In A Mesh? 1 Answer

Merging faces without effecting texture mapping 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