Need help with ModelVisual3Ds

DarkD

Member
Joined
Jun 16, 2014
Messages
16
Programming Experience
Beginner
I'm trying to make something like a freely rotatable rubicks cube of images. nine images on each side, and the whole thing can be rotated.

Now I have tried looking up how to do this and found

IT Notes: ???????? ? ????????????? 3d ?????? ? WPF

I don't understand the language, but it's the closest thing to what I want that I've found.

Now I am completely new to 3D WPF stuff and animations and such, and through sheer force of will have made a little progress in redoing this code to suit my needs. I have retooled this to have an image on each side, and I resized it to form a cube instead of a rectangle.

C#:
<Window x:Class="WPFApplication1.Sample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="3D Demo" Height="500" Width="500">
    <Window.Resources>




        <VisualBrush x:Key="mainCover">
            <VisualBrush.Visual>
                <Border Background="Yellow" BorderThickness="2">
                    <Image Source="image.jpg" />
                </Border>
            </VisualBrush.Visual>
        </VisualBrush>


        <SolidColorBrush x:Key="top" Color="BurlyWood" />
        <SolidColorBrush x:Key="pages" Color="BurlyWood" />
        <SolidColorBrush x:Key="back" Color="BurlyWood" />
        <SolidColorBrush x:Key="side" Color="BurlyWood" />
    </Window.Resources>
    <Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="0,-15,50" LookDirection="15,6,-50" />
        </Viewport3D.Camera>


        <ModelVisual3D>
            <ModelVisual3D.Content>
                <!--<AmbientLight Color="White" />-->
                <SpotLight Color="White" InnerConeAngle="20" OuterConeAngle="60" Direction="15,6,-50" Position="0,0,25" />
            </ModelVisual3D.Content>
        </ModelVisual3D>


        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>


                    <!-- front -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                                Positions="0 0 0, 16 0 0, 0 16 0, 16 16 0, 16 0 0"
                                TriangleIndices="0, 1, 2, 2, 4, 3"
                                TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"
                                />
                        </GeometryModel3D.Geometry>


                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>






                    <!-- left -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                            Positions="0 0 -16, 0 0 0, 0 16 -16, 0 16 0, 0 0 0"
                                TriangleIndices="0, 1, 2, 2, 4, 3"
                            TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"/>
                        </GeometryModel3D.Geometry>




                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>


                    <!-- right  -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                            Positions="16 0 0, 16 0 -16, 16 16 0, 16 16 -16, 16 0 -16"
                                TriangleIndices="0, 1, 2, 2, 4, 3"
                            TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"/>
                        </GeometryModel3D.Geometry>




                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>




                    <!-- top side -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                            Positions="0 16 0, 0 16 -16, 16 16 0, 16 16 -16, 0 16 -16"
                                TriangleIndices="0, 2, 1, 2, 3, 4"
                                TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"
                                />
                        </GeometryModel3D.Geometry>




                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>


                    <!-- bottom -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                            Positions="0 0 0, 0 0 -16, 16 0 0, 16 0 -16, 0 0 -16"
                                TriangleIndices="0, 1, 2, 2, 4, 3"
                            TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"/>
                        </GeometryModel3D.Geometry>




                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>


                    <!-- back -->
                    <GeometryModel3D>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D
                            Positions="0 0 -16, 16 0 -16, 0 16 -16, 16 16 -16, 16 0 -16"
                                TriangleIndices="0, 2, 1, 2, 3, 4"
                            TextureCoordinates="0 1, 1 1, 0 0, 1 0, 1 1"/>
                        </GeometryModel3D.Geometry>




                        <GeometryModel3D.Material>
                            <MaterialGroup>
                                <SpecularMaterial SpecularPower="99">
                                    <SpecularMaterial.Brush>
                                        <SolidColorBrush>Yellow</SolidColorBrush>
                                    </SpecularMaterial.Brush>
                                </SpecularMaterial>
                                <DiffuseMaterial Brush="{StaticResource mainCover}" />
                            </MaterialGroup>


                        </GeometryModel3D.Material>
                    </GeometryModel3D>




                    <Model3DGroup.Transform>
                        <RotateTransform3D CenterX="0" CenterY="0" CenterZ="0">
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D x:Name="angle" Axis="-1,-1,-1" Angle="70" />
                            </RotateTransform3D.Rotation>


                        </RotateTransform3D>
                    </Model3DGroup.Transform>


                </Model3DGroup>


            </ModelVisual3D.Content>
        </ModelVisual3D>


    </Viewport3D>
    <Window.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation From="0" To="360" Duration="00:00:10" Storyboard.TargetName="angle" Storyboard.TargetProperty="Angle" RepeatBehavior="Forever" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
</Window>
Now what I want to do next is first change the rotation axis so that it's at the center of the cube. Right now it's way out there making the cube fly around when it rotates. I can't find the right attribute to mess with for the life of me...

Then I wanna change it to full bright. Like I don't want some fancy lighting system, I just wanna see the images all fully lit.

Finally, is there a good beginners tutorial explaining all of this because the MSDN is painfully lacking information.
 
Top Bottom