Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
1
Question by FairGamesProductions · Jun 09, 2015 at 03:13 PM · meshmeshesprocedural meshprocedural-generationconvex

Creating a convex MESH (not collider)

I need to create a mesh around a group of other meshes (not necessarily one). As far as I can see, the simplest way would be to create a combined mesh (via script) of the meshes in question, add a Mesh Collider to the new mesh and make it Convex, then convert the convex colider to a mesh.

Now, I'm not even sure this is possible as I have found no references to anything like this on Google...

More details: I basically need a method to procedurally generate the Hull of a spaceship around it's hallways and rooms.

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 Hellium · Jun 09, 2015 at 03:18 PM 0
Share

Take a look at convex hull algorithms simply (QuickHull for example)

Some resources from google :

https://people.csail.mit.edu/indyk/6.838-old/handouts/lec10.pdf http://box2d.org/files/GDC2014/DirkGregorius_ImplementingQuickHull.pdf

You can construct a mesh by scripting using the $$anonymous$$esh class in Unity : http://docs.unity3d.com/ScriptReference/$$anonymous$$esh.html

avatar image FairGamesProductions · Jun 09, 2015 at 03:36 PM 0
Share

Well, this looks exactly like what I need, but unfortunately my coding skills are not quite there yet... Hard to believe this isn't an asset yet.

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by GLeBaTi · Feb 01, 2016 at 03:29 PM

I Found! 1) go to https://miconvexhull.codeplex.com/ 2) download and put "MIConvexHull" to unity project 3) Add class:

 public class Vertex : IVertex
 {
     public double[] Position { get; set; }
     public Vertex(double x, double y, double z)
     {
         Position = new double[3] { x, y, z };
     }
     public Vertex (Vector3 ver)
     {
         Position = new double[3] { ver.x, ver.y, ver.z };
     }
     public Vector3 ToVec()
     {
         return new Vector3((float)Position[0], (float)Position[1], (float)Position[2]);
     }
 }

4) Use It:

     void CreateSelection(IEnumerable<Vector3> points)
     {
         selection = new GameObject("Selection");
         MeshFilter meshFilter = (MeshFilter)selection.AddComponent(typeof(MeshFilter));
 
         meshFilter.mesh = CreateMesh(points);
 
         MeshRenderer renderer = selection.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
         renderer.material.shader = Shader.Find("Particles/Additive");
         Texture2D tex = new Texture2D(1, 1);
         tex.SetPixel(0, 0, Color.green);
         tex.Apply();
         renderer.material.mainTexture = tex;
         renderer.material.color = Color.green;
     }
 
     Mesh CreateMesh(IEnumerable<Vector3> stars)
     {
         Mesh m = new Mesh();
         m.name = "ScriptedMesh";
         List<int> triangles = new List<int>();
 
         var vertices = stars.Select(x => new Vertex(x)).ToList();
 
         var result = MIConvexHull.ConvexHull.Create(vertices);
         m.vertices = result.Points.Select(x => x.ToVec()).ToArray();
         var xxx = result.Points.ToList();
 
         foreach(var face in result.Faces)
         {
             triangles.Add(xxx.IndexOf(face.Vertices[0]));
             triangles.Add(xxx.IndexOf(face.Vertices[1]));
             triangles.Add(xxx.IndexOf(face.Vertices[2]));
         }
 
         m.triangles = triangles.ToArray();
         m.RecalculateNormals();
         return m;
     }

Comment
Add comment · Show 8 · 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 TurboTanker · Aug 20, 2016 at 04:16 PM 0
Share

I'm having trouble figuring out how to import $$anonymous$$IConvexHull into unity, could you explain how to do that in more detail? I downloaded the project, then copied the $$anonymous$$IConvexHull folder into my scripts folder, but a few code errors arose that I don't know how to fix.

avatar image GLeBaTi TurboTanker · Aug 21, 2016 at 08:54 AM 0
Share

1) copy only $$anonymous$$IConvexHull folder (not examples, asp, resources, sln, .ignore) Try to delete "Properties" folder and "$$anonymous$$IConvexHull.csproj" file

avatar image ole66 GLeBaTi · Aug 22, 2016 at 10:04 AM 0
Share

I've also problems running $$anonymous$$IConvexHull.

I've downlaoded at https://miconvexhull.codeplex.com/SourceControl/latest (https://miconvexhull.codeplex.com/SourceControl/latest#), extracted it and copied the folder "$$anonymous$$IConvexHull" (without the folder "Properties" and the file "$$anonymous$$IConvexHull.csproj"). I've also created a file Vertex.cs as you mentioned. But Unity is showing me some errors:

  • Assets/$$anonymous$$IConvexHull/Configuration.cs(125,87): error CS1750: Optional parameter value '0' cannot be converted to parameter type 'int?'

  • Assets/$$anonymous$$IConvexHull/Triangulation.cs(59,23): error CS0310: The type '$$anonymous$$IConvexHull.DefaultTriangulationCell' must have a public parameterless constructor in order to use it as parameter 'TCell' in the generic type or method '$$anonymous$$IConvexHull.ITriangulation'

  • Assets/$$anonymous$$IConvexHull/Triangulation.cs(71,23): error CS0310: The type '$$anonymous$$IConvexHull.DefaultTriangulationCell' must have a public parameterless constructor in order to use it as parameter 'TCell' in the generic type or method '$$anonymous$$IConvexHull.ITriangulation'

  • Assets/$$anonymous$$IConvexHull/Triangulation.cs(117,23): error CS0310: The type '$$anonymous$$IConvexHull.DefaultTriangulationCell' must have a public parameterless constructor in order to use it as parameter 'TCell' in the generic type or method '$$anonymous$$IConvexHull.Voronoi$$anonymous$$esh'

  • Assets/$$anonymous$$IConvexHull/Triangulation.cs(129,23): error CS0310: The type '$$anonymous$$IConvexHull.DefaultTriangulationCell' must have a public parameterless constructor in order to use it as parameter 'TCell' in the generic type or method '$$anonymous$$IConvexHull.Voronoi$$anonymous$$esh'

And some more but with the same kind of error for another row/line.

How did you managed to run $$anonymous$$IConvexHull in Unity?

EDIT: Found the reason. You have to copy the folder into to the Unity-project (top hierarchy) and not (as I did) in the Asset-folder.

Show more comments
Show more comments
avatar image Propagant · Mar 18, 2017 at 12:41 PM 0
Share

this helps a lot!

If you want to use it. Just add to you script:

   public void _CreateConvex$$anonymous$$esh()
 {
    //------This is currently taken from this gameobject
     CreateSelection(GetComponent<$$anonymous$$eshFilter>().shared$$anonymous$$esh.vertices);
 }




avatar image FaffyWaffles · Mar 23 at 02:49 AM 0
Share

MIConvexHull has been migrated from Codeplex to Github

https://github.com/DesignEngrLab/MIConvexHull is the new

avatar image
0

Answer by Jack · Jan 19, 2017 at 08:23 AM

I did it, just delete Triangulation.cs and Triangulation Folder

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

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

28 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

Related Questions

Mesh generation issue (C#) 1 Answer

C# Proceducal Mesh terrain 2 Answers

What is wrong with this mesh editing code? 0 Answers

Vertex Colors not smooth enough? 0 Answers

How can I remove redundant vertices in custom mesh? 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