D
D
DstivjTS2018-09-21 15:36:02
C++ / C#
DstivjTS, 2018-09-21 15:36:02

How to divide a cube into polygons?

(Sorry for the perversion) It is necessary that all sides of the cube be separated objects - for this I take the division in accordance with the vertices, I make new meshes. All 6 sides are perfect except for their position - they all have the same positions - i.e. cube position. How to make sure they have the right positions?
5ba4e656d6131194065155.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DstivjTS, 2018-09-21
@DstivjTS

Thanks to everyone who is interested, here is the code (do not scold too much):

void UpdatePivot(GameObject obj)


    {
        Mesh mesh = obj.GetComponent<MeshFilter>().mesh;
        Vector3[] verts= mesh.vertices;
         Vector3 p = new Vector3(verts[0].x+verts[1].x+verts[2].x)/3f, verts[0].y+verts[1].y+verts[2].y)/3f, verts[0].z+verts[1].z+verts[2].z)/3f);
        obj.transform.position = p; 
        for (int i = 0; i < verts.Length; i++)
        {
            verts[i] -= p;
        }
        mesh.vertices = verts; 
        mesh.RecalculateBounds(); 
    }

D
Denis Gaydak, 2018-09-21
@MrMureno

by the end. you create a set of new objects
whose mesh is a simple shape. and they all stand at 0,0,0 coordinates.
you need to or rotate your objects. or in meshes, specify the correct position of the vertices.
as an option, peep here how to create a cube from scratch.
ilkinulas.github.io/development/unity/2016/04/30/c...
or maybe suddenly how the starting point is changed in the script) this is so for reference
wiki.unity3d.com/index.php/SetPivot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question