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 u2dt · Nov 04, 2014 at 03:07 PM · arrayintvalueadd

Add values to Int[] (SetTriangles)

Hi, First, I'm sorry for my english, I'm french, I'll do my best to express myself.

I have to change some triangles of a submesh into another one, when the player hit it. That's how I did it :

         //TriInfo[2] is the index of the triangle in the submesh 0 I want to assign to the submesh 1
         //GoMesh is the mesh I'm working on
 
         //Define an Array wich will contain the triangles of the submesh 1 and the new one
         int[] AddTriangle = new int[GoMesh.GetTriangles (1).Length + 3];
         for (int i=0; i<GoMesh.GetTriangles (1).Length; i++){
             AddTriangle[i]=GoMesh.GetTriangles(1)[i];
         }
 
         AddTriangle[GoMesh.GetTriangles(1).Length]=GoMesh.GetTriangles(0)[TriInfo [2]*3];
         AddTriangle[GoMesh.GetTriangles(1).Length+1]=GoMesh.GetTriangles(0)[TriInfo [2]*3 + 1];
         AddTriangle[GoMesh.GetTriangles(1).Length+2]=GoMesh.GetTriangles(0)[TriInfo [2]*3 + 2];
 
 
         //I assign the new array AddTriangle to the submesh 1
         GoMesh.SetTriangles (AddTriangle, 1);

It works, but it is a frequent request and, when the int[] gets long, the game lags. It has to be a int[] and not a list (for the function SetTriangle), and i didn't find a better way to add values to it.

Thank you for reading, and if you have a solution, i would be really grateful.

Comment
Add comment · Show 2
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 robertbu · Nov 04, 2014 at 03:09 PM 0
Share

Is it always the same submesh, or are you doing different submeshes? How frequent...every frame?

avatar image u2dt · Nov 04, 2014 at 03:27 PM 0
Share

In this situation it is always from the submesh 0 to the submesh 1, yes. (I have 4 submeshes, and in specific situations, the triangles will go from 1 to 2, and from 2 to 3)

The context : The player is walking on a sphere. Every frame, I make a raycast hit to know on which triangle he is. If this triangle is on the submesh 0, I assign it to the submesh 1. So, the frequency depends of the movement of the player, but it can be some times per seconds (and at the end I have more than 2000 values in my array...)

Thanks for replying

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by brentatplayful · Nov 04, 2014 at 03:28 PM

I would look at Buffer.BlockCopy I'm not sure about these sub meshes you indexing but something like this will be faster

         const INT_LENGTH_IN_BYTES = 4;
         int[] subMesh0Tris = GoMesh.GetTriangles(0);
         int[] subMesh1Tris = GoMesh.GetTriangles(1);
 
         int[] newTriangles = new int[subMesh1Tris.Length + 3];
         Buffer.BlockCopy(subMesh1Tris, 0, newTriangles, 0, subMesh1Tris.Length * INT_LENGTH_IN_BYTES);
 
         newTriangles[newTriangles.Length-3]=subMesh0Tris[TriInfo[2]*3];
         newTriangles[newTriangles.Length-2]=subMesh0Tris[TriInfo[2]*3 + 1];
         newTriangles[newTriangles.Length-1]=subMesh0Tris[TriInfo[2]*3 + 2];
 
         //I assign the new array AddTriangle to the submesh 1
         GoMesh.SetTriangles (newTriangles, 1);

I did not test this but it should be close to what you're looking for

Comment
Add comment · Show 1 · 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 u2dt · Nov 04, 2014 at 04:22 PM 0
Share

It's perfect, thank you so much ! It didn't work in a first time, because I was using System.Collections. Now that I am using System, it's ok (I'm a beginner). Some methods I found on the $$anonymous$$SDN wich did'nt work would probably work now too.

Thank you again :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Array value not changing? 1 Answer

Search an array? 2 Answers

Keep adding targets to a list 2 Answers

Check if all elements of an array contain the same value? 3 Answers

How to convert String array to int array 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