Esempio n. 1
0
        private pb_Renderable BuildEdgeMesh(pb_Object pb, pb_Edge[] universalEdgesDistinct)
        {
            Vector3[]     pbverts       = pb.vertices;
            pb_IntArray[] sharedIndices = pb.sharedIndices;

            int vertexCount = System.Math.Min(universalEdgesDistinct.Count() * 2, pb_Constant.MAX_VERTEX_COUNT);

            Vector3[] edge_verts = new Vector3[vertexCount];

            int n = 0;

            for (int i = 0; i < vertexCount / 2; i++)            // (pb_Edge e in universalEdgesDistinct)
            {
                edge_verts[n++] = pbverts[sharedIndices[universalEdgesDistinct[i].x][0]];
                edge_verts[n++] = pbverts[sharedIndices[universalEdgesDistinct[i].y][0]];
            }

            pb_Renderable ren = pool.Get();

            ren.name      = "Wireframe Renderable";
            ren.materials = new Material[] { wireframeMaterial };
            ren.transform = pb.transform;
            ren.mesh.name = "Wireframe Mesh";
            ren.mesh.Clear();
            ren.mesh.vertices = edge_verts;
#if !UNITY_5
            ren.mesh.normals = edge_verts;              // appease unity 4
            ren.mesh.uv      = new Vector2[edge_verts.Length];
#endif
            ren.mesh.subMeshCount = 1;
            ren.mesh.SetIndices(SequentialTriangles(edge_verts.Length), MeshTopology.Lines, 0);

            return(ren);
        }
Esempio n. 2
0
        public static pb_Renderable CreateInstance(Mesh InMesh, Material InMaterial)
        {
            pb_Renderable ren = ScriptableObject.CreateInstance <pb_Renderable>();

            ren.mesh      = InMesh;
            ren.materials = new Material[] { InMaterial };
            return(ren);
        }
Esempio n. 3
0
        /**
         * Create a new pb_Renderable with an empty mesh and no materials.
         */
        public static pb_Renderable CreateInstance()
        {
            pb_Renderable ren = CreateInstance(new Mesh(), (Material)null);

            ren.mesh.name      = "pb_Renderable::Mesh";
            ren.mesh.hideFlags = HideFlags.DontSave;
            ren.mesh.MarkDynamic();
            ren.hideFlags = HideFlags.DontSave;

            // ren.hideFlags = PB_EDITOR_GRAPHIC_HIDE_FLAGS;
            // ren.mesh.hideFlags = PB_EDITOR_GRAPHIC_HIDE_FLAGS;
            return(ren);
        }
Esempio n. 4
0
        /**
         * Populate a renderable's mesh with a face highlight mesh matching the selected triangles array.
         */
        private pb_Renderable BuildFaceMesh(pb_Object pb)
        {
            int[] selectedTriangles = pb_Face.AllTriangles(pb.SelectedFaces);

            Vector3[] v = pbUtil.ValuesWithIndices(pb.vertices, selectedTriangles);

            pb_Renderable ren = pool.Get();

            ren.name      = "Faces Renderable";
            ren.transform = pb.transform;
            ren.materials = new Material[] { faceMaterial };

            ren.mesh.Clear();
            ren.mesh.vertices = v;
            ren.mesh.normals  = v;
#if UNITY_5
            ren.mesh.uv = null;
#else
            ren.mesh.uv = new Vector2[v.Length];
#endif
            ren.mesh.triangles = SequentialTriangles(v.Length);

            return(ren);
        }
Esempio n. 5
0
        /**
         * Populate a rendereble's mesh with a spattering of vertices representing both selected and not selected.
         */
        private pb_Renderable BuildVertexMesh(pb_Object pb)
        {
            int vcount = 0;

            Vector3[]     v        = new Vector3[pb.sharedIndices.Length];
            HashSet <int> selected = new HashSet <int>(pb.sharedIndices.GetUniversalIndices(pb.SelectedTriangles));

            for (int i = 0; i < v.Length; i++)
            {
                v[i] = pb.vertices[pb.sharedIndices[i][0]];
            }

            Vector3[] t_billboards = new Vector3[v.Length * 4];
            Vector3[] t_nrm        = new Vector3[v.Length * 4];
            Vector2[] t_uvs        = new Vector2[v.Length * 4];
            Vector2[] t_uv2        = new Vector2[v.Length * 4];
            Color[]   t_col        = new Color[v.Length * 4];
            int[]     t_tris       = new int[v.Length * 6];

            int n = 0;
            int t = 0;

            Vector3 up    = Vector3.up;         // * .1f;
            Vector3 right = Vector3.right;      // * .1f;

            for (int i = 0; i < v.Length; i++)
            {
                t_billboards[t + 0] = v[i];              //-up-right;
                t_billboards[t + 1] = v[i];              //-up+right;
                t_billboards[t + 2] = v[i];              //+up-right;
                t_billboards[t + 3] = v[i];              //+up+right;

                t_uvs[t + 0] = Vector3.zero;
                t_uvs[t + 1] = Vector3.right;
                t_uvs[t + 2] = Vector3.up;
                t_uvs[t + 3] = Vector3.one;

                t_uv2[t + 0] = -up - right;
                t_uv2[t + 1] = -up + right;
                t_uv2[t + 2] = up - right;
                t_uv2[t + 3] = up + right;

                t_nrm[t + 0] = Vector3.forward;
                t_nrm[t + 1] = Vector3.forward;
                t_nrm[t + 2] = Vector3.forward;
                t_nrm[t + 3] = Vector3.forward;

                t_tris[n + 0] = t + 0 + vcount;
                t_tris[n + 1] = t + 1 + vcount;
                t_tris[n + 2] = t + 2 + vcount;
                t_tris[n + 3] = t + 1 + vcount;
                t_tris[n + 4] = t + 3 + vcount;
                t_tris[n + 5] = t + 2 + vcount;

                if (selected.Contains(i))
                {
                    t_col[t + 0] = vertSelectionColor;
                    t_col[t + 1] = vertSelectionColor;
                    t_col[t + 2] = vertSelectionColor;
                    t_col[t + 3] = vertSelectionColor;

                    t_nrm[t].x     = .1f;
                    t_nrm[t + 1].x = .1f;
                    t_nrm[t + 2].x = .1f;
                    t_nrm[t + 3].x = .1f;
                }
                else
                {
                    t_col[t + 0] = vertexDotColor;
                    t_col[t + 1] = vertexDotColor;
                    t_col[t + 2] = vertexDotColor;
                    t_col[t + 3] = vertexDotColor;
                }

                t += 4;
                n += 6;
            }

            pb_Renderable ren = pool.Get();

            ren.name      = "Vertex Renderable";
            ren.transform = pb.transform;
            ren.materials = new Material[] { vertexMaterial };
            ren.mesh.Clear();
            ren.mesh.vertices  = t_billboards;
            ren.mesh.normals   = t_nrm;
            ren.mesh.uv        = t_uvs;
            ren.mesh.uv2       = t_uv2;
            ren.mesh.colors    = t_col;
            ren.mesh.triangles = t_tris;

            return(ren);
        }