컴퓨터 공학/Graphics

IRIT

코딩하는 Español되기 2024. 6. 12. 11:56

IRIT은 그래픽에서 유명한 오픈소스 중 하나입니다.

IRIT은 스크립팅 기능을 제공하는 오픈소스 3D 모델링 프로그램입니다.

아래 링크를 통해 확인해 볼 수 있습니다.

https://gershon.cs.technion.ac.il/irit/

 

The IRIT modeling environment - Home Page

General Information IRIT is a freeform geometric modeling environment that allows one to model general freeform surfaces' based models as well as polygonal objects, and use Boolean operations on both. Beyond its very strong support for Bezier and B-spline

gershon.cs.technion.ac.il

스크립트 파일(*.irt)으로 작성이 되고

실행을 위해서는 CMD에서 저장된 폴더로 이동 후 "irit64 *.irt"를 입력하면 계산 결과 혹은 생성된 파일을 확인 가능합니다.

cd c:\CG_irit
irit64 *.irt

 

 

irit을 통해 만드는 다각형, 기하객체, 구 등 생성법을 간단히 알아보겠습니다.

 

Box(VectorType Pt, NumericType Dx, NumericType Dy, NumericType Dz)
  • 다각형 객체 생성 : XY, XZ, YZ 평면과 공면인 BOX 다각형 객체를 생성합니다.
    이 BOX는 기본 위치로서 Point에 의해 정의되며, Dx, Dy, Dz =  BOX의 크기(음수 크기도 허용)
    • 예시: B = BOX( vector( 0, 0, 0 ), 1, 1, 1); 모든 축에서 0부터 1까지의 단위 큐브를 생성합니다.
SPHERE( VectorType Center, NumericType Radius )
  • SPHERE( VectorType Center, NumericType Radius )
    • Center를 구의 중심으로 하고 Radius를 구의 반지름으로 정의하여 구 기하 객체를 생성.
CYLIN( VectorType Center, VectorType Direction, NumericType Radius, NumericType Caps )
  • CYLINder 기하 객체: Center를 CYLINder의 밑면 중심으로, Direction을 CYLINder의 축과 높이로, Radius를 CYLINder 밑면의 반지름으로 정의
    • Caps가 0이면, 캡이 생성되지 않습니다. Caps가 1(2)이면, 아래쪽(위쪽) 캡만 생성됩니다. Caps가 3이면, 위쪽과 아래쪽 두 캡이 모두 생성됩니다.

이번에는 이동/변환/크기 변환을 알아보겠습니다.

tx(value): x축으로 value만큼 이동  - ty(value): y축으로 value만큼 이동 - tz(value): z축으로 value만큼 이동

rx(angle): x축으로 angle만큼 회전 - ry(angle): y축으로 angle만큼 회전 - rz(angle): z축으로 angle만큼 회전

sx(value): x축으로 value만큼 신축 - sy(value): y축으로 value만큼 신축 - sz(value) : z축으로 value만큼 신축

 

이번에는 CSG에 대해서 간단한 예시와 그림으로 알아보겠습니다.

 

Constructive Solid Geometry (CSG) : 구성적 솔리드 기하학; 기본 도형을 조합해 복잡한 도형 구성하는 기법으로

주로 부울 연산(합/교/차 집합)을 사용해 새로운 형태를 생성합니다.

 

간단한 박스와 합집합, 교집합을 사용한 예시 코드입니다.

 

 

b1 = box(vector(0,0,0),1,1,1);
s1 = sphere(vector(0.5,0.5,0.5),sqrt(2)/2.0); 
itst1 = s1 * b1;
itst1 = itst1 * tx(-0.5) * ty(-0.5) * tz(-0.5); 
interact(list(axes,b1,s1));
interact(list(axes,itst1)); 
save("mid0.obj",itst1);

s1 = cylin(vector(0,0,-1), vector(0,0,2), 0.45, 3); 
s2 = cylin(vector(0,-1,0), vector(0,2,0), 0.45, 3); 
s3 = cylin(vector(-1,0,0), vector(2,0,0), 0.45, 3); 
sum1 = s1 + s2 + s3;
interact(list(axes,itst1, sum1)); 
save("mid1.obj",sum1);

result = itst1 - sum1; 
interact(list(axes,result));

1 - 7 번 코드
9 - 14 코드
나머지

 

- InitMyMesh()를 활용해 크기가 2인 정육면체 만들기 간단한 코드입니다.

void DrawComponent::InitMyMesh()

{

    const float cubeSize = 2.0f;

 

    // Define vertices of the cube

    const auto v0 = mesh.add_vertex(pmp::Point(0, 0, 0));

    const auto v1 = mesh.add_vertex(pmp::Point(cubeSize, 0, 0));

    const auto v2 = mesh.add_vertex(pmp::Point(cubeSize, cubeSize, 0));

    const auto v3 = mesh.add_vertex(pmp::Point(0, cubeSize, 0));

    const auto v4 = mesh.add_vertex(pmp::Point(0, 0, cubeSize));

    const auto v5 = mesh.add_vertex(pmp::Point(cubeSize, 0, cubeSize));

    const auto v6 = mesh.add_vertex(pmp::Point(cubeSize, cubeSize, cubeSize));

    const auto v7 = mesh.add_vertex(pmp::Point(0, cubeSize, cubeSize));

 

    // Define faces of the cube using quads

    mesh.add_quad(v0, v1, v2, v3); // Bottom face

    mesh.add_quad(v4, v5, v6, v7); // Top face

    mesh.add_quad(v0, v4, v7, v3); // Front face

    mesh.add_quad(v1, v5, v6, v2); // Back face

    mesh.add_quad(v0, v1, v5, v4); // Left face

    mesh.add_quad(v3, v7, v6, v2); // Right face

 

    std::cout << "vertices: " << mesh.n_vertices() << std::endl;

    std::cout << "edges: " << mesh.n_edges() << std::endl;

    std::cout << "faces: " << mesh.n_faces() << std::endl;

 

    pmp::vertex_normals(mesh);

    pmp::face_normals(mesh);

}