본문 바로가기
Angular.js

Plotly.js + Blender, 좌표 생성, 중심점 지정 필수

by 찬찬2 2024. 4. 3.

mesh3d 로 오브젝트를 만들기 위해서 x, y, z, i, j, k 좌표가 필요.

 

Blender에서 좌표정보를 받아올 수 있는데 i, j, k를 얻는 방법은 추가적인 설정이 필요.

 

1. Edit mode -> 오브젝트 전체 선택

2. Triangulate Faces 선택

3. Edit mode 에서 Object mode로 전환

4. 아래 스크립트 실행

 

import bpy

outputFile = 'C:/yourlocation/list.csv'

obj = bpy.context.object
mesh = obj.data

coor = []
for vert in mesh.vertices:
    xyz = vert.co.xyz
    coor.append(f"{xyz[0]},{xyz[1]},{xyz[2]}")

indices = []
for face in mesh.polygons:
    indices.append(f"{face.vertices[0]},{face.vertices[1]},{face.vertices[2]}")

line = ["X,Y,Z,I,J,K\n"]
if len(indices) >= len(coor):
    for i, s in enumerate(coor):
        line.append(f"{s},{indices[i]}\n")
    for i in range(len(coor), len(indices)):
        line.append(f",,,{indices[i]}\n")
else:
    for i, s in enumerate(indices):
        line.append(f"{coor[i]},{s}\n")
    for i in range(len(indices), len(coor)):
        line.append(f"{coor[i]}\n")

f = open(outputFile, 'w')
f.writelines(line)
f.close()

 

참고: https://blender.stackexchange.com/questions/260913/trying-to-find-ijk-values-for-3d-mesh-plot

 

 

중요!!

이렇게 만들고 Plotly 에서mesh3d 로 만들었을때, 좌표가 마이너스 값 또는 x, y, z 방향이 내가  원하는 방향이 아닐 수 있다.

 

그 이유는 Object에 중심점을 잘못설정해서 그렇다.

 

오브젝트를 선택하고 edit mode 에서 shift + click 해서 꼭짓점을 선택하고, Object -> Set Origin -> Orign to 3D Cursor을 설정해줘야만 그 중심점을 바탕으로 좌표를 생성해준다.

 

여기서 팁으로, 정확한 시작위치를 잡고 싶을때 grid에 오브젝트를  snap 시키면 정확한 좌표를 뽑아낼 수 있다.

 

참고: https://www.youtube.com/watch?v=07rSFBpsW9k

댓글