Exemple #1
0
        private static void DrawGizmoVolume(DecalVolume decal, GizmoType gizmoType)
        {
            if (gizmoType != (GizmoType.Selected | GizmoType.InSelectionHierarchy | GizmoType.Active))
            {
                return;
            }

            //
            //  Uncomment this for debug affected bounds of volume.
            //
            //Gizmos.color = Color.red;
            //Bounds bounds = decal.GetBounds();
            //Gizmos.DrawWireCube(bounds.center, bounds.size);

            Vector3 pos = decal.transform.position;

            Gizmos.matrix = Matrix4x4.TRS(pos, decal.transform.rotation, Vector3.one);

            var color = DecalVolume.EditorColor;

            color.a      = 0.25f;
            Gizmos.color = color;

            Gizmos.DrawCube(decal.Origin, decal.Size);
        }
Exemple #2
0
        public static Mesh Create(DecalVolume decal, float surfaceMaxAngle, float surfaceDistance, float smoothAngle)
        {
            var pols      = new List <Polygon>();
            var transform = decal.transform;
            var bounds    = decal.GetBounds();

            GameObject[] affectedList = decal.GetGameObjectsInBounds(decal.Layer);
            Terrain[]    terrains     = Terrain.activeTerrains;

            for (int i = 0, count = terrains.Length; i < count; i++)
            {
                if ((1 << terrains[i].gameObject.layer & decal.Layer) == 0)
                {
                    continue;
                }

                Vector3 terrainPos    = terrains[i].GetPosition();
                Vector3 terrainSize   = terrains[i].terrainData.size;
                var     terrainBounds = new Bounds(terrainPos + terrainSize * 0.5f, terrainSize);

                if (bounds.Intersects(terrainBounds) == false)
                {
                    continue;
                }
                pols.AddRange(CreateFromTerrain(terrains[i], terrainPos, terrainSize, bounds, decal, surfaceMaxAngle));
            }

            pols.AddRange(CreateFromObjects(affectedList, decal, surfaceMaxAngle));

            Mesh mesh = CreateMesh(pols, true);

            var verts = mesh.vertices;

            for (int i = 0, count = verts.Length; i < count; i++)
            {
                verts[i] = transform.InverseTransformPoint(verts[i]);
            }
            mesh.vertices = verts;

            mesh.vertices = PushMesh(mesh, surfaceDistance);
            mesh.uv       = CreateUVs(mesh.vertices, decal.Volume, decal.Sprite);
            mesh.name     = "Decal Mesh";

            mesh.RecalculateBounds();
            mesh.RecalculateNormals();

            return(mesh);
        }