1 import bpy
, blf
, math
, gpu
, os
, time
5 from mathutils
import *
6 from gpu_extras
.batch
import batch_for_shader
7 from bpy_extras
import mesh_utils
8 from bpy_extras
import view3d_utils
11 "name":"Skaterift .mdl exporter",
12 "author": "Harry Godden (hgn)",
19 "category":"Import/Export",
23 ('none', 'None', '', 0 ),
24 ('ent_gate', 'Gate', '', 1 ),
25 ('ent_spawn', 'Spawn Point', '', 2 ),
26 ('ent_route_node', 'Routing Path', '', 3 ),
27 ('ent_route', 'Skate Course', '', 4 ),
28 ('ent_water', 'Water Surface', '', 5 ),
29 ('ent_volume', 'Volume/Trigger', '', 6 ),
30 ('ent_audio', 'Audio', '', 7 ),
31 ('ent_marker', 'Marker', '', 8 ),
32 ('ent_font', 'Font', '', 9 ),
33 ('ent_font_variant', 'Font:Variant', '', 10 ),
34 ('ent_traffic', 'Traffic Model', '', 11 ),
35 ('ent_skateshop', 'Skate Shop', '', 12 ),
36 ('ent_camera', 'Camera', '', 13 ),
37 ('ent_swspreview', 'Workshop Preview', '', 14 ),
38 ('ent_menuitem', 'Menu Item', '', 15 ),
39 ('ent_worldinfo', 'World Info', '', 16 ),
40 ('ent_ccmd', 'CCmd', '', 17 ),
41 ('ent_objective', 'Objective', '', 18 ),
42 ('ent_challenge', 'Challenge', '', 19 ),
43 ('ent_relay', 'Relay', '', 20 ),
44 ('ent_miniworld', 'Mini World', '', 22 ),
45 ('ent_prop', 'Prop', '', 23 ),
46 ('ent_list', 'Entity List', '', 24 ),
47 ('ent_region', 'Region', '', 25 ),
48 ('ent_glider', 'Glider', '', 26 ),
49 ('ent_npc', 'npc', '', 27 )
53 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
54 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
55 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
58 def get_entity_enum_id( alias
):
60 for et
in sr_entity_list
:#{
66 if alias
== 'ent_cubemap': return 21
71 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
72 #{ # the normals and uvs to i16s. Not an
73 _pack_
= 1 # real issue, yet.
74 _fields_
= [("co",c_float
*3),
78 ("weights",c_uint16
*4),
82 class mdl_transform(Structure
):
84 _fields_
= [("co",c_float
*3),
89 class mdl_submesh(Structure
):
91 _fields_
= [("indice_start",c_uint32
),
92 ("indice_count",c_uint32
),
93 ("vertex_start",c_uint32
),
94 ("vertex_count",c_uint32
),
95 ("bbx",(c_float
*3)*2),
96 ("material_id",c_uint16
), # index into the material array
101 # =================================================
103 class mdl_material(Structure
):
105 _fields_
= [("pstr_name",c_uint32
),
107 ("shader_data",c_uint32
),
108 ("shader_data_len",c_uint32
),
110 ("surface_prop",c_uint32
)]
112 # ("colour",c_float*4), (old) v105
113 # ("colour1",c_float*4),
114 # ("tex_diffuse",c_uint32),
115 # ("tex_none0",c_uint32),
116 # ("tex_none1",c_uint32)]
119 class mdl_bone(Structure
):
121 _fields_
= [("co",c_float
*3),("end",c_float
*3),
123 ("collider",c_uint32
),
124 ("ik_target",c_uint32
),
125 ("ik_pole",c_uint32
),
127 ("pstr_name",c_uint32
),
128 ("hitbox",(c_float
*3)*2),
129 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
133 class mdl_armature(Structure
):
135 _fields_
= [("transform",mdl_transform
),
136 ("bone_start",c_uint32
),
137 ("bone_count",c_uint32
),
138 ("anim_start",c_uint32
),
139 ("anim_count",c_uint32
)]
142 class mdl_animation(Structure
):
144 _fields_
= [("pstr_name",c_uint32
),
147 ("keyframe_start",c_uint32
)]
150 class mdl_mesh(Structure
):
152 _fields_
= [("transform",mdl_transform
),
153 ("submesh_start",c_uint32
),
154 ("submesh_count",c_uint32
),
155 ("pstr_name",c_uint32
),
156 ("entity_id",c_uint32
),
157 ("armature_id",c_uint32
)]
160 class mdl_file(Structure
):
162 _fields_
= [("path",c_uint32
),
163 ("pack_offset",c_uint32
),
164 ("pack_size",c_uint32
)]
167 class mdl_texture(Structure
):
169 _fields_
= [("file",mdl_file
),
173 class mdl_array(Structure
):
175 _fields_
= [("file_offset",c_uint32
),
176 ("item_count",c_uint32
),
177 ("item_size",c_uint32
),
181 class mdl_header(Structure
):
183 _fields_
= [("version",c_uint32
),
184 ("arrays",mdl_array
)]
187 class ent_spawn(Structure
):
189 _fields_
= [("transform",mdl_transform
),
190 ("pstr_name",c_uint32
)]
193 class ent_light(Structure
):
195 _fields_
= [("transform",mdl_transform
),
196 ("daytime",c_uint32
),
198 ("colour",c_float
*4),
201 ("inverse_world",(c_float
*3)*4), # Runtime
202 ("angle_sin_cos",(c_float
*2))] # Runtime
205 class version_refcount_union(Union
):
207 _fields_
= [("timing_version",c_uint32
),
208 ("ref_count",c_uint8
)]
211 class ent_gate(Structure
):
213 _fields_
= [("flags",c_uint32
),
214 ("target", c_uint32
),
216 ("dimensions", c_float
*3),
217 ("co", (c_float
*3)*2),
218 ("q", (c_float
*4)*2),
219 ("to_world",(c_float
*3)*4),
220 ("transport",(c_float
*3)*4),
221 ("_anonymous_union",version_refcount_union
),
222 ("timing_time",c_double
),
223 ("routes",c_uint16
*4),
224 ("route_count",c_uint8
),
225 ("submesh_start",c_uint32
), # v102+
226 ("submesh_count",c_uint32
), # v102+ (can be 0)
228 sr_functions
= { 0: 'unlock' }
231 class ent_route_node(Structure
):
233 _fields_
= [("co",c_float
*3),
234 ("ref_count",c_uint8
),
235 ("ref_total",c_uint8
)]
238 class ent_path_index(Structure
):
240 _fields_
= [("index",c_uint16
)]
243 class vg_audio_clip(Structure
):
245 _fields_
= [("path",c_uint64
),
251 class union_file_audio_clip(Union
):
253 _fields_
= [("file",mdl_file
),
254 ("reserved",vg_audio_clip
)]
257 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
258 # but then again, too late to change because compat.
259 class ent_audio_clip(Structure
):
261 _fields_
= [("_anon",union_file_audio_clip
),
262 ("probability",c_float
)]
265 class ent_list(Structure
):
267 _fields_
= [("entity_ref_start",c_uint32
),
268 ("entity_ref_count",c_uint32
)]
272 class file_entity_ref(Structure
):
274 _fields_
= [("index",c_uint32
)]
277 class ent_checkpoint(Structure
):
279 _fields_
= [("gate_index",c_uint16
),
280 ("path_start",c_uint16
),
281 ("path_count",c_uint16
)]
284 class ent_route(Structure
):
286 _fields_
= [("transform",mdl_transform
),
287 ("pstr_name",c_uint32
),
288 ("checkpoints_start",c_uint16
),
289 ("checkpoints_count",c_uint16
),
290 ("colour",c_float
*4),
291 ("active",c_uint32
), #runtime
293 ("board_transform",(c_float
*3)*4),
295 ("latest_pass",c_double
),
296 ("id_camera",c_uint32
), # v103+
299 sr_functions
= { 0: 'view' }
302 class ent_list(Structure
):#{
303 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
306 class ent_glider(Structure
):#{
307 _fields_
= [("transform",mdl_transform
),
309 ("cooldown",c_float
)]
310 sr_functions
= { 0: 'unlock',
314 class ent_npc(Structure
):#{
315 _fields_
= [("transform",mdl_transform
),
317 ("context",c_uint32
),
319 sr_functions
= { 0: 'proximity', -1: 'leave' }
322 class ent_water(Structure
):
324 _fields_
= [("transform",mdl_transform
),
325 ("max_dist",c_float
),
326 ("reserved0",c_uint32
),
327 ("reserved1",c_uint32
)]
330 class volume_trigger(Structure
):
332 _fields_
= [("event",c_uint32
),
333 ("event_leave",c_int32
)]
336 class volume_particles(Structure
):
338 _fields_
= [("blank",c_uint32
),
342 class volume_union(Union
):
344 _fields_
= [("trigger",volume_trigger
),
345 ("particles",volume_particles
)]
348 class ent_volume(Structure
):
350 _fields_
= [("transform",mdl_transform
),
351 ("to_world",(c_float
*3)*4),
352 ("to_local",(c_float
*3)*4),
355 ("_anon",volume_union
)]
358 class ent_audio(Structure
):
360 _fields_
= [("transform",mdl_transform
),
362 ("clip_start",c_uint32
),
363 ("clip_count",c_uint32
),
365 ("crossfade",c_float
),
366 ("channel_behaviour",c_uint32
),
368 ("probability_curve",c_uint32
),
369 ("max_channels",c_uint32
)]
372 class ent_marker(Structure
):
374 _fields_
= [("transform",mdl_transform
),
378 class ent_glyph(Structure
):
380 _fields_
= [("size",c_float
*2),
381 ("indice_start",c_uint32
),
382 ("indice_count",c_uint32
)]
385 class ent_font_variant(Structure
):
387 _fields_
= [("name",c_uint32
),
388 ("material_id",c_uint32
)]
391 class ent_font(Structure
):
393 _fields_
= [("alias",c_uint32
),
394 ("variant_start",c_uint32
),
395 ("variant_count",c_uint32
),
396 ("glyph_start",c_uint32
),
397 ("glyph_count",c_uint32
),
398 ("glyph_utf32_base",c_uint32
)]
401 class ent_traffic(Structure
):
403 _fields_
= [("transform",mdl_transform
),
404 ("submesh_start",c_uint32
),
405 ("submesh_count",c_uint32
),
406 ("start_node",c_uint32
),
407 ("node_count",c_uint32
),
414 # ---------------------------------------------------------------
415 class ent_skateshop_characters(Structure
):
417 _fields_
= [("id_display",c_uint32
),
418 ("id_info",c_uint32
)]
420 class ent_skateshop_boards(Structure
):
422 _fields_
= [("id_display",c_uint32
),
423 ("id_info",c_uint32
),
424 ("id_rack",c_uint32
)]
426 class ent_skateshop_worlds(Structure
):
428 _fields_
= [("id_display",c_uint32
),
429 ("id_info",c_uint32
)]
431 class ent_skateshop_server(Structure
):
433 _fields_
= [("id_lever",c_uint32
)]
435 class ent_skateshop_anon_union(Union
):
437 _fields_
= [("boards",ent_skateshop_boards
),
438 ("character",ent_skateshop_characters
),
439 ("worlds",ent_skateshop_worlds
),
440 ("server",ent_skateshop_server
)]
442 class ent_skateshop(Structure
):
444 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
445 ("id_camera",c_uint32
),
446 ("_anonymous_union",ent_skateshop_anon_union
)]
448 sr_functions
= { 0: 'trigger' }
451 class ent_swspreview(Structure
):
453 _fields_
= [("id_camera",c_uint32
),
454 ("id_display",c_uint32
),
455 ("id_display1",c_uint32
)]
459 # -----------------------------------------------------------------
460 class ent_menuitem_visual(Structure
):
462 _fields_
= [("pstr_name",c_uint32
)]
464 class ent_menuitem_slider(Structure
):
466 _fields_
= [("id_min",c_uint32
),
468 ("id_handle",c_uint32
),
469 ("pstr_data",c_uint32
)]
471 class ent_menuitem_button(Structure
):
473 _fields_
= [("pstr",c_uint32
),
474 ("stack_behaviour",c_uint32
)]
476 class ent_menuitem_checkmark(Structure
):
478 _fields_
= [("id_check",c_uint32
),
479 ("pstr_data",c_uint32
),
480 ("offset",c_float
*3)]
482 class ent_menuitem_page(Structure
):
484 _fields_
= [("pstr_name",c_uint32
),
485 ("id_entrypoint",c_uint32
),
486 ("id_viewpoint",c_uint32
)]
488 class ent_menuitem_binding(Structure
):
490 _fields_
= [("pstr_bind",c_uint32
),
491 ("font_variant",c_uint32
)]
493 class ent_menuitem_anon_union(Union
):
495 _fields_
= [("slider",ent_menuitem_slider
),
496 ("button",ent_menuitem_button
),
497 ("checkmark",ent_menuitem_checkmark
),
498 ("page",ent_menuitem_page
),
499 ("visual",ent_menuitem_visual
),
500 ("binding",ent_menuitem_binding
)]
502 class ent_menuitem(Structure
):
504 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
505 ("id_links",c_uint32
*4),
506 ("factive",c_float
), ("fvisible",c_float
),
507 #-- TODO: Refactor this into a simple mesh structure
508 ("transform",mdl_transform
),
509 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
512 ("_anonymous_union", ent_menuitem_anon_union
)]
515 class ent_camera(Structure
):
517 _fields_
= [("transform",mdl_transform
),
521 class ent_worldinfo(Structure
):
523 _fields_
= [("pstr_name",c_uint32
),
524 ("pstr_author",c_uint32
), # unused
525 ("pstr_desc",c_uint32
), # unused
526 ("timezone",c_float
),
527 ("pstr_skybox",c_uint32
),
531 class ent_ccmd(Structure
):
533 _fields_
= [("pstr_command",c_uint32
)]
536 class ent_objective(Structure
):#{
537 _fields_
= [("transform",mdl_transform
),
538 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
540 ("id_next",c_uint32
),
541 ("filter",c_uint32
),("filter2",c_uint32
),
543 ("win_event",c_int32
),
544 ("time_limit",c_float
)]
546 sr_functions
= { 0: 'trigger',
551 class ent_challenge(Structure
):#{
552 _fields_
= [("transform",mdl_transform
),
553 ("pstr_alias",c_uint32
),
556 ("target_event",c_int32
),
558 ("reset_event",c_int32
),
561 ("status",c_uint32
)] #runtime
562 sr_functions
= { 0: 'unlock',
566 class ent_region(Structure
):#{
567 _fields_
= [("transform",mdl_transform
),
568 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
569 ("pstr_title",c_uint32
),
571 ("zone_volume",c_uint32
),
573 ("target0",c_uint32
*2)]
574 sr_functions
= { 0: 'enter', 1: 'leave' }
577 class ent_relay(Structure
):#{
578 _fields_
= [("targets",(c_uint32
*2)*4),
579 ("targets_events",c_int32
*4)]
580 sr_functions
= { 0: 'trigger' }
583 class ent_cubemap(Structure
):#{
584 _fields_
= [("co",c_float
*3),
585 ("resolution",c_uint32
), #placeholder
586 ("live",c_uint32
), #placeholder
587 ("texture_id",c_uint32
), #engine
588 ("framebuffer_id",c_uint32
),#engine
589 ("renderbuffer_id",c_uint32
),#engine
590 ("placeholder",c_uint32
*2)]
593 print( sizeof(ent_cubemap
) )
595 class ent_miniworld(Structure
):#{
596 _fields_
= [("transform",mdl_transform
),
597 ("pstr_world",c_uint32
),
601 sr_functions
= { 0: 'zone', 1: 'leave' }
604 class ent_prop(Structure
):#{
605 _fields_
= [("transform",mdl_transform
),
606 ("submesh_start",c_uint32
),
607 ("submesh_count",c_uint32
),
609 ("pstr_alias",c_uint32
)]
612 def obj_ent_type( obj
):
614 if obj
.type == 'ARMATURE': return 'mdl_armature'
615 elif obj
.type == 'LIGHT': return 'ent_light'
616 elif obj
.type == 'CAMERA': return 'ent_camera'
617 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
619 else: return obj
.SR_data
.ent_type
622 def sr_filter_ent_type( obj
, ent_types
):
624 if obj
== bpy
.context
.active_object
: return False
626 for c0
in obj
.users_collection
:#{
627 for c1
in bpy
.context
.active_object
.users_collection
:#{
629 return obj_ent_type( obj
) in ent_types
637 def v4_dot( a
, b
):#{
638 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
641 def q_identity( q
):#{
648 def q_normalize( q
):#{
650 if( l2
< 0.00001 ):#{
654 s
= 1.0/math
.sqrt(l2
)
662 def compile_obj_transform( obj
, transform
):
664 co
= obj
.matrix_world
@ Vector((0,0,0))
666 # This was changed from matrix_local on 09.05.23
667 q
= obj
.matrix_world
.to_quaternion()
673 transform
.co
[0] = co
[0]
674 transform
.co
[1] = co
[2]
675 transform
.co
[2] = -co
[1]
676 transform
.q
[0] = q
[1]
677 transform
.q
[1] = q
[3]
678 transform
.q
[2] = -q
[2]
679 transform
.q
[3] = q
[0]
680 transform
.s
[0] = s
[0]
681 transform
.s
[1] = s
[2]
682 transform
.s
[2] = s
[1]
685 def int_align_to( v
, align
):
687 while(v
%align
)!=0: v
+= 1
691 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
693 while (len(buffer) % align
) != 0: buffer.extend(w
)
697 def bytearray_print_hex( s
, w
=16 ):
699 for r
in range((len(s
)+(w
-1))//w
):#{
701 i1
=min((r
+1)*w
,len(s
))
702 print( F
'{r*w:06x}| \x1B[31m', end
='')
703 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
704 print( "\x1B[0m", end
='')
705 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
709 def sr_compile_string( s
):
711 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
713 index
= len( sr_compile
.string_data
)
714 sr_compile
.string_cache
[s
] = index
715 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
716 sr_compile
.string_data
.extend( s
.encode('utf-8') )
717 sr_compile
.string_data
.extend( b
'\0' )
719 bytearray_align_to( sr_compile
.string_data
, 4 )
723 def material_tex_image(v
):
733 cxr_graph_mapping
= \
735 # Default shader setup
742 "image": "tex_diffuse"
746 "A": material_tex_image("tex_diffuse"),
747 "B": material_tex_image("tex_decal")
754 "Color": material_tex_image("tex_normal")
760 "Color": material_tex_image("tex_diffuse")
764 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
766 def material_info(mat
):
770 # Using the cxr_graph_mapping as a reference, go through the shader
771 # graph and gather all $props from it.
773 def _graph_read( node_def
, node
=None, depth
=0 ):#{
780 _graph_read
.extracted
= []
783 for node_idname
in node_def
:#{
784 for n
in mat
.node_tree
.nodes
:#{
785 if n
.name
== node_idname
:#{
786 node_def
= node_def
[node_idname
]
796 for link
in node_def
:#{
797 link_def
= node_def
[link
]
799 if isinstance( link_def
, dict ):#{
801 for x
in node
.inputs
:#{
802 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
810 if node_link
and node_link
.is_linked
:#{
811 # look for definitions for the connected node type
813 from_node
= node_link
.links
[0].from_node
815 node_name
= from_node
.name
.split('.')[0]
816 if node_name
in link_def
:#{
817 from_node_def
= link_def
[ node_name
]
819 _graph_read( from_node_def
, from_node
, depth
+1 )
823 if "default" in link_def
:#{
824 prop
= link_def
['default']
825 info
[prop
] = node_link
.default_value
831 info
[prop
] = getattr( node
, link
)
836 _graph_read( cxr_graph_mapping
)
842 decoded
= bytearray()
843 for i
in range(len(s
)//2):#{
844 c
= (ord(s
[i
*2+0])-0x41)
845 c |
= (ord(s
[i
*2+1])-0x41)<<4
846 decoded
.extend(bytearray(c_uint8(c
))) #??
851 def sr_pack_file( file, path
, data
):
853 file.path
= sr_compile_string( path
)
854 file.pack_offset
= len( sr_compile
.pack_data
)
855 file.pack_size
= len( data
)
857 sr_compile
.pack_data
.extend( data
)
858 bytearray_align_to( sr_compile
.pack_data
, 16 )
861 def sr_compile_texture( img
):
866 name
= os
.path
.splitext( img
.name
)[0]
868 if name
in sr_compile
.texture_cache
:
869 return sr_compile
.texture_cache
[name
]
871 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
876 if sr_compile
.pack_textures
:#{
877 filedata
= qoi_encode( img
)
878 sr_pack_file( tex
.file, name
, filedata
)
881 sr_compile
.texture_cache
[name
] = texture_index
882 sr_compile
.texture_data
.extend( bytearray(tex
) )
886 def sr_compile_material( mat
):
890 if mat
.name
in sr_compile
.material_cache
:
891 return sr_compile
.material_cache
[mat
.name
]
893 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
894 sr_compile
.material_cache
[mat
.name
] = index
897 m
.pstr_name
= sr_compile_string( mat
.name
)
900 if mat
.SR_data
.collision
:#{
901 flags |
= 0x2 # collision flag
902 if (mat
.SR_data
.shader
!= 'invisible') and \
903 (mat
.SR_data
.shader
!= 'boundary'):#{
904 if mat
.SR_data
.skate_surface
: flags |
= 0x1
905 if mat
.SR_data
.grow_grass
: flags |
= 0x4
906 if mat
.SR_data
.grind_surface
: flags |
= 0x8
907 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
909 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
910 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
911 if mat
.SR_data
.shader
== 'walking': flags |
= (0x10|
0x80)
916 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
917 inf
= material_info( mat
)
920 buf
= (c_uint8
* 512)()
921 sr_lib
.vg_msg_init( pointer(msg
), buf
, 512 )
924 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
925 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
926 if mat
.SR_data
.shader
== 'foliage': m
.shader
= 10
927 if mat
.SR_data
.shader
== 'terrain_blend':
930 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
931 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
932 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
934 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
935 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
937 if mat
.SR_data
.shader
== 'vertex_blend':
940 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
941 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
943 if mat
.SR_data
.shader
== 'water':
946 #m.colour[0] = pow( mat.SR_data.shore_colour[0], 1.0/2.2 )
947 #m.colour[1] = pow( mat.SR_data.shore_colour[1], 1.0/2.2 )
948 #m.colour[2] = pow( mat.SR_data.shore_colour[2], 1.0/2.2 )
950 #m.colour1[0] = pow( mat.SR_data.ocean_colour[0], 1.0/2.2 )
951 #m.colour1[1] = pow( mat.SR_data.ocean_colour[1], 1.0/2.2 )
952 #m.colour1[2] = pow( mat.SR_data.ocean_colour[2], 1.0/2.2 )
956 fog_scale
= c_float()
957 sr_lib
.vg_msg_wkvnum( byref(msg
), "shore_colour".encode(), k_vg_msg_f32
, 4, col
)
958 sr_lib
.vg_msg_wkvnum( byref(msg
), "deep_colour".encode(), k_vg_msg_f32
, 4, col
)
959 sr_lib
.vg_msg_wkvnum( byref(msg
), "fog_scale".encode(), k_vg_msg_f32
, 1, byref(fog_scale
) )
961 if mat
.SR_data
.shader
== 'invisible':
965 if mat
.SR_data
.shader
== 'boundary':
969 if mat
.SR_data
.shader
== 'fxglow':
973 if mat
.SR_data
.shader
== 'cubemap':
976 m
.tex_none0
= sr_entity_id( mat
.SR_data
.cubemap
)
978 m
.colour
[0] = pow( mat
.SR_data
.tint
[0], 1.0/2.2 )
979 m
.colour
[1] = pow( mat
.SR_data
.tint
[1], 1.0/2.2 )
980 m
.colour
[2] = pow( mat
.SR_data
.tint
[2], 1.0/2.2 )
981 m
.colour
[3] = pow( mat
.SR_data
.tint
[3], 1.0/2.2 )
983 if mat
.SR_data
.shader
== 'walking':
988 if mat
.SR_data
.shader
in ['standard', 'standard_cutout', 'terrain_blend', \
989 'vertex_blend', 'fxglow', 'cubemap', \
992 if 'tex_diffuse' in inf
:
993 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
996 if mat
.SR_data
.tex_diffuse_rt
>= 0:
998 m
.tex_diffuse
= 0x80000000 | mat
.SR_data
.tex_diffuse_rt
1001 sr_lib
.vg_msg_print( byref(msg
), msg
.cur
.co
)
1003 sr_compile
.material_data
.extend( bytearray(m
) )
1007 def sr_armature_bones( armature
):
1009 def _recurse_bone( b
):
1012 for c
in b
.children
: yield from _recurse_bone( c
)
1015 for b
in armature
.data
.bones
:
1017 yield from _recurse_bone( b
)
1020 def sr_entity_id( obj
):#{
1021 if not obj
: return 0
1023 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
1024 index
= sr_compile
.entity_ids
[ obj
.name
]
1026 return (tipo
&0xffff)<<16 |
(index
&0xffff)
1029 # Returns submesh_start,count and armature_id
1030 def sr_compile_mesh_internal( obj
):
1032 can_use_cache
= True
1039 for mod
in obj
.modifiers
:#{
1040 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
1041 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
1042 mod
.type == 'ARRAY':
1044 can_use_cache
= False
1047 if mod
.type == 'ARMATURE': #{
1048 armature
= mod
.object
1049 rig_weight_groups
= \
1050 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
1051 armature_id
= sr_compile
.entity_ids
[armature
.name
]
1053 POSE_OR_REST_CACHE
= armature
.data
.pose_position
1054 armature
.data
.pose_position
= 'REST'
1058 # Check the cache first
1060 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
1061 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
1062 submesh_start
= ref
[0]
1063 submesh_count
= ref
[1]
1064 return (submesh_start
,submesh_count
,armature_id
)
1067 # Compile a whole new mesh
1069 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
1072 dgraph
= bpy
.context
.evaluated_depsgraph_get()
1073 data
= obj
.evaluated_get(dgraph
).data
1074 data
.calc_loop_triangles()
1075 data
.calc_normals_split()
1077 # Mesh is split into submeshes based on their material
1079 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
1080 for material_id
, mat
in enumerate(mat_list
): #{
1084 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1085 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1088 sm
.material_id
= sr_compile_material( mat
)
1090 INF
=99999999.99999999
1091 for i
in range(3):#{
1096 # Keep a reference to very very very similar vertices
1097 # i have no idea how to speed it up.
1099 vertex_reference
= {}
1101 # Write the vertex / indice data
1103 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
1104 if tri
.material_index
!= material_id
: continue
1106 for j
in range(3):#{
1107 vert
= data
.vertices
[tri
.vertices
[j
]]
1109 vi
= data
.loops
[li
].vertex_index
1111 # Gather vertex information
1114 norm
= data
.loops
[li
].normal
1116 colour
= (255,255,255,255)
1123 uv
= data
.uv_layers
.active
.data
[li
].uv
1127 if data
.vertex_colors
:#{
1128 colour
= data
.vertex_colors
.active
.data
[li
].color
1129 colour
= (int(colour
[0]*255.0),\
1130 int(colour
[1]*255.0),\
1131 int(colour
[2]*255.0),\
1132 int(colour
[3]*255.0))
1135 # Weight groups: truncates to the 3 with the most influence. The
1136 # fourth bone ID is never used by the shader so it
1140 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
1141 if obj
.vertex_groups
[_
.group
].name
in \
1144 weight_groups
= sorted( src_groups
, key
= \
1145 lambda a
: a
.weight
, reverse
=True )
1147 for ml
in range(3):#{
1148 if len(weight_groups
) > ml
:#{
1149 g
= weight_groups
[ml
]
1150 name
= obj
.vertex_groups
[g
.group
].name
1152 weights
[ml
] = weight
1153 groups
[ml
] = rig_weight_groups
.index(name
)
1158 if len(weight_groups
) > 0:#{
1159 inv_norm
= (1.0/tot
) * 65535.0
1160 for ml
in range(3):#{
1161 weights
[ml
] = int( weights
[ml
] * inv_norm
)
1162 weights
[ml
] = min( weights
[ml
], 65535 )
1163 weights
[ml
] = max( weights
[ml
], 0 )
1168 li1
= tri
.loops
[(j
+1)%3]
1169 vi1
= data
.loops
[li1
].vertex_index
1170 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
1172 if e0
.use_freestyle_mark
and \
1173 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
1174 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
1180 TOLERENCE
= float(10**4)
1181 key
= (int(co
[0]*TOLERENCE
+0.5),
1182 int(co
[1]*TOLERENCE
+0.5),
1183 int(co
[2]*TOLERENCE
+0.5),
1184 int(norm
[0]*TOLERENCE
+0.5),
1185 int(norm
[1]*TOLERENCE
+0.5),
1186 int(norm
[2]*TOLERENCE
+0.5),
1187 int(uv
[0]*TOLERENCE
+0.5),
1188 int(uv
[1]*TOLERENCE
+0.5),
1189 colour
[0], # these guys are already quantized
1202 if key
in vertex_reference
:
1203 index
= vertex_reference
[key
]
1205 index
= bytearray(c_uint32(sm
.vertex_count
))
1208 vertex_reference
[key
] = index
1215 v
.norm
[2] = -norm
[1]
1218 v
.colour
[0] = colour
[0]
1219 v
.colour
[1] = colour
[1]
1220 v
.colour
[2] = colour
[2]
1221 v
.colour
[3] = colour
[3]
1222 v
.weights
[0] = weights
[0]
1223 v
.weights
[1] = weights
[1]
1224 v
.weights
[2] = weights
[2]
1225 v
.weights
[3] = weights
[3]
1226 v
.groups
[0] = groups
[0]
1227 v
.groups
[1] = groups
[1]
1228 v
.groups
[2] = groups
[2]
1229 v
.groups
[3] = groups
[3]
1231 for i
in range(3):#{
1232 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1233 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1236 sr_compile
.vertex_data
.extend(bytearray(v
))
1239 sm
.indice_count
+= 1
1240 sr_compile
.indice_data
.extend( index
)
1244 # Make sure bounding box isn't -inf -> inf if no vertices
1246 if sm
.vertex_count
== 0:
1251 # Add submesh to encoder
1253 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1258 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1261 # Save a reference to this mesh since we want to reuse the submesh indices
1263 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1264 return (submesh_start
,submesh_count
,armature_id
)
1267 def sr_compile_mesh( obj
):
1270 compile_obj_transform(obj
, node
.transform
)
1271 node
.pstr_name
= sr_compile_string(obj
.name
)
1272 ent_type
= obj_ent_type( obj
)
1276 if ent_type
!= 'none':#{
1277 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1278 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1279 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1282 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1283 sr_compile_mesh_internal( obj
)
1285 sr_compile
.mesh_data
.extend(bytearray(node
))
1288 def sr_compile_fonts( collection
):
1290 print( F
"[SR] Compiling fonts" )
1295 for obj
in collection
.all_objects
:#{
1296 if obj_ent_type(obj
) != 'ent_font': continue
1298 data
= obj
.SR_data
.ent_font
[0]
1301 font
.alias
= sr_compile_string( data
.alias
)
1302 font
.variant_start
= variant_count
1303 font
.variant_count
= 0
1304 font
.glyph_start
= glyph_count
1306 glyph_base
= data
.glyphs
[0].utf32
1307 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1309 font
.glyph_utf32_base
= glyph_base
1310 font
.glyph_count
= glyph_range
1312 for i
in range(len(data
.variants
)):#{
1313 data_var
= data
.variants
[i
]
1314 if not data_var
.mesh
: continue
1316 mesh
= data_var
.mesh
.data
1318 variant
= ent_font_variant()
1319 variant
.name
= sr_compile_string( data_var
.tipo
)
1321 # fonts (variants) only support one material each
1323 if len(mesh
.materials
) != 0:
1324 mat
= mesh
.materials
[0]
1325 variant
.material_id
= sr_compile_material( mat
)
1327 font
.variant_count
+= 1
1329 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1330 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1332 for j
in range(len(islands
)):#{
1333 for tri
in islands
[j
]:#{
1334 centroids
[j
].x
+= tri
.center
[0]
1335 centroids
[j
].y
+= tri
.center
[2]
1338 centroids
[j
] /= len(islands
[j
])
1341 for j
in range(glyph_range
):#{
1342 data_glyph
= data
.glyphs
[j
]
1344 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1345 glyph
.indice_count
= 0
1346 glyph
.size
[0] = data_glyph
.bounds
[2]
1347 glyph
.size
[1] = data_glyph
.bounds
[3]
1349 vertex_reference
= {}
1351 for k
in range(len(islands
)):#{
1352 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1353 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1354 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1355 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1360 for l
in range(len(islands
[k
])):#{
1362 for m
in range(3):#{
1363 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1365 vi
= mesh
.loops
[li
].vertex_index
1367 # Gather vertex information
1369 co
= [vert
.co
[_
] for _
in range(3)]
1370 co
[0] -= data_glyph
.bounds
[0]
1371 co
[2] -= data_glyph
.bounds
[1]
1372 norm
= mesh
.loops
[li
].normal
1374 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1376 TOLERENCE
= float(10**4)
1377 key
= (int(co
[0]*TOLERENCE
+0.5),
1378 int(co
[1]*TOLERENCE
+0.5),
1379 int(co
[2]*TOLERENCE
+0.5),
1380 int(norm
[0]*TOLERENCE
+0.5),
1381 int(norm
[1]*TOLERENCE
+0.5),
1382 int(norm
[2]*TOLERENCE
+0.5),
1383 int(uv
[0]*TOLERENCE
+0.5),
1384 int(uv
[1]*TOLERENCE
+0.5))
1386 if key
in vertex_reference
:
1387 index
= vertex_reference
[key
]
1389 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1390 index
= bytearray(c_uint32(vindex
))
1391 vertex_reference
[key
] = index
1398 v
.norm
[2] = -norm
[1]
1402 sr_compile
.vertex_data
.extend(bytearray(v
))
1405 glyph
.indice_count
+= 1
1406 sr_compile
.indice_data
.extend( index
)
1410 sr_ent_push( glyph
)
1412 sr_ent_push( variant
)
1418 def sr_compile_menus( collection
):
1420 print( "[SR1] Compiling menus" )
1423 for obj
in collection
.all_objects
:#{
1424 if obj_ent_type(obj
) != 'ent_menuitem': continue
1425 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1427 bitmask
= 0x00000000
1429 for col
in obj
.users_collection
:#{
1431 if name
not in groups
: groups
.append( name
)
1432 bitmask |
= (0x1 << groups
.index(name
))
1435 item
= ent_menuitem()
1436 item
.type = int( obj_data
.tipo
)
1437 item
.groups
= bitmask
1439 compile_obj_transform( obj
, item
.transform
)
1440 if obj
.type == 'MESH':#{
1441 item
.submesh_start
, item
.submesh_count
, _
= \
1442 sr_compile_mesh_internal( obj
)
1445 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1446 item_button
= item
._anonymous
_union
.button
1447 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1448 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1450 elif item
.type == 0:#{
1451 item_visual
= item
._anonymous
_union
.visual
1452 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1454 elif item
.type == 3:#{
1455 item_checkmark
= item
._anonymous
_union
.checkmark
1456 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1457 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1458 delta
= obj_data
.checkmark
.location
- obj
.location
1459 item_checkmark
.offset
[0] = delta
[0]
1460 item_checkmark
.offset
[1] = delta
[2]
1461 item_checkmark
.offset
[2] = -delta
[1]
1463 elif item
.type == 4:#{
1464 item_slider
= item
._anonymous
_union
.slider
1465 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1466 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1467 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1468 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1470 elif item
.type == 5:#{
1471 item_page
= item
._anonymous
_union
.page
1472 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1473 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1474 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1476 elif item
.type == 6:#{
1477 item_binding
= item
._anonymous
_union
.binding
1478 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1479 item_binding
.font_variant
= obj_data
.font_variant
1483 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1485 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1486 if item
.type != 4:#{
1488 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1490 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1497 def sr_compile_armature( obj
):
1499 node
= mdl_armature()
1500 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1502 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1505 bones
= [_
for _
in sr_armature_bones(obj
)]
1506 bones_names
= [None]+[_
.name
for _
in bones
]
1510 if b
.use_deform
: bone
.flags
= 0x1
1511 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1513 bone
.collider
= int(b
.SR_data
.collider
)
1515 if bone
.collider
>0:#{
1516 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1517 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1518 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1519 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1520 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1521 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1524 if b
.SR_data
.cone_constraint
:#{
1526 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1527 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1528 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1529 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1530 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1531 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1532 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1533 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1534 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1535 bone
.conet
= b
.SR_data
.conet
1538 bone
.co
[0] = b
.head_local
[0]
1539 bone
.co
[1] = b
.head_local
[2]
1540 bone
.co
[2] = -b
.head_local
[1]
1541 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1542 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1543 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1544 bone
.pstr_name
= sr_compile_string( b
.name
)
1546 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1547 if c
.type == 'IK':#{
1549 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1550 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1554 node
.bone_count
+= 1
1555 sr_compile
.bone_data
.extend(bytearray(bone
))
1560 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1561 # So we can restore later
1563 previous_frame
= bpy
.context
.scene
.frame_current
1564 previous_action
= obj
.animation_data
.action
1565 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1566 obj
.data
.pose_position
= 'POSE'
1568 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1569 for NLAStrip
in NLALayer
.strips
:#{
1572 for a
in bpy
.data
.actions
:#{
1573 if a
.name
== NLAStrip
.name
:#{
1574 obj
.animation_data
.action
= a
1579 # Clip to NLA settings
1581 anim_start
= int(NLAStrip
.action_frame_start
)
1582 anim_end
= int(NLAStrip
.action_frame_end
)
1586 anim
= mdl_animation()
1587 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1589 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1590 sizeof(mdl_transform
)
1591 anim
.length
= anim_end
-anim_start
1594 # Export the keyframes
1595 for frame
in range(anim_start
,anim_end
):#{
1596 bpy
.context
.scene
.frame_set(frame
)
1599 pb
= obj
.pose
.bones
[rb
.name
]
1601 # relative bone matrix
1602 if rb
.parent
is not None:#{
1603 offset_mtx
= rb
.parent
.matrix_local
1604 offset_mtx
= offset_mtx
.inverted_safe() @ \
1607 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1608 inv_parent
.invert_safe()
1609 fpm
= inv_parent
@ pb
.matrix
1612 bone_mtx
= rb
.matrix
.to_4x4()
1613 local_inv
= rb
.matrix_local
.inverted_safe()
1614 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1617 loc
, rot
, sca
= fpm
.decompose()
1620 lc_m
= pb
.matrix_channel
.to_3x3()
1621 if pb
.parent
is not None:#{
1622 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1623 lc_m
= smtx
.inverted() @ lc_m
1625 rq
= lc_m
.to_quaternion()
1628 kf
= mdl_transform()
1639 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1645 # Add to animation buffer
1647 sr_compile
.anim_data
.extend(bytearray(anim
))
1648 node
.anim_count
+= 1
1652 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1656 # Restore context to how it was before
1658 bpy
.context
.scene
.frame_set( previous_frame
)
1659 obj
.animation_data
.action
= previous_action
1660 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1663 sr_compile
.armature_data
.extend(bytearray(node
))
1666 def sr_ent_push( struct
):
1668 clase
= type(struct
).__name
__
1670 if clase
not in sr_compile
.entity_data
:#{
1671 sr_compile
.entity_data
[ clase
] = bytearray()
1672 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1675 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1676 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1680 def sr_array_title( arr
, name
, count
, size
, offset
):
1682 for i
in range(len(name
)):#{
1683 arr
.name
[i
] = ord(name
[i
])
1685 arr
.file_offset
= offset
1686 arr
.item_count
= count
1687 arr
.item_size
= size
1694 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1699 def sr_compile( collection
):
1701 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1705 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1706 sr_compile
.pack_animations
= collection
.SR_data
.animations
1709 sr_compile
.string_cache
= {}
1710 sr_compile
.mesh_cache
= {}
1711 sr_compile
.material_cache
= {}
1712 sr_compile
.texture_cache
= {}
1715 sr_compile
.mesh_data
= bytearray()
1716 sr_compile
.submesh_data
= bytearray()
1717 sr_compile
.vertex_data
= bytearray()
1718 sr_compile
.indice_data
= bytearray()
1719 sr_compile
.bone_data
= bytearray()
1720 sr_compile
.material_data
= bytearray()
1721 sr_compile
.armature_data
= bytearray()
1722 sr_compile
.anim_data
= bytearray()
1723 sr_compile
.keyframe_data
= bytearray()
1724 sr_compile
.texture_data
= bytearray()
1726 # just bytes not structures
1727 sr_compile
.string_data
= bytearray()
1728 sr_compile
.pack_data
= bytearray()
1731 sr_compile
.entity_data
= {}
1732 sr_compile
.entity_info
= {}
1734 print( F
"[SR] assign entity ID's" )
1735 sr_compile
.entities
= {}
1736 sr_compile
.entity_ids
= {}
1739 # -------------------------------------------------------
1741 sr_compile_string( "null" )
1744 for obj
in collection
.all_objects
: #{
1745 if obj
.type == 'MESH':#{
1749 ent_type
= obj_ent_type( obj
)
1750 if ent_type
== 'none': continue
1752 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1753 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1754 sr_compile
.entities
[ent_type
] += [obj
]
1757 print( F
"[SR] Compiling geometry" )
1759 for obj
in collection
.all_objects
:#{
1760 if obj
.type == 'MESH':#{
1763 ent_type
= obj_ent_type( obj
)
1765 # entity ignore mesh list
1767 if ent_type
== 'ent_traffic': continue
1768 if ent_type
== 'ent_prop': continue
1769 if ent_type
== 'ent_font': continue
1770 if ent_type
== 'ent_font_variant': continue
1771 if ent_type
== 'ent_menuitem': continue
1772 if ent_type
== 'ent_objective': continue
1773 if ent_type
== 'ent_region': continue
1775 #TODO: This is messy.
1776 if ent_type
== 'ent_gate':#{
1777 obj_data
= obj
.SR_data
.ent_gate
[0]
1778 if obj_data
.custom
: continue
1780 #--------------------------
1782 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1783 sr_compile_mesh( obj
)
1787 audio_clip_count
= 0
1788 entity_file_ref_count
= 0
1790 for ent_type
, arr
in sr_compile
.entities
.items():#{
1791 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1793 for i
in range(len(arr
)):#{
1796 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1798 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1799 elif ent_type
== 'ent_light': #{
1801 compile_obj_transform( obj
, light
.transform
)
1802 light
.daytime
= obj
.data
.SR_data
.daytime
1803 if obj
.data
.type == 'POINT':#{
1806 elif obj
.data
.type == 'SPOT':#{
1808 light
.angle
= obj
.data
.spot_size
*0.5
1810 light
.range = obj
.data
.cutoff_distance
1811 light
.colour
[0] = obj
.data
.color
[0]
1812 light
.colour
[1] = obj
.data
.color
[1]
1813 light
.colour
[2] = obj
.data
.color
[2]
1814 light
.colour
[3] = obj
.data
.energy
1815 sr_ent_push( light
)
1817 elif ent_type
== 'ent_camera': #{
1819 compile_obj_transform( obj
, cam
.transform
)
1820 cam
.fov
= obj
.data
.angle
* 45.0
1823 elif ent_type
== 'ent_gate': #{
1825 obj_data
= obj
.SR_data
.ent_gate
[0]
1826 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1830 if obj_data
.tipo
== 'default':#{
1831 if obj_data
.target
:#{
1832 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1836 elif obj_data
.tipo
== 'nonlocal':#{
1838 gate
.key
= sr_compile_string(obj_data
.key
)
1842 if obj_data
.flip
: flags |
= 0x0004
1843 if obj_data
.custom
:#{
1845 gate
.submesh_start
, gate
.submesh_count
, _
= \
1846 sr_compile_mesh_internal( obj
)
1848 if obj_data
.locked
: flags |
= 0x0010
1851 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1852 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1853 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1855 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1856 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1858 if obj_data
.target
:#{
1859 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1860 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1865 for x
in range(2):#{
1866 gate
.co
[x
][0] = co
[x
][0]
1867 gate
.co
[x
][1] = co
[x
][2]
1868 gate
.co
[x
][2] = -co
[x
][1]
1869 gate
.q
[x
][0] = q
[x
][1]
1870 gate
.q
[x
][1] = q
[x
][3]
1871 gate
.q
[x
][2] = -q
[x
][2]
1872 gate
.q
[x
][3] = q
[x
][0]
1877 elif ent_type
== 'ent_spawn': #{
1879 compile_obj_transform( obj
, spawn
.transform
)
1880 obj_data
= obj
.SR_data
.ent_spawn
[0]
1881 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1882 sr_ent_push( spawn
)
1884 elif ent_type
== 'ent_water':#{
1886 compile_obj_transform( obj
, water
.transform
)
1887 water
.max_dist
= 0.0
1888 sr_ent_push( water
)
1890 elif ent_type
== 'ent_audio':#{
1891 obj_data
= obj
.SR_data
.ent_audio
[0]
1893 compile_obj_transform( obj
, audio
.transform
)
1894 audio
.clip_start
= audio_clip_count
1895 audio
.clip_count
= len(obj_data
.files
)
1896 audio_clip_count
+= audio
.clip_count
1897 audio
.max_channels
= obj_data
.max_channels
1898 audio
.volume
= obj_data
.volume
1901 # - allow/disable doppler
1902 # - channel group tags with random colours
1903 # - transition properties
1905 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1906 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1907 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1908 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1909 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1910 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1911 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1913 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1914 if audio
.channel_behaviour
>= 1:#{
1915 audio
.group
= obj_data
.group
1917 if audio
.channel_behaviour
== 2:#{
1918 audio
.crossfade
= obj_data
.transition_duration
1920 audio
.probability_curve
= int(obj_data
.probability_curve
)
1922 for ci
in range(audio
.clip_count
):#{
1923 entry
= obj_data
.files
[ci
]
1924 clip
= ent_audio_clip()
1925 clip
.probability
= entry
.probability
1926 if obj_data
.formato
== '2':#{
1927 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1930 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1931 clip
._anon
.file.pack_offset
= 0
1932 clip
._anon
.file.pack_size
= 0
1936 sr_ent_push( audio
)
1938 elif ent_type
== 'ent_volume':#{
1939 obj_data
= obj
.SR_data
.ent_volume
[0]
1940 volume
= ent_volume()
1941 volume
.type = int(obj_data
.subtype
)
1942 compile_obj_transform( obj
, volume
.transform
)
1944 if obj_data
.target
:#{
1945 volume
.target
= sr_entity_id( obj_data
.target
)
1946 volume
._anon
.trigger
.event
= obj_data
.target_event
1947 volume
._anon
.trigger
.event_leave
= obj_data
.target_event_leave
1952 elif ent_type
== 'ent_marker':#{
1953 marker
= ent_marker()
1954 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1955 compile_obj_transform( obj
, marker
.transform
)
1958 elif ent_type
== 'ent_skateshop':#{
1959 skateshop
= ent_skateshop()
1960 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1961 skateshop
.type = int(obj_data
.tipo
)
1962 if skateshop
.type == 0:#{
1963 boardshop
= skateshop
._anonymous
_union
.boards
1964 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1965 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1966 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1968 elif skateshop
.type == 1:#{
1969 charshop
= skateshop
._anonymous
_union
.character
1970 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1971 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1973 elif skateshop
.type == 2:#{
1974 worldshop
= skateshop
._anonymous
_union
.worlds
1975 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1976 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1978 elif skateshop
.type == 3:#{
1979 server
= skateshop
._anonymous
_union
.server
1980 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1982 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1983 compile_obj_transform( obj
, skateshop
.transform
)
1984 sr_ent_push(skateshop
)
1986 elif ent_type
== 'ent_swspreview':#{
1987 workshop_preview
= ent_swspreview()
1988 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1989 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1990 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1991 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1992 sr_ent_push( workshop_preview
)
1994 elif ent_type
== 'ent_worldinfo':#{
1995 worldinfo
= ent_worldinfo()
1996 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1997 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1998 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1999 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
2003 if obj_data
.fix_time
:#{
2004 worldinfo
.timezone
= obj_data
.fixed_time
2008 worldinfo
.timezone
= obj_data
.timezone
2010 worldinfo
.flags
= flags
2011 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
2012 sr_ent_push( worldinfo
)
2014 elif ent_type
== 'ent_ccmd':#{
2016 obj_data
= obj
.SR_data
.ent_ccmd
[0]
2017 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
2020 elif ent_type
== 'ent_objective':#{
2021 objective
= ent_objective()
2022 obj_data
= obj
.SR_data
.ent_objective
[0]
2023 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
2024 objective
.id_win
= sr_entity_id( obj_data
.target
)
2025 objective
.win_event
= obj_data
.target_event
2026 objective
.filter = int(obj_data
.filtrar
)
2027 objective
.filter2
= 0
2028 objective
.time_limit
= obj_data
.time_limit
2030 compile_obj_transform( obj
, objective
.transform
)
2031 objective
.submesh_start
, objective
.submesh_count
, _
= \
2032 sr_compile_mesh_internal( obj
)
2034 sr_ent_push( objective
)
2036 elif ent_type
== 'ent_challenge':#{
2037 challenge
= ent_challenge()
2038 obj_data
= obj
.SR_data
.ent_challenge
[0]
2039 compile_obj_transform( obj
, challenge
.transform
)
2040 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2041 challenge
.target
= sr_entity_id( obj_data
.target
)
2042 challenge
.target_event
= obj_data
.target_event
2043 challenge
.reset
= sr_entity_id( obj_data
.reset
)
2044 challenge
.reset_event
= obj_data
.reset_event
2045 challenge
.first
= sr_entity_id( obj_data
.first
)
2046 challenge
.flags
= 0x00
2047 challenge
.camera
= sr_entity_id( obj_data
.camera
)
2048 if obj_data
.time_limit
: challenge
.flags |
= 0x01
2049 challenge
.status
= 0
2050 sr_ent_push( challenge
)
2052 elif ent_type
== 'ent_region':#{
2053 region
= ent_region()
2054 obj_data
= obj
.SR_data
.ent_region
[0]
2055 compile_obj_transform( obj
, region
.transform
)
2056 region
.submesh_start
, region
.submesh_count
, _
= \
2057 sr_compile_mesh_internal( obj
)
2058 region
.pstr_title
= sr_compile_string( obj_data
.title
)
2059 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
2060 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
2061 region
.target0
[1] = obj_data
.target0_event
2062 sr_ent_push( region
)
2064 elif ent_type
== 'ent_relay':#{
2066 obj_data
= obj
.SR_data
.ent_relay
[0]
2067 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
2068 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
2069 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
2070 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
2071 relay
.targets
[0][1] = obj_data
.target0_event
2072 relay
.targets
[1][1] = obj_data
.target1_event
2073 relay
.targets
[2][1] = obj_data
.target2_event
2074 relay
.targets
[3][1] = obj_data
.target3_event
2075 sr_ent_push( relay
)
2077 # elif ent_type == 'ent_list':#{
2078 # lista = ent_list()
2079 # obj_data = obj.SR_data.ent_list[0]
2081 # lista.entity_ref_start = entity_file_ref_count
2082 # lista.entity_ref_count = len( obj_data.entities )
2083 # entity_file_ref_count += lista.entity_ref_count
2085 # for child in obj_data.entities:#{
2086 # reference_struct = file_entity_ref()
2087 # reference_struct.index = sr_entity_id( child.target )
2088 # sr_ent_push( reference_struct )
2091 # sr_ent_push( lista )
2093 elif ent_type
== 'ent_glider':#{
2094 glider
= ent_glider()
2095 compile_obj_transform( obj
, glider
.transform
)
2096 sr_ent_push( glider
)
2098 elif ent_type
== 'ent_npc':#{
2099 obj_data
= obj
.SR_data
.ent_npc
[0]
2101 compile_obj_transform( obj
, npc
.transform
)
2102 npc
.id = obj_data
.au
2103 npc
.context
= obj_data
.context
2104 npc
.camera
= sr_entity_id( obj_data
.cam
)
2107 elif ent_type
== 'ent_cubemap':#{
2108 cubemap
= ent_cubemap()
2109 co
= obj
.matrix_world
@ Vector((0,0,0))
2110 cubemap
.co
[0] = co
[0]
2111 cubemap
.co
[1] = co
[2]
2112 cubemap
.co
[2] = -co
[1]
2113 cubemap
.resolution
= 0
2115 sr_ent_push( cubemap
)
2117 elif ent_type
== 'ent_miniworld':#{
2118 miniworld
= ent_miniworld()
2119 obj_data
= obj
.SR_data
.ent_miniworld
[0]
2121 compile_obj_transform( obj
, miniworld
.transform
)
2122 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
2123 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
2124 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
2125 sr_ent_push( miniworld
)
2127 elif ent_type
== 'ent_prop':#{
2129 obj_data
= obj
.SR_data
.ent_prop
[0]
2130 compile_obj_transform( obj
, prop
.transform
)
2131 prop
.submesh_start
, prop
.submesh_count
, _
= \
2132 sr_compile_mesh_internal( obj
)
2133 prop
.flags
= obj_data
.flags
2134 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2140 sr_compile_menus( collection
)
2141 sr_compile_fonts( collection
)
2143 def _children( col
):#{
2145 for c
in col
.children
:#{
2146 yield from _children(c
)
2150 checkpoint_count
= 0
2151 pathindice_count
= 0
2154 for col
in _children(collection
):#{
2155 print( F
"Adding routes for subcollection: {col.name}" )
2161 for obj
in col
.objects
:#{
2162 if obj
.type == 'ARMATURE': pass
2164 ent_type
= obj_ent_type( obj
)
2166 if ent_type
== 'ent_gate':
2167 route_gates
+= [obj
]
2168 elif ent_type
== 'ent_route_node':#{
2169 if obj
.type == 'CURVE':#{
2170 route_curves
+= [obj
]
2173 elif ent_type
== 'ent_route':
2175 elif ent_type
== 'ent_traffic':
2180 dij
= create_node_graph( route_curves
, route_gates
)
2182 for obj
in routes
:#{
2183 obj_data
= obj
.SR_data
.ent_route
[0]
2185 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
2186 route
.checkpoints_start
= checkpoint_count
2187 route
.checkpoints_count
= 0
2188 route
.id_camera
= sr_entity_id( obj_data
.cam
)
2191 route
.colour
[ci
] = obj_data
.colour
[ci
]
2192 route
.colour
[3] = 1.0
2194 compile_obj_transform( obj
, route
.transform
)
2195 checkpoints
= obj_data
.gates
2197 for i
in range(len(checkpoints
)):#{
2198 gi
= checkpoints
[i
].target
2199 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
2203 dest
= gi
.SR_data
.ent_gate
[0].target
2207 if gi
==gj
: continue # error?
2208 if not gi
or not gj
: continue
2210 checkpoint
= ent_checkpoint()
2211 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
2212 checkpoint
.path_start
= pathindice_count
2213 checkpoint
.path_count
= 0
2215 path
= solve_graph( dij
, gi
.name
, gj
.name
)
2218 for pi
in range(len(path
)):#{
2219 pathindice
= ent_path_index()
2220 pathindice
.index
= routenode_count
+ path
[pi
]
2221 sr_ent_push( pathindice
)
2223 checkpoint
.path_count
+= 1
2224 pathindice_count
+= 1
2228 sr_ent_push( checkpoint
)
2229 route
.checkpoints_count
+= 1
2230 checkpoint_count
+= 1
2233 sr_ent_push( route
)
2236 for obj
in traffics
:#{
2237 traffic
= ent_traffic()
2238 compile_obj_transform( obj
, traffic
.transform
)
2239 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2240 sr_compile_mesh_internal( obj
)
2242 # find best subsection
2244 graph_keys
= list(dij
.graph
)
2248 for j
in range(len(dij
.points
)):#{
2249 point
= dij
.points
[j
]
2250 dist
= (point
-obj
.location
).magnitude
2252 if dist
< min_dist
:#{
2259 best_begin
= best_point
2260 best_end
= best_point
2263 map0
= dij
.subsections
[best_begin
]
2264 if map0
[1] == -1: break
2265 best_begin
= map0
[1]
2268 map1
= dij
.subsections
[best_end
]
2269 if map1
[2] == -1: break
2273 traffic
.start_node
= routenode_count
+ best_begin
2274 traffic
.node_count
= best_end
- best_begin
2275 traffic
.index
= best_point
- best_begin
2276 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2279 sr_ent_push(traffic
)
2282 for point
in dij
.points
:#{
2283 rn
= ent_route_node()
2286 rn
.co
[2] = -point
[1]
2290 routenode_count
+= len(dij
.points
)
2293 print( F
"[SR] Writing file" )
2295 file_array_instructions
= {}
2298 def _write_array( name
, item_size
, data
):#{
2299 nonlocal file_array_instructions
, file_offset
2301 count
= len(data
)//item_size
2302 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2303 'data':data
, 'offset': file_offset
}
2304 file_offset
+= len(data
)
2305 file_offset
= int_align_to( file_offset
, 8 )
2308 _write_array( 'strings', 1, sr_compile
.string_data
)
2309 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2310 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2311 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2312 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2313 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2314 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2316 for name
, buffer in sr_compile
.entity_data
.items():#{
2317 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2320 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2321 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2322 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2323 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2324 _write_array( 'pack', 1, sr_compile
.pack_data
)
2326 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2327 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2329 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2330 path
= F
"{folder}{collection.name}.mdl"
2333 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2334 fp
= open( path
, "wb" )
2335 header
= mdl_header()
2336 header
.version
= MDL_VERSION_NR
2337 sr_array_title( header
.arrays
, \
2338 'index', len(file_array_instructions
), \
2339 sizeof(mdl_array
), header_size
)
2341 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2343 print( F
'[SR] {"name":>16}| count | offset' )
2345 for name
,info
in file_array_instructions
.items():#{
2347 offset
= info
['offset'] + header_size
+ index_size
2348 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2349 index
.extend( bytearray(arr
) )
2351 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2352 F
' 0x{info["offset"]:02x}' )
2354 fp
.write( bytearray_align_to( index
, 8 ) )
2355 #bytearray_print_hex( index )
2357 for name
,info
in file_array_instructions
.items():#{
2358 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2363 print( '[SR] done' )
2366 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2368 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2369 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2370 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2372 panel
: bpy
.props
.EnumProperty(
2376 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2377 ('ENTITY', 'Entity', '', 'MONKEY',1),
2378 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2383 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2385 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2386 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2389 def sr_get_mirror_bone( bones
):
2391 side
= bones
.active
.name
[-1:]
2392 other_name
= bones
.active
.name
[:-1]
2393 if side
== 'L': other_name
+= 'R'
2394 elif side
== 'R': other_name
+= 'L'
2398 if b
.name
== other_name
:
2405 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2407 bl_idname
="skaterift.mirror_bone"
2408 bl_label
="Mirror bone attributes - SkateRift"
2410 def execute(_
,context
):
2412 active_object
= context
.active_object
2413 bones
= active_object
.data
.bones
2415 b
= sr_get_mirror_bone( bones
)
2417 if not b
: return {'FINISHED'}
2419 b
.SR_data
.collider
= a
.SR_data
.collider
2421 def _v3copyflipy( a
, b
):#{
2427 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2428 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2429 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2430 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2432 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2434 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2435 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2436 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2438 b
.SR_data
.conet
= a
.SR_data
.conet
2441 ob
= bpy
.context
.scene
.objects
[0]
2442 ob
.hide_render
= ob
.hide_render
2447 class SR_COMPILE(bpy
.types
.Operator
):
2449 bl_idname
="skaterift.compile_all"
2450 bl_label
="Compile All"
2452 def execute(_
,context
):
2454 view_layer
= bpy
.context
.view_layer
2455 for col
in view_layer
.layer_collection
.children
["export"].children
:
2456 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2457 sr_compile( bpy
.data
.collections
[col
.name
] )
2463 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2465 bl_idname
="skaterift.compile_this"
2466 bl_label
="Compile This collection"
2468 def execute(_
,context
):
2470 col
= bpy
.context
.collection
2477 class SR_INTERFACE(bpy
.types
.Panel
):
2479 bl_idname
= "VIEW3D_PT_skate_rift"
2480 bl_label
= "Skate Rift"
2481 bl_space_type
= 'VIEW_3D'
2482 bl_region_type
= 'UI'
2483 bl_category
= "Skate Rift"
2485 def draw(_
, context
):
2489 row
= _
.layout
.row()
2491 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2493 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2494 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2496 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2497 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2498 col
= bpy
.context
.collection
2500 found_in_export
= False
2502 view_layer
= bpy
.context
.view_layer
2503 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2504 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2507 if c1
.name
== col
.name
: #{
2508 found_in_export
= True
2512 box
= _
.layout
.box()
2514 row
.alignment
= 'CENTER'
2517 if found_in_export
: #{
2518 row
.label( text
=col
.name
+ ".mdl" )
2519 box
.prop( col
.SR_data
, "pack_textures" )
2520 box
.prop( col
.SR_data
, "animations" )
2521 box
.operator( "skaterift.compile_this" )
2525 row
.label( text
=col
.name
)
2529 row
.alignment
= 'CENTER'
2531 row
.label( text
="This collection is not in the export group" )
2534 box
= _
.layout
.box()
2537 split
= row
.split( factor
=0.3, align
=True )
2538 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2541 if export_count
== 0:
2543 row1
.operator( "skaterift.compile_all", \
2544 text
=F
"Compile all ({export_count} collections)" )
2546 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2547 active_object
= context
.active_object
2548 if not active_object
: return
2550 amount
= max( 0, len(context
.selected_objects
)-1 )
2552 row
= _
.layout
.row()
2553 row
.operator( 'skaterift.copy_entity_data', \
2554 text
=F
'Copy entity data to {amount} other objects' )
2555 if amount
== 0: row
.enabled
=False
2557 box
= _
.layout
.box()
2559 row
.alignment
= 'CENTER'
2560 row
.label( text
=active_object
.name
)
2563 def _draw_prop_collection( source
, data
): #{
2566 row
.alignment
= 'CENTER'
2569 row
.label( text
=F
'{source}' )
2571 if hasattr(type(data
[0]),'sr_inspector'):#{
2572 type(data
[0]).sr_inspector( box
, data
)
2575 for a
in data
[0].__annotations
__:
2576 box
.prop( data
[0], a
)
2580 if active_object
.type == 'ARMATURE': #{
2581 if active_object
.mode
== 'POSE': #{
2582 bones
= active_object
.data
.bones
2583 mb
= sr_get_mirror_bone( bones
)
2585 box
.operator( "skaterift.mirror_bone", \
2586 text
=F
'Mirror attributes to {mb.name}' )
2589 _draw_prop_collection( \
2590 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2591 [bones
.active
.SR_data
] )
2595 row
.alignment
='CENTER'
2598 row
.label( text
="Enter pose mode to modify bone properties" )
2601 elif active_object
.type == 'LIGHT': #{
2602 _draw_prop_collection( \
2603 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2604 [active_object
.data
.SR_data
] )
2606 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2607 box
.prop( active_object
.SR_data
, "ent_type" )
2608 ent_type
= active_object
.SR_data
.ent_type
2610 col
= getattr( active_object
.SR_data
, ent_type
, None )
2611 if col
!= None and len(col
)!=0:
2612 _draw_prop_collection( \
2613 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2616 if active_object
.type == 'MESH':#{
2617 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2618 if col
!= None and len(col
)!=0:
2619 _draw_prop_collection( \
2620 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2628 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2630 bl_label
="Skate Rift material"
2631 bl_idname
="MATERIAL_PT_sr_material"
2632 bl_space_type
='PROPERTIES'
2633 bl_region_type
='WINDOW'
2634 bl_context
="material"
2636 def draw(_
,context
):
2638 active_object
= bpy
.context
.active_object
2639 if active_object
== None: return
2640 active_mat
= active_object
.active_material
2641 if active_mat
== None: return
2643 info
= material_info( active_mat
)
2645 if 'tex_diffuse' in info
:#{
2646 _
.layout
.label( icon
='INFO', \
2647 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2650 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2651 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2652 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2654 if active_mat
.SR_data
.collision
:#{
2655 box
= _
.layout
.box()
2658 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2659 (active_mat
.SR_data
.shader
!= 'boundary') and \
2660 (active_mat
.SR_data
.shader
!= 'walking'):#{
2661 row
.prop( active_mat
.SR_data
, "skate_surface" )
2662 row
.prop( active_mat
.SR_data
, "grind_surface" )
2663 row
.prop( active_mat
.SR_data
, "grow_grass" )
2664 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2668 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2669 box
= _
.layout
.box()
2670 box
.prop( active_mat
.SR_data
, "blend_offset" )
2671 box
.prop( active_mat
.SR_data
, "sand_colour" )
2673 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2674 box
= _
.layout
.box()
2675 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2676 box
.prop( active_mat
.SR_data
, "blend_offset" )
2678 elif active_mat
.SR_data
.shader
== "water":#{
2679 box
= _
.layout
.box()
2680 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2681 box
.prop( active_mat
.SR_data
, "shore_colour" )
2682 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2684 elif active_mat
.SR_data
.shader
== "cubemap":#{
2685 box
= _
.layout
.box()
2686 box
.prop( active_mat
.SR_data
, "cubemap" )
2687 box
.prop( active_mat
.SR_data
, "tint" )
2690 _
.layout
.label( text
="" )
2691 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2692 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2696 def sr_get_type_enum( scene
, context
):
2698 items
= [('none','None',"")]
2699 mesh_entities
=['ent_gate','ent_water']
2700 point_entities
=['ent_spawn','ent_route_node','ent_route']
2702 for e
in point_entities
: items
+= [(e
,e
,'')]
2704 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2705 if context
.active_object
.type == 'MESH': #{
2706 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2710 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2716 def sr_on_type_change( _
, context
):
2718 obj
= context
.active_object
2719 ent_type
= obj
.SR_data
.ent_type
2720 if ent_type
== 'none': return
2721 if obj
.type == 'MESH':#{
2722 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2723 if col
!= None and len(col
)==0: col
.add()
2726 col
= getattr( obj
.SR_data
, ent_type
, None )
2727 if col
!= None and len(col
)==0: col
.add()
2730 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2732 alias
: bpy
.props
.StringProperty( name
='alias' )
2735 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2737 target
: bpy
.props
.PointerProperty( \
2738 type=bpy
.types
.Object
, name
="destination", \
2739 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2741 key
: bpy
.props
.StringProperty()
2742 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2743 ('nonlocal', 'Non-Local', "")))
2745 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2746 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2747 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2750 def sr_inspector( layout
, data
):
2753 box
.prop( data
[0], 'tipo', text
="subtype" )
2755 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2756 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2759 flags
.prop( data
[0], 'flip' )
2760 flags
.prop( data
[0], 'custom' )
2761 flags
.prop( data
[0], 'locked' )
2765 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2767 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2770 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2772 target
: bpy
.props
.PointerProperty( \
2773 type=bpy
.types
.Object
, name
='target', \
2774 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2777 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2779 world
: bpy
.props
.StringProperty( name
='world UID' )
2780 proxy
: bpy
.props
.PointerProperty( \
2781 type=bpy
.types
.Object
, name
='proxy', \
2782 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2783 camera
: bpy
.props
.PointerProperty( \
2784 type=bpy
.types
.Object
, name
="Camera", \
2785 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2788 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2790 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2792 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2794 layout
.prop( item
, 'target', text
='', emboss
=False )
2798 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2800 active_object
= context
.active_object
2801 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2802 lista
= getattr(data
,collection_name
)
2803 index
= getattr(data
,F
'{collection_name}_index')
2807 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2811 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2813 active_object
= context
.active_object
2814 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2818 def copy_propgroup( de
, to
):
2820 for a
in de
.__annotations
__:#{
2821 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2825 while len(cb
) != len(ca
):#{
2826 if len(cb
) < len(ca
): cb
.add()
2829 for i
in range(len(ca
)):#{
2830 copy_propgroup(ca
[i
],cb
[i
])
2834 setattr(to
,a
,getattr(de
,a
))
2839 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2841 bl_idname
= "skaterift.copy_entity_data"
2842 bl_label
= "Copy entity data"
2844 def execute(self
, context
):#{
2845 data
= context
.active_object
.SR_data
2846 new_type
= data
.ent_type
2847 print( F
"Copy entity data from: {context.active_object.name}" )
2849 for obj
in context
.selected_objects
:#{
2850 if obj
!= context
.active_object
:#{
2851 print( F
" To: {obj.name}" )
2853 obj
.SR_data
.ent_type
= new_type
2855 if active_object
.type == 'MESH':#{
2856 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2857 if col
!= None and len(col
)==0: col
.add()
2858 mdata
= context
.active_object
.data
.SR_data
2859 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2862 col
= getattr( obj
.SR_data
, new_type
, None )
2863 if col
!= None and len(col
)==0: col
.add()
2864 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2871 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2873 bl_idname
= "skaterift.new_entry"
2874 bl_label
= "Add gate"
2876 def execute(self
, context
):#{
2877 return internal_listadd_execute(self
,context
,'ent_route','gates')
2881 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2883 bl_idname
= "skaterift.del_entry"
2884 bl_label
= "Remove gate"
2887 def poll(cls
, context
):#{
2888 active_object
= context
.active_object
2889 if obj_ent_type(active_object
) == 'ent_route':#{
2890 return active_object
.SR_data
.ent_route
[0].gates
2895 def execute(self
, context
):#{
2896 return internal_listdel_execute(self
,context
,'ent_route','gates')
2900 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2902 bl_idname
= "skaterift.al_new_entry"
2903 bl_label
= "Add file"
2905 def execute(self
, context
):#{
2906 return internal_listadd_execute(self
,context
,'ent_audio','files')
2910 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2912 bl_idname
= "skaterift.al_del_entry"
2913 bl_label
= "Remove file"
2916 def poll(cls
, context
):#{
2917 active_object
= context
.active_object
2918 if obj_ent_type(active_object
) == 'ent_audio':#{
2919 return active_object
.SR_data
.ent_audio
[0].files
2924 def execute(self
, context
):#{
2925 return internal_listdel_execute(self
,context
,'ent_audio','files')
2930 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2932 bl_idname
= "skaterift.gl_new_entry"
2933 bl_label
= "Add glyph"
2935 def execute(self
, context
):#{
2936 active_object
= context
.active_object
2938 font
= active_object
.SR_data
.ent_font
[0]
2941 if len(font
.glyphs
) > 1:#{
2942 prev
= font
.glyphs
[-2]
2943 cur
= font
.glyphs
[-1]
2945 cur
.bounds
= prev
.bounds
2946 cur
.utf32
= prev
.utf32
+1
2953 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2955 bl_idname
= "skaterift.gl_del_entry"
2956 bl_label
= "Remove Glyph"
2959 def poll(cls
, context
):#{
2960 active_object
= context
.active_object
2961 if obj_ent_type(active_object
) == 'ent_font':#{
2962 return active_object
.SR_data
.ent_font
[0].glyphs
2967 def execute(self
, context
):#{
2968 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2972 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2974 bl_idname
= "skaterift.gl_move_item"
2976 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2977 ('DOWN', 'Down', ""),))
2980 def poll(cls
, context
):#{
2981 active_object
= context
.active_object
2982 if obj_ent_type(active_object
) == 'ent_font':#{
2983 return active_object
.SR_data
.ent_font
[0].glyphs
2988 def execute(_
, context
):#{
2989 active_object
= context
.active_object
2990 data
= active_object
.SR_data
.ent_font
[0]
2992 index
= data
.glyphs_index
2993 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2994 data
.glyphs
.move( neighbor
, index
)
2996 list_length
= len(data
.glyphs
) - 1
2997 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2999 data
.glyphs_index
= max(0, min(new_index
, list_length
))
3005 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
3007 bl_idname
= "skaterift.fv_new_entry"
3008 bl_label
= "Add variant"
3010 def execute(self
, context
):#{
3011 return internal_listadd_execute(self
,context
,'ent_font','variants')
3015 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
3017 bl_idname
= "skaterift.fv_del_entry"
3018 bl_label
= "Remove variant"
3021 def poll(cls
, context
):#{
3022 active_object
= context
.active_object
3023 if obj_ent_type(active_object
) == 'ent_font':#{
3024 return active_object
.SR_data
.ent_font
[0].variants
3029 def execute(self
, context
):#{
3030 return internal_listdel_execute(self
,context
,'ent_font','variants')
3034 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
3036 path
: bpy
.props
.StringProperty( name
="Path" )
3037 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
3040 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
3042 bl_idname
= 'SR_UL_AUDIO_LIST'
3044 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3046 split
= layout
.split(factor
=0.7)
3048 c
.prop( item
, 'path', text
='', emboss
=False )
3050 c
.prop( item
, 'probability', text
='%', emboss
=True )
3054 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
3056 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
3058 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3060 layout
.prop( item
, 'mesh', emboss
=False )
3061 layout
.prop( item
, 'tipo' )
3065 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
3067 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
3069 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3071 s0
= layout
.split(factor
=0.3)
3073 s1
= c
.split(factor
=0.3)
3076 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
3080 c
.prop( item
, 'utf32', text
='', emboss
=True )
3083 row
.prop( item
, 'bounds', text
='', emboss
=False )
3087 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
3089 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
3090 gates_index
: bpy
.props
.IntProperty()
3092 colour
: bpy
.props
.FloatVectorProperty( \
3096 default
=Vector((0.79,0.63,0.48)),\
3097 description
="Route colour"\
3100 alias
: bpy
.props
.StringProperty(\
3102 default
="Untitled Course")
3104 cam
: bpy
.props
.PointerProperty( \
3105 type=bpy
.types
.Object
, name
="Viewpoint", \
3106 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3109 def sr_inspector( layout
, data
):
3111 layout
.prop( data
[0], 'alias' )
3112 layout
.prop( data
[0], 'colour' )
3113 layout
.prop( data
[0], 'cam' )
3115 layout
.label( text
='Checkpoints' )
3116 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
3117 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
3120 row
.operator( 'skaterift.new_entry', text
='Add' )
3121 row
.operator( 'skaterift.del_entry', text
='Remove' )
3126 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
3127 bl_idname
= "skaterift.ent_list_new_entry"
3128 bl_label
= "Add entity"
3130 def execute(self
, context
):#{
3131 return internal_listadd_execute(self
,context
,'ent_list','entities')
3135 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
3136 bl_idname
= "skaterift.ent_list_del_entry"
3137 bl_label
= "Remove entity"
3140 def poll(cls
, context
):#{
3141 active_object
= context
.active_object
3142 if obj_ent_type(active_object
) == 'ent_list':#{
3143 return active_object
.SR_data
.ent_list
[0].entities
3148 def execute(self
, context
):#{
3149 return internal_listdel_execute(self
,context
,'ent_list','entities')
3153 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
3155 target
: bpy
.props
.PointerProperty( \
3156 type=bpy
.types
.Object
, name
='target' )
3159 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
3160 bl_idname
= 'SR_UL_ENT_LIST'
3162 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
3163 layout
.prop( item
, 'target', text
='', emboss
=False )
3167 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
3168 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
3169 entities_index
: bpy
.props
.IntProperty()
3172 def sr_inspector( layout
, data
):#{
3173 layout
.label( text
='Entities' )
3174 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
3175 data
[0], 'entities', data
[0], \
3176 'entities_index', rows
=5)
3179 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
3180 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
3184 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
3185 nothing
: bpy
.props
.StringProperty()
3188 class SR_OBJECT_ENT_NPC(bpy
.types
.PropertyGroup
):#{
3189 au
: bpy
.props
.IntProperty()
3190 context
: bpy
.props
.IntProperty()
3191 cam
: bpy
.props
.PointerProperty( \
3192 type=bpy
.types
.Object
, name
="Viewpoint", \
3193 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3196 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
3197 subtype
: bpy
.props
.EnumProperty(
3199 items
=[('0','Trigger',''),
3200 ('1','Particles (0.1s)','')]
3203 target
: bpy
.props
.PointerProperty( \
3204 type=bpy
.types
.Object
, name
="Target", \
3205 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3206 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
3207 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
3210 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
3212 box
.prop( data
[0], propname
)
3214 for evname
in evs
:#{
3216 row
.prop( data
[0], propname
+ evname
)
3218 target
= getattr( data
[0], propname
)
3220 tipo
= target
.SR_data
.ent_type
3221 cls
= globals()[ tipo
]
3223 table
= getattr( cls
, 'sr_functions', None )
3225 index
= getattr( data
[0], propname
+ evname
)
3227 row
.label( text
=table
[index
] )
3229 row
.label( text
="undefined function" )
3233 row
.label( text
="..." )
3240 def sr_inspector( layout
, data
):#{
3241 layout
.prop( data
[0], 'subtype' )
3242 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3243 ['_event','_event_leave'] )
3247 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3249 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3250 files_index
: bpy
.props
.IntProperty()
3252 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3253 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3254 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3255 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3257 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3258 formato
: bpy
.props
.EnumProperty(
3260 items
=[('0','Uncompressed Mono',''),
3261 ('1','Compressed Vorbis',''),
3262 ('2','[vg] Bird Synthesis','')]
3264 probability_curve
: bpy
.props
.EnumProperty(
3265 name
="Probability Curve",
3266 items
=[('0','Constant',''),
3267 ('1','Wildlife Daytime',''),
3268 ('2','Wildlife Nighttime','')])
3269 channel_behaviour
: bpy
.props
.EnumProperty(
3270 name
="Channel Behaviour",
3271 items
=[('0','Unlimited',''),
3272 ('1','Discard if group full', ''),
3273 ('2','Crossfade if group full','')])
3275 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3278 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3279 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3282 def sr_inspector( layout
, data
):
3284 layout
.prop( data
[0], 'formato' )
3285 layout
.prop( data
[0], 'volume' )
3288 box
.label( text
='Channels' )
3289 split
= box
.split(factor
=0.3)
3291 c
.prop( data
[0], 'max_channels' )
3293 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3294 if data
[0].channel_behaviour
>= '1':
3295 box
.prop( data
[0], 'group' )
3296 if data
[0].channel_behaviour
== '2':
3297 box
.prop( data
[0], 'transition_duration' )
3300 box
.label( text
='Flags' )
3301 box
.prop( data
[0], 'flag_3d' )
3302 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3304 box
.prop( data
[0], 'flag_loop' )
3305 box
.prop( data
[0], 'flag_auto' )
3307 layout
.prop( data
[0], 'probability_curve' )
3309 split
= layout
.split(factor
=0.7)
3311 c
.label( text
='Filepath' )
3313 c
.label( text
='Chance' )
3314 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3315 data
[0], 'files', data
[0], 'files_index', rows
=5)
3318 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3319 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3323 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3325 alias
: bpy
.props
.StringProperty()
3326 flags
: bpy
.props
.IntProperty()
3329 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3331 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3332 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3333 utf32
: bpy
.props
.IntProperty()
3336 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3338 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3339 utf32
: bpy
.props
.IntProperty()
3342 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3344 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3345 tipo
: bpy
.props
.StringProperty()
3348 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3350 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3351 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3352 alias
: bpy
.props
.StringProperty()
3354 glyphs_index
: bpy
.props
.IntProperty()
3355 variants_index
: bpy
.props
.IntProperty()
3358 def sr_inspector( layout
, data
):
3360 layout
.prop( data
[0], 'alias' )
3362 layout
.label( text
='Variants' )
3363 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3364 data
[0], 'variants', data
[0], 'variants_index',\
3367 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3368 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3370 layout
.label( text
='ASCII Glyphs' )
3371 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3372 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3375 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3376 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3377 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3378 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3382 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3384 speed
: bpy
.props
.FloatProperty(default
=1.0)
3387 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3389 tipo
: bpy
.props
.EnumProperty( name
='Type',
3390 items
=[('0','boards',''),
3391 ('1','character',''),
3393 ('4','server','')] )
3394 mark_rack
: bpy
.props
.PointerProperty( \
3395 type=bpy
.types
.Object
, name
="Board Rack", \
3396 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3397 mark_display
: bpy
.props
.PointerProperty( \
3398 type=bpy
.types
.Object
, name
="Selected Board Display", \
3399 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3400 mark_info
: bpy
.props
.PointerProperty( \
3401 type=bpy
.types
.Object
, name
="Selected Board Info", \
3402 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3403 ['ent_marker','ent_prop']))
3404 cam
: bpy
.props
.PointerProperty( \
3405 type=bpy
.types
.Object
, name
="Viewpoint", \
3406 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3409 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3411 mark_display
: bpy
.props
.PointerProperty( \
3412 type=bpy
.types
.Object
, name
="Board Display", \
3413 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3414 mark_display1
: bpy
.props
.PointerProperty( \
3415 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3416 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3417 cam
: bpy
.props
.PointerProperty( \
3418 type=bpy
.types
.Object
, name
="Viewpoint", \
3419 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3422 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3424 link0
: bpy
.props
.PointerProperty( \
3425 type=bpy
.types
.Object
, name
="Link 0", \
3426 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3427 link1
: bpy
.props
.PointerProperty( \
3428 type=bpy
.types
.Object
, name
="Link 1", \
3429 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3430 link2
: bpy
.props
.PointerProperty( \
3431 type=bpy
.types
.Object
, name
="Link 2", \
3432 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3433 link3
: bpy
.props
.PointerProperty( \
3434 type=bpy
.types
.Object
, name
="Link 3", \
3435 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3437 newloc
: bpy
.props
.PointerProperty( \
3438 type=bpy
.types
.Object
, name
="New location", \
3439 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3440 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3441 items
=[('0','append',''),
3442 ('1','replace','')])
3444 camera
: bpy
.props
.PointerProperty( \
3445 type=bpy
.types
.Object
, name
="Camera", \
3446 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3448 slider_minloc
: bpy
.props
.PointerProperty( \
3449 type=bpy
.types
.Object
, name
="Slider min", \
3450 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3451 slider_maxloc
: bpy
.props
.PointerProperty( \
3452 type=bpy
.types
.Object
, name
="Slider max", \
3453 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3454 slider_handle
: bpy
.props
.PointerProperty( \
3455 type=bpy
.types
.Object
, name
="Slider handle", \
3456 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3458 checkmark
: bpy
.props
.PointerProperty( \
3459 type=bpy
.types
.Object
, name
="Checked", \
3460 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3462 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3464 string
: bpy
.props
.StringProperty( name
="String" )
3465 tipo
: bpy
.props
.EnumProperty( name
='Type',
3466 items
=[('0','visual',''),
3467 ('1','event button',''),
3468 ('2','page button',''),
3473 ('7','visual(no colourize)','')])
3476 def sr_inspector( layout
, data
):
3480 box
.prop( data
, 'tipo' )
3482 if data
.tipo
== '0' or data
.tipo
== '7':#{
3483 box
.prop( data
, 'string', text
='Name' )
3486 elif data
.tipo
== '1':#{
3487 box
.prop( data
, 'string', text
='Event' )
3489 elif data
.tipo
== '2':#{
3490 box
.prop( data
, 'string', text
='Page' )
3491 box
.prop( data
, 'stack_behaviour' )
3493 elif data
.tipo
== '3':#{
3494 box
.prop( data
, 'string', text
='Data (i32)' )
3495 box
.prop( data
, 'checkmark' )
3497 elif data
.tipo
== '4':#{
3498 box
.prop( data
, 'string', text
='Data (f32)' )
3499 box
.prop( data
, 'slider_minloc' )
3500 box
.prop( data
, 'slider_maxloc' )
3501 box
.prop( data
, 'slider_handle' )
3503 box
.label( text
="Links" )
3504 box
.prop( data
, 'link0', text
='v0' )
3505 box
.prop( data
, 'link1', text
='v1' )
3508 elif data
.tipo
== '5':#{
3509 box
.prop( data
, 'string', text
='Page Name' )
3510 box
.prop( data
, 'newloc', text
='Entry Point' )
3511 box
.prop( data
, 'camera', text
='Viewpoint' )
3514 elif data
.tipo
== '6':#{
3515 box
.prop( data
, 'string', text
='ID' )
3516 box
.prop( data
, 'font_variant' )
3521 box
.label( text
="Links" )
3522 box
.prop( data
, 'link0' )
3523 box
.prop( data
, 'link1' )
3524 box
.prop( data
, 'link2' )
3525 box
.prop( data
, 'link3' )
3529 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3531 name
: bpy
.props
.StringProperty(name
="Name")
3532 desc
: bpy
.props
.StringProperty(name
="Description")
3533 author
: bpy
.props
.StringProperty(name
="Author")
3534 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3536 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3537 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3538 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3541 def sr_inspector( layout
, data
):#{
3542 layout
.prop( data
[0], 'name' )
3543 layout
.prop( data
[0], 'desc' )
3544 layout
.prop( data
[0], 'author' )
3546 layout
.prop( data
[0], 'fix_time' )
3547 if data
[0].fix_time
:
3548 layout
.prop( data
[0], 'fixed_time' )
3550 layout
.prop( data
[0], 'timezone' )
3554 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3556 command
: bpy
.props
.StringProperty(name
="Command Line")
3559 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3560 proxima
: bpy
.props
.PointerProperty( \
3561 type=bpy
.types
.Object
, name
="Next", \
3562 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3563 target
: bpy
.props
.PointerProperty( \
3564 type=bpy
.types
.Object
, name
="Win", \
3565 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3566 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3567 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3568 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3569 items
=[('0','none',''),
3570 (str(0x1),'trick_shuvit',''),
3571 (str(0x2),'trick_kickflip',''),
3572 (str(0x4),'trick_treflip',''),
3573 (str(0x1|
0x2|
0x4),'trick_any',''),
3574 (str(0x8),'flip_back',''),
3575 (str(0x10),'flip_front',''),
3576 (str(0x8|
0x10),'flip_any',''),
3577 (str(0x20),'grind_truck_any',''),
3578 (str(0x40),'grind_board_any',''),
3579 (str(0x20|
0x40),'grind_any',''),
3580 (str(0x80),'footplant',''),
3581 (str(0x100),'passthrough',''),
3585 def sr_inspector( layout
, data
):#{
3586 layout
.prop( data
[0], 'proxima' )
3587 layout
.prop( data
[0], 'time_limit' )
3588 layout
.prop( data
[0], 'filtrar' )
3589 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3593 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3594 alias
: bpy
.props
.StringProperty( name
="Alias" )
3596 target
: bpy
.props
.PointerProperty( \
3597 type=bpy
.types
.Object
, name
="On Complete", \
3598 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3599 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3600 reset
: bpy
.props
.PointerProperty( \
3601 type=bpy
.types
.Object
, name
="On Reset", \
3602 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3603 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3605 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3607 first
: bpy
.props
.PointerProperty( \
3608 type=bpy
.types
.Object
, name
="First Objective", \
3609 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3611 camera
: bpy
.props
.PointerProperty( \
3612 type=bpy
.types
.Object
, name
="Camera", \
3613 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3617 def sr_inspector( layout
, data
):#{
3618 layout
.prop( data
[0], 'alias' )
3619 layout
.prop( data
[0], 'camera' )
3620 layout
.prop( data
[0], 'first' )
3621 layout
.prop( data
[0], 'time_limit' )
3622 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3623 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3627 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3628 title
: bpy
.props
.StringProperty( name
="Title" )
3629 zone_volume
: bpy
.props
.PointerProperty(
3630 type=bpy
.types
.Object
, name
="Zone Volume", \
3631 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3633 target0
: bpy
.props
.PointerProperty( \
3634 type=bpy
.types
.Object
, name
="Triger on unlock", \
3635 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3636 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3639 def sr_inspector( layout
, data
):#{
3640 layout
.prop( data
[0], 'title' )
3641 layout
.prop( data
[0], 'zone_volume' )
3642 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3646 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3647 target0
: bpy
.props
.PointerProperty( \
3648 type=bpy
.types
.Object
, name
="Target 0", \
3649 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3650 target1
: bpy
.props
.PointerProperty( \
3651 type=bpy
.types
.Object
, name
="Target 1", \
3652 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3653 target2
: bpy
.props
.PointerProperty( \
3654 type=bpy
.types
.Object
, name
="Target 2", \
3655 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3656 target3
: bpy
.props
.PointerProperty( \
3657 type=bpy
.types
.Object
, name
="Target 3", \
3658 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3660 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3661 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3662 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3663 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3666 def sr_inspector( layout
, data
):#{
3667 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3668 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3669 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3670 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3674 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3676 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3677 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3678 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3679 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3680 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3681 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3682 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3683 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3684 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3685 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3686 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3688 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3689 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3690 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3691 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3692 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3693 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3694 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3695 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3696 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3697 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3698 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3699 ent_npc
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_NPC
)
3701 ent_type
: bpy
.props
.EnumProperty(
3703 items
=sr_entity_list
,
3704 update
=sr_on_type_change
3708 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3710 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3713 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3715 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3718 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3720 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3721 items
=[('0','none',''),
3723 ('2','capsule','')])
3725 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3726 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3728 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3730 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3731 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3732 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3733 conet
: bpy
.props
.FloatProperty( name
='t' )
3736 def sr_inspector( layout
, data
):
3740 box
.prop( data
, 'collider' )
3742 if int(data
.collider
)>0:#{
3744 row
.prop( data
, 'collider_min' )
3746 row
.prop( data
, 'collider_max' )
3750 box
.prop( data
, 'cone_constraint' )
3751 if data
.cone_constraint
:#{
3753 row
.prop( data
, 'conevx' )
3755 row
.prop( data
, 'conevy' )
3757 row
.prop( data
, 'coneva' )
3758 box
.prop( data
, 'conet' )
3763 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3765 shader
: bpy
.props
.EnumProperty(
3768 ('standard',"standard",''),
3769 ('standard_cutout', "standard_cutout", ''),
3770 ('terrain_blend', "terrain_blend", ''),
3771 ('vertex_blend', "vertex_blend", ''),
3772 ('water',"water",''),
3773 ('invisible','Invisible',''),
3774 ('boundary','Boundary',''),
3775 ('fxglow','FX Glow',''),
3776 ('cubemap','Cubemap',''),
3777 ('walking','Walking',''),
3778 ('foliage','Foliage','')
3781 surface_prop
: bpy
.props
.EnumProperty(
3782 name
="Surface Property",
3784 ('0','concrete',''),
3789 ('5','snow (low friction)',''),
3790 ('6','sand (medium friction)','')
3793 collision
: bpy
.props
.BoolProperty( \
3794 name
="Collisions Enabled",\
3796 description
= "Can the player collide with this material?"\
3798 skate_surface
: bpy
.props
.BoolProperty( \
3799 name
="Skate Target", \
3801 description
= "Should the game try to target this surface?" \
3803 grind_surface
: bpy
.props
.BoolProperty( \
3806 description
= "Can you grind on this surface?" \
3808 grow_grass
: bpy
.props
.BoolProperty( \
3809 name
="Grow Grass", \
3811 description
= "Spawn grass sprites on this surface?" \
3813 preview_visibile
: bpy
.props
.BoolProperty( \
3814 name
="Preview visibile", \
3816 description
= "Show this material in preview models?" \
3818 blend_offset
: bpy
.props
.FloatVectorProperty( \
3819 name
="Blend Offset", \
3821 default
=Vector((0.5,0.0)),\
3822 description
="When surface is more than 45 degrees, add this vector " +\
3825 sand_colour
: bpy
.props
.FloatVectorProperty( \
3826 name
="Sand Colour",\
3829 default
=Vector((0.79,0.63,0.48)),\
3830 description
="Blend to this colour near the 0 coordinate on UP axis"\
3832 shore_colour
: bpy
.props
.FloatVectorProperty( \
3833 name
="Shore Colour",\
3836 default
=Vector((0.03,0.32,0.61)),\
3837 description
="Water colour at the shoreline"\
3839 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3840 name
="Ocean Colour",\
3843 default
=Vector((0.0,0.006,0.03)),\
3844 description
="Water colour in the deep bits"\
3846 tint
: bpy
.props
.FloatVectorProperty( \
3851 default
=Vector((1.0,1.0,1.0,1.0)),\
3852 description
="Reflection tint"\
3855 water_fog
: bpy
.props
.FloatProperty( name
="Water fog", default
=0.04 )
3857 cubemap
: bpy
.props
.PointerProperty( \
3858 type=bpy
.types
.Object
, name
="cubemap", \
3859 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3861 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3864 # ---------------------------------------------------------------------------- #
3868 # ---------------------------------------------------------------------------- #
3870 cv_view_draw_handler
= None
3871 cv_view_pixel_handler
= None
3872 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3874 cv_view_colours
= []
3875 cv_view_course_i
= 0
3877 # Draw axis alligned sphere at position with radius
3879 def cv_draw_sphere( pos
, radius
, colour
):
3881 global cv_view_verts
, cv_view_colours
3883 ly
= pos
+ Vector((0,0,radius
))
3884 lx
= pos
+ Vector((0,radius
,0))
3885 lz
= pos
+ Vector((0,0,radius
))
3887 pi
= 3.14159265358979323846264
3889 for i
in range(16):#{
3890 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3894 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3895 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3896 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3898 cv_view_verts
+= [ px
, lx
]
3899 cv_view_verts
+= [ py
, ly
]
3900 cv_view_verts
+= [ pz
, lz
]
3902 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3911 # Draw axis alligned sphere at position with radius
3913 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3915 global cv_view_verts
, cv_view_colours
3917 ly
= pos
+ tz
*radius
3918 lx
= pos
+ ty
*radius
3919 lz
= pos
+ tz
*radius
3921 pi
= 3.14159265358979323846264
3923 for i
in range(16):#{
3924 t
= ((i
+1.0) * 1.0/16.0) * pi
3928 s1
= math
.sin(t
*2.0)
3929 c1
= math
.cos(t
*2.0)
3931 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3932 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3933 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3935 cv_view_verts
+= [ px
, lx
]
3936 cv_view_verts
+= [ py
, ly
]
3937 cv_view_verts
+= [ pz
, lz
]
3939 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3948 # Draw transformed -1 -> 1 cube
3950 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3952 global cv_view_verts
, cv_view_colours
3958 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3959 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3960 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3961 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3962 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3963 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3964 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3965 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3967 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3968 (0,4),(1,5),(2,6),(3,7)]
3973 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3974 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3975 cv_view_colours
+= [colour
, colour
]
3980 # Draw line with colour
3982 def cv_draw_line( p0
, p1
, colour
):
3984 global cv_view_verts
, cv_view_colours
3986 cv_view_verts
+= [p0
,p1
]
3987 cv_view_colours
+= [colour
, colour
]
3991 # Draw line with colour(s)
3993 def cv_draw_line2( p0
, p1
, c0
, c1
):
3995 global cv_view_verts
, cv_view_colours
3997 cv_view_verts
+= [p0
,p1
]
3998 cv_view_colours
+= [c0
,c1
]
4004 def cv_tangent_basis( n
, tx
, ty
):
4006 if abs( n
[0] ) >= 0.57735027:#{
4025 # Draw coloured arrow
4027 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
4029 global cv_view_verts
, cv_view_colours
4035 tx
= Vector((1,0,0))
4036 ty
= Vector((1,0,0))
4037 cv_tangent_basis( n
, tx
, ty
)
4043 gpu
.state
.line_width_set(1.0)
4046 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
4047 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
4051 gpu
.state
.line_width_set(3.0)
4052 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
4054 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
4056 gpu
.state
.line_width_set(2.0)
4060 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
4062 global cv_view_verts
, cv_view_colours
4064 for i
in range(dots
):#{
4068 p2
= p0
*(1.0-t0
)+p1
*t0
4069 p3
= p0
*(1.0-t1
)+p1
*t1
4071 cv_view_verts
+= [p2
,p3
]
4072 cv_view_colours
+= [c0
,c0
]
4077 # Drawhandles of a bezier control point
4079 def cv_draw_bhandle( obj
, direction
, colour
):
4081 global cv_view_verts
, cv_view_colours
4084 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
4086 cv_view_verts
+= [p0
]
4087 cv_view_verts
+= [h0
]
4088 cv_view_colours
+= [colour
,colour
]
4092 # Draw a bezier curve (at fixed resolution 10)
4094 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
4096 global cv_view_verts
, cv_view_colours
4099 for i
in range(10):#{
4105 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
4107 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
4108 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
4109 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
4116 # I think this one extends the handles of the bezier otwards......
4118 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
4120 global cv_view_course_i
4122 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
4124 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
4125 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
4126 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
4127 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
4129 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
4133 # Flush the lines buffers. This is called often because god help you if you want
4134 # to do fixed, fast buffers in this catastrophic programming language.
4136 def cv_draw_lines():
4138 global cv_view_shader
, cv_view_verts
, cv_view_colours
4140 if len(cv_view_verts
) < 2:
4143 lines
= batch_for_shader(\
4144 cv_view_shader
, 'LINES', \
4145 { "pos":cv_view_verts
, "color":cv_view_colours
})
4147 if bpy
.context
.scene
.SR_data
.gizmos
:
4148 lines
.draw( cv_view_shader
)
4151 cv_view_colours
= []
4154 # I dont remember what this does exactly
4156 def cv_draw_bpath( o0
,o1
,c0
,c1
):
4158 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
4161 # Semi circle to show the limit. and some lines
4163 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
4165 global cv_view_verts
, cv_view_colours
4170 for x
in range(16):#{
4173 a0
= amin
*(1.0-t0
)+amax
*t0
4174 a1
= amin
*(1.0-t1
)+amax
*t1
4176 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
4177 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
4179 p0
=obj
.matrix_world
@ p0
4180 p1
=obj
.matrix_world
@ p1
4181 cv_view_verts
+= [p0
,p1
]
4182 cv_view_colours
+= [colour
,colour
]
4185 cv_view_verts
+= [p0
,center
]
4186 cv_view_colours
+= [colour
,colour
]
4189 cv_view_verts
+= [p1
,center
]
4190 cv_view_colours
+= [colour
,colour
]
4194 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
4195 cv_view_colours
+= [colour
,colour
]
4200 # Cone and twist limit
4202 def draw_cone_twist( center
, vx
, vy
, va
):
4204 global cv_view_verts
, cv_view_colours
4205 axis
= vy
.cross( vx
)
4210 cv_view_verts
+= [center
, center
+va
*size
]
4211 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4213 for x
in range(32):#{
4214 t0
= (x
/32) * math
.tau
4215 t1
= ((x
+1)/32) * math
.tau
4222 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4223 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4225 col0
= ( abs(c0
), abs(s0
), 0.0 )
4226 col1
= ( abs(c1
), abs(s1
), 0.0 )
4228 cv_view_verts
+= [center
, p0
, p0
, p1
]
4229 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4235 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4237 def draw_skeleton_helpers( obj
):
4239 global cv_view_verts
, cv_view_colours
4241 if obj
.data
.pose_position
!= 'REST':#{
4245 for bone
in obj
.data
.bones
:#{
4247 a
= Vector((bone
.SR_data
.collider_min
[0],
4248 bone
.SR_data
.collider_min
[1],
4249 bone
.SR_data
.collider_min
[2]))
4250 b
= Vector((bone
.SR_data
.collider_max
[0],
4251 bone
.SR_data
.collider_max
[1],
4252 bone
.SR_data
.collider_max
[2]))
4254 if bone
.SR_data
.collider
== '1':#{
4256 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4257 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4258 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4259 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4260 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4261 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4262 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4263 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4265 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4266 (0,4),(1,5),(2,6),(3,7)]
4272 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4273 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4274 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4277 elif bone
.SR_data
.collider
== '2':#{
4282 for i
in range(3):#{
4283 if abs(v0
[i
]) > largest
:#{
4284 largest
= abs(v0
[i
])
4289 v1
= Vector((0,0,0))
4290 v1
[major_axis
] = 1.0
4292 tx
= Vector((0,0,0))
4293 ty
= Vector((0,0,0))
4295 cv_tangent_basis( v1
, tx
, ty
)
4296 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4297 l
= v0
[ major_axis
] - r
*2
4299 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4300 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4302 colour
= [0.2,0.2,0.2]
4303 colour
[major_axis
] = 0.5
4305 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4306 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4307 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4308 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4309 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4310 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4316 center
= obj
.matrix_world
@ c
4317 if bone
.SR_data
.cone_constraint
:#{
4318 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4319 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4320 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4321 draw_cone_twist( center
, vx
, vy
, va
)
4326 def cv_draw_wireframe( mdl
, points
, colour
):#{
4327 for i
in range(len(points
)//2):#{
4328 p0
= mdl
@points[i
*2+0]
4329 p1
= mdl
@points[i
*2+1]
4330 cv_draw_line( p0
, p1
, colour
)
4334 def cv_ent_gate( obj
):
4336 global cv_view_verts
, cv_view_colours
4338 if obj
.type != 'MESH': return
4340 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4341 data
= obj
.SR_data
.ent_gate
[0]
4342 dims
= mesh_data
.dimensions
4345 c
= Vector((0,0,dims
[2]))
4347 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4348 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4349 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4350 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4351 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4352 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4353 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4354 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4355 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4357 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4359 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4361 p0
= r3d
.view_matrix
.inverted().translation
4362 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4363 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4365 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4371 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4372 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4373 cv_view_colours
+= [cc
,cc
]
4377 if data
.target
!= None:
4378 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4381 def cv_ent_volume( obj
):
4383 global cv_view_verts
, cv_view_colours
4385 data
= obj
.SR_data
.ent_volume
[0]
4387 if data
.subtype
== '0':#{
4388 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4391 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4394 elif data
.subtype
== '1':#{
4395 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4398 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4403 def dijkstra( graph
, start_node
, target_node
):
4405 unvisited
= [_
for _
in graph
]
4410 shortest_path
[n
] = 9999999.999999
4411 shortest_path
[start_node
] = 0
4414 current_min_node
= None
4415 for n
in unvisited
:#{
4416 if current_min_node
== None:
4417 current_min_node
= n
4418 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4419 current_min_node
= n
4422 for branch
in graph
[current_min_node
]:#{
4423 tentative_value
= shortest_path
[current_min_node
]
4424 tentative_value
+= graph
[current_min_node
][branch
]
4425 if tentative_value
< shortest_path
[branch
]:#{
4426 shortest_path
[branch
] = tentative_value
4427 previous_nodes
[branch
] = current_min_node
4431 unvisited
.remove(current_min_node
)
4436 while node
!= start_node
:#{
4439 if node
not in previous_nodes
: return None
4440 node
= previous_nodes
[node
]
4443 # Add the start node manually
4444 path
.append(start_node
)
4450 def __init__(_
,points
,graph
,subsections
):#{
4453 _
.subsections
= subsections
4457 def create_node_graph( curves
, gates
):
4459 # add endpoints of curves
4466 for c
in range(len(curves
)):#{
4467 for s
in range(len(curves
[c
].data
.splines
)):#{
4468 spline
= curves
[c
].data
.splines
[s
]
4469 l
= len(spline
.points
)
4472 dist
= round(spline
.calc_length(),2)
4475 ib
= point_count
+l
-1
4477 graph
[ia
] = { ib
: dist
}
4478 graph
[ib
] = { ia
: dist
}
4480 for i
in range(len(spline
.points
)):#{
4481 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4482 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4487 if i
== 0: previous
= -1
4488 if i
== len(spline
.points
)-1: proxima
= -1
4490 subsections
.append((spline_count
,previous
,proxima
))
4499 graph_keys
= list(graph
)
4500 for i
in range(len(graph_keys
)-1):#{
4501 for j
in range(i
+1, len(graph_keys
)):#{
4502 if i
%2==0 and i
+1==j
: continue
4506 pi
= route_points
[ni
]
4507 pj
= route_points
[nj
]
4509 dist
= round((pj
-pi
).magnitude
,2)
4512 graph
[ni
][nj
] = dist
4513 graph
[nj
][ni
] = dist
4518 # add and link gates( by name )
4519 for gate
in gates
:#{
4520 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4521 if gate
.SR_data
.ent_gate
[0].target
:
4524 graph
[ gate
.name
] = {}
4526 for i
in range(len(graph_keys
)):#{
4528 pi
= route_points
[ni
]
4530 v0
= pi
-gate
.location
4531 if v0
.dot(v1
) < 0.0: continue
4533 dist
= round(v0
.magnitude
,2)
4536 graph
[ gate
.name
][ ni
] = dist
4537 graph
[ ni
][ gate
.name
] = dist
4542 return dij_graph(route_points
,graph
,subsections
)
4545 def solve_graph( dij
, start
, end
):
4547 path
= dijkstra( dij
.graph
, end
, start
)
4551 for sj
in range(1,len(path
)-2):#{
4554 map0
= dij
.subsections
[i0
]
4555 map1
= dij
.subsections
[i1
]
4557 if map0
[0] == map1
[0]:#{
4558 if map0
[1] == -1: direction
= 2
4563 map0
= dij
.subsections
[i0
]
4564 i1
= map0
[direction
]
4578 full
.append( path
[-2] )
4583 def cv_draw_route( route
, dij
):
4585 pole
= Vector((0.2,0.2,10))
4586 hat
= Vector((1,8,0.2))
4587 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4588 route
.SR_data
.ent_route
[0].colour
[1],
4589 route
.SR_data
.ent_route
[0].colour
[2])
4591 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4592 Vector((0,-6.5,5.5)))
4593 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4594 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4595 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4596 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4598 checkpoints
= route
.SR_data
.ent_route
[0].gates
4600 for i
in range(len(checkpoints
)):#{
4601 gi
= checkpoints
[i
].target
4602 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4605 dest
= gi
.SR_data
.ent_gate
[0].target
4607 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4611 if gi
==gj
: continue # error?
4612 if not gi
or not gj
: continue
4614 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4617 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4618 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4619 for j
in range(len(path
)-1):#{
4622 o0
= dij
.points
[ i0
]
4623 o1
= dij
.points
[ i1
]
4624 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4628 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4634 global cv_view_shader
4635 global cv_view_verts
4636 global cv_view_colours
4637 global cv_view_course_i
4639 cv_view_course_i
= 0
4641 cv_view_colours
= []
4643 cv_view_shader
.bind()
4644 gpu
.state
.depth_mask_set(True)
4645 gpu
.state
.line_width_set(2.0)
4646 gpu
.state
.face_culling_set('BACK')
4647 gpu
.state
.depth_test_set('LESS')
4648 gpu
.state
.blend_set('NONE')
4654 for obj
in bpy
.context
.collection
.objects
:#{
4655 if obj
.type == 'ARMATURE':#{
4656 if obj
.data
.pose_position
== 'REST':
4657 draw_skeleton_helpers( obj
)
4660 ent_type
= obj_ent_type( obj
)
4662 if ent_type
== 'ent_gate':#{
4664 route_gates
+= [obj
]
4666 elif ent_type
== 'ent_route_node':#{
4667 if obj
.type == 'CURVE':#{
4668 route_curves
+= [obj
]
4671 elif ent_type
== 'ent_route':
4673 elif ent_type
== 'ent_volume':#{
4674 cv_ent_volume( obj
)
4676 elif ent_type
== 'ent_objective':#{
4677 data
= obj
.SR_data
.ent_objective
[0]
4679 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4682 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4684 elif ent_type
== 'ent_relay':#{
4685 data
= obj
.SR_data
.ent_relay
[0]
4687 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4689 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4691 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4693 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4695 elif ent_type
== 'ent_challenge':#{
4696 data
= obj
.SR_data
.ent_challenge
[0]
4698 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4700 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4702 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4705 info_cu
= Vector((1.2,0.01,0.72))*0.5
4706 info_co
= Vector((0.0,0.0,0.72))*0.5
4707 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4709 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4711 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4712 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4713 Vector(( 0.1,0.0,0.30))]
4714 for v
in range(len(vs
)):#{
4715 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4718 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4719 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4721 elif ent_type
== 'ent_audio':#{
4722 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4723 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4725 elif ent_type
== 'ent_font':#{
4726 data
= obj
.SR_data
.ent_font
[0]
4728 for i
in range(len(data
.variants
)):#{
4729 sub
= data
.variants
[i
].mesh
4730 if not sub
: continue
4732 for ch
in data
.glyphs
:#{
4733 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4734 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4735 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4736 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4737 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4738 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4740 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4743 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4744 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4748 elif ent_type
== 'ent_glider':#{
4749 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4750 Vector(( 1.13982, 0.137084, -0.026358)), \
4751 Vector(( 0.0, 1.6, 1.0)), \
4752 Vector(( 0.0, -3.0, 1.0)), \
4753 Vector(( -3.45, -1.78, 0.9)), \
4754 Vector(( 0.0, 1.6, 1.0)), \
4755 Vector(( 3.45, -1.78, 0.9)), \
4756 Vector(( 0.0, 1.6, 1.0)), \
4757 Vector(( 3.45, -1.78, 0.9)), \
4758 Vector(( -3.45, -1.78, 0.9))]
4760 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4762 elif ent_type
== 'ent_skateshop':#{
4763 data
= obj
.SR_data
.ent_skateshop
[0]
4764 display
= data
.mark_display
4765 info
= data
.mark_info
4767 if data
.tipo
== '0':#{
4772 rack
= data
.mark_rack
4774 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4775 rack_co
= Vector((0.0,0.0,0.0))
4776 display_cu
= Vector((0.3,1.2,0.1))*0.5
4777 display_co
= Vector((0.0,0.0,0.1))*0.5
4778 info_cu
= Vector((1.2,0.01,0.3))*0.5
4779 info_co
= Vector((0.0,0.0,0.0))*0.5
4781 elif data
.tipo
== '1':#{
4785 display_cu
= Vector((0.4,0.4,2.0))*0.5
4786 display_co
= Vector((0.0,0.0,1.0))*0.5
4787 info_cu
= Vector((1.2,0.01,0.3))*0.5
4788 info_co
= Vector((0.0,0.0,0.0))*0.5
4790 elif data
.tipo
== '2':#{
4794 display_cu
= Vector((1.0,1.0,0.5))*0.5
4795 display_co
= Vector((0.0,0.0,0.5))*0.5
4796 info_cu
= Vector((1.2,0.01,0.3))*0.5
4797 info_co
= Vector((0.0,0.0,0.0))*0.5
4799 elif data
.tipo
== '3':#{
4804 elif data
.tipo
== '4':#{
4811 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4813 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4815 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4817 elif ent_type
== 'ent_swspreview':#{
4819 data
= obj
.SR_data
.ent_swspreview
[0]
4820 display
= data
.mark_display
4821 display1
= data
.mark_display1
4822 display_cu
= Vector((0.3,1.2,0.1))*0.5
4823 display_co
= Vector((0.0,0.0,0.1))*0.5
4825 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4827 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4829 # elif ent_type == 'ent_list':#{
4830 # data = obj.SR_data.ent_list[0]
4831 # for child in data.entities:#{
4832 # if child.target:#{
4833 # cv_draw_arrow( obj.location, child.target.location, \
4838 elif ent_type
== 'ent_region':#{
4839 data
= obj
.SR_data
.ent_region
[0]
4841 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4845 elif ent_type
== 'ent_menuitem':#{
4846 for i
,col
in enumerate(obj
.users_collection
):#{
4847 colour32
= hash_djb2( col
.name
)
4848 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4849 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4850 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4852 vs
= [None for _
in range(8)]
4854 for j
in range(8):#{
4855 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4856 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4858 vs
[j
] = obj
.matrix_world
@ v0
4860 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4861 (0,4),(1,5),(2,6),(3,7)]
4865 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4866 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4867 cv_view_colours
+= [cc
,cc
]
4872 data
= obj
.SR_data
.ent_menuitem
[0]
4873 if data
.tipo
== '4':#{
4874 if data
.slider_minloc
and data
.slider_maxloc
:#{
4875 v0
= data
.slider_minloc
.location
4876 v1
= data
.slider_maxloc
.location
4877 cv_draw_line( v0
, v1
, cc
)
4881 colour32
= hash_djb2(obj
.name
)
4882 r
= ((colour32
) & 0xff) / 255.0
4883 g
= ((colour32
>>8 ) & 0xff) / 255.0
4884 b
= ((colour32
>>16) & 0xff) / 255.0
4886 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4891 if data
.tipo
!= '0':#{
4892 if data
.tipo
== '4':#{
4894 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4897 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4902 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4905 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4908 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4911 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4919 dij
= create_node_graph( route_curves
, route_gates
)
4921 #cv_draw_route_map( route_nodes )
4922 for route
in routes
:#{
4923 cv_draw_route( route
, dij
)
4929 def pos3d_to_2d( pos
):#{
4930 return view3d_utils
.location_3d_to_region_2d( \
4931 bpy
.context
.region
, \
4932 bpy
.context
.space_data
.region_3d
, pos
)
4935 def cv_draw_pixel():#{
4936 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4938 blf
.color(0, 1.0,1.0,1.0,0.9)
4939 blf
.enable(0,blf
.SHADOW
)
4940 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4941 for obj
in bpy
.context
.collection
.objects
:#{
4942 ent_type
= obj_ent_type( obj
)
4944 if ent_type
!= 'none':#{
4945 co
= pos3d_to_2d( obj
.location
)
4948 blf
.position(0,co
[0],co
[1],0)
4949 blf
.draw(0,ent_type
)
4954 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4955 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4956 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4958 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4959 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4960 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4961 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4962 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4963 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4964 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4965 SR_OT_COPY_ENTITY_DATA
, \
4966 SR_OBJECT_ENT_VOLUME
, \
4967 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4968 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4969 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4970 SR_OBJECT_ENT_FONT_VARIANT
,
4971 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4972 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4973 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4974 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4975 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4976 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4977 SR_OBJECT_ENT_REGION
,\
4978 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4979 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4980 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4981 SR_OBJECT_ENT_GLIDER
, SR_OBJECT_ENT_NPC
, \
4983 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4984 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4990 bpy
.utils
.register_class(c
)
4992 bpy
.types
.Scene
.SR_data
= \
4993 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4994 bpy
.types
.Collection
.SR_data
= \
4995 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4997 bpy
.types
.Object
.SR_data
= \
4998 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4999 bpy
.types
.Light
.SR_data
= \
5000 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
5001 bpy
.types
.Bone
.SR_data
= \
5002 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
5003 bpy
.types
.Mesh
.SR_data
= \
5004 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
5005 bpy
.types
.Material
.SR_data
= \
5006 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
5008 global cv_view_draw_handler
, cv_view_pixel_handler
5009 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
5010 cv_draw
,(),'WINDOW','POST_VIEW')
5011 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
5012 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
5018 bpy
.utils
.unregister_class(c
)
5020 global cv_view_draw_handler
, cv_view_pixel_handler
5021 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
5022 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')
5026 # -------------------------------------------------------------------
5028 # control characters
5031 k_vg_msg_endframe
= 2
5033 k_vg_msg_kvstring
= 11
5036 # variable sized types
5037 k_vg_msg_float
= 0x40
5038 k_vg_msg_unsigned
= 0x80
5039 k_vg_msg_signed
= 0xC0
5042 k_vg_msg_array_count_bits
= 0x3C
5043 k_vg_msg_type_size_bits
= 0x03
5044 k_vg_msg_type_base_bits
= 0xC0
5045 k_vg_msg_type_bits
= k_vg_msg_type_base_bits|k_vg_msg_type_size_bits
5054 k_vg_msg_u8
= k_vg_msg_unsigned|k_vg_msg_8b
5055 k_vg_msg_u16
= k_vg_msg_unsigned|k_vg_msg_16b
5056 k_vg_msg_u32
= k_vg_msg_unsigned|k_vg_msg_32b
5057 k_vg_msg_u64
= k_vg_msg_unsigned|k_vg_msg_64b
5058 k_vg_msg_i8
= k_vg_msg_signed |k_vg_msg_8b
5059 k_vg_msg_i16
= k_vg_msg_signed |k_vg_msg_16b
5060 k_vg_msg_i32
= k_vg_msg_signed |k_vg_msg_32b
5061 k_vg_msg_i64
= k_vg_msg_signed |k_vg_msg_64b
5062 k_vg_msg_f32
= k_vg_msg_float |k_vg_msg_32b
5063 k_vg_msg_f64
= k_vg_msg_float |k_vg_msg_64b
5064 k_vg_msg_v2f
= k_vg_msg_float |k_vg_msg_32b |
(1<<2)
5065 k_vg_msg_v3f
= k_vg_msg_float |k_vg_msg_32b |
(2<<2)
5066 k_vg_msg_v4f
= k_vg_msg_float |k_vg_msg_32b |
(3<<2)
5068 class vg_msg_cursor(Structure
):
5070 _fields_
= [("co",c_uint32
),
5074 class vg_msg(Structure
):
5076 _fields_
= [("max",c_uint32
),
5077 ("buf",POINTER(c_uint8
)),
5078 ("cur",vg_msg_cursor
),
5082 class vg_msg_cmd(Structure
):
5084 _fields_
= [("code",c_uint8
),
5085 ("key",POINTER(c_char
)),
5086 ("key_djb2",c_uint32
),
5088 ("value_djb2",c_uint32
),
5099 ext
= '.dll' if os
.name
=='nt' else '.so'
5100 path
= F
'{os.path.dirname(__file__)}/skaterift{ext}'
5101 print( F
'Loading so: {path}' )
5102 sr_lib
= cdll
.LoadLibrary( path
)
5103 sr_lib
.qoi_encode_rgbaf32
.argtypes
= \
5104 [ np
.ctypeslib
.ndpointer(dtype
=np
.float32
,\
5106 flags
='C_CONTIGUOUS'), \
5107 c_uint32
, c_uint32
, POINTER(c_int32
) ]
5108 sr_lib
.qoi_encode_rgbaf32
.restype
= POINTER(c_uint8
)
5109 sr_lib
.qoi_free
.argtypes
= [ POINTER(c_uint8
) ]
5111 sr_lib
.vg_msg_wbuf
.argtypes
= [ POINTER(vg_msg
), POINTER(c_uint8
), c_uint32
]
5112 sr_lib
.vg_msg_rbuf
.argtypes
= [ POINTER(vg_msg
), POINTER(c_uint8
), c_uint32
]
5113 sr_lib
.vg_msg_wstr
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
) ]
5114 sr_lib
.vg_msg_rstr
.argtypes
= [ POINTER(vg_msg
), POINTER(c_uint32
) ]
5115 sr_lib
.vg_msg_rstr
.restype
= POINTER(c_char
)
5116 sr_lib
.vg_msg_frame
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
) ]
5117 sr_lib
.vg_msg_end_frame
.argtypes
= [ POINTER(vg_msg
) ]
5118 sr_lib
.vg_msg_wkvstr
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), POINTER(c_char
) ]
5119 sr_lib
.vg_msg_wkvbin
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), POINTER(c_uint8
), c_uint32
]
5120 sr_lib
.vg_msg_wkvnum
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), c_uint8
, c_uint8
, c_void_p
]
5122 sr_lib
.vg_msg_cmd_array_count
.argtypes
= [ c_uint8
]
5123 sr_lib
.vg_msg_cmd_array_count
.restype
= c_uint32
5124 sr_lib
.vg_msg_cmd_type_size
.argtypes
= [ c_uint8
]
5125 sr_lib
.vg_msg_cmd_type_size
.restype
= c_uint32
5126 sr_lib
.vg_msg_cmd_bytecount
.argtypes
= [ c_uint8
]
5127 sr_lib
.vg_msg_cmd_bytecount
.restype
= c_uint32
5128 sr_lib
.vg_msg_count_bits
.argtypes
= [ c_uint32
]
5129 sr_lib
.vg_msg_count_bits
.restype
= c_uint8
5131 sr_lib
.vg_msg_init
.argtypes
= [ POINTER(vg_msg
), POINTER(c_uint8
), c_uint32
]
5132 sr_lib
.vg_msg_next
.argtypes
= [ POINTER(vg_msg
), POINTER(vg_msg_cmd
) ]
5133 sr_lib
.vg_msg_next
.restype
= c_int32
5134 sr_lib
.vg_msg_skip_frame
.argtypes
= [ POINTER(vg_msg
) ]
5135 sr_lib
.vg_msg_skip_frame
.restype
= c_int32
5136 sr_lib
.vg_msg_seekframe
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
) ]
5137 sr_lib
.vg_msg_seekframe
.restype
= c_int32
5138 sr_lib
.vg_msg_cast_to_u64
.argtypes
= [ POINTER(c_char
), c_uint8
, c_uint8
]
5139 sr_lib
.vg_msg_cast_to_u64
.restype
= c_uint64
5140 sr_lib
.vg_msg_cast_to_i64
.argtypes
= [ POINTER(c_char
), c_uint8
, c_uint8
]
5141 sr_lib
.vg_msg_cast_to_i64
.restype
= c_int64
5142 sr_lib
.vg_msg_cast_to_f64
.argtypes
= [ POINTER(c_char
), c_uint8
, c_uint8
]
5143 sr_lib
.vg_msg_cast_to_f64
.restype
= c_double
5144 sr_lib
.vg_msg_cast
.argtypes
= [ POINTER(c_char
), c_uint8
, c_void_p
, c_uint8
]
5145 sr_lib
.vg_msg_getkvcmd
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), POINTER(vg_msg_cmd
) ]
5146 sr_lib
.vg_msg_getkvcmd
.restype
= c_int32
5147 sr_lib
.vg_msg_getkvintg
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), c_uint8
, c_void_p
]
5148 sr_lib
.vg_msg_getkvintg
.restype
= c_int32
5149 sr_lib
.vg_msg_getkvstr
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
) ]
5150 sr_lib
.vg_msg_getkvstr
.restype
= POINTER(c_char
)
5151 sr_lib
.vg_msg_getkvvecf
.argtypes
= [ POINTER(vg_msg
), POINTER(c_char
), c_uint8
, c_void_p
, c_void_p
]
5152 sr_lib
.vg_msg_getkvvecf
.restype
= c_int32
5153 sr_lib
.vg_msg_print
.argtypes
= [ POINTER(vg_msg
), c_uint32
]
5156 def qoi_encode( img
):
5158 print(F
"{' ':<30}",end
='\r')
5159 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
5162 crab
= np
.asarray(img
.pixels
, dtype
=np
.float32
)
5164 comped
= qoi_encode_rgbaf32( crab
, img
.size
[0], img
.size
[1], byref(length
) )
5166 data
= bytearray(comped
[:length
.value
])
5167 bytearray_align_to( data
, 16, b
'\x00' )