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.
2
19
3
20
bl_info = {
4
21
"name" : "gpmesh Exporter" ,
5
22
"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++"
7
26
}
8
27
9
28
import bpy
@@ -26,7 +45,6 @@ def generate_gpmesh_json():
26
45
for vert in mesh .vertices :
27
46
pos = vert .co
28
47
normal = vert .normal
29
- uv = uv_layer [vert .index ].uv
30
48
gp_vert = []
31
49
gp_vert .extend ([pos .y , pos .x , pos .z ])
32
50
gp_vert .extend ([normal .y , normal .x , normal .z ])
@@ -54,10 +72,17 @@ def generate_gpmesh_json():
54
72
55
73
gp_vert .extend (boneIndices )
56
74
gp_vert .extend (weights )
57
- gp_vert .extend ([uv .x , uv .y ])
58
75
59
76
gpmesh ["vertices" ].append (gp_vert )
60
77
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
+
61
86
for poly in mesh .polygons :
62
87
tri = []
63
88
for loop_index in poly .loop_indices :
0 commit comments