0

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

Anonymous 5 years ago 0
This discussion was imported from CodePlex

pyrrhicpk1 wrote at 2012-10-16 11:37:

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


objo wrote at 2012-10-16 15:37:

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


pyrrhicpk1 wrote at 2012-10-17 04:17:

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.

 


pyrrhicpk1 wrote at 2012-10-17 04:44:

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.


objo wrote at 2012-10-17 08:40:

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