0

Using MeshBuilder for bounding box in MVVM

Anonymous 10 years ago 0
This discussion was imported from CodePlex

ahmad_luqman wrote at 2013-04-02 15:06:

I want to create a bounding box in helix view port in MVVM.

My ViewModel has this:
var size = 6000;
var axesMeshBuilder = new HelixToolkit.Wpf.MeshBuilder();
var bb = new Rect3D(-1 * size / 2, -1 * size / 2, -1*size, size, size, size);
axesMeshBuilder.AddBoundingBox(bb, 10);
Box = axesMeshBuilder.ToMesh();
Which sets the Geometry3d type Box property in ViewModel:
public Geometry3D Box { get; set; }
And the Xaml View has:
         <h:HelixViewport3D>
            <h:SunLight />
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <GeometryModel3D Geometry="{Binding Box}" Material="{h:Material Black}"/>
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </h:HelixViewport3D>
This works but unit tests on ViewModel fails with exception:
System.ServiceModel.CommunicationObjectAbortedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it has been Aborted.
This is because I am setting the MeshBuilder in View Model. Ideally this logic should be in Xaml View. Can you suggest how can I move the MeshBuilder logic to XAML and bind to Rect3d?

Something like this:
         <h:HelixViewport3D>
            <h:SunLight />
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <GeometryModel3D Material="{h:Material Black}">
                        <!--Mesh Builder logic here -->
                    <GeometryModel3D />
                </ModelVisual3D.Content>
            </ModelVisual3D>
        </h:HelixViewport3D>
In case if the above answer is no we can't do that, alternatively how can we draw similar bounding box following MVVM?

ahmad_luqman wrote at 2013-04-02 15:40:

I think I got it.
This works:
<h:BoundingBoxVisual3D Diameter="10" BoundingBox="{Binding Box}" Fill="White"/>
Thanks for the cool library.