Viewport3D 类Viewport3D 类Viewport3D 类

.NET Framework 类库
Viewport3D 类

更新:2007 年 11 月

为三维可视内容提供呈现图面。

命名空间:  System.Windows.Controls
程序集:  PresentationFramework(在 PresentationFramework.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation

Visual Basic(声明)
<LocalizabilityAttribute(LocalizationCategory.NeverLocalize)> _
<ContentPropertyAttribute("Children")> _
Public Class Viewport3D _
Inherits FrameworkElement _
Implements IAddChild
Visual Basic (用法)
Dim instance As Viewport3D
C#
[LocalizabilityAttribute(LocalizationCategory.NeverLocalize)]
[ContentPropertyAttribute("Children")]
public class Viewport3D : FrameworkElement, IAddChild
Visual C++
[LocalizabilityAttribute(LocalizationCategory::NeverLocalize)]
[ContentPropertyAttribute(L"Children")]
public ref class Viewport3D : public FrameworkElement, 
IAddChild
J#
/** @attribute LocalizabilityAttribute(LocalizationCategory.NeverLocalize) */
/** @attribute ContentPropertyAttribute("Children") */
public class Viewport3D extends FrameworkElement implements IAddChild
JScript
public class Viewport3D extends FrameworkElement implements IAddChild
XAML 对象元素用法
<Viewport3D>
Children
</Viewport3D>

此控件显示三维内容,同时提供与二维布局(如剪辑、高度和宽度及鼠标事件)一致的属性。

当此控件作为布局元素(如 Canvas)的内容包含时,可通过设置其 HeightWidth 属性(继承自 FrameworkElement)来指定 Viewport3D 的大小。

Viewport3D 可提供三维场景级别的命中测试。 调用 HitTest 方法可返回有关命中可视对象、模型、网格和交点的详细命中结果信息。

在 Microsoft Windows XP 上,如果显示颜色质量没有设置为 32 位或 16 位,则 Viewport3D 可能无法正常呈现。

本示例演示如何创建类似于已旋转的平板纸的三维对象。利用 Viewport3D 以及下面的组件创建这一简单的三维场景:

  • 使用 PerspectiveCamera 创建一个照相机。该照相机指定三维场景的哪个部分是可见的。

  • 创建一个网格,以使用 GeometryModel3DGeometry 属性指定三维对象(平板纸)的形状。

  • 使用 GeometryModel3DMaterial 属性指定要在对象表面显示的材料(本示例中是线性渐变)。

  • 使用 DirectionalLight 创建在对象上发光的光源。

下面的代码演示如何以 XAML 创建三维场景。

XAML
复制代码
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<DockPanel>
<Viewbox>
<Canvas Width="321" Height="201">
<!-- The Viewport3D provides a rendering surface for 3-D visual content. -->
<Viewport3D ClipToBounds="True" Width="150" Height="150" Canvas.Left="0" Canvas.Top="10">
<!-- Defines the camera used to view the 3D object. -->
<Viewport3D.Camera>
<PerspectiveCamera Position="0,0,2" LookDirection="0,0,-1" FieldOfView="60" />
</Viewport3D.Camera>
<!-- The ModelVisual3D children contain the 3D models -->
<Viewport3D.Children>
<!-- This ModelVisual3D defines the light cast in the scene. Without light, the 3D 
object cannot be seen. Also, the direction of the lights affect shadowing. If desired,
you can create multiple lights with different colors that shine from different directions. -->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<!-- The geometry specifes the shape of the 3D plane. In this sample, a flat sheet is created. -->
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0,1,2 3,4,5 "
Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 "
TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 "
Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 " />
</GeometryModel3D.Geometry>
<!-- The material specifies the material applied to the 3D object. In this sample a linear gradient 
covers the surface of the 3D object.-->
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Yellow" Offset="0" />
<GradientStop Color="Red" Offset="0.25" />
<GradientStop Color="Blue" Offset="0.75" />
<GradientStop Color="LimeGreen" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
<!-- Apply a transform to the object. In this sample, a rotation transform is applied, rendering the 
3D object rotated. -->
<GeometryModel3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,3,0" Angle="40" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</GeometryModel3D.Transform>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D.Children>
</Viewport3D>
</Canvas>
</Viewbox>
</DockPanel>
</Page>

下面的代码演示如何以程序代码创建同一三维场景。

C#
复制代码
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace SDKSample
{
public partial class Basic3DShapeExample : Page
{
public Basic3DShapeExample()
{
// Declare scene objects.
Viewport3D myViewport3D = new Viewport3D();
Model3DGroup myModel3DGroup = new Model3DGroup();
GeometryModel3D myGeometryModel = new GeometryModel3D();
ModelVisual3D myModelVisual3D = new ModelVisual3D();
// Defines the camera used to view the 3D object. In order to view the 3D object,
// the camera must be positioned and pointed such that the object is within view 
// of the camera.
PerspectiveCamera myPCamera = new PerspectiveCamera();
// Specify where in the 3D scene the camera is.
myPCamera.Position = new Point3D(0, 0, 2);
// Specify the direction that the camera is pointing.
myPCamera.LookDirection = new Vector3D(0, 0, -1);
// Define camera's horizontal field of view in degrees.
myPCamera.FieldOfView = 60;
// Asign the camera to the viewport
myViewport3D.Camera = myPCamera;
// Define the lights cast in the scene. Without light, the 3D object cannot 
// be seen. Also, the direction of the lights affect shadowing. Note: to 
// illuminate an object from additional directions, create additional lights.
DirectionalLight myDirectionalLight = new DirectionalLight();
myDirectionalLight.Color = Colors.White;
myDirectionalLight.Direction = new Vector3D(-0.61, -0.5, -0.61);
myModel3DGroup.Children.Add(myDirectionalLight);
// The geometry specifes the shape of the 3D plane. In this sample, a flat sheet 
// is created.
MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D();
// Create a collection of normal vectors for the MeshGeometry3D.
Vector3DCollection myNormalCollection = new Vector3DCollection();
myNormalCollection.Add(new Vector3D(0,0,1));
myNormalCollection.Add(new Vector3D(0,0,1));
myNormalCollection.Add(new Vector3D(0,0,1));
myNormalCollection.Add(new Vector3D(0,0,1));
myNormalCollection.Add(new Vector3D(0,0,1));
myNormalCollection.Add(new Vector3D(0,0,1));
myMeshGeometry3D.Normals = myNormalCollection;
// Create a collection of vertex positions for the MeshGeometry3D. 
Point3DCollection myPositionCollection = new Point3DCollection();
myPositionCollection.Add(new Point3D(-0.5, -0.5, 0.5));
myPositionCollection.Add(new Point3D(0.5, -0.5, 0.5));
myPositionCollection.Add(new Point3D(0.5, 0.5, 0.5));
myPositionCollection.Add(new Point3D(0.5, 0.5, 0.5));
myPositionCollection.Add(new Point3D(-0.5, 0.5, 0.5));
myPositionCollection.Add(new Point3D(-0.5, -0.5, 0.5));
myMeshGeometry3D.Positions = myPositionCollection;
// Create a collection of texture coordinates for the MeshGeometry3D.
PointCollection myTextureCoordinatesCollection = new PointCollection();
myTextureCoordinatesCollection.Add(new Point(0, 0));
myTextureCoordinatesCollection.Add(new Point(1, 0));
myTextureCoordinatesCollection.Add(new Point(1, 1));
myTextureCoordinatesCollection.Add(new Point(1, 1));
myTextureCoordinatesCollection.Add(new Point(0, 1));
myTextureCoordinatesCollection.Add(new Point(0, 0));
myMeshGeometry3D.TextureCoordinates = myTextureCoordinatesCollection;
// Create a collection of triangle indices for the MeshGeometry3D.
Int32Collection myTriangleIndicesCollection = new Int32Collection();
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(1);
myTriangleIndicesCollection.Add(2);
myTriangleIndicesCollection.Add(3);
myTriangleIndicesCollection.Add(4);
myTriangleIndicesCollection.Add(5);
myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection;
// Apply the mesh to the geometry model.
myGeometryModel.Geometry = myMeshGeometry3D;
// The material specifies the material applied to the 3D object. In this sample a  
// linear gradient covers the surface of the 3D object.
// Create a horizontal linear gradient with four stops.   
LinearGradientBrush myHorizontalGradient = new LinearGradientBrush();
myHorizontalGradient.StartPoint = new Point(0, 0.5);
myHorizontalGradient.EndPoint = new Point(1, 0.5);
myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.Red, 0.25));
myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));
myHorizontalGradient.GradientStops.Add(new GradientStop(Colors.LimeGreen, 1.0));
// Define material and apply to the mesh geometries.
DiffuseMaterial myMaterial = new DiffuseMaterial(myHorizontalGradient);
myGeometryModel.Material = myMaterial;
// Apply a transform to the object. In this sample, a rotation transform is applied,  
// rendering the 3D object rotated.
RotateTransform3D myRotateTransform3D = new RotateTransform3D();
AxisAngleRotation3D myAxisAngleRotation3d = new AxisAngleRotation3D();
myAxisAngleRotation3d.Axis = new Vector3D(0,3,0);
myAxisAngleRotation3d.Angle = 40;
myRotateTransform3D.Rotation = myAxisAngleRotation3d;
myGeometryModel.Transform = myRotateTransform3D;
// Add the geometry model to the model group.
myModel3DGroup.Children.Add(myGeometryModel);
// Add the group of models to the ModelVisual3d.
myModelVisual3D.Content = myModel3DGroup;
// 
myViewport3D.Children.Add(myModelVisual3D);
// Apply the viewport to the page so it will be rendered.
this.Content = myViewport3D;
}
}
}
System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows.Media..::.Visual
        System.Windows..::.UIElement
          System.Windows..::.FrameworkElement
            System.Windows.Controls..::.Viewport3D
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5、3.0

参考

Viewport3D 成员
System.Windows.Controls 命名空间
Viewport3DVisual

其他资源

三维图形概述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389164.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网络浏览器如何工作

Behind the scenes of modern Web Browsers现代Web浏览器的幕后花絮 The Web Browser is inarguably the most common portal for users to access the web. The advancement of the web browsers (through the series of history) has led many traditional “thick clients”…

让自己的头脑极度开放

为什么80%的码农都做不了架构师&#xff1f;>>> 一. 头脑封闭和头脑开放 头脑封闭 你是否经常有这样的经历&#xff0c;在一次会议或者在一次小组讨论时&#xff0c;当你提出一个观点而被别人否定时&#xff0c;你非常急迫地去反驳别人&#xff0c;从而捍卫自己的尊…

简介DOTNET 编译原理 简介DOTNET 编译原理 简介DOTNET 编译原理

简介DOTNET 编译原理 相信大家都使用过 Dotnet &#xff0c;可能还有不少高手。不过我还要讲讲Dotnet的基础知识&#xff0c;Dotnet的编译原理。 Dotnet是一种建立在虚拟机上执行的语言&#xff0c;它直接生成 MSIL 的中间语言&#xff0c;再由DotNet编译器 JIT 解释映象为本机…

RecyclerView详细了解

关于RecyclerView大家都不陌生了&#xff0c;它的使用也越来越受欢迎&#xff0c;现在总体了解一下RecyclerView的作用&#xff0c;为什么会有RecyclerView呢&#xff0c;我用ListView也能干所有的事情啊&#xff0c;尺有所短&#xff0c;寸有所长&#xff0c;先来看看Recycler…

案例与案例之间的非常规排版

In 1929 the Cond Nast publishing group brought Russian-born Mehemed Fehmy Agha—who had been working for the German edition of Vogue magazine—to America as art director for House & Garden, Vanity Fair, and the senior edition of Vogue.1929年&#xff0c…

熊猫分发_熊猫新手:第二部分

熊猫分发This article is a continuation of a previous article which kick-started the journey to learning Python for data analysis. You can check out the previous article here: Pandas for Newbies: An Introduction Part I.本文是上一篇文章的延续&#xff0c;该文…

浅析微信支付:申请退款、退款回调接口、查询退款

本文是【浅析微信支付】系列文章的第八篇&#xff0c;主要讲解商户如何处理微信申请退款、退款回调、查询退款接口&#xff0c;其中有一些坑的地方&#xff0c;会着重强调。 浅析微信支付系列已经更新七篇了哟&#xff5e;&#xff0c;没有看过的朋友们可以看一下哦。 浅析微信…

view工作原理-计算视图大小的过程(onMeasure)

view的视图有两种情况&#xff1a; 内容型视图&#xff1a;由视图的内容决定其大小。图形型视图&#xff1a;父视图为view动态调整大小。 ### measure的本质 把视图布局使用的“相对值”转化成具体值的过程&#xff0c;即把WRAP_CONTENT,MATCH_PARENT转化为具体的值。 measur…

基于Redis实现分布式锁实战

背景在很多互联网产品应用中&#xff0c;有些场景需要加锁处理&#xff0c;比如&#xff1a;秒杀&#xff0c;全局递增ID&#xff0c;楼层生成等等。大部分的解决方案是基于DB实现的&#xff0c;Redis为单进程单线程模式&#xff0c;采用队列模式将并发访问变成串行访问&#x…

数据分析 绩效_如何在绩效改善中使用数据分析

数据分析 绩效Imagine you need to do a bank transaction, but the website is so slow. The page takes so much time to load, all you can see is a blue circle.想象您需要进行银行交易&#xff0c;但是网站是如此缓慢。 该页面需要花费很多时间来加载&#xff0c;您只能看…

隐私策略_隐私图标

隐私策略During its 2020 Worldwide Developers Conference, Apple spent time on one of today’s hottest topics — privacy. During the past couple of years, Apple has been rolling out various public campaigns aiming to position itself as a company that respect…

您一直在寻找5+个简单的一线工具来提升Python可视化效果

Insightful and aesthetic visualizations don’t have to be a pain to create. This article will prevent 5 simple one-liners you can add to your code to increase its style and informational value.富有洞察力和美学的可视化不必费心创建。 本文将防止您添加到代码中…

figma 安装插件_彩色滤光片Figma插件,用于色盲

figma 安装插件So as a UX Designer, it is important to design with disabilities in mind. One of these is color blindness. It is important to make sure important information on your product is legible to everyone. This is why I like using this tool:因此&…

产品观念:更好的捕鼠器_故事很重要:为什么您需要成为更好的讲故事的人

产品观念&#xff1a;更好的捕鼠器重点 (Top highlight)Telling a compelling story helps you get your point across effectively else you get lost in translation.讲一个引人入胜的故事可以帮助您有效地传达观点&#xff0c;否则您会迷失在翻译中。 Great stories happen…

7月15号day7总结

今天复习了springMVC的框架搭建。 思维导图&#xff1a; 转载于:https://www.cnblogs.com/kangy123/p/9315919.html

设计师的10种范式转变

For $250, a business can pay a graphic designer to create a logo for their business. Or, for $10,000 a business can hire a graphic designer to form a design strategy that contextually places the business’s branding in a stronghold against the market it’s…

面向Tableau开发人员的Python简要介绍(第2部分)

用PYTHON探索数据 (EXPLORING DATA WITH PYTHON) And we’re back! Let’s pick up where we left off in the first article of this series and use the visual we built there as a starting point.我们回来了&#xff01; 让我们从在本系列的第一篇文章中停下来的地方开始&…

设计组合中的10个严重错误可能会导致您丧命

As an agency co-founder and design lead, I’ve been participating in many recruitment processes. I’ve seen hundreds of portfolios and CVs of aspiring designers. If you’re applying for a UI designer position, it is good to have some things in mind and to …

MySQL命令学习

上面两篇博客讲了MySQL的安装、登录&#xff0c;密码重置&#xff0c;为接下来的MySQL命令学习做好了准备&#xff0c;现在开启MySQL命令学习之旅吧。 首先打开CMD&#xff0c;输入命令&#xff1a;mysql -u root -p 登录MySQL。 注意&#xff1a;MySQL命令终止符为分号 (;) …

实验心得_大肠杆菌原核表达实验心得(上篇)

大肠杆菌原核表达实验心得&#xff08;上篇&#xff09;对于大肠杆菌蛋白表达&#xff0c;大部分小伙伴都觉得 so easy! 做大肠杆菌蛋白表达十几年经历的老司机还经常阴沟翻船&#xff0c;被大肠杆菌表达蛋白虐千百遍的惨痛经历&#xff0c;很多小伙伴都有切肤之痛。福因德接下…