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
1
Question by rhaak17 · May 24, 2018 at 02:28 PM · texturemeshcutout

How to apply a png texture to a selfmade mesh?

Hello everybody,

I am currently working at a project where I have to cut out some form from a rectangle, by pressing down a certain button and draw any form I want to cut out. I have added a picture where you can see it, maybe it get's more clear seeing the picture.
I split the rectangle with the corresponding hole inside and the cutted out piece in two different gameobjects by using an algorithm I found in the internet, which works well.
But when I want to apply a texture it comes to problems; If I apply the texture to the 'normal'/'uncutted' object, all is fine. But when I apply such a texture to a cutted out piece or the rectangle with the hole inside, it only changes it's color, but the texture is not correctly applied.

I am not sure what the problem is, do I have to do something like UV-remapping ? And how ? In the second picture you can see the shaded wireframe of the meshes, I want to apply the texture to.
Thanks for your help!

alt text alt text

cutout.png (337.0 kB)
triangles.png (520.9 kB)
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
2
Best Answer

Answer by Bunny83 · May 24, 2018 at 03:06 PM

Yes, you have to define UV coordinates for each of your vertex. There are several ways to accomplish this. Some are easier some are a bit more difficult. The easier methods depend on certain pre-knowledge of the original object. The other method is a more general approach which should work with potentially any mesh.


First of all if you use a MeshCollider on your original mesh and using a Raycast against that collider you already get the interpolated UV coordinate of the hit point. This would be the simplest general approach. We don't know how you "draw" your shape in the first place but i guess you already use raycasting?


The second general approach would be to determine the triangle as well as baricentric coordinate of each vertex position within the triangle of the original mesh. Once you have that you can simply use the baricentric coordinate to interpolate the UV of the 3 corners of the triangle to get the UV at a given point.


The more straight forward solutions require certain conditions of the original mesh. If you have your new vertex coordinates in local space of the object and the original rectangle is perfectly aligned with two local axis, you can simply divide the vertex coordinate by the size of the mesh to get the interpolcated UV coordinate. Though for this you have to know where the origin of the local space is (in one of the corners of the rectangle or the center) and how large the rectangle is in local space. All this information is missing from your question so it would be pointless to show an example for one way if it doesn't apply to your case.


If you need further help, provide more details about how you do the "drawing" and how the original mesh is defined.

Comment
Add comment · Show 2 · 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 Bunny83 · May 24, 2018 at 03:48 PM 0
Share

For reference over here i posted a 2d cartesian coordinate to barycentriic conversion, and here's a 3d version.


I've packed this all together into a custom struct on the wiki which should simplfy the usage.

avatar image rhaak17 · May 24, 2018 at 05:18 PM 0
Share

At first - thank you really much for your detailed answer, I really appreciate it!

I think the first approach will work for me, because I define the form of the cutted out piece in form of a List with the raycast hit points.

But when reading your answer I noticed that I should get to know a bit more about meshes, uv-mapping, textures etc. in general before implementing something..

I think with a better understanding of the topic in general, combined with your answer I'll be able to find a solution which works for me.

Thanks for your help!

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

118 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

Related Questions

Layered Textures/Materials 0 Answers

How to texture an irregular (hexagon) shape (mesh) ? 1 Answer

How to confirm the vertex of a mesh that mouse in and change its texture 0 Answers

rendering hollow mesh ? 0 Answers

Texture layers on single mesh 1 Answer


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