Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91a7f71

Browse files
committed
fix UV export and add documentation
1 parent 9938c8f commit 91a7f71

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

Exporter/Blender/gpmesh_export.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
1+
# Usage:
2+
#
3+
# - You should make a copy of your .blend file eg. 'my-scene-export.blend'!
4+
#
5+
# - The armature's pivot must be the same as the meshe's it is attached to.
6+
#
7+
# - The animation must have at least 2 keyframes and start at position 1.
8+
#
9+
# - UVs are stored per face in Blender. The GPmesh format expects to have _one_ UV per vertex.
10+
# Blender can easily have multiple UV coordinates assigned to the same vertex-index. Thus,
11+
# in order to get UVs exported correctly, vertices must be dublicated. This can be done
12+
# in the following way:
13+
# 1.) Go into edit mode and select all edges.
14+
# 2.) From the menu choose Edge -> Mark Sharp.
15+
# 3.) Switch into object mode and assign the 'Edge Split' modifier. Apply that. Done.
16+
#
17+
# - The engine of the book expects all polygons to be a triangle. So if your mesh has
18+
# n-gons, with n > 3, you have to apply the 'Triangulate' modifier or split your polygons manually.
219

320
bl_info = {
421
"name": "gpmesh Exporter",
522
"blender": (3,00,0),
6-
"category": "Export"
23+
"category": "Export",
24+
"author": "Michael Eggers",
25+
"description": "GPmesh exporter for the book Game Programming in C++"
726
}
827

928
import bpy
@@ -26,7 +45,6 @@ def generate_gpmesh_json():
2645
for vert in mesh.vertices:
2746
pos = vert.co
2847
normal = vert.normal
29-
uv = uv_layer[vert.index].uv
3048
gp_vert = []
3149
gp_vert.extend([pos.y, pos.x, pos.z])
3250
gp_vert.extend([normal.y, normal.x, normal.z])
@@ -54,10 +72,17 @@ def generate_gpmesh_json():
5472

5573
gp_vert.extend(boneIndices)
5674
gp_vert.extend(weights)
57-
gp_vert.extend([uv.x, uv.y])
5875

5976
gpmesh["vertices"].append(gp_vert)
6077

78+
# UVs are stored separately, because even if multiple vertices share the same pos/normal/..
79+
# they can have easily have completely differen UVs!
80+
for l in mesh.loops:
81+
uv = uv_layer[l.index].uv
82+
if len(gpmesh["vertices"][l.vertex_index]) <= 14:
83+
gpmesh["vertices"][l.vertex_index].extend([uv.x, -uv.y])
84+
# print(vert_idx, loop_idx, uv)
85+
6186
for poly in mesh.polygons:
6287
tri = []
6388
for loop_index in poly.loop_indices:

0 commit comments

Comments
 (0)