# SPDX-License-Identifier: GPL-2.0-or-later bl_info = { "name": "Export Pointcache Format(.pc2)", "author": "Florian Meyer (tstscr)", "version": (1, 1, 2), "blender": (2, 80, 0), "location": "File > Export > Pointcache (.pc2)", "description": "Export mesh Pointcache data (.pc2)", "warning": "", "doc_url": "{BLENDER_MANUAL_URL}/addons/import_export/pc2.html", "category": "Import-Export", } """ Related links: https://developer.blender.org/T34456 https://developer.blender.org/T25408 Usage Notes: in Maya Mel: cacheFile -pc2 1 -pcf "" -f "" -dir "" -format "OneFile"; """ import bpy from bpy.props import BoolProperty, IntProperty, EnumProperty import mathutils from bpy_extras.io_utils import ExportHelper from os import remove import time import math import struct def get_sampled_frames(start, end, sampling): return [math.modf(start + x * sampling) for x in range(int((end - start) / sampling) + 1)] def do_export(context, props, filepath): mat_x90 = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X') ob = context.active_object sc = context.scene start = props.range_start end = props.range_end sampling = float(props.sampling) apply_modifiers = props.apply_modifiers depsgraph = None if apply_modifiers: depsgraph = context.evaluated_depsgraph_get() me = ob.evaluated_get(depsgraph).to_mesh() else: me = ob.to_mesh() vertCount = len(me.vertices) sampletimes = get_sampled_frames(start, end, sampling) sampleCount = len(sampletimes) # Create the header headerFormat = '<12siiffi' headerStr = struct.pack(headerFormat, b'POINTCACHE2\0', 1, vertCount, start, sampling, sampleCount) file = open(filepath, "wb") file.write(headerStr) for frame in sampletimes: # stupid modf() gives decimal part first! sc.frame_set(int(frame[1]), subframe=frame[0]) if apply_modifiers: me = ob.evaluated_get(depsgraph).to_mesh() else: me = ob.to_mesh() if len(me.vertices) != vertCount: bpy.data.meshes.remove(me, do_unlink=True) file.close() try: remove(filepath) except: empty = open(filepath, 'w') empty.write('DUMMIFILE - export failed\n') empty.close() print('Export failed. Vertexcount of Object is not constant') return False if props.world_space: me.transform(ob.matrix_world) if props.rot_x90: me.transform(mat_x90) for v in me.vertices: thisVertex = struct.pack('