#!BPY """ Name: 'FCollada (Curves only) (.dae)...' Blender: 243 Group: 'Export' Tooltip: 'Save Selected Curves to COLLADA .dae file' """ __author__ = "Matt Ebb / ProMotion Studios" __url__ = ['mke3.net'] __version__ = "1.1" __bpydoc__ = """\ This script exports 3D bezier curves to the COLLADA file format. It is designed for compatibility with the open source FCollada library by Feeling Software, which their ColladaMax and ColladaMaya I/O plugins are based on. FCollada's method of interpreting bezier handles and segment interpolation seems to differ from what's in the COLLADA spec, so I don't know how this will work when imported into other applications. See http://www.feelingsoftware.com for more information on this library. Usage: Select the objects you wish to export and run this script from "File->Export" menu. Due to limitations in the COLLADA file format, all individual curves (even inside a singlecurve datablock) will be exported as separate objects. """ import Blender, BPySys from Blender import * def save_curve_fcollada(filename): scn = Scene.GetCurrent() file = open(filename, "w") header = ''' \t \t\t \t\t\tBlender 2.43 FCollada Curve Exporter \t\t \t\tZ_UP \t\t \t ''' file.write(header) file.write('\t\n') geomlist = [] for ob in scn.objects.selected: if ob.type != 'Curve': continue curvedata = ob.data curvedataname = BPySys.cleanName(curvedata.name) for cni, curnurb in enumerate(curvedata): cname = "%s-%d" % (curvedataname, cni) geominfo = {} if len(curnurb) > 1: geominfo['obname'] = BPySys.cleanName(ob.name) + '-' + cname else: geominfo['obname'] = BPySys.cleanName(ob.name) # Store geometry info for each sub-curve, since they will be split # into individual geometry nodes geominfo['dataname'] = cname geominfo['translate'] = '%.6f %.6f %.6f' % (ob.LocX, ob.LocY, ob.LocZ) geominfo['rotateZ'] = '%.6f' % ob.RotZ geominfo['rotateY'] = '%.6f' % ob.RotY geominfo['rotateX'] = '%.6f' % ob.RotX geominfo['scale'] = '%.6f %.6f %.6f' % (ob.SizeX, ob.SizeY, ob.SizeZ) geomlist.append(geominfo) file.write('\t\t\n' % cname) file.write('\t\t\t\n' % curnurb.isCyclic()) file.write('\t\t\t\t\n' % cname) # This way below of representing curve CVs and tangents seems to conflict with the actual spec, # but it's the way that the Fcollada/colladaMax importer seems to expect the data, so # practicality wins over correctness here. if curnurb.isCyclic(): numpoints = 3*len(curnurb) else: numpoints = 3*(len(curnurb))-2 # minus start h2 and end h2 file.write('\t\t\t\t\t\n' % (cname, numpoints*3)) # *3 --> X,Y,Z cvs = '' for pni, point in enumerate(curnurb): cvs += ' ' # only include h1 for first point of closed (cyclic) curves, ignore for open curves if pni or curnurb.isCyclic(): cvs += '%.6f %.6f %.6f ' % (point.vec[0][0], point.vec[0][1], point.vec[0][2]) cvs += '%.6f %.6f %.6f ' % (point.vec[1][0], point.vec[1][1], point.vec[1][2]) # only include h2 for last point of closed (cyclic) curves, ignore for open curves if pni!=len(curnurb)-1 or curnurb.isCyclic(): cvs += '%.6f %.6f %.6f ' % (point.vec[2][0], point.vec[2][1], point.vec[2][2]) cvs += '\n' file.write(cvs) file.write('\t\t\t\t\t\n') file.write('\t\t\t\t\t\n') file.write('\t\t\t\t\t\t\n' % (cname, numpoints)) paramxyz = '''\t\t\t\t\t\t\t \t\t\t\t\t\t\t \t\t\t\t\t\t\t ''' file.write(paramxyz) file.write('\t\t\t\t\t\t\n') file.write('\t\t\t\t\t\n') file.write('\t\t\t\t\n') file.write('\t\t\t\t\n') file.write('\t\t\t\t\t\n' % cname) file.write('\t\t\t\t\n') extra = '''\t\t\t \t\t\t\t \t\t\t\t\tBEZIER \t\t\t\t \t\t\t ''' file.write(extra) file.write('\t\t\t\n') file.write('\t\t\n') file.write('\t\n') file.write('\t\n') scnname = BPySys.cleanName(scn.name) file.write('\t\t\n' % (scnname, scnname)) # Separate node for each connected curve segment. # COLLADA doesn't support multiple curve per node. for g in geomlist: file.write('\t\t\t\n' % (g['obname'], g['obname'])) file.write('\t\t\t\t%s\n' % g['translate']) file.write('\t\t\t\t0 0 1 %s\n' % g['rotateZ']) file.write('\t\t\t\t0 1 0 %s\n' % g['rotateY']) file.write('\t\t\t\t1 0 0 %s\n' % g['rotateX']) file.write('\t\t\t\t%s\n' % g['scale']) file.write('\t\t\t\t\n' % g['dataname']) file.write('\t\t\t\n') file.write('\t\t\n') file.write('\t\n') file.write('\t\n') file.write('\t\t\n' % scnname) file.write('\t\n') file.write('\n') file.close() Window.FileSelector(save_curve_fcollada, 'Export Curve to FCollada')