Help in translate/redraw a triangle geometry using a set of new points in 3D

Oct 16, 2012 at 10:37 AM

Hi,

I am able to draw a triangle using meshbuilder with Heli3DToolkit given three points in 3D space. My program updates these points and I want the triangle to get updated as well i.e. redrawn on the new points. How to do this?

At the moment I am re-creating the triangle using meshbuilder every time new set of points are available. This is working but computationally very expensive. It is also causing the UI to respond slowly. I was wondering if there could be a way to apply some transformation to the triangle geometry and re-position it to the new points rather than creating new triangle geometries.

Pleas guide me in this regard.

Thanks

Coordinator
Oct 16, 2012 at 2:37 PM

You should replace the positions only, it is not necessary to create new triangle indices and a new MeshGeometry3D instance.

See also http://msdn.microsoft.com/en-us/library/bb613553.aspx

Oct 17, 2012 at 3:17 AM
objo wrote:

You should replace the positions only, it is not necessary to create new triangle indices and a new MeshGeometry3D instance.

See also http://msdn.microsoft.com/en-us/library/bb613553.aspx

 

You mean, I should apply a TranslateTransform3D to my triangle geometry to reposition it to the new position. But, what would be this new position? My program is only updating the position of three spheres which I am using to create a triangle. So, when I get a new set of positions for these three spheres, how should I redraw/re-position my triangle geometry to these new positions? Could you please guide me with a few lines of sample code.

Thanks.

 

Oct 17, 2012 at 3:44 AM

I am creating a triangle as follows:

 

 meshBuilder.AddTriangle(new Point3D(x, y, z));

var mesh = meshBuilder.ToMesh(true);

myTrianglegeometry = new GeometryModel3D();
myTrianglegeometry.Material = greenMaterial;
myTrianglegeometry.BackMaterial = yellowMaterial;
myTrianglegeometry.Geometry = mesh;
modelGroup.Children.Add(myTrianglegeometry);

myModelVisual3D = new ModelVisual3D();
myModelVisual3D.Content = modelGroup;

Now my program is updating the values for x, y, and z. So, I am calling the above code for each update of x, y, z which creates a new triangle every-time a set of new x,y,z are available. This works but computationally very intensive and causes the UI response very slow.

To avoid this, how should I re-draw/re-position "myTrianglegeometry" to the new values of x,y,z rather than creating new triangles? Is it possible to change the vertices of the "myTrianglegeometry"?

Please guide me in this regard.

Thanks.

Coordinator
Oct 17, 2012 at 7:40 AM

if you are drawing a single triangle I think you should create the MeshGeometry3D directly, not using the MeshBuilder. 

See http://msdn.microsoft.com/en-us/library/bb613553.aspx

This section is important:

MeshGeometry3D

 

Mesh animation—changing the individual vertices of a mesh on a per-frame basis—is not always efficient in Windows Presentation Foundation (WPF).  To minimize the performance impact of change notifications when each vertex is modified, detach the mesh from the visual tree before performing per-vertex modification.  Once the mesh has been modified, reattach it to the visual tree.  Also, try to minimize the size of meshes that will be animated in this way.