Skip to content

Commit

Permalink
Fix issue with incorrect face count when model has quads/n-gons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ithamar committed Oct 30, 2022
1 parent d9d604d commit cf2bd5c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
25 changes: 25 additions & 0 deletions DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,33 @@

I'm storing links and code snippets here related to Blender scripting, to save me googling in the future ;)

# TODO

## Export multiple objects

Allow multiple meshes to be exported, and create a dummy bone per mesh. This is so every "sub mesh" can get its own collision in-game.

## 3DF import

Create mesh, convert face-uv to vertex-uv. Look into creating Armature and weights based on the 3DF.

## CAR import

Use 3DF import code for base mesh, import animation frames as shape keys.

# Links

## Animation

- Keyframe information: https://blender.stackexchange.com/questions/27889/how-to-find-number-of-animated-frames-in-a-scene-via-python
- Multiple animation export: https://blender.stackexchange.com/questions/3281/how-do-i-export-animation-data-stored-in-actions-using-the-python-api

## Shape keys

- Shape key creation: https://blender.stackexchange.com/questions/111661/creating-shape-keys-using-python

## Armature/Bones

- https://blender.stackexchange.com/questions/51684/python-create-custom-armature-without-ops
- https://devtalk.blender.org/t/vertex-weights-and-indices-for-a-bmesh/1457
- https://devtalk.blender.org/t/help-implementing-animation-in-blender-2-8-import-addon/7093
13 changes: 9 additions & 4 deletions io_carnivores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
bl_info = {
"name": "Carnivores Model/Animation Export (3DF,VTL)",
"author": "Ithamar R. Adema",
"version": (1, 0, 2),
"version": (1, 0, 3),
"blender": (2, 82, 0),
"description": "Export plugin for classic Carnivores formats 3DF (base model), VTL (animations)",
"category": "Import-Export",
Expand Down Expand Up @@ -61,14 +61,13 @@ def export_3df(context, filepath, obj, 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("<LLLL", len(mesh.vertices), face_count, 1, 0)) # bones, texturesize
f.write(struct.pack("<LLLL", len(mesh.vertices), len(mesh.polygons), 1, 0)) # bones, texturesize

# Write faces
face_count = 0
for poly in mesh.polygons:
# Start of poly loop
start = poly.loop_start
Expand Down Expand Up @@ -99,6 +98,7 @@ def export_3df(context, filepath, obj, mat):
0, # group
)
)
face_count += 1

# Write Vertices
for v in mesh.vertices:
Expand All @@ -107,6 +107,11 @@ def export_3df(context, filepath, obj, mat):
# Write default bone
f.write(struct.pack("<32sfffhH", b'default', 0, 0, 0, -1, 0)) # x,y,z, parent, hidden

# Optionally fix up face count in header, due to quad/n-gon conversion
if face_count != len(mesh.polygons):
f.seek(4)
f.write(struct.pack("<L", face_count))

f.close()

return {'FINISHED'}
Expand Down

0 comments on commit cf2bd5c

Please sign in to comment.