1 import bpy
, math
, gpu
, os
4 from mathutils
import *
5 from gpu_extras
.batch
import batch_for_shader
8 "name":"Skaterift .mdl exporter",
9 "author": "Harry Godden (hgn)",
16 "category":"Import/Export",
30 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
31 #{ # the normals and uvs to i16s. Not an
32 _pack_
= 1 # real issue, yet.
33 _fields_
= [("co",c_float
*3),
37 ("weights",c_uint16
*4),
41 class mdl_transform(Structure
):
43 _fields_
= [("co",c_float
*3),
48 class mdl_submesh(Structure
):
50 _fields_
= [("indice_start",c_uint32
),
51 ("indice_count",c_uint32
),
52 ("vertex_start",c_uint32
),
53 ("vertex_count",c_uint32
),
54 ("bbx",(c_float
*3)*2),
55 ("material_id",c_uint32
)] # index into the material array
58 class mdl_material(Structure
):
60 _fields_
= [("pstr_name",c_uint32
),
63 ("surface_prop",c_uint32
),
65 ("colour1",c_float
*4),
66 ("tex_diffuse",c_uint32
),
67 ("tex_none0",c_uint32
),
68 ("tex_none1",c_uint32
)]
71 class mdl_bone(Structure
):
73 _fields_
= [("co",c_float
*3),("end",c_float
*3),
75 ("collider",c_uint32
),
76 ("ik_target",c_uint32
),
79 ("pstr_name",c_uint32
),
80 ("hitbox",(c_float
*3)*2),
81 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
85 class mdl_armature(Structure
):
87 _fields_
= [("transform",mdl_transform
),
88 ("bone_start",c_uint32
),
89 ("bone_count",c_uint32
),
90 ("anim_start",c_uint32
),
91 ("anim_count",c_uint32
)]
94 class mdl_animation(Structure
):
96 _fields_
= [("pstr_name",c_uint32
),
99 ("keyframe_start",c_uint32
)]
102 class mdl_mesh(Structure
):
104 _fields_
= [("transform",mdl_transform
),
105 ("submesh_start",c_uint32
),
106 ("submesh_count",c_uint32
),
107 ("pstr_name",c_uint32
),
109 ("armature_id",c_uint32
)]
112 class mdl_file(Structure
):
114 _fields_
= [("path",c_uint32
),
115 ("pack_offset",c_uint32
),
116 ("pack_size",c_uint32
)]
119 class mdl_texture(Structure
):
121 _fields_
= [("file",mdl_file
),
125 class mdl_array(Structure
):
127 _fields_
= [("file_offset",c_uint32
),
128 ("item_count",c_uint32
),
129 ("item_size",c_uint32
),
133 class mdl_header(Structure
):
135 _fields_
= [("version",c_uint32
),
136 ("arrays",mdl_array
)]
139 class ent_spawn(Structure
):
141 _fields_
= [("transform",mdl_transform
),
142 ("pstr_name",c_uint32
)]
145 class ent_light(Structure
):
147 _fields_
= [("transform",mdl_transform
),
148 ("daytime",c_uint32
),
150 ("colour",c_float
*4),
153 ("inverse_world",(c_float
*3)*4), # Runtime
154 ("angle_sin_cos",(c_float
*2))] # Runtime
157 class version_refcount_union(Union
):
159 _fields_
= [("timing_version",c_uint32
),
160 ("ref_count",c_uint8
)]
163 class ent_gate(Structure
):
165 _fields_
= [("type",c_uint32
),
166 ("target", c_uint32
),
167 ("dimensions", c_float
*3),
168 ("co", (c_float
*3)*2),
169 ("q", (c_float
*4)*2),
170 ("to_world",(c_float
*3)*4),
171 ("transport",(c_float
*3)*4),
172 ("_anonymous_union",version_refcount_union
),
173 ("timing_time",c_double
),
174 ("routes",c_uint16
*4)]
177 class ent_route_node(Structure
):
179 _fields_
= [("co",c_float
*3),
180 ("ref_count",c_uint8
),
181 ("ref_total",c_uint8
)]
184 class ent_path_index(Structure
):
186 _fields_
= [("index",c_uint16
)]
189 class vg_audio_clip(Structure
):
191 _fields_
= [("path",c_uint64
),
197 class union_file_audio_clip(Union
):
199 _fields_
= [("file",mdl_file
),
200 ("reserved",vg_audio_clip
)]
203 class ent_audio_clip(Structure
):
205 _fields_
= [("_anon",union_file_audio_clip
),
206 ("probability",c_float
)]
209 class ent_checkpoint(Structure
):
211 _fields_
= [("gate_index",c_uint16
),
212 ("path_start",c_uint16
),
213 ("path_count",c_uint16
)]
216 class ent_route(Structure
):
218 _fields_
= [("transform",mdl_transform
),
219 ("pstr_name",c_uint32
),
220 ("checkpoints_start",c_uint16
),
221 ("checkpoints_count",c_uint16
),
222 ("colour",c_float
*4),
223 ("active",c_uint32
), #runtime
225 ("board_transform",(c_float
*3)*4),
227 ("latest_pass",c_double
)]
230 class ent_water(Structure
):
232 _fields_
= [("transform",mdl_transform
),
233 ("max_dist",c_float
),
234 ("reserved0",c_uint32
),
235 ("reserved1",c_uint32
)]
238 class volume_trigger(Structure
):
240 _fields_
= [("event",c_uint32
),
244 class volume_particles(Structure
):
246 _fields_
= [("blank",c_uint32
),
250 class volume_union(Union
):
252 _fields_
= [("trigger",volume_trigger
),
253 ("particles",volume_particles
)]
256 class ent_index(Structure
):
258 _fields_
= [("type",c_uint32
),
262 class ent_volume(Structure
):
264 _fields_
= [("transform",mdl_transform
),
265 ("to_world",(c_float
*3)*4),
266 ("to_local",(c_float
*3)*4),
268 ("target",ent_index
),
269 ("_anon",volume_union
)]
272 class ent_audio(Structure
):
274 _fields_
= [("transform",mdl_transform
),
276 ("clip_start",c_uint32
),
277 ("clip_count",c_uint32
),
279 ("crossfade",c_float
),
280 ("channel_behaviour",c_uint32
),
282 ("probability_curve",c_uint32
),
283 ("max_channels",c_uint32
)]
286 class ent_marker(Structure
):
288 _fields_
= [("transform",mdl_transform
),
292 def obj_ent_type( obj
):
294 if obj
.type == 'ARMATURE': return 'mdl_armature'
295 elif obj
.type == 'LIGHT': return 'ent_light'
296 else: return obj
.SR_data
.ent_type
299 def sr_filter_ent_type( obj
, ent_types
):
301 if obj
== bpy
.context
.active_object
: return False
303 for c0
in obj
.users_collection
:#{
304 for c1
in bpy
.context
.active_object
.users_collection
:#{
306 return obj_ent_type( obj
) in ent_types
314 def compile_obj_transform( obj
, transform
):
316 co
= obj
.matrix_world
@ Vector((0,0,0))
317 q
= obj
.matrix_local
.to_quaternion()
322 transform
.co
[0] = co
[0]
323 transform
.co
[1] = co
[2]
324 transform
.co
[2] = -co
[1]
325 transform
.q
[0] = q
[1]
326 transform
.q
[1] = q
[3]
327 transform
.q
[2] = -q
[2]
328 transform
.q
[3] = q
[0]
329 transform
.s
[0] = s
[0]
330 transform
.s
[1] = s
[2]
331 transform
.s
[2] = s
[1]
334 def int_align_to( v
, align
):
336 while(v
%align
)!=0: v
+= 1
340 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
342 while (len(buffer) % align
) != 0: buffer.extend(w
)
346 def bytearray_print_hex( s
, w
=16 ):
348 for r
in range((len(s
)+(w
-1))//w
):#{
350 i1
=min((r
+1)*w
,len(s
))
351 print( F
'{r*w:06x}| \x1B[31m', end
='')
352 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
353 print( "\x1B[0m", end
='')
354 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
358 def sr_compile_string( s
):
360 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
362 index
= len( sr_compile
.string_data
)
363 sr_compile
.string_cache
[s
] = index
364 sr_compile
.string_data
.extend( s
.encode('utf-8') )
365 sr_compile
.string_data
.extend( b
'\0' )
367 bytearray_align_to( sr_compile
.string_data
, 4 )
371 def material_tex_image(v
):
381 cxr_graph_mapping
= \
383 # Default shader setup
390 "image": "tex_diffuse"
394 "A": material_tex_image("tex_diffuse"),
395 "B": material_tex_image("tex_decal")
402 "Color": material_tex_image("tex_normal")
408 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
410 def material_info(mat
):
414 # Using the cxr_graph_mapping as a reference, go through the shader
415 # graph and gather all $props from it.
417 def _graph_read( node_def
, node
=None, depth
=0 ):#{
424 _graph_read
.extracted
= []
426 for node_idname
in node_def
:#{
427 for n
in mat
.node_tree
.nodes
:#{
428 if n
.name
== node_idname
:#{
429 node_def
= node_def
[node_idname
]
437 for link
in node_def
:#{
438 link_def
= node_def
[link
]
440 if isinstance( link_def
, dict ):#{
442 for x
in node
.inputs
:#{
443 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
451 if node_link
and node_link
.is_linked
:#{
452 # look for definitions for the connected node type
454 from_node
= node_link
.links
[0].from_node
456 node_name
= from_node
.name
.split('.')[0]
457 if node_name
in link_def
:#{
458 from_node_def
= link_def
[ node_name
]
460 _graph_read( from_node_def
, from_node
, depth
+1 )
464 if "default" in link_def
:#{
465 prop
= link_def
['default']
466 info
[prop
] = node_link
.default_value
472 info
[prop
] = getattr( node
, link
)
477 _graph_read( cxr_graph_mapping
)
483 decoded
= bytearray()
484 for i
in range(len(s
)//2):#{
485 c
= (ord(s
[i
*2+0])-0x41)
486 c |
= (ord(s
[i
*2+1])-0x41)<<4
487 decoded
.extend(bytearray(c_uint8(c
))) #??
492 def sr_pack_file( file, path
, data
):
494 file.path
= sr_compile_string( path
)
495 file.pack_offset
= len( sr_compile
.pack_data
)
496 file.pack_size
= len( data
)
498 sr_compile
.pack_data
.extend( data
)
499 bytearray_align_to( sr_compile
.pack_data
, 16 )
502 def sr_compile_texture( img
):
507 name
= os
.path
.splitext( img
.name
)[0]
509 if name
in sr_compile
.texture_cache
:
510 return sr_compile
.texture_cache
[name
]
512 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
517 if sr_compile
.pack_textures
:#{
518 filedata
= qoi_encode( img
)
519 sr_pack_file( tex
.file, name
, filedata
)
522 sr_compile
.texture_cache
[name
] = texture_index
523 sr_compile
.texture_data
.extend( bytearray(tex
) )
527 def sr_compile_material( mat
):
531 if mat
.name
in sr_compile
.material_cache
:
532 return sr_compile
.material_cache
[mat
.name
]
534 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
535 sr_compile
.material_cache
[mat
.name
] = index
538 m
.pstr_name
= sr_compile_string( mat
.name
)
541 if mat
.SR_data
.collision
:#{
543 if mat
.SR_data
.skate_surface
: flags |
= 0x1
544 if mat
.SR_data
.grind_surface
: flags |
= (0x8|
0x1)
547 if mat
.SR_data
.grow_grass
: flags |
= 0x4
550 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
552 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
553 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
554 if mat
.SR_data
.shader
== 'terrain_blend':#{
557 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
558 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
559 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
562 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
563 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
566 if mat
.SR_data
.shader
== 'vertex_blend':#{
569 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
570 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
573 if mat
.SR_data
.shader
== 'water':#{
576 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
577 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
578 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
580 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
581 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
582 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
586 inf
= material_info( mat
)
588 if mat
.SR_data
.shader
== 'standard' or \
589 mat
.SR_data
.shader
== 'standard_cutout' or \
590 mat
.SR_data
.shader
== 'terrain_blend' or \
591 mat
.SR_data
.shader
== 'vertex_blend':
593 if 'tex_diffuse' in inf
:
594 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
597 sr_compile
.material_data
.extend( bytearray(m
) )
601 def sr_armature_bones( armature
):
603 def _recurse_bone( b
):
606 for c
in b
.children
: yield from _recurse_bone( c
)
609 for b
in armature
.data
.bones
:
611 yield from _recurse_bone( b
)
614 def sr_compile_mesh( obj
):
617 compile_obj_transform(obj
, node
.transform
)
618 node
.pstr_name
= sr_compile_string(obj
.name
)
624 for mod
in obj
.modifiers
:#{
625 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
626 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
629 can_use_cache
= False
632 if mod
.type == 'ARMATURE': #{
634 armature
= mod
.object
635 rig_weight_groups
= \
636 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
637 node
.armature_id
= sr_compile
.entity_ids
[armature
.name
]
639 POSE_OR_REST_CACHE
= armature
.data
.pose_position
640 armature
.data
.pose_position
= 'REST'
644 # Check the cache first
646 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
647 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
648 node
.submesh_start
= ref
[0]
649 node
.submesh_count
= ref
[1]
650 sr_compile
.mesh_data
.extend(bytearray(node
))
654 # Compile a whole new mesh
656 node
.submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
657 node
.submesh_count
= 0
659 dgraph
= bpy
.context
.evaluated_depsgraph_get()
660 data
= obj
.evaluated_get(dgraph
).data
661 data
.calc_loop_triangles()
662 data
.calc_normals_split()
664 # Mesh is split into submeshes based on their material
666 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
667 for material_id
, mat
in enumerate(mat_list
): #{
671 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
672 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
675 sm
.material_id
= sr_compile_material( mat
)
677 INF
=99999999.99999999
683 # Keep a reference to very very very similar vertices
684 # i have no idea how to speed it up.
686 vertex_reference
= {}
688 # Write the vertex / indice data
690 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
691 if tri
.material_index
!= material_id
:
695 vert
= data
.vertices
[tri
.vertices
[j
]]
697 vi
= data
.loops
[li
].vertex_index
699 # Gather vertex information
702 norm
= data
.loops
[li
].normal
704 colour
= (255,255,255,255)
711 uv
= data
.uv_layers
.active
.data
[li
].uv
715 if data
.vertex_colors
:#{
716 colour
= data
.vertex_colors
.active
.data
[li
].color
717 colour
= (int(colour
[0]*255.0),\
718 int(colour
[1]*255.0),\
719 int(colour
[2]*255.0),\
720 int(colour
[3]*255.0))
723 # Weight groups: truncates to the 3 with the most influence. The
724 # fourth bone ID is never used by the shader so it
728 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
729 if obj
.vertex_groups
[_
.group
].name
in \
732 weight_groups
= sorted( src_groups
, key
= \
733 lambda a
: a
.weight
, reverse
=True )
735 for ml
in range(3):#{
736 if len(weight_groups
) > ml
:#{
737 g
= weight_groups
[ml
]
738 name
= obj
.vertex_groups
[g
.group
].name
741 groups
[ml
] = rig_weight_groups
.index(name
)
746 if len(weight_groups
) > 0:#{
747 inv_norm
= (1.0/tot
) * 65535.0
748 for ml
in range(3):#{
749 weights
[ml
] = int( weights
[ml
] * inv_norm
)
750 weights
[ml
] = min( weights
[ml
], 65535 )
751 weights
[ml
] = max( weights
[ml
], 0 )
756 li1
= tri
.loops
[(j
+1)%3]
757 vi1
= data
.loops
[li1
].vertex_index
758 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
760 if e0
.use_freestyle_mark
and \
761 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
762 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
768 TOLERENCE
= float(10**4)
769 key
= (int(co
[0]*TOLERENCE
+0.5),
770 int(co
[1]*TOLERENCE
+0.5),
771 int(co
[2]*TOLERENCE
+0.5),
772 int(norm
[0]*TOLERENCE
+0.5),
773 int(norm
[1]*TOLERENCE
+0.5),
774 int(norm
[2]*TOLERENCE
+0.5),
775 int(uv
[0]*TOLERENCE
+0.5),
776 int(uv
[1]*TOLERENCE
+0.5),
777 colour
[0], # these guys are already quantized
790 if key
in vertex_reference
:
791 index
= vertex_reference
[key
]
793 index
= bytearray(c_uint32(sm
.vertex_count
))
796 vertex_reference
[key
] = index
806 v
.colour
[0] = colour
[0]
807 v
.colour
[1] = colour
[1]
808 v
.colour
[2] = colour
[2]
809 v
.colour
[3] = colour
[3]
810 v
.weights
[0] = weights
[0]
811 v
.weights
[1] = weights
[1]
812 v
.weights
[2] = weights
[2]
813 v
.weights
[3] = weights
[3]
814 v
.groups
[0] = groups
[0]
815 v
.groups
[1] = groups
[1]
816 v
.groups
[2] = groups
[2]
817 v
.groups
[3] = groups
[3]
820 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
821 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
824 sr_compile
.vertex_data
.extend(bytearray(v
))
828 sr_compile
.indice_data
.extend( index
)
832 # Make sure bounding box isn't -inf -> inf if no vertices
834 if sm
.vertex_count
== 0:
839 # Add submesh to encoder
841 sr_compile
.submesh_data
.extend( bytearray(sm
) )
842 node
.submesh_count
+= 1
846 armature
.data
.pose_position
= POSE_OR_REST_CACHE
849 # Save a reference to this node since we want to reuse the submesh indices
851 sr_compile
.mesh_cache
[obj
.data
.name
]=(node
.submesh_start
,node
.submesh_count
)
852 sr_compile
.mesh_data
.extend(bytearray(node
))
855 def sr_compile_armature( obj
):
857 node
= mdl_armature()
858 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
860 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
863 bones
= [_
for _
in sr_armature_bones(obj
)]
864 bones_names
= [None]+[_
.name
for _
in bones
]
868 if b
.use_deform
: bone
.flags
= 0x1
869 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
871 bone
.collider
= int(b
.SR_data
.collider
)
873 if bone
.collider
>0:#{
874 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
875 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
876 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
877 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
878 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
879 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
882 if b
.SR_data
.cone_constraint
:#{
884 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
885 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
886 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
887 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
888 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
889 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
890 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
891 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
892 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
893 bone
.conet
= b
.SR_data
.conet
896 bone
.co
[0] = b
.head_local
[0]
897 bone
.co
[1] = b
.head_local
[2]
898 bone
.co
[2] = -b
.head_local
[1]
899 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
900 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
901 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
902 bone
.pstr_name
= sr_compile_string( b
.name
)
904 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
907 bone
.ik_target
= bones_names
.index(c
.subtarget
)
908 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
913 sr_compile
.bone_data
.extend(bytearray(bone
))
918 if obj
.animation_data
and sr_compile
.pack_animations
: #{
919 # So we can restore later
921 previous_frame
= bpy
.context
.scene
.frame_current
922 previous_action
= obj
.animation_data
.action
923 POSE_OR_REST_CACHE
= obj
.data
.pose_position
924 obj
.data
.pose_position
= 'POSE'
926 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
927 for NLAStrip
in NLALayer
.strips
:#{
930 for a
in bpy
.data
.actions
:#{
931 if a
.name
== NLAStrip
.name
:#{
932 obj
.animation_data
.action
= a
937 # Clip to NLA settings
939 anim_start
= int(NLAStrip
.action_frame_start
)
940 anim_end
= int(NLAStrip
.action_frame_end
)
944 anim
= mdl_animation()
945 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
947 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
948 sizeof(mdl_transform
)
949 anim
.length
= anim_end
-anim_start
952 # Export the keyframes
953 for frame
in range(anim_start
,anim_end
):#{
954 bpy
.context
.scene
.frame_set(frame
)
957 pb
= obj
.pose
.bones
[rb
.name
]
959 # relative bone matrix
960 if rb
.parent
is not None:#{
961 offset_mtx
= rb
.parent
.matrix_local
962 offset_mtx
= offset_mtx
.inverted_safe() @ \
965 inv_parent
= pb
.parent
.matrix
@ offset_mtx
966 inv_parent
.invert_safe()
967 fpm
= inv_parent
@ pb
.matrix
970 bone_mtx
= rb
.matrix
.to_4x4()
971 local_inv
= rb
.matrix_local
.inverted_safe()
972 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
975 loc
, rot
, sca
= fpm
.decompose()
978 lc_m
= pb
.matrix_channel
.to_3x3()
979 if pb
.parent
is not None:#{
980 smtx
= pb
.parent
.matrix_channel
.to_3x3()
981 lc_m
= smtx
.inverted() @ lc_m
983 rq
= lc_m
.to_quaternion()
996 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1002 # Add to animation buffer
1004 sr_compile
.anim_data
.extend(bytearray(anim
))
1005 node
.anim_count
+= 1
1009 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1013 # Restore context to how it was before
1015 bpy
.context
.scene
.frame_set( previous_frame
)
1016 obj
.animation_data
.action
= previous_action
1017 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1020 sr_compile
.armature_data
.extend(bytearray(node
))
1023 def sr_ent_push( struct
):
1025 clase
= type(struct
).__name
__
1027 if clase
not in sr_compile
.entity_data
:#{
1028 sr_compile
.entity_data
[ clase
] = bytearray()
1029 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1032 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1033 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1037 def sr_array_title( arr
, name
, count
, size
, offset
):
1039 for i
in range(len(name
)):#{
1040 arr
.name
[i
] = ord(name
[i
])
1042 arr
.file_offset
= offset
1043 arr
.item_count
= count
1044 arr
.item_size
= size
1047 def sr_compile( collection
):
1049 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1052 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1053 sr_compile
.pack_animations
= collection
.SR_data
.animations
1056 sr_compile
.string_cache
= {}
1057 sr_compile
.mesh_cache
= {}
1058 sr_compile
.material_cache
= {}
1059 sr_compile
.texture_cache
= {}
1062 sr_compile
.mesh_data
= bytearray()
1063 sr_compile
.submesh_data
= bytearray()
1064 sr_compile
.vertex_data
= bytearray()
1065 sr_compile
.indice_data
= bytearray()
1066 sr_compile
.bone_data
= bytearray()
1067 sr_compile
.material_data
= bytearray()
1068 sr_compile
.armature_data
= bytearray()
1069 sr_compile
.anim_data
= bytearray()
1070 sr_compile
.keyframe_data
= bytearray()
1071 sr_compile
.texture_data
= bytearray()
1073 # just bytes not structures
1074 sr_compile
.string_data
= bytearray()
1075 sr_compile
.pack_data
= bytearray()
1078 sr_compile
.entity_data
= {}
1079 sr_compile
.entity_info
= {}
1081 print( F
"[SR] assign entity ID's" )
1082 sr_compile
.entities
= {}
1083 sr_compile
.entity_ids
= {}
1086 for obj
in collection
.all_objects
: #{
1087 if obj
.type == 'MESH': mesh_count
+= 1
1089 ent_type
= obj_ent_type( obj
)
1090 if ent_type
== 'none': continue
1092 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1093 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1094 sr_compile
.entities
[ent_type
] += [obj
]
1097 print( F
"[SR] Compiling geometry" )
1099 for obj
in collection
.all_objects
:#{
1100 if obj
.type == 'MESH':#{
1102 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end
='\r' )
1103 sr_compile_mesh( obj
)
1107 audio_clip_count
= 0
1109 for ent_type
, arr
in sr_compile
.entities
.items():#{
1110 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1112 for i
in range(len(arr
)):#{
1115 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1117 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1118 elif ent_type
== 'ent_light': #{
1120 compile_obj_transform( obj
, light
.transform
)
1121 light
.daytime
= obj
.data
.SR_data
.daytime
1122 if obj
.data
.type == 'POINT':#{
1125 elif obj
.data
.type == 'SPOT':#{
1127 light
.angle
= obj
.data
.spot_size
*0.5
1129 light
.range = obj
.data
.cutoff_distance
1130 light
.colour
[0] = obj
.data
.color
[0]
1131 light
.colour
[1] = obj
.data
.color
[1]
1132 light
.colour
[2] = obj
.data
.color
[2]
1133 light
.colour
[3] = obj
.data
.energy
1134 sr_ent_push( light
)
1136 elif ent_type
== 'ent_gate': #{
1139 obj_data
= obj
.SR_data
.ent_gate
[0]
1140 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1141 if obj_data
.target
:#{
1142 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1145 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1146 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1147 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1149 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1150 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1152 if obj_data
.target
:#{
1153 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1154 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1159 for x
in range(2):#{
1160 gate
.co
[x
][0] = co
[x
][0]
1161 gate
.co
[x
][1] = co
[x
][2]
1162 gate
.co
[x
][2] = -co
[x
][1]
1163 gate
.q
[x
][0] = q
[x
][1]
1164 gate
.q
[x
][1] = q
[x
][3]
1165 gate
.q
[x
][2] = -q
[x
][2]
1166 gate
.q
[x
][3] = q
[x
][0]
1171 elif ent_type
== 'ent_spawn': #{
1173 compile_obj_transform( obj
, spawn
.transform
)
1174 obj_data
= obj
.SR_data
.ent_spawn
[0]
1175 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1176 sr_ent_push( spawn
)
1178 elif ent_type
== 'ent_water':#{
1180 compile_obj_transform( obj
, water
.transform
)
1181 water
.max_dist
= 0.0
1182 sr_ent_push( water
)
1184 elif ent_type
== 'ent_audio':#{
1185 obj_data
= obj
.SR_data
.ent_audio
[0]
1187 compile_obj_transform( obj
, audio
.transform
)
1188 audio
.clip_start
= audio_clip_count
1189 audio
.clip_count
= len(obj_data
.files
)
1190 audio_clip_count
+= audio
.clip_count
1191 audio
.max_channels
= obj_data
.max_channels
1192 audio
.volume
= obj_data
.volume
1195 # - allow/disable doppler
1196 # - channel group tags with random colours
1197 # - transition properties
1199 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1200 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1201 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1202 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1203 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1204 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1205 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1207 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1208 if audio
.channel_behaviour
>= 1:#{
1209 audio
.group
= obj_data
.group
1211 if audio
.channel_behaviour
== 2:#{
1212 audio
.crossfade
= obj_data
.transition_duration
1214 audio
.probability_curve
= int(obj_data
.probability_curve
)
1216 for ci
in range(audio
.clip_count
):#{
1217 entry
= obj_data
.files
[ci
]
1218 clip
= ent_audio_clip()
1219 clip
.probability
= entry
.probability
1220 if obj_data
.formato
== '2':#{
1221 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1224 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1225 clip
._anon
.file.pack_offset
= 0
1226 clip
._anon
.file.pack_size
= 0
1230 sr_ent_push( audio
)
1232 elif ent_type
== 'ent_volume':#{
1233 obj_data
= obj
.SR_data
.ent_volume
[0]
1234 volume
= ent_volume()
1235 volume
.type = int(obj_data
.subtype
)
1236 compile_obj_transform( obj
, volume
.transform
)
1238 if obj_data
.target
:#{
1239 target
= obj_data
.target
1240 volume
.target
.type = sr_entity_alias
[obj_ent_type(target
)]
1241 volume
.target
.index
= sr_compile
.entity_ids
[ target
.name
]
1246 elif ent_type
== 'ent_marker':#{
1247 marker
= ent_marker()
1248 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1249 compile_obj_transform( obj
, marker
.transform
)
1255 def _children( col
):#{
1257 for c
in col
.children
:#{
1258 yield from _children(c
)
1262 checkpoint_count
= 0
1263 pathindice_count
= 0
1266 for col
in _children(collection
):#{
1267 print( F
"Adding routes for subcollection: {col.name}" )
1272 for obj
in col
.objects
:#{
1273 if obj
.type == 'ARMATURE': pass
1275 ent_type
= obj_ent_type( obj
)
1277 if ent_type
== 'ent_gate':
1278 route_gates
+= [obj
]
1279 elif ent_type
== 'ent_route_node':#{
1280 if obj
.type == 'CURVE':#{
1281 route_curves
+= [obj
]
1284 elif ent_type
== 'ent_route':
1289 dij
= create_node_graph( route_curves
, route_gates
)
1291 for obj
in routes
:#{
1292 obj_data
= obj
.SR_data
.ent_route
[0]
1294 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1295 route
.checkpoints_start
= checkpoint_count
1296 route
.checkpoints_count
= 0
1299 route
.colour
[ci
] = obj_data
.colour
[ci
]
1300 route
.colour
[3] = 1.0
1302 compile_obj_transform( obj
, route
.transform
)
1303 checkpoints
= obj_data
.gates
1305 for i
in range(len(checkpoints
)):#{
1306 gi
= checkpoints
[i
].target
1307 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1311 dest
= gi
.SR_data
.ent_gate
[0].target
1315 if gi
==gj
: continue # error?
1316 if not gi
or not gj
: continue
1318 checkpoint
= ent_checkpoint()
1319 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1320 checkpoint
.path_start
= pathindice_count
1321 checkpoint
.path_count
= 0
1323 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1326 for pi
in range(len(path
)):#{
1327 pathindice
= ent_path_index()
1328 pathindice
.index
= routenode_count
+ path
[pi
]
1329 sr_ent_push( pathindice
)
1331 checkpoint
.path_count
+= 1
1332 pathindice_count
+= 1
1336 sr_ent_push( checkpoint
)
1337 route
.checkpoints_count
+= 1
1338 checkpoint_count
+= 1
1341 sr_ent_push( route
)
1344 for point
in dij
.points
:#{
1345 rn
= ent_route_node()
1348 rn
.co
[2] = -point
[1]
1352 routenode_count
+= len(dij
.points
)
1356 print( F
"[SR] Writing file" )
1358 file_array_instructions
= {}
1361 def _write_array( name
, item_size
, data
):#{
1362 nonlocal file_array_instructions
, file_offset
1364 count
= len(data
)//item_size
1365 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
1366 'data':data
, 'offset': file_offset
}
1367 file_offset
+= len(data
)
1368 file_offset
= int_align_to( file_offset
, 8 )
1371 _write_array( 'strings', 1, sr_compile
.string_data
)
1372 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
1373 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
1374 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
1375 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
1376 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
1377 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
1379 for name
, buffer in sr_compile
.entity_data
.items():#{
1380 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
1383 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
1384 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
1385 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
1386 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
1387 _write_array( 'pack', 1, sr_compile
.pack_data
)
1389 header_size
= int_align_to( sizeof(mdl_header
), 8 )
1390 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
1392 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
1393 path
= F
"{folder}{collection.name}.mdl"
1396 fp
= open( path
, "wb" )
1397 header
= mdl_header()
1399 sr_array_title( header
.arrays
, \
1400 'index', len(file_array_instructions
), \
1401 sizeof(mdl_array
), header_size
)
1403 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
1405 print( F
'[SR] {"name":>16}| count | offset' )
1407 for name
,info
in file_array_instructions
.items():#{
1409 offset
= info
['offset'] + header_size
+ index_size
1410 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
1411 index
.extend( bytearray(arr
) )
1413 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
1414 F
' 0x{info["offset"]:02x}' )
1416 fp
.write( bytearray_align_to( index
, 8 ) )
1417 #bytearray_print_hex( index )
1419 for name
,info
in file_array_instructions
.items():#{
1420 fp
.write( bytearray_align_to( info
['data'], 8 ) )
1425 print( '[SR] done' )
1428 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
1430 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
1431 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
1432 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=True )
1434 panel
: bpy
.props
.EnumProperty(
1438 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
1439 ('ENTITY', 'Entity', '', 'MONKEY',1),
1440 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
1445 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
1447 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
1448 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
1451 def sr_get_mirror_bone( bones
):
1453 side
= bones
.active
.name
[-1:]
1454 other_name
= bones
.active
.name
[:-1]
1455 if side
== 'L': other_name
+= 'R'
1456 elif side
== 'R': other_name
+= 'L'
1460 if b
.name
== other_name
:
1467 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
1469 bl_idname
="skaterift.mirror_bone"
1470 bl_label
="Mirror bone attributes - SkateRift"
1472 def execute(_
,context
):
1474 active_object
= context
.active_object
1475 bones
= active_object
.data
.bones
1477 b
= sr_get_mirror_bone( bones
)
1479 if not b
: return {'FINISHED'}
1481 b
.SR_data
.collider
= a
.SR_data
.collider
1483 def _v3copyflipy( a
, b
):#{
1489 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
1490 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
1491 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
1492 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
1494 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
1496 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
1497 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
1498 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
1500 b
.SR_data
.conet
= a
.SR_data
.conet
1503 ob
= bpy
.context
.scene
.objects
[0]
1504 ob
.hide_render
= ob
.hide_render
1509 class SR_COMPILE(bpy
.types
.Operator
):
1511 bl_idname
="skaterift.compile_all"
1512 bl_label
="Compile All"
1514 def execute(_
,context
):
1516 view_layer
= bpy
.context
.view_layer
1517 for col
in view_layer
.layer_collection
.children
["export"].children
:
1518 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
1519 sr_compile( bpy
.data
.collections
[col
.name
] )
1525 class SR_COMPILE_THIS(bpy
.types
.Operator
):
1527 bl_idname
="skaterift.compile_this"
1528 bl_label
="Compile This collection"
1530 def execute(_
,context
):
1532 col
= bpy
.context
.collection
1539 class SR_INTERFACE(bpy
.types
.Panel
):
1541 bl_idname
= "VIEW3D_PT_skate_rift"
1542 bl_label
= "Skate Rift"
1543 bl_space_type
= 'VIEW_3D'
1544 bl_region_type
= 'UI'
1545 bl_category
= "Skate Rift"
1547 def draw(_
, context
):
1551 row
= _
.layout
.row()
1553 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
1555 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
1556 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
1558 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
1559 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
1560 col
= bpy
.context
.collection
1562 found_in_export
= False
1564 view_layer
= bpy
.context
.view_layer
1565 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
1566 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
1569 if c1
.name
== col
.name
: #{
1570 found_in_export
= True
1574 box
= _
.layout
.box()
1576 row
.alignment
= 'CENTER'
1579 if found_in_export
: #{
1580 row
.label( text
=col
.name
+ ".mdl" )
1581 box
.prop( col
.SR_data
, "pack_textures" )
1582 box
.prop( col
.SR_data
, "animations" )
1583 box
.operator( "skaterift.compile_this" )
1587 row
.label( text
=col
.name
)
1591 row
.alignment
= 'CENTER'
1593 row
.label( text
="This collection is not in the export group" )
1596 box
= _
.layout
.box()
1599 split
= row
.split( factor
=0.3, align
=True )
1600 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
1603 if export_count
== 0:
1605 row1
.operator( "skaterift.compile_all", \
1606 text
=F
"Compile all ({export_count} collections)" )
1608 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
1609 active_object
= context
.active_object
1610 if not active_object
: return
1612 box
= _
.layout
.box()
1614 row
.alignment
= 'CENTER'
1615 row
.label( text
=active_object
.name
)
1618 def _draw_prop_collection( data
): #{
1621 row
.alignment
= 'CENTER'
1624 row
.label( text
=F
'{data[0]}' )
1626 if hasattr(type(data
[0]),'sr_inspector'):#{
1627 type(data
[0]).sr_inspector( box
, data
)
1630 for a
in data
[0].__annotations
__:
1631 box
.prop( data
[0], a
)
1635 if active_object
.type == 'ARMATURE': #{
1636 if active_object
.mode
== 'POSE': #{
1637 bones
= active_object
.data
.bones
1638 mb
= sr_get_mirror_bone( bones
)
1640 box
.operator( "skaterift.mirror_bone", \
1641 text
=F
'Mirror attributes to {mb.name}' )
1644 _draw_prop_collection( [bones
.active
.SR_data
] )
1648 row
.alignment
='CENTER'
1651 row
.label( text
="Enter pose mode to modify bone properties" )
1654 elif active_object
.type == 'LIGHT': #{
1655 _draw_prop_collection( [active_object
.data
.SR_data
] )
1657 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
1658 box
.prop( active_object
.SR_data
, "ent_type" )
1659 ent_type
= active_object
.SR_data
.ent_type
1661 col
= getattr( active_object
.SR_data
, ent_type
, None )
1662 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
1664 if active_object
.type == 'MESH':#{
1665 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
1666 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
1673 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
1675 bl_label
="Skate Rift material"
1676 bl_idname
="MATERIAL_PT_sr_material"
1677 bl_space_type
='PROPERTIES'
1678 bl_region_type
='WINDOW'
1679 bl_context
="material"
1681 def draw(_
,context
):
1683 active_object
= bpy
.context
.active_object
1684 if active_object
== None: return
1685 active_mat
= active_object
.active_material
1686 if active_mat
== None: return
1688 info
= material_info( active_mat
)
1690 if 'tex_diffuse' in info
:#{
1691 _
.layout
.label( icon
='INFO', \
1692 text
=F
"{info['tex_diffuse'].name} will be compiled" )
1695 _
.layout
.prop( active_mat
.SR_data
, "shader" )
1696 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
1697 _
.layout
.prop( active_mat
.SR_data
, "collision" )
1699 if active_mat
.SR_data
.collision
:#{
1700 _
.layout
.prop( active_mat
.SR_data
, "skate_surface" )
1701 _
.layout
.prop( active_mat
.SR_data
, "grind_surface" )
1702 _
.layout
.prop( active_mat
.SR_data
, "grow_grass" )
1705 if active_mat
.SR_data
.shader
== "terrain_blend":#{
1706 box
= _
.layout
.box()
1707 box
.prop( active_mat
.SR_data
, "blend_offset" )
1708 box
.prop( active_mat
.SR_data
, "sand_colour" )
1710 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
1711 box
= _
.layout
.box()
1712 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
1713 box
.prop( active_mat
.SR_data
, "blend_offset" )
1715 elif active_mat
.SR_data
.shader
== "water":#{
1716 box
= _
.layout
.box()
1717 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
1718 box
.prop( active_mat
.SR_data
, "shore_colour" )
1719 box
.prop( active_mat
.SR_data
, "ocean_colour" )
1724 def sr_get_type_enum( scene
, context
):
1726 items
= [('none','None',"")]
1727 mesh_entities
=['ent_gate','ent_water']
1728 point_entities
=['ent_spawn','ent_route_node','ent_route']
1730 for e
in point_entities
: items
+= [(e
,e
,'')]
1732 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
1733 if context
.active_object
.type == 'MESH': #{
1734 for e
in mesh_entities
: items
+= [(e
,e
,'')]
1738 for e
in mesh_entities
: items
+= [(e
,e
,'')]
1744 def sr_on_type_change( _
, context
):
1746 obj
= context
.active_object
1747 ent_type
= obj
.SR_data
.ent_type
1748 if ent_type
== 'none': return
1749 if obj
.type == 'MESH':#{
1750 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
1751 if col
!= None and len(col
)==0: col
.add()
1754 col
= getattr( obj
.SR_data
, ent_type
, None )
1755 if col
!= None and len(col
)==0: col
.add()
1758 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
1760 alias
: bpy
.props
.StringProperty( name
='alias' )
1763 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
1765 target
: bpy
.props
.PointerProperty( \
1766 type=bpy
.types
.Object
, name
="destination", \
1767 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
1770 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
1772 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
1775 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
1777 target
: bpy
.props
.PointerProperty( \
1778 type=bpy
.types
.Object
, name
='target', \
1779 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
1782 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
1784 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
1786 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
1788 layout
.prop( item
, 'target', text
='', emboss
=False )
1792 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
1794 bl_idname
= "skaterift.new_entry"
1795 bl_label
= "Add gate"
1797 def execute(self
, context
):#{
1798 active_object
= context
.active_object
1799 active_object
.SR_data
.ent_route
[0].gates
.add()
1804 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
1806 bl_idname
= "skaterift.del_entry"
1807 bl_label
= "Remove gate"
1810 def poll(cls
, context
):#{
1811 active_object
= context
.active_object
1812 if obj_ent_type(active_object
) == 'ent_gate':#{
1813 return active_object
.SR_data
.ent_route
[0].gates
1818 def execute(self
, context
):#{
1819 active_object
= context
.active_object
1820 lista
= active_object
.SR_data
.ent_route
[0].gates
1821 index
= active_object
.SR_data
.ent_route
[0].gates_index
1823 active_object
.SR_data
.ent_route
[0].gates_index
= \
1824 min(max(0, index
-1), len(lista
) - 1)
1829 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
1831 bl_idname
= "skaterift.al_new_entry"
1832 bl_label
= "Add file"
1834 def execute(self
, context
):#{
1835 active_object
= context
.active_object
1836 active_object
.SR_data
.ent_audio
[0].files
.add()
1841 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
1843 bl_idname
= "skaterift.al_del_entry"
1844 bl_label
= "Remove file"
1847 def poll(cls
, context
):#{
1848 active_object
= context
.active_object
1849 if obj_ent_type(active_object
) == 'ent_audio':#{
1850 return active_object
.SR_data
.ent_audio
[0].files
1855 def execute(self
, context
):#{
1856 active_object
= context
.active_object
1857 lista
= active_object
.SR_data
.ent_audio
[0].files
1858 index
= active_object
.SR_data
.ent_audio
[0].file_index
1860 active_object
.SR_data
.ent_audio
[0].file_index
= \
1861 min(max(0, index
-1), len(lista
) - 1)
1866 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
1868 path
: bpy
.props
.StringProperty( name
="Path" )
1869 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
1872 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
1874 bl_idname
= 'SR_UL_AUDIO_LIST'
1876 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
1878 split
= layout
.split(factor
=0.7)
1880 c
.prop( item
, 'path', text
='', emboss
=False )
1882 c
.prop( item
, 'probability', text
='%', emboss
=True )
1887 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
1889 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
1890 gates_index
: bpy
.props
.IntProperty()
1892 colour
: bpy
.props
.FloatVectorProperty( \
1896 default
=Vector((0.79,0.63,0.48)),\
1897 description
="Route colour"\
1900 alias
: bpy
.props
.StringProperty(\
1902 default
="Untitled Course")
1905 def sr_inspector( layout
, data
):
1907 layout
.prop( data
[0], 'alias' )
1908 layout
.prop( data
[0], 'colour' )
1910 layout
.label( text
='Checkpoints' )
1911 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
1912 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
1915 row
.operator( 'skaterift.new_entry', text
='Add' )
1916 row
.operator( 'skaterift.del_entry', text
='Remove' )
1920 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):
1922 subtype
: bpy
.props
.EnumProperty(
1924 items
=[('0','Trigger',''),
1925 ('1','Particles (0.1s)','')]
1928 target
: bpy
.props
.PointerProperty( \
1929 type=bpy
.types
.Object
, name
="Target", \
1930 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_audio']))
1933 def sr_inspector( layout
, data
):
1936 layout
.prop( data
, 'subtype' )
1937 layout
.prop( data
, 'target' )
1941 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
1943 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
1944 file_index
: bpy
.props
.IntProperty()
1946 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
1947 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
1948 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
1949 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
1951 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
1952 formato
: bpy
.props
.EnumProperty(
1954 items
=[('0','Uncompressed Mono',''),
1955 ('1','Compressed Vorbis',''),
1956 ('2','[vg] Bird Synthesis','')]
1958 probability_curve
: bpy
.props
.EnumProperty(
1959 name
="Probability Curve",
1960 items
=[('0','Constant',''),
1961 ('1','Wildlife Daytime',''),
1962 ('2','Wildlife Nighttime','')])
1963 channel_behaviour
: bpy
.props
.EnumProperty(
1964 name
="Channel Behaviour",
1965 items
=[('0','Unlimited',''),
1966 ('1','Discard if group full', ''),
1967 ('2','Crossfade if group full','')])
1969 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
1972 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
1973 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
1976 def sr_inspector( layout
, data
):
1978 layout
.prop( data
[0], 'formato' )
1979 layout
.prop( data
[0], 'volume' )
1982 box
.label( text
='Channels' )
1983 split
= box
.split(factor
=0.3)
1985 c
.prop( data
[0], 'max_channels' )
1987 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
1988 if data
[0].channel_behaviour
>= '1':
1989 box
.prop( data
[0], 'group' )
1990 if data
[0].channel_behaviour
== '2':
1991 box
.prop( data
[0], 'transition_duration' )
1994 box
.label( text
='Flags' )
1995 box
.prop( data
[0], 'flag_3d' )
1996 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
1998 box
.prop( data
[0], 'flag_loop' )
1999 box
.prop( data
[0], 'flag_auto' )
2001 split
= layout
.split(factor
=0.7)
2003 c
.label( text
='Filepath' )
2005 c
.label( text
='Chance (0.1s)' )
2007 layout
.prop( data
[0], 'probability_curve' )
2009 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
2010 data
[0], 'files', data
[0], 'file_index', rows
=5)
2013 row
.operator( 'skaterift.al_new_entry', text
='Add' )
2014 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
2018 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
2020 alias
: bpy
.props
.StringProperty()
2023 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
2025 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
2026 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
2027 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
2028 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
2029 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
2030 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
2032 ent_type
: bpy
.props
.EnumProperty(
2034 items
=[('none', 'None', '', 0),
2035 ('ent_gate','Gate','', 1),
2036 ('ent_spawn','Spawn','', 2),
2037 ('ent_route_node', 'Route Node', '', 3 ),
2038 ('ent_route', 'Route', '', 4),
2039 ('ent_water', 'Water Surface', '', 5),
2040 ('ent_volume', 'Volume', '', 6 ),
2041 ('ent_audio', 'Audio Files', '', 7),
2042 ('ent_marker', 'Marker', '', 8)],
2043 update
=sr_on_type_change
2047 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
2049 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
2052 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
2054 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
2057 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
2059 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
2060 items
=[('0','none',''),
2062 ('2','capsule','')])
2064 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
2065 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
2067 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
2069 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
2070 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
2071 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
2072 conet
: bpy
.props
.FloatProperty( name
='t' )
2075 def sr_inspector( layout
, data
):
2079 box
.prop( data
, 'collider' )
2081 if int(data
.collider
)>0:#{
2083 row
.prop( data
, 'collider_min' )
2085 row
.prop( data
, 'collider_max' )
2089 box
.prop( data
, 'cone_constraint' )
2090 if data
.cone_constraint
:#{
2092 row
.prop( data
, 'conevx' )
2094 row
.prop( data
, 'conevy' )
2096 row
.prop( data
, 'coneva' )
2097 box
.prop( data
, 'conet' )
2102 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
2104 shader
: bpy
.props
.EnumProperty(
2107 ('standard',"standard",''),
2108 ('standard_cutout', "standard_cutout", ''),
2109 ('terrain_blend', "terrain_blend", ''),
2110 ('vertex_blend', "vertex_blend", ''),
2111 ('water',"water",'')
2114 surface_prop
: bpy
.props
.EnumProperty(
2115 name
="Surface Property",
2117 ('0','concrete',''),
2124 collision
: bpy
.props
.BoolProperty( \
2125 name
="Collisions Enabled",\
2127 description
= "Can the player collide with this material"\
2129 skate_surface
: bpy
.props
.BoolProperty( \
2130 name
="Skate Surface", \
2132 description
= "Should the game try to target this surface?" \
2134 grind_surface
: bpy
.props
.BoolProperty( \
2135 name
="Grind Surface", \
2137 description
= "Grind face?" \
2139 grow_grass
: bpy
.props
.BoolProperty( \
2140 name
="Grow Grass", \
2142 description
= "Spawn grass sprites on this surface?" \
2144 blend_offset
: bpy
.props
.FloatVectorProperty( \
2145 name
="Blend Offset", \
2147 default
=Vector((0.5,0.0)),\
2148 description
="When surface is more than 45 degrees, add this vector " +\
2151 sand_colour
: bpy
.props
.FloatVectorProperty( \
2152 name
="Sand Colour",\
2155 default
=Vector((0.79,0.63,0.48)),\
2156 description
="Blend to this colour near the 0 coordinate on UP axis"\
2158 shore_colour
: bpy
.props
.FloatVectorProperty( \
2159 name
="Shore Colour",\
2162 default
=Vector((0.03,0.32,0.61)),\
2163 description
="Water colour at the shoreline"\
2165 ocean_colour
: bpy
.props
.FloatVectorProperty( \
2166 name
="Ocean Colour",\
2169 default
=Vector((0.0,0.006,0.03)),\
2170 description
="Water colour in the deep bits"\
2174 # ---------------------------------------------------------------------------- #
2178 # ---------------------------------------------------------------------------- #
2180 cv_view_draw_handler
= None
2181 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
2183 cv_view_colours
= []
2184 cv_view_course_i
= 0
2186 # Draw axis alligned sphere at position with radius
2188 def cv_draw_sphere( pos
, radius
, colour
):
2190 global cv_view_verts
, cv_view_colours
2192 ly
= pos
+ Vector((0,0,radius
))
2193 lx
= pos
+ Vector((0,radius
,0))
2194 lz
= pos
+ Vector((0,0,radius
))
2196 pi
= 3.14159265358979323846264
2198 for i
in range(16):#{
2199 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
2203 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
2204 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
2205 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
2207 cv_view_verts
+= [ px
, lx
]
2208 cv_view_verts
+= [ py
, ly
]
2209 cv_view_verts
+= [ pz
, lz
]
2211 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
2220 # Draw axis alligned sphere at position with radius
2222 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
2224 global cv_view_verts
, cv_view_colours
2226 ly
= pos
+ tz
*radius
2227 lx
= pos
+ ty
*radius
2228 lz
= pos
+ tz
*radius
2230 pi
= 3.14159265358979323846264
2232 for i
in range(16):#{
2233 t
= ((i
+1.0) * 1.0/16.0) * pi
2237 s1
= math
.sin(t
*2.0)
2238 c1
= math
.cos(t
*2.0)
2240 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
2241 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
2242 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
2244 cv_view_verts
+= [ px
, lx
]
2245 cv_view_verts
+= [ py
, ly
]
2246 cv_view_verts
+= [ pz
, lz
]
2248 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
2257 # Draw transformed -1 -> 1 cube
2259 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
2261 global cv_view_verts
, cv_view_colours
2267 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
2268 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
2269 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
2270 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
2271 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
2272 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
2273 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
2274 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
2276 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
2277 (0,4),(1,5),(2,6),(3,7)]
2282 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
2283 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
2284 cv_view_colours
+= [colour
, colour
]
2289 # Draw line with colour
2291 def cv_draw_line( p0
, p1
, colour
):
2293 global cv_view_verts
, cv_view_colours
2295 cv_view_verts
+= [p0
,p1
]
2296 cv_view_colours
+= [colour
, colour
]
2300 # Draw line with colour(s)
2302 def cv_draw_line2( p0
, p1
, c0
, c1
):
2304 global cv_view_verts
, cv_view_colours
2306 cv_view_verts
+= [p0
,p1
]
2307 cv_view_colours
+= [c0
,c1
]
2313 def cv_tangent_basis( n
, tx
, ty
):
2315 if abs( n
[0] ) >= 0.57735027:#{
2334 # Draw coloured arrow
2336 def cv_draw_arrow( p0
, p1
, c0
, size
=0.15 ):
2338 global cv_view_verts
, cv_view_colours
2344 tx
= Vector((1,0,0))
2345 ty
= Vector((1,0,0))
2346 cv_tangent_basis( n
, tx
, ty
)
2348 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
2349 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
2353 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
2355 global cv_view_verts
, cv_view_colours
2357 for i
in range(dots
):#{
2361 p2
= p0
*(1.0-t0
)+p1
*t0
2362 p3
= p0
*(1.0-t1
)+p1
*t1
2364 cv_view_verts
+= [p2
,p3
]
2365 cv_view_colours
+= [c0
,c0
]
2370 # Drawhandles of a bezier control point
2372 def cv_draw_bhandle( obj
, direction
, colour
):
2374 global cv_view_verts
, cv_view_colours
2377 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
2379 cv_view_verts
+= [p0
]
2380 cv_view_verts
+= [h0
]
2381 cv_view_colours
+= [colour
,colour
]
2385 # Draw a bezier curve (at fixed resolution 10)
2387 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
2389 global cv_view_verts
, cv_view_colours
2392 for i
in range(10):#{
2398 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
2400 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
2401 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
2402 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
2409 # I think this one extends the handles of the bezier otwards......
2411 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
2413 global cv_view_course_i
2415 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
2417 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
2418 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
2419 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
2420 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
2422 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
2426 # Flush the lines buffers. This is called often because god help you if you want
2427 # to do fixed, fast buffers in this catastrophic programming language.
2429 def cv_draw_lines():
2431 global cv_view_shader
, cv_view_verts
, cv_view_colours
2433 if len(cv_view_verts
) < 2:
2436 lines
= batch_for_shader(\
2437 cv_view_shader
, 'LINES', \
2438 { "pos":cv_view_verts
, "color":cv_view_colours
})
2440 lines
.draw( cv_view_shader
)
2443 cv_view_colours
= []
2446 # I dont remember what this does exactly
2448 def cv_draw_bpath( o0
,o1
,c0
,c1
):
2450 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
2453 # Semi circle to show the limit. and some lines
2455 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
2457 global cv_view_verts
, cv_view_colours
2462 for x
in range(16):#{
2465 a0
= amin
*(1.0-t0
)+amax
*t0
2466 a1
= amin
*(1.0-t1
)+amax
*t1
2468 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
2469 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
2471 p0
=obj
.matrix_world
@ p0
2472 p1
=obj
.matrix_world
@ p1
2473 cv_view_verts
+= [p0
,p1
]
2474 cv_view_colours
+= [colour
,colour
]
2477 cv_view_verts
+= [p0
,center
]
2478 cv_view_colours
+= [colour
,colour
]
2481 cv_view_verts
+= [p1
,center
]
2482 cv_view_colours
+= [colour
,colour
]
2486 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
2487 cv_view_colours
+= [colour
,colour
]
2492 # Cone and twist limit
2494 def draw_cone_twist( center
, vx
, vy
, va
):
2496 global cv_view_verts
, cv_view_colours
2497 axis
= vy
.cross( vx
)
2502 cv_view_verts
+= [center
, center
+va
*size
]
2503 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
2505 for x
in range(32):#{
2506 t0
= (x
/32) * math
.tau
2507 t1
= ((x
+1)/32) * math
.tau
2514 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
2515 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
2517 col0
= ( abs(c0
), abs(s0
), 0.0, 1.0 )
2518 col1
= ( abs(c1
), abs(s1
), 0.0, 1.0 )
2520 cv_view_verts
+= [center
, p0
, p0
, p1
]
2521 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
2527 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
2529 def draw_skeleton_helpers( obj
):
2531 global cv_view_verts
, cv_view_colours
2533 if obj
.data
.pose_position
!= 'REST':#{
2537 for bone
in obj
.data
.bones
:#{
2539 a
= Vector((bone
.SR_data
.collider_min
[0],
2540 bone
.SR_data
.collider_min
[1],
2541 bone
.SR_data
.collider_min
[2]))
2542 b
= Vector((bone
.SR_data
.collider_max
[0],
2543 bone
.SR_data
.collider_max
[1],
2544 bone
.SR_data
.collider_max
[2]))
2546 if bone
.SR_data
.collider
== '1':#{
2548 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
2549 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
2550 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
2551 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
2552 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
2553 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
2554 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
2555 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
2557 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
2558 (0,4),(1,5),(2,6),(3,7)]
2564 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
2565 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
2566 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
2569 elif bone
.SR_data
.collider
== '2':#{
2574 for i
in range(3):#{
2575 if abs(v0
[i
]) > largest
:#{
2576 largest
= abs(v0
[i
])
2581 v1
= Vector((0,0,0))
2582 v1
[major_axis
] = 1.0
2584 tx
= Vector((0,0,0))
2585 ty
= Vector((0,0,0))
2587 cv_tangent_basis( v1
, tx
, ty
)
2588 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
2589 l
= v0
[ major_axis
] - r
*2
2591 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
2592 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
2594 colour
= [0.2,0.2,0.2]
2595 colour
[major_axis
] = 0.5
2597 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
2598 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
2599 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
2600 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
2601 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
2602 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
2608 center
= obj
.matrix_world
@ c
2609 if bone
.SR_data
.cone_constraint
:#{
2610 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
2611 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
2612 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
2613 draw_cone_twist( center
, vx
, vy
, va
)
2618 def cv_ent_gate( obj
):
2620 global cv_view_verts
, cv_view_colours
2622 if obj
.type != 'MESH': return
2624 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
2625 data
= obj
.SR_data
.ent_gate
[0]
2626 dims
= mesh_data
.dimensions
2629 c
= Vector((0,0,dims
[2]))
2631 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
2632 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
2633 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
2634 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
2635 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
2636 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
2637 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
2638 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
2639 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
2641 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
2643 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
2645 p0
= r3d
.view_matrix
.inverted().translation
2646 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
2647 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
2649 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
2655 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
2656 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
2657 cv_view_colours
+= [cc
,cc
]
2661 if data
.target
!= None:
2662 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
2665 def cv_ent_volume( obj
):
2667 global cv_view_verts
, cv_view_colours
2669 data
= obj
.SR_data
.ent_volume
[0]
2671 if data
.subtype
== '0':#{
2672 cv_draw_ucube( obj
.matrix_world
, (0,1,0) )
2675 cv_draw_line( obj
.location
, data
.target
.location
, (0,1,0) )
2678 elif data
.subtype
== '1':#{
2679 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
2682 cv_draw_line( obj
.location
, data
.target
.location
, (1,1,0) )
2687 def dijkstra( graph
, start_node
, target_node
):
2689 unvisited
= [_
for _
in graph
]
2694 shortest_path
[n
] = 9999999.999999
2695 shortest_path
[start_node
] = 0
2698 current_min_node
= None
2699 for n
in unvisited
:#{
2700 if current_min_node
== None:
2701 current_min_node
= n
2702 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
2703 current_min_node
= n
2706 for branch
in graph
[current_min_node
]:#{
2707 tentative_value
= shortest_path
[current_min_node
]
2708 tentative_value
+= graph
[current_min_node
][branch
]
2709 if tentative_value
< shortest_path
[branch
]:#{
2710 shortest_path
[branch
] = tentative_value
2711 previous_nodes
[branch
] = current_min_node
2715 unvisited
.remove(current_min_node
)
2720 while node
!= start_node
:#{
2723 if node
not in previous_nodes
: return None
2724 node
= previous_nodes
[node
]
2727 # Add the start node manually
2728 path
.append(start_node
)
2734 def __init__(_
,points
,graph
,subsections
):#{
2737 _
.subsections
= subsections
2741 def create_node_graph( curves
, gates
):
2743 # add endpoints of curves
2750 for c
in range(len(curves
)):#{
2751 for s
in range(len(curves
[c
].data
.splines
)):#{
2752 spline
= curves
[c
].data
.splines
[s
]
2753 l
= len(spline
.points
)
2756 dist
= round(spline
.calc_length(),2)
2759 ib
= point_count
+l
-1
2761 graph
[ia
] = { ib
: dist
}
2762 graph
[ib
] = { ia
: dist
}
2764 for i
in range(len(spline
.points
)):#{
2765 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
2766 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
2771 if i
== 0: previous
= -1
2772 if i
== len(spline
.points
)-1: proxima
= -1
2774 subsections
.append((spline_count
,previous
,proxima
))
2783 graph_keys
= list(graph
)
2784 for i
in range(len(graph_keys
)-1):#{
2785 for j
in range(i
+1, len(graph_keys
)):#{
2786 if i
%2==0 and i
+1==j
: continue
2790 pi
= route_points
[ni
]
2791 pj
= route_points
[nj
]
2793 dist
= round((pj
-pi
).magnitude
,2)
2796 graph
[ni
][nj
] = dist
2797 graph
[nj
][ni
] = dist
2802 # add and link gates( by name )
2803 for gate
in gates
:#{
2804 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
2805 if gate
.SR_data
.ent_gate
[0].target
:
2808 graph
[ gate
.name
] = {}
2810 for i
in range(len(graph_keys
)):#{
2812 pi
= route_points
[ni
]
2814 v0
= pi
-gate
.location
2815 if v0
.dot(v1
) < 0.0: continue
2817 dist
= round(v0
.magnitude
,2)
2820 graph
[ gate
.name
][ ni
] = dist
2821 graph
[ ni
][ gate
.name
] = dist
2826 return dij_graph(route_points
,graph
,subsections
)
2829 def solve_graph( dij
, start
, end
):
2831 path
= dijkstra( dij
.graph
, end
, start
)
2835 for sj
in range(1,len(path
)-2):#{
2838 map0
= dij
.subsections
[i0
]
2839 map1
= dij
.subsections
[i1
]
2841 if map0
[0] == map1
[0]:#{
2842 if map0
[1] == -1: direction
= 2
2847 map0
= dij
.subsections
[i0
]
2848 i1
= map0
[direction
]
2862 full
.append( path
[-2] )
2867 def cv_draw_route( route
, dij
):
2869 pole
= Vector((0.2,0.2,10))
2870 hat
= Vector((1,8,0.2))
2871 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
2872 route
.SR_data
.ent_route
[0].colour
[1],
2873 route
.SR_data
.ent_route
[0].colour
[2])
2875 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
2876 Vector((0,-6.5,5.5)))
2877 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
2878 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
2879 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
2880 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
2882 checkpoints
= route
.SR_data
.ent_route
[0].gates
2884 for i
in range(len(checkpoints
)):#{
2885 gi
= checkpoints
[i
].target
2886 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
2889 dest
= gi
.SR_data
.ent_gate
[0].target
2891 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
2895 if gi
==gj
: continue # error?
2896 if not gi
or not gj
: continue
2898 path
= solve_graph( dij
, gi
.name
, gj
.name
)
2901 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5)
2902 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5)
2903 for j
in range(len(path
)-1):#{
2906 o0
= dij
.points
[ i0
]
2907 o1
= dij
.points
[ i1
]
2908 cv_draw_arrow(o0
,o1
,cc
,1.5)
2912 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
2919 global cv_view_shader
2920 global cv_view_verts
2921 global cv_view_colours
2922 global cv_view_course_i
2924 cv_view_course_i
= 0
2926 cv_view_colours
= []
2928 cv_view_shader
.bind()
2929 gpu
.state
.depth_mask_set(False)
2930 gpu
.state
.line_width_set(2.0)
2931 gpu
.state
.face_culling_set('BACK')
2932 gpu
.state
.depth_test_set('LESS')
2933 gpu
.state
.blend_set('NONE')
2939 for obj
in bpy
.context
.collection
.objects
:#{
2940 if obj
.type == 'ARMATURE':#{
2941 if obj
.data
.pose_position
== 'REST':
2942 draw_skeleton_helpers( obj
)
2945 ent_type
= obj_ent_type( obj
)
2947 if ent_type
== 'ent_gate':#{
2949 route_gates
+= [obj
]
2951 elif ent_type
== 'ent_route_node':#{
2952 if obj
.type == 'CURVE':#{
2953 route_curves
+= [obj
]
2956 elif ent_type
== 'ent_route':
2958 elif ent_type
== 'ent_volume':#{
2959 cv_ent_volume( obj
)
2961 elif ent_type
== 'ent_audio':#{
2962 if obj
.SR_data
.ent_audio
[0].flag_3d
:
2963 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
2968 dij
= create_node_graph( route_curves
, route_gates
)
2970 #cv_draw_route_map( route_nodes )
2971 for route
in routes
:#{
2972 cv_draw_route( route
, dij
)
2979 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
2980 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
2981 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
2983 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
2984 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
2985 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
2986 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
2987 SR_OBJECT_ENT_VOLUME
,
2988 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
2989 SR_OT_ROUTE_LIST_DEL_ITEM
,\
2990 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,\
2992 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
2993 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
2999 bpy
.utils
.register_class(c
)
3001 bpy
.types
.Scene
.SR_data
= \
3002 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
3003 bpy
.types
.Collection
.SR_data
= \
3004 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
3006 bpy
.types
.Object
.SR_data
= \
3007 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
3008 bpy
.types
.Light
.SR_data
= \
3009 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
3010 bpy
.types
.Bone
.SR_data
= \
3011 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
3012 bpy
.types
.Mesh
.SR_data
= \
3013 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
3014 bpy
.types
.Material
.SR_data
= \
3015 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
3017 global cv_view_draw_handler
3018 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
3019 cv_draw
,(),'WINDOW','POST_VIEW')
3025 bpy
.utils
.unregister_class(c
)
3027 global cv_view_draw_handler
3028 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
3031 # ---------------------------------------------------------------------------- #
3035 # ---------------------------------------------------------------------------- #
3037 # Transliteration of: #
3038 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
3040 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
3041 # SPDX-License-Identifier: MIT #
3042 # QOI - The "Quite OK Image" format for fast, lossless image compression #
3044 # ---------------------------------------------------------------------------- #
3046 class qoi_rgba_t(Structure
):
3049 _fields_
= [("r",c_uint8
),
3055 QOI_OP_INDEX
= 0x00 # 00xxxxxx
3056 QOI_OP_DIFF
= 0x40 # 01xxxxxx
3057 QOI_OP_LUMA
= 0x80 # 10xxxxxx
3058 QOI_OP_RUN
= 0xc0 # 11xxxxxx
3059 QOI_OP_RGB
= 0xfe # 11111110
3060 QOI_OP_RGBA
= 0xff # 11111111
3062 QOI_MASK_2
= 0xc0 # 11000000
3064 def qoi_colour_hash( c
):
3066 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
3071 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
3076 return bytearray([ (0xff000000 & v
) >> 24, \
3077 (0x00ff0000 & v
) >> 16, \
3078 (0x0000ff00 & v
) >> 8, \
3082 def qoi_encode( img
):
3086 print(F
"{' ':<30}",end
='\r')
3087 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
3089 index
= [ qoi_rgba_t() for _
in range(64) ]
3093 data
.extend( bytearray(c_uint32(0x66696f71)) )
3094 data
.extend( qoi_32bit( img
.size
[0] ) )
3095 data
.extend( qoi_32bit( img
.size
[1] ) )
3096 data
.extend( bytearray(c_uint8(4)) )
3097 data
.extend( bytearray(c_uint8(0)) )
3100 px_prev
= qoi_rgba_t()
3101 px_prev
.r
= c_uint8(0)
3102 px_prev
.g
= c_uint8(0)
3103 px_prev
.b
= c_uint8(0)
3104 px_prev
.a
= c_uint8(255)
3112 px_len
= img
.size
[0] * img
.size
[1]
3113 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
3115 for px_pos
in range( px_len
): #{
3116 idx
= px_pos
* img
.channels
3119 px
.r
= paxels
[idx
+min(0,nc
)]
3120 px
.g
= paxels
[idx
+min(1,nc
)]
3121 px
.b
= paxels
[idx
+min(2,nc
)]
3122 px
.a
= paxels
[idx
+min(3,nc
)]
3124 if qoi_eq( px
, px_prev
): #{
3127 if (run
== 62) or (px_pos
== px_len
-1): #{
3128 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
3134 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
3138 index_pos
= qoi_colour_hash(px
) % 64
3140 if qoi_eq( index
[index_pos
], px
): #{
3141 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
3144 index
[ index_pos
].r
= px
.r
3145 index
[ index_pos
].g
= px
.g
3146 index
[ index_pos
].b
= px
.b
3147 index
[ index_pos
].a
= px
.a
3149 if px
.a
== px_prev
.a
: #{
3150 vr
= int(px
.r
) - int(px_prev
.r
)
3151 vg
= int(px
.g
) - int(px_prev
.g
)
3152 vb
= int(px
.b
) - int(px_prev
.b
)
3157 if (vr
> -3) and (vr
< 2) and\
3158 (vg
> -3) and (vg
< 2) and\
3159 (vb
> -3) and (vb
< 2):
3161 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
3162 data
.extend( bytearray( c_uint8(op
) ))
3164 elif (vg_r
> -9) and (vg_r
< 8) and\
3165 (vg
> -33) and (vg
< 32 ) and\
3166 (vg_b
> -9) and (vg_b
< 8):
3168 op
= QOI_OP_LUMA |
(vg
+32)
3169 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
3170 data
.extend( bytearray( c_uint8(op
) ) )
3171 data
.extend( bytearray( c_uint8(delta
) ))
3174 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
3175 data
.extend( bytearray( c_uint8(px
.r
) ))
3176 data
.extend( bytearray( c_uint8(px
.g
) ))
3177 data
.extend( bytearray( c_uint8(px
.b
) ))
3181 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
3182 data
.extend( bytearray( c_uint8(px
.r
) ))
3183 data
.extend( bytearray( c_uint8(px
.g
) ))
3184 data
.extend( bytearray( c_uint8(px
.b
) ))
3185 data
.extend( bytearray( c_uint8(px
.a
) ))
3198 data
.extend( bytearray( c_uint8(0) ))
3199 data
.extend( bytearray( c_uint8(1) ))
3200 bytearray_align_to( data
, 16, b
'\x00' )