0

Viewport3d にビデオストリームを表示しようとしています。xaml 経由で MediaElement を追加すると、ビデオは問題なく再生されます。コード ビハインドでビデオを ModelVisual3D として追加しても、ビデオは機能します。ただし、ビデオをクラスに抽象化すると、ビデオが表示されなくなります。これは、Web ビデオ ファイルとローカル ビデオ ファイルの両方で発生します。x86 と 64 ビットの両方でコンパイルしてみました。この動作を修正する方法はありますか? なぜこうなった?

次のビューポートがあります。

<Viewport3D>
    <!-- Camera -->
    <Viewport3D.Camera>
        <PerspectiveCamera Position="0,0,100" LookDirection="0,0,-1" UpDirection="0,1,0" />
    </Viewport3D.Camera>

    <!-- Light -->
    <ModelVisual3D>
        <ModelVisual3D.Content>
            <AmbientLight Color="White" />
        </ModelVisual3D.Content>
    </ModelVisual3D>

    <!-- this doesn't work -->
    <mediaElementTest:VideoControl />

    <!-- but this does? -->
    <!--<ModelVisual3D>
        <ModelVisual3D.Content>
            <GeometryModel3D>

                <GeometryModel3D.Geometry>
                    <MeshGeometry3D 
                        Positions="-100,-100,0 100,-100,0 100,100,0 -100,100,0"
                        TextureCoordinates="0,1 1,1 1,0 0,0"
                        TriangleIndices="0 1 2   0 2 3"
                        />
                </GeometryModel3D.Geometry>

                <GeometryModel3D.Material>
                    <DiffuseMaterial>
                        <DiffuseMaterial.Brush>
                            <VisualBrush>
                                <VisualBrush.Visual>
                                    <MediaElement Source="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" />
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </DiffuseMaterial.Brush>
                    </DiffuseMaterial>
                </GeometryModel3D.Material>
            </GeometryModel3D>
        </ModelVisual3D.Content>
    </ModelVisual3D>-->
</Viewport3D>

VideoControl.xaml

<UIElement3D x:Class="MediaElementTest.VideoControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"/>

VideoControl.xaml.cs

public partial class VideoControl
{
    public VideoControl()
    {
        InitializeComponent();
        Visual3DModel = CreateModel();
    }

    private GeometryModel3D CreateModel()
    {
        return new GeometryModel3D
        {
            Geometry = new MeshGeometry3D
            {
                Positions = new Point3DCollection
                {
                    new Point3D(-100, -100, 0),
                    new Point3D(100, -100, 0),
                    new Point3D(100, 100, 0),
                    new Point3D(-100, 100, 0)
                },

                TextureCoordinates = new PointCollection
                {
                    new Point(0, 1),
                    new Point(1, 1),
                    new Point(1, 0),
                    new Point(0, 0)
                },

                TriangleIndices = new Int32Collection
                {
                    0, 1, 2,
                    0, 2, 3
                }
            },
            Material = new DiffuseMaterial(new VisualBrush(new MediaElement
            {
                Source = new Uri("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", UriKind.RelativeOrAbsolute)
            }))
        };
    }
}
4

1 に答える 1

0

ここで回答: MediaElement がカスタム 3D クラスに表示されない

あなたの問題については、根本的な原因は VideoControl の作成方法にあると思います。UIElement3D から継承する 3D プリミティブの基本クラスを作成し、デモとして機能する MediaElement 実装を作成する必要があります。これが私のサンプルです:

ReusableUIElement3D.cs:

public abstract class ReusableUIElement3D : UIElement3D
{
    public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof (Model3D),
        typeof (ReusableUIElement3D), new PropertyMetadata(ModelPropertyChanged));

    public Model3D Model
    {
        get
        {
            return (Model3D)GetValue(ModelProperty);
        }
        set
        {
            SetValue(ModelProperty, value);
        }
    }

    protected override void OnUpdateModel()
    {
        this.Model = this.CreateElementModel();
    }

    protected virtual Model3D CreateElementModel()
    {
        return null;
    }

    protected static void VisualPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ReusableUIElement3D reusableElement = (ReusableUIElement3D)d;
        reusableElement.InvalidateModel();
    }

    protected static void ModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ReusableUIElement3D reusableElement = (ReusableUIElement3D)d;
        reusableElement.Visual3DModel = reusableElement.Model;
    }
}

VideoControl.cs

public class VideoControl : ReusableUIElement3D
{
    protected override Model3D CreateElementModel()
    {
        Model3DGroup cubeModel = new Model3DGroup();
        cubeModel.Children.Add(CreateModel());
        return cubeModel;
    }

    private GeometryModel3D CreateModel()
    {
        return new GeometryModel3D
        {
            Geometry = new MeshGeometry3D
            {
                Positions = new Point3DCollection
            {
                new Point3D(-100, -100, 0),
                new Point3D(100, -100, 0),
                new Point3D(100, 100, 0),
                new Point3D(-100, 100, 0)
            },

                TextureCoordinates = new PointCollection
            {
                new Point(0, 1),
                new Point(1, 1),
                new Point(1, 0),
                new Point(0, 0)
            },

                TriangleIndices = new Int32Collection
            {
                0, 1, 2,
                0, 2, 3
            }
            },
            Material = new DiffuseMaterial(new VisualBrush(new MediaElement
            {
                Source = new Uri("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", UriKind.RelativeOrAbsolute),
            }))
        };
    }
}

VideoControl クラスを使用するには、次のようにします。

<Viewport3D>
    <!-- Camera -->
    <Viewport3D.Camera>
        <PerspectiveCamera Position="0,0,100" LookDirection="0,0,-1" UpDirection="0,1,0" />
    </Viewport3D.Camera>

    <!-- Light -->
    <ModelVisual3D>
        <ModelVisual3D.Content>
            <AmbientLight Color="White" />
        </ModelVisual3D.Content>
    </ModelVisual3D>

    <ModelVisual3D x:Name="UIElement3DContainer">
        <mediaElementTest:VideoControl />
    </ModelVisual3D>
</Viewport3D>
于 2014-05-30T09:20:14.513 に答える