|
import bpy
import math
import os.path
import time
from time import ctime
import shutil
#---------------------------------------------------------------------------#
def ss2f1 (a):
return '%9.4f' %(float(a))
#---------------------------------------------------------------------------#
def ss2f(s):
for i in range(len(s)):
s[i]=ss2f1(s[i])
return s
#---------------------------------------------------------------------------#
def deg2rad (deg): return math.radians(deg)
def rad2deg (rad): return math.degrees(rad)
#---------------------------------------------------------------------------#
def r2d (r): return rad2deg(r)
#---------------------------------------------------------------------------#
def path_check(s):
s=s.replace('pose.bones["','')
s=s.replace('"]','')
if '.location' in s:
s=s.replace('.location','')
return(s,'loc')
elif 'location' in s:
s='body'
return(s,'loc')
elif '.rotation_euler' in s:
s=s.replace('.rotation_euler','')
return(s,'rot')
elif 'rotation_euler' in s:
s='body'
return(s,'rot')
#---------------------------------------------------------------------------#
def ndic_add (key,fr):
global ndic
if key not in ndic: ndic[key]={}
if fr not in ndic[key]:
ndic[key][fr]=[0,0,0]
#---------------------------------------------------------------------------#
def ndic_put (key,fr,x,f):
ndic_add(key,fr)
ndic[key][fr][x]=f
#---------------------------------------------------------------------------#
ndic={}
#---------------------------------------------------------------------------#
print()
print("Start bone2_wr at ",ctime())
ob = bpy.context.object
name = bpy.context.object.name
#rint("KK1: object.name : ",name)
#---------------------------------------------------------------------------#
if ob is not None:
if ob.animation_data is not None \
and ob.animation_data.action is not None :
action = ob.animation_data.action
for fcu in action.fcurves:
if 'scale' in fcu.data_path: continue
if 'quaternion' in fcu.data_path: continue
(name,com)=path_check(fcu.data_path)
key='%s %s' %(name,com)
x=int(fcu.array_index)
for kp in fcu.keyframe_points:
fr=int(kp.co[0])
f=float(kp.co[1])
if com != 'loc': f=r2d(f)
#if key == 'body rot': #rint("KK11:",key)
#if key == 'spine loc': #rint("KK11:",key)
ndic_put(key,fr,x,f)
#rint("KK81:ndic[key][fr]:",key,fr,x,f)
#rint("KK82:ndic[key][fr]:",key,fr,ndic[key][fr])
#---------------------------------------------------------------------------#
if os.path.isfile('bone2.rot'):
ofile='backup\\bone2.rot.'+str(int(time.time()))
shutil.copyfile('bone2.rot',ofile)
#---------------------------------------------------------------------------#
#rint("KK2: write bone.rot...")
fo = open('bone2.rot','w')
for name in sorted(ndic.keys()):
num=0
for fr in sorted(ndic[name].keys()):
name2 = name.replace(' ',' ')
if fr%4>-1 :
s='jin1e %s %3d' %(name2,fr)
(a,b,c)=ss2f(ndic[name][fr][0:3])
s+=' %s %s %s\n' %(a,b,c)
fo.write(s)
if num>0: fo.write('\n')
fo.close()
#---------------------------------------------------------------------------#
print("Finish bone2_wr at ",ctime())
print()
#---------------------------------------------------------------------------# |
|