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
6
Question by Shujal · Jun 18, 2013 at 07:03 PM · meshflipinsideout

Flip a mesh inside-out?

Basically, I need to have a inside-out cube to use for a cloud skybox overlay. So as we al know, triangles are only rendered on one side. So I thought I could simply flip the tris over, but it didn't seem to work. Here is my script:

using UnityEngine;

using System.Collections;

public class FlipInsideOut: MonoBehaviour {

 public int[] Tris = new int[100];

 int temp;
 
 

 void Start () {

     Tris = this.GetComponent().mesh.triangles;

     for(int i = 0; i < 100; i++){
         if(Tris[3*i] != null){
             temp = Tris[3*i+1];
             Tris[3*i+1] = Tris[3*i+2];
             Tris[3*i+2] = temp;
         }
     }
     
     this.GetComponent().mesh.triangles = Tris;
     
 }
 

}

Does anybody have any idea why it isnt working? I shouldn't see the mesh from the outside. If anybody could help me I'd be very happy.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
13

Answer by Jessy · Jun 18, 2013 at 08:24 PM

Your method should work fine. This is easier:

 using System.Linq;
 
 Mesh mesh = GetComponent<MeshFilter>().mesh;
 mesh.triangles = mesh.triangles.Reverse().ToArray();
Comment
Add comment · Show 6 · 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 mire · Feb 20, 2015 at 03:03 PM 1
Share

This worked perfectly for me, thanks!

avatar image Dune2 · Sep 27, 2016 at 06:20 AM 1
Share

This is beautiful. Anyway to get the geometry saved, so in the Editor it shows flipped?

avatar image maarten_unity795 Dune2 · Nov 30, 2021 at 03:28 PM 0
Share

Instead of triggering it in playmode you use

  [ContextMenu( "Flip" )]
         public void FlipMeshContext ( ) {
             Mesh mesh = GetComponent<MeshFilter>().mesh;
             mesh. triangles = mesh. triangles. Reverse( ). ToArray( );
         }

This will add the "flip" option to the context menu of your script, you can then trigger it without being in playmode.

avatar image SPOOKYBOOGIE · Sep 26, 2018 at 10:49 AM 0
Share

awesome! it works

avatar image davidlannan · Feb 16, 2019 at 10:58 AM 0
Share

This is ok if you are just working with geometry. If you have any UV maps, this will create problems with your uv indexes. Remember a triangle will be indexed like so: TRIANGLE 1 = VERTEXidx1 + UVidx1 and VERTEXidx2 + UVidx2 and VERTEXidx3 and UVidx3 If you rearrange your geometry (vertex list) then you will need to fix your uv list and normal (for faces) as well. https://docs.unity3d.com/ScriptReference/$$anonymous$$esh-triangles.html

avatar image Bunny83 davidlannan · Feb 16, 2019 at 12:55 PM 0
Share

The UVs are actually tied to the vertex and they don't change at all if you flip the triangles. $$anonymous$$eep in $$anonymous$$d that we flip / reverse the index array, not the vertices array. There is only one index array.


Of course the image will actually be mirrored (since you look at it from the other side). However there's no "generally valid" way to "flip the UV" as it highly depends on the topography of the mesh and the UV layout. $$anonymous$$ost unwraps are not symetrically laid out and therefore can't be simply flipped in texture space. Though it probably would work for a cube if all sides are mapped to the whole texture. Though this is not what you would use for a skybox.


Though you are right about the vertex normals and tangents when a lit shader is used. They would need to be flipped as well to get the correct lighting. Though if you use an unlit shader the vertex normals don't matter (the mesh doesn't need to have normals in this case). $$anonymous$$ost skyboxes are unlit or calculate the lighting in a different way. Using vertex or face normals wouldn't make much sense as they often cause visible seems at the edges

avatar image
1

Answer by ExplodingCookie · Jun 18, 2013 at 08:40 PM

There are two ways to render the inside of a cube.

  1. Use the Flip Normals in the modeling application of your choice. (Not sure if the function is universally flip normals) This makes the visible side of the mesh only visible from within the cube

  2. Use a shader that renders both sides of the mesh(exe Toon Shaders and the Particle Shaders)

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

21 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

Related Questions

Is there a cheap way to flip a collider´s normals in real time? 0 Answers

Why does half my model flip when I animate it? 2 Answers

Detail mesh normals sometimes flipped inside. 0 Answers

Can a shader render darkness inside a mesh? 2 Answers

Am I inside a volume? (without colliders) 3 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