Sample
View Mouse Down/Move/Up/DoubleClick/Wheel 이벤트 추가
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
public void Example()
{
vizcore3d.View.OnViewDefaultMouseDownEvent += View_OnViewDefaultMouseDownEvent;
vizcore3d.View.OnViewDefaultMouseMoveEvent += View_OnViewDefaultMouseMoveEvent;
vizcore3d.View.OnViewDefaultMouseUpEvent += View_OnViewDefaultMouseUpEvent;
vizcore3d.View.OnViewDefaultMouseDoubleClickEvent += View_OnViewDefaultMouseDoubleClickEvent;
vizcore3d.View.OnViewDefaultMouseWheelEvent += View_OnViewDefaultMouseWheelEvent;
}
private void View_OnViewDefaultMouseDownEvent(object sender, MouseEventArgs e)
{
int index = vizcore3d.View.HitTest(e.Location.X, e.Location.Y);
if (index == -1) return;
VIZCore3D.NET.Data.Node node = vizcore3d.Object3D.FromIndex(index);
}
private void View_OnViewDefaultMouseMoveEvent(object sender, MouseEventArgs e)
{
}
private void View_OnViewDefaultMouseUpEvent(object sender, MouseEventArgs e)
{
int index = vizcore3d.View.HitTest(e.Location.X, e.Location.Y);
if (index == -1) return;
VIZCore3D.NET.Data.Node node = vizcore3d.Object3D.FromIndex(index);
}
private void View_OnViewDefaultMouseDoubleClickEvent(object sender, MouseEventArgs e)
{
int index = vizcore3d.View.HitTest(e.Location.X, e.Location.Y);
if (index == -1) return;
VIZCore3D.NET.Data.Node node = vizcore3d.Object3D.FromIndex(index);
}
private void View_OnViewDefaultMouseWheelEvent(object sender, MouseEventArgs e)
{
if(e.Delta > 0)
{
// Some Code Here...
}
else
{
// Some Code Here...
}
}
Matrix 기반 모델(노드) Transform
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
public void Example()
{
string matrixStr = "1,0,0,0,0,1,0,0,0,0,1,0,188370,-22350,0,1";
VIZCore3D.NET.Data.Matrix3D matrix = VIZCore3D.NET.Data.Matrix3D.FromString(matrixStr);
VIZCore3D.NET.Data.Node node = vizcore3d.Object3D.FromIndex(5);
node.Transform(matrix, true);
}
Matrix 행열/열행 우선 전환 함수
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
public void Example()
{
string matrixStr = "1,0,0,0,0,1,0,0,0,0,1,0,188370,-22350,0,1";
VIZCore3D.NET.Data.Matrix3D matrix = VIZCore3D.NET.Data.Matrix3D.FromString(matrixStr);
// If necessary
matrix.Flip();
VIZCore3D.NET.Data.Node node = vizcore3d.Object3D.FromIndex(5);
node.Transform(matrix, true);
}
VIZCore3D.NET Module 초기화 유틸리티 함수
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
public FrmMain()
{
InitializeComponent();
//===================================
// Environment
//===================================
string assemblyPath = VIZCore3D.NET.ModuleInitializer.GetAssemblyLocation();
string entryAssemblyPath = VIZCore3D.NET.ModuleInitializer.GetEntryAssemblyLocation();
string assemblyVersion = VIZCore3D.NET.ModuleInitializer.GetLibraryVersion();
string interopVersion = VIZCore3D.NET.ModuleInitializer.GetInteropLibraryVersion();
bool compareVersion = VIZCore3D.NET.ModuleInitializer.CompareVersion();
bool existLibrary = VIZCore3D.NET.ModuleInitializer.ExistLibrary();
// Initialize VIZCore3D.NET
// Case 1. : Extract Library by Condition
//if(existLibrary == false || compareVersion == false)
// VIZCore3D.NET.ModuleInitializer.Run();
// Case 2. : Extract Library Always
VIZCore3D.NET.ModuleInitializer.Run();
// Construction
vizcore3d = new VIZCore3D.NET.VIZCore3DControl();
vizcore3d.Dock = DockStyle.Fill;
panelView.Controls.Add(vizcore3d);
// Event
vizcore3d.OnInitializedVIZCore3D += VIZCore3D_OnInitializedVIZCore3D;
}
리뷰(노트, 측정)의 위치 변경 기능 추가
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
public void Example()
{
int noteId = 5;
// 해당 리뷰(노트)의 정보 조회
VIZCore3D.NET.Data.NoteItem note = vizcore3d.Review.Note.GetItem(noteId);
// 해당 리뷰(노트)의 위치 정보 조회
List<VIZCore3D.NET.Data.ReviewPosition> positions = note.Position;
// 이동 거리
VIZCore3D.NET.Data.Vertex3D distance = new Data.Vertex3D(100, 200, 0);
// 마우스가 이동한 거리만큼 리뷰의 위치를 재설정
// Note Data : positions[0]
// Note Position : positions[0].Position
note.UpdatePosition(positions[0], positions[0].Position + distance);
}
마우스 기반 이동/회전 관련 기능에 Mouse Down/Move/Up/DoubleClick 이벤트 추가
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
// 마우스 위치
public System.Drawing.Point MousePt { get; set; }
// 선택 BLOCK 이동 거리
public VIZCore3D.NET.Data.Vertex3D BlockMovingDistance { get; set; }
private void Example()
{
// 마우스 다운 이벤트
vizcore3d.View.MouseBasedObjectMove.OnMouseDownEvent += MouseBasedObjectMove_OnMouseDownEvent;
// 마우스 이동 이벤트
vizcore3d.View.MouseBasedObjectMove.OnMouseMoveEvent += MouseBasedObjectMove_OnMouseMoveEvent;
// 마우스 업 이벤트
vizcore3d.View.MouseBasedObjectMove.OnMouseUpEvent += MouseBasedObjectMove_OnMouseUpEvent;
// 마우스 더블클릭 이벤트
vizcore3d.View.MouseBasedObjectMove.OnMouseDoubleClickEvent += MouseBasedObjectMove_OnMouseDoubleClickEvent;
}
private void MouseBasedObjectMove_OnMouseDownEvent(object sender, VIZCore3D.NET.Event.EventManager.MouseBaseObjectMoveEventArgs e)
{
string str = string.Format("Mouse Down : {0} / {1} / {2} / {3} / {4} / {5} / {6}"
, e.MoveOption.ToString()
, e.GroupId
, e.Move.ToString()
, e.Anlge
, e.MousePosition.X
, e.MousePosition.Y
, e.Node.Count()
);
System.Diagnostics.Debug.WriteLine(str);
// Mouse Down 위치 백업
MousePt = e.MousePosition;
// 선택 BLOCK 위치
BlockMovingDistance = new VIZCore3D.NET.Data.Vertex3D(0, 0, 0);
}
private void MouseBasedObjectMove_OnMouseMoveEvent(object sender, VIZCore3D.NET.Event.EventManager.MouseBaseObjectMoveEventArgs e)
{
string str = string.Format("Mouse Move : {0} / {1} / {2} / {3} / {4} / {5} / {6}"
, e.MoveOption.ToString()
, e.GroupId
, e.Move.ToString()
, e.Anlge
, e.MousePosition.X
, e.MousePosition.Y
, e.Node.Count()
);
System.Diagnostics.Debug.WriteLine(str);
// 마우스로 회전일 경우는 중단
if (e.MoveOption == VIZCore3D.NET.Manager.MouseBasedObjectMoveManager.MovingOptions.ROTATION) return;
// 현재 이동되는 개체의 연계된 리뷰 정보(아이디) 조회
List<int> review = vizcore3d.View.MouseBasedObjectMove.GetLinkedReview(e.GroupId);
if (review.Count == 0) return;
// 해당 리뷰(노트)의 정보 조회
VIZCore3D.NET.Data.NoteItem note = vizcore3d.Review.Note.GetItem(review[0]);
// 해당 리뷰(노트)의 위치 정보 조회
List<VIZCore3D.NET.Data.ReviewPosition> position = note.Position;
// 마우스가 이동한 거리만큼 리뷰의 위치를 재설정
note.UpdatePosition(position[0], position[0].Position + e.Move);
// BLOCK 이동 거리 누적
BlockMovingDistance = BlockMovingDistance + e.Move;
}
private void MouseBasedObjectMove_OnMouseUpEvent(object sender, VIZCore3D.NET.Event.EventManager.MouseBaseObjectMoveEventArgs e)
{
string str = string.Format("Mouse Up : {0} / {1} / {2} / {3} / {4} / {5} / {6}"
, e.MoveOption.ToString()
, e.GroupId
, e.Move.ToString()
, e.Anlge
, e.MousePosition.X
, e.MousePosition.Y
, e.Node.Count()
);
System.Diagnostics.Debug.WriteLine(str);
string ptStr = string.Format("X: {0}=={1} / Y: {2}=={3}", MousePt.X, e.MousePosition.X, MousePt.Y, e.MousePosition.Y);
System.Diagnostics.Debug.WriteLine(ptStr);
List<VIZCore3D.NET.Data.NearestObjectByAxisPoint> items
= vizcore3d.GeometryUtility.GetNearestObjects(
e.MousePosition.X /* Mouse Location X */
, e.MousePosition.Y /* Mouse Location Y */
, true /* Visible Only */
, false /* Opaque Only */
);
if (items.Count != 1) return;
// 현재 이동되는 개체의 연계된 리뷰 정보(아이디) 조회
List<int> review = vizcore3d.View.MouseBasedObjectMove.GetLinkedReview(e.GroupId);
if (review.Count == 0) return;
// 해당 리뷰(노트)의 정보 조회
VIZCore3D.NET.Data.NoteItem note = vizcore3d.Review.Note.GetItem(review[0]);
// 해당 리뷰(노트)의 위치 정보 조회
List<VIZCore3D.NET.Data.ReviewPosition> position = note.Position;
// 마우스가 이동한 거리만큼 리뷰의 위치를 재설정
note.UpdatePosition(position[0], position[0].Position - new VIZCore3D.NET.Data.Vertex3D(BlockMovingDistance.X, BlockMovingDistance.Y, BlockMovingDistance.Z));
// 원래 이동전 위치로 이동
vizcore3d.Object3D.Transform.Move(e.Node.ToArray(), -BlockMovingDistance.X, -BlockMovingDistance.Y, -BlockMovingDistance.Z, false);
}
private void MouseBasedObjectMove_OnMouseDoubleClickEvent(object sender, Event.EventManager.MouseBaseObjectMoveEventArgs e)
{
string str = string.Format("Mouse DoubleClick : {0} / {1} / {2} / {3} / {4} / {5} / {6}"
, e.MoveOption.ToString()
, e.GroupId
, e.Move.ToString()
, e.Anlge
, e.MousePosition.X
, e.MousePosition.Y
, e.Node.Count()
);
System.Diagnostics.Debug.WriteLine(str);
List<VIZCore3D.NET.Data.NearestObjectByAxisPoint> items
= vizcore3d.GeometryUtility.GetNearestObjects(
e.MousePosition.X /* Mouse Location X */
, e.MousePosition.Y /* Mouse Location Y */
, true /* Visible Only */
, false /* Opaque Only */
);
if (items.Count == 0) return;
// 선택된 블록 90도 회전
vizcore3d.Object3D.Transform.Rotate(e.Node.ToArray(), 0, 0, 90, false, false);
}
Body 노드에 Polyhedral Primitive 생성 (혹은 추가) 기능
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
private void Example()
{
// New Empty Model
int index = vizcore3d.Model.NewEmptyModel("MODEL");
string assemblyName = "ASSEMBLY";
VIZCore3D.NET.Data.Node assemblyNode =
vizcore3d.Structure.CreateNode(
index /* Parent Node Index */
, VIZCore3D.NET.Data.NodeKind.ASSEMBLY /* Node Kind */
, assemblyName /* Node Name */
);
string partName = "PART";
VIZCore3D.NET.Data.Node partNode =
vizcore3d.Structure.CreateNode(
assemblyNode.Index /* Parent Node Index */
, VIZCore3D.NET.Data.NodeKind.PART /* Node Kind */
, partName /* Node Name */
);
string bodyName = "BODY";
int bodyId =
vizcore3d.Structure.CreateBody(
partNode.Index /* Parent Node Index */
, bodyName /* Node Name */
);
int bodyIndex = vizcore3d.Object3D.GetBodyIndex(bodyId);
{
List<Point> point = new List<Point>();
point.Add(new Point(100, 0));
point.Add(new Point(600, 0));
point.Add(new Point(600, -600));
point.Add(new Point(0, -600));
point.Add(new Point(0, -100));
point.Add(new Point(100, -100));
vizcore3d.MeshEdit.AddPrimitivePolyhedral(
bodyIndex /* Body Node Index */
, point /* Point */
, 300.0f /* Height */
, Color.Orange /* Color */
, false /* Rebuild Data */
);
}
vizcore3d.Structure.RebuildData();
}
키보드 방향키를 활용하여 모델 이동/회전 기능
// VIZCore3D.NET Control
private VIZCore3D.NET.VIZCore3DControl vizcore3d;
private void Example()
{
if (vizcore3d.Model.IsOpen() == false) return;
// 기능 활성화
vizcore3d.View.KeyboardBasedTransform.Enable = true;
// 기준 축 지정
vizcore3d.View.KeyboardBasedTransform.Axis = VIZCore3D.NET.Data.AxisDirection.Z_PLUS;
// 이동 거리 : 기본, 상세
vizcore3d.View.KeyboardBasedTransform.Distance = 1000.0f;
vizcore3d.View.KeyboardBasedTransform.DetailDistance = 100.0f;
// 회전 각도 : 기본, 상세
vizcore3d.View.KeyboardBasedTransform.Angle = 90.0f;
vizcore3d.View.KeyboardBasedTransform.DetailAngle = 10.0f;
// 이동/회전 이벤트
vizcore3d.View.KeyboardBasedTransform.OnTransformEvent += KeyboardBasedTransform_OnTransformEvent;
}
private void KeyboardBasedTransform_OnTransformEvent(object sender, Event.EventManager.KeyboardBasedObjectTransformEventArgs e)
{
// 이동
if(e.Angle == null)
{
VIZCore3D.NET.Data.AxisDirection axis = e.Axis;
VIZCore3D.NET.Data.Vertex3D distance = e.Distance;
List<VIZCore3D.NET.Data.Node> node = e.Node;
}
// 회전
else
{
VIZCore3D.NET.Data.AxisDirection axis = e.Axis;
VIZCore3D.NET.Data.Vertex3D angle = e.Angle;
List<VIZCore3D.NET.Data.Node> node = e.Node;
}
}