我正在处理具有4个视口的WPF应用程序。我建立了一个相当复杂的3D模型,其中包含50,000-100,000个三角形。然后我想在所有4个视口中显示相同的3D模型。我这样做的模式需要大约10秒才能在所有4个视口中显示(实际上HelixViewports来自Helix 3D Toolkit for WPF)。我从来没有使用过多线程,但我认为这可能是一个好主意。我需要模型在不到2秒的时间内在所有4个视口中渲染。我可能写的代码效率低下,下面是一个示例。谢谢你的帮助!在多个WPF视口中呈现相同的模型
渲染()函数(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显卡。我一直在寻找加快我的应用程序的方法,并会继续这样做,如果任何人有建议或可以指向我的有用信息,将不胜感激!
我已经能够显着加快我的应用程序,但它仍然太慢。我现在有2个大视口,而不是4个小视口,都显示相同的模型。我还能够将我的三角形数减少到30,000-45,000个三角形,具体取决于扫描结果的模型。现在将这些模型渲染到两个视口中大约需要3.2-4.0秒。我的目标是低于1.5秒。我也做了这些事情:从我的三角形中删除了法线向量,改变了我编写的一些方法,使得每个三角形都是一个GeometryModel3D,而不是包含一个孩子(三角形)的Model3DGroup。 – Doug 2013-04-25 13:05:28