Search Unity

Question How do I extrude a 2d plane to a 3d mesh?

Discussion in 'Scripting' started by Philip2809, Mar 30, 2023.

  1. Philip2809

    Philip2809

    Joined:
    Jan 14, 2022
    Posts:
    4
    Hey! I have a plane mesh and I am trying to figure out how to extrude it. Can someone please help me? this is my mesh and I have tried to use MeshExtrusion.cs but I am getting an error.

    Error:
    Code (CSharp):
    1. IndexOutOfRangeException: Index was outside the bounds of the array.
    2. MeshExtrusion.ExtrudeMesh (UnityEngine.Mesh srcMesh, UnityEngine.Mesh extrudedMesh, UnityEngine.Matrix4x4[] extrusion, MeshExtrusion+Edge[]
    Mesh:



    Code:


    MeshExtrusion.cs is from github and discussed here:
    https://github.com/nickhall/Unity-Procedural/blob/master/Splines/Assets/Plugins/MeshExtrusion.cs
    https://forum.unity.com/threads/how...eshextrusion-cs-with-another-c-script.428149/
    https://forum.unity.com/threads/how...eshextrusion-cs-with-another-c-script.427867/
    But I cant really wrap my head around how to use it, can someone please help me?

    Any help is appreciated!
    Thanks Philip!
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,116
    How we're supposed to know what produced that error? If I'm preparing Crème Brûlée and then show you an Instagram picture of some burnt toast, can you tell what I did wrong?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Here are some notes on IndexOutOfRangeException and ArgumentOutOfRangeException:

    http://plbm.com/?p=236

    Steps to success:
    - find which collection it is and what line of code accesses it <--- critical first step!)
    - find out why it has fewer items than you expect
    - fix whatever logic is making the indexing value exceed the collection size
    - remember that a collection with ZERO elements cannot be indexed at all: it is empty
    - remember you might have more than one instance of this script in your scene/prefab
    - remember the collection may be used in more than one location in the code
    - remember that indices start at ZERO (0) and go to the count / length minus 1.

    This means with three (3) elements, they are numbered 0, 1, and 2 only.

    If you would like an example of extrusion, I have one in my MakeGeo project... look for
    Extrude2DShape.cs


    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo