locked
2d on 3d cube question RRS feed

  • Question

  • I followed a rather insightful video by a user named Barkest to turn a 3d cube created in zam into a 3d cube with 2d objects on each face. Here is the xaml I have as a result:

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Tools="clr-namespace:_3DTools;assembly=3DTools"
        x:Class="cube.Window1"
        x:Name="Window"
        Title="Window1"
        Width="640" Height="480">
        <Window.Resources>
            <MaterialGroup x:Key="face2MR2" >
                <DiffuseMaterial Brush="#FFFF0000" Color="#FFFF0000" AmbientColor="#FFFF0000"/>
                <SpecularMaterial SpecularPower="85.3333">
                    <SpecularMaterial.Brush>
                        <SolidColorBrush Color="#FFFFFF" Opacity="1.000000"/>
                    </SpecularMaterial.Brush>
                </SpecularMaterial>
            </MaterialGroup>
            <MaterialGroup x:Key="face3MR3" >
                <DiffuseMaterial Color="#FFFF0000" Brush="#FFFF0000" AmbientColor="#FFFF0000"/>
                <SpecularMaterial SpecularPower="85.3333">
                    <SpecularMaterial.Brush>
                        <SolidColorBrush Color="#FFFFFF" Opacity="1.000000"/>
                    </SpecularMaterial.Brush>
                </SpecularMaterial>
            </MaterialGroup>
            <MaterialGroup x:Key="face4MR4" >
                <DiffuseMaterial Brush="#FFFF0000" Color="#FFFF0000" AmbientColor="#FFFF0000"/>
                <SpecularMaterial SpecularPower="85.3333">
                    <SpecularMaterial.Brush>
                        <SolidColorBrush Color="#FFFFFF" Opacity="1.000000"/>
                    </SpecularMaterial.Brush>
                </SpecularMaterial>
            </MaterialGroup>
            <MaterialGroup x:Key="face5MR5" >
                <DiffuseMaterial Brush="#FFFF0000" Color="#FFFF0000" AmbientColor="#FFFF0000"/>
                <SpecularMaterial SpecularPower="85.3333">
                    <SpecularMaterial.Brush>
                        <SolidColorBrush Color="#FFFFFF" Opacity="1.000000"/>
                    </SpecularMaterial.Brush>
                </SpecularMaterial>
            </MaterialGroup>
            <MaterialGroup x:Key="face6MR6" >
                <DiffuseMaterial Brush="#FFFF0000" Color="#FFFF0000" AmbientColor="#FFFF0000"/>
                <SpecularMaterial SpecularPower="85.3333">
                    <SpecularMaterial.Brush>
                        <SolidColorBrush Color="#FFFFFF" Opacity="1.000000"/>
                    </SpecularMaterial.Brush>
                </SpecularMaterial>
            </MaterialGroup>
            <Transform3DGroup x:Key="SceneTR12" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <Transform3DGroup x:Key="cubeGroupOR14TR13" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <Transform3DGroup x:Key="frontOR16TR15" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="frontOR16GR17"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1 "
                    TextureCoordinates="0,1 1,1 1,0 0,0 "
                    Positions="-3.98039,-2.95874,3.48956 2.99855,-2.95874,3.48956 2.99855,4.02016,3.48956 -3.98039,4.02016,3.48956 "
                />
            <Transform3DGroup x:Key="leftOR19TR18" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="leftOR19GR20"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                    TextureCoordinates="0,0 0,1 1,1 1,0 "
                    Positions="-3.98039,4.02016,-3.48931 -3.98039,-2.95874,-3.48931 -3.98039,-2.95874,3.48956 -3.98039,4.02016,3.48956 "
                />
            <Transform3DGroup x:Key="rightOR22TR21" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="rightOR22GR23"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                    TextureCoordinates="1,1 1,0 -0,0 -0,1 "
                    Positions="2.99855,-2.95874,-3.48931 2.99855,4.02016,-3.48931 2.99855,4.02016,3.48956 2.99855,-2.95874,3.48956 "
                />
            <Transform3DGroup x:Key="backOR25TR24" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="backOR25GR26"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                    TextureCoordinates="1,1 1,0 -0,0 -0,1 "
                    Positions="-3.98039,-2.95874,-3.48931 -3.98039,4.02016,-3.48931 2.99855,4.02016,-3.48931 2.99855,-2.95874,-3.48931 "
                />
            <Transform3DGroup x:Key="topOR28TR27" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="topOR28GR29"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                    TextureCoordinates="1,0 0,0 0,1 1,1 "
                    Positions="2.99855,4.02016,-3.48931 -3.98039,4.02016,-3.48931 -3.98039,4.02016,3.48956 2.99855,4.02016,3.48956 "
                />
            <Transform3DGroup x:Key="bottomOR31TR30" >
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
            </Transform3DGroup>
            <MeshGeometry3D x:Key="bottomOR31GR32"
                    TriangleIndices="0,1,2 2,3,0 "
                    Normals="0,0,1 0,0,1 0,0,1 0,0,1"
                    TextureCoordinates="0,1 1,1 1,0 0,0 "
                    Positions="-3.98039,-2.95874,-3.48931 2.99855,-2.95874,-3.48931 2.99855,-2.95874,3.48956 -3.98039,-2.95874,3.48956 "
                />

        </Window.Resources>


        <Grid x:Name="LayoutRoot">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Tools:TrackballDecorator Margin="125.159,69.626,106.841,76.374">
           
            <Viewport3D x:Name="ZAM3DViewport3D" ClipToBounds="false" Width="400" Height="300" >

                    <Viewport3D.Camera>
                        <PerspectiveCamera x:Name="FrontOR11" FarPlaneDistance="30" LookDirection="0,0,-1" UpDirection="0,1,0" NearPlaneDistance="0.1" Position="-0.490924,0.53071,18.0451" FieldOfView="39.5978" />
                    </Viewport3D.Camera>

                    <Viewport2DVisual3D Transform="{StaticResource frontOR16TR15}" Geometry="{StaticResource frontOR16GR17}">
                        <Viewport2DVisual3D.Material>
                       
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                       
                        <Grid x:Name="face1Grid">
                            <TextBox>front</TextBox>
                        </Grid>
                       
                    </Viewport2DVisual3D>
                   
                    <Viewport2DVisual3D Transform="{StaticResource leftOR19TR18}" Geometry="{StaticResource leftOR19GR20}">
                        <Viewport2DVisual3D.Material>
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                        <Grid x:Name="leftGrid">
                            <TextBox>left</TextBox>
                        </Grid>   
                    </Viewport2DVisual3D>
                   
                    <Viewport2DVisual3D Transform="{StaticResource rightOR22TR21}" Geometry="{StaticResource rightOR22GR23}">
                        <Viewport2DVisual3D.Material>
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                        <Grid x:Name="rightGrid">
                            <TextBox>right</TextBox>
                        </Grid>   
                    </Viewport2DVisual3D>
                   
                    <Viewport2DVisual3D Transform="{StaticResource backOR25TR24}" Geometry="{StaticResource backOR25GR26}">
                        <Viewport2DVisual3D.Material>
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                        <Grid x:Name="backGrid">
                            <TextBox>back</TextBox>
                        </Grid>   
                    </Viewport2DVisual3D>

                    <Viewport2DVisual3D Transform="{StaticResource topOR28TR27}" Geometry="{StaticResource topOR28GR29}">
                        <Viewport2DVisual3D.Material>
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                        <Grid x:Name="topGrid">
                            <TextBox>top</TextBox>
                        </Grid>   
                    </Viewport2DVisual3D>

                    <Viewport2DVisual3D Transform="{StaticResource bottomOR31TR30}" Geometry="{StaticResource bottomOR31GR32}">
                        <Viewport2DVisual3D.Material>
                            <MaterialGroup>
                                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/>
                                <SpecularMaterial Color="#FFFFFFFF" Brush="#FFFFFFFF"/>
                            </MaterialGroup>
                        </Viewport2DVisual3D.Material>
                        <Grid x:Name="bottomGrid">
                            <TextBox>bottom</TextBox>
                        </Grid>   
                    </Viewport2DVisual3D>

                    <ModelVisual3D>
                        <ModelVisual3D.Content>
                            <Model3DGroup x:Name="Scene" Transform="{DynamicResource SceneTR12}">
                                <AmbientLight Color="#333333" />
                                <DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
                                <DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" />
                            </Model3DGroup>
                        </ModelVisual3D.Content>
                    </ModelVisual3D>
                </Viewport3D>
            </Tools:TrackballDecorator>
        </Grid>
    </Window>

    My question is how can I make a rotation animation for this cube? I can no longer drag the 3d adorners in blend and move the entire cube at once. I have to make an animation cube that rotates the cube from it's current position 90 degrees in any direction (effectively showing the adjoining face) and I need to be able to twist the cube 90 degrees and 180 degrees from its current position in case the content on the cube is upside down. Does this make sense? I'm not real sure what terminology to use here I am really new to this 3d stuff.
    Monday, May 19, 2008 2:15 AM

Answers

  • Through a bit of trial and error and experimentation I found that I could wrap the pieces of the cube in a ModelVisual3D object and just move that object, it will in turn rotate all of the 3D pieces of the cube (the Viewport2DVisual3Ds).

    The other half of the solution to this was to create the storyboards in a programmatic fashion. I ultimately found no way of creating an animation in blend (or in XAML markup) that would rotate the cube by an offset, I could only do hard-coded values for the rotation and axis values in the animation that way.
    • Marked as answer by omatase Tuesday, June 24, 2008 4:24 PM
    Tuesday, June 24, 2008 3:55 PM