在多个WPF视图中渲染相同的模型

本文关键字:模型 WPF 视图 | 更新日期: 2023-09-27 18:10:36

我正在研究一个有4个视图的WPF应用程序。我建立了一个相当复杂的3D模型,包含5万到10万个三角形。然后我想在所有4个视口中显示相同的3D模型。我这样做的方式是,模型在所有4个视口中显示大约需要10秒(实际上是HelixViewports,来自Helix 3D Toolkit for WPF)。我从来没有使用多线程,但我认为这可能是一个好主意。我需要模型在不到2秒的时间内渲染所有4个视图。我可能也在低效地编写代码,下面是一个示例。谢谢你的帮助!

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显卡。我一直在寻找加快我的应用程序的方法,并将继续这样做,如果有人有建议或可以指出我有用的信息,将不胜感激!

在多个WPF视图中渲染相同的模型

你为什么不把你的整个模型在一个GeometryModel3D?你有35,000 -40000个三角形,这意味着你有35,000 -40000个GeometryModel3D!?这是巨大的…

你应该有一个包含Model3DGroup的Visual(它等于一个包含多个部分的场景或模型),包含与你拥有的模型(而不是三角形!)一样多的GeometryModel3D。每个GeometryModel3D包含一个MeshGeometry3D,其中包含一个模型的所有三角形,索引,法线,uv坐标。