简体   繁体   English

.NET高级图形库

[英].NET high level graphics library

I am programming various simulation tools in C#/.NET 我在C#/ .NET中编写各种模拟工具

What I am looking for is a high level visualization library; 我正在寻找的是一个高级可视化库; create a scene, with a camera with some standard controls, and render a few hunderd thousand spheres to it, or some wireframes. 使用带有一些标准控件的相机创建一个场景,并为其渲染一些数千个球体或一些线框。 That kind of thing. 那种事。 If it takes more than one line to initialize a context, it deviates from my ideal. 如果初始化上下文需要多行,则它会偏离我的理想。

Ive looked at slimDX, but its way lower level than im looking for (at least the documented parts, but I dont really care for any other). 我看过slimDX,但它的方式低于我寻找的水平(至少记录的部分,但我真的不关心任何其他)。 WPF perspective looked cool, but it seems targeted at static XAML defined scenes, and that doesnt really suit me either. WPF透视看起来很酷,但它似乎针对静态XAML定义的场景,而且这也不适合我。

Basically, im looking for the kind of features languages like blitzbasic used to provide. 基本上,我正在寻找像blitzbasic这样的特色语言。 Does that exist at all? 这根本存在吗?

Maybe the XNA Game studio is what you are looking for. 也许XNA游戏工作室正是您所寻找的。

Also take a look at DirectX . 另请参阅DirectX

WPF perspective looked cool, but it seems targeted at static XAML defined scenes WPF透视看起来很酷,但它似乎针对静态XAML定义的场景

Look again, WPF can be as dynamic as you will ever need. 再看一下,WPF可以像你需要的那样动态。

You can write any WPF program, including 3D, totally without XAML. 您可以完全不使用XAML编写任何WPF程序,包括3D。

I'm also interested in this (as I'm also developing simulation tools) and ended up hacking together some stuff in XNA. 我也对此感兴趣(因为我也在开发模拟工具)并最终在XNA中将一些东西混在一起。 It's definitely a lot more work than you've described, however. 然而,这肯定比你描述的要多得多。 Note that anything you can do in WPF via XAML can also be done via code, as XAML is merely a representation of an object hierarchy and its relationships. 请注意,您可以通过XAML在WPF中执行的任何操作也可以通过代码完成,因为XAML仅仅是对象层次结构及其关系的表示。 I think that may be your best bet, though I don't have any metrics on what kind of performance you could expect with a few hundred thousand spheres (you're absolutely going to need some culling in that case and the culling itself may be expensive if you don't use optimizations like grid partitioning.) 我认为这可能是你最好的选择,虽然我没有任何关于你可以期望用几十万个球体表现出什么样的表现的指标(在这种情况下你绝对需要进行一些剔除而且剔除本身可能是如果不使用网格分区等优化,则会很昂贵。)


EDIT: If you really need to support 100K entities and they can all be rendered as spheres, I would recommend that you bypass the 3d engine entirely and only use XNA for math. 编辑:如果你真的需要支持100K实体并且它们都可以渲染为球体,我建议你完全绕过3d引擎,只使用XNA进行数学运算。 I would imagine an approach like the following: 我想象一下如下的方法:

  • Use XNA to set up Camera (View) and Perspective matrices. 使用XNA设置Camera(View)和Perspective矩阵。 It has some handy Matrix static functions that make this easy. 它有一些方便的Matrix静态函数,使这很容易。

  • Compute the Projection matrix and project all of your 'sphere' origin points to the viewing frustrum. 计算投影矩阵并将所有“球体”原点投影到观看截头体。 This will give you X,Y screen coordinates and Z depth in the frustrum. 这将为您提供截止日期中的X,Y屏幕坐标和Z深度。 You can either express this as 100K individual matrix multiplications or multiplication of the Projection matrix by a single 3 x 100K element matrix. 您可以将其表示为100K单个矩阵乘法或将投影矩阵乘以单个3 x 100K元素矩阵。 In the former case, this is a great candidate for parallelism using the new .NET 4 Parallel functionality. 在前一种情况下,这是使用新的.NET 4 Parallel功能并行的很好的候选者。

  • If you find that the 100K matrix multplications are a problem, you can reduce this significantly by performing culling of points before transformation if you know that only a small subset of them will be visible at a given time. 如果您发现100K矩阵乘法是一个问题,如果您知道在给定时间只能看到它们中的一小部分,则可以通过在变换之前执行剔除来显着减少这一点。 For instance, you can invert the Projection matrix to find the bounds of your frustrum in your original space and create an axis-aligned bounding box for the frustrum. 例如,您可以反转Projection矩阵以在原始空间中找到截头体的边界,并为截头体创建一个轴对齐的边界框。 You can then exclude all points outside this box (simple comparison tests in X, Y and Z.) You only need to recompute this bounding box when the Projection matrix changes, so if it changes infrequently, this can be a reasonable optimization. 然后,您可以排除此框外的所有点(X,Y和Z中的简单比较测试。)您只需在Projection矩阵更改时重新计算此边界框,因此如果它不经常更改,则这可以是合理的优化。

  • Once you have your transformed points, clip any outside the frustum (Z < 0, Z > maxDist, X<0, Y<0, X>width, Y>height). 获得变换点后,剪切平截头体外的任何一个(Z <0,Z> maxDist,X <0,Y <0,X>宽度,Y>高度)。 You can now render each point by drawing a filled circle, with its radius proportional to Z (Z=0 would have largest radius and Z=maxDist would probably fade to a single point.) If you want to provide a sense of shading/depth, you can render with a shaded brush to very loosely emulate lighting on spheres. 您现在可以通过绘制一个填充圆来渲染每个点,其半径与Z成比例(Z = 0将具有最大半径,Z = maxDist可能会淡化为单个点。)如果您想提供阴影/深度感,您可以使用阴影刷渲染,以非常松散地模拟球体上的光照。 This works because everything in your scene is a sphere and you're presumably not worried about things like shadows. 这是有效的,因为你场景中的所有东西都是一个球体,你可能不会担心像阴影这样的东西。 All of this would be fairly easy to do in WPF (including the Shaded Brush), but be sure to use DrawingVisual classes and not framework elements. 所有这些在WPF(包括着色画笔)中都相当容易,但一定要使用DrawingVisual类而不是框架元素。 Also, you'll need to make sure you draw in the correct Z order, so it helps if you store the transformed points in a data structure that sorts as you add. 此外,您需要确保以正确的Z顺序绘制,因此如果将变换后的点存储在添加时排序的数据结构中,则会有所帮助。

  • If you're still having performance problems, there are further optimizations you can pursue. 如果您仍然遇到性能问题,可以进一步优化。 For instance, if you know that only a subset of your points are moving, you can cache the transformed locations for the immobile points. 例如,如果您知道只有一部分点在移动,则可以缓存转换后的固定点位置。 It really depends on the nature of your data set and how it evolves. 这实际上取决于数据集的性质及其演变方式。

  • Since your data set is so large, you might consider changing the way you visualize it. 由于您的数据集太大,您可以考虑更改可视化方式。 Instead of rendering 100K points, partition your working space into a volumetric grid and record the number (density) of points inside each grid cube. 不是渲染100K点,而是将工作空间划分为体积网格,并记录每个网格立方体内点的数量(密度)。 You can Project only the center of the grid and render it as a 'sphere' with some additional feedback (like color, opacity or brush texture) to indicate the point density. 您可以仅投影网格的中心并将其渲染为具有一些额外反馈(如颜色,不透明度或笔刷纹理)的“球体”以指示点密度。 You can combine this technique with the traditional rendering approach, by rendering near points as 'spheres' and far points as 'cluster' objects with some brush patterning to match the density. 您可以将此技术与传统渲染方法相结合,将近点渲染为“球体”,将远点渲染为“群集”对象,并使用一些画笔图案来匹配密度。 One simple algorithm is to consider a bounding sphere around the camera; 一种简单的算法是考虑相机周围的边界球; all points inside the sphere will be transformed normally; 球体内的所有点都将正常转换; beyond the sphere, you will only render using the density grid. 在球体之外,您将仅使用密度网格进行渲染。

Do you have to use C#/.Net or would MonoDevelop be good enough? 您是否必须使用C#/ .Net或MonoDevelop是否足够好? I can recomend http://unity3d.com/ if you want a powerful 3D-engine. 如果你想要一个强大的3D引擎,我可以推荐http://unity3d.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM