Viewport 3D WPF C#

馋奶兔 提交于 2019-12-08 04:32:31

问题


Can you please show how to set and save the background color of the viewport3D. Whenever I save no background is visible only model, I tried the grid but that gets everything in the grid? Any help will do?


回答1:


Viewport3D doesn't have a Background property so you need something behind it.

your approach using a Grid is right, you might want to use a Border to enforce the use of a single child.

 <Border Background="Green">
  <Viewport3D Width="640.0" Height="480.0" >
    <ModelVisual3D/>
  </Viewport3D>
</Border>

I assume you are using XamlWriter, XamlReader . Just save the border instead of the Viewport3D and everything inside the border will be saved as well.




回答2:


I have provided some code for this, please verify it.

<Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera Position="2,0,10" LookDirection="0.2,0.4,-1" FieldOfView="65" UpDirection="0,1,0">
                </PerspectiveCamera>
            </Viewport3D.Camera>
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <Model3DGroup>
                        <AmbientLight Color="#fff"/>
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D Positions="0,0,0 0,10,0 10,0,0 10,10,0"
                                                Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                                                TriangleIndices="0,2,1,1,2,3"/>
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial Brush="Red"/>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </Model3DGroup>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </Viewport3D>


来源:https://stackoverflow.com/questions/1841489/viewport-3d-wpf-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!