diff --git a/README.md b/README.md index a68c1aa..0a06113 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ -# io_carnivores -Blender export script for classic Carnivores formats +# Carnivores Export Addon for Blender + +This is a first stab at creating an addon to support modelling/rigging/animating classic Carnivores models in Blender. + +NOTE: This addon has only been tested with Blender 2.92.0 + +## Install + +Simply go to Edit/Preferences/Addons, click Install, and select `io_carnivores.py`. You should see the addon in the addon list, click the checkbox before its name to enable, and you should be good to go. + +## Exporting 3DF + +Simply open any Blender file, select the mesh you wish to export as 3DF model, and select File/Export/3DF. Specify name/location of output file, and you should have a 3DF file usable in CMM / C3dit, etc. + +## Exporting VLT + +In any Blender project, select an active animation, then select the mesh, go to File/Export/VTL, choose name/location of output file, and you should be good to go. + +## Troubleshooting / bugs + +This is my first Blender addon, so please be gentle. Known issues: + +* Due to the VTL format, very small objects will show artifacts due to limited X/Y/Z value range. +* Using a model without uv layer gives script errors +* Selecting something else then a mesh will cause script errors +* Likely much more ;) + +Feel free to let me know any additional issues you run into, or any features you would like to see added. diff --git a/io_carnivores.py b/io_carnivores.py new file mode 100644 index 0000000..11dd56e --- /dev/null +++ b/io_carnivores.py @@ -0,0 +1,197 @@ +import bpy +import struct + +bl_info = { + "name": "Carnivores Export (3DF,VTL)", + "author": "Ithamar R. Adema", + "version": (1, 0, 0), + "blender": (2, 82, 0), + "description": "Export plugin for classic Carnivores formats 3DF (base model), VTL (animations)", + "category": "Import-Export", +} + +def mesh_triangulate(me): + import bmesh + bm = bmesh.new() + bm.from_mesh(me) + bmesh.ops.triangulate(bm, faces=bm.faces) + bm.to_mesh(me) + bm.free() + +def export_3df(context, filepath, mat): + depsgraph = context.evaluated_depsgraph_get() + + # get selected object and create mesh + obj = context.selected_objects[0] + obj_for_convert = obj.evaluated_get(depsgraph) + mesh = obj_for_convert.to_mesh() + + # Triangulate mesh + mesh_triangulate(mesh) + mesh.transform(mat) + + # UV layer + uv_layer = mesh.uv_layers.active.data + + face_count = len(mesh.polygons) + + f = open(filepath, 'wb') + + # Write Header + f.write(struct.pack("