첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형

TestProject.zip
다운로드

▶ MeshExtension.cs

using System;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace TestProject
{
    /// <summary>
    /// 메쉬 확장
    /// </summary>
    public static class MeshExtension
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 세그먼트 추가하기 - AddSegment(meshGeometry3D, point3D1, point3D2, upVector3D, thickness, extend)

        /// <summary>
        /// 세그먼트 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="upVector3D">UP 3차원 벡터</param>
        /// <param name="thickness">두께</param>
        /// <param name="extend">확장 여부</param>
        public static void AddSegment(MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, Vector3D upVector3D, double thickness, bool extend)
        {
            Vector3D vector = point3D2 - point3D1;

            if(extend)
            {
                Vector3D scaleVector = GetScaleVector(vector, thickness / 2.0);

                point3D1 -= scaleVector;
                point3D2 += scaleVector;
            }

            Vector3D vector1 = GetScaleVector(upVector3D, thickness / 2.0);
            Vector3D vector2 = Vector3D.CrossProduct(vector, vector1);

            vector2 = GetScaleVector(vector2, thickness / 2.0);

            Point3D p1pp = point3D1 + vector1 + vector2;
            Point3D p1mp = point3D1 - vector1 + vector2;
            Point3D p1pm = point3D1 + vector1 - vector2;
            Point3D p1mm = point3D1 - vector1 - vector2;
            Point3D p2pp = point3D2 + vector1 + vector2;
            Point3D p2mp = point3D2 - vector1 + vector2;
            Point3D p2pm = point3D2 + vector1 - vector2;
            Point3D p2mm = point3D2 - vector1 - vector2;

            AddTriangle(meshGeometry3D, p1pp, p1mp, p2mp);
            AddTriangle(meshGeometry3D, p1pp, p2mp, p2pp);

            AddTriangle(meshGeometry3D, p1pp, p2pp, p2pm);
            AddTriangle(meshGeometry3D, p1pp, p2pm, p1pm);

            AddTriangle(meshGeometry3D, p1pm, p2pm, p2mm);
            AddTriangle(meshGeometry3D, p1pm, p2mm, p1mm);

            AddTriangle(meshGeometry3D, p1mm, p2mm, p2mp);
            AddTriangle(meshGeometry3D, p1mm, p2mp, p1mp);

            AddTriangle(meshGeometry3D, p1pp, p1pm, p1mm);
            AddTriangle(meshGeometry3D, p1pp, p1mm, p1mp);

            AddTriangle(meshGeometry3D, p2pp, p2mp, p2mm);
            AddTriangle(meshGeometry3D, p2pp, p2mm, p2pm);
        }

        #endregion
        #region 세그먼트 추가하기 - AddSegment(meshGeometry3D, point3D1, point3D2, upVector3D, thickness)

        /// <summary>
        /// 세그먼트 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="upVector3D">UP 3차원 벡터</param>
        /// <param name="thickness">두께</param>
        public static void AddSegment(MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, Vector3D upVector3D, double thickness)
        {
            AddSegment(meshGeometry3D, point3D1, point3D2, upVector3D, thickness, false);
        }

        #endregion
        #region 세그먼트 추가하기 - AddSegment(meshGeometry3D, point3D1, point3D2, thickness, extend)

        /// <summary>
        /// 세그먼트 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="thickness">두께</param>
        /// <param name="extend">확장 여부</param>
        public static void AddSegment(MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, double thickness, bool extend)
        {
            Vector3D upVector3D = new Vector3D(0, 1, 0);

            Vector3D segmentVector3D = point3D2 - point3D1;

            segmentVector3D.Normalize();

            if(Math.Abs(Vector3D.DotProduct(upVector3D, segmentVector3D)) > 0.9)
            {
                upVector3D = new Vector3D(1, 0, 0);
            }

            AddSegment(meshGeometry3D, point3D1, point3D2, upVector3D, thickness, extend);
        }

        #endregion
        #region 세그먼트 추가하기 - AddSegment(meshGeometry3D, point3D1, point3D2, thickness)

        /// <summary>
        /// 세그먼트 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하학</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="thickness">두께</param>
        public static void AddSegment(MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, double thickness)
        {
            AddSegment(meshGeometry3D, point3D1, point3D2, thickness, false);
        }

        #endregion

        #region 스케일 벡터 구하기 - GetScaleVector(vector3D, length)

        /// <summary>
        /// 스케일 벡터 구하기
        /// </summary>
        /// <param name="vector3D">3차원 벡터</param>
        /// <param name="length">길이</param>
        /// <returns>스케일 벡터</returns>
        public static Vector3D GetScaleVector(Vector3D vector3D, double length)
        {
            double scale = length / vector3D.Length;

            return new Vector3D
            (
                vector3D.X * scale,
                vector3D.Y * scale,
                vector3D.Z * scale
            );
        }

        #endregion

        #region 화살 추가하기 - AddArrow(meshGeometry3D, point3D1, point3D2, upVector3D, barbLength)

        /// <summary>
        /// 화살 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="upVector3D">UP 3차원 벡터</param>
        /// <param name="barbLength">미늘 길이</param>
        public static void AddArrow(this MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, Vector3D upVector3D, double barbLength)
        {
            AddSegment(meshGeometry3D, point3D1, point3D2, 0.05, true);

            Vector3D vector = point3D2 - point3D1;

            vector.Normalize();

            Vector3D perpendicularVector = Vector3D.CrossProduct(vector, upVector3D);

            perpendicularVector.Normalize();

            Vector3D vector1 = GetScaleVector(-vector + perpendicularVector, barbLength);
            Vector3D vector2 = GetScaleVector(-vector - perpendicularVector, barbLength);

            AddSegment(meshGeometry3D, point3D2, point3D2 + vector1, upVector3D, 0.05);
            AddSegment(meshGeometry3D, point3D2, point3D2 + vector2, upVector3D, 0.05);
        }

        #endregion
        #region 축 추가하기 - AddAxis(meshGeometry3D, point3D1, point3D2, upVector3D, ticDiameter, ticSeparation)

        /// <summary>
        /// 축 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="upVector3D">UP 3차원 벡터</param>
        /// <param name="ticDiameter">틱 반경</param>
        /// <param name="ticSeparation">틱 분리</param>
        public static void AddAxis(this MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, Vector3D upVector3D, double ticDiameter, double ticSeparation)
        {
            AddSegment(meshGeometry3D, point3D1, point3D2, 0.05, true);

            Vector3D vector = point3D2 - point3D1;

            double length = vector.Length;

            vector.Normalize();

            Point3D ticPoint3D = point3D1 + vector * (ticSeparation - 0.025);

            int ticCount = (int)(length / ticSeparation) - 1;

            for(int i = 0; i < ticCount; i++)
            {
                Point3D ticPoint3D2 = ticPoint3D + vector * 0.05;

                AddSegment(meshGeometry3D, ticPoint3D, ticPoint3D2, ticDiameter);

                ticPoint3D += vector * ticSeparation;
            }
        }

        #endregion
        #region 상자 추가하기 - AddBox(meshGeometry3D, x, y, z, deltaX, deltaY, deltaZ)

        /// <summary>
        /// 상자 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="x">X 좌표</param>
        /// <param name="y">X 좌표</param>
        /// <param name="z">X 좌표</param>
        /// <param name="deltaX">델타 X</param>
        /// <param name="deltaY">델타 Y</param>
        /// <param name="deltaZ">델타 Z</param>
        public static void AddBox(this MeshGeometry3D meshGeometry3D, float x, float y, float z, float deltaX, float deltaY, float deltaZ)
        {
            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y, z         ),
                new Point3D(x + deltaX, y, z         ),
                new Point3D(x + deltaX, y, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y, z         ),
                new Point3D(x + deltaX, y, z + deltaZ),
                new Point3D(x         , y, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y + deltaY, z         ),
                new Point3D(x         , y + deltaY, z + deltaZ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y + deltaY, z         ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ),
                new Point3D(x + deltaX, y + deltaY, z         )
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x, y         , z         ),
                new Point3D(x, y         , z + deltaZ),
                new Point3D(x, y + deltaY, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x, y         , z         ),
                new Point3D(x, y + deltaY, z + deltaZ),
                new Point3D(x, y + deltaY, z         )
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x + deltaX, y         , z         ),
                new Point3D(x + deltaX, y + deltaY, z         ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x + deltaX, y         , z         ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ),
                new Point3D(x + deltaX, y         , z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y         , z + deltaZ),
                new Point3D(x + deltaX, y         , z + deltaZ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y         , z + deltaZ),
                new Point3D(x + deltaX, y + deltaY, z + deltaZ),
                new Point3D(x         , y + deltaY, z + deltaZ)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y         , z),
                new Point3D(x         , y + deltaY, z),
                new Point3D(x + deltaX, y + deltaY, z)
            );

            AddTriangle
            (
                meshGeometry3D,
                new Point3D(x         , y         , z),
                new Point3D(x + deltaX, y + deltaY, z),
                new Point3D(x + deltaX, y         , z)
            );
        }

        #endregion

        #region X축 화살 3차원 메쉬 기하 구하기 - GetXAxisArrowMeshGeometry3D(length)

        /// <summary>
        /// X축 화살 3차원 메쉬 기하 구하기
        /// </summary>
        /// <param name="length">길이</param>
        /// <returns>X축 화살 3차원 메쉬 기하</returns>
        public static MeshGeometry3D GetXAxisArrowMeshGeometry3D(float length)
        {
            MeshGeometry3D meshGeometry3D = new MeshGeometry3D();

            meshGeometry3D.AddArrow(new Point3D(0, 0, 0), new Point3D(6, 0, 0), new Vector3D(0, 1, 0), 0.5);

            return meshGeometry3D;
        }

        #endregion
        #region Y축 화살 3차원 메쉬 기하 구하기 - GetYAxisArrowMeshGeometry3D(length)

        /// <summary>
        /// Y축 화살 3차원 메쉬 기하 구하기
        /// </summary>
        /// <param name="length">길이</param>
        /// <returns>Y축 화살 3차원 메쉬 기하</returns>
        public static MeshGeometry3D GetYAxisArrowMeshGeometry3D(float length)
        {
            MeshGeometry3D meshGeometry3D = new MeshGeometry3D();

            meshGeometry3D.AddArrow(new Point3D(0, 0, 0), new Point3D(0, 6, 0), new Vector3D(1, 0, 0), 0.5);

            return meshGeometry3D;
        }

        #endregion
        #region Z축 화살 3차원 메쉬 기하 구하기 - GetZAxisArrowMeshGeometry3D(length)

        /// <summary>
        /// Z축 화살 3차원 메쉬 기하 구하기
        /// </summary>
        /// <param name="length">길이</param>
        /// <returns>Z축 화살 3차원 메쉬 기하</returns>
        public static MeshGeometry3D GetZAxisArrowMeshGeometry3D(float length)
        {
            MeshGeometry3D meshGeometry3D = new MeshGeometry3D();

            meshGeometry3D.AddArrow(new Point3D(0, 0, 0), new Point3D(0, 0, 6), new Vector3D(0, 1, 0), 0.5);

            return meshGeometry3D;
        }

        #endregion

        #region 재료 설정하기 - SetMaterial(meshGeometry3D, brush, setBackMaterial)

        /// <summary>
        /// 재료 설정하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="brush">브러쉬</param>
        /// <param name="setBackMaterial">후면 재료 설정 여부</param>
        /// <returns>3차원 기하 모델</returns>
        public static GeometryModel3D SetMaterial(this MeshGeometry3D meshGeometry3D, Brush brush, bool setBackMaterial)
        {
            DiffuseMaterial diffuseMaterial = new DiffuseMaterial(brush);
            GeometryModel3D geometryModel3D = new GeometryModel3D(meshGeometry3D, diffuseMaterial);

            if(setBackMaterial)
            {
                geometryModel3D.BackMaterial = diffuseMaterial;
            }

            return geometryModel3D;
        }

        #endregion

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

        #region 삼각형 추가하기 - AddTriangle(meshGeometry3D, point3D1, point3D2, point3D3)

        /// <summary>
        /// 삼각형 추가하기
        /// </summary>
        /// <param name="meshGeometry3D">3차원 메쉬 기하</param>
        /// <param name="point3D1">3차원 포인트 1</param>
        /// <param name="point3D2">3차원 포인트 2</param>
        /// <param name="point3D3">3차원 포인트 2</param>
        private static void AddTriangle(MeshGeometry3D meshGeometry3D, Point3D point3D1, Point3D point3D2, Point3D point3D3)
        {
            int index = meshGeometry3D.Positions.Count;

            meshGeometry3D.Positions.Add(point3D1);
            meshGeometry3D.Positions.Add(point3D2);
            meshGeometry3D.Positions.Add(point3D3);

            meshGeometry3D.TriangleIndices.Add(index++);
            meshGeometry3D.TriangleIndices.Add(index++);
            meshGeometry3D.TriangleIndices.Add(index  );
        }

        #endregion
    }
}

 

728x90

 

▶ 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="3차원 객체 선택하기"
    Loaded="Window_Loaded"
    KeyDown="Window_KeyDown">
    <Grid>
        <Border Grid.Row="0" Grid.Column="0" Background="White"
            MouseDown="viewport3D_MouseDown">
            <Viewport3D Name="viewport3D" />
        </Border>
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 3차원 모델 그룹
        /// </summary>
        private Model3DGroup model3DGroup = new Model3DGroup();

        /// <summary>
        /// 카메라
        /// </summary>
        private PerspectiveCamera camera;

        /// <summary>
        /// 카메라 파이
        /// </summary>
        private double cameraPhi = Math.PI / 6.0;

        /// <summary>
        /// 카메라 세타
        /// </summary>
        private double cameraTheta = Math.PI / 6.0;

        /// <summary>
        /// 카메라 R
        /// </summary>
        private double cameraR = 15.0;

        /// <summary>
        /// 카메라 델타 파이
        /// </summary>
        private const double CAMERA_DELTA_PHI = 0.1;

        /// <summary>
        /// 카메라 델타 세타
        /// </summary>
        private const double CAMERA_DELTA_THETA = 0.1;

        /// <summary>
        /// 카메라 델타 R
        /// </summary>
        private const double CAMERA_DELTA_R = 0.1;

        /// <summary>
        /// 선택 3차원 기하 모델
        /// </summary>
        private GeometryModel3D selectedGeometryModel3D = null;

        /// <summary>
        /// 일반 재료
        /// </summary>
        private Material normalMaterial;
        
        /// <summary>
        /// 선택 재료
        /// </summary>
        private Material selectedMaterial;

        /// <summary>
        /// 선택 3차원 기하 모델 리스트
        /// </summary>
        private List<GeometryModel3D> selectedGeometryModel3DList = new List<GeometryModel3D>();

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

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

        /// <summary>
        /// 윈도우 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.camera = new PerspectiveCamera();

            this.camera.FieldOfView = 60;

            this.viewport3D.Camera = this.camera;

            SetCameraPosition();

            DefineLight(this.model3DGroup);

            DefineModel(this.model3DGroup);

            ModelVisual3D modelVisual3D = new ModelVisual3D();

            modelVisual3D.Content = this.model3DGroup;

            this.viewport3D.Children.Add(modelVisual3D);
        }

        #endregion
        #region 윈도우 키 DOWN 처리하기 - Window_KeyDown(sender, e)

        /// <summary>
        /// 윈도우 키 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            switch(e.Key)
            {
                case Key.Up :

                    this.cameraPhi += CAMERA_DELTA_PHI;

                    if(this.cameraPhi > Math.PI / 2.0)
                    {
                        this.cameraPhi = Math.PI / 2.0;
                    }

                    break;

                case Key.Down :

                    this.cameraPhi -= CAMERA_DELTA_PHI;

                    if(this.cameraPhi < -Math.PI / 2.0)
                    {
                        this.cameraPhi = -Math.PI / 2.0;
                    }

                    break;

                case Key.Left :

                    this.cameraTheta += CAMERA_DELTA_THETA;

                    break;

                case Key.Right :

                    this.cameraTheta -= CAMERA_DELTA_THETA;

                    break;

                case Key.Add     :
                case Key.OemPlus :

                    this.cameraR -= CAMERA_DELTA_R;

                    if(this.cameraR < CAMERA_DELTA_R)
                    {
                        this.cameraR = CAMERA_DELTA_R;
                    }

                    break;

                case Key.Subtract :
                case Key.OemMinus :

                    this.cameraR += CAMERA_DELTA_R;

                    break;
            }

            SetCameraPosition();
        }

        #endregion
        #region 3차원 뷰포트 마우스 DOWN 처리하기 - viewport3D_MouseDown(sender, e)

        /// <summary>
        /// 3차원 뷰포트 마우스 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void viewport3D_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if(this.selectedGeometryModel3D != null)
            {
                this.selectedGeometryModel3D.Material = this.normalMaterial;

                this.selectedGeometryModel3D = null;
            }

            Point mousePoint = e.GetPosition(this.viewport3D);

            HitTestResult hitTestResult = VisualTreeHelper.HitTest(this.viewport3D, mousePoint);

            RayMeshGeometry3DHitTestResult result = hitTestResult as RayMeshGeometry3DHitTestResult;

            if(result != null)
            {
                GeometryModel3D geometryModel3D = (GeometryModel3D)result.ModelHit;

                if(this.selectedGeometryModel3DList.Contains(geometryModel3D))
                {
                    this.selectedGeometryModel3D = geometryModel3D;

                    this.selectedGeometryModel3D.Material = this.selectedMaterial;
                }
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 카메라 위치 설정하기 - SetCameraPosition()

        /// <summary>
        /// 카메라 위치 설정하기
        /// </summary>
        private void SetCameraPosition()
        {
            double y   = this.cameraR * Math.Sin(this.cameraPhi);
            double hyp = this.cameraR * Math.Cos(this.cameraPhi);
            double x   = hyp * Math.Cos(this.cameraTheta);
            double z   = hyp * Math.Sin(this.cameraTheta);

            this.camera.Position = new Point3D(x, y, z);

            this.camera.LookDirection = new Vector3D(-x, -y, -z);

            this.camera.UpDirection = new Vector3D(0, 1, 0);
        }

        #endregion
        #region 조명 정의하기 - DefineLight(model3DGroup)

        /// <summary>
        /// 조명 정의하기
        /// </summary>
        /// <param name="model3DGroup">3차원 모델 그룹</param>
        private void DefineLight(Model3DGroup model3DGroup)
        {
            model3DGroup.Children.Add(new AmbientLight(Colors.DarkSlateGray));
            model3DGroup.Children.Add(new DirectionalLight(Colors.Gray, new Vector3D(3.0, -2.0, 1.0)));
            model3DGroup.Children.Add(new DirectionalLight(Colors.DarkGray, new Vector3D(-3.0, -2.0, -1.0)));
        }

        #endregion
        #region 모델 정의하기 - DefineModel(model3DGroup)

        /// <summary>
        /// 모델 정의하기
        /// </summary>
        /// <param name="model3DGroup">3차원 모델 그룹</param>
        private void DefineModel(Model3DGroup model3DGroup)
        {
            this.normalMaterial = new DiffuseMaterial(Brushes.LightGreen);

            this.selectedMaterial = new DiffuseMaterial(Brushes.Red);

            for(int x = -5; x <= 3; x += 4)
            {
                for(int y = -5; y <= 3; y += 4)
                {
                    for(int z = -5; z <= 3; z += 4)
                    {
                        MeshGeometry3D meshGeometry3D = new MeshGeometry3D();

                        meshGeometry3D.AddBox(x, y, z, 2, 2, 2);

                        GeometryModel3D geometryModel3D = new GeometryModel3D(meshGeometry3D, this.normalMaterial);

                        model3DGroup.Children.Add(geometryModel3D);

                        this.selectedGeometryModel3DList.Add(geometryModel3D);
                    }
                }
            }

            MeshGeometry3D xAxisMeshGeometry3D = MeshExtension.GetXAxisArrowMeshGeometry3D(6);

            model3DGroup.Children.Add(xAxisMeshGeometry3D.SetMaterial(Brushes.Red, false));

            MeshGeometry3D yAxisMeshGeometry3D = MeshExtension.GetYAxisArrowMeshGeometry3D(6);

            model3DGroup.Children.Add(yAxisMeshGeometry3D.SetMaterial(Brushes.Green, false));

            MeshGeometry3D zAxisMeshGeometry3D = MeshExtension.GetZAxisArrowMeshGeometry3D(6);

            model3DGroup.Children.Add(zAxisMeshGeometry3D.SetMaterial(Brushes.Blue, false));
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by 사용자 icodebroker
TAG , , ,

댓글을 달아 주세요