x


Flip Normals, Unity, Lightwave, spheres

I want to flip the normals on a texture in unity. I have a model and a texture and wish for the texture to be inside the sphere model and not on the outside. I want to create a 360 panoramic effect by moving the camera around the images inside the sphere on top of the flipped texture. Can anyone help with this, I have searched how to flip normals etc and cannot find what I need.

Thanks for any help!

Judith.

more ▼

asked Oct 09, 2012 at 04:07 PM

judith gravatar image

judith
1 1 2 2

Did you manage to flip the normals in Lightwave but that is not coming across when you import to Unity? Or are you asking how to flip the normals in Lightwave?

Oct 09, 2012 at 05:43 PM shaderop
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Flipping normals won't draw on the inside of the sphere. You need to flip the triangle winding of the mesh instead.

//get a reference to the mesh
var mesh : Mesh = GetComponent(MeshFilter).mesh;
//reverse triangle winding
var triangles:int[]=mesh.triangles;
var numpolies : int =triangles.Length / 3;

for(var t=0;t<numpolies;t++)
    {
    var tribuffer : int = triangles[t*3];
    triangles[t*3]=triangles[(t*3)+2];
    triangles[(t*3)+2]=tribuffer;
    }

mesh.triangles=triangles;
more ▼

answered Oct 09, 2012 at 06:22 PM

BPPHarv gravatar image

BPPHarv
61 1

Yes, you're absolutely right. The confusion comes from the fact that most modelling tools (blender, 3ds max, ...) call the winding order "face normal". They show which side a face is looking by drawing a normal vector at the trianges (or quads) center.

The face normal(winding order) has nothing to do with the vertex normals which are used in the shader to shade the object.

Oct 09, 2012 at 07:47 PM Bunny83

I am completely new to this sort of thing, I had a hunch I had to change the normals of the texture as they where on the outside of the sphere instead of inside. I need to have it on inside then get the camera to rotate round creating a panoramic effect.

Essentially, if I apply the code above to the object this will flip the triangles or reverse them?

Is the scripting much different in c#?

Oct 10, 2012 at 11:48 AM judith
(comments are locked)
10|3000 characters needed characters left

Thanks BPPHarv, I condensed that to the following if it helps:

using System.Linq;

using UnityEngine;

public class FlipNormals : MonoBehaviour

{

void Start()
{
    var mesh = (transform.GetComponent("MeshFilter") as MeshFilter).mesh;
    mesh.uv = mesh.uv.Select(o => new Vector2(1 - o.x, o.y)).ToArray();
    mesh.triangles = mesh.triangles.Reverse().ToArray();
    mesh.normals = mesh.normals.Select(o => -o).ToArray();
}

}

more ▼

answered Nov 17, 2013 at 03:14 PM

xavier steele gravatar image

xavier steele
15

(comments are locked)
10|3000 characters needed characters left

I'm new to this whole thing, and I just had a hunch I needed to change the normals, I need to get the texture on the inside of the sphere and from there move my camera around it creating a panoramic effect.

Essentially, can I just use this code posted and add it to the object?...Will there be much difference for c# scripting?

more ▼

answered Oct 10, 2012 at 11:53 AM

judith gravatar image

judith
1 1 2 2

For my own personal interest I banged out this little script. It takes a unity sphere and "turns it inside out" to create an inner projective surface. It's far from perfect but it might get you started. To use it apply it on a sphere sized (by scale) to fit your scene. The panoskyies I use from http://www.cgskies.com will fit the upper portion when the texture uses a 1x 2y tile material setting.

What you would ideally do is search for skydome implementations for Unity3d, there are a few out there both free and pay which will have a much more complete solution for you.

QuickieSkyDome.cs

using UnityEngine; using System.Collections;

public class QuickieSkyDome : MonoBehaviour
{

// Use this for initialization

//This will modify a unity prefab sphere "inside out" for inner surface project
void Start () 
    {
    //get a reference to the mesh
    MeshFilter BaseMeshFilter = transform.GetComponent("MeshFilter") as MeshFilter;
    Mesh mesh = BaseMeshFilter.mesh;

    //reverse triangle winding
    int[] triangles= mesh.triangles;

    int numpolies = triangles.Length / 3;
    for(int t=0;t < numpolies;t++)
        {
        int tribuffer = triangles[t*3];
        triangles[t*3]=triangles[(t*3)+2];
        triangles[(t*3)+2]=tribuffer;
        }

    //readjust uv map for inner sphere projection
    Vector2[] uvs = mesh.uv;
    for(int uvnum = 0;uvnum < uvs.Length;uvnum++)
        {
        uvs[uvnum]=new Vector2(1-uvs[uvnum].x,uvs[uvnum].y);
        }

    //readjust normals for inner sphere projection  
    Vector3[] norms = mesh.normals;        
    for(int normalsnum = 0;normalsnum < norms.Length;normalsnum++)
        {
        norms[normalsnum]=-norms[normalsnum];
        }

    //copy local built in arrays back to the mesh
    mesh.uv = uvs;
    mesh.triangles=triangles;
    mesh.normals=norms;    
    }   
}
Oct 11, 2012 at 07:02 AM BPPHarv
(comments are locked)
10|3000 characters needed characters left

Thank you very much this is exactly what I needed!

Thanks again!!

more ▼

answered Oct 11, 2012 at 09:01 AM

judith gravatar image

judith
1 1 2 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6598
x4813
x24
x8

asked: Oct 09, 2012 at 04:07 PM

Seen: 3987 times

Last Updated: Nov 17, 2013 at 03:14 PM