在多个 WPF 视口中渲染相同的模型 [英] Rendering the same model in multiple WPF Viewports
问题描述
我正在开发具有 4 个视口的 WPF 应用程序.我构建了一个相当复杂的 3D 模型,其中包含 50,000-100,000 个三角形.然后我想在所有 4 个视口中显示相同的 3D 模型.我这样做的方式是,模型在所有 4 个视口(实际上是 HelixViewports,来自 Helix 3D Toolkit for WPF)中显示大约需要 10 秒.我从未使用过多线程,但我认为这可能是个好主意.我需要模型在不到 2 秒的时间内在所有 4 个视口中呈现.我的代码编写效率也可能低下,示例如下.感谢您的帮助!
I am working on a WPF application which has 4 viewports. I build a 3D model which is fairly complex and contains 50,000-100,000 Triangles. I then want to display the same 3D model in all 4 viewports. The way I am doing this, it takes about 10 seconds for the model to display in all 4 viewports (which are actually HelixViewports, from the Helix 3D Toolkit for WPF). I have never used multi threading, but I am thinking this may be a good idea. I need the models to render in all 4 viewports in less than 2 seconds. I am probably writing my code inefficiently as well, a sample is below. Thanks for your help!
Render() 函数(C#):
Render() function (C#):
//Each Viewport must have it's own ModelVisual3D
ModelVisual3D renderModel = new ModelVisual3D();
ModelVisual3D renderModel2 = new ModelVisual3D();
ModelVisual3D renderModel3 = new ModelVisual3D();
ModelVisual3D renderModel4 = new ModelVisual3D();
Model3DGroup modelGroup = new Model3DGroup();
//Here is an example of the 2 different ways
//I add components to the Models:
//Add the cylinder to the viewport
if (isCylinder)
{
//Each viewport must have its' own
PipeVisual3D ballBat = dO.getRound();
PipeVisual3D ballBat2, ballBat3, ballBat4;
ballBat2 = new PipeVisual3D();
ballBat2.Content = ballBat.Content;
ballBat3 = new PipeVisual3D();
ballBat3.Content = ballBat.Content;
ballBat4 = new PipeVisual3D();
ballBat4.Content = ballBat.Content;
this.mainViewport.Children.Add(ballBat);
this.mainViewport2.Children.Add(ballBat2);
this.mainViewport3.Children.Add(ballBat3);
this.mainViewport4.Children.Add(ballBat4);
}
//OR this way:
//Add inner top wane to the viewport
if (isTopWane)
{
modelGroup.Children.Add(dO.getTopWane());
}
//Add inner bottom wane to the viewport
if (isBottomWane)
{
modelGroup.Children.Add(dO.getBottomWane());
}
//Then, at the end of all my IF checks, this is how I
//'Draw' the models into the viewports:
//Each ModelVisual3D has the same content
renderModel2.Content = renderModel.Content;
renderModel3.Content = renderModel.Content;
renderModel4.Content = renderModel.Content;
//"Paint" the viewports
this.mainViewport.Children.Add(renderModel);
this.mainViewport2.Children.Add(renderModel2);
this.mainViewport3.Children.Add(renderModel3);
this.mainViewport4.Children.Add(renderModel4);
另外,知道我正在一台配备 16GB 内存、i7 核心的笔记本电脑上测试这个应用程序可能会有所帮助处理器和 NVIDIA Quadro 3000M 显卡.我一直在寻找加速我的应用程序的方法并将继续这样做,如果有人有建议或可以向我指出有用的信息,我们将不胜感激!
Also, it may help to know that I am testing this app on a laptop with 16GB ram, a core i7 processor, and an NVIDIA Quadro 3000M graphics card. I have been searching for ways to speed up my app and will continue to do so, if anyone has a suggestion or can point me to useful information it will be greatly appreciated!
推荐答案
为什么不将整个模型放在一个 GeometryModel3D 中?你有 35000-40000 个三角形,这意味着你有 35000-40000 个 GeometryModel3D!?太厉害了...
Why don't you put your entire model in one GeometryModel3D? You have 35000-40000 triangles, it means that you have 35000-40000 GeometryModel3D!? That's huge...
您应该有一个包含 Model3DGroup 的 Visual(相当于一个场景或包含多个部分的模型),其中包含与模型(而不是三角形!)一样多的 GeometryModel3D.每个 GeometryModel3D 包含一个 MeshGeometry3D,其中包含一个模型的所有三角形、索引、法线、uv 坐标.
You should have one Visual (which equals a scene or a model containing multiple parts) containing a Model3DGroup, containing as many GeometryModel3D as you have models (and not triangles!). Each GeometryModel3D containing a MeshGeometry3D which contains all the triangles, indices, normales, uv coords of one model.
这篇关于在多个 WPF 视口中渲染相同的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!