Beispiel #1
0
        internal static void SetPivot(this ProBuilderMesh mesh, PivotLocation pivotType, int firstVertexIndex = 0)
        {
            switch (pivotType)
            {
            case PivotLocation.Center:
                mesh.CenterPivot(null);
                break;

            case PivotLocation.FirstVertex:
                mesh.CenterPivot(new int[1] {
                    firstVertexIndex
                });
                break;
            }
        }
Beispiel #2
0
    void Initialize()
    {
        Vector3[] points     = new Vector3[UVLength * UVLength];
        Face[]    faces      = new Face[(UVLength - 1) * (UVLength - 1)];
        float     xThreshold = (edgeLength) / UVLength;

        for (int i = 0; i < points.Length; i++)
        {
            points[i] = new Vector3(center.x + (xThreshold * (i % UVLength)), center.y, center.z + (xThreshold * (i / UVLength)));
        }
        int j = 0;

        for (int i = 0; i < points.Length - UVLength; i++)
        {
            if (i % UVLength != UVLength - 1)
            {
                faces[j] = new Face(new int[] { i, i + 1, i + UVLength, i + 1, i + UVLength + 1, i + UVLength });
                j++;
            }
        }

        ground = ProBuilderMesh.Create(points, faces);
        ground.CenterPivot(new int[] { 0, UVLength - 1, UVLength * (UVLength - 1), (UVLength * UVLength) - 1 });
        ground.Refresh();
        MeshRenderer meshRend = ground.GetComponent <MeshRenderer>();

        meshRend.material         = fogMaterial;
        ground.transform.position = center;
        ground.gameObject.layer   = 9;
        ground.gameObject.name    = "fog";
        ground.gameObject.AddComponent <MeshCollider>();
        ground.transform.Rotate(new Vector3(180f, 0, 0));
        ground.transform.localScale = (new Vector3(1 / 3f, 1 / 3f, 1 / 3f));
    }
Beispiel #3
0
        static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs)
        {
            if (lhs == null || rhs == null)
            {
                return(new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects"));
            }

            string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect");

            ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs };

            UndoUtility.RecordSelection(sel, op_string);

            UnityEngine.ProBuilder.Csg.Model result;

            switch (operation)
            {
            case BooleanOperation.Union:
                result = Boolean.Union(lhs.gameObject, rhs.gameObject);
                break;

            case BooleanOperation.Subtract:
                result = Boolean.Subtract(lhs.gameObject, rhs.gameObject);
                break;

            default:
                result = Boolean.Intersect(lhs.gameObject, rhs.gameObject);
                break;
            }

            var            materials = result.materials.ToArray();
            ProBuilderMesh pb        = ProBuilderMesh.Create();

            pb.GetComponent <MeshFilter>().sharedMesh        = (Mesh)result;
            pb.GetComponent <MeshRenderer>().sharedMaterials = materials;
            MeshImporter importer = new MeshImporter(pb.gameObject);

            importer.Import(new MeshImportSettings()
            {
                quads = true, smoothing = true, smoothingAngle = 1f
            });
            pb.Rebuild();
            pb.CenterPivot(null);
            Selection.objects = new Object[] { pb.gameObject };

            return(new ActionResult(ActionResult.Status.Success, op_string));
        }
Beispiel #4
0
        internal static void SetPivot(this ProBuilderMesh mesh, PivotLocation pivotType, Vector3?pivotPosition = null)
        {
            if (mesh.vertexCount == 0)
            {
                return;
            }

            switch (pivotType)
            {
            case PivotLocation.Center:
                mesh.CenterPivot(null);
                break;

            case PivotLocation.FirstCorner:
                mesh.SetPivot(pivotPosition == null ? Vector3.zero : (Vector3)pivotPosition);
                break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// "ProBuilder-ize" function
        /// </summary>
        /// <param name="t"></param>
        /// <param name="preserveFaces"></param>
        /// <returns></returns>
        public static ProBuilderMesh CreateMeshWithTransform(Transform t, bool preserveFaces)
        {
            Mesh m = t.GetComponent <MeshFilter>().sharedMesh;

            Vector3[] m_vertices = MeshUtility.GetMeshChannel <Vector3[]>(t.gameObject, x => x.vertices);
            Color[]   m_colors   = MeshUtility.GetMeshChannel <Color[]>(t.gameObject, x => x.colors);
            Vector2[] m_uvs      = MeshUtility.GetMeshChannel <Vector2[]>(t.gameObject, x => x.uv);

            List <Vector3> verts = preserveFaces ? new List <Vector3>(m.vertices) : new List <Vector3>();
            List <Color>   cols  = preserveFaces ? new List <Color>(m.colors) : new List <Color>();
            List <Vector2> uvs   = preserveFaces ? new List <Vector2>(m.uv) : new List <Vector2>();
            List <Face>    faces = new List <Face>();

            for (int n = 0; n < m.subMeshCount; n++)
            {
                int[] tris = m.GetTriangles(n);
                for (int i = 0; i < tris.Length; i += 3)
                {
                    int index = -1;
                    if (preserveFaces)
                    {
                        for (int j = 0; j < faces.Count; j++)
                        {
                            if (faces[j].distinctIndexesInternal.Contains(tris[i + 0]) ||
                                faces[j].distinctIndexesInternal.Contains(tris[i + 1]) ||
                                faces[j].distinctIndexesInternal.Contains(tris[i + 2]))
                            {
                                index = j;
                                break;
                            }
                        }
                    }

                    if (index > -1 && preserveFaces)
                    {
                        int   len = faces[index].indexesInternal.Length;
                        int[] arr = new int[len + 3];
                        System.Array.Copy(faces[index].indexesInternal, 0, arr, 0, len);
                        arr[len + 0] = tris[i + 0];
                        arr[len + 1] = tris[i + 1];
                        arr[len + 2] = tris[i + 2];
                        faces[index].indexesInternal = arr;
                    }
                    else
                    {
                        int[] faceTris;

                        if (preserveFaces)
                        {
                            faceTris = new int[3]
                            {
                                tris[i + 0],
                                tris[i + 1],
                                tris[i + 2]
                            };
                        }
                        else
                        {
                            verts.Add(m_vertices[tris[i + 0]]);
                            verts.Add(m_vertices[tris[i + 1]]);
                            verts.Add(m_vertices[tris[i + 2]]);

                            cols.Add(m_colors != null ? m_colors[tris[i + 0]] : Color.white);
                            cols.Add(m_colors != null ? m_colors[tris[i + 1]] : Color.white);
                            cols.Add(m_colors != null ? m_colors[tris[i + 2]] : Color.white);

                            uvs.Add(m_uvs[tris[i + 0]]);
                            uvs.Add(m_uvs[tris[i + 1]]);
                            uvs.Add(m_uvs[tris[i + 2]]);

                            faceTris = new int[3] {
                                i + 0, i + 1, i + 2
                            };
                        }

                        faces.Add(
                            new Face(
                                faceTris,
                                n,
                                AutoUnwrapSettings.tile,
                                0,      // smoothing group
                                -1,     // texture group
                                -1,     // element group
                                true    // manualUV
                                ));
                    }
                }
            }

            GameObject go = (GameObject)Object.Instantiate(t.gameObject);

            go.GetComponent <MeshFilter>().sharedMesh = null;

            ProBuilderMesh pb = go.AddComponent <ProBuilderMesh>();

            pb.RebuildWithPositionsAndFaces(verts.ToArray(), faces.ToArray());

            pb.colorsInternal = cols.ToArray();
            pb.textures       = uvs;

            pb.gameObject.name = t.name;

            go.transform.position      = t.position;
            go.transform.localRotation = t.localRotation;
            go.transform.localScale    = t.localScale;

            pb.CenterPivot(null);

            return(pb);
        }
Beispiel #6
0
        public void CenterPivot()
        {
            m_pbMesh.CenterPivot(null);

            RaiseChanged(false, true);
        }