This README gives a brief overview of the major classes used to enable
interactive 2D on 3D, a high level overview of how it works,
as well as a list of known issues and changes that can be made to get
around them.
---------------
Class Overview:
---------------
There are three main classes that are used to enable interacting with 2D
content on 3D objects: Viewport3DDecorator, Interactive3DDecorator and
InteractiveVisual3D. As a client of the 2D on 3D code, only Interactive3DDecorator
and InteractiveVisual3D need to be used. These three classes are explained next.
Viewport3DDecorator:
--------------------
The Viewport3DDecorator is used to extend the functionality of a Viewport3D.
It does so by allowing UIElements to be placed in front of and behind the
Viewport3D that is being decorated. This enables, for instance, the
Interactive3DDecorator to place its hidden layer on top of the Viewport3D it
is decorating, or the trackball to put a pane of glass beneath the Viewport3D
it is decorating, so it can be notified when the mouse is clicked within
the bounds of the Viewport3D. The UIElements that occur in front of and behind the
Viewport3D are exposed via the PreViewportChildren and PostViewportChildren dependency
properties. The Viewport3D or Viewport3DDecorator that is decorated is exposed
via the Content property of the class. The class takes care of laying out all
of its children, but this can be overridden by derived classes if desired.
Interactive3DDecorator:
-----------------------
The Interactive3DDecorator is a subclass of the Viewport3DDecorator, and uses
its PostViewportChildren property to position the hidden visual layer which
actually provides the interaction. This class provides interactivity to a Viewport3D.
In XAML, the Interactive3DDecorator is used as follows:
<local:Interactive3DDecorator>
<Viewport3D>
</Viewport3D>
</local:Interactive3DDecorator>
InteractiveVisual3D:
--------------------
The final class, the InteractiveVisual3D, is used to create the interactive 3D content
and also to signal to the Interactive3DDecorator that this Visual3D is intended to
be interacted with. InteractiveVisual3D is a subclass of ModelVisual3D and provides
the following dependency properties:
Geometry - The Geometry3D that is to become the content of the InteractiveVisual3D.
Visual The Visual that is to be used in a VisualBrush, which will then
be used in a material for the geometry for the InteractiveVisual3D.
Material A user specified material, with the IsInteractiveMaterial attached
property being used to mark the locations where the user wants the
VisualBrush used to represent the Visual, to be placed. By default,
a DiffuseMaterial is used.
IsBackVisible Indicates whether the material used for the front face should also be
mirrored on the back face.
The first two properties, Geometry and Visual, are the primary ones needed. They allow
the geometry for the Visual3D to be set, as well as the Visual that should appear on that
geometry. Note: the texture coordinates used for the Geometry must be in the range
(0,0) to (1,1) to enable interaction with the Visual. If they are outside this range, the
user will be interacting outside of the bounds of the Visual.
The others allow for fine tuning of the objects appearance. The Material property allows
a user to create their own material for the object. Because there potentially need to be
things added above the Visual specified by the user, and because parameters of the
VisualBrush are modified, the user does not directly specify the VisualBrush used. Instead,
they specify using the IsInteractiveMaterial attached property, which material they wish to
make interactive (i.e. set the VisualBrush created using the passed in Visual as the
Brush for that material). As an example, the following code sets the material to be composed
of a DiffuseMaterial, which will contain the visual brush, and a SpecularMaterial.
<local:InteractiveVisual3D.Material>
<MaterialGroup>
<DiffuseMaterial local:InteractiveVisual3D.IsInteractiveMaterial="True"/>
<SpecularMaterial Brush="Red" />
</MaterialGroup>
</local:InteractiveVisual3D.Material>
Finally, IsBackVisible sets the material used on the front face to also be used on the back face.
Currently, the Interactive3DDecorator does not distinguish between front and back faces, so this
allows for there to be interaction with the back face as well.
The following is an example use of the InteractiveVisual3D in XAML:
<local:InteractiveVisual3D Geometry="{StaticResource PlaneMesh}">
<local:InteractiveVisual3D.Visual>
<StackPanel>
<Label Content="Sample UI 2" />
<Button Content="Close Window"/>
<TextBox />
</StackPanel>
</local:InteractiveVisual3D.Visual>
</local:InteractiveVisual3D>
-----------------
How does it work:
-----------------
At a very high level, the interaction with 2D on 3D is achieved by really interacting
with a hidden version of that 2D content in 2D. The 2D is positioned such that the
point in 3D the mouse is over is the exact same point as the mouse is over on the
hidden 2D version. Then, when the user clicks, etc
they are interacting with exactly
the same location. If you want to see this for yourself, you can set the Debug
property on Interactive3DDecorator to true, which makes the hidden layer partially visible.
The Interactive3DDecorator then consists of two elements: the 3D content that is displayed
within it and a hidden layer that is used to position and display the 2D content that is
being interacted with. Depending on what 2D content on 3D is being interacted with, the
hidden layer changes to hold that 2D content. For example, consider a simple case of a
button, with text "Button", placed on a sphere. When the mouse moves over the B in
the button on the sphere, the hidden layer (the button) is moved such that the mouse is
over the same point in the hidden layer as it is in the 3D scene.
To figure out where to position the hidden layer works as follows. When the mouse moves
in the 3D scene, a ray is shot in to the 3D scene to see if it intersects any object.
If it hit an object, and it is an InteractiveVisual3D, we can use the return parameters
from the intersection to compute the texture coordinate that was hit. Then from these,
we can map from the (u,v) value of the texture coordinate, on to an x,y point on the 2D
visual, which is the point we need to place under the mouse. More specifically, the code
assumes texture coordinates are all in the range (0,0) to (1,1) i.e. upper left to lower
right of the image (this is important to know, since your texture coordinates need to
be within this range to enable interaction with the 2D content). Then the point on the
2D object that was hit is simply (u * Width, v * Height).
Theres one very interesting gotcha though: what happens when one of the 2D objects grabs
capture and then you move off the 3D mesh it is on? For example, you select some text, and
then move the mouse above that selected text, or click and hold on a button, and then move
away from it. Correct hidden content positioning becomes more complicated in this case.
The problem becomes difficult for many reasons. In the normal 2D situation, both the mouse
position and the 2D content exist in the same plane. The transformation that is applied to
the 2D content can be used to transform the mouse position to the contents local coordinate
system. However in 3D, due to the projection of 3D on to a 2D plane, the mouses position
actually corresponds to a line in 3D space. In addition, the element with capture could also
be mapped to any arbitrary geometry.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
WPF编程宝典——C# 2010版 (2000个子文件)
shapes.ai 409KB
shapes.ai 409KB
ScrollableTextBoxColumn.baml 4KB
CustomListViewTest.baml 3KB
DataGridEditing.baml 3KB
ModularContent.baml 3KB
DataGridTest.baml 2KB
TextBoxColumn.baml 2KB
Generic.baml 2KB
MultiDirectionExpanders.baml 2KB
DataGridRowDetails.baml 2KB
TextBoxTest.baml 2KB
DataGridGrouping.baml 2KB
AdvancedListView.baml 2KB
ExpandableContent.baml 2KB
Menu.baml 2KB
LocalizableText.baml 2KB
TunneledKeyPress.baml 2KB
ExpandableScrollableContent.baml 2KB
SlidersCompared.baml 2KB
SharedSizeGroup.baml 2KB
BubbledLabelClick.baml 2KB
DoubleSplitWindow.baml 2KB
Tooltips.baml 1KB
DateControls.baml 1KB
BoundTreeView.baml 1KB
Menu.baml 1KB
SplitWindow.baml 1KB
ButtonsWithContent.baml 1KB
ImageList.baml 1KB
PopupTest.baml 1KB
KeyPressEvents.baml 1KB
SimpleStack.baml 1KB
SimpleInkCanvas.baml 1KB
LayoutRoundingTest.baml 1KB
DragAndDrop.baml 1KB
ComboBoxTest.baml 1KB
CheckBoxList.baml 1KB
BasicListView.baml 1KB
CustomSpellChecker.baml 1KB
RadioButtonGroups.baml 1KB
Manipulations.baml 1KB
Menu.baml 1KB
SimpleDock.baml 1KB
SimpleGrid.baml 1KB
Menu.baml 1KB
GraphicalTabTitles.baml 1KB
SliderTest.baml 1KB
BoundTreeViewDataSet.baml 1KB
MousePosition.baml 1KB
BasicDialogBox.baml 1KB
SimpleCanvas.baml 1KB
GdiTextRendering.baml 1010B
SimpleWrap.baml 992B
LabelTest.baml 967B
LogicalScrolling.baml 918B
TheUniformGrid.baml 918B
ButtonWithShape.baml 911B
KeyModifiers.baml 880B
Focus.baml 870B
OnlyNumbers.baml 851B
Menu.baml 823B
EmbeddedFont.baml 815B
IndeterminateProgressBar.baml 793B
ButtonMouseUpEvent.baml 792B
DirectoryTreeView.baml 789B
RawTouch.baml 771B
ResolveAssemblyReference.cache 15KB
DesignTimeResolveAssemblyReferences.cache 10KB
DesignTimeResolveAssemblyReferencesInput.cache 8KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 7KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
Controls_MarkupCompile.i.cache 798B
Controls_MarkupCompile.cache 797B
LayoutPanels_MarkupCompile.cache 680B
LayoutPanels_MarkupCompile.i.cache 679B
DataBinding_MarkupCompile.cache 571B
RoutedEvents_MarkupCompile.i.cache 522B
RoutedEvents_MarkupCompile.cache 521B
Multitouch_MarkupCompile.i.cache 418B
Multitouch_MarkupCompile.cache 417B
app.config 952B
app.config 952B
app.config 204B
StoreDatabase.dll.config 204B
app.config 204B
app.config 204B
app.config 204B
app.config 204B
app.config 204B
app.config 204B
app.config 204B
app.config 204B
DataBinding.exe.config 204B
DataBinding.vshost.exe.config 204B
app.config 204B
app.config 204B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
weiningbo2010
- 粉丝: 13
- 资源: 53
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页