ModelVisual3D vs Model3DGroup - wpf

Is there any disadvantage of using ModelVisual3D over Model3DGroup. How much can the resource/performance impact possibly be?
ModelVisual3D gives me much more than Model3DGroup does but AFAIK everything that can be done with Model3DGroup can alos be done with ModelVisual3D.
So why not just always use ModelVisual3D?

The answer is Yes. Having many ModelVisual3ds will be orders of magnitude slower than using a Model3DGroup
My understanding is that ModelVisual3D is more akin to a UIElement, i.e. more of a heavy weight object. MSDN says about ModelVisual3d:
"Provides services and properties that are common to all visual objects, including hit-testing, coordinate transformation, and bounding-box calculations."
So if you wanted to 100 clickable 3d objects in your scene you would need 100 ModelVisual3d elements.
Model3DGroup (along with GeometryModel3D) on the other hand is a Model3D - the building blocks of 3d models. A single Model3D can appear as the content for several ModelVisual3Ds. Model3Ds are more lightweight than ModelVisual3D.
If you wanted to construct 3d models from building blocks (like Lego), you could define several GeometryModel3Ds, then combine them together using a Model3dGroup.
Yes, the class naming is horribly confusing, and I don't think the Daniel Lehenbauer sheds any light on the subject for the average human.

Related

Polygon limit for 3D objects used for Three.js

We are in the process of developing our first website made using Three.js. It of course uses a collection of 3D models, some of which are fairly busy cityscapes. We made them low poly, and are avoiding animation at this point, but would like to add some moving elements eventually.
My 3D designer is more used to working with objects used in Unity games, and he says that the industry standard is to keep each model below 100K polygons. Is there a similar limit that is typically used for Three.js?
In my mind, the issue should rather be focussed on file size, so we are trying to optimize this of course. I was just wondering if anyone knows whether there are other concerns to take into consideration in terms of poly-count?

wpf 3d with lots of models

I'm making a model of human anatomy . there is about 2100 mesh and model.
I used Helix 3d toolkit to import all files into a scene but that takes a long time to import (about 20 second) and scroll and rotations are slow. and that takes 800 meg of RAM.
objects are optimized and the sum of vertics must be less that 2 million.
i don't need shadows or any special effect. but i need scroll , zoom , hit testing and ..
what format should i use for saving models? i think .obj files are slow. should i use 3ds? or xaml?
should i use 2000 modelvisual3d or one with 2000 Geometrymodel3d ?
or should i use XNA?
can i disable some features to speed things up ?
tnx
you could try to save them as .vtk (visual toolkit) and load them with a library like three.js in a webgl canvas. (it also understands collada)
Very interesting idea to present 3D "Alive" - interactive human anatomy within WPF3D.
what format should i use for saving models? i think .obj files are slow. should i use 3ds? or xaml?
I am sure that .obj is one of fastest. In loading it is slow but in working it is.
should i use 2000 modelvisual3d or one with 2000 Geometrymodel3d ?
One ModelVisual3D and not 2000 Geometrymodel3d if it is possible by coding. Geometrymodel3d is for different materials. It has .Geometry, .BackMaterial and .Material.
or should i use XNA?
XNA more faster but not interactive. You are working at application not at game.
can i disable some features to speed things up ?
Very interesting task. At model preparing remove all back materials, made materials as simple as possible, take into account to meshes that you do not need. Provide camera rotation if it is possible.
You can send me model and I will try to help.

Choosing between Drawing and Shape in WPF

I am not quite sure about the differences between the classes System.Windows.Media.Drawing and System.Windows.Shapes.Shape. They both expose functionality related to 2D graphics in WPF. When would you choose one in your WPF application, and when would you choose the other?
A Shape inherits from FrameworkElement and is therefore a high level object which provides features such as hit-testing, styling, layout and data binding. In contrast a Drawing does not inherit from FrameworkElemet and doesn't support any of these features. As the documentation mentions a Drawing is useful for lightweight visual objects. If you are creating a complex brush to use to paint areas or a background a DrawingBrush would be very efficient.
Drawings can combine text, video, images and Geometry objects (another light weight class) to create complex but very efficient and fast drawings.
In short a Drawing is a low-level alternative to a Shape.
As for use cases, it depends.
If you have to animate or do any sort of binding you would use Shapes.
If you are creating brushes or complex clip arts/vector graphics you would probably use Drawings.
Also, if you draw things by overriding OnRender you would mostly use Geometries.
A Drawing is also Freezable and can thus be shared among threads (assuming it is frozen).

What is the best approach to render charts in WPF?

What is the best approach to render charts and then save them on a hard drive for further distribution using WPF?
I found a number of ways to accomplish this by using the following types:
DrawingVisual - creating a object of this type and then rendering graphics on its context;
Shape - deriving from the Shape class and then overriding its DefiningGeometry property where the actual rendering is happening;
PathFigure - adding LineSegment-s to an instance of this class and then adding this instance to a Canvas;
Adorner - deriving from it and then overriding its OnRender method;
WritableBitmap - rendering on it and then adding the bitmap to a Canvas.
Of course I'm going to write an app to test how fast each of these will be. But can anybody tell me:
whether am I on the right track?
are there any other means to do such rendering?
which one of them is the best in
terms of performance?
It all depends on your actual usage, in your case you mention saving on the hard drive for "further distribution" - I'm going to assume you are saving them as an image (jpg or png) and not as wpf objects (xaml).
You should consider if WPF is the right tool for the job, WPF is a UI framework and not a generic image processing library, it may be best to use something else entirely for generating images.
For a reasonable number of points your performance bottleneck will be encoding the image and saving it to disk - not actually rendering it - so you should choose the method that is easier for you to code.
All the articles about high performance WPF charts are a: about charts with 10,000 points and more (because that is where the performance problems are), b: about charts you display in your GUI (because otherwise you can use an image processing library to create the bitmap) and c: charts that change all the time (so they work nicely with data binding) - there's a reason why they don't talk about saving charts to disk.
For a very large number of points:
The fastest way to draw in WPF is to inherit from FrameworkElement (not Adorner) and override OnRender.
When the data changes often it is recommended to use multiple DrawingVisual objects because then you don't have to re-render everything when one value change - but this is not relevant for you since the image won't change after you save it anyway.
WritableBitmap is used for raw bitmap access, you use it when you decide to give up on all the nice layout and drawing WPF gives you because you can't take the overhead, if this is the case you should re-read my first point above.
So, to summarize, you are asking the wrong question :-) if you need to save images to disk than either the WPF rendering speed is not your bottleneck or you shouldn't be using WPF to begin with. If you do use WPF just pick whatever is easiest for you to code.
BTW: Adorners are used to display "floating" elements above the normal UI, you can use them for tooltip-like features but not for the main chart rendering (and you probably don't want them at all since your main usage is saving the image to disk), FrameworkElement is the base class you are looking for.

WPF: 3D cube with rounded corners

is it possible create a cube with rounded corners in WPF? I found many examples that easily create cubes with hard edges but none with rounded ones. One possible solution would be a pre-rendered object, but that's not easy and controls to be put on the sides must be transformed separately.
You'll need to use a 3D modelling package to create the object and then export it to XAML.
There are plenty of free packages out there, or expensive ones with free trials, that should have this functionality.

Resources