Last active
February 20, 2022 16:15
-
-
Save ghiboz/8b2f7193c4f0b970ae98d84ffac0fc2f to your computer and use it in GitHub Desktop.
Export Spline Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ##### BEGIN GPL LICENSE BLOCK ##### | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software Foundation, | |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
# | |
# ##### END GPL LICENSE BLOCK ##### | |
bl_info = { | |
"name": "Export gRally stage spline (.xml)", | |
"author": "ghiboz", | |
"version": (1, 0, 0), | |
"blender": (2, 80, 0), | |
"location": "File > Export > gRallySpline (.xml)", | |
"description": "Export gRally stage spline (.xml)", | |
"warning": "", | |
"category": "Import-Export", | |
} | |
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): | |
obj = context.active_object | |
mesh = obj.data | |
skip = 0 | |
f = open(filepath, "w") | |
f.write("<xml>\n") | |
for vert in mesh.vertices: | |
if skip > 2: | |
v = vert.co | |
f.write("\t<P pos=\"{:3f} {:3f} {:3f}\" />\n".format(v.x, v.y, v.z)) | |
skip = skip + 1 | |
f.write("</xml>\n") | |
f.close() | |
return True | |
# EXPORT OPERATOR | |
class Export_pc2(bpy.types.Operator, ExportHelper): | |
"""Export the active Object as a .xml gRally spline""" | |
bl_idname = "export_shape.xml" | |
bl_label = "Export gRally spline (.xml)" | |
filename_ext = ".xml" | |
# rot_x90: BoolProperty( | |
# name="Convert to Y-up", | |
# description="Rotate 90 degrees around X to convert to y-up", | |
# default=True,) | |
# world_space: BoolProperty( | |
# name="Export into Worldspace", | |
# description="Transform the Vertexcoordinates into Worldspace", | |
# default=False,) | |
# apply_modifiers: BoolProperty( | |
# name="Apply Modifiers", | |
# description="Applies the Modifiers", | |
# default=True,) | |
# range_start: IntProperty( | |
# name='Start Frame', | |
# description='First frame to use for Export', | |
# default=1,) | |
# range_end: IntProperty( | |
# name='End Frame', | |
# description='Last frame to use for Export', | |
# default=250,) | |
# sampling: EnumProperty( | |
# name='Sampling', | |
# description='Sampling --> frames per sample (0.1 yields 10 samples per frame)', | |
# items=(('0.01', '0.01', ''), | |
# ('0.05', '0.05', ''), | |
# ('0.1', '0.1', ''), | |
# ('0.2', '0.2', ''), | |
# ('0.25', '0.25', ''), | |
# ('0.5', '0.5', ''), | |
# ('1', '1', ''), | |
# ('2', '2', ''), | |
# ('3', '3', ''), | |
# ('4', '4', ''), | |
# ('5', '5', ''), | |
# ('10', '10', ''), | |
# ), | |
# default='1', | |
# ) | |
@classmethod | |
def poll(cls, context): | |
obj = context.active_object | |
return ( | |
obj is not None | |
and obj.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'} | |
) | |
def execute(self, context): | |
start_time = time.time() | |
print('\n_____START_____') | |
props = self.properties | |
filepath = self.filepath | |
filepath = bpy.path.ensure_ext(filepath, self.filename_ext) | |
exported = do_export(context, props, filepath) | |
if exported: | |
print('finished export in %s seconds' % | |
((time.time() - start_time))) | |
print(filepath) | |
return {'FINISHED'} | |
def invoke(self, context, event): | |
wm = context.window_manager | |
if True: | |
# File selector | |
wm.fileselect_add(self) # will run self.execute() | |
return {'RUNNING_MODAL'} | |
elif True: | |
# search the enum | |
wm.invoke_search_popup(self) | |
return {'RUNNING_MODAL'} | |
elif False: | |
# Redo popup | |
return wm.invoke_props_popup(self, event) | |
elif False: | |
return self.execute(context) | |
def menu_func_export_button(self, context): | |
self.layout.operator(Export_pc2.bl_idname, text="gRally Spline (.xml)") | |
classes = [ | |
Export_pc2, | |
] | |
def register(): | |
for cls in classes: | |
bpy.utils.register_class(cls) | |
bpy.types.TOPBAR_MT_file_export.append(menu_func_export_button) | |
#bpy.types.VIEW3D_PT_tools_objectmode.prepend(menu_func_export_button) | |
def unregister(): | |
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export_button) | |
#bpy.types.VIEW3D_PT_tools_objectmode.remove(menu_func_export_button) | |
for cls in classes: | |
bpy.utils.unregister_class(cls) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment