C# 如何在wpf 3d多维数据集中插入2d控件

C# 如何在wpf 3d多维数据集中插入2d控件,c#,.net,wpf,vb.net,xaml,C#,.net,Wpf,Vb.net,Xaml,我在WPF中使用Viewport3D创建了一个3d立方体。我在视口内创建了6个GeometryModel3D,因为我想在每个面上显示不同的内容。我想在其中一个面(正面)上插入一个userinteractice按钮控件多维数据集的。我知道我们应该使用Viewport2DVisual3D实现此目的。但我无法找到如何使用Viewport2DVisual3D在面上插入2ndd控件的解决方案。请帮助我。以下是我迄今为止编写的Xamal代码: <Grid> <Viewpor

我在WPF中使用Viewport3D创建了一个3d立方体。我在视口内创建了6个GeometryModel3D,因为我想在每个面上显示不同的内容。我想在其中一个面(正面)上插入一个userinteractice按钮控件多维数据集的。我知道我们应该使用Viewport2DVisual3D实现此目的。但我无法找到如何使用Viewport2DVisual3D在面上插入2ndd控件的解决方案。请帮助我。以下是我迄今为止编写的Xamal代码:

<Grid>
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera Position="0,0,25" LookDirection="15,6,-50" />
            </Viewport3D.Camera>

            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <!--<AmbientLight Color="White" />-->
                    <SpotLight Color="White" InnerConeAngle="20" OuterConeAngle="60" Direction="15,6,-50" Position="0,0,25" />
                </ModelVisual3D.Content>
            </ModelVisual3D>

            <ModelVisual3D>

                <ModelVisual3D.Content>

                    <Model3DGroup>


                                <!-- front -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                                Positions="0 0 0, 10 0 0, 0 16 0, 10 16 0, 10 0 0"
                                TriangleIndices="0, 1, 2, 2, 4, 3"
                                TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"
                                />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="White"/>

                            </GeometryModel3D.Material>

                            <Viewport2DVisual3D>

                                <StackPanel>   
                                <Button>Hello, 3D</Button>
                                 </StackPanel>
                            </Viewport2DVisual3D>

                        </GeometryModel3D>


                        <!-- left -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="0 0 -.5, 0 0 0, 0 14 -.5, 0 14 0, 0 0 0"
                            TriangleIndices="0, 1, 2, 2, 4, 3" />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial Brush="{StaticResource side}" />
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>

                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="0 14 -4, 0 14 0, 0 16 -4, 0 16 0, 0 14 0"
                            TriangleIndices="0, 1, 2, 2, 4, 3" />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial Brush="{StaticResource top}" />
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>

                        <!-- right  -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="10 0 0, 10 0 -.5, 10 16 0, 10 16 -.5, 10 0 -.5"
                            TriangleIndices="0, 1, 2, 2, 4, 3" />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial Brush="{StaticResource top}" />
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>


                        <!-- top side -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="0 16 0, 0 16 -.5, 10 16 0, 10 16 -.5, 0 16 -.5"
                            TriangleIndices="0, 2, 1, 2, 3, 4"
                                TextureCoordinates="0 1, 0 0, 1 1, 1 0, 0 0"
                                />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial Brush="{StaticResource pages}" />
                                </MaterialGroup>

                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>

                        <!-- bottom -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="0 0 0, 0 0 -.5, 10 0 0, 10 0 -.5, 0 0 -.5"
                            TriangleIndices="0, 1, 2, 2, 4, 3"
                                TextureCoordinates="0 1, 0 0, 1 1, 1 0, 0 0"
                                />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="{StaticResource pages}" />
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>

                        <!-- back -->
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D
                            Positions="0 0 -.5, 10 0 -.5, 0 16 -.5, 10 16 -.5, 10 0 -.5"
                            TriangleIndices="0, 2, 1, 2, 3, 4" />
                            </GeometryModel3D.Geometry>

                            <GeometryModel3D.Material>
                                <MaterialGroup>
                                    <DiffuseMaterial Brush="{StaticResource back}" />
                                </MaterialGroup>
                            </GeometryModel3D.Material>
                            <GeometryModel3D.BackMaterial>
                                <DiffuseMaterial Color="Blue" />
                            </GeometryModel3D.BackMaterial>
                        </GeometryModel3D>




                    </Model3DGroup>

                </ModelVisual3D.Content>
            </ModelVisual3D>

        </Viewport3D>
    </Grid>

你好,3D

您在这里做错了几件事。Viewport2DVisual3D不在GeometryModel3D中,而是替换它。这也意味着您必须将其拉到Model3DGroup之外。最后,您需要设置
Viewport2DVisual3D.IsVisualHostMaterial
,以便WPF也知道如何对二维元素使用画笔。这应该足以让您开始:

<Grid>
    <Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="-10,0,50" LookDirection="15,10,-50" />
        </Viewport3D.Camera>

        <ModelVisual3D>
            <ModelVisual3D.Content>
                <!--<AmbientLight Color="White" />-->
                <SpotLight Color="White" InnerConeAngle="20" OuterConeAngle="60" Direction="15,6,-50" Position="0,0,25" />
            </ModelVisual3D.Content>
        </ModelVisual3D>


        <!-- front -->
        <Viewport2DVisual3D>
            <Viewport2DVisual3D.Geometry>
                <MeshGeometry3D
                            Positions="0 0 0, 10 0 0, 0 16 0, 10 16 0, 10 0 0"
                            TriangleIndices="0, 1, 2, 2, 4, 3"
                            TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"
                            />
            </Viewport2DVisual3D.Geometry>

            <Viewport2DVisual3D.Material>
                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
            </Viewport2DVisual3D.Material>

            <StackPanel>
                <Button>Hello, 3D</Button>
            </StackPanel>

        </Viewport2DVisual3D>

    </Viewport3D>
</Grid>


谢谢…但我希望这个按钮在立方体表面上,这样每当用户旋转立方体时,这个按钮就会粘在立方体表面上并旋转