Search code examples
c#wpftoolkithelix

how can i change default camera direction in wpf helix toolkit


<Grid>
    <hx:HelixViewport3D ZoomExtentsWhenLoaded="True" >
        <hx:SunLight/>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D x:Name="meshMain"
                    Positions="0 0 0  1 0 0  0 1 0  1 1 0  0 0 1  1 0 1  0 1 1  1 1 1"
                    TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 0  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4">
                        </MeshGeometry3D>
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <DiffuseMaterial x:Name="matDiffuseMain">
                            <DiffuseMaterial.Brush>
                                <SolidColorBrush Color="Red"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <GeometryModel3D>
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D x:Name="aaa"
                    Positions="1 1 1  2 1 1  1 2 1  2 2 1  1 1 2  2 1 2  1 2 2  2 2 2"
                    TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 0  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4">
                        </MeshGeometry3D>
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <DiffuseMaterial x:Name="sa">
                            <DiffuseMaterial.Brush>
                                <SolidColorBrush Color="Red"/>
                            </DiffuseMaterial.Brush>
                        </DiffuseMaterial>
                    </GeometryModel3D.Material>
                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <hx:GridLinesVisual3D Width="8" Length="8" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>
    </hx:HelixViewport3D>
</Grid>

How can I make that normally when you open the program you have the camera looking from the top ?

Pointed to you in helix toolkit.

So an user can see the 3d scene from the top and can move after if needed


Solution

  • I will show you step by step.

    Add this ShowCameraInfo="True" into your HelixViewport3D

        <hx:HelixViewport3D ShowCameraInfo="True">
            ...
        </hx:HelixViewport3D>
    

    Then run the program and click the right corner position box's up side there. enter image description here

    Then the view will be from top and you will see the camera informations on left corner. Save them somewhere.

    enter image description here

    Then finally we will put the values into your HelixViewport3D

    <hx:HelixViewport3D ...>
        <hx:HelixViewport3D.Camera>
            <PerspectiveCamera Position="0 0 24.285"
                               LookDirection="0 0 -23.285"
                               UpDirection="0 1 0"/>
        </hx:HelixViewport3D.Camera>
        ...
    </hx:HelixViewport3D>
    

    And it's done!

    For your example:

    <Grid>
            <hx:HelixViewport3D ZoomExtentsWhenLoaded="True">
                <hx:HelixViewport3D.Camera>
                    <PerspectiveCamera Position="0 0 24.285"
                                       LookDirection="0 0 -23.285"
                                       UpDirection="0 1 0"/>
                </hx:HelixViewport3D.Camera>
                <hx:SunLight/>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D x:Name="meshMain"
                        Positions="0 0 0  1 0 0  0 1 0  1 1 0  0 0 1  1 0 1  0 1 1  1 1 1"
                        TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 0  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4">
                                </MeshGeometry3D>
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial x:Name="matDiffuseMain">
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush Color="Red"/>
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </ModelVisual3D.Content>
                </ModelVisual3D>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <GeometryModel3D>
                            <GeometryModel3D.Geometry>
                                <MeshGeometry3D x:Name="aaa"
                        Positions="1 1 1  2 1 1  1 2 1  2 2 1  1 1 2  2 1 2  1 2 2  2 2 2"
                        TriangleIndices="2 3 1  2 1 0  7 1 3  7 5 1  6 5 7  6 4 5  6 2 0  2 0 4  2 7 3  2 6 7  0 1 5  0 5 4">
                                </MeshGeometry3D>
                            </GeometryModel3D.Geometry>
                            <GeometryModel3D.Material>
                                <DiffuseMaterial x:Name="sa">
                                    <DiffuseMaterial.Brush>
                                        <SolidColorBrush Color="Red"/>
                                    </DiffuseMaterial.Brush>
                                </DiffuseMaterial>
                            </GeometryModel3D.Material>
                        </GeometryModel3D>
                    </ModelVisual3D.Content>
                </ModelVisual3D>
                <hx:GridLinesVisual3D Width="8" Length="8" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>
            </hx:HelixViewport3D>
        </Grid>
    

    enter image description here