1 import bpy
, blf
, math
, gpu
, os
4 from mathutils
import *
5 from gpu_extras
.batch
import batch_for_shader
6 from bpy_extras
import mesh_utils
7 from bpy_extras
import view3d_utils
10 "name":"Skaterift .mdl exporter",
11 "author": "Harry Godden (hgn)",
18 "category":"Import/Export",
22 ('none', 'None', '', 0 ),
23 ('ent_gate', 'Gate', '', 1 ),
24 ('ent_spawn', 'Spawn Point', '', 2 ),
25 ('ent_route_node', 'Routing Path', '', 3 ),
26 ('ent_route', 'Skate Course', '', 4 ),
27 ('ent_water', 'Water Surface', '', 5 ),
28 ('ent_volume', 'Volume/Trigger', '', 6 ),
29 ('ent_audio', 'Audio', '', 7 ),
30 ('ent_marker', 'Marker', '', 8 ),
31 ('ent_font', 'Font', '', 9 ),
32 ('ent_font_variant', 'Font:Variant', '', 10 ),
33 ('ent_traffic', 'Traffic Model', '', 11 ),
34 ('ent_skateshop', 'Skate Shop', '', 12 ),
35 ('ent_camera', 'Camera', '', 13 ),
36 ('ent_swspreview', 'Workshop Preview', '', 14 ),
37 ('ent_menuitem', 'Menu Item', '', 15 ),
38 ('ent_worldinfo', 'World Info', '', 16 ),
39 ('ent_ccmd', 'CCmd', '', 17 ),
40 ('ent_objective', 'Objective', '', 18 ),
41 ('ent_challenge', 'Challenge', '', 19 ),
42 ('ent_relay', 'Relay', '', 20 ),
43 ('ent_miniworld', 'Mini World', '', 22 ),
44 ('ent_prop', 'Prop', '', 23 ),
45 ('ent_list', 'Entity List', '', 24 ),
46 ('ent_region', 'Region', '', 25 ),
47 ('ent_glider', 'Glider', '', 26 ),
48 ('ent_npc', 'npc', '', 27 )
52 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
53 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
54 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
57 def get_entity_enum_id( alias
):
59 for et
in sr_entity_list
:#{
65 if alias
== 'ent_cubemap': return 21
70 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
71 #{ # the normals and uvs to i16s. Not an
72 _pack_
= 1 # real issue, yet.
73 _fields_
= [("co",c_float
*3),
77 ("weights",c_uint16
*4),
81 class mdl_transform(Structure
):
83 _fields_
= [("co",c_float
*3),
88 class mdl_submesh(Structure
):
90 _fields_
= [("indice_start",c_uint32
),
91 ("indice_count",c_uint32
),
92 ("vertex_start",c_uint32
),
93 ("vertex_count",c_uint32
),
94 ("bbx",(c_float
*3)*2),
95 ("material_id",c_uint16
), # index into the material array
99 class mdl_material(Structure
):
101 _fields_
= [("pstr_name",c_uint32
),
104 ("surface_prop",c_uint32
),
105 ("colour",c_float
*4),
106 ("colour1",c_float
*4),
107 ("tex_diffuse",c_uint32
),
108 ("tex_none0",c_uint32
),
109 ("tex_none1",c_uint32
)]
112 class mdl_bone(Structure
):
114 _fields_
= [("co",c_float
*3),("end",c_float
*3),
116 ("collider",c_uint32
),
117 ("ik_target",c_uint32
),
118 ("ik_pole",c_uint32
),
120 ("pstr_name",c_uint32
),
121 ("hitbox",(c_float
*3)*2),
122 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
126 class mdl_armature(Structure
):
128 _fields_
= [("transform",mdl_transform
),
129 ("bone_start",c_uint32
),
130 ("bone_count",c_uint32
),
131 ("anim_start",c_uint32
),
132 ("anim_count",c_uint32
)]
135 class mdl_animation(Structure
):
137 _fields_
= [("pstr_name",c_uint32
),
140 ("keyframe_start",c_uint32
)]
143 class mdl_mesh(Structure
):
145 _fields_
= [("transform",mdl_transform
),
146 ("submesh_start",c_uint32
),
147 ("submesh_count",c_uint32
),
148 ("pstr_name",c_uint32
),
149 ("entity_id",c_uint32
),
150 ("armature_id",c_uint32
)]
153 class mdl_file(Structure
):
155 _fields_
= [("path",c_uint32
),
156 ("pack_offset",c_uint32
),
157 ("pack_size",c_uint32
)]
160 class mdl_texture(Structure
):
162 _fields_
= [("file",mdl_file
),
166 class mdl_array(Structure
):
168 _fields_
= [("file_offset",c_uint32
),
169 ("item_count",c_uint32
),
170 ("item_size",c_uint32
),
174 class mdl_header(Structure
):
176 _fields_
= [("version",c_uint32
),
177 ("arrays",mdl_array
)]
180 class ent_spawn(Structure
):
182 _fields_
= [("transform",mdl_transform
),
183 ("pstr_name",c_uint32
)]
186 class ent_light(Structure
):
188 _fields_
= [("transform",mdl_transform
),
189 ("daytime",c_uint32
),
191 ("colour",c_float
*4),
194 ("inverse_world",(c_float
*3)*4), # Runtime
195 ("angle_sin_cos",(c_float
*2))] # Runtime
198 class version_refcount_union(Union
):
200 _fields_
= [("timing_version",c_uint32
),
201 ("ref_count",c_uint8
)]
204 class ent_gate(Structure
):
206 _fields_
= [("flags",c_uint32
),
207 ("target", c_uint32
),
209 ("dimensions", c_float
*3),
210 ("co", (c_float
*3)*2),
211 ("q", (c_float
*4)*2),
212 ("to_world",(c_float
*3)*4),
213 ("transport",(c_float
*3)*4),
214 ("_anonymous_union",version_refcount_union
),
215 ("timing_time",c_double
),
216 ("routes",c_uint16
*4),
217 ("route_count",c_uint8
),
218 ("submesh_start",c_uint32
), # v102+
219 ("submesh_count",c_uint32
), # v102+ (can be 0)
221 sr_functions
= { 0: 'unlock' }
224 class ent_route_node(Structure
):
226 _fields_
= [("co",c_float
*3),
227 ("ref_count",c_uint8
),
228 ("ref_total",c_uint8
)]
231 class ent_path_index(Structure
):
233 _fields_
= [("index",c_uint16
)]
236 class vg_audio_clip(Structure
):
238 _fields_
= [("path",c_uint64
),
244 class union_file_audio_clip(Union
):
246 _fields_
= [("file",mdl_file
),
247 ("reserved",vg_audio_clip
)]
250 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
251 # but then again, too late to change because compat.
252 class ent_audio_clip(Structure
):
254 _fields_
= [("_anon",union_file_audio_clip
),
255 ("probability",c_float
)]
258 class ent_list(Structure
):
260 _fields_
= [("entity_ref_start",c_uint32
),
261 ("entity_ref_count",c_uint32
)]
265 class file_entity_ref(Structure
):
267 _fields_
= [("index",c_uint32
)]
270 class ent_checkpoint(Structure
):
272 _fields_
= [("gate_index",c_uint16
),
273 ("path_start",c_uint16
),
274 ("path_count",c_uint16
)]
277 class ent_route(Structure
):
279 _fields_
= [("transform",mdl_transform
),
280 ("pstr_name",c_uint32
),
281 ("checkpoints_start",c_uint16
),
282 ("checkpoints_count",c_uint16
),
283 ("colour",c_float
*4),
284 ("active",c_uint32
), #runtime
286 ("board_transform",(c_float
*3)*4),
288 ("latest_pass",c_double
),
289 ("id_camera",c_uint32
), # v103+
292 sr_functions
= { 0: 'view' }
295 class ent_list(Structure
):#{
296 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
299 class ent_glider(Structure
):#{
300 _fields_
= [("transform",mdl_transform
),
302 ("cooldown",c_float
)]
303 sr_functions
= { 0: 'unlock',
307 class ent_npc(Structure
):#{
308 _fields_
= [("transform",mdl_transform
),
310 ("context",c_uint32
),
312 sr_functions
= { 0: 'proximity', -1: 'leave' }
315 class ent_water(Structure
):
317 _fields_
= [("transform",mdl_transform
),
318 ("max_dist",c_float
),
319 ("reserved0",c_uint32
),
320 ("reserved1",c_uint32
)]
323 class volume_trigger(Structure
):
325 _fields_
= [("event",c_uint32
),
326 ("event_leave",c_int32
)]
329 class volume_particles(Structure
):
331 _fields_
= [("blank",c_uint32
),
335 class volume_union(Union
):
337 _fields_
= [("trigger",volume_trigger
),
338 ("particles",volume_particles
)]
341 class ent_volume(Structure
):
343 _fields_
= [("transform",mdl_transform
),
344 ("to_world",(c_float
*3)*4),
345 ("to_local",(c_float
*3)*4),
348 ("_anon",volume_union
)]
351 class ent_audio(Structure
):
353 _fields_
= [("transform",mdl_transform
),
355 ("clip_start",c_uint32
),
356 ("clip_count",c_uint32
),
358 ("crossfade",c_float
),
359 ("channel_behaviour",c_uint32
),
361 ("probability_curve",c_uint32
),
362 ("max_channels",c_uint32
)]
365 class ent_marker(Structure
):
367 _fields_
= [("transform",mdl_transform
),
371 class ent_glyph(Structure
):
373 _fields_
= [("size",c_float
*2),
374 ("indice_start",c_uint32
),
375 ("indice_count",c_uint32
)]
378 class ent_font_variant(Structure
):
380 _fields_
= [("name",c_uint32
),
381 ("material_id",c_uint32
)]
384 class ent_font(Structure
):
386 _fields_
= [("alias",c_uint32
),
387 ("variant_start",c_uint32
),
388 ("variant_count",c_uint32
),
389 ("glyph_start",c_uint32
),
390 ("glyph_count",c_uint32
),
391 ("glyph_utf32_base",c_uint32
)]
394 class ent_traffic(Structure
):
396 _fields_
= [("transform",mdl_transform
),
397 ("submesh_start",c_uint32
),
398 ("submesh_count",c_uint32
),
399 ("start_node",c_uint32
),
400 ("node_count",c_uint32
),
407 # ---------------------------------------------------------------
408 class ent_skateshop_characters(Structure
):
410 _fields_
= [("id_display",c_uint32
),
411 ("id_info",c_uint32
)]
413 class ent_skateshop_boards(Structure
):
415 _fields_
= [("id_display",c_uint32
),
416 ("id_info",c_uint32
),
417 ("id_rack",c_uint32
)]
419 class ent_skateshop_worlds(Structure
):
421 _fields_
= [("id_display",c_uint32
),
422 ("id_info",c_uint32
)]
424 class ent_skateshop_server(Structure
):
426 _fields_
= [("id_lever",c_uint32
)]
428 class ent_skateshop_anon_union(Union
):
430 _fields_
= [("boards",ent_skateshop_boards
),
431 ("character",ent_skateshop_characters
),
432 ("worlds",ent_skateshop_worlds
),
433 ("server",ent_skateshop_server
)]
435 class ent_skateshop(Structure
):
437 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
438 ("id_camera",c_uint32
),
439 ("_anonymous_union",ent_skateshop_anon_union
)]
441 sr_functions
= { 0: 'trigger' }
444 class ent_swspreview(Structure
):
446 _fields_
= [("id_camera",c_uint32
),
447 ("id_display",c_uint32
),
448 ("id_display1",c_uint32
)]
452 # -----------------------------------------------------------------
453 class ent_menuitem_visual(Structure
):
455 _fields_
= [("pstr_name",c_uint32
)]
457 class ent_menuitem_slider(Structure
):
459 _fields_
= [("id_min",c_uint32
),
461 ("id_handle",c_uint32
),
462 ("pstr_data",c_uint32
)]
464 class ent_menuitem_button(Structure
):
466 _fields_
= [("pstr",c_uint32
),
467 ("stack_behaviour",c_uint32
)]
469 class ent_menuitem_checkmark(Structure
):
471 _fields_
= [("id_check",c_uint32
),
472 ("pstr_data",c_uint32
),
473 ("offset",c_float
*3)]
475 class ent_menuitem_page(Structure
):
477 _fields_
= [("pstr_name",c_uint32
),
478 ("id_entrypoint",c_uint32
),
479 ("id_viewpoint",c_uint32
)]
481 class ent_menuitem_binding(Structure
):
483 _fields_
= [("pstr_bind",c_uint32
),
484 ("font_variant",c_uint32
)]
486 class ent_menuitem_anon_union(Union
):
488 _fields_
= [("slider",ent_menuitem_slider
),
489 ("button",ent_menuitem_button
),
490 ("checkmark",ent_menuitem_checkmark
),
491 ("page",ent_menuitem_page
),
492 ("visual",ent_menuitem_visual
),
493 ("binding",ent_menuitem_binding
)]
495 class ent_menuitem(Structure
):
497 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
498 ("id_links",c_uint32
*4),
499 ("factive",c_float
), ("fvisible",c_float
),
500 #-- TODO: Refactor this into a simple mesh structure
501 ("transform",mdl_transform
),
502 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
505 ("_anonymous_union", ent_menuitem_anon_union
)]
508 class ent_camera(Structure
):
510 _fields_
= [("transform",mdl_transform
),
514 class ent_worldinfo(Structure
):
516 _fields_
= [("pstr_name",c_uint32
),
517 ("pstr_author",c_uint32
), # unused
518 ("pstr_desc",c_uint32
), # unused
519 ("timezone",c_float
),
520 ("pstr_skybox",c_uint32
),
524 class ent_ccmd(Structure
):
526 _fields_
= [("pstr_command",c_uint32
)]
529 class ent_objective(Structure
):#{
530 _fields_
= [("transform",mdl_transform
),
531 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
533 ("id_next",c_uint32
),
534 ("filter",c_uint32
),("filter2",c_uint32
),
536 ("win_event",c_int32
),
537 ("time_limit",c_float
)]
539 sr_functions
= { 0: 'trigger',
544 class ent_challenge(Structure
):#{
545 _fields_
= [("transform",mdl_transform
),
546 ("pstr_alias",c_uint32
),
549 ("target_event",c_int32
),
551 ("reset_event",c_int32
),
554 ("status",c_uint32
)] #runtime
555 sr_functions
= { 0: 'unlock',
559 class ent_region(Structure
):#{
560 _fields_
= [("transform",mdl_transform
),
561 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
562 ("pstr_title",c_uint32
),
564 ("zone_volume",c_uint32
),
566 ("target0",c_uint32
*2)]
567 sr_functions
= { 0: 'enter', 1: 'leave' }
570 class ent_relay(Structure
):#{
571 _fields_
= [("targets",(c_uint32
*2)*4),
572 ("targets_events",c_int32
*4)]
573 sr_functions
= { 0: 'trigger' }
576 class ent_cubemap(Structure
):#{
577 _fields_
= [("co",c_float
*3),
578 ("resolution",c_uint32
), #placeholder
579 ("live",c_uint32
), #placeholder
580 ("texture_id",c_uint32
), #engine
581 ("framebuffer_id",c_uint32
),#engine
582 ("renderbuffer_id",c_uint32
),#engine
583 ("placeholder",c_uint32
*2)]
586 print( sizeof(ent_cubemap
) )
588 class ent_miniworld(Structure
):#{
589 _fields_
= [("transform",mdl_transform
),
590 ("pstr_world",c_uint32
),
594 sr_functions
= { 0: 'zone', 1: 'leave' }
597 class ent_prop(Structure
):#{
598 _fields_
= [("transform",mdl_transform
),
599 ("submesh_start",c_uint32
),
600 ("submesh_count",c_uint32
),
602 ("pstr_alias",c_uint32
)]
605 def obj_ent_type( obj
):
607 if obj
.type == 'ARMATURE': return 'mdl_armature'
608 elif obj
.type == 'LIGHT': return 'ent_light'
609 elif obj
.type == 'CAMERA': return 'ent_camera'
610 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
612 else: return obj
.SR_data
.ent_type
615 def sr_filter_ent_type( obj
, ent_types
):
617 if obj
== bpy
.context
.active_object
: return False
619 for c0
in obj
.users_collection
:#{
620 for c1
in bpy
.context
.active_object
.users_collection
:#{
622 return obj_ent_type( obj
) in ent_types
630 def v4_dot( a
, b
):#{
631 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
634 def q_identity( q
):#{
641 def q_normalize( q
):#{
643 if( l2
< 0.00001 ):#{
647 s
= 1.0/math
.sqrt(l2
)
655 def compile_obj_transform( obj
, transform
):
657 co
= obj
.matrix_world
@ Vector((0,0,0))
659 # This was changed from matrix_local on 09.05.23
660 q
= obj
.matrix_world
.to_quaternion()
666 transform
.co
[0] = co
[0]
667 transform
.co
[1] = co
[2]
668 transform
.co
[2] = -co
[1]
669 transform
.q
[0] = q
[1]
670 transform
.q
[1] = q
[3]
671 transform
.q
[2] = -q
[2]
672 transform
.q
[3] = q
[0]
673 transform
.s
[0] = s
[0]
674 transform
.s
[1] = s
[2]
675 transform
.s
[2] = s
[1]
678 def int_align_to( v
, align
):
680 while(v
%align
)!=0: v
+= 1
684 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
686 while (len(buffer) % align
) != 0: buffer.extend(w
)
690 def bytearray_print_hex( s
, w
=16 ):
692 for r
in range((len(s
)+(w
-1))//w
):#{
694 i1
=min((r
+1)*w
,len(s
))
695 print( F
'{r*w:06x}| \x1B[31m', end
='')
696 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
697 print( "\x1B[0m", end
='')
698 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
702 def sr_compile_string( s
):
704 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
706 index
= len( sr_compile
.string_data
)
707 sr_compile
.string_cache
[s
] = index
708 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
709 sr_compile
.string_data
.extend( s
.encode('utf-8') )
710 sr_compile
.string_data
.extend( b
'\0' )
712 bytearray_align_to( sr_compile
.string_data
, 4 )
716 def material_tex_image(v
):
726 cxr_graph_mapping
= \
728 # Default shader setup
735 "image": "tex_diffuse"
739 "A": material_tex_image("tex_diffuse"),
740 "B": material_tex_image("tex_decal")
747 "Color": material_tex_image("tex_normal")
753 "Color": material_tex_image("tex_diffuse")
757 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
759 def material_info(mat
):
763 # Using the cxr_graph_mapping as a reference, go through the shader
764 # graph and gather all $props from it.
766 def _graph_read( node_def
, node
=None, depth
=0 ):#{
773 _graph_read
.extracted
= []
776 for node_idname
in node_def
:#{
777 for n
in mat
.node_tree
.nodes
:#{
778 if n
.name
== node_idname
:#{
779 node_def
= node_def
[node_idname
]
789 for link
in node_def
:#{
790 link_def
= node_def
[link
]
792 if isinstance( link_def
, dict ):#{
794 for x
in node
.inputs
:#{
795 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
803 if node_link
and node_link
.is_linked
:#{
804 # look for definitions for the connected node type
806 from_node
= node_link
.links
[0].from_node
808 node_name
= from_node
.name
.split('.')[0]
809 if node_name
in link_def
:#{
810 from_node_def
= link_def
[ node_name
]
812 _graph_read( from_node_def
, from_node
, depth
+1 )
816 if "default" in link_def
:#{
817 prop
= link_def
['default']
818 info
[prop
] = node_link
.default_value
824 info
[prop
] = getattr( node
, link
)
829 _graph_read( cxr_graph_mapping
)
835 decoded
= bytearray()
836 for i
in range(len(s
)//2):#{
837 c
= (ord(s
[i
*2+0])-0x41)
838 c |
= (ord(s
[i
*2+1])-0x41)<<4
839 decoded
.extend(bytearray(c_uint8(c
))) #??
844 def sr_pack_file( file, path
, data
):
846 file.path
= sr_compile_string( path
)
847 file.pack_offset
= len( sr_compile
.pack_data
)
848 file.pack_size
= len( data
)
850 sr_compile
.pack_data
.extend( data
)
851 bytearray_align_to( sr_compile
.pack_data
, 16 )
854 def sr_compile_texture( img
):
859 name
= os
.path
.splitext( img
.name
)[0]
861 if name
in sr_compile
.texture_cache
:
862 return sr_compile
.texture_cache
[name
]
864 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
869 if sr_compile
.pack_textures
:#{
870 filedata
= qoi_encode( img
)
871 sr_pack_file( tex
.file, name
, filedata
)
874 sr_compile
.texture_cache
[name
] = texture_index
875 sr_compile
.texture_data
.extend( bytearray(tex
) )
879 def sr_compile_material( mat
):#{
882 if mat
.name
in sr_compile
.material_cache
:
883 return sr_compile
.material_cache
[mat
.name
]
885 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
886 sr_compile
.material_cache
[mat
.name
] = index
889 m
.pstr_name
= sr_compile_string( mat
.name
)
892 if mat
.SR_data
.collision
:#{
893 flags |
= 0x2 # collision flag
894 if (mat
.SR_data
.shader
!= 'invisible') and \
895 (mat
.SR_data
.shader
!= 'boundary'):#{
896 if mat
.SR_data
.skate_surface
: flags |
= 0x1
897 if mat
.SR_data
.grow_grass
: flags |
= 0x4
898 if mat
.SR_data
.grind_surface
: flags |
= 0x8
899 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
901 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
902 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
903 if mat
.SR_data
.shader
== 'walking': flags |
= (0x10|
0x80)
908 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
909 inf
= material_info( mat
)
911 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
912 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
913 if mat
.SR_data
.shader
== 'foliage': m
.shader
= 10
914 if mat
.SR_data
.shader
== 'terrain_blend':#{
917 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
918 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
919 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
922 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
923 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
926 if mat
.SR_data
.shader
== 'vertex_blend':#{
929 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
930 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
933 if mat
.SR_data
.shader
== 'water':#{
936 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
937 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
938 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
940 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
941 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
942 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
946 if mat
.SR_data
.shader
== 'invisible':#{
950 if mat
.SR_data
.shader
== 'boundary':#{
954 if mat
.SR_data
.shader
== 'fxglow':#{
958 if mat
.SR_data
.shader
== 'cubemap':#{
960 m
.tex_none0
= sr_entity_id( mat
.SR_data
.cubemap
)
962 m
.colour
[0] = pow( mat
.SR_data
.tint
[0], 1.0/2.2 )
963 m
.colour
[1] = pow( mat
.SR_data
.tint
[1], 1.0/2.2 )
964 m
.colour
[2] = pow( mat
.SR_data
.tint
[2], 1.0/2.2 )
965 m
.colour
[3] = pow( mat
.SR_data
.tint
[3], 1.0/2.2 )
968 if mat
.SR_data
.shader
== 'walking':#{
972 if mat
.SR_data
.shader
in ['standard', 'standard_cutout', 'terrain_blend', \
973 'vertex_blend', 'fxglow', 'cubemap', \
975 if 'tex_diffuse' in inf
:
976 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
979 if mat
.SR_data
.tex_diffuse_rt
>= 0:#{
980 m
.tex_diffuse
= 0x80000000 | mat
.SR_data
.tex_diffuse_rt
983 sr_compile
.material_data
.extend( bytearray(m
) )
987 def sr_armature_bones( armature
):
989 def _recurse_bone( b
):
992 for c
in b
.children
: yield from _recurse_bone( c
)
995 for b
in armature
.data
.bones
:
997 yield from _recurse_bone( b
)
1000 def sr_entity_id( obj
):#{
1001 if not obj
: return 0
1003 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
1004 index
= sr_compile
.entity_ids
[ obj
.name
]
1006 return (tipo
&0xffff)<<16 |
(index
&0xffff)
1009 # Returns submesh_start,count and armature_id
1010 def sr_compile_mesh_internal( obj
):
1012 can_use_cache
= True
1019 for mod
in obj
.modifiers
:#{
1020 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
1021 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
1022 mod
.type == 'ARRAY':
1024 can_use_cache
= False
1027 if mod
.type == 'ARMATURE': #{
1028 armature
= mod
.object
1029 rig_weight_groups
= \
1030 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
1031 armature_id
= sr_compile
.entity_ids
[armature
.name
]
1033 POSE_OR_REST_CACHE
= armature
.data
.pose_position
1034 armature
.data
.pose_position
= 'REST'
1038 # Check the cache first
1040 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
1041 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
1042 submesh_start
= ref
[0]
1043 submesh_count
= ref
[1]
1044 return (submesh_start
,submesh_count
,armature_id
)
1047 # Compile a whole new mesh
1049 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
1052 dgraph
= bpy
.context
.evaluated_depsgraph_get()
1053 data
= obj
.evaluated_get(dgraph
).data
1054 data
.calc_loop_triangles()
1055 data
.calc_normals_split()
1057 # Mesh is split into submeshes based on their material
1059 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
1060 for material_id
, mat
in enumerate(mat_list
): #{
1064 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1065 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1068 sm
.material_id
= sr_compile_material( mat
)
1070 INF
=99999999.99999999
1071 for i
in range(3):#{
1076 # Keep a reference to very very very similar vertices
1077 # i have no idea how to speed it up.
1079 vertex_reference
= {}
1081 # Write the vertex / indice data
1083 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
1084 if tri
.material_index
!= material_id
: continue
1086 for j
in range(3):#{
1087 vert
= data
.vertices
[tri
.vertices
[j
]]
1089 vi
= data
.loops
[li
].vertex_index
1091 # Gather vertex information
1094 norm
= data
.loops
[li
].normal
1096 colour
= (255,255,255,255)
1103 uv
= data
.uv_layers
.active
.data
[li
].uv
1107 if data
.vertex_colors
:#{
1108 colour
= data
.vertex_colors
.active
.data
[li
].color
1109 colour
= (int(colour
[0]*255.0),\
1110 int(colour
[1]*255.0),\
1111 int(colour
[2]*255.0),\
1112 int(colour
[3]*255.0))
1115 # Weight groups: truncates to the 3 with the most influence. The
1116 # fourth bone ID is never used by the shader so it
1120 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
1121 if obj
.vertex_groups
[_
.group
].name
in \
1124 weight_groups
= sorted( src_groups
, key
= \
1125 lambda a
: a
.weight
, reverse
=True )
1127 for ml
in range(3):#{
1128 if len(weight_groups
) > ml
:#{
1129 g
= weight_groups
[ml
]
1130 name
= obj
.vertex_groups
[g
.group
].name
1132 weights
[ml
] = weight
1133 groups
[ml
] = rig_weight_groups
.index(name
)
1138 if len(weight_groups
) > 0:#{
1139 inv_norm
= (1.0/tot
) * 65535.0
1140 for ml
in range(3):#{
1141 weights
[ml
] = int( weights
[ml
] * inv_norm
)
1142 weights
[ml
] = min( weights
[ml
], 65535 )
1143 weights
[ml
] = max( weights
[ml
], 0 )
1148 li1
= tri
.loops
[(j
+1)%3]
1149 vi1
= data
.loops
[li1
].vertex_index
1150 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
1152 if e0
.use_freestyle_mark
and \
1153 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
1154 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
1160 TOLERENCE
= float(10**4)
1161 key
= (int(co
[0]*TOLERENCE
+0.5),
1162 int(co
[1]*TOLERENCE
+0.5),
1163 int(co
[2]*TOLERENCE
+0.5),
1164 int(norm
[0]*TOLERENCE
+0.5),
1165 int(norm
[1]*TOLERENCE
+0.5),
1166 int(norm
[2]*TOLERENCE
+0.5),
1167 int(uv
[0]*TOLERENCE
+0.5),
1168 int(uv
[1]*TOLERENCE
+0.5),
1169 colour
[0], # these guys are already quantized
1182 if key
in vertex_reference
:
1183 index
= vertex_reference
[key
]
1185 index
= bytearray(c_uint32(sm
.vertex_count
))
1188 vertex_reference
[key
] = index
1195 v
.norm
[2] = -norm
[1]
1198 v
.colour
[0] = colour
[0]
1199 v
.colour
[1] = colour
[1]
1200 v
.colour
[2] = colour
[2]
1201 v
.colour
[3] = colour
[3]
1202 v
.weights
[0] = weights
[0]
1203 v
.weights
[1] = weights
[1]
1204 v
.weights
[2] = weights
[2]
1205 v
.weights
[3] = weights
[3]
1206 v
.groups
[0] = groups
[0]
1207 v
.groups
[1] = groups
[1]
1208 v
.groups
[2] = groups
[2]
1209 v
.groups
[3] = groups
[3]
1211 for i
in range(3):#{
1212 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1213 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1216 sr_compile
.vertex_data
.extend(bytearray(v
))
1219 sm
.indice_count
+= 1
1220 sr_compile
.indice_data
.extend( index
)
1224 # Make sure bounding box isn't -inf -> inf if no vertices
1226 if sm
.vertex_count
== 0:
1231 # Add submesh to encoder
1233 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1238 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1241 # Save a reference to this mesh since we want to reuse the submesh indices
1243 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1244 return (submesh_start
,submesh_count
,armature_id
)
1247 def sr_compile_mesh( obj
):
1250 compile_obj_transform(obj
, node
.transform
)
1251 node
.pstr_name
= sr_compile_string(obj
.name
)
1252 ent_type
= obj_ent_type( obj
)
1256 if ent_type
!= 'none':#{
1257 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1258 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1259 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1262 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1263 sr_compile_mesh_internal( obj
)
1265 sr_compile
.mesh_data
.extend(bytearray(node
))
1268 def sr_compile_fonts( collection
):
1270 print( F
"[SR] Compiling fonts" )
1275 for obj
in collection
.all_objects
:#{
1276 if obj_ent_type(obj
) != 'ent_font': continue
1278 data
= obj
.SR_data
.ent_font
[0]
1281 font
.alias
= sr_compile_string( data
.alias
)
1282 font
.variant_start
= variant_count
1283 font
.variant_count
= 0
1284 font
.glyph_start
= glyph_count
1286 glyph_base
= data
.glyphs
[0].utf32
1287 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1289 font
.glyph_utf32_base
= glyph_base
1290 font
.glyph_count
= glyph_range
1292 for i
in range(len(data
.variants
)):#{
1293 data_var
= data
.variants
[i
]
1294 if not data_var
.mesh
: continue
1296 mesh
= data_var
.mesh
.data
1298 variant
= ent_font_variant()
1299 variant
.name
= sr_compile_string( data_var
.tipo
)
1301 # fonts (variants) only support one material each
1303 if len(mesh
.materials
) != 0:
1304 mat
= mesh
.materials
[0]
1305 variant
.material_id
= sr_compile_material( mat
)
1307 font
.variant_count
+= 1
1309 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1310 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1312 for j
in range(len(islands
)):#{
1313 for tri
in islands
[j
]:#{
1314 centroids
[j
].x
+= tri
.center
[0]
1315 centroids
[j
].y
+= tri
.center
[2]
1318 centroids
[j
] /= len(islands
[j
])
1321 for j
in range(glyph_range
):#{
1322 data_glyph
= data
.glyphs
[j
]
1324 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1325 glyph
.indice_count
= 0
1326 glyph
.size
[0] = data_glyph
.bounds
[2]
1327 glyph
.size
[1] = data_glyph
.bounds
[3]
1329 vertex_reference
= {}
1331 for k
in range(len(islands
)):#{
1332 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1333 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1334 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1335 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1340 for l
in range(len(islands
[k
])):#{
1342 for m
in range(3):#{
1343 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1345 vi
= mesh
.loops
[li
].vertex_index
1347 # Gather vertex information
1349 co
= [vert
.co
[_
] for _
in range(3)]
1350 co
[0] -= data_glyph
.bounds
[0]
1351 co
[2] -= data_glyph
.bounds
[1]
1352 norm
= mesh
.loops
[li
].normal
1354 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1356 TOLERENCE
= float(10**4)
1357 key
= (int(co
[0]*TOLERENCE
+0.5),
1358 int(co
[1]*TOLERENCE
+0.5),
1359 int(co
[2]*TOLERENCE
+0.5),
1360 int(norm
[0]*TOLERENCE
+0.5),
1361 int(norm
[1]*TOLERENCE
+0.5),
1362 int(norm
[2]*TOLERENCE
+0.5),
1363 int(uv
[0]*TOLERENCE
+0.5),
1364 int(uv
[1]*TOLERENCE
+0.5))
1366 if key
in vertex_reference
:
1367 index
= vertex_reference
[key
]
1369 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1370 index
= bytearray(c_uint32(vindex
))
1371 vertex_reference
[key
] = index
1378 v
.norm
[2] = -norm
[1]
1382 sr_compile
.vertex_data
.extend(bytearray(v
))
1385 glyph
.indice_count
+= 1
1386 sr_compile
.indice_data
.extend( index
)
1390 sr_ent_push( glyph
)
1392 sr_ent_push( variant
)
1398 def sr_compile_menus( collection
):
1400 print( "[SR1] Compiling menus" )
1403 for obj
in collection
.all_objects
:#{
1404 if obj_ent_type(obj
) != 'ent_menuitem': continue
1405 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1407 bitmask
= 0x00000000
1409 for col
in obj
.users_collection
:#{
1411 if name
not in groups
: groups
.append( name
)
1412 bitmask |
= (0x1 << groups
.index(name
))
1415 item
= ent_menuitem()
1416 item
.type = int( obj_data
.tipo
)
1417 item
.groups
= bitmask
1419 compile_obj_transform( obj
, item
.transform
)
1420 if obj
.type == 'MESH':#{
1421 item
.submesh_start
, item
.submesh_count
, _
= \
1422 sr_compile_mesh_internal( obj
)
1425 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1426 item_button
= item
._anonymous
_union
.button
1427 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1428 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1430 elif item
.type == 0:#{
1431 item_visual
= item
._anonymous
_union
.visual
1432 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1434 elif item
.type == 3:#{
1435 item_checkmark
= item
._anonymous
_union
.checkmark
1436 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1437 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1438 delta
= obj_data
.checkmark
.location
- obj
.location
1439 item_checkmark
.offset
[0] = delta
[0]
1440 item_checkmark
.offset
[1] = delta
[2]
1441 item_checkmark
.offset
[2] = -delta
[1]
1443 elif item
.type == 4:#{
1444 item_slider
= item
._anonymous
_union
.slider
1445 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1446 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1447 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1448 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1450 elif item
.type == 5:#{
1451 item_page
= item
._anonymous
_union
.page
1452 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1453 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1454 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1456 elif item
.type == 6:#{
1457 item_binding
= item
._anonymous
_union
.binding
1458 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1459 item_binding
.font_variant
= obj_data
.font_variant
1463 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1465 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1466 if item
.type != 4:#{
1468 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1470 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1477 def sr_compile_armature( obj
):
1479 node
= mdl_armature()
1480 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1482 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1485 bones
= [_
for _
in sr_armature_bones(obj
)]
1486 bones_names
= [None]+[_
.name
for _
in bones
]
1490 if b
.use_deform
: bone
.flags
= 0x1
1491 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1493 bone
.collider
= int(b
.SR_data
.collider
)
1495 if bone
.collider
>0:#{
1496 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1497 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1498 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1499 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1500 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1501 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1504 if b
.SR_data
.cone_constraint
:#{
1506 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1507 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1508 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1509 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1510 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1511 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1512 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1513 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1514 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1515 bone
.conet
= b
.SR_data
.conet
1518 bone
.co
[0] = b
.head_local
[0]
1519 bone
.co
[1] = b
.head_local
[2]
1520 bone
.co
[2] = -b
.head_local
[1]
1521 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1522 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1523 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1524 bone
.pstr_name
= sr_compile_string( b
.name
)
1526 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1527 if c
.type == 'IK':#{
1529 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1530 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1534 node
.bone_count
+= 1
1535 sr_compile
.bone_data
.extend(bytearray(bone
))
1540 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1541 # So we can restore later
1543 previous_frame
= bpy
.context
.scene
.frame_current
1544 previous_action
= obj
.animation_data
.action
1545 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1546 obj
.data
.pose_position
= 'POSE'
1548 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1549 for NLAStrip
in NLALayer
.strips
:#{
1552 for a
in bpy
.data
.actions
:#{
1553 if a
.name
== NLAStrip
.name
:#{
1554 obj
.animation_data
.action
= a
1559 # Clip to NLA settings
1561 anim_start
= int(NLAStrip
.action_frame_start
)
1562 anim_end
= int(NLAStrip
.action_frame_end
)
1566 anim
= mdl_animation()
1567 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1569 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1570 sizeof(mdl_transform
)
1571 anim
.length
= anim_end
-anim_start
1574 # Export the keyframes
1575 for frame
in range(anim_start
,anim_end
):#{
1576 bpy
.context
.scene
.frame_set(frame
)
1579 pb
= obj
.pose
.bones
[rb
.name
]
1581 # relative bone matrix
1582 if rb
.parent
is not None:#{
1583 offset_mtx
= rb
.parent
.matrix_local
1584 offset_mtx
= offset_mtx
.inverted_safe() @ \
1587 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1588 inv_parent
.invert_safe()
1589 fpm
= inv_parent
@ pb
.matrix
1592 bone_mtx
= rb
.matrix
.to_4x4()
1593 local_inv
= rb
.matrix_local
.inverted_safe()
1594 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1597 loc
, rot
, sca
= fpm
.decompose()
1600 lc_m
= pb
.matrix_channel
.to_3x3()
1601 if pb
.parent
is not None:#{
1602 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1603 lc_m
= smtx
.inverted() @ lc_m
1605 rq
= lc_m
.to_quaternion()
1608 kf
= mdl_transform()
1619 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1625 # Add to animation buffer
1627 sr_compile
.anim_data
.extend(bytearray(anim
))
1628 node
.anim_count
+= 1
1632 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1636 # Restore context to how it was before
1638 bpy
.context
.scene
.frame_set( previous_frame
)
1639 obj
.animation_data
.action
= previous_action
1640 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1643 sr_compile
.armature_data
.extend(bytearray(node
))
1646 def sr_ent_push( struct
):
1648 clase
= type(struct
).__name
__
1650 if clase
not in sr_compile
.entity_data
:#{
1651 sr_compile
.entity_data
[ clase
] = bytearray()
1652 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1655 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1656 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1660 def sr_array_title( arr
, name
, count
, size
, offset
):
1662 for i
in range(len(name
)):#{
1663 arr
.name
[i
] = ord(name
[i
])
1665 arr
.file_offset
= offset
1666 arr
.item_count
= count
1667 arr
.item_size
= size
1674 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1679 def sr_compile( collection
):
1681 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1684 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1685 sr_compile
.pack_animations
= collection
.SR_data
.animations
1688 sr_compile
.string_cache
= {}
1689 sr_compile
.mesh_cache
= {}
1690 sr_compile
.material_cache
= {}
1691 sr_compile
.texture_cache
= {}
1694 sr_compile
.mesh_data
= bytearray()
1695 sr_compile
.submesh_data
= bytearray()
1696 sr_compile
.vertex_data
= bytearray()
1697 sr_compile
.indice_data
= bytearray()
1698 sr_compile
.bone_data
= bytearray()
1699 sr_compile
.material_data
= bytearray()
1700 sr_compile
.armature_data
= bytearray()
1701 sr_compile
.anim_data
= bytearray()
1702 sr_compile
.keyframe_data
= bytearray()
1703 sr_compile
.texture_data
= bytearray()
1705 # just bytes not structures
1706 sr_compile
.string_data
= bytearray()
1707 sr_compile
.pack_data
= bytearray()
1710 sr_compile
.entity_data
= {}
1711 sr_compile
.entity_info
= {}
1713 print( F
"[SR] assign entity ID's" )
1714 sr_compile
.entities
= {}
1715 sr_compile
.entity_ids
= {}
1718 # -------------------------------------------------------
1720 sr_compile_string( "null" )
1723 for obj
in collection
.all_objects
: #{
1724 if obj
.type == 'MESH':#{
1728 ent_type
= obj_ent_type( obj
)
1729 if ent_type
== 'none': continue
1731 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1732 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1733 sr_compile
.entities
[ent_type
] += [obj
]
1736 print( F
"[SR] Compiling geometry" )
1738 for obj
in collection
.all_objects
:#{
1739 if obj
.type == 'MESH':#{
1742 ent_type
= obj_ent_type( obj
)
1744 # entity ignore mesh list
1746 if ent_type
== 'ent_traffic': continue
1747 if ent_type
== 'ent_prop': continue
1748 if ent_type
== 'ent_font': continue
1749 if ent_type
== 'ent_font_variant': continue
1750 if ent_type
== 'ent_menuitem': continue
1751 if ent_type
== 'ent_objective': continue
1752 if ent_type
== 'ent_region': continue
1754 #TODO: This is messy.
1755 if ent_type
== 'ent_gate':#{
1756 obj_data
= obj
.SR_data
.ent_gate
[0]
1757 if obj_data
.custom
: continue
1759 #--------------------------
1761 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1762 sr_compile_mesh( obj
)
1766 audio_clip_count
= 0
1767 entity_file_ref_count
= 0
1769 for ent_type
, arr
in sr_compile
.entities
.items():#{
1770 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1772 for i
in range(len(arr
)):#{
1775 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1777 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1778 elif ent_type
== 'ent_light': #{
1780 compile_obj_transform( obj
, light
.transform
)
1781 light
.daytime
= obj
.data
.SR_data
.daytime
1782 if obj
.data
.type == 'POINT':#{
1785 elif obj
.data
.type == 'SPOT':#{
1787 light
.angle
= obj
.data
.spot_size
*0.5
1789 light
.range = obj
.data
.cutoff_distance
1790 light
.colour
[0] = obj
.data
.color
[0]
1791 light
.colour
[1] = obj
.data
.color
[1]
1792 light
.colour
[2] = obj
.data
.color
[2]
1793 light
.colour
[3] = obj
.data
.energy
1794 sr_ent_push( light
)
1796 elif ent_type
== 'ent_camera': #{
1798 compile_obj_transform( obj
, cam
.transform
)
1799 cam
.fov
= obj
.data
.angle
* 45.0
1802 elif ent_type
== 'ent_gate': #{
1804 obj_data
= obj
.SR_data
.ent_gate
[0]
1805 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1809 if obj_data
.tipo
== 'default':#{
1810 if obj_data
.target
:#{
1811 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1815 elif obj_data
.tipo
== 'nonlocal':#{
1817 gate
.key
= sr_compile_string(obj_data
.key
)
1821 if obj_data
.flip
: flags |
= 0x0004
1822 if obj_data
.custom
:#{
1824 gate
.submesh_start
, gate
.submesh_count
, _
= \
1825 sr_compile_mesh_internal( obj
)
1827 if obj_data
.locked
: flags |
= 0x0010
1830 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1831 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1832 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1834 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1835 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1837 if obj_data
.target
:#{
1838 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1839 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1844 for x
in range(2):#{
1845 gate
.co
[x
][0] = co
[x
][0]
1846 gate
.co
[x
][1] = co
[x
][2]
1847 gate
.co
[x
][2] = -co
[x
][1]
1848 gate
.q
[x
][0] = q
[x
][1]
1849 gate
.q
[x
][1] = q
[x
][3]
1850 gate
.q
[x
][2] = -q
[x
][2]
1851 gate
.q
[x
][3] = q
[x
][0]
1856 elif ent_type
== 'ent_spawn': #{
1858 compile_obj_transform( obj
, spawn
.transform
)
1859 obj_data
= obj
.SR_data
.ent_spawn
[0]
1860 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1861 sr_ent_push( spawn
)
1863 elif ent_type
== 'ent_water':#{
1865 compile_obj_transform( obj
, water
.transform
)
1866 water
.max_dist
= 0.0
1867 sr_ent_push( water
)
1869 elif ent_type
== 'ent_audio':#{
1870 obj_data
= obj
.SR_data
.ent_audio
[0]
1872 compile_obj_transform( obj
, audio
.transform
)
1873 audio
.clip_start
= audio_clip_count
1874 audio
.clip_count
= len(obj_data
.files
)
1875 audio_clip_count
+= audio
.clip_count
1876 audio
.max_channels
= obj_data
.max_channels
1877 audio
.volume
= obj_data
.volume
1880 # - allow/disable doppler
1881 # - channel group tags with random colours
1882 # - transition properties
1884 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1885 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1886 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1887 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1888 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1889 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1890 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1892 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1893 if audio
.channel_behaviour
>= 1:#{
1894 audio
.group
= obj_data
.group
1896 if audio
.channel_behaviour
== 2:#{
1897 audio
.crossfade
= obj_data
.transition_duration
1899 audio
.probability_curve
= int(obj_data
.probability_curve
)
1901 for ci
in range(audio
.clip_count
):#{
1902 entry
= obj_data
.files
[ci
]
1903 clip
= ent_audio_clip()
1904 clip
.probability
= entry
.probability
1905 if obj_data
.formato
== '2':#{
1906 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1909 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1910 clip
._anon
.file.pack_offset
= 0
1911 clip
._anon
.file.pack_size
= 0
1915 sr_ent_push( audio
)
1917 elif ent_type
== 'ent_volume':#{
1918 obj_data
= obj
.SR_data
.ent_volume
[0]
1919 volume
= ent_volume()
1920 volume
.type = int(obj_data
.subtype
)
1921 compile_obj_transform( obj
, volume
.transform
)
1923 if obj_data
.target
:#{
1924 volume
.target
= sr_entity_id( obj_data
.target
)
1925 volume
._anon
.trigger
.event
= obj_data
.target_event
1926 volume
._anon
.trigger
.event_leave
= obj_data
.target_event_leave
1931 elif ent_type
== 'ent_marker':#{
1932 marker
= ent_marker()
1933 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1934 compile_obj_transform( obj
, marker
.transform
)
1937 elif ent_type
== 'ent_skateshop':#{
1938 skateshop
= ent_skateshop()
1939 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1940 skateshop
.type = int(obj_data
.tipo
)
1941 if skateshop
.type == 0:#{
1942 boardshop
= skateshop
._anonymous
_union
.boards
1943 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1944 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1945 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1947 elif skateshop
.type == 1:#{
1948 charshop
= skateshop
._anonymous
_union
.character
1949 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1950 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1952 elif skateshop
.type == 2:#{
1953 worldshop
= skateshop
._anonymous
_union
.worlds
1954 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1955 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1957 elif skateshop
.type == 3:#{
1958 server
= skateshop
._anonymous
_union
.server
1959 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1961 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1962 compile_obj_transform( obj
, skateshop
.transform
)
1963 sr_ent_push(skateshop
)
1965 elif ent_type
== 'ent_swspreview':#{
1966 workshop_preview
= ent_swspreview()
1967 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1968 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1969 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1970 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1971 sr_ent_push( workshop_preview
)
1973 elif ent_type
== 'ent_worldinfo':#{
1974 worldinfo
= ent_worldinfo()
1975 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1976 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1977 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1978 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1982 if obj_data
.fix_time
:#{
1983 worldinfo
.timezone
= obj_data
.fixed_time
1987 worldinfo
.timezone
= obj_data
.timezone
1989 worldinfo
.flags
= flags
1990 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1991 sr_ent_push( worldinfo
)
1993 elif ent_type
== 'ent_ccmd':#{
1995 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1996 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1999 elif ent_type
== 'ent_objective':#{
2000 objective
= ent_objective()
2001 obj_data
= obj
.SR_data
.ent_objective
[0]
2002 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
2003 objective
.id_win
= sr_entity_id( obj_data
.target
)
2004 objective
.win_event
= obj_data
.target_event
2005 objective
.filter = int(obj_data
.filtrar
)
2006 objective
.filter2
= 0
2007 objective
.time_limit
= obj_data
.time_limit
2009 compile_obj_transform( obj
, objective
.transform
)
2010 objective
.submesh_start
, objective
.submesh_count
, _
= \
2011 sr_compile_mesh_internal( obj
)
2013 sr_ent_push( objective
)
2015 elif ent_type
== 'ent_challenge':#{
2016 challenge
= ent_challenge()
2017 obj_data
= obj
.SR_data
.ent_challenge
[0]
2018 compile_obj_transform( obj
, challenge
.transform
)
2019 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2020 challenge
.target
= sr_entity_id( obj_data
.target
)
2021 challenge
.target_event
= obj_data
.target_event
2022 challenge
.reset
= sr_entity_id( obj_data
.reset
)
2023 challenge
.reset_event
= obj_data
.reset_event
2024 challenge
.first
= sr_entity_id( obj_data
.first
)
2025 challenge
.flags
= 0x00
2026 challenge
.camera
= sr_entity_id( obj_data
.camera
)
2027 if obj_data
.time_limit
: challenge
.flags |
= 0x01
2028 challenge
.status
= 0
2029 sr_ent_push( challenge
)
2031 elif ent_type
== 'ent_region':#{
2032 region
= ent_region()
2033 obj_data
= obj
.SR_data
.ent_region
[0]
2034 compile_obj_transform( obj
, region
.transform
)
2035 region
.submesh_start
, region
.submesh_count
, _
= \
2036 sr_compile_mesh_internal( obj
)
2037 region
.pstr_title
= sr_compile_string( obj_data
.title
)
2038 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
2039 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
2040 region
.target0
[1] = obj_data
.target0_event
2041 sr_ent_push( region
)
2043 elif ent_type
== 'ent_relay':#{
2045 obj_data
= obj
.SR_data
.ent_relay
[0]
2046 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
2047 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
2048 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
2049 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
2050 relay
.targets
[0][1] = obj_data
.target0_event
2051 relay
.targets
[1][1] = obj_data
.target1_event
2052 relay
.targets
[2][1] = obj_data
.target2_event
2053 relay
.targets
[3][1] = obj_data
.target3_event
2054 sr_ent_push( relay
)
2056 # elif ent_type == 'ent_list':#{
2057 # lista = ent_list()
2058 # obj_data = obj.SR_data.ent_list[0]
2060 # lista.entity_ref_start = entity_file_ref_count
2061 # lista.entity_ref_count = len( obj_data.entities )
2062 # entity_file_ref_count += lista.entity_ref_count
2064 # for child in obj_data.entities:#{
2065 # reference_struct = file_entity_ref()
2066 # reference_struct.index = sr_entity_id( child.target )
2067 # sr_ent_push( reference_struct )
2070 # sr_ent_push( lista )
2072 elif ent_type
== 'ent_glider':#{
2073 glider
= ent_glider()
2074 compile_obj_transform( obj
, glider
.transform
)
2075 sr_ent_push( glider
)
2077 elif ent_type
== 'ent_npc':#{
2078 obj_data
= obj
.SR_data
.ent_npc
[0]
2080 compile_obj_transform( obj
, npc
.transform
)
2081 npc
.id = obj_data
.au
2082 npc
.context
= obj_data
.context
2083 npc
.camera
= sr_entity_id( obj_data
.cam
)
2086 elif ent_type
== 'ent_cubemap':#{
2087 cubemap
= ent_cubemap()
2088 co
= obj
.matrix_world
@ Vector((0,0,0))
2089 cubemap
.co
[0] = co
[0]
2090 cubemap
.co
[1] = co
[2]
2091 cubemap
.co
[2] = -co
[1]
2092 cubemap
.resolution
= 0
2094 sr_ent_push( cubemap
)
2096 elif ent_type
== 'ent_miniworld':#{
2097 miniworld
= ent_miniworld()
2098 obj_data
= obj
.SR_data
.ent_miniworld
[0]
2100 compile_obj_transform( obj
, miniworld
.transform
)
2101 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
2102 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
2103 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
2104 sr_ent_push( miniworld
)
2106 elif ent_type
== 'ent_prop':#{
2108 obj_data
= obj
.SR_data
.ent_prop
[0]
2109 compile_obj_transform( obj
, prop
.transform
)
2110 prop
.submesh_start
, prop
.submesh_count
, _
= \
2111 sr_compile_mesh_internal( obj
)
2112 prop
.flags
= obj_data
.flags
2113 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2119 sr_compile_menus( collection
)
2120 sr_compile_fonts( collection
)
2122 def _children( col
):#{
2124 for c
in col
.children
:#{
2125 yield from _children(c
)
2129 checkpoint_count
= 0
2130 pathindice_count
= 0
2133 for col
in _children(collection
):#{
2134 print( F
"Adding routes for subcollection: {col.name}" )
2140 for obj
in col
.objects
:#{
2141 if obj
.type == 'ARMATURE': pass
2143 ent_type
= obj_ent_type( obj
)
2145 if ent_type
== 'ent_gate':
2146 route_gates
+= [obj
]
2147 elif ent_type
== 'ent_route_node':#{
2148 if obj
.type == 'CURVE':#{
2149 route_curves
+= [obj
]
2152 elif ent_type
== 'ent_route':
2154 elif ent_type
== 'ent_traffic':
2159 dij
= create_node_graph( route_curves
, route_gates
)
2161 for obj
in routes
:#{
2162 obj_data
= obj
.SR_data
.ent_route
[0]
2164 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
2165 route
.checkpoints_start
= checkpoint_count
2166 route
.checkpoints_count
= 0
2167 route
.id_camera
= sr_entity_id( obj_data
.cam
)
2170 route
.colour
[ci
] = obj_data
.colour
[ci
]
2171 route
.colour
[3] = 1.0
2173 compile_obj_transform( obj
, route
.transform
)
2174 checkpoints
= obj_data
.gates
2176 for i
in range(len(checkpoints
)):#{
2177 gi
= checkpoints
[i
].target
2178 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
2182 dest
= gi
.SR_data
.ent_gate
[0].target
2186 if gi
==gj
: continue # error?
2187 if not gi
or not gj
: continue
2189 checkpoint
= ent_checkpoint()
2190 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
2191 checkpoint
.path_start
= pathindice_count
2192 checkpoint
.path_count
= 0
2194 path
= solve_graph( dij
, gi
.name
, gj
.name
)
2197 for pi
in range(len(path
)):#{
2198 pathindice
= ent_path_index()
2199 pathindice
.index
= routenode_count
+ path
[pi
]
2200 sr_ent_push( pathindice
)
2202 checkpoint
.path_count
+= 1
2203 pathindice_count
+= 1
2207 sr_ent_push( checkpoint
)
2208 route
.checkpoints_count
+= 1
2209 checkpoint_count
+= 1
2212 sr_ent_push( route
)
2215 for obj
in traffics
:#{
2216 traffic
= ent_traffic()
2217 compile_obj_transform( obj
, traffic
.transform
)
2218 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2219 sr_compile_mesh_internal( obj
)
2221 # find best subsection
2223 graph_keys
= list(dij
.graph
)
2227 for j
in range(len(dij
.points
)):#{
2228 point
= dij
.points
[j
]
2229 dist
= (point
-obj
.location
).magnitude
2231 if dist
< min_dist
:#{
2238 best_begin
= best_point
2239 best_end
= best_point
2242 map0
= dij
.subsections
[best_begin
]
2243 if map0
[1] == -1: break
2244 best_begin
= map0
[1]
2247 map1
= dij
.subsections
[best_end
]
2248 if map1
[2] == -1: break
2252 traffic
.start_node
= routenode_count
+ best_begin
2253 traffic
.node_count
= best_end
- best_begin
2254 traffic
.index
= best_point
- best_begin
2255 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2258 sr_ent_push(traffic
)
2261 for point
in dij
.points
:#{
2262 rn
= ent_route_node()
2265 rn
.co
[2] = -point
[1]
2269 routenode_count
+= len(dij
.points
)
2272 print( F
"[SR] Writing file" )
2274 file_array_instructions
= {}
2277 def _write_array( name
, item_size
, data
):#{
2278 nonlocal file_array_instructions
, file_offset
2280 count
= len(data
)//item_size
2281 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2282 'data':data
, 'offset': file_offset
}
2283 file_offset
+= len(data
)
2284 file_offset
= int_align_to( file_offset
, 8 )
2287 _write_array( 'strings', 1, sr_compile
.string_data
)
2288 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2289 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2290 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2291 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2292 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2293 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2295 for name
, buffer in sr_compile
.entity_data
.items():#{
2296 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2299 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2300 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2301 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2302 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2303 _write_array( 'pack', 1, sr_compile
.pack_data
)
2305 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2306 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2308 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2309 path
= F
"{folder}{collection.name}.mdl"
2312 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2313 fp
= open( path
, "wb" )
2314 header
= mdl_header()
2315 header
.version
= MDL_VERSION_NR
2316 sr_array_title( header
.arrays
, \
2317 'index', len(file_array_instructions
), \
2318 sizeof(mdl_array
), header_size
)
2320 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2322 print( F
'[SR] {"name":>16}| count | offset' )
2324 for name
,info
in file_array_instructions
.items():#{
2326 offset
= info
['offset'] + header_size
+ index_size
2327 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2328 index
.extend( bytearray(arr
) )
2330 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2331 F
' 0x{info["offset"]:02x}' )
2333 fp
.write( bytearray_align_to( index
, 8 ) )
2334 #bytearray_print_hex( index )
2336 for name
,info
in file_array_instructions
.items():#{
2337 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2342 print( '[SR] done' )
2345 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2347 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2348 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2349 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2351 panel
: bpy
.props
.EnumProperty(
2355 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2356 ('ENTITY', 'Entity', '', 'MONKEY',1),
2357 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2362 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2364 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2365 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2368 def sr_get_mirror_bone( bones
):
2370 side
= bones
.active
.name
[-1:]
2371 other_name
= bones
.active
.name
[:-1]
2372 if side
== 'L': other_name
+= 'R'
2373 elif side
== 'R': other_name
+= 'L'
2377 if b
.name
== other_name
:
2384 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2386 bl_idname
="skaterift.mirror_bone"
2387 bl_label
="Mirror bone attributes - SkateRift"
2389 def execute(_
,context
):
2391 active_object
= context
.active_object
2392 bones
= active_object
.data
.bones
2394 b
= sr_get_mirror_bone( bones
)
2396 if not b
: return {'FINISHED'}
2398 b
.SR_data
.collider
= a
.SR_data
.collider
2400 def _v3copyflipy( a
, b
):#{
2406 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2407 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2408 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2409 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2411 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2413 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2414 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2415 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2417 b
.SR_data
.conet
= a
.SR_data
.conet
2420 ob
= bpy
.context
.scene
.objects
[0]
2421 ob
.hide_render
= ob
.hide_render
2426 class SR_COMPILE(bpy
.types
.Operator
):
2428 bl_idname
="skaterift.compile_all"
2429 bl_label
="Compile All"
2431 def execute(_
,context
):
2433 view_layer
= bpy
.context
.view_layer
2434 for col
in view_layer
.layer_collection
.children
["export"].children
:
2435 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2436 sr_compile( bpy
.data
.collections
[col
.name
] )
2442 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2444 bl_idname
="skaterift.compile_this"
2445 bl_label
="Compile This collection"
2447 def execute(_
,context
):
2449 col
= bpy
.context
.collection
2456 class SR_INTERFACE(bpy
.types
.Panel
):
2458 bl_idname
= "VIEW3D_PT_skate_rift"
2459 bl_label
= "Skate Rift"
2460 bl_space_type
= 'VIEW_3D'
2461 bl_region_type
= 'UI'
2462 bl_category
= "Skate Rift"
2464 def draw(_
, context
):
2468 row
= _
.layout
.row()
2470 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2472 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2473 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2475 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2476 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2477 col
= bpy
.context
.collection
2479 found_in_export
= False
2481 view_layer
= bpy
.context
.view_layer
2482 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2483 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2486 if c1
.name
== col
.name
: #{
2487 found_in_export
= True
2491 box
= _
.layout
.box()
2493 row
.alignment
= 'CENTER'
2496 if found_in_export
: #{
2497 row
.label( text
=col
.name
+ ".mdl" )
2498 box
.prop( col
.SR_data
, "pack_textures" )
2499 box
.prop( col
.SR_data
, "animations" )
2500 box
.operator( "skaterift.compile_this" )
2504 row
.label( text
=col
.name
)
2508 row
.alignment
= 'CENTER'
2510 row
.label( text
="This collection is not in the export group" )
2513 box
= _
.layout
.box()
2516 split
= row
.split( factor
=0.3, align
=True )
2517 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2520 if export_count
== 0:
2522 row1
.operator( "skaterift.compile_all", \
2523 text
=F
"Compile all ({export_count} collections)" )
2525 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2526 active_object
= context
.active_object
2527 if not active_object
: return
2529 amount
= max( 0, len(context
.selected_objects
)-1 )
2531 row
= _
.layout
.row()
2532 row
.operator( 'skaterift.copy_entity_data', \
2533 text
=F
'Copy entity data to {amount} other objects' )
2534 if amount
== 0: row
.enabled
=False
2536 box
= _
.layout
.box()
2538 row
.alignment
= 'CENTER'
2539 row
.label( text
=active_object
.name
)
2542 def _draw_prop_collection( source
, data
): #{
2545 row
.alignment
= 'CENTER'
2548 row
.label( text
=F
'{source}' )
2550 if hasattr(type(data
[0]),'sr_inspector'):#{
2551 type(data
[0]).sr_inspector( box
, data
)
2554 for a
in data
[0].__annotations
__:
2555 box
.prop( data
[0], a
)
2559 if active_object
.type == 'ARMATURE': #{
2560 if active_object
.mode
== 'POSE': #{
2561 bones
= active_object
.data
.bones
2562 mb
= sr_get_mirror_bone( bones
)
2564 box
.operator( "skaterift.mirror_bone", \
2565 text
=F
'Mirror attributes to {mb.name}' )
2568 _draw_prop_collection( \
2569 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2570 [bones
.active
.SR_data
] )
2574 row
.alignment
='CENTER'
2577 row
.label( text
="Enter pose mode to modify bone properties" )
2580 elif active_object
.type == 'LIGHT': #{
2581 _draw_prop_collection( \
2582 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2583 [active_object
.data
.SR_data
] )
2585 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2586 box
.prop( active_object
.SR_data
, "ent_type" )
2587 ent_type
= active_object
.SR_data
.ent_type
2589 col
= getattr( active_object
.SR_data
, ent_type
, None )
2590 if col
!= None and len(col
)!=0:
2591 _draw_prop_collection( \
2592 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2595 if active_object
.type == 'MESH':#{
2596 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2597 if col
!= None and len(col
)!=0:
2598 _draw_prop_collection( \
2599 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2607 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2609 bl_label
="Skate Rift material"
2610 bl_idname
="MATERIAL_PT_sr_material"
2611 bl_space_type
='PROPERTIES'
2612 bl_region_type
='WINDOW'
2613 bl_context
="material"
2615 def draw(_
,context
):
2617 active_object
= bpy
.context
.active_object
2618 if active_object
== None: return
2619 active_mat
= active_object
.active_material
2620 if active_mat
== None: return
2622 info
= material_info( active_mat
)
2624 if 'tex_diffuse' in info
:#{
2625 _
.layout
.label( icon
='INFO', \
2626 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2629 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2630 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2631 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2633 if active_mat
.SR_data
.collision
:#{
2634 box
= _
.layout
.box()
2637 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2638 (active_mat
.SR_data
.shader
!= 'boundary') and \
2639 (active_mat
.SR_data
.shader
!= 'walking'):#{
2640 row
.prop( active_mat
.SR_data
, "skate_surface" )
2641 row
.prop( active_mat
.SR_data
, "grind_surface" )
2642 row
.prop( active_mat
.SR_data
, "grow_grass" )
2643 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2647 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2648 box
= _
.layout
.box()
2649 box
.prop( active_mat
.SR_data
, "blend_offset" )
2650 box
.prop( active_mat
.SR_data
, "sand_colour" )
2652 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2653 box
= _
.layout
.box()
2654 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2655 box
.prop( active_mat
.SR_data
, "blend_offset" )
2657 elif active_mat
.SR_data
.shader
== "water":#{
2658 box
= _
.layout
.box()
2659 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2660 box
.prop( active_mat
.SR_data
, "shore_colour" )
2661 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2663 elif active_mat
.SR_data
.shader
== "cubemap":#{
2664 box
= _
.layout
.box()
2665 box
.prop( active_mat
.SR_data
, "cubemap" )
2666 box
.prop( active_mat
.SR_data
, "tint" )
2669 _
.layout
.label( text
="" )
2670 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2671 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2675 def sr_get_type_enum( scene
, context
):
2677 items
= [('none','None',"")]
2678 mesh_entities
=['ent_gate','ent_water']
2679 point_entities
=['ent_spawn','ent_route_node','ent_route']
2681 for e
in point_entities
: items
+= [(e
,e
,'')]
2683 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2684 if context
.active_object
.type == 'MESH': #{
2685 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2689 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2695 def sr_on_type_change( _
, context
):
2697 obj
= context
.active_object
2698 ent_type
= obj
.SR_data
.ent_type
2699 if ent_type
== 'none': return
2700 if obj
.type == 'MESH':#{
2701 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2702 if col
!= None and len(col
)==0: col
.add()
2705 col
= getattr( obj
.SR_data
, ent_type
, None )
2706 if col
!= None and len(col
)==0: col
.add()
2709 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2711 alias
: bpy
.props
.StringProperty( name
='alias' )
2714 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2716 target
: bpy
.props
.PointerProperty( \
2717 type=bpy
.types
.Object
, name
="destination", \
2718 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2720 key
: bpy
.props
.StringProperty()
2721 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2722 ('nonlocal', 'Non-Local', "")))
2724 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2725 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2726 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2729 def sr_inspector( layout
, data
):
2732 box
.prop( data
[0], 'tipo', text
="subtype" )
2734 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2735 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2738 flags
.prop( data
[0], 'flip' )
2739 flags
.prop( data
[0], 'custom' )
2740 flags
.prop( data
[0], 'locked' )
2744 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2746 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2749 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2751 target
: bpy
.props
.PointerProperty( \
2752 type=bpy
.types
.Object
, name
='target', \
2753 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2756 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2758 world
: bpy
.props
.StringProperty( name
='world UID' )
2759 proxy
: bpy
.props
.PointerProperty( \
2760 type=bpy
.types
.Object
, name
='proxy', \
2761 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2762 camera
: bpy
.props
.PointerProperty( \
2763 type=bpy
.types
.Object
, name
="Camera", \
2764 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2767 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2769 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2771 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2773 layout
.prop( item
, 'target', text
='', emboss
=False )
2777 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2779 active_object
= context
.active_object
2780 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2781 lista
= getattr(data
,collection_name
)
2782 index
= getattr(data
,F
'{collection_name}_index')
2786 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2790 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2792 active_object
= context
.active_object
2793 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2797 def copy_propgroup( de
, to
):
2799 for a
in de
.__annotations
__:#{
2800 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2804 while len(cb
) != len(ca
):#{
2805 if len(cb
) < len(ca
): cb
.add()
2808 for i
in range(len(ca
)):#{
2809 copy_propgroup(ca
[i
],cb
[i
])
2813 setattr(to
,a
,getattr(de
,a
))
2818 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2820 bl_idname
= "skaterift.copy_entity_data"
2821 bl_label
= "Copy entity data"
2823 def execute(self
, context
):#{
2824 data
= context
.active_object
.SR_data
2825 new_type
= data
.ent_type
2826 print( F
"Copy entity data from: {context.active_object.name}" )
2828 for obj
in context
.selected_objects
:#{
2829 if obj
!= context
.active_object
:#{
2830 print( F
" To: {obj.name}" )
2832 obj
.SR_data
.ent_type
= new_type
2834 if active_object
.type == 'MESH':#{
2835 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2836 if col
!= None and len(col
)==0: col
.add()
2837 mdata
= context
.active_object
.data
.SR_data
2838 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2841 col
= getattr( obj
.SR_data
, new_type
, None )
2842 if col
!= None and len(col
)==0: col
.add()
2843 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2850 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2852 bl_idname
= "skaterift.new_entry"
2853 bl_label
= "Add gate"
2855 def execute(self
, context
):#{
2856 return internal_listadd_execute(self
,context
,'ent_route','gates')
2860 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2862 bl_idname
= "skaterift.del_entry"
2863 bl_label
= "Remove gate"
2866 def poll(cls
, context
):#{
2867 active_object
= context
.active_object
2868 if obj_ent_type(active_object
) == 'ent_route':#{
2869 return active_object
.SR_data
.ent_route
[0].gates
2874 def execute(self
, context
):#{
2875 return internal_listdel_execute(self
,context
,'ent_route','gates')
2879 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2881 bl_idname
= "skaterift.al_new_entry"
2882 bl_label
= "Add file"
2884 def execute(self
, context
):#{
2885 return internal_listadd_execute(self
,context
,'ent_audio','files')
2889 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2891 bl_idname
= "skaterift.al_del_entry"
2892 bl_label
= "Remove file"
2895 def poll(cls
, context
):#{
2896 active_object
= context
.active_object
2897 if obj_ent_type(active_object
) == 'ent_audio':#{
2898 return active_object
.SR_data
.ent_audio
[0].files
2903 def execute(self
, context
):#{
2904 return internal_listdel_execute(self
,context
,'ent_audio','files')
2909 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2911 bl_idname
= "skaterift.gl_new_entry"
2912 bl_label
= "Add glyph"
2914 def execute(self
, context
):#{
2915 active_object
= context
.active_object
2917 font
= active_object
.SR_data
.ent_font
[0]
2920 if len(font
.glyphs
) > 1:#{
2921 prev
= font
.glyphs
[-2]
2922 cur
= font
.glyphs
[-1]
2924 cur
.bounds
= prev
.bounds
2925 cur
.utf32
= prev
.utf32
+1
2932 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2934 bl_idname
= "skaterift.gl_del_entry"
2935 bl_label
= "Remove Glyph"
2938 def poll(cls
, context
):#{
2939 active_object
= context
.active_object
2940 if obj_ent_type(active_object
) == 'ent_font':#{
2941 return active_object
.SR_data
.ent_font
[0].glyphs
2946 def execute(self
, context
):#{
2947 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2951 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2953 bl_idname
= "skaterift.gl_move_item"
2955 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2956 ('DOWN', 'Down', ""),))
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(_
, context
):#{
2968 active_object
= context
.active_object
2969 data
= active_object
.SR_data
.ent_font
[0]
2971 index
= data
.glyphs_index
2972 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2973 data
.glyphs
.move( neighbor
, index
)
2975 list_length
= len(data
.glyphs
) - 1
2976 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2978 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2984 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2986 bl_idname
= "skaterift.fv_new_entry"
2987 bl_label
= "Add variant"
2989 def execute(self
, context
):#{
2990 return internal_listadd_execute(self
,context
,'ent_font','variants')
2994 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2996 bl_idname
= "skaterift.fv_del_entry"
2997 bl_label
= "Remove variant"
3000 def poll(cls
, context
):#{
3001 active_object
= context
.active_object
3002 if obj_ent_type(active_object
) == 'ent_font':#{
3003 return active_object
.SR_data
.ent_font
[0].variants
3008 def execute(self
, context
):#{
3009 return internal_listdel_execute(self
,context
,'ent_font','variants')
3013 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
3015 path
: bpy
.props
.StringProperty( name
="Path" )
3016 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
3019 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
3021 bl_idname
= 'SR_UL_AUDIO_LIST'
3023 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3025 split
= layout
.split(factor
=0.7)
3027 c
.prop( item
, 'path', text
='', emboss
=False )
3029 c
.prop( item
, 'probability', text
='%', emboss
=True )
3033 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
3035 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
3037 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3039 layout
.prop( item
, 'mesh', emboss
=False )
3040 layout
.prop( item
, 'tipo' )
3044 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
3046 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
3048 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3050 s0
= layout
.split(factor
=0.3)
3052 s1
= c
.split(factor
=0.3)
3055 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
3059 c
.prop( item
, 'utf32', text
='', emboss
=True )
3062 row
.prop( item
, 'bounds', text
='', emboss
=False )
3066 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
3068 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
3069 gates_index
: bpy
.props
.IntProperty()
3071 colour
: bpy
.props
.FloatVectorProperty( \
3075 default
=Vector((0.79,0.63,0.48)),\
3076 description
="Route colour"\
3079 alias
: bpy
.props
.StringProperty(\
3081 default
="Untitled Course")
3083 cam
: bpy
.props
.PointerProperty( \
3084 type=bpy
.types
.Object
, name
="Viewpoint", \
3085 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3088 def sr_inspector( layout
, data
):
3090 layout
.prop( data
[0], 'alias' )
3091 layout
.prop( data
[0], 'colour' )
3092 layout
.prop( data
[0], 'cam' )
3094 layout
.label( text
='Checkpoints' )
3095 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
3096 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
3099 row
.operator( 'skaterift.new_entry', text
='Add' )
3100 row
.operator( 'skaterift.del_entry', text
='Remove' )
3105 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
3106 bl_idname
= "skaterift.ent_list_new_entry"
3107 bl_label
= "Add entity"
3109 def execute(self
, context
):#{
3110 return internal_listadd_execute(self
,context
,'ent_list','entities')
3114 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
3115 bl_idname
= "skaterift.ent_list_del_entry"
3116 bl_label
= "Remove entity"
3119 def poll(cls
, context
):#{
3120 active_object
= context
.active_object
3121 if obj_ent_type(active_object
) == 'ent_list':#{
3122 return active_object
.SR_data
.ent_list
[0].entities
3127 def execute(self
, context
):#{
3128 return internal_listdel_execute(self
,context
,'ent_list','entities')
3132 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
3134 target
: bpy
.props
.PointerProperty( \
3135 type=bpy
.types
.Object
, name
='target' )
3138 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
3139 bl_idname
= 'SR_UL_ENT_LIST'
3141 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
3142 layout
.prop( item
, 'target', text
='', emboss
=False )
3146 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
3147 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
3148 entities_index
: bpy
.props
.IntProperty()
3151 def sr_inspector( layout
, data
):#{
3152 layout
.label( text
='Entities' )
3153 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
3154 data
[0], 'entities', data
[0], \
3155 'entities_index', rows
=5)
3158 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
3159 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
3163 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
3164 nothing
: bpy
.props
.StringProperty()
3167 class SR_OBJECT_ENT_NPC(bpy
.types
.PropertyGroup
):#{
3168 au
: bpy
.props
.IntProperty()
3169 context
: bpy
.props
.IntProperty()
3170 cam
: bpy
.props
.PointerProperty( \
3171 type=bpy
.types
.Object
, name
="Viewpoint", \
3172 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3175 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
3176 subtype
: bpy
.props
.EnumProperty(
3178 items
=[('0','Trigger',''),
3179 ('1','Particles (0.1s)','')]
3182 target
: bpy
.props
.PointerProperty( \
3183 type=bpy
.types
.Object
, name
="Target", \
3184 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3185 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
3186 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
3189 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
3191 box
.prop( data
[0], propname
)
3193 for evname
in evs
:#{
3195 row
.prop( data
[0], propname
+ evname
)
3197 target
= getattr( data
[0], propname
)
3199 tipo
= target
.SR_data
.ent_type
3200 cls
= globals()[ tipo
]
3202 table
= getattr( cls
, 'sr_functions', None )
3204 index
= getattr( data
[0], propname
+ evname
)
3206 row
.label( text
=table
[index
] )
3208 row
.label( text
="undefined function" )
3212 row
.label( text
="..." )
3219 def sr_inspector( layout
, data
):#{
3220 layout
.prop( data
[0], 'subtype' )
3221 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3222 ['_event','_event_leave'] )
3226 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3228 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3229 files_index
: bpy
.props
.IntProperty()
3231 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3232 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3233 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3234 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3236 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3237 formato
: bpy
.props
.EnumProperty(
3239 items
=[('0','Uncompressed Mono',''),
3240 ('1','Compressed Vorbis',''),
3241 ('2','[vg] Bird Synthesis','')]
3243 probability_curve
: bpy
.props
.EnumProperty(
3244 name
="Probability Curve",
3245 items
=[('0','Constant',''),
3246 ('1','Wildlife Daytime',''),
3247 ('2','Wildlife Nighttime','')])
3248 channel_behaviour
: bpy
.props
.EnumProperty(
3249 name
="Channel Behaviour",
3250 items
=[('0','Unlimited',''),
3251 ('1','Discard if group full', ''),
3252 ('2','Crossfade if group full','')])
3254 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3257 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3258 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3261 def sr_inspector( layout
, data
):
3263 layout
.prop( data
[0], 'formato' )
3264 layout
.prop( data
[0], 'volume' )
3267 box
.label( text
='Channels' )
3268 split
= box
.split(factor
=0.3)
3270 c
.prop( data
[0], 'max_channels' )
3272 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3273 if data
[0].channel_behaviour
>= '1':
3274 box
.prop( data
[0], 'group' )
3275 if data
[0].channel_behaviour
== '2':
3276 box
.prop( data
[0], 'transition_duration' )
3279 box
.label( text
='Flags' )
3280 box
.prop( data
[0], 'flag_3d' )
3281 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3283 box
.prop( data
[0], 'flag_loop' )
3284 box
.prop( data
[0], 'flag_auto' )
3286 layout
.prop( data
[0], 'probability_curve' )
3288 split
= layout
.split(factor
=0.7)
3290 c
.label( text
='Filepath' )
3292 c
.label( text
='Chance' )
3293 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3294 data
[0], 'files', data
[0], 'files_index', rows
=5)
3297 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3298 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3302 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3304 alias
: bpy
.props
.StringProperty()
3305 flags
: bpy
.props
.IntProperty()
3308 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3310 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3311 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3312 utf32
: bpy
.props
.IntProperty()
3315 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3317 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3318 utf32
: bpy
.props
.IntProperty()
3321 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3323 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3324 tipo
: bpy
.props
.StringProperty()
3327 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3329 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3330 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3331 alias
: bpy
.props
.StringProperty()
3333 glyphs_index
: bpy
.props
.IntProperty()
3334 variants_index
: bpy
.props
.IntProperty()
3337 def sr_inspector( layout
, data
):
3339 layout
.prop( data
[0], 'alias' )
3341 layout
.label( text
='Variants' )
3342 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3343 data
[0], 'variants', data
[0], 'variants_index',\
3346 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3347 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3349 layout
.label( text
='ASCII Glyphs' )
3350 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3351 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3354 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3355 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3356 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3357 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3361 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3363 speed
: bpy
.props
.FloatProperty(default
=1.0)
3366 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3368 tipo
: bpy
.props
.EnumProperty( name
='Type',
3369 items
=[('0','boards',''),
3370 ('1','character',''),
3372 ('4','server','')] )
3373 mark_rack
: bpy
.props
.PointerProperty( \
3374 type=bpy
.types
.Object
, name
="Board Rack", \
3375 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3376 mark_display
: bpy
.props
.PointerProperty( \
3377 type=bpy
.types
.Object
, name
="Selected Board Display", \
3378 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3379 mark_info
: bpy
.props
.PointerProperty( \
3380 type=bpy
.types
.Object
, name
="Selected Board Info", \
3381 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3382 ['ent_marker','ent_prop']))
3383 cam
: bpy
.props
.PointerProperty( \
3384 type=bpy
.types
.Object
, name
="Viewpoint", \
3385 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3388 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3390 mark_display
: bpy
.props
.PointerProperty( \
3391 type=bpy
.types
.Object
, name
="Board Display", \
3392 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3393 mark_display1
: bpy
.props
.PointerProperty( \
3394 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3395 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3396 cam
: bpy
.props
.PointerProperty( \
3397 type=bpy
.types
.Object
, name
="Viewpoint", \
3398 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3401 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3403 link0
: bpy
.props
.PointerProperty( \
3404 type=bpy
.types
.Object
, name
="Link 0", \
3405 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3406 link1
: bpy
.props
.PointerProperty( \
3407 type=bpy
.types
.Object
, name
="Link 1", \
3408 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3409 link2
: bpy
.props
.PointerProperty( \
3410 type=bpy
.types
.Object
, name
="Link 2", \
3411 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3412 link3
: bpy
.props
.PointerProperty( \
3413 type=bpy
.types
.Object
, name
="Link 3", \
3414 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3416 newloc
: bpy
.props
.PointerProperty( \
3417 type=bpy
.types
.Object
, name
="New location", \
3418 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3419 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3420 items
=[('0','append',''),
3421 ('1','replace','')])
3423 camera
: bpy
.props
.PointerProperty( \
3424 type=bpy
.types
.Object
, name
="Camera", \
3425 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3427 slider_minloc
: bpy
.props
.PointerProperty( \
3428 type=bpy
.types
.Object
, name
="Slider min", \
3429 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3430 slider_maxloc
: bpy
.props
.PointerProperty( \
3431 type=bpy
.types
.Object
, name
="Slider max", \
3432 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3433 slider_handle
: bpy
.props
.PointerProperty( \
3434 type=bpy
.types
.Object
, name
="Slider handle", \
3435 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3437 checkmark
: bpy
.props
.PointerProperty( \
3438 type=bpy
.types
.Object
, name
="Checked", \
3439 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3441 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3443 string
: bpy
.props
.StringProperty( name
="String" )
3444 tipo
: bpy
.props
.EnumProperty( name
='Type',
3445 items
=[('0','visual',''),
3446 ('1','event button',''),
3447 ('2','page button',''),
3452 ('7','visual(no colourize)','')])
3455 def sr_inspector( layout
, data
):
3459 box
.prop( data
, 'tipo' )
3461 if data
.tipo
== '0' or data
.tipo
== '7':#{
3462 box
.prop( data
, 'string', text
='Name' )
3465 elif data
.tipo
== '1':#{
3466 box
.prop( data
, 'string', text
='Event' )
3468 elif data
.tipo
== '2':#{
3469 box
.prop( data
, 'string', text
='Page' )
3470 box
.prop( data
, 'stack_behaviour' )
3472 elif data
.tipo
== '3':#{
3473 box
.prop( data
, 'string', text
='Data (i32)' )
3474 box
.prop( data
, 'checkmark' )
3476 elif data
.tipo
== '4':#{
3477 box
.prop( data
, 'string', text
='Data (f32)' )
3478 box
.prop( data
, 'slider_minloc' )
3479 box
.prop( data
, 'slider_maxloc' )
3480 box
.prop( data
, 'slider_handle' )
3482 box
.label( text
="Links" )
3483 box
.prop( data
, 'link0', text
='v0' )
3484 box
.prop( data
, 'link1', text
='v1' )
3487 elif data
.tipo
== '5':#{
3488 box
.prop( data
, 'string', text
='Page Name' )
3489 box
.prop( data
, 'newloc', text
='Entry Point' )
3490 box
.prop( data
, 'camera', text
='Viewpoint' )
3493 elif data
.tipo
== '6':#{
3494 box
.prop( data
, 'string', text
='ID' )
3495 box
.prop( data
, 'font_variant' )
3500 box
.label( text
="Links" )
3501 box
.prop( data
, 'link0' )
3502 box
.prop( data
, 'link1' )
3503 box
.prop( data
, 'link2' )
3504 box
.prop( data
, 'link3' )
3508 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3510 name
: bpy
.props
.StringProperty(name
="Name")
3511 desc
: bpy
.props
.StringProperty(name
="Description")
3512 author
: bpy
.props
.StringProperty(name
="Author")
3513 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3515 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3516 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3517 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3520 def sr_inspector( layout
, data
):#{
3521 layout
.prop( data
[0], 'name' )
3522 layout
.prop( data
[0], 'desc' )
3523 layout
.prop( data
[0], 'author' )
3525 layout
.prop( data
[0], 'fix_time' )
3526 if data
[0].fix_time
:
3527 layout
.prop( data
[0], 'fixed_time' )
3529 layout
.prop( data
[0], 'timezone' )
3533 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3535 command
: bpy
.props
.StringProperty(name
="Command Line")
3538 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3539 proxima
: bpy
.props
.PointerProperty( \
3540 type=bpy
.types
.Object
, name
="Next", \
3541 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3542 target
: bpy
.props
.PointerProperty( \
3543 type=bpy
.types
.Object
, name
="Win", \
3544 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3545 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3546 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3547 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3548 items
=[('0','none',''),
3549 (str(0x1),'trick_shuvit',''),
3550 (str(0x2),'trick_kickflip',''),
3551 (str(0x4),'trick_treflip',''),
3552 (str(0x1|
0x2|
0x4),'trick_any',''),
3553 (str(0x8),'flip_back',''),
3554 (str(0x10),'flip_front',''),
3555 (str(0x8|
0x10),'flip_any',''),
3556 (str(0x20),'grind_truck_any',''),
3557 (str(0x40),'grind_board_any',''),
3558 (str(0x20|
0x40),'grind_any',''),
3559 (str(0x80),'footplant',''),
3560 (str(0x100),'passthrough',''),
3564 def sr_inspector( layout
, data
):#{
3565 layout
.prop( data
[0], 'proxima' )
3566 layout
.prop( data
[0], 'time_limit' )
3567 layout
.prop( data
[0], 'filtrar' )
3568 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3572 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3573 alias
: bpy
.props
.StringProperty( name
="Alias" )
3575 target
: bpy
.props
.PointerProperty( \
3576 type=bpy
.types
.Object
, name
="On Complete", \
3577 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3578 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3579 reset
: bpy
.props
.PointerProperty( \
3580 type=bpy
.types
.Object
, name
="On Reset", \
3581 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3582 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3584 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3586 first
: bpy
.props
.PointerProperty( \
3587 type=bpy
.types
.Object
, name
="First Objective", \
3588 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3590 camera
: bpy
.props
.PointerProperty( \
3591 type=bpy
.types
.Object
, name
="Camera", \
3592 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3596 def sr_inspector( layout
, data
):#{
3597 layout
.prop( data
[0], 'alias' )
3598 layout
.prop( data
[0], 'camera' )
3599 layout
.prop( data
[0], 'first' )
3600 layout
.prop( data
[0], 'time_limit' )
3601 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3602 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3606 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3607 title
: bpy
.props
.StringProperty( name
="Title" )
3608 zone_volume
: bpy
.props
.PointerProperty(
3609 type=bpy
.types
.Object
, name
="Zone Volume", \
3610 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3612 target0
: bpy
.props
.PointerProperty( \
3613 type=bpy
.types
.Object
, name
="Triger on unlock", \
3614 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3615 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3618 def sr_inspector( layout
, data
):#{
3619 layout
.prop( data
[0], 'title' )
3620 layout
.prop( data
[0], 'zone_volume' )
3621 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3625 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3626 target0
: bpy
.props
.PointerProperty( \
3627 type=bpy
.types
.Object
, name
="Target 0", \
3628 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3629 target1
: bpy
.props
.PointerProperty( \
3630 type=bpy
.types
.Object
, name
="Target 1", \
3631 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3632 target2
: bpy
.props
.PointerProperty( \
3633 type=bpy
.types
.Object
, name
="Target 2", \
3634 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3635 target3
: bpy
.props
.PointerProperty( \
3636 type=bpy
.types
.Object
, name
="Target 3", \
3637 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3639 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3640 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3641 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3642 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3645 def sr_inspector( layout
, data
):#{
3646 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3647 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3648 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3649 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3653 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3655 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3656 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3657 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3658 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3659 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3660 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3661 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3662 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3663 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3664 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3665 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3667 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3668 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3669 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3670 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3671 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3672 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3673 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3674 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3675 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3676 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3677 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3678 ent_npc
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_NPC
)
3680 ent_type
: bpy
.props
.EnumProperty(
3682 items
=sr_entity_list
,
3683 update
=sr_on_type_change
3687 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3689 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3692 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3694 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3697 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3699 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3700 items
=[('0','none',''),
3702 ('2','capsule','')])
3704 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3705 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3707 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3709 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3710 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3711 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3712 conet
: bpy
.props
.FloatProperty( name
='t' )
3715 def sr_inspector( layout
, data
):
3719 box
.prop( data
, 'collider' )
3721 if int(data
.collider
)>0:#{
3723 row
.prop( data
, 'collider_min' )
3725 row
.prop( data
, 'collider_max' )
3729 box
.prop( data
, 'cone_constraint' )
3730 if data
.cone_constraint
:#{
3732 row
.prop( data
, 'conevx' )
3734 row
.prop( data
, 'conevy' )
3736 row
.prop( data
, 'coneva' )
3737 box
.prop( data
, 'conet' )
3742 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3744 shader
: bpy
.props
.EnumProperty(
3747 ('standard',"standard",''),
3748 ('standard_cutout', "standard_cutout", ''),
3749 ('terrain_blend', "terrain_blend", ''),
3750 ('vertex_blend', "vertex_blend", ''),
3751 ('water',"water",''),
3752 ('invisible','Invisible',''),
3753 ('boundary','Boundary',''),
3754 ('fxglow','FX Glow',''),
3755 ('cubemap','Cubemap',''),
3756 ('walking','Walking',''),
3757 ('foliage','Foliage','')
3760 surface_prop
: bpy
.props
.EnumProperty(
3761 name
="Surface Property",
3763 ('0','concrete',''),
3768 ('5','snow (low friction)',''),
3769 ('6','sand (medium friction)','')
3772 collision
: bpy
.props
.BoolProperty( \
3773 name
="Collisions Enabled",\
3775 description
= "Can the player collide with this material?"\
3777 skate_surface
: bpy
.props
.BoolProperty( \
3778 name
="Skate Target", \
3780 description
= "Should the game try to target this surface?" \
3782 grind_surface
: bpy
.props
.BoolProperty( \
3785 description
= "Can you grind on this surface?" \
3787 grow_grass
: bpy
.props
.BoolProperty( \
3788 name
="Grow Grass", \
3790 description
= "Spawn grass sprites on this surface?" \
3792 preview_visibile
: bpy
.props
.BoolProperty( \
3793 name
="Preview visibile", \
3795 description
= "Show this material in preview models?" \
3797 blend_offset
: bpy
.props
.FloatVectorProperty( \
3798 name
="Blend Offset", \
3800 default
=Vector((0.5,0.0)),\
3801 description
="When surface is more than 45 degrees, add this vector " +\
3804 sand_colour
: bpy
.props
.FloatVectorProperty( \
3805 name
="Sand Colour",\
3808 default
=Vector((0.79,0.63,0.48)),\
3809 description
="Blend to this colour near the 0 coordinate on UP axis"\
3811 shore_colour
: bpy
.props
.FloatVectorProperty( \
3812 name
="Shore Colour",\
3815 default
=Vector((0.03,0.32,0.61)),\
3816 description
="Water colour at the shoreline"\
3818 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3819 name
="Ocean Colour",\
3822 default
=Vector((0.0,0.006,0.03)),\
3823 description
="Water colour in the deep bits"\
3825 tint
: bpy
.props
.FloatVectorProperty( \
3830 default
=Vector((1.0,1.0,1.0,1.0)),\
3831 description
="Reflection tint"\
3834 cubemap
: bpy
.props
.PointerProperty( \
3835 type=bpy
.types
.Object
, name
="cubemap", \
3836 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3838 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3841 # ---------------------------------------------------------------------------- #
3845 # ---------------------------------------------------------------------------- #
3847 cv_view_draw_handler
= None
3848 cv_view_pixel_handler
= None
3849 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3851 cv_view_colours
= []
3852 cv_view_course_i
= 0
3854 # Draw axis alligned sphere at position with radius
3856 def cv_draw_sphere( pos
, radius
, colour
):
3858 global cv_view_verts
, cv_view_colours
3860 ly
= pos
+ Vector((0,0,radius
))
3861 lx
= pos
+ Vector((0,radius
,0))
3862 lz
= pos
+ Vector((0,0,radius
))
3864 pi
= 3.14159265358979323846264
3866 for i
in range(16):#{
3867 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3871 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3872 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3873 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3875 cv_view_verts
+= [ px
, lx
]
3876 cv_view_verts
+= [ py
, ly
]
3877 cv_view_verts
+= [ pz
, lz
]
3879 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3888 # Draw axis alligned sphere at position with radius
3890 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3892 global cv_view_verts
, cv_view_colours
3894 ly
= pos
+ tz
*radius
3895 lx
= pos
+ ty
*radius
3896 lz
= pos
+ tz
*radius
3898 pi
= 3.14159265358979323846264
3900 for i
in range(16):#{
3901 t
= ((i
+1.0) * 1.0/16.0) * pi
3905 s1
= math
.sin(t
*2.0)
3906 c1
= math
.cos(t
*2.0)
3908 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3909 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3910 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3912 cv_view_verts
+= [ px
, lx
]
3913 cv_view_verts
+= [ py
, ly
]
3914 cv_view_verts
+= [ pz
, lz
]
3916 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3925 # Draw transformed -1 -> 1 cube
3927 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3929 global cv_view_verts
, cv_view_colours
3935 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3936 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3937 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3938 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3939 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3940 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3941 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3942 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3944 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3945 (0,4),(1,5),(2,6),(3,7)]
3950 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3951 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3952 cv_view_colours
+= [colour
, colour
]
3957 # Draw line with colour
3959 def cv_draw_line( p0
, p1
, colour
):
3961 global cv_view_verts
, cv_view_colours
3963 cv_view_verts
+= [p0
,p1
]
3964 cv_view_colours
+= [colour
, colour
]
3968 # Draw line with colour(s)
3970 def cv_draw_line2( p0
, p1
, c0
, c1
):
3972 global cv_view_verts
, cv_view_colours
3974 cv_view_verts
+= [p0
,p1
]
3975 cv_view_colours
+= [c0
,c1
]
3981 def cv_tangent_basis( n
, tx
, ty
):
3983 if abs( n
[0] ) >= 0.57735027:#{
4002 # Draw coloured arrow
4004 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
4006 global cv_view_verts
, cv_view_colours
4012 tx
= Vector((1,0,0))
4013 ty
= Vector((1,0,0))
4014 cv_tangent_basis( n
, tx
, ty
)
4020 gpu
.state
.line_width_set(1.0)
4023 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
4024 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
4028 gpu
.state
.line_width_set(3.0)
4029 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
4031 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
4033 gpu
.state
.line_width_set(2.0)
4037 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
4039 global cv_view_verts
, cv_view_colours
4041 for i
in range(dots
):#{
4045 p2
= p0
*(1.0-t0
)+p1
*t0
4046 p3
= p0
*(1.0-t1
)+p1
*t1
4048 cv_view_verts
+= [p2
,p3
]
4049 cv_view_colours
+= [c0
,c0
]
4054 # Drawhandles of a bezier control point
4056 def cv_draw_bhandle( obj
, direction
, colour
):
4058 global cv_view_verts
, cv_view_colours
4061 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
4063 cv_view_verts
+= [p0
]
4064 cv_view_verts
+= [h0
]
4065 cv_view_colours
+= [colour
,colour
]
4069 # Draw a bezier curve (at fixed resolution 10)
4071 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
4073 global cv_view_verts
, cv_view_colours
4076 for i
in range(10):#{
4082 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
4084 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
4085 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
4086 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
4093 # I think this one extends the handles of the bezier otwards......
4095 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
4097 global cv_view_course_i
4099 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
4101 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
4102 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
4103 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
4104 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
4106 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
4110 # Flush the lines buffers. This is called often because god help you if you want
4111 # to do fixed, fast buffers in this catastrophic programming language.
4113 def cv_draw_lines():
4115 global cv_view_shader
, cv_view_verts
, cv_view_colours
4117 if len(cv_view_verts
) < 2:
4120 lines
= batch_for_shader(\
4121 cv_view_shader
, 'LINES', \
4122 { "pos":cv_view_verts
, "color":cv_view_colours
})
4124 if bpy
.context
.scene
.SR_data
.gizmos
:
4125 lines
.draw( cv_view_shader
)
4128 cv_view_colours
= []
4131 # I dont remember what this does exactly
4133 def cv_draw_bpath( o0
,o1
,c0
,c1
):
4135 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
4138 # Semi circle to show the limit. and some lines
4140 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
4142 global cv_view_verts
, cv_view_colours
4147 for x
in range(16):#{
4150 a0
= amin
*(1.0-t0
)+amax
*t0
4151 a1
= amin
*(1.0-t1
)+amax
*t1
4153 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
4154 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
4156 p0
=obj
.matrix_world
@ p0
4157 p1
=obj
.matrix_world
@ p1
4158 cv_view_verts
+= [p0
,p1
]
4159 cv_view_colours
+= [colour
,colour
]
4162 cv_view_verts
+= [p0
,center
]
4163 cv_view_colours
+= [colour
,colour
]
4166 cv_view_verts
+= [p1
,center
]
4167 cv_view_colours
+= [colour
,colour
]
4171 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
4172 cv_view_colours
+= [colour
,colour
]
4177 # Cone and twist limit
4179 def draw_cone_twist( center
, vx
, vy
, va
):
4181 global cv_view_verts
, cv_view_colours
4182 axis
= vy
.cross( vx
)
4187 cv_view_verts
+= [center
, center
+va
*size
]
4188 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4190 for x
in range(32):#{
4191 t0
= (x
/32) * math
.tau
4192 t1
= ((x
+1)/32) * math
.tau
4199 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4200 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4202 col0
= ( abs(c0
), abs(s0
), 0.0 )
4203 col1
= ( abs(c1
), abs(s1
), 0.0 )
4205 cv_view_verts
+= [center
, p0
, p0
, p1
]
4206 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4212 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4214 def draw_skeleton_helpers( obj
):
4216 global cv_view_verts
, cv_view_colours
4218 if obj
.data
.pose_position
!= 'REST':#{
4222 for bone
in obj
.data
.bones
:#{
4224 a
= Vector((bone
.SR_data
.collider_min
[0],
4225 bone
.SR_data
.collider_min
[1],
4226 bone
.SR_data
.collider_min
[2]))
4227 b
= Vector((bone
.SR_data
.collider_max
[0],
4228 bone
.SR_data
.collider_max
[1],
4229 bone
.SR_data
.collider_max
[2]))
4231 if bone
.SR_data
.collider
== '1':#{
4233 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4234 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4235 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4236 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4237 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4238 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4239 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4240 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4242 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4243 (0,4),(1,5),(2,6),(3,7)]
4249 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4250 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4251 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4254 elif bone
.SR_data
.collider
== '2':#{
4259 for i
in range(3):#{
4260 if abs(v0
[i
]) > largest
:#{
4261 largest
= abs(v0
[i
])
4266 v1
= Vector((0,0,0))
4267 v1
[major_axis
] = 1.0
4269 tx
= Vector((0,0,0))
4270 ty
= Vector((0,0,0))
4272 cv_tangent_basis( v1
, tx
, ty
)
4273 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4274 l
= v0
[ major_axis
] - r
*2
4276 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4277 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4279 colour
= [0.2,0.2,0.2]
4280 colour
[major_axis
] = 0.5
4282 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4283 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4284 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4285 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4286 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4287 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4293 center
= obj
.matrix_world
@ c
4294 if bone
.SR_data
.cone_constraint
:#{
4295 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4296 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4297 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4298 draw_cone_twist( center
, vx
, vy
, va
)
4303 def cv_draw_wireframe( mdl
, points
, colour
):#{
4304 for i
in range(len(points
)//2):#{
4305 p0
= mdl
@points[i
*2+0]
4306 p1
= mdl
@points[i
*2+1]
4307 cv_draw_line( p0
, p1
, colour
)
4311 def cv_ent_gate( obj
):
4313 global cv_view_verts
, cv_view_colours
4315 if obj
.type != 'MESH': return
4317 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4318 data
= obj
.SR_data
.ent_gate
[0]
4319 dims
= mesh_data
.dimensions
4322 c
= Vector((0,0,dims
[2]))
4324 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4325 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4326 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4327 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4328 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4329 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4330 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4331 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4332 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4334 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4336 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4338 p0
= r3d
.view_matrix
.inverted().translation
4339 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4340 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4342 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4348 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4349 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4350 cv_view_colours
+= [cc
,cc
]
4354 if data
.target
!= None:
4355 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4358 def cv_ent_volume( obj
):
4360 global cv_view_verts
, cv_view_colours
4362 data
= obj
.SR_data
.ent_volume
[0]
4364 if data
.subtype
== '0':#{
4365 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4368 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4371 elif data
.subtype
== '1':#{
4372 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4375 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4380 def dijkstra( graph
, start_node
, target_node
):
4382 unvisited
= [_
for _
in graph
]
4387 shortest_path
[n
] = 9999999.999999
4388 shortest_path
[start_node
] = 0
4391 current_min_node
= None
4392 for n
in unvisited
:#{
4393 if current_min_node
== None:
4394 current_min_node
= n
4395 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4396 current_min_node
= n
4399 for branch
in graph
[current_min_node
]:#{
4400 tentative_value
= shortest_path
[current_min_node
]
4401 tentative_value
+= graph
[current_min_node
][branch
]
4402 if tentative_value
< shortest_path
[branch
]:#{
4403 shortest_path
[branch
] = tentative_value
4404 previous_nodes
[branch
] = current_min_node
4408 unvisited
.remove(current_min_node
)
4413 while node
!= start_node
:#{
4416 if node
not in previous_nodes
: return None
4417 node
= previous_nodes
[node
]
4420 # Add the start node manually
4421 path
.append(start_node
)
4427 def __init__(_
,points
,graph
,subsections
):#{
4430 _
.subsections
= subsections
4434 def create_node_graph( curves
, gates
):
4436 # add endpoints of curves
4443 for c
in range(len(curves
)):#{
4444 for s
in range(len(curves
[c
].data
.splines
)):#{
4445 spline
= curves
[c
].data
.splines
[s
]
4446 l
= len(spline
.points
)
4449 dist
= round(spline
.calc_length(),2)
4452 ib
= point_count
+l
-1
4454 graph
[ia
] = { ib
: dist
}
4455 graph
[ib
] = { ia
: dist
}
4457 for i
in range(len(spline
.points
)):#{
4458 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4459 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4464 if i
== 0: previous
= -1
4465 if i
== len(spline
.points
)-1: proxima
= -1
4467 subsections
.append((spline_count
,previous
,proxima
))
4476 graph_keys
= list(graph
)
4477 for i
in range(len(graph_keys
)-1):#{
4478 for j
in range(i
+1, len(graph_keys
)):#{
4479 if i
%2==0 and i
+1==j
: continue
4483 pi
= route_points
[ni
]
4484 pj
= route_points
[nj
]
4486 dist
= round((pj
-pi
).magnitude
,2)
4489 graph
[ni
][nj
] = dist
4490 graph
[nj
][ni
] = dist
4495 # add and link gates( by name )
4496 for gate
in gates
:#{
4497 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4498 if gate
.SR_data
.ent_gate
[0].target
:
4501 graph
[ gate
.name
] = {}
4503 for i
in range(len(graph_keys
)):#{
4505 pi
= route_points
[ni
]
4507 v0
= pi
-gate
.location
4508 if v0
.dot(v1
) < 0.0: continue
4510 dist
= round(v0
.magnitude
,2)
4513 graph
[ gate
.name
][ ni
] = dist
4514 graph
[ ni
][ gate
.name
] = dist
4519 return dij_graph(route_points
,graph
,subsections
)
4522 def solve_graph( dij
, start
, end
):
4524 path
= dijkstra( dij
.graph
, end
, start
)
4528 for sj
in range(1,len(path
)-2):#{
4531 map0
= dij
.subsections
[i0
]
4532 map1
= dij
.subsections
[i1
]
4534 if map0
[0] == map1
[0]:#{
4535 if map0
[1] == -1: direction
= 2
4540 map0
= dij
.subsections
[i0
]
4541 i1
= map0
[direction
]
4555 full
.append( path
[-2] )
4560 def cv_draw_route( route
, dij
):
4562 pole
= Vector((0.2,0.2,10))
4563 hat
= Vector((1,8,0.2))
4564 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4565 route
.SR_data
.ent_route
[0].colour
[1],
4566 route
.SR_data
.ent_route
[0].colour
[2])
4568 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4569 Vector((0,-6.5,5.5)))
4570 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4571 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4572 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4573 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4575 checkpoints
= route
.SR_data
.ent_route
[0].gates
4577 for i
in range(len(checkpoints
)):#{
4578 gi
= checkpoints
[i
].target
4579 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4582 dest
= gi
.SR_data
.ent_gate
[0].target
4584 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4588 if gi
==gj
: continue # error?
4589 if not gi
or not gj
: continue
4591 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4594 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4595 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4596 for j
in range(len(path
)-1):#{
4599 o0
= dij
.points
[ i0
]
4600 o1
= dij
.points
[ i1
]
4601 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4605 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4611 global cv_view_shader
4612 global cv_view_verts
4613 global cv_view_colours
4614 global cv_view_course_i
4616 cv_view_course_i
= 0
4618 cv_view_colours
= []
4620 cv_view_shader
.bind()
4621 gpu
.state
.depth_mask_set(True)
4622 gpu
.state
.line_width_set(2.0)
4623 gpu
.state
.face_culling_set('BACK')
4624 gpu
.state
.depth_test_set('LESS')
4625 gpu
.state
.blend_set('NONE')
4631 for obj
in bpy
.context
.collection
.objects
:#{
4632 if obj
.type == 'ARMATURE':#{
4633 if obj
.data
.pose_position
== 'REST':
4634 draw_skeleton_helpers( obj
)
4637 ent_type
= obj_ent_type( obj
)
4639 if ent_type
== 'ent_gate':#{
4641 route_gates
+= [obj
]
4643 elif ent_type
== 'ent_route_node':#{
4644 if obj
.type == 'CURVE':#{
4645 route_curves
+= [obj
]
4648 elif ent_type
== 'ent_route':
4650 elif ent_type
== 'ent_volume':#{
4651 cv_ent_volume( obj
)
4653 elif ent_type
== 'ent_objective':#{
4654 data
= obj
.SR_data
.ent_objective
[0]
4656 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4659 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4661 elif ent_type
== 'ent_relay':#{
4662 data
= obj
.SR_data
.ent_relay
[0]
4664 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4666 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4668 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4670 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4672 elif ent_type
== 'ent_challenge':#{
4673 data
= obj
.SR_data
.ent_challenge
[0]
4675 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4677 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4679 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4682 info_cu
= Vector((1.2,0.01,0.72))*0.5
4683 info_co
= Vector((0.0,0.0,0.72))*0.5
4684 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4686 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4688 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4689 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4690 Vector(( 0.1,0.0,0.30))]
4691 for v
in range(len(vs
)):#{
4692 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4695 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4696 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4698 elif ent_type
== 'ent_audio':#{
4699 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4700 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4702 elif ent_type
== 'ent_font':#{
4703 data
= obj
.SR_data
.ent_font
[0]
4705 for i
in range(len(data
.variants
)):#{
4706 sub
= data
.variants
[i
].mesh
4707 if not sub
: continue
4709 for ch
in data
.glyphs
:#{
4710 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4711 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4712 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4713 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4714 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4715 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4717 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4720 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4721 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4725 elif ent_type
== 'ent_glider':#{
4726 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4727 Vector(( 1.13982, 0.137084, -0.026358)), \
4728 Vector(( 0.0, 1.6, 1.0)), \
4729 Vector(( 0.0, -3.0, 1.0)), \
4730 Vector(( -3.45, -1.78, 0.9)), \
4731 Vector(( 0.0, 1.6, 1.0)), \
4732 Vector(( 3.45, -1.78, 0.9)), \
4733 Vector(( 0.0, 1.6, 1.0)), \
4734 Vector(( 3.45, -1.78, 0.9)), \
4735 Vector(( -3.45, -1.78, 0.9))]
4737 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4739 elif ent_type
== 'ent_skateshop':#{
4740 data
= obj
.SR_data
.ent_skateshop
[0]
4741 display
= data
.mark_display
4742 info
= data
.mark_info
4744 if data
.tipo
== '0':#{
4749 rack
= data
.mark_rack
4751 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4752 rack_co
= Vector((0.0,0.0,0.0))
4753 display_cu
= Vector((0.3,1.2,0.1))*0.5
4754 display_co
= Vector((0.0,0.0,0.1))*0.5
4755 info_cu
= Vector((1.2,0.01,0.3))*0.5
4756 info_co
= Vector((0.0,0.0,0.0))*0.5
4758 elif data
.tipo
== '1':#{
4762 display_cu
= Vector((0.4,0.4,2.0))*0.5
4763 display_co
= Vector((0.0,0.0,1.0))*0.5
4764 info_cu
= Vector((1.2,0.01,0.3))*0.5
4765 info_co
= Vector((0.0,0.0,0.0))*0.5
4767 elif data
.tipo
== '2':#{
4771 display_cu
= Vector((1.0,1.0,0.5))*0.5
4772 display_co
= Vector((0.0,0.0,0.5))*0.5
4773 info_cu
= Vector((1.2,0.01,0.3))*0.5
4774 info_co
= Vector((0.0,0.0,0.0))*0.5
4776 elif data
.tipo
== '3':#{
4781 elif data
.tipo
== '4':#{
4788 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4790 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4792 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4794 elif ent_type
== 'ent_swspreview':#{
4796 data
= obj
.SR_data
.ent_swspreview
[0]
4797 display
= data
.mark_display
4798 display1
= data
.mark_display1
4799 display_cu
= Vector((0.3,1.2,0.1))*0.5
4800 display_co
= Vector((0.0,0.0,0.1))*0.5
4802 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4804 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4806 # elif ent_type == 'ent_list':#{
4807 # data = obj.SR_data.ent_list[0]
4808 # for child in data.entities:#{
4809 # if child.target:#{
4810 # cv_draw_arrow( obj.location, child.target.location, \
4815 elif ent_type
== 'ent_region':#{
4816 data
= obj
.SR_data
.ent_region
[0]
4818 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4822 elif ent_type
== 'ent_menuitem':#{
4823 for i
,col
in enumerate(obj
.users_collection
):#{
4824 colour32
= hash_djb2( col
.name
)
4825 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4826 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4827 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4829 vs
= [None for _
in range(8)]
4831 for j
in range(8):#{
4832 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4833 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4835 vs
[j
] = obj
.matrix_world
@ v0
4837 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4838 (0,4),(1,5),(2,6),(3,7)]
4842 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4843 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4844 cv_view_colours
+= [cc
,cc
]
4849 data
= obj
.SR_data
.ent_menuitem
[0]
4850 if data
.tipo
== '4':#{
4851 if data
.slider_minloc
and data
.slider_maxloc
:#{
4852 v0
= data
.slider_minloc
.location
4853 v1
= data
.slider_maxloc
.location
4854 cv_draw_line( v0
, v1
, cc
)
4858 colour32
= hash_djb2(obj
.name
)
4859 r
= ((colour32
) & 0xff) / 255.0
4860 g
= ((colour32
>>8 ) & 0xff) / 255.0
4861 b
= ((colour32
>>16) & 0xff) / 255.0
4863 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4868 if data
.tipo
!= '0':#{
4869 if data
.tipo
== '4':#{
4871 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4874 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4879 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4882 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4885 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4888 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4896 dij
= create_node_graph( route_curves
, route_gates
)
4898 #cv_draw_route_map( route_nodes )
4899 for route
in routes
:#{
4900 cv_draw_route( route
, dij
)
4906 def pos3d_to_2d( pos
):#{
4907 return view3d_utils
.location_3d_to_region_2d( \
4908 bpy
.context
.region
, \
4909 bpy
.context
.space_data
.region_3d
, pos
)
4912 def cv_draw_pixel():#{
4913 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4915 blf
.color(0, 1.0,1.0,1.0,0.9)
4916 blf
.enable(0,blf
.SHADOW
)
4917 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4918 for obj
in bpy
.context
.collection
.objects
:#{
4919 ent_type
= obj_ent_type( obj
)
4921 if ent_type
!= 'none':#{
4922 co
= pos3d_to_2d( obj
.location
)
4925 blf
.position(0,co
[0],co
[1],0)
4926 blf
.draw(0,ent_type
)
4931 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4932 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4933 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4935 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4936 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4937 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4938 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4939 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4940 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4941 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4942 SR_OT_COPY_ENTITY_DATA
, \
4943 SR_OBJECT_ENT_VOLUME
, \
4944 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4945 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4946 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4947 SR_OBJECT_ENT_FONT_VARIANT
,
4948 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4949 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4950 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4951 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4952 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4953 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4954 SR_OBJECT_ENT_REGION
,\
4955 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4956 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4957 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4958 SR_OBJECT_ENT_GLIDER
, SR_OBJECT_ENT_NPC
, \
4960 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4961 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4967 bpy
.utils
.register_class(c
)
4969 bpy
.types
.Scene
.SR_data
= \
4970 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4971 bpy
.types
.Collection
.SR_data
= \
4972 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4974 bpy
.types
.Object
.SR_data
= \
4975 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4976 bpy
.types
.Light
.SR_data
= \
4977 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4978 bpy
.types
.Bone
.SR_data
= \
4979 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4980 bpy
.types
.Mesh
.SR_data
= \
4981 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4982 bpy
.types
.Material
.SR_data
= \
4983 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4985 global cv_view_draw_handler
, cv_view_pixel_handler
4986 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4987 cv_draw
,(),'WINDOW','POST_VIEW')
4988 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4989 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4995 bpy
.utils
.unregister_class(c
)
4997 global cv_view_draw_handler
, cv_view_pixel_handler
4998 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4999 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')
5002 # ---------------------------------------------------------------------------- #
5006 # ---------------------------------------------------------------------------- #
5008 # Transliteration of: #
5009 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
5011 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
5012 # SPDX-License-Identifier: MIT #
5013 # QOI - The "Quite OK Image" format for fast, lossless image compression #
5015 # ---------------------------------------------------------------------------- #
5017 class qoi_rgba_t(Structure
):
5020 _fields_
= [("r",c_uint8
),
5026 QOI_OP_INDEX
= 0x00 # 00xxxxxx
5027 QOI_OP_DIFF
= 0x40 # 01xxxxxx
5028 QOI_OP_LUMA
= 0x80 # 10xxxxxx
5029 QOI_OP_RUN
= 0xc0 # 11xxxxxx
5030 QOI_OP_RGB
= 0xfe # 11111110
5031 QOI_OP_RGBA
= 0xff # 11111111
5033 QOI_MASK_2
= 0xc0 # 11000000
5035 def qoi_colour_hash( c
):
5037 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
5042 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
5047 return bytearray([ (0xff000000 & v
) >> 24, \
5048 (0x00ff0000 & v
) >> 16, \
5049 (0x0000ff00 & v
) >> 8, \
5053 def qoi_encode( img
):
5057 print(F
"{' ':<30}",end
='\r')
5058 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
5060 index
= [ qoi_rgba_t() for _
in range(64) ]
5064 data
.extend( bytearray(c_uint32(0x66696f71)) )
5065 data
.extend( qoi_32bit( img
.size
[0] ) )
5066 data
.extend( qoi_32bit( img
.size
[1] ) )
5067 data
.extend( bytearray(c_uint8(4)) )
5068 data
.extend( bytearray(c_uint8(0)) )
5071 px_prev
= qoi_rgba_t()
5072 px_prev
.r
= c_uint8(0)
5073 px_prev
.g
= c_uint8(0)
5074 px_prev
.b
= c_uint8(0)
5075 px_prev
.a
= c_uint8(255)
5083 px_len
= img
.size
[0] * img
.size
[1]
5084 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
5086 for px_pos
in range( px_len
): #{
5087 idx
= px_pos
* img
.channels
5090 px
.r
= paxels
[idx
+min(0,nc
)]
5091 px
.g
= paxels
[idx
+min(1,nc
)]
5092 px
.b
= paxels
[idx
+min(2,nc
)]
5093 px
.a
= paxels
[idx
+min(3,nc
)]
5095 if qoi_eq( px
, px_prev
): #{
5098 if (run
== 62) or (px_pos
== px_len
-1): #{
5099 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
5105 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
5109 index_pos
= qoi_colour_hash(px
) % 64
5111 if qoi_eq( index
[index_pos
], px
): #{
5112 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
5115 index
[ index_pos
].r
= px
.r
5116 index
[ index_pos
].g
= px
.g
5117 index
[ index_pos
].b
= px
.b
5118 index
[ index_pos
].a
= px
.a
5120 if px
.a
== px_prev
.a
: #{
5121 vr
= int(px
.r
) - int(px_prev
.r
)
5122 vg
= int(px
.g
) - int(px_prev
.g
)
5123 vb
= int(px
.b
) - int(px_prev
.b
)
5128 if (vr
> -3) and (vr
< 2) and\
5129 (vg
> -3) and (vg
< 2) and\
5130 (vb
> -3) and (vb
< 2):
5132 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
5133 data
.extend( bytearray( c_uint8(op
) ))
5135 elif (vg_r
> -9) and (vg_r
< 8) and\
5136 (vg
> -33) and (vg
< 32 ) and\
5137 (vg_b
> -9) and (vg_b
< 8):
5139 op
= QOI_OP_LUMA |
(vg
+32)
5140 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
5141 data
.extend( bytearray( c_uint8(op
) ) )
5142 data
.extend( bytearray( c_uint8(delta
) ))
5145 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
5146 data
.extend( bytearray( c_uint8(px
.r
) ))
5147 data
.extend( bytearray( c_uint8(px
.g
) ))
5148 data
.extend( bytearray( c_uint8(px
.b
) ))
5152 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
5153 data
.extend( bytearray( c_uint8(px
.r
) ))
5154 data
.extend( bytearray( c_uint8(px
.g
) ))
5155 data
.extend( bytearray( c_uint8(px
.b
) ))
5156 data
.extend( bytearray( c_uint8(px
.a
) ))
5169 data
.extend( bytearray( c_uint8(0) ))
5170 data
.extend( bytearray( c_uint8(1) ))
5171 bytearray_align_to( data
, 16, b
'\x00' )