Ejemplo n.º 1
0
        static void GenerateVertexPickingObjects(
            IList <ProBuilderMesh> selection,
            bool doDepthTest,
            out Dictionary <uint, SimpleTuple <ProBuilderMesh, int> > map,
            out GameObject[] depthObjects,
            out GameObject[] pickerObjects)
        {
            map = new Dictionary <uint, SimpleTuple <ProBuilderMesh, int> >();

            // don't start at 0 because that means one vertex would be black, matching
            // the color used to cull hidden vertices.
            uint index          = 0x02;
            int  selectionCount = selection.Count;

            pickerObjects = new GameObject[selectionCount];

            for (int i = 0; i < selectionCount; i++)
            {
                // build vertex billboards
                var pb = selection[i];

                var        mesh = BuildVertexMesh(pb, map, ref index);
                GameObject go   = InternalUtility.MeshGameObjectWithTransform(pb.name + " (Vertex Billboards)", pb.transform, mesh,
                                                                              BuiltinMaterials.vertexPickerMaterial, true);

                pickerObjects[i] = go;
            }

            if (doDepthTest)
            {
                depthObjects = new GameObject[selectionCount];

                // copy the select gameobject just for z-write
                for (int i = 0; i < selectionCount; i++)
                {
                    var pb = selection[i];

                    GameObject go = InternalUtility.MeshGameObjectWithTransform(pb.name + " (Depth Mask)", pb.transform, pb.mesh,
                                                                                BuiltinMaterials.facePickerMaterial, true);

                    depthObjects[i] = go;
                }
            }
            else
            {
                depthObjects = null;
            }
        }
Ejemplo n.º 2
0
        public static GameObject MeshGameObjectWithTransform(string name, Transform t, Mesh mesh, Material mat, bool inheritParent)
        {
            GameObject go = InternalUtility.EmptyGameObjectWithTransform(t);

            go.name = name;
            go.AddComponent <MeshFilter>().sharedMesh       = mesh;
            go.AddComponent <MeshRenderer>().sharedMaterial = mat;
            go.hideFlags = HideFlags.HideAndDontSave;

            if (inheritParent)
            {
                go.transform.SetParent(t.parent, false);
            }

            return(go);
        }
Ejemplo n.º 3
0
        static void GenerateEdgePickingObjects(
            IList <ProBuilderMesh> selection,
            bool doDepthTest,
            out Dictionary <uint, SimpleTuple <ProBuilderMesh, Edge> > map,
            out GameObject[] depthObjects,
            out GameObject[] pickerObjects)
        {
            map = new Dictionary <uint, SimpleTuple <ProBuilderMesh, Edge> >();

            uint index          = 0x2;
            int  selectionCount = selection.Count;

            pickerObjects = new GameObject[selectionCount];

            for (int i = 0; i < selectionCount; i++)
            {
                // build edge billboards
                var pb = selection[i];

                var        mesh = BuildEdgeMesh(pb, map, ref index);
                GameObject go   = InternalUtility.MeshGameObjectWithTransform(pb.name + " (Edge Billboards)", pb.transform, mesh,
                                                                              BuiltinMaterials.edgePickerMaterial, true);

                pickerObjects[i] = go;
            }

            if (doDepthTest)
            {
                depthObjects = new GameObject[selectionCount];

                for (int i = 0; i < selectionCount; i++)
                {
                    var pb = selection[i];

                    // copy the select gameobject just for z-write
                    GameObject go = InternalUtility.MeshGameObjectWithTransform(pb.name + " (Depth Mask)", pb.transform, pb.mesh,
                                                                                BuiltinMaterials.facePickerMaterial, true);

                    depthObjects[i] = go;
                }
            }
            else
            {
                depthObjects = null;
            }
        }
        static GameObject[] GenerateFacePickingObjects(
            IList <ProBuilderMesh> selection,
            out Dictionary <uint, SimpleTuple <ProBuilderMesh, Face> > map)
        {
            int selectionCount = selection.Count;

            GameObject[] pickerObjects = new GameObject[selectionCount];
            map = new Dictionary <uint, SimpleTuple <ProBuilderMesh, Face> >();

            uint index = 0;

            for (int i = 0; i < selectionCount; i++)
            {
                var pb = selection[i];

                GameObject go = InternalUtility.EmptyGameObjectWithTransform(pb.transform);
                go.name = pb.name + " (Face Depth Test)";

                Mesh m = new Mesh();
                m.vertices  = pb.positionsInternal;
                m.triangles = pb.facesInternal.SelectMany(x => x.indexesInternal).ToArray();
                Color32[] colors = new Color32[m.vertexCount];

                foreach (Face f in pb.facesInternal)
                {
                    Color32 color = EncodeRGBA(index++);
                    map.Add(DecodeRGBA(color), new SimpleTuple <ProBuilderMesh, Face>(pb, f));

                    for (int n = 0; n < f.distinctIndexesInternal.Length; n++)
                    {
                        colors[f.distinctIndexesInternal[n]] = color;
                    }
                }

                m.colors32 = colors;

                go.AddComponent <MeshFilter>().sharedMesh       = m;
                go.AddComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.facePickerMaterial;

                pickerObjects[i] = go;
            }

            return(pickerObjects);
        }