• 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 radacadabra · Sep 08, 2020 at 02:38 AM · meshmanipulationcutting

Texture problems when cutting large meshes at runtime

Hello!

I'm hoping to find some help or ideas for an issue I'm unable to solve for a long time now. I'll try to give as much info in as little space possible :)


Goal

I need to be able to cut large meshes at runtime (100M vertices+). Meshes sometimes have per-vertex colouring and sometimes have texture maps with multiple materials.

There isn't much I can do to modify the input data - models are otputs of surveying (laser scanning or photogrammetry).


Problem

I wrote a simple script for mesh cutting that works on per-vertex coloured mesh, but when used on mesh with texture maps it successfully cuts but the texture gets broken.


The script runs through the vertices, identifies w$$anonymous$$ch are our of boundaries, and then modifies the list of indices by removing the triangles that are out of boundaries. It doesn't modify the lists of vertices, normals, or any other part of the mesh, only indices.


Any ideas why t$$anonymous$$s doesn't work? Any help would be much appreciated!


 Mesh mesh = mesh.GetComponent<MeshFilter>().mesh;
 Vector3[] vertices = mesh.vertices;
 int[] triangles = mesh.triangles;
 
 //create list for new indices
 List<int> newTriangles = new List<int>();
 //create list for is-inside-or-outside of boundaries
 List<bool> insideOrNot = new List<bool>();
 
 float vertexX;
 float vertexY;
 float vertexZ;
 
 for (int i = 0; i < vertices.Length; i++)
 {
     //ensure world coordinates
     vertexX = transform.TransformPoint(vertices[i]).x;
     vertexY = transform.TransformPoint(vertices[i]).y;
     vertexZ = transform.TransformPoint(vertices[i]).z;
 
     //maxX, minX, maxY, minY, maxZ, minZ are boundaries of the box used for cutting
     //only the part of the mesh inside t$$anonymous$$s box is to be displayed
     if (vertexX < maxX && vertexX > minX && vertexY < maxY && vertexY > minY && vertexZ < maxZ && vertexZ > minZ)
         insideOrNot.Add(true);
     else
         insideOrNot.Add(false);
 }
 
 for (int i = 0; i < triangles.Length; i += 3)
 {
     if (insideOrNot[triangles[i]] && insideOrNot[triangles[i + 1]] && insideOrNot[triangles[i + 2]])
     {
         newTriangles.Add(triangles[i]);
         newTriangles.Add(triangles[i + 1]);
         newTriangles.Add(triangles[i + 2]);
     }
 }
 mesh.triangles = newTriangles.ToArray();
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
0

Answer by radacadabra · Nov 10, 2020 at 01:46 AM

Anyone?

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
avatar image
0

Answer by tuinal · Nov 10, 2020 at 02:10 AM

You're fundamentally in a bad place trying to render 100M+ vertices realtime, and in a worse place trying to use the CPU to handle slicing. It would be normal to optimise t$$anonymous$$s mesh first. Simply whacking it into Blender and doing a Decimate would probably help.
If what you need is a clear 'clip plane' type cut, that intersects the model, then a shader would be a lot more efficient than CPU code at doing t$$anonymous$$s. A simple shadergraph with a branch+alpha clipping based on xyz world space coordinate would cleanly clip the model along a given plane. Looking at the code you seem only interested in what's 'inside', so t$$anonymous$$s would work for that.
If you're literally trying to dissect the mesh, so you could (e.g.) sword slice somet$$anonymous$$ng in two, and have the bits fall apart, then the CPU approach would be needed, but it would be on the constraint of relatively low vertex counts. If it were trivial to slice complicated meshes into two discrete meshes in realtime, you'd be seeing that in games - I don't t$$anonymous$$nk you're trying to do t$$anonymous$$s so I'd suggest looking at shaders.

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 radacadabra · Nov 11, 2020 at 04:08 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

154 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 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

How to cut or make transparent part of a mesh 0 Answers

Mesh deformation/wobbling 1 Answer

Cutting a desired shape out of mesh 1 Answer

Mash Manipulation like in real world? 0 Answers

Run Time Plastic Shrink/Wrap , Mesh Manipulation 0 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