AB4D Forum

Full Version: Changing the color of an OptimizedPointMesh, i.e. from ShadedPointCloud
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I am looking at using the Ab3d.DXEngine for an application displaying point cloud data.

The ShadedPointCloudSample example is great and using that within my application is giving some great results.

In my application, I need to display multiple point clouds.  So I've adapted the example to create additional OptimizedPointMesh objects and for each adding a SceneNodeVisual3D created from a CustomRenderableNode.

I set the color of each point cloud when creating the CustomRenderableNode,  by using a particular effect, e.g...
var customRenderableNode = new CustomRenderableNode(RenderAction, new Bounds(boundingBox), optimizedPointMesh, ScanEffectMaterial);

However, I want to be able to show each separate point cloud highlighted or not.  To achieve this, I need to change the display color of each individual OptimizedPointMesh as required.

My question is, how can I change the effect used for a particular CustomRenderableNode at a later time, so the point cloud color is changed. 

I can't just change the DiffuseColor for the effect as that will change all other CustomRenderableNode's using that effect.

I have tried to solve this by removing the SceneNodeVisual3D and re-creating a new CustomRenderableNode using a different effect. This does work, I just don't know if this is the best way?
To correct myself here, I see its the Material I need to change for CustomRenderableNode.

So I'm thinking I can have two seperate EffectMaterial(s), one for highlight, one for dimmed.

So then the question is how can I swap the Material that is used for a particular CustomRenderableNode.

Thank you in advance.
All OptimizedPointMeshes can have the same effect but each of them should have its own material - for example PixelMaterial (as in OptimizedPointCloud.xaml.cs sample).

Then you only need to change the PixelColor value in the specific PixelMaterial and notify DXEngine about the changes and the whole point cloud will be rendered with a different color.

For example, if you add a Test button to OptimizedPointCloud.xaml then you can use the following code to change the color:
       private void TestButton_OnClick(object sender, RoutedEventArgs e)
           _pixelMaterial.PixelColor = Colors.Aqua.ToColor4();

This is a usual approach for the effects in DXEngine.

But the effect in ShadedPointCloudSample is different - this effect does not support multiple materials and defines all the material's properties in the effect's properties. So if you use the source code from that sample, then you need to create new ShadedPointCloudEffect instance for each point cloud. This will then allow you to change the color of each effect. Having multiple effect instances does not have any performance of memory drawbacks.

Note that if you do not need to have individual points in the point could shaded by light angle (so in case when all your points can have the same color), then it is much easier to use standard OptimizedPointMeshes instead of ShadedPointCloudEffect. The later can be also used when you want full control of the point cloud rendering and want to change the hlsl code of the shaders (this effect if provided with full source).
Thank you Andrej for your detailed reply.  I'll look into your advice today.  Much appreciated.