English 中文(简体)
从 3D 元素 WPF 内部查看
原标题:View from inside of 3d element WPF
  • 时间:2012-05-24 09:18:50
  •  标签:
  • wpf
  • 3d
  • camera

Im using SphereMeshGenerator to create a sphere element in a WPF application. This sphere is mapped with a media element (video).

我想把摄像机放在球体中间 从球体内部查看

Ive tried to play with camera position and direction without any success. My knowledge about wpf and 3d are quite limited unfortunately.

所以,我的问题是,如果可能,如何做到这一点?

我的目标是模仿全景的视频动画。

谢谢

PS:这个问题已经提出,但仍未答复。

Link page

最佳回答

话题很旧,但是,因为这样可以帮助 处于同样情况下的其他人, 我认为我必须发布 这样做的方式。

使用 SphereMeshGenerator 的代码 XAML 代码 :

<Window x:Class="WpfSphereMeshGenerator.SphereMeshGeneratorMediaInto"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfSphereMeshGenerator"
    Title="SphereMeshGeneratorMediaInto" 
    Height="300" Width="300"
    Loaded="Window_Loaded">

<!-- OXYZ axis in WPF are in center of ViewPort3D-->

<Window.Resources>
  <!--sphere diameter--> 
    <local:SphereMeshGenerator 
    x:Key="MySphereMeshGenerator"
    Center="0 0 0"
    Radius="100.0" />
</Window.Resources>
<Grid>
    <Viewport3D>
        <!--camera in center of ViewPort => 0,0,0-->  
        <Viewport3D.Camera>
            <PerspectiveCamera 
                    x:Name="Camera"
                    UpDirection="0,1,0"
                    LookDirection="-2,-2,-2"
                    Position="0,0,0" 
                    FieldOfView="100" >

            </PerspectiveCamera>
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight 
                        Color="White">
                </AmbientLight >
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <!--ModelVisualD by default in center of ViewPort-->
        <ModelVisual3D
            x:Name="ModelA">
            <ModelVisual3D.Content>
                <GeometryModel3D 
                        Geometry="{Binding 
                        Source={StaticResource 
                        MySphereMeshGenerator}, 
                        Path=Geometry}">
                    <!--turn sphere-->
                    <GeometryModel3D.Transform>
                        <RotateTransform3D >
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D
                                            x:Name="Rotate"
                                            Axis="0,1,0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </GeometryModel3D.Transform>
                    <!--video put on BackMaterial-->
                    <!--inside face-->
                    <GeometryModel3D.BackMaterial>
                        <DiffuseMaterial>
                            <DiffuseMaterial.Brush>
                                <VisualBrush>
                                    <VisualBrush.Visual>
                                        <MediaElement>
                                            <MediaElement.Triggers>
                                                <EventTrigger RoutedEvent="MediaElement.Loaded">
                                                    <EventTrigger.Actions>
                                                        <BeginStoryboard>
                                                            <Storyboard>
                                                                <MediaTimeline 
                                                                    x:Name="mediaTimeline"
                                                                    RepeatBehavior="Forever" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </EventTrigger.Actions>
                                                </EventTrigger>
                                            </MediaElement.Triggers>
                                        </MediaElement>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.BackMaterial>
                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Grid>
<Window.Triggers>
    <EventTrigger  
        RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation
                    Storyboard.TargetName="Rotate"
                    Storyboard.TargetProperty="Angle"
                    From="0" To="360" Duration="0:0:10"
                    RepeatBehavior="Forever">
                </DoubleAnimation>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>

向美宝基求救

问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签