Viewport3D ModelVisuals3D 在 Canvas 内不可见

发布于 2024-09-30 18:37:32 字数 1074 浏览 6 评论 0原文

如果我将 viewport3D 放入 Canvas 中,我的 viewport3D 将不再可见。如果我删除 Canvas,则 Viewport3D 会再次可见。我做错了什么?

          <Canvas  Width="900" Height="524">
            <Viewport3D Name="mainViewport" ClipToBounds="True" HitTestVisible="False">
                        <Viewport3D.Camera>
                            <PerspectiveCamera 
                              FarPlaneDistance="3500"
                              LookDirection="0,0,1"
                              UpDirection="0,1,0"
                              NearPlaneDistance="1" 
                              Position="0,0,0" 
                              FieldOfView="66" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <AmbientLight Color="White" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
            </Canvas>

If I put viewport3D inside Canvas my viewport3D is not visible anymore. If I remove Canvas then Viewport3D is visible again. What I'm doing wrong?

          <Canvas  Width="900" Height="524">
            <Viewport3D Name="mainViewport" ClipToBounds="True" HitTestVisible="False">
                        <Viewport3D.Camera>
                            <PerspectiveCamera 
                              FarPlaneDistance="3500"
                              LookDirection="0,0,1"
                              UpDirection="0,1,0"
                              NearPlaneDistance="1" 
                              Position="0,0,0" 
                              FieldOfView="66" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <AmbientLight Color="White" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
            </Canvas>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-10-07 18:37:32

我认为 ViewPort3D 最终会位于 Canvas 的左上角,宽度和高度均为 0,因为 Canvas 永远不会拉伸其子项。尝试在您选择的位置添加 Canvas.Left 和 Canvas.Top,然后为 Viewport3D 添加宽度和高度。如果您希望 Viewport3D 始终填充可用空间,那么 Canvas 是错误的选择。

<Canvas Width="900" Height="524">
    <Viewport3D Canvas.Left="100"
                Canvas.Top="100"
                Width="200"
                Height="200"
                Name="mainViewport"
                ClipToBounds="True" 
                IsHitTestVisible="False">
        <Viewport3D.Camera>
            <PerspectiveCamera  
                        FarPlaneDistance="3500" 
                        LookDirection="0,0,1" 
                        UpDirection="0,1,0" 
                        NearPlaneDistance="1"  
                        Position="0,0,0"  
                        FieldOfView="66" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White" />
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Canvas>

I think the ViewPort3D will end up in the upper left corner of the Canvas with a Width and Height of 0 since Canvas never stretches its Children. Try to add Canvas.Left and Canvas.Top at the positioning of your choise and then add Width and Height for your Viewport3D. If you want your Viewport3D to always fill the available space then Canvas is the wrong way to go.

<Canvas Width="900" Height="524">
    <Viewport3D Canvas.Left="100"
                Canvas.Top="100"
                Width="200"
                Height="200"
                Name="mainViewport"
                ClipToBounds="True" 
                IsHitTestVisible="False">
        <Viewport3D.Camera>
            <PerspectiveCamera  
                        FarPlaneDistance="3500" 
                        LookDirection="0,0,1" 
                        UpDirection="0,1,0" 
                        NearPlaneDistance="1"  
                        Position="0,0,0"  
                        FieldOfView="66" />
        </Viewport3D.Camera>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White" />
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Canvas>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文