locked
WPF 3D How to make a cube on each side of which is another picture? RRS feed

  • Question

  • Good day!

    Please help!

    I did the program that created a cube that can be rotated on the axes. I pulled on this cube texture in the form of a cat. For some reason, the texture appeared on 4 of the 6 sides of the cube (you can tell why? Although, it is not the main issue in this thread).

    The main question is: I need that would be on each side of the cube has been different pictures. How to do it?

    So, a full listing of the 'cube rotation about the axes'

    <Window x:Class="Вращение_кубика_вокруг_осей.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Вращение кубика вокруг осей" Height="350" Width="525" WindowStartupLocation="CenterScreen">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="3*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="0" VerticalAlignment="Stretch" Width="5"></GridSplitter>
    
            <Label Grid.Column="0" Content="xyz" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,0,0,0" FontSize="14"/>
    
            <Label Grid.Column="0" Content="z" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="18,25,0,0" FontSize="14"/>
            <Label Grid.Column="0" Content="y" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,50,0,0" FontSize="14"/>
            <Label Grid.Column="0" Content="x" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8,75,0,0" FontSize="14"/>
    
            <Slider Grid.Column="0" Height="25" VerticalAlignment="Top"  Minimum="-360" Maximum="360" Value="{Binding ElementName=rotate_xyz, Path= Angle}" Margin="40,3,0,0" />
    
            <Slider Grid.Column="0" Height="25" VerticalAlignment="Top"  Minimum="-360" Maximum="360" Value="{Binding ElementName=rotate_z, Path= Angle}" Margin="40,28,0,0" />
            <Slider Grid.Column="0" Height="25" VerticalAlignment="Top"  Minimum="-360" Maximum="360" Value="{Binding ElementName=rotate_y, Path= Angle}" Margin="40,53,0,0" />
            <Slider Grid.Column="0" Height="25" VerticalAlignment="Top"  Minimum="-360" Maximum="360" Value="{Binding ElementName=rotate_x, Path= Angle}" Margin="40,78,0,0" />
    
    
            <Viewport3D Grid.Column="1" Margin="0,0,0,0">
                <Viewport3D.Camera>
                    <!--Установка камеры - перспективная проекция-->
                    <PerspectiveCamera Position="0, 0, 8" LookDirection="0, 0, -3.5" />
                    <!--FieldOfView="120"-->
                </Viewport3D.Camera>
                <Viewport3D.Children>
                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <!--Установка освещения - прямой свет-->
                            <DirectionalLight Color="White" Direction="-2, -2.5, -2" />
                            <!--<PointLight Color="White" Position="2,2,2" />-->
                            <!--<SpotLight Color="White" Position="1,3,2" Direction="1,-1,-1"
                   InnerConeAngle="90" OuterConeAngle="90" Range="4" />-->
                        </ModelVisual3D.Content>
                    </ModelVisual3D>
                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <GeometryModel3D>
                                <!--Определяем геометрию объекта-->
                                <GeometryModel3D.Geometry>
                                    <MeshGeometry3D Positions="-1,-1,-1 1,-1,-1 -1,1,-1 1,1,-1 
                                                               -1,-1, 1 1,-1, 1 -1,1, 1 1,1,1"
                                        
                                                    TriangleIndices="0,2,1 1,2,3 4,6,0 2,0,6 
                                                                     0,1,4 1,5,4 1,7,5 1,3,7
                                                                     4,5,6 7,6,5 2,6,3 3,6,7"
                                                    TextureCoordinates="1,1 0,1 1,0 0,0
                                                                        0,1 1,1 0,0 1,0"/>
                                </GeometryModel3D.Geometry>
                                <!--Установка материала - красный цвет-->
                                <GeometryModel3D.Material>
                                    <!--<DiffuseMaterial Brush="LightCoral" AmbientColor="Red" />-->
                                    <MaterialGroup>
                                        <DiffuseMaterial Brush="LightBlue" />
                                        <DiffuseMaterial>
                                            <DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="cat.jpg" />
                                            </DiffuseMaterial.Brush>
                                            <!--<DiffuseMaterial.Brush>
                                                <ImageBrush ImageSource="http://social.msdn.microsoft.com/Forums/getfile/305344" />
                                            </DiffuseMaterial.Brush>-->
                                        </DiffuseMaterial>
                                        <EmissiveMaterial Brush="DarkBlue" />
                                    </MaterialGroup>
                                </GeometryModel3D.Material>
                            </GeometryModel3D>
                        </ModelVisual3D.Content>
                        <ModelVisual3D.Transform>
                            <Transform3DGroup>
                                <RotateTransform3D>
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="rotate_xyz" Axis="1 1 1" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <RotateTransform3D>
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="rotate_x" Axis="1 0 0" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <RotateTransform3D>
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="rotate_y" Axis="0 1 0" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <RotateTransform3D>
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="rotate_z" Axis="0 0 1" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                            </Transform3DGroup>
                        </ModelVisual3D.Transform>
                    </ModelVisual3D>
                </Viewport3D.Children>
            </Viewport3D>
        </Grid>
    </Window>

    sorry for my english

    I saw this: WPF 3D CUBE design

    Is it possible to not draw 6 sides? And draw a 1 cube. And on each side of the cube to place another picture?

    P.S. my original question: WPF 3D Как сделать кубик на каждой стороне которого будет свой рисунок?



    • Edited by sg6336 Friday, July 5, 2013 5:22 PM
    Friday, July 5, 2013 5:17 PM

Answers

All replies