Saturday, August 16, 2008

ScreenSpaceLines3D WPF Fix

Second Post...

As you may know ScreenSpaceLines3D class in 3D tools for WPF has a small bug, once created it can't never be disposed, besides its rather slow. In my current project i had to draw a 3D model with a wireframe so i decided to use 3D tools and its Line3D class, but the performance was very poor so i did a little hack to improve it, it may not be a best way to do it but it might give you the basic idea how to improve this (great) class. All you need to do is to un register the class when its not needed and instead of adding its OnRender handler to CompositionTarget.Rendering (rescaling 60 times per second, bad idea) create a refresh function and update (rescale) when you really need to do it. Another idea is to create a worker thread that will be rescaling the lines when the user is doing nothing to the model.

Some Code:

public void Refresh()
if (Points.Count == 0 && _mesh.Positions.Count == 0)



if (UpdateTransforms() == true)



1 comment:

Neil Bourgeois said...

Hi, I'm having the same problem with ScreenSpaceLines3D. I have several thousand lines and the performance is brutal. Your solution is a great idea. I'm just wondering when do you actually call the Refresh method?