WPF 3D 上での画像とビデオの表示

イメージ部分を抜き出したもの

image 

<GeometryModel3D.Material>
    <DiffuseMaterial>
        <DiffuseMaterial.Brush>
            <ImageBrush ImageSource="bobsled.jpg"></ImageBrush>
        </DiffuseMaterial.Brush>
    </DiffuseMaterial>
</GeometryModel3D.Material>
<GeometryModel3D.Geometry>
    <MeshGeometry3D
        TriangleIndices="0 1 2  0 2 3 "
        Positions="0 0 0,  1 0 0, 1 1 0, 0 1 0"
        TextureCoordinates="0,1 1,1 1,0 0,0 "
        Normals="0,0,1 0,0,1 0,0,1 0,0,1"
    />
</GeometryModel3D.Geometry>

ビデオ部分を抜き出したもの

image 

<GeometryModel3D.Material>
    <DiffuseMaterial>
        <DiffuseMaterial.Brush>
            <VisualBrush>
                <VisualBrush.Visual>
                    <MediaElement Source="wildlife.wmv" />
                </VisualBrush.Visual>
            </VisualBrush>

        </DiffuseMaterial.Brush>
    </DiffuseMaterial>
</GeometryModel3D.Material>
<GeometryModel3D.Geometry>
    <MeshGeometry3D
        TriangleIndices="0 1 2  0 2 3 "
        Positions="0 0 0,  1 0 0, 1 1 0, 0 1 0"
        TextureCoordinates="0,1 1,1 1,0 0,0 "
        Normals="0,0,1 0,0,1 0,0,1 0,0,1"
    />
</GeometryModel3D.Geometry>

WPF覚書

image

サンプルコード

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="WpfApplication2.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480" mc:Ignorable="d">

<Viewport3D xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006" c:Ignorable="d" x:Name="ZAM3DViewport3D" ClipToBounds="true" Width="400" Height="300">
    <Viewport3D.Camera>
        <PerspectiveCamera x:Name="Free_CameraOR6" FarPlaneDistance="10" LookDirection="0,0,-1" UpDirection="0,1,0" NearPlaneDistance="1" Position="0,0.0199925,2.5" FieldOfView="39.5978" />
    </Viewport3D.Camera>

    <ModelVisual3D>
        <ModelVisual3D.Content>
            <Model3DGroup x:Name="Scene"> <!– Scene (XAML Path = ) –>
                <Model3DGroup.Transform>
                    <Transform3DGroup>
                        <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                        <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                        <RotateTransform3D d:EulerAngles="0,27.919,0">
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D Angle="27.919" Axis="0,1,0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                        <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                        <TranslateTransform3D OffsetY="0.401" OffsetX="-0.446" OffsetZ="0.052"/>
                    </Transform3DGroup>
                </Model3DGroup.Transform>
                <AmbientLight Color="#333333" />
                <DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
                <DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" />
                <Model3DGroup x:Name="BoxOR9"> <!– Box (XAML Path = (Viewport3D.Children)[0].(ModelVisual3D.Content).(Model3DGroup.Children)[3]) –>
                    <Model3DGroup.Transform>
                        <Transform3DGroup>
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                            <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                            <RotateTransform3D>
                                <RotateTransform3D.Rotation>
                                    <AxisAngleRotation3D Angle="65.59121363" Axis="0.1478755617 0.6791817096 0.7189193443"/>
                                </RotateTransform3D.Rotation>
                            </RotateTransform3D>
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                        </Transform3DGroup>
                    </Model3DGroup.Transform>
                    <GeometryModel3D x:Name="BoxOR9GR10">
                        <GeometryModel3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <VisualBrush>
                                        <VisualBrush.Visual>
                                            <MediaElement Source="wildlife.wmv" />
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                                TriangleIndices="0 1 2  0 2 3 "
                                Positions="0 0 0,  1 0 0, 1 1 0, 0 1 0"
                                TextureCoordinates="0,1 1,1 1,0 0,0 "
                                Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                            />
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Transform>
                            <Transform3DGroup>
                                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                                <RotateTransform3D d:EulerAngles="-4.454,-33.326,-46.125">
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D Angle="57.575" Axis="-0.304,-0.517,-0.8"/>
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                                <TranslateTransform3D OffsetX="-1.015" OffsetY="-0.317" OffsetZ="0.226"/>
                            </Transform3DGroup>
                        </GeometryModel3D.Transform>
                    </GeometryModel3D>
                </Model3DGroup>
            </Model3DGroup>
        </ModelVisual3D.Content>
    </ModelVisual3D>
</Viewport3D>
</Window>

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です