How to change color of WPF HelixViewport3D cube and write text on it

1.8k views Asked by At

The following code:

<Window x:Class="helixCube.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:h="http://helix-toolkit.org/wpf"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:helixPerfectCube"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">

    <Grid Width="200" Height="200" Background="Red">
        <h:HelixViewport3D Title="Titlee" ShowViewCube="False" TextBrush="Black" Opacity="0.9">
            <h:SunLight/>
            <h:BoxVisual3D Width="12" Length="12" Height="12"/>
        </h:HelixViewport3D>
    </Grid>


</Window>

gives me the following cube:

enter image description here

I would like to make the following 2 changes:

  1. I want the color of the cube to be black. However, I can't find a way to do this.

  2. I want the title to be displyed directly on (the surface of) the cube.

Does anybody know how this can be done?

1

There are 1 answers

0
Skyuppercut On

In viewmodel, Create some materials as follows:

public Model3D Model {get; set;}
public MainViewModel()
{

  var outsideMaterial = MaterialHelper.CreateMaterial(Colors.LightGray, 0.1);
  var insideMaterial = MaterialHelper.CreateMaterial(Colors.Gray);
  var modelGroup = new Model3DGroup();

  modelGroup.Children.Add(new GeometryModel3D {Geometry = cubeObj, Material =outsideMaterial, BackMaterial = insideMaterial});
  }

Create a cube object.! (cubeObj) After that
In Ui,

 <h:HelixViewport3D Title="Titlee" ShowViewCube="False" TextBrush="Black" Opacity="0.9">
        <h:SunLight/>
        <ModelVisual3D Content = "{Binding Model}"/>
    </h:HelixViewport3D>

Helix ViewPort allows rotation, pan and zoom. text doesn't render neatly in such 3d space while performing above actions. Hence, it isn't recommended to put text on top of the cube.

Disclaimer: Untested code.!