첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ Viewport3D 클래스 : 큐브 움직이기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip



MainWindow.xaml

 

 

<Window x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="800"

    Height="600"

    Title="Viewport3D 클래스 : 큐브 움직이기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Window.Resources>

        <SolidColorBrush x:Key="blueSolidColorBrushKey"

            Color="Blue"

            Opacity="1.0" />

        <SolidColorBrush x:Key="orangeSolidColorBrushKey"

            Color="Orange"

            Opacity="1.0" />

        <SolidColorBrush x:Key="yellowSolidColorBrushKey"

            Color="Yellow"

            Opacity="1.0" />

        <SolidColorBrush x:Key="redSolidColorBrushKey"

            Color="Red"

            Opacity="1.0" />

        <SolidColorBrush x:Key="cyanSolidColorBrushKey"

            Color="Cyan"

            Opacity="1.0" />

        <DrawingBrush x:Key="patternDrawingBrushKey"

            Viewport="0 0 0.1 0.1"

            TileMode="Tile">

            <DrawingBrush.Drawing>

                <DrawingGroup>

                    <DrawingGroup.Children>

                        <GeometryDrawing

                            Brush="Gray"

                            Geometry="M 0 0.1 L 0.1 0 1 0.9 0.9 1 z" />

                        <GeometryDrawing

                            Brush="Gray"

                            Geometry="M 0.9 0 L 1 0.1 0.1 1 0 0.9 z" />

                        <GeometryDrawing

                            Brush="#ffff00"

                            Geometry="M 0.25 0.25 L 0.5 0.125 0.75 0.25 0.5 0.5 z" />

                        <GeometryDrawing

                            Brush="Black"

                            Geometry="M 0.25 0.75 L 0.5 0.875 0.75 0.75 0.5 0.5 z" />

                        <GeometryDrawing

                            Brush="#ff0000"

                            Geometry="M 0.25 0.75 L 0.125 0.5 0.25 0.25 0.5 0.5 z" />

                        <GeometryDrawing

                            Brush="MediumBlue"

                            Geometry="M 0.75 0.25 L 0.875 0.5 0.75 0.75 0.5 0.5 z" />

                    </DrawingGroup.Children>

                </DrawingGroup>

            </DrawingBrush.Drawing>

        </DrawingBrush>

    </Window.Resources>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

using System.Windows.Media.Media3D;

using System.Windows.Media.Animation;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            Loaded += Window_Loaded;

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

 

        /// <summary>

        /// 윈도우 로드시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 발생자</param>

        private void Window_Loaded(object sender, EventArgs e)

        {

            #region 사이드 1 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side1PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5,  0.5, -0.5));

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5,  0.5, -0.5));

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5,  0.5, -0.5));

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, -0.5, -0.5));

            side1PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

 

            side1PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side1PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side1PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side1PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side1PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side1PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

            side1PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, -1));

 

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side1PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

 

            #endregion

            #region 사이드 2 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side2PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, 0.5));

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, -0.5, 0.5));

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5,  0.5, 0.5));

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5,  0.5, 0.5));

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5,  0.5, 0.5));

            side2PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, 0.5));

 

            side2PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side2PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side2PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side2PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side2PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side2PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

            side2PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 0, 1));

 

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side2PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

 

            #endregion

            #region 사이드 3 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side3PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, -0.5, -0.5));

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, -0.5,  0.5));

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, -0.5,  0.5));

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5,  0.5));

            side3PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

 

            side3PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side3PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side3PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side3PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side3PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side3PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

            side3PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, -1, 0));

 

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side3PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

 

            #endregion

            #region 사이드 4 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side4PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5, -0.5, -0.5));

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5,  0.5, -0.5));

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5,  0.5,  0.5));

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5,  0.5,  0.5));

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5, -0.5,  0.5));

            side4PlaneMeshGeometry3D.Positions.Add(new Point3D(0.5, -0.5, -0.5));

 

            side4PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side4PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side4PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side4PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side4PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side4PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

            side4PlaneMeshGeometry3D.Normals.Add(new Vector3D(1, 0, 0));

 

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side4PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

 

            #endregion

            #region 사이드 5 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side5PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, 0.5, -0.5));

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, 0.5, -0.5));

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, 0.5,  0.5));

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, 0.5,  0.5));

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, 0.5,  0.5));

            side5PlaneMeshGeometry3D.Positions.Add(new Point3D( 0.5, 0.5, -0.5));

 

            side5PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side5PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side5PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side5PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side5PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side5PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

            side5PlaneMeshGeometry3D.Normals.Add(new Vector3D(0, 1, 0));

 

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side5PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

 

            #endregion

            #region 사이드 6 면 메쉬 지오메트리 3D를 설정한다.

 

            MeshGeometry3D side6PlaneMeshGeometry3D = new MeshGeometry3D();

 

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5,  0.5, -0.5));

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5,  0.5));

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5, -0.5,  0.5));

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5,  0.5,  0.5));

            side6PlaneMeshGeometry3D.Positions.Add(new Point3D(-0.5,  0.5, -0.5));

 

            side6PlaneMeshGeometry3D.TriangleIndices.Add(0);

            side6PlaneMeshGeometry3D.TriangleIndices.Add(1);

            side6PlaneMeshGeometry3D.TriangleIndices.Add(2);

            side6PlaneMeshGeometry3D.TriangleIndices.Add(3);

            side6PlaneMeshGeometry3D.TriangleIndices.Add(4);

            side6PlaneMeshGeometry3D.TriangleIndices.Add(5);

 

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

            side6PlaneMeshGeometry3D.Normals.Add(new Vector3D(-1, 0, 0));

 

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

            side6PlaneMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

 

            #endregion

 

            #region 사이드 1 확산 재질을 설정한다.

 

            DiffuseMaterial side1DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("blueSolidColorBrushKey"));

 

            #endregion

            #region 사이드 2 확산 재질을 설정한다.

 

            DiffuseMaterial side2DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("yellowSolidColorBrushKey"));

 

            #endregion

            #region 사이드 3 확산 재질을 설정한다.

 

            DiffuseMaterial side3DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("redSolidColorBrushKey"));

 

            #endregion

            #region 사이드 4 확산 재질을 설정한다.

 

            DiffuseMaterial side4DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("cyanSolidColorBrushKey"));

 

            #endregion

            #region 사이드 5 확산 재질을 설정한다.

 

            DiffuseMaterial side5DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("patternDrawingBrushKey"));

 

            #endregion

            #region 사이드 6 확산 재질을 설정한다.

 

            DiffuseMaterial side6DiffuseMaterial = new DiffuseMaterial(GetResource<Brush>("orangeSolidColorBrushKey"));

 

            #endregion

 

            #region 사이드 1 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side1GeometryModel3D = new GeometryModel3D();

 

            side1GeometryModel3D.Geometry = side1PlaneMeshGeometry3D;

            side1GeometryModel3D.Material = side1DiffuseMaterial;

 

            #endregion

            #region 사이드 2 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side2GeometryModel3D = new GeometryModel3D();

 

            side2GeometryModel3D.Geometry = side2PlaneMeshGeometry3D;

            side2GeometryModel3D.Material = side2DiffuseMaterial;

 

            #endregion

            #region 사이드 3 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side3GeometryModel3D = new GeometryModel3D();

 

            side3GeometryModel3D.Geometry = side3PlaneMeshGeometry3D;

            side3GeometryModel3D.Material = side3DiffuseMaterial;

 

            #endregion

            #region 사이드 4 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side4GeometryModel3D = new GeometryModel3D();

 

            side4GeometryModel3D.Geometry = side4PlaneMeshGeometry3D;

            side4GeometryModel3D.Material = side4DiffuseMaterial;

 

            #endregion

            #region 사이드 5 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side5GeometryModel3D = new GeometryModel3D();

 

            side5GeometryModel3D.Geometry = side5PlaneMeshGeometry3D;

            side5GeometryModel3D.Material = side5DiffuseMaterial;

 

            #endregion

            #region 사이드 6 지오메트리 모델 3D를 설정한다.

 

            GeometryModel3D side6GeometryModel3D = new GeometryModel3D();

 

            side6GeometryModel3D.Geometry = side6PlaneMeshGeometry3D;

            side6GeometryModel3D.Material = side6DiffuseMaterial;

 

            #endregion

 

            #region 큐브 2 이동 변환 3D를 설정한다.

 

            TranslateTransform3D cube2TranslateTransform3D = new TranslateTransform3D(new Vector3D(2, 0, 0));

 

            #endregion

            #region 큐브 3 이동 변환 3D를 설정한다.

 

            TranslateTransform3D cube3TranslateTransform3D = new TranslateTransform3D(new Vector3D(4, 0, 0));

 

            #endregion

            #region 회전 변환 3D를 설정한다.

 

            RotateTransform3D rotateTransform3D = new RotateTransform3D

            (

                new AxisAngleRotation3D

                (

                    new Vector3D(0, 1, 0),

                    1

                )

            );

 

            #endregion

 

            #region 실수 애니메이션을 설정한다.

 

            DoubleAnimation doubleAnimation = new DoubleAnimation();

 

            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            doubleAnimation.From           = 1;

            doubleAnimation.To             = 361;

            doubleAnimation.Duration       = new Duration(TimeSpan.FromMilliseconds(5000));

 

            #endregion

            #region 벡터 3D 애니메이션을 설정한다.

 

            Vector3DAnimation vector3DAnimation = new Vector3DAnimation

            (

                new Vector3D(-1, -1, -1),

                new Duration(TimeSpan.FromMilliseconds(5000))

            );

 

            vector3DAnimation.RepeatBehavior = RepeatBehavior.Forever;

 

            #endregion

 

            #region 큐브 1 변환 3D 그룹을 설정한다.

 

            Transform3DGroup cube1Transform3DGroup = new Transform3DGroup();

 

            cube1Transform3DGroup.Children.Add(rotateTransform3D);

 

            #endregion

            #region 큐브 2 변환 3D 그룹을 설정한다.

 

            Transform3DGroup cube2Transform3DGroup = new Transform3DGroup();

 

            cube2Transform3DGroup.Children.Add(rotateTransform3D);

            cube2Transform3DGroup.Children.Add(cube2TranslateTransform3D);

 

            #endregion

            #region 큐브 3 변환 3D 그룹을 설정한다.

 

            Transform3DGroup cube3Transform3DGroup = new Transform3DGroup();

 

            cube3Transform3DGroup.Children.Add(rotateTransform3D);

            cube3Transform3DGroup.Children.Add(cube3TranslateTransform3D);

 

            #endregion

            #region 모든 큐브 변환 3D 그룹을 설정한다.

 

            Transform3DGroup allTransform3DGroup = new Transform3DGroup();

 

            allTransform3DGroup.Children.Add(rotateTransform3D);

 

            #endregion

 

            #region 큐브 1 모델 3D 그룹을 설정한다.

 

            Model3DGroup cube1Model3DGroup = new Model3DGroup();

 

            cube1Model3DGroup.Transform = cube1Transform3DGroup;

 

            cube1Model3DGroup.Children.Add(side1GeometryModel3D);

            cube1Model3DGroup.Children.Add(side2GeometryModel3D);

            cube1Model3DGroup.Children.Add(side3GeometryModel3D);

            cube1Model3DGroup.Children.Add(side4GeometryModel3D);

            cube1Model3DGroup.Children.Add(side5GeometryModel3D);

            cube1Model3DGroup.Children.Add(side6GeometryModel3D);

 

            #endregion

            #region 큐브 2 모델 3D 그룹을 설정한다.

 

            Model3DGroup cube2Model3DGroup = new Model3DGroup();

 

            cube2Model3DGroup.Transform = cube2Transform3DGroup;

 

            cube2Model3DGroup.Children.Add(side1GeometryModel3D);

            cube2Model3DGroup.Children.Add(side2GeometryModel3D);

            cube2Model3DGroup.Children.Add(side3GeometryModel3D);

            cube2Model3DGroup.Children.Add(side4GeometryModel3D);

            cube2Model3DGroup.Children.Add(side5GeometryModel3D);

            cube2Model3DGroup.Children.Add(side6GeometryModel3D);

 

            #endregion

            #region 큐브 3 모델 3D 그룹을 설정한다.

 

            Model3DGroup cube3Model3DGroup = new Model3DGroup();

 

            cube3Model3DGroup.Transform = cube3Transform3DGroup;

 

            cube3Model3DGroup.Children.Add(side1GeometryModel3D);

            cube3Model3DGroup.Children.Add(side2GeometryModel3D);

            cube3Model3DGroup.Children.Add(side3GeometryModel3D);

            cube3Model3DGroup.Children.Add(side4GeometryModel3D);

            cube3Model3DGroup.Children.Add(side5GeometryModel3D);

            cube3Model3DGroup.Children.Add(side6GeometryModel3D);

 

            #endregion

 

            #region 주변광을 설정한다.

 

            AmbientLight ambientLight = new AmbientLight();

 

            ambientLight.Color = Colors.White;

 

            #endregion

            #region 모든 큐브 모델 3D 그룹을 설정한다.

 

            Model3DGroup allModel3DGroup = new Model3DGroup();

 

            allModel3DGroup.Transform = allTransform3DGroup;

 

            allModel3DGroup.Children.Add(cube3Model3DGroup);

            allModel3DGroup.Children.Add(cube2Model3DGroup);

            allModel3DGroup.Children.Add(cube1Model3DGroup);

 

            allModel3DGroup.Children.Add(ambientLight);

 

            #endregion

 

            #region 모델 비주얼 3D를 설정한다.

 

            ModelVisual3D modelVisual3D = new ModelVisual3D();

 

            modelVisual3D.Content = allModel3DGroup;

 

            #endregion

            #region 카메라를 설정한다.

 

            PerspectiveCamera perspectiveCamera = new PerspectiveCamera();

 

            perspectiveCamera.Position          = new Point3D(-5, 2, 3);

            perspectiveCamera.UpDirection       = new Vector3D(0, 1, 0);

            perspectiveCamera.LookDirection     = new Vector3D(5, -2, -3);

            perspectiveCamera.FieldOfView       = 50;

            perspectiveCamera.FarPlaneDistance  = 20;

            perspectiveCamera.NearPlaneDistance = 0;

 

            #endregion

            #region 뷰포트 3D를 설정한다.

 

            Viewport3D viewport3D = new Viewport3D();

 

            viewport3D.Camera = perspectiveCamera;

 

            viewport3D.Children.Add(modelVisual3D);

 

            Content = viewport3D;

 

            #endregion

 

            rotateTransform3D.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, doubleAnimation  );

            rotateTransform3D.Rotation.BeginAnimation(AxisAngleRotation3D.AxisProperty , vector3DAnimation);

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 리소스 구하기 - GetResource<T>(resourceKey)

 

        /// <summary>

        /// 리소스 구하기

        /// </summary>

        /// <typeparam name="T">리소스 타입</typeparam>

        /// <param name="resourceKey">리소스 키</param>

        /// <returns>리소스</returns>

        private T GetResource<T>(string resourceKey)

        {

            return (T)Application.Current.MainWindow.Resources[resourceKey];

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요