blender python script
블랜더에서 파이썬을 이용하여 매쉬의 절대 위치 바꾸기
블랜더의 좌표계는
- Global
- Local
- Normal
- Gimbal
이렇게 나뉜다
매쉬를 이동시키기 위해선 global과 local좌표계가 필요하다
global 좌표계는 흔히 우리가 생각하는 데카르트좌표계 => x축, y축, z축 이 있는 그리드를 의미함
local 좌표계는 각 객체(매쉬 object)에서 정의된 좌표계를 뜻한다.
매쉬의 자료형태가 local로 정의 되어 있기 때문에 local의 vertecs를 다 읽은뒤 그것을 global 좌표계로 변환 해주어야한다.
##########주의###########
#블랜더 버전에 따라서 표현이 바뀐게 많음
#elementwise 곱 *==>@
#cursor_location ==>cursor.location
import bpy
# get the current object
current_obj = bpy.context.active_object
# get the scene
scene = bpy.context.scene
# set geometry to origin
bpy.ops.object.origin_set(type="GEOMETRY_ORIGIN")
#obj.location[2]+=obj.dimensions[2]/2
zverts = []
# get all z coordinates of the vertices
for face in current_obj.data.polygons:
verts_in_face = face.vertices[:]
for vert in verts_in_face:
local_point = current_obj.data.vertices[vert].co
world_point = current_obj.matrix_world @ local_point
zverts.append(world_point[2])
# set the minimum z coordinate as z for cursor location
scene.cursor.location = (0, 0, min(zverts))
# set the origin to the cursor
bpy.ops.object.origin_set(type="ORIGIN_CURSOR")
# set the object to (0,0,0)
current_obj.location = (0,0,0)
# reset the cursor
scene.cursor.location = (0,0,0)
Reference
https://itadventure.tistory.com/319
3D 블렌더 2.83 + 파이썬 스크립트와의 만남
3D 블렌더 프로그램에는 파이썬 스크립트 엔진이 내장되어 있는데요. 관련 스크립트를 통해 재미난 것들을 할 수가 있지요. 앞으로 이걸로 어디까지 할 수 있을지 알아 보는 시간을 가져보도록
itadventure.tistory.com
Coordinate Systems in Blender - dummies
About the book author: Jason van Gumster, author of all editions of Blender For Dummies, has used Blender in animation, video, and digital design for over 20 years. A Blender Foundation certified trainer, he has taught numerous students and serves as lead
www.dummies.com
https://blender.stackexchange.com/questions/1311/how-can-i-get-vertex-positions-from-a-mesh
How can I get vertex positions from a mesh?
I want to read the vertex x and y coordinates with a script or a function. How can I do that? The MeshVertex appears to have no position I could use. I'd take any alternative approach that coul...
blender.stackexchange.com