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 Sassieee · Aug 06, 2014 at 08:44 PM · game

'Use SetTriangles instead. Internally this function will convert the triangle strip to a list of triangles anyway.' (27,74) & (130,73) & (177,30)

 sing UnityEngine;
 using System.Collections;
 
 public class MeshCombineUtility {
     
     public struct MeshInstance
     {
         public Mesh      mesh;
         public int       subMeshIndex;            
         public Matrix4x4 transform;
     }
     
     public static Mesh Combine (MeshInstance[] combines, bool generateStrips)
     {
         int vertexCount = 0;
         int triangleCount = 0;
         int stripCount = 0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
             {
                 vertexCount += combine.mesh.vertexCount;
                 
                 if (generateStrips)
                 {
                     // SUBOPTIMAL FOR PERFORMANCE
                     int curStripCount = combine.mesh.GetTriangleStrip(combine.subMeshIndex).Length;
                     if (curStripCount != 0)
                     {
                         if( stripCount != 0 )
                         {
                             if ((stripCount & 1) == 1 )
                                 stripCount += 3;
                             else
                                 stripCount += 2;
                         }
                         stripCount += curStripCount;
                     }
                     else
                     {
                         generateStrips = false;
                     }
                 }
             }
         }
         
         // Precomputed how many triangles we need instead
         if (!generateStrips)
         {
             foreach( MeshInstance combine in combines )
             {
                 if (combine.mesh)
                 {
                     triangleCount += combine.mesh.GetTriangles(combine.subMeshIndex).Length;
                 }
             }
         }
         
         Vector3[] vertices = new Vector3[vertexCount] ;
         Vector3[] normals = new Vector3[vertexCount] ;
         Vector4[] tangents = new Vector4[vertexCount] ;
         Vector2[] uv = new Vector2[vertexCount];
         Vector2[] uv1 = new Vector2[vertexCount];
         Color[] colors = new Color[vertexCount];
         
         int[] triangles = new int[triangleCount];
         int[] strip = new int[stripCount];
         
         int offset;
         
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
                 Copy(combine.mesh.vertexCount, combine.mesh.vertices, vertices, ref offset, combine.transform);
         }
 
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
             {
                 Matrix4x4 invTranspose = combine.transform;
                 invTranspose = invTranspose.inverse.transpose;
                 CopyNormal(combine.mesh.vertexCount, combine.mesh.normals, normals, ref offset, invTranspose);
             }
                 
         }
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
             {
                 Matrix4x4 invTranspose = combine.transform;
                 invTranspose = invTranspose.inverse.transpose;
                 CopyTangents(combine.mesh.vertexCount, combine.mesh.tangents, tangents, ref offset, invTranspose);
             }
                 
         }
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
                 Copy(combine.mesh.vertexCount, combine.mesh.uv, uv, ref offset);
         }
         
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
                 Copy(combine.mesh.vertexCount, combine.mesh.uv1, uv1, ref offset);
         }
         
         offset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
                 CopyColors(combine.mesh.vertexCount, combine.mesh.colors, colors, ref offset);
         }
         
         int triangleOffset=0;
         int stripOffset=0;
         int vertexOffset=0;
         foreach( MeshInstance combine in combines )
         {
             if (combine.mesh)
             {
                 if (generateStrips)
                 {
                     int[] inputstrip = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
                     if (stripOffset != 0)
                     {
                         if ((stripOffset & 1) == 1)
                         {
                             strip[stripOffset+0] = strip[stripOffset-1];
                             strip[stripOffset+1] = inputstrip[0] + vertexOffset;
                             strip[stripOffset+2] = inputstrip[0] + vertexOffset;
                             stripOffset+=3;
                         }
                         else
                         {
                             strip[stripOffset+0] = strip[stripOffset-1];
                             strip[stripOffset+1] = inputstrip[0] + vertexOffset;
                             stripOffset+=2;
                         }
                     }
                     
                     for (int i=0;i<inputstrip.Length;i++)
                     {
                         strip[i+stripOffset] = inputstrip[i] + vertexOffset;
                     }
                     stripOffset += inputstrip.Length;
                 }
                 else
                 {
                     int[]  inputtriangles = combine.mesh.GetTriangles(combine.subMeshIndex);
                     for (int i=0;i<inputtriangles.Length;i++)
                     {
                         triangles[i+triangleOffset] = inputtriangles[i] + vertexOffset;
                     }
                     triangleOffset += inputtriangles.Length;
                 }
                 
                 vertexOffset += combine.mesh.vertexCount;
             }
         }
         
         Mesh mesh = new Mesh();
         mesh.name = "Combined Mesh";
         mesh.vertices = vertices;
         mesh.normals = normals;
         mesh.colors = colors;
         mesh.uv = uv;
         mesh.uv1 = uv1;
         mesh.tangents = tangents;
         if (generateStrips)
             mesh.SetTriangleStrip(strip, 0);
         else
             mesh.triangles = triangles;
         
         return mesh;
     }
     
     static void Copy (int vertexcount, Vector3[] src, Vector3[] dst, ref int offset, Matrix4x4 transform)
     {
         for (int i=0;i<src.Length;i++)
             dst[i+offset] = transform.MultiplyPoint(src[i]);
         offset += vertexcount;
     }
 
     static void CopyNormal (int vertexcount, Vector3[] src, Vector3[] dst, ref int offset, Matrix4x4 transform)
     {
         for (int i=0;i<src.Length;i++)
             dst[i+offset] = transform.MultiplyVector(src[i]).normalized;
         offset += vertexcount;
     }
 
     static void Copy (int vertexcount, Vector2[] src, Vector2[] dst, ref int offset)
     {
         for (int i=0;i<src.Length;i++)
             dst[i+offset] = src[i];
         offset += vertexcount;
     }
 
     static void CopyColors (int vertexcount, Color[] src, Color[] dst, ref int offset)
     {
         for (int i=0;i<src.Length;i++)
             dst[i+offset] = src[i];
         offset += vertexcount;
     }
     
     static void CopyTangents (int vertexcount, Vector4[] src, Vector4[] dst, ref int offset, Matrix4x4 transform)
     {
         for (int i=0;i<src.Length;i++)
         {
             Vector4 p4 = src[i];
             Vector3 p = new Vector3(p4.x, p4.y, p4.z);
             p = transform.MultiplyVector(p).normalized;
             dst[i+offset] = new Vector4(p.x, p.y, p.z, p4.w);
         }
             
         offset += vertexcount;
     }
 }
 
Comment
Add comment · Show 3
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 Sassieee · Aug 06, 2014 at 07:07 PM 0
Share

So can anybody help me ?

avatar image tanoshimi · Aug 06, 2014 at 08:53 PM 0
Share

Ummm, you've not actually asked a question... what you've done is pasted 225 lines of uncommented code with an error message for a title. Why aren't you using SetTriangles?

avatar image gjf · Aug 07, 2014 at 07:52 AM 0
Share

i'm going to guess that the OP has just downloaded an asset which uses some deprecated code, and the chances are they don't even need this and just don't know it ;)

i say this because i was asked the exact same questions from the OP the other day, albeit by somebody else. they had downloaded some old warplane game.

i could be wrong...

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Running a Unity 4.6 game on Unity 4.5.2 - Possible? 1 Answer

End game after livesLeft = 0 0 Answers

A node in a childnode? 1 Answer

Help Understanding the Use of Unity with Android 1 Answer

Unity and Ports : Networking 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