在多个WPF视口中渲染同一模型 [英] Rendering the same model in multiple WPF Viewports

查看:156
本文介绍了在多个WPF视口中渲染同一模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理具有4个视口的WPF应用程序.我建立了一个相当复杂的3D模型,其中包含50,000-100,000三角形.然后,我想在所有4个视口中显示相同的3D模型.我这样做的方式是,模型在所有4个视口(实际上是HelixViewports,来自用于WPF的Helix 3D工具包)中显示,大约需要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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆