How to create a mesh dynamically In unity The Next CEO of Stack OverflowAlgorithm for duplicating problem resolution during search process for mesh dynamic generationTo create a bounding box in a texture in UnityHow do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I generate a random int number?Deserialize JSON into C# dynamic object?WPF applications for 3D image viewFind out the texture portion needed for a meshCoordinate of a pixel of an image to coordinate on the textureHow to filter light through non transparent pixel in texture?Coloring Rgl 3d mesh faces

What is the purpose of the Evocation wizard's Potent Cantrip feature?

Grabbing quick drinks

Can the Reverse Gravity spell affect the Meteor Swarm spell?

When did Lisp start using symbols for arithmetic?

How can I open an app using Terminal?

Why didn't Khan get resurrected in the Genesis Explosion?

How to be diplomatic in refusing to write code that breaches the privacy of our users

How to Reset Passwords on Multiple Websites Easily?

How to write the block matrix in LaTex?

Is the concept of a "numerable" fiber bundle really useful or an empty generalization?

Why did we only see the N-1 starfighters in one film?

Solution of this Diophantine Equation

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

How do I solve this limit?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Is a stroke of luck acceptable after a series of unfavorable events?

How long to clear the 'suck zone' of a turbofan after start is initiated?

When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

How to start emacs in "nothing" mode (`fundamental-mode`)

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

How to make a variable always equal to the result of some calculations?

How do spells that require an ability check vs. the caster's spell save DC work?

Removing read access from a file



How to create a mesh dynamically In unity



The Next CEO of Stack OverflowAlgorithm for duplicating problem resolution during search process for mesh dynamic generationTo create a bounding box in a texture in UnityHow do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I generate a random int number?Deserialize JSON into C# dynamic object?WPF applications for 3D image viewFind out the texture portion needed for a meshCoordinate of a pixel of an image to coordinate on the textureHow to filter light through non transparent pixel in texture?Coloring Rgl 3d mesh faces










0















I have vertex that have a color value.



I'd like to make a mesh using vertex with the same color values.



enter image description here



This picture is an example.



I took pictures with my Android Phone, and I did image segmentation on the object



So I got a color value corresponding to the coordinate value.



I succeeded in just making textures. please check the image.
enter image description here



But I want a mesh object.



Below is making texture code.



var pixel = await this.segmentation.SegmentAsync(rotated, scaled.width, scaled.height);
// int pixel[][]; // image segmentation using tensorflow

Color transparentColor = new Color32(255, 255, 255, 0); // transparent
for (int y = 0; y < texture.height; y++)

for (int x = 0; x < texture.width; x++)

int class_output = pixel[y][x];

texture.SetPixel(x, y, pixel[y][x] == 0 ? transparentColor : colors[class_output]);


texture.Apply();


How can I make a mesh object?










share|improve this question






















  • With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

    – Dave
    Mar 8 at 13:06











  • if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

    – zambari
    Mar 8 at 13:27











  • Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

    – Ali Kanat
    Mar 8 at 13:28















0















I have vertex that have a color value.



I'd like to make a mesh using vertex with the same color values.



enter image description here



This picture is an example.



I took pictures with my Android Phone, and I did image segmentation on the object



So I got a color value corresponding to the coordinate value.



I succeeded in just making textures. please check the image.
enter image description here



But I want a mesh object.



Below is making texture code.



var pixel = await this.segmentation.SegmentAsync(rotated, scaled.width, scaled.height);
// int pixel[][]; // image segmentation using tensorflow

Color transparentColor = new Color32(255, 255, 255, 0); // transparent
for (int y = 0; y < texture.height; y++)

for (int x = 0; x < texture.width; x++)

int class_output = pixel[y][x];

texture.SetPixel(x, y, pixel[y][x] == 0 ? transparentColor : colors[class_output]);


texture.Apply();


How can I make a mesh object?










share|improve this question






















  • With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

    – Dave
    Mar 8 at 13:06











  • if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

    – zambari
    Mar 8 at 13:27











  • Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

    – Ali Kanat
    Mar 8 at 13:28













0












0








0








I have vertex that have a color value.



I'd like to make a mesh using vertex with the same color values.



enter image description here



This picture is an example.



I took pictures with my Android Phone, and I did image segmentation on the object



So I got a color value corresponding to the coordinate value.



I succeeded in just making textures. please check the image.
enter image description here



But I want a mesh object.



Below is making texture code.



var pixel = await this.segmentation.SegmentAsync(rotated, scaled.width, scaled.height);
// int pixel[][]; // image segmentation using tensorflow

Color transparentColor = new Color32(255, 255, 255, 0); // transparent
for (int y = 0; y < texture.height; y++)

for (int x = 0; x < texture.width; x++)

int class_output = pixel[y][x];

texture.SetPixel(x, y, pixel[y][x] == 0 ? transparentColor : colors[class_output]);


texture.Apply();


How can I make a mesh object?










share|improve this question














I have vertex that have a color value.



I'd like to make a mesh using vertex with the same color values.



enter image description here



This picture is an example.



I took pictures with my Android Phone, and I did image segmentation on the object



So I got a color value corresponding to the coordinate value.



I succeeded in just making textures. please check the image.
enter image description here



But I want a mesh object.



Below is making texture code.



var pixel = await this.segmentation.SegmentAsync(rotated, scaled.width, scaled.height);
// int pixel[][]; // image segmentation using tensorflow

Color transparentColor = new Color32(255, 255, 255, 0); // transparent
for (int y = 0; y < texture.height; y++)

for (int x = 0; x < texture.width; x++)

int class_output = pixel[y][x];

texture.SetPixel(x, y, pixel[y][x] == 0 ? transparentColor : colors[class_output]);


texture.Apply();


How can I make a mesh object?







c# unity3d dynamic mesh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 12:53









Han Seob KimHan Seob Kim

477




477












  • With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

    – Dave
    Mar 8 at 13:06











  • if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

    – zambari
    Mar 8 at 13:27











  • Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

    – Ali Kanat
    Mar 8 at 13:28

















  • With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

    – Dave
    Mar 8 at 13:06











  • if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

    – zambari
    Mar 8 at 13:27











  • Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

    – Ali Kanat
    Mar 8 at 13:28
















With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

– Dave
Mar 8 at 13:06





With Unity3D Mesh class... docs.unity3d.com/ScriptReference/Mesh.html

– Dave
Mar 8 at 13:06













if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

– zambari
Mar 8 at 13:27





if you have the outline, the process you are looking for is called triangulation (if 2d is ok)

– zambari
Mar 8 at 13:27













Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

– Ali Kanat
Mar 8 at 13:28





Apparently you are using ARCore. You can use extracted points to create your meshes as @Dave mentioned. However, i highly doubt that you get a proper mesh at the end of this procedure.

– Ali Kanat
Mar 8 at 13:28












1 Answer
1






active

oldest

votes


















1














1- Set a prefab with a MeshFilter and a MeshRenderer.



2- Variables inside the script that you will need to fill.



// This first list contains every vertex of the mesh that we are going to render
public List<Vector3> newVertices = new List<Vector3>();

// The triangles tell Unity how to build each section of the mesh joining
// the vertices
public List<int> newTriangles = new List<int>();

// The UV list is unimportant right now but it tells Unity how the texture is
// aligned on each polygon
public List<Vector2> newUV = new List<Vector2>();


// A mesh is made up of the vertices, triangles and UVs we are going to define,
// after we make them up we'll save them as this mesh
private Mesh mesh;


3- Initialize the mesh



void Start () 

mesh = GetComponent<MeshFilter> ().mesh;

float x = transform.position.x;
float y = transform.position.y;
float z = transform.position.z;

newVertices.Add( new Vector3 (x , y , z ));
newVertices.Add( new Vector3 (x + 1 , y , z ));
newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
newVertices.Add( new Vector3 (x , y-1 , z ));

newTriangles.Add(0);
newTriangles.Add(1);
newTriangles.Add(3);
newTriangles.Add(1);
newTriangles.Add(2);
newTriangles.Add(3);

newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit));
newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit));
newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y));
newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));

mesh.Clear ();
mesh.vertices = newVertices.ToArray();
mesh.triangles = newTriangles.ToArray();
mesh.uv = newUV.ToArray(); // add this line to the code here
mesh.Optimize ();
mesh.RecalculateNormals ();



This code will draw a square at the position of the prefab, if you keep adding vertices you can generate a more complex mesh.



The source of information is a tutorial to generate mensh for a terrain like minecrat, check the link for more information.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063656%2fhow-to-create-a-mesh-dynamically-in-unity%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    1- Set a prefab with a MeshFilter and a MeshRenderer.



    2- Variables inside the script that you will need to fill.



    // This first list contains every vertex of the mesh that we are going to render
    public List<Vector3> newVertices = new List<Vector3>();

    // The triangles tell Unity how to build each section of the mesh joining
    // the vertices
    public List<int> newTriangles = new List<int>();

    // The UV list is unimportant right now but it tells Unity how the texture is
    // aligned on each polygon
    public List<Vector2> newUV = new List<Vector2>();


    // A mesh is made up of the vertices, triangles and UVs we are going to define,
    // after we make them up we'll save them as this mesh
    private Mesh mesh;


    3- Initialize the mesh



    void Start () 

    mesh = GetComponent<MeshFilter> ().mesh;

    float x = transform.position.x;
    float y = transform.position.y;
    float z = transform.position.z;

    newVertices.Add( new Vector3 (x , y , z ));
    newVertices.Add( new Vector3 (x + 1 , y , z ));
    newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
    newVertices.Add( new Vector3 (x , y-1 , z ));

    newTriangles.Add(0);
    newTriangles.Add(1);
    newTriangles.Add(3);
    newTriangles.Add(1);
    newTriangles.Add(2);
    newTriangles.Add(3);

    newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit));
    newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit));
    newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y));
    newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));

    mesh.Clear ();
    mesh.vertices = newVertices.ToArray();
    mesh.triangles = newTriangles.ToArray();
    mesh.uv = newUV.ToArray(); // add this line to the code here
    mesh.Optimize ();
    mesh.RecalculateNormals ();



    This code will draw a square at the position of the prefab, if you keep adding vertices you can generate a more complex mesh.



    The source of information is a tutorial to generate mensh for a terrain like minecrat, check the link for more information.






    share|improve this answer





























      1














      1- Set a prefab with a MeshFilter and a MeshRenderer.



      2- Variables inside the script that you will need to fill.



      // This first list contains every vertex of the mesh that we are going to render
      public List<Vector3> newVertices = new List<Vector3>();

      // The triangles tell Unity how to build each section of the mesh joining
      // the vertices
      public List<int> newTriangles = new List<int>();

      // The UV list is unimportant right now but it tells Unity how the texture is
      // aligned on each polygon
      public List<Vector2> newUV = new List<Vector2>();


      // A mesh is made up of the vertices, triangles and UVs we are going to define,
      // after we make them up we'll save them as this mesh
      private Mesh mesh;


      3- Initialize the mesh



      void Start () 

      mesh = GetComponent<MeshFilter> ().mesh;

      float x = transform.position.x;
      float y = transform.position.y;
      float z = transform.position.z;

      newVertices.Add( new Vector3 (x , y , z ));
      newVertices.Add( new Vector3 (x + 1 , y , z ));
      newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
      newVertices.Add( new Vector3 (x , y-1 , z ));

      newTriangles.Add(0);
      newTriangles.Add(1);
      newTriangles.Add(3);
      newTriangles.Add(1);
      newTriangles.Add(2);
      newTriangles.Add(3);

      newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit));
      newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit));
      newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y));
      newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));

      mesh.Clear ();
      mesh.vertices = newVertices.ToArray();
      mesh.triangles = newTriangles.ToArray();
      mesh.uv = newUV.ToArray(); // add this line to the code here
      mesh.Optimize ();
      mesh.RecalculateNormals ();



      This code will draw a square at the position of the prefab, if you keep adding vertices you can generate a more complex mesh.



      The source of information is a tutorial to generate mensh for a terrain like minecrat, check the link for more information.






      share|improve this answer



























        1












        1








        1







        1- Set a prefab with a MeshFilter and a MeshRenderer.



        2- Variables inside the script that you will need to fill.



        // This first list contains every vertex of the mesh that we are going to render
        public List<Vector3> newVertices = new List<Vector3>();

        // The triangles tell Unity how to build each section of the mesh joining
        // the vertices
        public List<int> newTriangles = new List<int>();

        // The UV list is unimportant right now but it tells Unity how the texture is
        // aligned on each polygon
        public List<Vector2> newUV = new List<Vector2>();


        // A mesh is made up of the vertices, triangles and UVs we are going to define,
        // after we make them up we'll save them as this mesh
        private Mesh mesh;


        3- Initialize the mesh



        void Start () 

        mesh = GetComponent<MeshFilter> ().mesh;

        float x = transform.position.x;
        float y = transform.position.y;
        float z = transform.position.z;

        newVertices.Add( new Vector3 (x , y , z ));
        newVertices.Add( new Vector3 (x + 1 , y , z ));
        newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
        newVertices.Add( new Vector3 (x , y-1 , z ));

        newTriangles.Add(0);
        newTriangles.Add(1);
        newTriangles.Add(3);
        newTriangles.Add(1);
        newTriangles.Add(2);
        newTriangles.Add(3);

        newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit));
        newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit));
        newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y));
        newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));

        mesh.Clear ();
        mesh.vertices = newVertices.ToArray();
        mesh.triangles = newTriangles.ToArray();
        mesh.uv = newUV.ToArray(); // add this line to the code here
        mesh.Optimize ();
        mesh.RecalculateNormals ();



        This code will draw a square at the position of the prefab, if you keep adding vertices you can generate a more complex mesh.



        The source of information is a tutorial to generate mensh for a terrain like minecrat, check the link for more information.






        share|improve this answer















        1- Set a prefab with a MeshFilter and a MeshRenderer.



        2- Variables inside the script that you will need to fill.



        // This first list contains every vertex of the mesh that we are going to render
        public List<Vector3> newVertices = new List<Vector3>();

        // The triangles tell Unity how to build each section of the mesh joining
        // the vertices
        public List<int> newTriangles = new List<int>();

        // The UV list is unimportant right now but it tells Unity how the texture is
        // aligned on each polygon
        public List<Vector2> newUV = new List<Vector2>();


        // A mesh is made up of the vertices, triangles and UVs we are going to define,
        // after we make them up we'll save them as this mesh
        private Mesh mesh;


        3- Initialize the mesh



        void Start () 

        mesh = GetComponent<MeshFilter> ().mesh;

        float x = transform.position.x;
        float y = transform.position.y;
        float z = transform.position.z;

        newVertices.Add( new Vector3 (x , y , z ));
        newVertices.Add( new Vector3 (x + 1 , y , z ));
        newVertices.Add( new Vector3 (x + 1 , y-1 , z ));
        newVertices.Add( new Vector3 (x , y-1 , z ));

        newTriangles.Add(0);
        newTriangles.Add(1);
        newTriangles.Add(3);
        newTriangles.Add(1);
        newTriangles.Add(2);
        newTriangles.Add(3);

        newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y + tUnit));
        newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y + tUnit));
        newUV.Add(new Vector2 (tUnit * tStone.x + tUnit, tUnit * tStone.y));
        newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));

        mesh.Clear ();
        mesh.vertices = newVertices.ToArray();
        mesh.triangles = newTriangles.ToArray();
        mesh.uv = newUV.ToArray(); // add this line to the code here
        mesh.Optimize ();
        mesh.RecalculateNormals ();



        This code will draw a square at the position of the prefab, if you keep adding vertices you can generate a more complex mesh.



        The source of information is a tutorial to generate mensh for a terrain like minecrat, check the link for more information.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 8 at 14:00

























        answered Mar 8 at 13:45









        Dom93Dom93

        1019




        1019





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063656%2fhow-to-create-a-mesh-dynamically-in-unity%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229