Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
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 which 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 this 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 this 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 this 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 this. 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 this would work for that.
If you're literally trying to dissect the mesh, so you could (e.g.) sword slice something 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 think you're trying to do this 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

Hi @tuinal, thanks for the help, but I don't think I can do that.

I see your points and all of them are valid! But, I'm working with meshes of heriatage buildings (from laser scanning or photogrammetry) and I'm essentially not able to decimate/modify this input data (it's imported at runtime). Also, I plan to add exporting of the slice later on, so I don't think I can use the shader here.

The CPU approach actually works pretty fast (as far as polygons go), the only problem I have is in the texture. If you forget for a second that using CPU here isn't the best option, could you maybe take a guess at why are my textures distorted?

Thanks 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

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 modify mesh of object when other object trigger like cut 0 Answers

Melting a mesh on top of another mesh? 1 Answer

how to cut a mesh? 1 Answer

modify mesh in real time 0 Answers

How can I ADD vertices and faces to a mesh? 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