我正在开发一个有 4 个视口的 WPF 应用程序。我构建了一个相当复杂的 3D 模型,包含 50,000-100,000 个三角形。然后我想在所有 4 个视口中显示相同的 3D 模型。我这样做的方式是,模型在所有 4 个视口(实际上是 HelixViewports,来自 Helix 3D Toolkit for WPF)中显示大约需要 10 秒。我从未使用过多线程,但我认为这可能是个好主意。我需要模型在不到 2 秒的时间内在所有 4 个视口中渲染。我可能也在低效地编写我的代码,下面是一个示例。谢谢你的帮助!
渲染()函数(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 显卡的笔记本电脑上测试这个应用程序可能会有所帮助。我一直在寻找加速我的应用程序的方法,并将继续这样做,如果有人有建议或可以向我指出有用的信息,我将不胜感激!