我在Viewport3D中有一个模型,我想在它旁边绘制一个文本框,文本框可以将“常规”控件添加到Viewport3D吗?
答案 0 :(得分:2)
在XAML下面,我在水平堆栈面板中创建了一个带有一些2D控件,文本块和文本框的Viewport3D,您正在寻找的控件是Viewport2DVisual3D,您需要描述它的几何和材质但是之后,它将在世界空间中使用。
Viewport2DVisual3D控件的最佳之处在于它将鼠标操作重新投射回世界空间,这意味着您放置在视口中的控件仍然可用,就像它们是以2D绘制一样。
<Viewport3D>
<!-- To look in to a 3D world you need a camera just like a game.-->
<Viewport3D.Camera>
<!--
I've positioned the camera at the center of the world and moved it back
Along the Z axis, try changing the numbers here to see how it works.
-->
<PerspectiveCamera Position="0, 0, 3"/>
</Viewport3D.Camera>
<!-- All 3D worlds need to have a light, you can again play with the values
here to see what they mean, Directional light is one that starts at a
location in the world and shines in a given direction.
-->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="0,0,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<!--
This is the wonder control that allows you to display WPF controls
in a 3D model.
-->
<Viewport2DVisual3D >
<!--
The 3D model is made up of a vertex list, each grouping of 3 digits
in the positions property is a point on a polygon, here I've used
4 points to represent a flat square surface (2 triangles to make the square)
and relate to a bitmap produced from your WPF controls
Triangle TriangleIndices map positions in to triangles, here I've got
1 2 imagine a triangle drawn through points 0, 1, 2
and another drawn from 0, 2 and 3
0 3
The texture coords tell the 3D viewport how to map your controls visual to the
points in positions, texture coordinates range from 0,0 top left to 1,1 bottom right
-->
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0" TriangleIndices="0 1 2 0 2 3" TextureCoordinates="0,0 0,1 1,1 1,0"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
</Viewport2DVisual3D.Material>
<!-- Here I'm doing a transform, it's the same as simply rotating a control using it's render transform
in WPF
-->
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<!-- Play around with the Axis numbers to see what they mean.-->
<AxisAngleRotation3D Angle="-45" Axis="1, 0, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform>
<!-- This is the 2D bit, inside the visual property you can place any WPF controls. -->
<Viewport2DVisual3D.Visual>
<StackPanel Orientation="Horizontal">
<!-- This bit is obvious. -->
<TextBlock Text="3D user interface!"/>
<TextBox />
</StackPanel>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
</Viewport3D>
答案 1 :(得分:0)
您可以简单地在Viewport3D上方放置一个画布:
<Grid>
<Viewport3D>
[..]
</Viewport3D>
<Canvas>
<TextBox />
</Canvas>
</Grid>
这取决于你想要做什么。