Beispiel #1
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);
        }
        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];
                GameObject go = InternalUtility.EmptyGameObjectWithTransform(pb.transform);
                go.name = pb.name + "  (Vertex Billboards)";
                go.AddComponent <MeshFilter>().sharedMesh       = BuildVertexMesh(pb, map, ref index);
                go.AddComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.vertexPickerMaterial;
                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.EmptyGameObjectWithTransform(pb.transform);
                    go.name = pb.name + "  (Depth Mask)";
                    go.AddComponent <MeshFilter>().sharedMesh       = pb.mesh;
                    go.AddComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.facePickerMaterial;
                    depthObjects[i] = go;
                }
            }
            else
            {
                depthObjects = null;
            }
        }
        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];
                GameObject go = InternalUtility.EmptyGameObjectWithTransform(pb.transform);
                go.name = pb.name + "  (Edge Billboards)";
                go.AddComponent <MeshFilter>().sharedMesh       = BuildEdgeMesh(pb, map, ref index);
                go.AddComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.edgePickerMaterial;
                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.EmptyGameObjectWithTransform(pb.transform);
                    go.name = pb.name + "  (Depth Mask)";
                    go.AddComponent <MeshFilter>().sharedMesh       = pb.mesh;
                    go.AddComponent <MeshRenderer>().sharedMaterial = BuiltinMaterials.facePickerMaterial;
                    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);
        }