pyjallib 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyjallib/max/anim.py ADDED
@@ -0,0 +1,594 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 애니메이션 모듈 - 3ds Max용 애니메이션 관련 기능 제공
6
+ 원본 MAXScript의 anim.ms를 Python으로 변환하였으며, pymxs 모듈 기반으로 구현됨
7
+ """
8
+
9
+ import math
10
+ import copy
11
+ from pymxs import attime, animate, undo
12
+ from pymxs import runtime as rt
13
+
14
+
15
+ class Anim:
16
+ """
17
+ 애니메이션 관련 기능을 제공하는 클래스.
18
+ MAXScript의 _Anim 구조체 개념을 Python으로 재구현한 클래스이며, 3ds Max의 기능들을 pymxs API를 통해 제어합니다.
19
+ """
20
+
21
+ def __init__(self):
22
+ """클래스 초기화 (현재 특별한 초기화 동작은 없음)"""
23
+ pass
24
+
25
+ def rotate_local(self, inObj, rx, ry, rz):
26
+ """
27
+ 객체를 로컬 좌표계에서 회전시킴.
28
+
29
+ 매개변수:
30
+ inObj : 회전할 객체
31
+ rx : X축 회전 각도 (도 단위)
32
+ ry : Y축 회전 각도 (도 단위)
33
+ rz : Z축 회전 각도 (도 단위)
34
+ """
35
+ # 현재 객체의 변환 행렬을 가져옴
36
+ currentMatrix = rt.getProperty(inObj, "transform")
37
+ # 오일러 각도를 통해 회전 행렬(쿼터니언) 생성
38
+ eulerAngles = rt.eulerAngles(rx, ry, rz)
39
+ quatRotation = rt.eulertoquat(eulerAngles)
40
+ # preRotate를 이용해 회전 적용
41
+ rt.preRotate(currentMatrix, quatRotation)
42
+ # 변경된 행렬을 객체에 설정
43
+ rt.setProperty(inObj, "transform", currentMatrix)
44
+
45
+ def move_local(self, inObj, mx, my, mz):
46
+ """
47
+ 객체를 로컬 좌표계에서 이동시킴.
48
+
49
+ 매개변수:
50
+ inObj : 이동할 객체
51
+ mx : X축 이동 거리
52
+ my : Y축 이동 거리
53
+ mz : Z축 이동 거리
54
+ """
55
+ # 현재 변환 행렬 가져오기
56
+ currentMatrix = rt.getProperty(inObj, "transform")
57
+ # 이동량을 Point3 형태로 생성
58
+ translation = rt.Point3(mx, my, mz)
59
+ # preTranslate를 이용해 행렬에 이동 적용
60
+ rt.preTranslate(currentMatrix, translation)
61
+ # 적용된 이동 변환 행렬을 객체에 설정
62
+ rt.setProperty(inObj, "transform", currentMatrix)
63
+
64
+ def reset_transform_controller(self, inObj):
65
+ """
66
+ 객체의 트랜스폼 컨트롤러를 기본 상태로 재설정함.
67
+
68
+ 매개변수:
69
+ inObj : 초기화할 객체
70
+ """
71
+ # Biped_Object가 아닐 경우에만 실행
72
+ if rt.classOf(inObj) != rt.Biped_Object:
73
+ # 현재 변환 행렬 백업
74
+ tempTransform = rt.getProperty(inObj, "transform")
75
+ # 위치, 회전, 스케일 컨트롤러를 기본 컨트롤러로 재설정
76
+ rt.setPropertyController(inObj.controller, "Position", rt.Position_XYZ())
77
+ rt.setPropertyController(inObj.controller, "Rotation", rt.Euler_XYZ())
78
+ rt.setPropertyController(inObj.controller, "Scale", rt.Bezier_Scale())
79
+ # 백업한 행렬을 다시 객체에 할당
80
+ inObj.transform = tempTransform
81
+
82
+ def freeze_transform(self, inObj):
83
+ """
84
+ 객체의 변환(회전, 위치)을 키프레임에 의한 애니메이션 영향 없이 고정함.
85
+
86
+ 매개변수:
87
+ inObj : 변환을 고정할 객체
88
+ """
89
+ curObj = inObj
90
+
91
+ # 회전 컨트롤러 고정 (Rotation_list 사용)
92
+ if rt.classOf(rt.getPropertyController(curObj.controller, "Rotation")) != rt.Rotation_list():
93
+ rotList = rt.Rotation_list()
94
+ rt.setPropertyController(curObj.controller, "Rotation", rotList)
95
+ rt.setPropertyController(rotList, "Available", rt.Euler_xyz())
96
+
97
+ # 컨트롤러 이름 설정
98
+ rotList.setname(1, "Frozen Rotation")
99
+ rotList.setname(2, "Zero Euler XYZ")
100
+
101
+ # 활성 컨트롤러 설정
102
+ rotList.setActive(2)
103
+
104
+ # 포지션 컨트롤러 고정 (Position_list 사용)
105
+ if rt.classOf(rt.getPropertyController(curObj.controller, "position")) != rt.Position_list():
106
+ posList = rt.Position_list()
107
+ rt.setPropertyController(curObj.controller, "position", posList)
108
+ rt.setPropertyController(posList, "Available", rt.Position_XYZ())
109
+
110
+ # 컨트롤러 이름 설정
111
+ posList.setname(1, "Frozen Position")
112
+ posList.setname(2, "Zero Position XYZ")
113
+
114
+ # 활성 컨트롤러 설정
115
+ posList.setActive(2)
116
+
117
+ # 위치를 0으로 초기화
118
+ zeroPosController = rt.getPropertyController(posList, "Zero Position XYZ")
119
+ xPosController = rt.getPropertyController(zeroPosController, "X Position")
120
+ yPosController = rt.getPropertyController(zeroPosController, "Y Position")
121
+ zPosController = rt.getPropertyController(zeroPosController, "Z Position")
122
+
123
+ rt.setProperty(xPosController, "value", 0.0)
124
+ rt.setProperty(yPosController, "value", 0.0)
125
+ rt.setProperty(zPosController, "value", 0.0)
126
+
127
+ def collape_anim_transform(self, inObj, startFrame=None, endFrame=None):
128
+ """
129
+ 객체의 애니메이션 변환을 병합하여 단일 트랜스폼으로 통합함.
130
+
131
+ 매개변수:
132
+ inObj : 변환 병합 대상 객체
133
+ startFrame : 시작 프레임 (기본값: 애니메이션 범위의 시작)
134
+ endFrame : 끝 프레임 (기본값: 애니메이션 범위의 끝)
135
+ """
136
+ # 시작과 끝 프레임이 지정되지 않은 경우 기본값 할당
137
+ if startFrame is None:
138
+ startFrame = int(rt.animationRange.start)
139
+ if endFrame is None:
140
+ endFrame = int(rt.animationRange.end)
141
+
142
+ # 씬 리드로우(화면 업데이트)를 중단하여 성능 최적화
143
+ rt.disableSceneRedraw()
144
+
145
+ # 진행 상태 표시 시작
146
+ progressMessage = f"Collapse transform {inObj.name}..."
147
+ rt.progressStart(progressMessage, allowCancel=True)
148
+
149
+ # 임시 포인트 객체 생성 (중간 변환값 저장용)
150
+ p = rt.Point()
151
+
152
+ # 각 프레임에서 대상 객체의 변환 정보를 임시 포인트에 저장
153
+ for k in range(startFrame, endFrame+1):
154
+ with attime(k):
155
+ with animate(True):
156
+ rt.setProperty(p, "transform", rt.getProperty(inObj, "transform"))
157
+
158
+ # 트랜스폼 컨트롤러를 스크립트와 PRS 컨트롤러로 재설정
159
+ rt.setPropertyController(inObj.controller, "Transform", rt.transform_Script())
160
+ rt.setPropertyController(inObj.controller, "Transform", rt.prs())
161
+
162
+ # 각 프레임별로 임시 포인트와의 차이를 계산해서 최종 변환 적용
163
+ for k in range(startFrame, endFrame+1):
164
+ with attime(k):
165
+ with animate(True):
166
+ tm = inObj.transform * rt.inverse(p.transform)
167
+ rt.setProperty(inObj, "rotation", tm.rotation)
168
+ rt.setProperty(inObj, "position", p.transform.position)
169
+ rt.setProperty(inObj, "scale", p.transform.scale)
170
+
171
+ # 진행 상황 업데이트 (백분율 계산)
172
+ rt.progressUpdate(100 * k / endFrame)
173
+
174
+ # 임시 포인트 객체 삭제
175
+ rt.delete(p)
176
+
177
+ # 진행 상태 종료 및 씬 업데이트 재활성화
178
+ rt.progressEnd()
179
+ rt.enableSceneRedraw()
180
+
181
+ def match_anim_transform(self, inObj, inTarget, startFrame=None, endFrame=None):
182
+ """
183
+ 한 객체의 애니메이션 변환을 다른 객체의 변환과 일치시킴.
184
+
185
+ 매개변수:
186
+ inObj : 변환을 적용할 객체
187
+ inTarget : 기준이 될 대상 객체
188
+ startFrame : 시작 프레임 (기본값: 애니메이션 범위의 시작)
189
+ endFrame : 끝 프레임 (기본값: 애니메이션 범위의 끝)
190
+ """
191
+ # 시작/끝 프레임 기본값 설정
192
+ if startFrame is None:
193
+ startFrame = int(rt.animationRange.start)
194
+ if endFrame is None:
195
+ endFrame = int(rt.animationRange.end)
196
+
197
+ # 대상 객체와 기준 객체가 유효한지 확인
198
+ if rt.isValidNode(inObj) and rt.isValidNode(inTarget):
199
+ # 씬 업데이트 중단
200
+ rt.disableSceneRedraw()
201
+
202
+ # 진행 상태 표시 시작
203
+ progressMessage = f"Match transform {inObj.name} to {inTarget.name}"
204
+ rt.progressStart(progressMessage, allowCancel=True)
205
+ progressCounter = 0
206
+
207
+ # 임시 포인트 객체 생성 (타겟 변환 저장용)
208
+ p = rt.Point()
209
+
210
+ # 각 프레임마다 inTarget의 변환을 저장하고 inObj의 기존 키 삭제
211
+ for k in range(startFrame, endFrame + 1):
212
+ with attime(k):
213
+ with animate(True):
214
+ rt.setProperty(p, "transform", rt.getProperty(inTarget, "transform"))
215
+
216
+ # inObj의 위치, 회전, 스케일 컨트롤러에서 기존 키 삭제
217
+ inObjControllers = []
218
+ inObjControllers.append(rt.getPropertyController(inObj.controller, "Position"))
219
+ inObjControllers.append(rt.getPropertyController(inObj.controller, "Rotation"))
220
+ inObjControllers.append(rt.getPropertyController(inObj.controller, "Scale"))
221
+
222
+ for controller in inObjControllers:
223
+ rt.deselectKeys(controller)
224
+ rt.selectKeys(controller, k)
225
+ rt.deleteKeys(controller, rt.Name("selection"))
226
+ rt.deselectKeys(controller)
227
+
228
+ progressCounter += 1
229
+ if progressCounter >= 100:
230
+ progressCounter = 0
231
+ rt.progressUpdate(progressCounter)
232
+
233
+ # 시작 프레임 이전의 불필요한 키 삭제
234
+ if startFrame != rt.animationRange.start:
235
+ dumPointControllers = []
236
+ dumPointControllers.append(rt.getPropertyController(p.controller, "Position"))
237
+ dumPointControllers.append(rt.getPropertyController(p.controller, "Rotation"))
238
+ dumPointControllers.append(rt.getPropertyController(p.controller, "Scale"))
239
+
240
+ for controller in dumPointControllers:
241
+ rt.deselectKeys(controller)
242
+ rt.selectKeys(controller, startFrame)
243
+ rt.deleteKeys(controller, rt.Name("selection"))
244
+ rt.deselectKeys(controller)
245
+
246
+ progressCounter += 1
247
+ if progressCounter >= 100:
248
+ progressCounter = 0
249
+ rt.progressUpdate(progressCounter)
250
+
251
+ # inTarget의 각 컨트롤러에서 키 배열을 가져옴
252
+ inTargetPosController = rt.getPropertyController(inTarget.controller, "Position")
253
+ inTargetRotController = rt.getPropertyController(inTarget.controller, "Rotation")
254
+ inTargetScaleController = rt.getPropertyController(inTarget.controller, "Scale")
255
+
256
+ posKeyArray = inTargetPosController.keys
257
+ rotKeyArray = inTargetRotController.keys
258
+ scaleKeyArray = inTargetScaleController.keys
259
+
260
+ # 시작 프레임 및 끝 프레임의 변환 적용
261
+ with attime(startFrame):
262
+ with animate(True):
263
+ rt.setProperty(inObj, "transform", rt.getProperty(p, "transform"))
264
+ with attime(endFrame):
265
+ with animate(True):
266
+ rt.setProperty(inObj, "transform", rt.getProperty(p, "transform"))
267
+
268
+ # 위치 키프레임 적용
269
+ for key in posKeyArray:
270
+ keyTime = int(rt.getProperty(key, "time"))
271
+ if keyTime >= startFrame and keyTime <= endFrame:
272
+ with attime(keyTime):
273
+ with animate(True):
274
+ rt.setProperty(inObj, "transform", rt.getProperty(p, "transform"))
275
+ progressCounter += 1
276
+ if progressCounter >= 100:
277
+ progressCounter = 0
278
+ rt.progressUpdate(progressCounter)
279
+
280
+ # 회전 키프레임 적용
281
+ for key in rotKeyArray:
282
+ keyTime = int(rt.getProperty(key, "time"))
283
+ if keyTime >= startFrame and keyTime <= endFrame:
284
+ with attime(keyTime):
285
+ with animate(True):
286
+ rt.setProperty(inObj, "transform", rt.getProperty(p, "transform"))
287
+ progressCounter += 1
288
+ if progressCounter >= 100:
289
+ progressCounter = 0
290
+ rt.progressUpdate(progressCounter)
291
+
292
+ # 스케일 키프레임 적용
293
+ for key in scaleKeyArray:
294
+ keyTime = int(rt.getProperty(key, "time"))
295
+ if keyTime >= startFrame and keyTime <= endFrame:
296
+ with attime(keyTime):
297
+ with animate(True):
298
+ rt.setProperty(inObj, "transform", rt.getProperty(p, "transform"))
299
+ progressCounter += 1
300
+ if progressCounter >= 100:
301
+ progressCounter = 0
302
+ rt.progressUpdate(progressCounter)
303
+
304
+ # 임시 포인트 객체 삭제
305
+ rt.delete(p)
306
+
307
+ # 진행 상태 100% 업데이트 후 종료
308
+ rt.progressUpdate(100)
309
+ rt.progressEnd()
310
+ rt.enableSceneRedraw()
311
+
312
+ def create_average_pos_transform(self, inTargetArray):
313
+ """
314
+ 여러 객체들의 평균 위치를 계산하여 단일 변환 행렬을 생성함.
315
+
316
+ 매개변수:
317
+ inTargetArray : 평균 위치 계산 대상 객체 배열
318
+
319
+ 반환:
320
+ 계산된 평균 위치를 적용한 변환 행렬
321
+ """
322
+ # 임시 포인트 객체 생성
323
+ posConstDum = rt.Point()
324
+
325
+ # 포지션 제약 컨트롤러 생성
326
+ targetPosConstraint = rt.Position_Constraint()
327
+
328
+ # 대상 객체에 동일 가중치 부여 (전체 100%)
329
+ targetWeight = 100.0 / (len(inTargetArray) + 1)
330
+
331
+ # 제약 컨트롤러를 임시 객체에 할당
332
+ rt.setPropertyController(posConstDum.controller, "Position", targetPosConstraint)
333
+
334
+ # 각 대상 객체를 제약에 추가
335
+ for item in inTargetArray:
336
+ targetPosConstraint.appendTarget(item, targetWeight)
337
+
338
+ # 계산된 변환 값을 복사
339
+ returnTransform = rt.copy(rt.getProperty(posConstDum, "transform"))
340
+
341
+ # 임시 객체 삭제
342
+ rt.delete(posConstDum)
343
+
344
+ return returnTransform
345
+
346
+ def create_average_rot_transform(self, inTargetArray):
347
+ """
348
+ 여러 객체들의 평균 회전을 계산하여 단일 변환 행렬을 생성함.
349
+
350
+ 매개변수:
351
+ inTargetArray : 평균 회전 계산 대상 객체 배열
352
+
353
+ 반환:
354
+ 계산된 평균 회전을 적용한 변환 행렬
355
+ """
356
+ # 임시 포인트 객체 생성
357
+ rotConstDum = rt.Point()
358
+
359
+ # 방향(회전) 제약 컨트롤러 생성
360
+ targetOriConstraint = rt.Orientation_Constraint()
361
+
362
+ # 대상 객체에 동일 가중치 부여
363
+ targetWeight = 100.0 / (len(inTargetArray) + 1)
364
+
365
+ # 회전 제약 컨트롤러를 임시 객체에 할당
366
+ rt.setPropertyController(rotConstDum.controller, "Rotation", targetOriConstraint)
367
+
368
+ # 각 대상 객체를 제약에 추가
369
+ for item in inTargetArray:
370
+ targetOriConstraint.appendTarget(item, targetWeight)
371
+
372
+ # 계산된 변환 값을 복사
373
+ returnTransform = rt.copy(rt.getProperty(rotConstDum, "transform"))
374
+
375
+ # 임시 객체 삭제
376
+ rt.delete(rotConstDum)
377
+
378
+ return returnTransform
379
+
380
+ def get_all_keys_in_controller(self, inController, keys_list):
381
+ """
382
+ 주어진 컨트롤러와 그 하위 컨트롤러에서 모든 키프레임을 재귀적으로 수집함.
383
+
384
+ 매개변수:
385
+ inController : 키프레임 검색 대상 컨트롤러 객체
386
+ keys_list : 수집된 키프레임들을 저장할 리스트 (참조로 전달)
387
+ """
388
+ with undo(False):
389
+ # 현재 컨트롤러에 키프레임이 있으면 리스트에 추가
390
+ if rt.isProperty(inController, 'keys'):
391
+ for k in inController.keys:
392
+ keys_list.append(k)
393
+
394
+ # 하위 컨트롤러에 대해서 재귀적으로 검색
395
+ for i in range(inController.numSubs):
396
+ sub_controller = inController[i] # 1부터 시작하는 인덱스
397
+ if sub_controller:
398
+ self.get_all_keys_in_controller(sub_controller, keys_list)
399
+
400
+ def get_all_keys(self, inObj):
401
+ """
402
+ 객체에 적용된 모든 키프레임을 가져옴.
403
+
404
+ 매개변수:
405
+ inObj : 키프레임을 검색할 객체
406
+
407
+ 반환:
408
+ 객체에 적용된 키프레임들의 리스트
409
+ """
410
+ with undo(False):
411
+ keys_list = []
412
+ if rt.isValidNode(inObj):
413
+ self.get_all_keys_in_controller(inObj.controller, keys_list)
414
+ return keys_list
415
+
416
+ def get_start_end_keys(self, inObj):
417
+ """
418
+ 객체의 키프레임 중 가장 먼저와 마지막 키프레임을 찾음.
419
+
420
+ 매개변수:
421
+ inObj : 키프레임을 검색할 객체
422
+
423
+ 반환:
424
+ [시작 키프레임, 끝 키프레임] (키가 없으면 빈 리스트 반환)
425
+ """
426
+ with undo(False):
427
+ keys = self.get_all_keys(inObj)
428
+ if keys and len(keys) > 0:
429
+ # 각 키의 시간값을 추출하여 최소, 최대값 확인
430
+ keyTimes = [key.time for key in keys]
431
+ minTime = rt.amin(keyTimes)
432
+ maxTime = rt.amax(keyTimes)
433
+ minIndex = keyTimes.index(minTime)
434
+ maxIndex = keyTimes.index(maxTime)
435
+ return [rt.amin(minIndex), rt.amax(maxIndex)]
436
+ else:
437
+ return []
438
+
439
+ def delete_all_keys(self, inObj):
440
+ """
441
+ 객체에 적용된 모든 키프레임을 삭제함.
442
+
443
+ 매개변수:
444
+ inObj : 삭제 대상 객체
445
+ """
446
+ rt.deleteKeys(inObj, rt.Name('allKeys'))
447
+
448
+ def is_node_animated(self, node):
449
+ """
450
+ 객체 및 그 하위 요소(애니메이션, 커스텀 속성 등)가 애니메이션 되었는지 재귀적으로 확인함.
451
+
452
+ 매개변수:
453
+ node : 애니메이션 여부를 확인할 객체 또는 서브 애니메이션
454
+
455
+ 반환:
456
+ True : 애니메이션이 적용된 경우
457
+ False : 애니메이션이 없는 경우
458
+ """
459
+ animated = False
460
+ obj = node
461
+
462
+ # SubAnim인 경우 키프레임 여부 확인
463
+ if rt.isKindOf(node, rt.SubAnim):
464
+ if node.keys and len(node.keys) > 0:
465
+ animated = True
466
+ obj = node.object
467
+
468
+ # MaxWrapper인 경우 커스텀 속성에 대해 확인
469
+ if rt.isKindOf(obj, rt.MaxWrapper):
470
+ for ca in obj.custAttributes:
471
+ animated = self.is_node_animated(ca)
472
+ if animated:
473
+ break
474
+
475
+ # 하위 애니메이션에 대해 재귀적으로 검사
476
+ for i in range(node.numSubs):
477
+ animated = self.is_node_animated(node[i])
478
+ if animated:
479
+ break
480
+
481
+ return animated
482
+
483
+ def find_animated_nodes(self, nodes=None):
484
+ """
485
+ 애니메이션이 적용된 객체들을 모두 찾음.
486
+
487
+ 매개변수:
488
+ nodes : 검색 대상 객체 리스트 (None이면 전체 객체)
489
+
490
+ 반환:
491
+ 애니메이션이 적용된 객체들의 리스트
492
+ """
493
+ if nodes is None:
494
+ nodes = rt.objects
495
+
496
+ result = []
497
+ for node in nodes:
498
+ if self.is_node_animated(node):
499
+ result.append(node)
500
+
501
+ return result
502
+
503
+ def find_animated_material_nodes(self, nodes=None):
504
+ """
505
+ 애니메이션이 적용된 재질을 가진 객체들을 모두 찾음.
506
+
507
+ 매개변수:
508
+ nodes : 검색 대상 객체 리스트 (None이면 전체 객체)
509
+
510
+ 반환:
511
+ 애니메이션이 적용된 재질을 가진 객체들의 리스트
512
+ """
513
+ if nodes is None:
514
+ nodes = rt.objects
515
+
516
+ result = []
517
+ for node in nodes:
518
+ mat = rt.getProperty(node, "material")
519
+ if mat is not None and self.is_node_animated(mat):
520
+ result.append(node)
521
+
522
+ return result
523
+
524
+ def find_animated_transform_nodes(self, nodes=None):
525
+ """
526
+ 애니메이션이 적용된 변환 정보를 가진 객체들을 모두 찾음.
527
+
528
+ 매개변수:
529
+ nodes : 검색 대상 객체 리스트 (None이면 전체 객체)
530
+
531
+ 반환:
532
+ 애니메이션이 적용된 변환 데이터를 가진 객체들의 리스트
533
+ """
534
+ if nodes is None:
535
+ nodes = rt.objects
536
+
537
+ result = []
538
+ for node in nodes:
539
+ controller = rt.getProperty(node, "controller")
540
+ if self.is_node_animated(controller):
541
+ result.append(node)
542
+
543
+ return result
544
+
545
+ def save_xform(self, inObj):
546
+ """
547
+ 객체의 현재 변환 행렬(월드, 부모 스페이스)을 저장하여 복원을 가능하게 함.
548
+
549
+ 매개변수:
550
+ inObj : 변환 값을 저장할 객체
551
+ """
552
+ try:
553
+ # 월드 스페이스 행렬 저장
554
+ transformString = str(inObj.transform)
555
+ rt.setUserProp(inObj, rt.Name("WorldSpaceMatrix"), transformString)
556
+
557
+ # 부모가 존재하면 부모 스페이스 행렬도 저장
558
+ parent = inObj.parent
559
+ if parent is not None:
560
+ parentTransform = parent.transform
561
+ inverseParent = rt.inverse(parentTransform)
562
+ objTransform = inObj.transform
563
+ parentSpaceMatrix = objTransform * inverseParent
564
+ rt.setUserProp(inObj, rt.Name("ParentSpaceMatrix"), str(parentSpaceMatrix))
565
+ except:
566
+ # 오류 발생 시 예외 무시
567
+ pass
568
+
569
+ def set_xform(self, inObj, space="World"):
570
+ """
571
+ 저장된 변환 행렬을 객체에 적용함.
572
+
573
+ 매개변수:
574
+ inObj : 변환 값을 적용할 객체
575
+ space : "World" 또는 "Parent" (적용할 변환 공간)
576
+ """
577
+ try:
578
+ if space == "World":
579
+ # 월드 스페이스 행렬 적용
580
+ matrixString = rt.getUserProp(inObj, rt.Name("WorldSpaceMatrix"))
581
+ transformMatrix = rt.execute(matrixString)
582
+ rt.setProperty(inObj, "transform", transformMatrix)
583
+ elif space == "Parent":
584
+ # 부모 스페이스 행렬 적용
585
+ parent = inObj.parent
586
+ matrixString = rt.getUserProp(inObj, rt.Name("ParentSpaceMatrix"))
587
+ parentSpaceMatrix = rt.execute(matrixString)
588
+ if parent is not None:
589
+ parentTransform = parent.transform
590
+ transformMatrix = parentSpaceMatrix * parentTransform
591
+ rt.setProperty(inObj, "transform", transformMatrix)
592
+ except:
593
+ # 오류 발생 시 예외 무시
594
+ pass