3. Function
$$
y=\frac{(\sin x-1)(\cos x-1)}{2+\sin 2 x}(x \in \mathbf{R})
$$

The maximum value is ( ).
(A) $\frac{\sqrt{2}}{2}$
(B) 1
(C) $\frac{1}{2}+\frac{\sqrt{2}}{2}$
(D) $\sqrt{2}$
3. B.

According to the problem, we have
$$
y=\frac{\sin x \cdot \cos x-(\sin x+\cos x)+1}{2+2 \sin x \cdot \cos x} .
$$

Let $t=\sin x+\cos x$
$$
=\sqrt{2} \sin \left(x+\frac{\pi}{4}\right) \in[-\sqrt{2}, \sqrt{2}] \text {. }
$$

Then $\sin x \cdot \cos x=\frac{1}{2}\left(1-t^{2}\right)$.
Thus, $y=\frac{\frac{1}{2}\left(t^{2}-1\right)-t+1}{2+\left(t^{2}-1\right)}=\frac{1}{2}-\frac{t}{t^{2}+1}$.
Let $g(t)=\frac{t}{t^{2}+1}(t \in[-\sqrt{2}, \sqrt{2}])$.
Therefore, $g^{\prime}(t)=\frac{1-t^{2}}{\left(t^{2}+1\right)^{2}}$.
By $g^{\prime}(t)=0$, we know $t=-1$ or 1 .
$$
\begin{array}{l}
\text { Also, } g(-\sqrt{2})=-\frac{\sqrt{2}}{3}, g(-1)=-\frac{1}{2}, \\
g(1)=\frac{1}{2}, g(\sqrt{2})=\frac{\sqrt{2}}{3},
\end{array}
$$

Thus, the minimum value of $g(t)$ is $g(-1)=-\frac{1}{2}$.
Therefore, the maximum value of $y$ is $\frac{1}{2}-\left(-\frac{1}{2}\right)=1$.