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 ),
51 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
52 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
53 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list' ]
55 def get_entity_enum_id( alias
):
57 for et
in sr_entity_list
:#{
63 if alias
== 'ent_cubemap': return 21
68 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
69 #{ # the normals and uvs to i16s. Not an
70 _pack_
= 1 # real issue, yet.
71 _fields_
= [("co",c_float
*3),
75 ("weights",c_uint16
*4),
79 class mdl_transform(Structure
):
81 _fields_
= [("co",c_float
*3),
86 class mdl_submesh(Structure
):
88 _fields_
= [("indice_start",c_uint32
),
89 ("indice_count",c_uint32
),
90 ("vertex_start",c_uint32
),
91 ("vertex_count",c_uint32
),
92 ("bbx",(c_float
*3)*2),
93 ("material_id",c_uint16
), # index into the material array
97 class mdl_material(Structure
):
99 _fields_
= [("pstr_name",c_uint32
),
102 ("surface_prop",c_uint32
),
103 ("colour",c_float
*4),
104 ("colour1",c_float
*4),
105 ("tex_diffuse",c_uint32
),
106 ("tex_none0",c_uint32
),
107 ("tex_none1",c_uint32
)]
110 class mdl_bone(Structure
):
112 _fields_
= [("co",c_float
*3),("end",c_float
*3),
114 ("collider",c_uint32
),
115 ("ik_target",c_uint32
),
116 ("ik_pole",c_uint32
),
118 ("pstr_name",c_uint32
),
119 ("hitbox",(c_float
*3)*2),
120 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
124 class mdl_armature(Structure
):
126 _fields_
= [("transform",mdl_transform
),
127 ("bone_start",c_uint32
),
128 ("bone_count",c_uint32
),
129 ("anim_start",c_uint32
),
130 ("anim_count",c_uint32
)]
133 class mdl_animation(Structure
):
135 _fields_
= [("pstr_name",c_uint32
),
138 ("keyframe_start",c_uint32
)]
141 class mdl_mesh(Structure
):
143 _fields_
= [("transform",mdl_transform
),
144 ("submesh_start",c_uint32
),
145 ("submesh_count",c_uint32
),
146 ("pstr_name",c_uint32
),
147 ("entity_id",c_uint32
),
148 ("armature_id",c_uint32
)]
151 class mdl_file(Structure
):
153 _fields_
= [("path",c_uint32
),
154 ("pack_offset",c_uint32
),
155 ("pack_size",c_uint32
)]
158 class mdl_texture(Structure
):
160 _fields_
= [("file",mdl_file
),
164 class mdl_array(Structure
):
166 _fields_
= [("file_offset",c_uint32
),
167 ("item_count",c_uint32
),
168 ("item_size",c_uint32
),
172 class mdl_header(Structure
):
174 _fields_
= [("version",c_uint32
),
175 ("arrays",mdl_array
)]
178 class ent_spawn(Structure
):
180 _fields_
= [("transform",mdl_transform
),
181 ("pstr_name",c_uint32
)]
184 class ent_light(Structure
):
186 _fields_
= [("transform",mdl_transform
),
187 ("daytime",c_uint32
),
189 ("colour",c_float
*4),
192 ("inverse_world",(c_float
*3)*4), # Runtime
193 ("angle_sin_cos",(c_float
*2))] # Runtime
196 class version_refcount_union(Union
):
198 _fields_
= [("timing_version",c_uint32
),
199 ("ref_count",c_uint8
)]
202 class ent_gate(Structure
):
204 _fields_
= [("flags",c_uint32
),
205 ("target", c_uint32
),
207 ("dimensions", c_float
*3),
208 ("co", (c_float
*3)*2),
209 ("q", (c_float
*4)*2),
210 ("to_world",(c_float
*3)*4),
211 ("transport",(c_float
*3)*4),
212 ("_anonymous_union",version_refcount_union
),
213 ("timing_time",c_double
),
214 ("routes",c_uint16
*4),
215 ("route_count",c_uint8
),
216 ("submesh_start",c_uint32
), # v102+
217 ("submesh_count",c_uint32
), # v102+ (can be 0)
219 sr_functions
= { 0: 'unlock' }
222 class ent_route_node(Structure
):
224 _fields_
= [("co",c_float
*3),
225 ("ref_count",c_uint8
),
226 ("ref_total",c_uint8
)]
229 class ent_path_index(Structure
):
231 _fields_
= [("index",c_uint16
)]
234 class vg_audio_clip(Structure
):
236 _fields_
= [("path",c_uint64
),
242 class union_file_audio_clip(Union
):
244 _fields_
= [("file",mdl_file
),
245 ("reserved",vg_audio_clip
)]
248 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
249 # but then again, too late to change because compat.
250 class ent_audio_clip(Structure
):
252 _fields_
= [("_anon",union_file_audio_clip
),
253 ("probability",c_float
)]
256 class ent_list(Structure
):
258 _fields_
= [("entity_ref_start",c_uint32
),
259 ("entity_ref_count",c_uint32
)]
263 class file_entity_ref(Structure
):
265 _fields_
= [("index",c_uint32
)]
268 class ent_checkpoint(Structure
):
270 _fields_
= [("gate_index",c_uint16
),
271 ("path_start",c_uint16
),
272 ("path_count",c_uint16
)]
275 class ent_route(Structure
):
277 _fields_
= [("transform",mdl_transform
),
278 ("pstr_name",c_uint32
),
279 ("checkpoints_start",c_uint16
),
280 ("checkpoints_count",c_uint16
),
281 ("colour",c_float
*4),
282 ("active",c_uint32
), #runtime
284 ("board_transform",(c_float
*3)*4),
286 ("latest_pass",c_double
),
287 ("id_camera",c_uint32
), # v103+
290 sr_functions
= { 0: 'view' }
293 class ent_list(Structure
):#{
294 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
297 class ent_glider(Structure
):#{
298 _fields_
= [("transform",mdl_transform
),
300 ("cooldown",c_float
)]
301 sr_functions
= { 0: 'unlock',
305 class ent_water(Structure
):
307 _fields_
= [("transform",mdl_transform
),
308 ("max_dist",c_float
),
309 ("reserved0",c_uint32
),
310 ("reserved1",c_uint32
)]
313 class volume_trigger(Structure
):
315 _fields_
= [("event",c_uint32
),
316 ("event_leave",c_uint32
)]
319 class volume_particles(Structure
):
321 _fields_
= [("blank",c_uint32
),
325 class volume_union(Union
):
327 _fields_
= [("trigger",volume_trigger
),
328 ("particles",volume_particles
)]
331 class ent_volume(Structure
):
333 _fields_
= [("transform",mdl_transform
),
334 ("to_world",(c_float
*3)*4),
335 ("to_local",(c_float
*3)*4),
338 ("_anon",volume_union
)]
341 class ent_audio(Structure
):
343 _fields_
= [("transform",mdl_transform
),
345 ("clip_start",c_uint32
),
346 ("clip_count",c_uint32
),
348 ("crossfade",c_float
),
349 ("channel_behaviour",c_uint32
),
351 ("probability_curve",c_uint32
),
352 ("max_channels",c_uint32
)]
355 class ent_marker(Structure
):
357 _fields_
= [("transform",mdl_transform
),
361 class ent_glyph(Structure
):
363 _fields_
= [("size",c_float
*2),
364 ("indice_start",c_uint32
),
365 ("indice_count",c_uint32
)]
368 class ent_font_variant(Structure
):
370 _fields_
= [("name",c_uint32
),
371 ("material_id",c_uint32
)]
374 class ent_font(Structure
):
376 _fields_
= [("alias",c_uint32
),
377 ("variant_start",c_uint32
),
378 ("variant_count",c_uint32
),
379 ("glyph_start",c_uint32
),
380 ("glyph_count",c_uint32
),
381 ("glyph_utf32_base",c_uint32
)]
384 class ent_traffic(Structure
):
386 _fields_
= [("transform",mdl_transform
),
387 ("submesh_start",c_uint32
),
388 ("submesh_count",c_uint32
),
389 ("start_node",c_uint32
),
390 ("node_count",c_uint32
),
397 # ---------------------------------------------------------------
398 class ent_skateshop_characters(Structure
):
400 _fields_
= [("id_display",c_uint32
),
401 ("id_info",c_uint32
)]
403 class ent_skateshop_boards(Structure
):
405 _fields_
= [("id_display",c_uint32
),
406 ("id_info",c_uint32
),
407 ("id_rack",c_uint32
)]
409 class ent_skateshop_worlds(Structure
):
411 _fields_
= [("id_display",c_uint32
),
412 ("id_info",c_uint32
)]
414 class ent_skateshop_server(Structure
):
416 _fields_
= [("id_lever",c_uint32
)]
418 class ent_skateshop_anon_union(Union
):
420 _fields_
= [("boards",ent_skateshop_boards
),
421 ("character",ent_skateshop_characters
),
422 ("worlds",ent_skateshop_worlds
),
423 ("server",ent_skateshop_server
)]
425 class ent_skateshop(Structure
):
427 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
428 ("id_camera",c_uint32
),
429 ("_anonymous_union",ent_skateshop_anon_union
)]
431 sr_functions
= { 0: 'trigger' }
434 class ent_swspreview(Structure
):
436 _fields_
= [("id_camera",c_uint32
),
437 ("id_display",c_uint32
),
438 ("id_display1",c_uint32
)]
442 # -----------------------------------------------------------------
443 class ent_menuitem_visual(Structure
):
445 _fields_
= [("pstr_name",c_uint32
)]
447 class ent_menuitem_slider(Structure
):
449 _fields_
= [("id_min",c_uint32
),
451 ("id_handle",c_uint32
),
452 ("pstr_data",c_uint32
)]
454 class ent_menuitem_button(Structure
):
456 _fields_
= [("pstr",c_uint32
),
457 ("stack_behaviour",c_uint32
)]
459 class ent_menuitem_checkmark(Structure
):
461 _fields_
= [("id_check",c_uint32
),
462 ("pstr_data",c_uint32
),
463 ("offset",c_float
*3)]
465 class ent_menuitem_page(Structure
):
467 _fields_
= [("pstr_name",c_uint32
),
468 ("id_entrypoint",c_uint32
),
469 ("id_viewpoint",c_uint32
)]
471 class ent_menuitem_binding(Structure
):
473 _fields_
= [("pstr_bind",c_uint32
),
474 ("font_variant",c_uint32
)]
476 class ent_menuitem_anon_union(Union
):
478 _fields_
= [("slider",ent_menuitem_slider
),
479 ("button",ent_menuitem_button
),
480 ("checkmark",ent_menuitem_checkmark
),
481 ("page",ent_menuitem_page
),
482 ("visual",ent_menuitem_visual
),
483 ("binding",ent_menuitem_binding
)]
485 class ent_menuitem(Structure
):
487 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
488 ("id_links",c_uint32
*4),
489 ("factive",c_float
), ("fvisible",c_float
),
490 #-- TODO: Refactor this into a simple mesh structure
491 ("transform",mdl_transform
),
492 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
495 ("_anonymous_union", ent_menuitem_anon_union
)]
498 class ent_camera(Structure
):
500 _fields_
= [("transform",mdl_transform
),
504 class ent_worldinfo(Structure
):
506 _fields_
= [("pstr_name",c_uint32
),
507 ("pstr_author",c_uint32
), # unused
508 ("pstr_desc",c_uint32
), # unused
509 ("timezone",c_float
),
510 ("pstr_skybox",c_uint32
),
514 class ent_ccmd(Structure
):
516 _fields_
= [("pstr_command",c_uint32
)]
519 class ent_objective(Structure
):#{
520 _fields_
= [("transform",mdl_transform
),
521 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
523 ("id_next",c_uint32
),
524 ("filter",c_uint32
),("filter2",c_uint32
),
526 ("win_event",c_uint32
),
527 ("time_limit",c_float
)]
529 sr_functions
= { 0: 'trigger',
534 class ent_challenge(Structure
):#{
535 _fields_
= [("transform",mdl_transform
),
536 ("pstr_alias",c_uint32
),
539 ("target_event",c_uint32
),
541 ("reset_event",c_uint32
),
544 ("status",c_uint32
)] #runtime
545 sr_functions
= { 0: 'unlock',
549 class ent_region(Structure
):#{
550 _fields_
= [("transform",mdl_transform
),
551 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
552 ("pstr_title",c_uint32
),
554 ("zone_volume",c_uint32
),
556 ("target0",c_uint32
*2)]
557 sr_functions
= { 0: 'enter', 1: 'leave' }
560 class ent_relay(Structure
):#{
561 _fields_
= [("targets",(c_uint32
*2)*4),
562 ("targets_events",c_uint32
*4)]
563 sr_functions
= { 0: 'trigger' }
566 class ent_cubemap(Structure
):#{
567 _fields_
= [("co",c_float
*3),
568 ("resolution",c_uint32
), #placeholder
569 ("live",c_uint32
), #placeholder
570 ("texture_id",c_uint32
), #engine
571 ("framebuffer_id",c_uint32
),#engine
572 ("renderbuffer_id",c_uint32
),#engine
573 ("placeholder",c_uint32
*2)]
576 print( sizeof(ent_cubemap
) )
578 class ent_miniworld(Structure
):#{
579 _fields_
= [("transform",mdl_transform
),
580 ("pstr_world",c_uint32
),
584 sr_functions
= { 0: 'zone', 1: 'leave' }
587 class ent_prop(Structure
):#{
588 _fields_
= [("transform",mdl_transform
),
589 ("submesh_start",c_uint32
),
590 ("submesh_count",c_uint32
),
592 ("pstr_alias",c_uint32
)]
595 def obj_ent_type( obj
):
597 if obj
.type == 'ARMATURE': return 'mdl_armature'
598 elif obj
.type == 'LIGHT': return 'ent_light'
599 elif obj
.type == 'CAMERA': return 'ent_camera'
600 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
602 else: return obj
.SR_data
.ent_type
605 def sr_filter_ent_type( obj
, ent_types
):
607 if obj
== bpy
.context
.active_object
: return False
609 for c0
in obj
.users_collection
:#{
610 for c1
in bpy
.context
.active_object
.users_collection
:#{
612 return obj_ent_type( obj
) in ent_types
620 def v4_dot( a
, b
):#{
621 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
624 def q_identity( q
):#{
631 def q_normalize( q
):#{
633 if( l2
< 0.00001 ):#{
637 s
= 1.0/math
.sqrt(l2
)
645 def compile_obj_transform( obj
, transform
):
647 co
= obj
.matrix_world
@ Vector((0,0,0))
649 # This was changed from matrix_local on 09.05.23
650 q
= obj
.matrix_world
.to_quaternion()
656 transform
.co
[0] = co
[0]
657 transform
.co
[1] = co
[2]
658 transform
.co
[2] = -co
[1]
659 transform
.q
[0] = q
[1]
660 transform
.q
[1] = q
[3]
661 transform
.q
[2] = -q
[2]
662 transform
.q
[3] = q
[0]
663 transform
.s
[0] = s
[0]
664 transform
.s
[1] = s
[2]
665 transform
.s
[2] = s
[1]
668 def int_align_to( v
, align
):
670 while(v
%align
)!=0: v
+= 1
674 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
676 while (len(buffer) % align
) != 0: buffer.extend(w
)
680 def bytearray_print_hex( s
, w
=16 ):
682 for r
in range((len(s
)+(w
-1))//w
):#{
684 i1
=min((r
+1)*w
,len(s
))
685 print( F
'{r*w:06x}| \x1B[31m', end
='')
686 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
687 print( "\x1B[0m", end
='')
688 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
692 def sr_compile_string( s
):
694 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
696 index
= len( sr_compile
.string_data
)
697 sr_compile
.string_cache
[s
] = index
698 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
699 sr_compile
.string_data
.extend( s
.encode('utf-8') )
700 sr_compile
.string_data
.extend( b
'\0' )
702 bytearray_align_to( sr_compile
.string_data
, 4 )
706 def material_tex_image(v
):
716 cxr_graph_mapping
= \
718 # Default shader setup
725 "image": "tex_diffuse"
729 "A": material_tex_image("tex_diffuse"),
730 "B": material_tex_image("tex_decal")
737 "Color": material_tex_image("tex_normal")
743 "Color": material_tex_image("tex_diffuse")
747 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
749 def material_info(mat
):
753 # Using the cxr_graph_mapping as a reference, go through the shader
754 # graph and gather all $props from it.
756 def _graph_read( node_def
, node
=None, depth
=0 ):#{
763 _graph_read
.extracted
= []
766 for node_idname
in node_def
:#{
767 for n
in mat
.node_tree
.nodes
:#{
768 if n
.name
== node_idname
:#{
769 node_def
= node_def
[node_idname
]
779 for link
in node_def
:#{
780 link_def
= node_def
[link
]
782 if isinstance( link_def
, dict ):#{
784 for x
in node
.inputs
:#{
785 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
793 if node_link
and node_link
.is_linked
:#{
794 # look for definitions for the connected node type
796 from_node
= node_link
.links
[0].from_node
798 node_name
= from_node
.name
.split('.')[0]
799 if node_name
in link_def
:#{
800 from_node_def
= link_def
[ node_name
]
802 _graph_read( from_node_def
, from_node
, depth
+1 )
806 if "default" in link_def
:#{
807 prop
= link_def
['default']
808 info
[prop
] = node_link
.default_value
814 info
[prop
] = getattr( node
, link
)
819 _graph_read( cxr_graph_mapping
)
825 decoded
= bytearray()
826 for i
in range(len(s
)//2):#{
827 c
= (ord(s
[i
*2+0])-0x41)
828 c |
= (ord(s
[i
*2+1])-0x41)<<4
829 decoded
.extend(bytearray(c_uint8(c
))) #??
834 def sr_pack_file( file, path
, data
):
836 file.path
= sr_compile_string( path
)
837 file.pack_offset
= len( sr_compile
.pack_data
)
838 file.pack_size
= len( data
)
840 sr_compile
.pack_data
.extend( data
)
841 bytearray_align_to( sr_compile
.pack_data
, 16 )
844 def sr_compile_texture( img
):
849 name
= os
.path
.splitext( img
.name
)[0]
851 if name
in sr_compile
.texture_cache
:
852 return sr_compile
.texture_cache
[name
]
854 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
859 if sr_compile
.pack_textures
:#{
860 filedata
= qoi_encode( img
)
861 sr_pack_file( tex
.file, name
, filedata
)
864 sr_compile
.texture_cache
[name
] = texture_index
865 sr_compile
.texture_data
.extend( bytearray(tex
) )
869 def sr_compile_material( mat
):#{
872 if mat
.name
in sr_compile
.material_cache
:
873 return sr_compile
.material_cache
[mat
.name
]
875 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
876 sr_compile
.material_cache
[mat
.name
] = index
879 m
.pstr_name
= sr_compile_string( mat
.name
)
882 if mat
.SR_data
.collision
:#{
883 flags |
= 0x2 # collision flag
884 if (mat
.SR_data
.shader
!= 'invisible') and \
885 (mat
.SR_data
.shader
!= 'boundary'):#{
886 if mat
.SR_data
.skate_surface
: flags |
= 0x1
887 if mat
.SR_data
.grow_grass
: flags |
= 0x4
888 if mat
.SR_data
.grind_surface
: flags |
= 0x8
889 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
891 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
892 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
893 if mat
.SR_data
.shader
== 'walking': flags |
= (0x10|
0x80)
898 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
899 inf
= material_info( mat
)
901 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
902 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
903 if mat
.SR_data
.shader
== 'foliage': m
.shader
= 10
904 if mat
.SR_data
.shader
== 'terrain_blend':#{
907 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
908 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
909 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
912 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
913 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
916 if mat
.SR_data
.shader
== 'vertex_blend':#{
919 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
920 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
923 if mat
.SR_data
.shader
== 'water':#{
926 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
927 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
928 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
930 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
931 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
932 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
936 if mat
.SR_data
.shader
== 'invisible':#{
940 if mat
.SR_data
.shader
== 'boundary':#{
944 if mat
.SR_data
.shader
== 'fxglow':#{
948 if mat
.SR_data
.shader
== 'cubemap':#{
950 m
.tex_none0
= sr_entity_id( mat
.SR_data
.cubemap
)
952 m
.colour
[0] = pow( mat
.SR_data
.tint
[0], 1.0/2.2 )
953 m
.colour
[1] = pow( mat
.SR_data
.tint
[1], 1.0/2.2 )
954 m
.colour
[2] = pow( mat
.SR_data
.tint
[2], 1.0/2.2 )
955 m
.colour
[3] = pow( mat
.SR_data
.tint
[3], 1.0/2.2 )
958 if mat
.SR_data
.shader
== 'walking':#{
962 if mat
.SR_data
.shader
in ['standard', 'standard_cutout', 'terrain_blend', \
963 'vertex_blend', 'fxglow', 'cubemap', \
965 if 'tex_diffuse' in inf
:
966 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
969 if mat
.SR_data
.tex_diffuse_rt
>= 0:#{
970 m
.tex_diffuse
= 0x80000000 | mat
.SR_data
.tex_diffuse_rt
973 sr_compile
.material_data
.extend( bytearray(m
) )
977 def sr_armature_bones( armature
):
979 def _recurse_bone( b
):
982 for c
in b
.children
: yield from _recurse_bone( c
)
985 for b
in armature
.data
.bones
:
987 yield from _recurse_bone( b
)
990 def sr_entity_id( obj
):#{
993 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
994 index
= sr_compile
.entity_ids
[ obj
.name
]
996 return (tipo
&0xffff)<<16 |
(index
&0xffff)
999 # Returns submesh_start,count and armature_id
1000 def sr_compile_mesh_internal( obj
):
1002 can_use_cache
= True
1009 for mod
in obj
.modifiers
:#{
1010 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
1011 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
1012 mod
.type == 'ARRAY':
1014 can_use_cache
= False
1017 if mod
.type == 'ARMATURE': #{
1018 armature
= mod
.object
1019 rig_weight_groups
= \
1020 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
1021 armature_id
= sr_compile
.entity_ids
[armature
.name
]
1023 POSE_OR_REST_CACHE
= armature
.data
.pose_position
1024 armature
.data
.pose_position
= 'REST'
1028 # Check the cache first
1030 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
1031 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
1032 submesh_start
= ref
[0]
1033 submesh_count
= ref
[1]
1034 return (submesh_start
,submesh_count
,armature_id
)
1037 # Compile a whole new mesh
1039 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
1042 dgraph
= bpy
.context
.evaluated_depsgraph_get()
1043 data
= obj
.evaluated_get(dgraph
).data
1044 data
.calc_loop_triangles()
1045 data
.calc_normals_split()
1047 # Mesh is split into submeshes based on their material
1049 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
1050 for material_id
, mat
in enumerate(mat_list
): #{
1054 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1055 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1058 sm
.material_id
= sr_compile_material( mat
)
1060 INF
=99999999.99999999
1061 for i
in range(3):#{
1066 # Keep a reference to very very very similar vertices
1067 # i have no idea how to speed it up.
1069 vertex_reference
= {}
1071 # Write the vertex / indice data
1073 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
1074 if tri
.material_index
!= material_id
: continue
1076 for j
in range(3):#{
1077 vert
= data
.vertices
[tri
.vertices
[j
]]
1079 vi
= data
.loops
[li
].vertex_index
1081 # Gather vertex information
1084 norm
= data
.loops
[li
].normal
1086 colour
= (255,255,255,255)
1093 uv
= data
.uv_layers
.active
.data
[li
].uv
1097 if data
.vertex_colors
:#{
1098 colour
= data
.vertex_colors
.active
.data
[li
].color
1099 colour
= (int(colour
[0]*255.0),\
1100 int(colour
[1]*255.0),\
1101 int(colour
[2]*255.0),\
1102 int(colour
[3]*255.0))
1105 # Weight groups: truncates to the 3 with the most influence. The
1106 # fourth bone ID is never used by the shader so it
1110 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
1111 if obj
.vertex_groups
[_
.group
].name
in \
1114 weight_groups
= sorted( src_groups
, key
= \
1115 lambda a
: a
.weight
, reverse
=True )
1117 for ml
in range(3):#{
1118 if len(weight_groups
) > ml
:#{
1119 g
= weight_groups
[ml
]
1120 name
= obj
.vertex_groups
[g
.group
].name
1122 weights
[ml
] = weight
1123 groups
[ml
] = rig_weight_groups
.index(name
)
1128 if len(weight_groups
) > 0:#{
1129 inv_norm
= (1.0/tot
) * 65535.0
1130 for ml
in range(3):#{
1131 weights
[ml
] = int( weights
[ml
] * inv_norm
)
1132 weights
[ml
] = min( weights
[ml
], 65535 )
1133 weights
[ml
] = max( weights
[ml
], 0 )
1138 li1
= tri
.loops
[(j
+1)%3]
1139 vi1
= data
.loops
[li1
].vertex_index
1140 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
1142 if e0
.use_freestyle_mark
and \
1143 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
1144 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
1150 TOLERENCE
= float(10**4)
1151 key
= (int(co
[0]*TOLERENCE
+0.5),
1152 int(co
[1]*TOLERENCE
+0.5),
1153 int(co
[2]*TOLERENCE
+0.5),
1154 int(norm
[0]*TOLERENCE
+0.5),
1155 int(norm
[1]*TOLERENCE
+0.5),
1156 int(norm
[2]*TOLERENCE
+0.5),
1157 int(uv
[0]*TOLERENCE
+0.5),
1158 int(uv
[1]*TOLERENCE
+0.5),
1159 colour
[0], # these guys are already quantized
1172 if key
in vertex_reference
:
1173 index
= vertex_reference
[key
]
1175 index
= bytearray(c_uint32(sm
.vertex_count
))
1178 vertex_reference
[key
] = index
1185 v
.norm
[2] = -norm
[1]
1188 v
.colour
[0] = colour
[0]
1189 v
.colour
[1] = colour
[1]
1190 v
.colour
[2] = colour
[2]
1191 v
.colour
[3] = colour
[3]
1192 v
.weights
[0] = weights
[0]
1193 v
.weights
[1] = weights
[1]
1194 v
.weights
[2] = weights
[2]
1195 v
.weights
[3] = weights
[3]
1196 v
.groups
[0] = groups
[0]
1197 v
.groups
[1] = groups
[1]
1198 v
.groups
[2] = groups
[2]
1199 v
.groups
[3] = groups
[3]
1201 for i
in range(3):#{
1202 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1203 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1206 sr_compile
.vertex_data
.extend(bytearray(v
))
1209 sm
.indice_count
+= 1
1210 sr_compile
.indice_data
.extend( index
)
1214 # Make sure bounding box isn't -inf -> inf if no vertices
1216 if sm
.vertex_count
== 0:
1221 # Add submesh to encoder
1223 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1228 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1231 # Save a reference to this mesh since we want to reuse the submesh indices
1233 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1234 return (submesh_start
,submesh_count
,armature_id
)
1237 def sr_compile_mesh( obj
):
1240 compile_obj_transform(obj
, node
.transform
)
1241 node
.pstr_name
= sr_compile_string(obj
.name
)
1242 ent_type
= obj_ent_type( obj
)
1246 if ent_type
!= 'none':#{
1247 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1248 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1249 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1252 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1253 sr_compile_mesh_internal( obj
)
1255 sr_compile
.mesh_data
.extend(bytearray(node
))
1258 def sr_compile_fonts( collection
):
1260 print( F
"[SR] Compiling fonts" )
1265 for obj
in collection
.all_objects
:#{
1266 if obj_ent_type(obj
) != 'ent_font': continue
1268 data
= obj
.SR_data
.ent_font
[0]
1271 font
.alias
= sr_compile_string( data
.alias
)
1272 font
.variant_start
= variant_count
1273 font
.variant_count
= 0
1274 font
.glyph_start
= glyph_count
1276 glyph_base
= data
.glyphs
[0].utf32
1277 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1279 font
.glyph_utf32_base
= glyph_base
1280 font
.glyph_count
= glyph_range
1282 for i
in range(len(data
.variants
)):#{
1283 data_var
= data
.variants
[i
]
1284 if not data_var
.mesh
: continue
1286 mesh
= data_var
.mesh
.data
1288 variant
= ent_font_variant()
1289 variant
.name
= sr_compile_string( data_var
.tipo
)
1291 # fonts (variants) only support one material each
1293 if len(mesh
.materials
) != 0:
1294 mat
= mesh
.materials
[0]
1295 variant
.material_id
= sr_compile_material( mat
)
1297 font
.variant_count
+= 1
1299 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1300 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1302 for j
in range(len(islands
)):#{
1303 for tri
in islands
[j
]:#{
1304 centroids
[j
].x
+= tri
.center
[0]
1305 centroids
[j
].y
+= tri
.center
[2]
1308 centroids
[j
] /= len(islands
[j
])
1311 for j
in range(glyph_range
):#{
1312 data_glyph
= data
.glyphs
[j
]
1314 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1315 glyph
.indice_count
= 0
1316 glyph
.size
[0] = data_glyph
.bounds
[2]
1317 glyph
.size
[1] = data_glyph
.bounds
[3]
1319 vertex_reference
= {}
1321 for k
in range(len(islands
)):#{
1322 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1323 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1324 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1325 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1330 for l
in range(len(islands
[k
])):#{
1332 for m
in range(3):#{
1333 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1335 vi
= mesh
.loops
[li
].vertex_index
1337 # Gather vertex information
1339 co
= [vert
.co
[_
] for _
in range(3)]
1340 co
[0] -= data_glyph
.bounds
[0]
1341 co
[2] -= data_glyph
.bounds
[1]
1342 norm
= mesh
.loops
[li
].normal
1344 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1346 TOLERENCE
= float(10**4)
1347 key
= (int(co
[0]*TOLERENCE
+0.5),
1348 int(co
[1]*TOLERENCE
+0.5),
1349 int(co
[2]*TOLERENCE
+0.5),
1350 int(norm
[0]*TOLERENCE
+0.5),
1351 int(norm
[1]*TOLERENCE
+0.5),
1352 int(norm
[2]*TOLERENCE
+0.5),
1353 int(uv
[0]*TOLERENCE
+0.5),
1354 int(uv
[1]*TOLERENCE
+0.5))
1356 if key
in vertex_reference
:
1357 index
= vertex_reference
[key
]
1359 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1360 index
= bytearray(c_uint32(vindex
))
1361 vertex_reference
[key
] = index
1368 v
.norm
[2] = -norm
[1]
1372 sr_compile
.vertex_data
.extend(bytearray(v
))
1375 glyph
.indice_count
+= 1
1376 sr_compile
.indice_data
.extend( index
)
1380 sr_ent_push( glyph
)
1382 sr_ent_push( variant
)
1388 def sr_compile_menus( collection
):
1390 print( "[SR1] Compiling menus" )
1393 for obj
in collection
.all_objects
:#{
1394 if obj_ent_type(obj
) != 'ent_menuitem': continue
1395 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1397 bitmask
= 0x00000000
1399 for col
in obj
.users_collection
:#{
1401 if name
not in groups
: groups
.append( name
)
1402 bitmask |
= (0x1 << groups
.index(name
))
1405 item
= ent_menuitem()
1406 item
.type = int( obj_data
.tipo
)
1407 item
.groups
= bitmask
1409 compile_obj_transform( obj
, item
.transform
)
1410 if obj
.type == 'MESH':#{
1411 item
.submesh_start
, item
.submesh_count
, _
= \
1412 sr_compile_mesh_internal( obj
)
1415 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1416 item_button
= item
._anonymous
_union
.button
1417 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1418 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1420 elif item
.type == 0:#{
1421 item_visual
= item
._anonymous
_union
.visual
1422 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1424 elif item
.type == 3:#{
1425 item_checkmark
= item
._anonymous
_union
.checkmark
1426 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1427 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1428 delta
= obj_data
.checkmark
.location
- obj
.location
1429 item_checkmark
.offset
[0] = delta
[0]
1430 item_checkmark
.offset
[1] = delta
[2]
1431 item_checkmark
.offset
[2] = -delta
[1]
1433 elif item
.type == 4:#{
1434 item_slider
= item
._anonymous
_union
.slider
1435 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1436 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1437 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1438 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1440 elif item
.type == 5:#{
1441 item_page
= item
._anonymous
_union
.page
1442 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1443 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1444 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1446 elif item
.type == 6:#{
1447 item_binding
= item
._anonymous
_union
.binding
1448 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1449 item_binding
.font_variant
= obj_data
.font_variant
1453 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1455 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1456 if item
.type != 4:#{
1458 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1460 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1467 def sr_compile_armature( obj
):
1469 node
= mdl_armature()
1470 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1472 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1475 bones
= [_
for _
in sr_armature_bones(obj
)]
1476 bones_names
= [None]+[_
.name
for _
in bones
]
1480 if b
.use_deform
: bone
.flags
= 0x1
1481 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1483 bone
.collider
= int(b
.SR_data
.collider
)
1485 if bone
.collider
>0:#{
1486 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1487 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1488 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1489 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1490 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1491 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1494 if b
.SR_data
.cone_constraint
:#{
1496 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1497 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1498 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1499 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1500 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1501 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1502 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1503 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1504 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1505 bone
.conet
= b
.SR_data
.conet
1508 bone
.co
[0] = b
.head_local
[0]
1509 bone
.co
[1] = b
.head_local
[2]
1510 bone
.co
[2] = -b
.head_local
[1]
1511 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1512 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1513 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1514 bone
.pstr_name
= sr_compile_string( b
.name
)
1516 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1517 if c
.type == 'IK':#{
1519 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1520 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1524 node
.bone_count
+= 1
1525 sr_compile
.bone_data
.extend(bytearray(bone
))
1530 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1531 # So we can restore later
1533 previous_frame
= bpy
.context
.scene
.frame_current
1534 previous_action
= obj
.animation_data
.action
1535 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1536 obj
.data
.pose_position
= 'POSE'
1538 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1539 for NLAStrip
in NLALayer
.strips
:#{
1542 for a
in bpy
.data
.actions
:#{
1543 if a
.name
== NLAStrip
.name
:#{
1544 obj
.animation_data
.action
= a
1549 # Clip to NLA settings
1551 anim_start
= int(NLAStrip
.action_frame_start
)
1552 anim_end
= int(NLAStrip
.action_frame_end
)
1556 anim
= mdl_animation()
1557 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1559 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1560 sizeof(mdl_transform
)
1561 anim
.length
= anim_end
-anim_start
1564 # Export the keyframes
1565 for frame
in range(anim_start
,anim_end
):#{
1566 bpy
.context
.scene
.frame_set(frame
)
1569 pb
= obj
.pose
.bones
[rb
.name
]
1571 # relative bone matrix
1572 if rb
.parent
is not None:#{
1573 offset_mtx
= rb
.parent
.matrix_local
1574 offset_mtx
= offset_mtx
.inverted_safe() @ \
1577 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1578 inv_parent
.invert_safe()
1579 fpm
= inv_parent
@ pb
.matrix
1582 bone_mtx
= rb
.matrix
.to_4x4()
1583 local_inv
= rb
.matrix_local
.inverted_safe()
1584 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1587 loc
, rot
, sca
= fpm
.decompose()
1590 lc_m
= pb
.matrix_channel
.to_3x3()
1591 if pb
.parent
is not None:#{
1592 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1593 lc_m
= smtx
.inverted() @ lc_m
1595 rq
= lc_m
.to_quaternion()
1598 kf
= mdl_transform()
1609 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1615 # Add to animation buffer
1617 sr_compile
.anim_data
.extend(bytearray(anim
))
1618 node
.anim_count
+= 1
1622 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1626 # Restore context to how it was before
1628 bpy
.context
.scene
.frame_set( previous_frame
)
1629 obj
.animation_data
.action
= previous_action
1630 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1633 sr_compile
.armature_data
.extend(bytearray(node
))
1636 def sr_ent_push( struct
):
1638 clase
= type(struct
).__name
__
1640 if clase
not in sr_compile
.entity_data
:#{
1641 sr_compile
.entity_data
[ clase
] = bytearray()
1642 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1645 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1646 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1650 def sr_array_title( arr
, name
, count
, size
, offset
):
1652 for i
in range(len(name
)):#{
1653 arr
.name
[i
] = ord(name
[i
])
1655 arr
.file_offset
= offset
1656 arr
.item_count
= count
1657 arr
.item_size
= size
1664 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1669 def sr_compile( collection
):
1671 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1674 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1675 sr_compile
.pack_animations
= collection
.SR_data
.animations
1678 sr_compile
.string_cache
= {}
1679 sr_compile
.mesh_cache
= {}
1680 sr_compile
.material_cache
= {}
1681 sr_compile
.texture_cache
= {}
1684 sr_compile
.mesh_data
= bytearray()
1685 sr_compile
.submesh_data
= bytearray()
1686 sr_compile
.vertex_data
= bytearray()
1687 sr_compile
.indice_data
= bytearray()
1688 sr_compile
.bone_data
= bytearray()
1689 sr_compile
.material_data
= bytearray()
1690 sr_compile
.armature_data
= bytearray()
1691 sr_compile
.anim_data
= bytearray()
1692 sr_compile
.keyframe_data
= bytearray()
1693 sr_compile
.texture_data
= bytearray()
1695 # just bytes not structures
1696 sr_compile
.string_data
= bytearray()
1697 sr_compile
.pack_data
= bytearray()
1700 sr_compile
.entity_data
= {}
1701 sr_compile
.entity_info
= {}
1703 print( F
"[SR] assign entity ID's" )
1704 sr_compile
.entities
= {}
1705 sr_compile
.entity_ids
= {}
1708 # -------------------------------------------------------
1710 sr_compile_string( "null" )
1713 for obj
in collection
.all_objects
: #{
1714 if obj
.type == 'MESH':#{
1718 ent_type
= obj_ent_type( obj
)
1719 if ent_type
== 'none': continue
1721 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1722 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1723 sr_compile
.entities
[ent_type
] += [obj
]
1726 print( F
"[SR] Compiling geometry" )
1728 for obj
in collection
.all_objects
:#{
1729 if obj
.type == 'MESH':#{
1732 ent_type
= obj_ent_type( obj
)
1734 # entity ignore mesh list
1736 if ent_type
== 'ent_traffic': continue
1737 if ent_type
== 'ent_prop': continue
1738 if ent_type
== 'ent_font': continue
1739 if ent_type
== 'ent_font_variant': continue
1740 if ent_type
== 'ent_menuitem': continue
1741 if ent_type
== 'ent_objective': continue
1742 if ent_type
== 'ent_region': continue
1744 #TODO: This is messy.
1745 if ent_type
== 'ent_gate':#{
1746 obj_data
= obj
.SR_data
.ent_gate
[0]
1747 if obj_data
.custom
: continue
1749 #--------------------------
1751 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1752 sr_compile_mesh( obj
)
1756 audio_clip_count
= 0
1757 entity_file_ref_count
= 0
1759 for ent_type
, arr
in sr_compile
.entities
.items():#{
1760 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1762 for i
in range(len(arr
)):#{
1765 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1767 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1768 elif ent_type
== 'ent_light': #{
1770 compile_obj_transform( obj
, light
.transform
)
1771 light
.daytime
= obj
.data
.SR_data
.daytime
1772 if obj
.data
.type == 'POINT':#{
1775 elif obj
.data
.type == 'SPOT':#{
1777 light
.angle
= obj
.data
.spot_size
*0.5
1779 light
.range = obj
.data
.cutoff_distance
1780 light
.colour
[0] = obj
.data
.color
[0]
1781 light
.colour
[1] = obj
.data
.color
[1]
1782 light
.colour
[2] = obj
.data
.color
[2]
1783 light
.colour
[3] = obj
.data
.energy
1784 sr_ent_push( light
)
1786 elif ent_type
== 'ent_camera': #{
1788 compile_obj_transform( obj
, cam
.transform
)
1789 cam
.fov
= obj
.data
.angle
* 45.0
1792 elif ent_type
== 'ent_gate': #{
1794 obj_data
= obj
.SR_data
.ent_gate
[0]
1795 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1799 if obj_data
.tipo
== 'default':#{
1800 if obj_data
.target
:#{
1801 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1805 elif obj_data
.tipo
== 'nonlocal':#{
1807 gate
.key
= sr_compile_string(obj_data
.key
)
1811 if obj_data
.flip
: flags |
= 0x0004
1812 if obj_data
.custom
:#{
1814 gate
.submesh_start
, gate
.submesh_count
, _
= \
1815 sr_compile_mesh_internal( obj
)
1817 if obj_data
.locked
: flags |
= 0x0010
1820 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1821 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1822 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1824 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1825 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1827 if obj_data
.target
:#{
1828 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1829 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1834 for x
in range(2):#{
1835 gate
.co
[x
][0] = co
[x
][0]
1836 gate
.co
[x
][1] = co
[x
][2]
1837 gate
.co
[x
][2] = -co
[x
][1]
1838 gate
.q
[x
][0] = q
[x
][1]
1839 gate
.q
[x
][1] = q
[x
][3]
1840 gate
.q
[x
][2] = -q
[x
][2]
1841 gate
.q
[x
][3] = q
[x
][0]
1846 elif ent_type
== 'ent_spawn': #{
1848 compile_obj_transform( obj
, spawn
.transform
)
1849 obj_data
= obj
.SR_data
.ent_spawn
[0]
1850 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1851 sr_ent_push( spawn
)
1853 elif ent_type
== 'ent_water':#{
1855 compile_obj_transform( obj
, water
.transform
)
1856 water
.max_dist
= 0.0
1857 sr_ent_push( water
)
1859 elif ent_type
== 'ent_audio':#{
1860 obj_data
= obj
.SR_data
.ent_audio
[0]
1862 compile_obj_transform( obj
, audio
.transform
)
1863 audio
.clip_start
= audio_clip_count
1864 audio
.clip_count
= len(obj_data
.files
)
1865 audio_clip_count
+= audio
.clip_count
1866 audio
.max_channels
= obj_data
.max_channels
1867 audio
.volume
= obj_data
.volume
1870 # - allow/disable doppler
1871 # - channel group tags with random colours
1872 # - transition properties
1874 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1875 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1876 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1877 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1878 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1879 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1880 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1882 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1883 if audio
.channel_behaviour
>= 1:#{
1884 audio
.group
= obj_data
.group
1886 if audio
.channel_behaviour
== 2:#{
1887 audio
.crossfade
= obj_data
.transition_duration
1889 audio
.probability_curve
= int(obj_data
.probability_curve
)
1891 for ci
in range(audio
.clip_count
):#{
1892 entry
= obj_data
.files
[ci
]
1893 clip
= ent_audio_clip()
1894 clip
.probability
= entry
.probability
1895 if obj_data
.formato
== '2':#{
1896 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1899 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1900 clip
._anon
.file.pack_offset
= 0
1901 clip
._anon
.file.pack_size
= 0
1905 sr_ent_push( audio
)
1907 elif ent_type
== 'ent_volume':#{
1908 obj_data
= obj
.SR_data
.ent_volume
[0]
1909 volume
= ent_volume()
1910 volume
.type = int(obj_data
.subtype
)
1911 compile_obj_transform( obj
, volume
.transform
)
1913 if obj_data
.target
:#{
1914 volume
.target
= sr_entity_id( obj_data
.target
)
1915 volume
._anon
.trigger
.event
= obj_data
.target_event
1917 ev
= 0xffffffff if obj_data
.target_event_leave
< 0 else \
1918 obj_data
.target_event_leave
1919 volume
._anon
.trigger
.event_leave
= ev
1924 elif ent_type
== 'ent_marker':#{
1925 marker
= ent_marker()
1926 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1927 compile_obj_transform( obj
, marker
.transform
)
1930 elif ent_type
== 'ent_skateshop':#{
1931 skateshop
= ent_skateshop()
1932 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1933 skateshop
.type = int(obj_data
.tipo
)
1934 if skateshop
.type == 0:#{
1935 boardshop
= skateshop
._anonymous
_union
.boards
1936 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1937 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1938 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1940 elif skateshop
.type == 1:#{
1941 charshop
= skateshop
._anonymous
_union
.character
1942 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1943 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1945 elif skateshop
.type == 2:#{
1946 worldshop
= skateshop
._anonymous
_union
.worlds
1947 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1948 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1950 elif skateshop
.type == 3:#{
1951 server
= skateshop
._anonymous
_union
.server
1952 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1954 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1955 compile_obj_transform( obj
, skateshop
.transform
)
1956 sr_ent_push(skateshop
)
1958 elif ent_type
== 'ent_swspreview':#{
1959 workshop_preview
= ent_swspreview()
1960 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1961 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1962 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1963 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1964 sr_ent_push( workshop_preview
)
1966 elif ent_type
== 'ent_worldinfo':#{
1967 worldinfo
= ent_worldinfo()
1968 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1969 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1970 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1971 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1975 if obj_data
.fix_time
:#{
1976 worldinfo
.timezone
= obj_data
.fixed_time
1980 worldinfo
.timezone
= obj_data
.timezone
1982 worldinfo
.flags
= flags
1983 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1984 sr_ent_push( worldinfo
)
1986 elif ent_type
== 'ent_ccmd':#{
1988 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1989 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1992 elif ent_type
== 'ent_objective':#{
1993 objective
= ent_objective()
1994 obj_data
= obj
.SR_data
.ent_objective
[0]
1995 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
1996 objective
.id_win
= sr_entity_id( obj_data
.target
)
1997 objective
.win_event
= obj_data
.target_event
1998 objective
.filter = int(obj_data
.filtrar
)
1999 objective
.filter2
= 0
2000 objective
.time_limit
= obj_data
.time_limit
2002 compile_obj_transform( obj
, objective
.transform
)
2003 objective
.submesh_start
, objective
.submesh_count
, _
= \
2004 sr_compile_mesh_internal( obj
)
2006 sr_ent_push( objective
)
2008 elif ent_type
== 'ent_challenge':#{
2009 challenge
= ent_challenge()
2010 obj_data
= obj
.SR_data
.ent_challenge
[0]
2011 compile_obj_transform( obj
, challenge
.transform
)
2012 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2013 challenge
.target
= sr_entity_id( obj_data
.target
)
2014 challenge
.target_event
= obj_data
.target_event
2015 challenge
.reset
= sr_entity_id( obj_data
.reset
)
2016 challenge
.reset_event
= obj_data
.reset_event
2017 challenge
.first
= sr_entity_id( obj_data
.first
)
2018 challenge
.flags
= 0x00
2019 challenge
.camera
= sr_entity_id( obj_data
.camera
)
2020 if obj_data
.time_limit
: challenge
.flags |
= 0x01
2021 challenge
.status
= 0
2022 sr_ent_push( challenge
)
2024 elif ent_type
== 'ent_region':#{
2025 region
= ent_region()
2026 obj_data
= obj
.SR_data
.ent_region
[0]
2027 compile_obj_transform( obj
, region
.transform
)
2028 region
.submesh_start
, region
.submesh_count
, _
= \
2029 sr_compile_mesh_internal( obj
)
2030 region
.pstr_title
= sr_compile_string( obj_data
.title
)
2031 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
2032 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
2033 region
.target0
[1] = obj_data
.target0_event
2034 sr_ent_push( region
)
2036 elif ent_type
== 'ent_relay':#{
2038 obj_data
= obj
.SR_data
.ent_relay
[0]
2039 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
2040 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
2041 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
2042 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
2043 relay
.targets
[0][1] = obj_data
.target0_event
2044 relay
.targets
[1][1] = obj_data
.target1_event
2045 relay
.targets
[2][1] = obj_data
.target2_event
2046 relay
.targets
[3][1] = obj_data
.target3_event
2047 sr_ent_push( relay
)
2049 # elif ent_type == 'ent_list':#{
2050 # lista = ent_list()
2051 # obj_data = obj.SR_data.ent_list[0]
2053 # lista.entity_ref_start = entity_file_ref_count
2054 # lista.entity_ref_count = len( obj_data.entities )
2055 # entity_file_ref_count += lista.entity_ref_count
2057 # for child in obj_data.entities:#{
2058 # reference_struct = file_entity_ref()
2059 # reference_struct.index = sr_entity_id( child.target )
2060 # sr_ent_push( reference_struct )
2063 # sr_ent_push( lista )
2065 elif ent_type
== 'ent_glider':#{
2066 glider
= ent_glider()
2067 compile_obj_transform( obj
, glider
.transform
)
2068 sr_ent_push( glider
)
2070 elif ent_type
== 'ent_cubemap':#{
2071 cubemap
= ent_cubemap()
2072 co
= obj
.matrix_world
@ Vector((0,0,0))
2073 cubemap
.co
[0] = co
[0]
2074 cubemap
.co
[1] = co
[2]
2075 cubemap
.co
[2] = -co
[1]
2076 cubemap
.resolution
= 0
2078 sr_ent_push( cubemap
)
2080 elif ent_type
== 'ent_miniworld':#{
2081 miniworld
= ent_miniworld()
2082 obj_data
= obj
.SR_data
.ent_miniworld
[0]
2084 compile_obj_transform( obj
, miniworld
.transform
)
2085 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
2086 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
2087 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
2088 sr_ent_push( miniworld
)
2090 elif ent_type
== 'ent_prop':#{
2092 obj_data
= obj
.SR_data
.ent_prop
[0]
2093 compile_obj_transform( obj
, prop
.transform
)
2094 prop
.submesh_start
, prop
.submesh_count
, _
= \
2095 sr_compile_mesh_internal( obj
)
2096 prop
.flags
= obj_data
.flags
2097 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
2103 sr_compile_menus( collection
)
2104 sr_compile_fonts( collection
)
2106 def _children( col
):#{
2108 for c
in col
.children
:#{
2109 yield from _children(c
)
2113 checkpoint_count
= 0
2114 pathindice_count
= 0
2117 for col
in _children(collection
):#{
2118 print( F
"Adding routes for subcollection: {col.name}" )
2124 for obj
in col
.objects
:#{
2125 if obj
.type == 'ARMATURE': pass
2127 ent_type
= obj_ent_type( obj
)
2129 if ent_type
== 'ent_gate':
2130 route_gates
+= [obj
]
2131 elif ent_type
== 'ent_route_node':#{
2132 if obj
.type == 'CURVE':#{
2133 route_curves
+= [obj
]
2136 elif ent_type
== 'ent_route':
2138 elif ent_type
== 'ent_traffic':
2143 dij
= create_node_graph( route_curves
, route_gates
)
2145 for obj
in routes
:#{
2146 obj_data
= obj
.SR_data
.ent_route
[0]
2148 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
2149 route
.checkpoints_start
= checkpoint_count
2150 route
.checkpoints_count
= 0
2151 route
.id_camera
= sr_entity_id( obj_data
.cam
)
2154 route
.colour
[ci
] = obj_data
.colour
[ci
]
2155 route
.colour
[3] = 1.0
2157 compile_obj_transform( obj
, route
.transform
)
2158 checkpoints
= obj_data
.gates
2160 for i
in range(len(checkpoints
)):#{
2161 gi
= checkpoints
[i
].target
2162 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
2166 dest
= gi
.SR_data
.ent_gate
[0].target
2170 if gi
==gj
: continue # error?
2171 if not gi
or not gj
: continue
2173 checkpoint
= ent_checkpoint()
2174 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
2175 checkpoint
.path_start
= pathindice_count
2176 checkpoint
.path_count
= 0
2178 path
= solve_graph( dij
, gi
.name
, gj
.name
)
2181 for pi
in range(len(path
)):#{
2182 pathindice
= ent_path_index()
2183 pathindice
.index
= routenode_count
+ path
[pi
]
2184 sr_ent_push( pathindice
)
2186 checkpoint
.path_count
+= 1
2187 pathindice_count
+= 1
2191 sr_ent_push( checkpoint
)
2192 route
.checkpoints_count
+= 1
2193 checkpoint_count
+= 1
2196 sr_ent_push( route
)
2199 for obj
in traffics
:#{
2200 traffic
= ent_traffic()
2201 compile_obj_transform( obj
, traffic
.transform
)
2202 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2203 sr_compile_mesh_internal( obj
)
2205 # find best subsection
2207 graph_keys
= list(dij
.graph
)
2211 for j
in range(len(dij
.points
)):#{
2212 point
= dij
.points
[j
]
2213 dist
= (point
-obj
.location
).magnitude
2215 if dist
< min_dist
:#{
2222 best_begin
= best_point
2223 best_end
= best_point
2226 map0
= dij
.subsections
[best_begin
]
2227 if map0
[1] == -1: break
2228 best_begin
= map0
[1]
2231 map1
= dij
.subsections
[best_end
]
2232 if map1
[2] == -1: break
2236 traffic
.start_node
= routenode_count
+ best_begin
2237 traffic
.node_count
= best_end
- best_begin
2238 traffic
.index
= best_point
- best_begin
2239 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2242 sr_ent_push(traffic
)
2245 for point
in dij
.points
:#{
2246 rn
= ent_route_node()
2249 rn
.co
[2] = -point
[1]
2253 routenode_count
+= len(dij
.points
)
2256 print( F
"[SR] Writing file" )
2258 file_array_instructions
= {}
2261 def _write_array( name
, item_size
, data
):#{
2262 nonlocal file_array_instructions
, file_offset
2264 count
= len(data
)//item_size
2265 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2266 'data':data
, 'offset': file_offset
}
2267 file_offset
+= len(data
)
2268 file_offset
= int_align_to( file_offset
, 8 )
2271 _write_array( 'strings', 1, sr_compile
.string_data
)
2272 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2273 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2274 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2275 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2276 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2277 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2279 for name
, buffer in sr_compile
.entity_data
.items():#{
2280 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2283 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2284 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2285 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2286 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2287 _write_array( 'pack', 1, sr_compile
.pack_data
)
2289 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2290 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2292 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2293 path
= F
"{folder}{collection.name}.mdl"
2296 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2297 fp
= open( path
, "wb" )
2298 header
= mdl_header()
2299 header
.version
= MDL_VERSION_NR
2300 sr_array_title( header
.arrays
, \
2301 'index', len(file_array_instructions
), \
2302 sizeof(mdl_array
), header_size
)
2304 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2306 print( F
'[SR] {"name":>16}| count | offset' )
2308 for name
,info
in file_array_instructions
.items():#{
2310 offset
= info
['offset'] + header_size
+ index_size
2311 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2312 index
.extend( bytearray(arr
) )
2314 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2315 F
' 0x{info["offset"]:02x}' )
2317 fp
.write( bytearray_align_to( index
, 8 ) )
2318 #bytearray_print_hex( index )
2320 for name
,info
in file_array_instructions
.items():#{
2321 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2326 print( '[SR] done' )
2329 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2331 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2332 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2333 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2335 panel
: bpy
.props
.EnumProperty(
2339 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2340 ('ENTITY', 'Entity', '', 'MONKEY',1),
2341 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2346 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2348 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2349 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2352 def sr_get_mirror_bone( bones
):
2354 side
= bones
.active
.name
[-1:]
2355 other_name
= bones
.active
.name
[:-1]
2356 if side
== 'L': other_name
+= 'R'
2357 elif side
== 'R': other_name
+= 'L'
2361 if b
.name
== other_name
:
2368 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2370 bl_idname
="skaterift.mirror_bone"
2371 bl_label
="Mirror bone attributes - SkateRift"
2373 def execute(_
,context
):
2375 active_object
= context
.active_object
2376 bones
= active_object
.data
.bones
2378 b
= sr_get_mirror_bone( bones
)
2380 if not b
: return {'FINISHED'}
2382 b
.SR_data
.collider
= a
.SR_data
.collider
2384 def _v3copyflipy( a
, b
):#{
2390 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2391 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2392 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2393 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2395 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2397 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2398 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2399 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2401 b
.SR_data
.conet
= a
.SR_data
.conet
2404 ob
= bpy
.context
.scene
.objects
[0]
2405 ob
.hide_render
= ob
.hide_render
2410 class SR_COMPILE(bpy
.types
.Operator
):
2412 bl_idname
="skaterift.compile_all"
2413 bl_label
="Compile All"
2415 def execute(_
,context
):
2417 view_layer
= bpy
.context
.view_layer
2418 for col
in view_layer
.layer_collection
.children
["export"].children
:
2419 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2420 sr_compile( bpy
.data
.collections
[col
.name
] )
2426 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2428 bl_idname
="skaterift.compile_this"
2429 bl_label
="Compile This collection"
2431 def execute(_
,context
):
2433 col
= bpy
.context
.collection
2440 class SR_INTERFACE(bpy
.types
.Panel
):
2442 bl_idname
= "VIEW3D_PT_skate_rift"
2443 bl_label
= "Skate Rift"
2444 bl_space_type
= 'VIEW_3D'
2445 bl_region_type
= 'UI'
2446 bl_category
= "Skate Rift"
2448 def draw(_
, context
):
2452 row
= _
.layout
.row()
2454 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2456 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2457 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2459 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2460 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2461 col
= bpy
.context
.collection
2463 found_in_export
= False
2465 view_layer
= bpy
.context
.view_layer
2466 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2467 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2470 if c1
.name
== col
.name
: #{
2471 found_in_export
= True
2475 box
= _
.layout
.box()
2477 row
.alignment
= 'CENTER'
2480 if found_in_export
: #{
2481 row
.label( text
=col
.name
+ ".mdl" )
2482 box
.prop( col
.SR_data
, "pack_textures" )
2483 box
.prop( col
.SR_data
, "animations" )
2484 box
.operator( "skaterift.compile_this" )
2488 row
.label( text
=col
.name
)
2492 row
.alignment
= 'CENTER'
2494 row
.label( text
="This collection is not in the export group" )
2497 box
= _
.layout
.box()
2500 split
= row
.split( factor
=0.3, align
=True )
2501 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2504 if export_count
== 0:
2506 row1
.operator( "skaterift.compile_all", \
2507 text
=F
"Compile all ({export_count} collections)" )
2509 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2510 active_object
= context
.active_object
2511 if not active_object
: return
2513 amount
= max( 0, len(context
.selected_objects
)-1 )
2515 row
= _
.layout
.row()
2516 row
.operator( 'skaterift.copy_entity_data', \
2517 text
=F
'Copy entity data to {amount} other objects' )
2518 if amount
== 0: row
.enabled
=False
2520 box
= _
.layout
.box()
2522 row
.alignment
= 'CENTER'
2523 row
.label( text
=active_object
.name
)
2526 def _draw_prop_collection( source
, data
): #{
2529 row
.alignment
= 'CENTER'
2532 row
.label( text
=F
'{source}' )
2534 if hasattr(type(data
[0]),'sr_inspector'):#{
2535 type(data
[0]).sr_inspector( box
, data
)
2538 for a
in data
[0].__annotations
__:
2539 box
.prop( data
[0], a
)
2543 if active_object
.type == 'ARMATURE': #{
2544 if active_object
.mode
== 'POSE': #{
2545 bones
= active_object
.data
.bones
2546 mb
= sr_get_mirror_bone( bones
)
2548 box
.operator( "skaterift.mirror_bone", \
2549 text
=F
'Mirror attributes to {mb.name}' )
2552 _draw_prop_collection( \
2553 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2554 [bones
.active
.SR_data
] )
2558 row
.alignment
='CENTER'
2561 row
.label( text
="Enter pose mode to modify bone properties" )
2564 elif active_object
.type == 'LIGHT': #{
2565 _draw_prop_collection( \
2566 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2567 [active_object
.data
.SR_data
] )
2569 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2570 box
.prop( active_object
.SR_data
, "ent_type" )
2571 ent_type
= active_object
.SR_data
.ent_type
2573 col
= getattr( active_object
.SR_data
, ent_type
, None )
2574 if col
!= None and len(col
)!=0:
2575 _draw_prop_collection( \
2576 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2579 if active_object
.type == 'MESH':#{
2580 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2581 if col
!= None and len(col
)!=0:
2582 _draw_prop_collection( \
2583 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2591 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2593 bl_label
="Skate Rift material"
2594 bl_idname
="MATERIAL_PT_sr_material"
2595 bl_space_type
='PROPERTIES'
2596 bl_region_type
='WINDOW'
2597 bl_context
="material"
2599 def draw(_
,context
):
2601 active_object
= bpy
.context
.active_object
2602 if active_object
== None: return
2603 active_mat
= active_object
.active_material
2604 if active_mat
== None: return
2606 info
= material_info( active_mat
)
2608 if 'tex_diffuse' in info
:#{
2609 _
.layout
.label( icon
='INFO', \
2610 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2613 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2614 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2615 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2617 if active_mat
.SR_data
.collision
:#{
2618 box
= _
.layout
.box()
2621 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2622 (active_mat
.SR_data
.shader
!= 'boundary') and \
2623 (active_mat
.SR_data
.shader
!= 'walking'):#{
2624 row
.prop( active_mat
.SR_data
, "skate_surface" )
2625 row
.prop( active_mat
.SR_data
, "grind_surface" )
2626 row
.prop( active_mat
.SR_data
, "grow_grass" )
2627 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2631 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2632 box
= _
.layout
.box()
2633 box
.prop( active_mat
.SR_data
, "blend_offset" )
2634 box
.prop( active_mat
.SR_data
, "sand_colour" )
2636 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2637 box
= _
.layout
.box()
2638 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2639 box
.prop( active_mat
.SR_data
, "blend_offset" )
2641 elif active_mat
.SR_data
.shader
== "water":#{
2642 box
= _
.layout
.box()
2643 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2644 box
.prop( active_mat
.SR_data
, "shore_colour" )
2645 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2647 elif active_mat
.SR_data
.shader
== "cubemap":#{
2648 box
= _
.layout
.box()
2649 box
.prop( active_mat
.SR_data
, "cubemap" )
2650 box
.prop( active_mat
.SR_data
, "tint" )
2653 _
.layout
.label( text
="" )
2654 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2655 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2659 def sr_get_type_enum( scene
, context
):
2661 items
= [('none','None',"")]
2662 mesh_entities
=['ent_gate','ent_water']
2663 point_entities
=['ent_spawn','ent_route_node','ent_route']
2665 for e
in point_entities
: items
+= [(e
,e
,'')]
2667 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2668 if context
.active_object
.type == 'MESH': #{
2669 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2673 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2679 def sr_on_type_change( _
, context
):
2681 obj
= context
.active_object
2682 ent_type
= obj
.SR_data
.ent_type
2683 if ent_type
== 'none': return
2684 if obj
.type == 'MESH':#{
2685 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2686 if col
!= None and len(col
)==0: col
.add()
2689 col
= getattr( obj
.SR_data
, ent_type
, None )
2690 if col
!= None and len(col
)==0: col
.add()
2693 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2695 alias
: bpy
.props
.StringProperty( name
='alias' )
2698 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2700 target
: bpy
.props
.PointerProperty( \
2701 type=bpy
.types
.Object
, name
="destination", \
2702 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2704 key
: bpy
.props
.StringProperty()
2705 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2706 ('nonlocal', 'Non-Local', "")))
2708 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2709 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2710 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2713 def sr_inspector( layout
, data
):
2716 box
.prop( data
[0], 'tipo', text
="subtype" )
2718 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2719 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2722 flags
.prop( data
[0], 'flip' )
2723 flags
.prop( data
[0], 'custom' )
2724 flags
.prop( data
[0], 'locked' )
2728 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2730 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2733 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2735 target
: bpy
.props
.PointerProperty( \
2736 type=bpy
.types
.Object
, name
='target', \
2737 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2740 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2742 world
: bpy
.props
.StringProperty( name
='world UID' )
2743 proxy
: bpy
.props
.PointerProperty( \
2744 type=bpy
.types
.Object
, name
='proxy', \
2745 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2746 camera
: bpy
.props
.PointerProperty( \
2747 type=bpy
.types
.Object
, name
="Camera", \
2748 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2751 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2753 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2755 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2757 layout
.prop( item
, 'target', text
='', emboss
=False )
2761 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2763 active_object
= context
.active_object
2764 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2765 lista
= getattr(data
,collection_name
)
2766 index
= getattr(data
,F
'{collection_name}_index')
2770 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2774 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2776 active_object
= context
.active_object
2777 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2781 def copy_propgroup( de
, to
):
2783 for a
in de
.__annotations
__:#{
2784 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2788 while len(cb
) != len(ca
):#{
2789 if len(cb
) < len(ca
): cb
.add()
2792 for i
in range(len(ca
)):#{
2793 copy_propgroup(ca
[i
],cb
[i
])
2797 setattr(to
,a
,getattr(de
,a
))
2802 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2804 bl_idname
= "skaterift.copy_entity_data"
2805 bl_label
= "Copy entity data"
2807 def execute(self
, context
):#{
2808 data
= context
.active_object
.SR_data
2809 new_type
= data
.ent_type
2810 print( F
"Copy entity data from: {context.active_object.name}" )
2812 for obj
in context
.selected_objects
:#{
2813 if obj
!= context
.active_object
:#{
2814 print( F
" To: {obj.name}" )
2816 obj
.SR_data
.ent_type
= new_type
2818 if active_object
.type == 'MESH':#{
2819 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2820 if col
!= None and len(col
)==0: col
.add()
2821 mdata
= context
.active_object
.data
.SR_data
2822 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2825 col
= getattr( obj
.SR_data
, new_type
, None )
2826 if col
!= None and len(col
)==0: col
.add()
2827 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2834 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2836 bl_idname
= "skaterift.new_entry"
2837 bl_label
= "Add gate"
2839 def execute(self
, context
):#{
2840 return internal_listadd_execute(self
,context
,'ent_route','gates')
2844 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2846 bl_idname
= "skaterift.del_entry"
2847 bl_label
= "Remove gate"
2850 def poll(cls
, context
):#{
2851 active_object
= context
.active_object
2852 if obj_ent_type(active_object
) == 'ent_route':#{
2853 return active_object
.SR_data
.ent_route
[0].gates
2858 def execute(self
, context
):#{
2859 return internal_listdel_execute(self
,context
,'ent_route','gates')
2863 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2865 bl_idname
= "skaterift.al_new_entry"
2866 bl_label
= "Add file"
2868 def execute(self
, context
):#{
2869 return internal_listadd_execute(self
,context
,'ent_audio','files')
2873 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2875 bl_idname
= "skaterift.al_del_entry"
2876 bl_label
= "Remove file"
2879 def poll(cls
, context
):#{
2880 active_object
= context
.active_object
2881 if obj_ent_type(active_object
) == 'ent_audio':#{
2882 return active_object
.SR_data
.ent_audio
[0].files
2887 def execute(self
, context
):#{
2888 return internal_listdel_execute(self
,context
,'ent_audio','files')
2893 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2895 bl_idname
= "skaterift.gl_new_entry"
2896 bl_label
= "Add glyph"
2898 def execute(self
, context
):#{
2899 active_object
= context
.active_object
2901 font
= active_object
.SR_data
.ent_font
[0]
2904 if len(font
.glyphs
) > 1:#{
2905 prev
= font
.glyphs
[-2]
2906 cur
= font
.glyphs
[-1]
2908 cur
.bounds
= prev
.bounds
2909 cur
.utf32
= prev
.utf32
+1
2916 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2918 bl_idname
= "skaterift.gl_del_entry"
2919 bl_label
= "Remove Glyph"
2922 def poll(cls
, context
):#{
2923 active_object
= context
.active_object
2924 if obj_ent_type(active_object
) == 'ent_font':#{
2925 return active_object
.SR_data
.ent_font
[0].glyphs
2930 def execute(self
, context
):#{
2931 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2935 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2937 bl_idname
= "skaterift.gl_move_item"
2939 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2940 ('DOWN', 'Down', ""),))
2943 def poll(cls
, context
):#{
2944 active_object
= context
.active_object
2945 if obj_ent_type(active_object
) == 'ent_font':#{
2946 return active_object
.SR_data
.ent_font
[0].glyphs
2951 def execute(_
, context
):#{
2952 active_object
= context
.active_object
2953 data
= active_object
.SR_data
.ent_font
[0]
2955 index
= data
.glyphs_index
2956 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2957 data
.glyphs
.move( neighbor
, index
)
2959 list_length
= len(data
.glyphs
) - 1
2960 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2962 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2968 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2970 bl_idname
= "skaterift.fv_new_entry"
2971 bl_label
= "Add variant"
2973 def execute(self
, context
):#{
2974 return internal_listadd_execute(self
,context
,'ent_font','variants')
2978 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2980 bl_idname
= "skaterift.fv_del_entry"
2981 bl_label
= "Remove variant"
2984 def poll(cls
, context
):#{
2985 active_object
= context
.active_object
2986 if obj_ent_type(active_object
) == 'ent_font':#{
2987 return active_object
.SR_data
.ent_font
[0].variants
2992 def execute(self
, context
):#{
2993 return internal_listdel_execute(self
,context
,'ent_font','variants')
2997 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2999 path
: bpy
.props
.StringProperty( name
="Path" )
3000 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
3003 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
3005 bl_idname
= 'SR_UL_AUDIO_LIST'
3007 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3009 split
= layout
.split(factor
=0.7)
3011 c
.prop( item
, 'path', text
='', emboss
=False )
3013 c
.prop( item
, 'probability', text
='%', emboss
=True )
3017 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
3019 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
3021 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3023 layout
.prop( item
, 'mesh', emboss
=False )
3024 layout
.prop( item
, 'tipo' )
3028 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
3030 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
3032 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
3034 s0
= layout
.split(factor
=0.3)
3036 s1
= c
.split(factor
=0.3)
3039 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
3043 c
.prop( item
, 'utf32', text
='', emboss
=True )
3046 row
.prop( item
, 'bounds', text
='', emboss
=False )
3050 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
3052 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
3053 gates_index
: bpy
.props
.IntProperty()
3055 colour
: bpy
.props
.FloatVectorProperty( \
3059 default
=Vector((0.79,0.63,0.48)),\
3060 description
="Route colour"\
3063 alias
: bpy
.props
.StringProperty(\
3065 default
="Untitled Course")
3067 cam
: bpy
.props
.PointerProperty( \
3068 type=bpy
.types
.Object
, name
="Viewpoint", \
3069 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3072 def sr_inspector( layout
, data
):
3074 layout
.prop( data
[0], 'alias' )
3075 layout
.prop( data
[0], 'colour' )
3076 layout
.prop( data
[0], 'cam' )
3078 layout
.label( text
='Checkpoints' )
3079 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
3080 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
3083 row
.operator( 'skaterift.new_entry', text
='Add' )
3084 row
.operator( 'skaterift.del_entry', text
='Remove' )
3089 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
3090 bl_idname
= "skaterift.ent_list_new_entry"
3091 bl_label
= "Add entity"
3093 def execute(self
, context
):#{
3094 return internal_listadd_execute(self
,context
,'ent_list','entities')
3098 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
3099 bl_idname
= "skaterift.ent_list_del_entry"
3100 bl_label
= "Remove entity"
3103 def poll(cls
, context
):#{
3104 active_object
= context
.active_object
3105 if obj_ent_type(active_object
) == 'ent_list':#{
3106 return active_object
.SR_data
.ent_list
[0].entities
3111 def execute(self
, context
):#{
3112 return internal_listdel_execute(self
,context
,'ent_list','entities')
3116 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
3118 target
: bpy
.props
.PointerProperty( \
3119 type=bpy
.types
.Object
, name
='target' )
3122 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
3123 bl_idname
= 'SR_UL_ENT_LIST'
3125 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
3126 layout
.prop( item
, 'target', text
='', emboss
=False )
3130 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
3131 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
3132 entities_index
: bpy
.props
.IntProperty()
3135 def sr_inspector( layout
, data
):#{
3136 layout
.label( text
='Entities' )
3137 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
3138 data
[0], 'entities', data
[0], \
3139 'entities_index', rows
=5)
3142 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
3143 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
3147 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
3148 nothing
: bpy
.props
.StringProperty()
3151 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
3152 subtype
: bpy
.props
.EnumProperty(
3154 items
=[('0','Trigger',''),
3155 ('1','Particles (0.1s)','')]
3158 target
: bpy
.props
.PointerProperty( \
3159 type=bpy
.types
.Object
, name
="Target", \
3160 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3161 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
3162 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
3165 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
3167 box
.prop( data
[0], propname
)
3169 for evname
in evs
:#{
3171 row
.prop( data
[0], propname
+ evname
)
3173 target
= getattr( data
[0], propname
)
3175 tipo
= target
.SR_data
.ent_type
3176 cls
= globals()[ tipo
]
3178 table
= getattr( cls
, 'sr_functions', None )
3180 index
= getattr( data
[0], propname
+ evname
)
3182 row
.label( text
=table
[index
] )
3184 row
.label( text
="undefined function" )
3188 row
.label( text
="..." )
3195 def sr_inspector( layout
, data
):#{
3196 layout
.prop( data
[0], 'subtype' )
3197 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3198 ['_event','_event_leave'] )
3202 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3204 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3205 files_index
: bpy
.props
.IntProperty()
3207 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3208 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3209 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3210 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3212 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3213 formato
: bpy
.props
.EnumProperty(
3215 items
=[('0','Uncompressed Mono',''),
3216 ('1','Compressed Vorbis',''),
3217 ('2','[vg] Bird Synthesis','')]
3219 probability_curve
: bpy
.props
.EnumProperty(
3220 name
="Probability Curve",
3221 items
=[('0','Constant',''),
3222 ('1','Wildlife Daytime',''),
3223 ('2','Wildlife Nighttime','')])
3224 channel_behaviour
: bpy
.props
.EnumProperty(
3225 name
="Channel Behaviour",
3226 items
=[('0','Unlimited',''),
3227 ('1','Discard if group full', ''),
3228 ('2','Crossfade if group full','')])
3230 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3233 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3234 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3237 def sr_inspector( layout
, data
):
3239 layout
.prop( data
[0], 'formato' )
3240 layout
.prop( data
[0], 'volume' )
3243 box
.label( text
='Channels' )
3244 split
= box
.split(factor
=0.3)
3246 c
.prop( data
[0], 'max_channels' )
3248 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3249 if data
[0].channel_behaviour
>= '1':
3250 box
.prop( data
[0], 'group' )
3251 if data
[0].channel_behaviour
== '2':
3252 box
.prop( data
[0], 'transition_duration' )
3255 box
.label( text
='Flags' )
3256 box
.prop( data
[0], 'flag_3d' )
3257 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3259 box
.prop( data
[0], 'flag_loop' )
3260 box
.prop( data
[0], 'flag_auto' )
3262 layout
.prop( data
[0], 'probability_curve' )
3264 split
= layout
.split(factor
=0.7)
3266 c
.label( text
='Filepath' )
3268 c
.label( text
='Chance' )
3269 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3270 data
[0], 'files', data
[0], 'files_index', rows
=5)
3273 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3274 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3278 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3280 alias
: bpy
.props
.StringProperty()
3281 flags
: bpy
.props
.IntProperty()
3284 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3286 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3287 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3288 utf32
: bpy
.props
.IntProperty()
3291 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3293 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3294 utf32
: bpy
.props
.IntProperty()
3297 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3299 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3300 tipo
: bpy
.props
.StringProperty()
3303 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3305 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3306 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3307 alias
: bpy
.props
.StringProperty()
3309 glyphs_index
: bpy
.props
.IntProperty()
3310 variants_index
: bpy
.props
.IntProperty()
3313 def sr_inspector( layout
, data
):
3315 layout
.prop( data
[0], 'alias' )
3317 layout
.label( text
='Variants' )
3318 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3319 data
[0], 'variants', data
[0], 'variants_index',\
3322 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3323 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3325 layout
.label( text
='ASCII Glyphs' )
3326 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3327 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3330 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3331 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3332 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3333 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3337 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3339 speed
: bpy
.props
.FloatProperty(default
=1.0)
3342 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3344 tipo
: bpy
.props
.EnumProperty( name
='Type',
3345 items
=[('0','boards',''),
3346 ('1','character',''),
3348 ('4','server','')] )
3349 mark_rack
: bpy
.props
.PointerProperty( \
3350 type=bpy
.types
.Object
, name
="Board Rack", \
3351 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3352 mark_display
: bpy
.props
.PointerProperty( \
3353 type=bpy
.types
.Object
, name
="Selected Board Display", \
3354 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3355 mark_info
: bpy
.props
.PointerProperty( \
3356 type=bpy
.types
.Object
, name
="Selected Board Info", \
3357 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3358 ['ent_marker','ent_prop']))
3359 cam
: bpy
.props
.PointerProperty( \
3360 type=bpy
.types
.Object
, name
="Viewpoint", \
3361 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3364 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3366 mark_display
: bpy
.props
.PointerProperty( \
3367 type=bpy
.types
.Object
, name
="Board Display", \
3368 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3369 mark_display1
: bpy
.props
.PointerProperty( \
3370 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3371 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3372 cam
: bpy
.props
.PointerProperty( \
3373 type=bpy
.types
.Object
, name
="Viewpoint", \
3374 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3377 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3379 link0
: bpy
.props
.PointerProperty( \
3380 type=bpy
.types
.Object
, name
="Link 0", \
3381 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3382 link1
: bpy
.props
.PointerProperty( \
3383 type=bpy
.types
.Object
, name
="Link 1", \
3384 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3385 link2
: bpy
.props
.PointerProperty( \
3386 type=bpy
.types
.Object
, name
="Link 2", \
3387 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3388 link3
: bpy
.props
.PointerProperty( \
3389 type=bpy
.types
.Object
, name
="Link 3", \
3390 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3392 newloc
: bpy
.props
.PointerProperty( \
3393 type=bpy
.types
.Object
, name
="New location", \
3394 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3395 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3396 items
=[('0','append',''),
3397 ('1','replace','')])
3399 camera
: bpy
.props
.PointerProperty( \
3400 type=bpy
.types
.Object
, name
="Camera", \
3401 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3403 slider_minloc
: bpy
.props
.PointerProperty( \
3404 type=bpy
.types
.Object
, name
="Slider min", \
3405 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3406 slider_maxloc
: bpy
.props
.PointerProperty( \
3407 type=bpy
.types
.Object
, name
="Slider max", \
3408 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3409 slider_handle
: bpy
.props
.PointerProperty( \
3410 type=bpy
.types
.Object
, name
="Slider handle", \
3411 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3413 checkmark
: bpy
.props
.PointerProperty( \
3414 type=bpy
.types
.Object
, name
="Checked", \
3415 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3417 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3419 string
: bpy
.props
.StringProperty( name
="String" )
3420 tipo
: bpy
.props
.EnumProperty( name
='Type',
3421 items
=[('0','visual',''),
3422 ('1','event button',''),
3423 ('2','page button',''),
3428 ('7','visual(no colourize)','')])
3431 def sr_inspector( layout
, data
):
3435 box
.prop( data
, 'tipo' )
3437 if data
.tipo
== '0' or data
.tipo
== '7':#{
3438 box
.prop( data
, 'string', text
='Name' )
3441 elif data
.tipo
== '1':#{
3442 box
.prop( data
, 'string', text
='Event' )
3444 elif data
.tipo
== '2':#{
3445 box
.prop( data
, 'string', text
='Page' )
3446 box
.prop( data
, 'stack_behaviour' )
3448 elif data
.tipo
== '3':#{
3449 box
.prop( data
, 'string', text
='Data (i32)' )
3450 box
.prop( data
, 'checkmark' )
3452 elif data
.tipo
== '4':#{
3453 box
.prop( data
, 'string', text
='Data (f32)' )
3454 box
.prop( data
, 'slider_minloc' )
3455 box
.prop( data
, 'slider_maxloc' )
3456 box
.prop( data
, 'slider_handle' )
3458 box
.label( text
="Links" )
3459 box
.prop( data
, 'link0', text
='v0' )
3460 box
.prop( data
, 'link1', text
='v1' )
3463 elif data
.tipo
== '5':#{
3464 box
.prop( data
, 'string', text
='Page Name' )
3465 box
.prop( data
, 'newloc', text
='Entry Point' )
3466 box
.prop( data
, 'camera', text
='Viewpoint' )
3469 elif data
.tipo
== '6':#{
3470 box
.prop( data
, 'string', text
='ID' )
3471 box
.prop( data
, 'font_variant' )
3476 box
.label( text
="Links" )
3477 box
.prop( data
, 'link0' )
3478 box
.prop( data
, 'link1' )
3479 box
.prop( data
, 'link2' )
3480 box
.prop( data
, 'link3' )
3484 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3486 name
: bpy
.props
.StringProperty(name
="Name")
3487 desc
: bpy
.props
.StringProperty(name
="Description")
3488 author
: bpy
.props
.StringProperty(name
="Author")
3489 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3491 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3492 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3493 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3496 def sr_inspector( layout
, data
):#{
3497 layout
.prop( data
[0], 'name' )
3498 layout
.prop( data
[0], 'desc' )
3499 layout
.prop( data
[0], 'author' )
3501 layout
.prop( data
[0], 'fix_time' )
3502 if data
[0].fix_time
:
3503 layout
.prop( data
[0], 'fixed_time' )
3505 layout
.prop( data
[0], 'timezone' )
3509 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3511 command
: bpy
.props
.StringProperty(name
="Command Line")
3514 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3515 proxima
: bpy
.props
.PointerProperty( \
3516 type=bpy
.types
.Object
, name
="Next", \
3517 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3518 target
: bpy
.props
.PointerProperty( \
3519 type=bpy
.types
.Object
, name
="Win", \
3520 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3521 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3522 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3523 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3524 items
=[('0','none',''),
3525 (str(0x1),'trick_shuvit',''),
3526 (str(0x2),'trick_kickflip',''),
3527 (str(0x4),'trick_treflip',''),
3528 (str(0x1|
0x2|
0x4),'trick_any',''),
3529 (str(0x8),'flip_back',''),
3530 (str(0x10),'flip_front',''),
3531 (str(0x8|
0x10),'flip_any',''),
3532 (str(0x20),'grind_truck_any',''),
3533 (str(0x40),'grind_board_any',''),
3534 (str(0x20|
0x40),'grind_any',''),
3535 (str(0x80),'footplant',''),
3536 (str(0x100),'passthrough',''),
3540 def sr_inspector( layout
, data
):#{
3541 layout
.prop( data
[0], 'proxima' )
3542 layout
.prop( data
[0], 'time_limit' )
3543 layout
.prop( data
[0], 'filtrar' )
3544 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3548 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3549 alias
: bpy
.props
.StringProperty( name
="Alias" )
3551 target
: bpy
.props
.PointerProperty( \
3552 type=bpy
.types
.Object
, name
="On Complete", \
3553 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3554 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3555 reset
: bpy
.props
.PointerProperty( \
3556 type=bpy
.types
.Object
, name
="On Reset", \
3557 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3558 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3560 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3562 first
: bpy
.props
.PointerProperty( \
3563 type=bpy
.types
.Object
, name
="First Objective", \
3564 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3566 camera
: bpy
.props
.PointerProperty( \
3567 type=bpy
.types
.Object
, name
="Camera", \
3568 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3572 def sr_inspector( layout
, data
):#{
3573 layout
.prop( data
[0], 'alias' )
3574 layout
.prop( data
[0], 'camera' )
3575 layout
.prop( data
[0], 'first' )
3576 layout
.prop( data
[0], 'time_limit' )
3577 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3578 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3582 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3583 title
: bpy
.props
.StringProperty( name
="Title" )
3584 zone_volume
: bpy
.props
.PointerProperty(
3585 type=bpy
.types
.Object
, name
="Zone Volume", \
3586 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3588 target0
: bpy
.props
.PointerProperty( \
3589 type=bpy
.types
.Object
, name
="Triger on unlock", \
3590 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3591 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3594 def sr_inspector( layout
, data
):#{
3595 layout
.prop( data
[0], 'title' )
3596 layout
.prop( data
[0], 'zone_volume' )
3597 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3601 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3602 target0
: bpy
.props
.PointerProperty( \
3603 type=bpy
.types
.Object
, name
="Target 0", \
3604 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3605 target1
: bpy
.props
.PointerProperty( \
3606 type=bpy
.types
.Object
, name
="Target 1", \
3607 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3608 target2
: bpy
.props
.PointerProperty( \
3609 type=bpy
.types
.Object
, name
="Target 2", \
3610 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3611 target3
: bpy
.props
.PointerProperty( \
3612 type=bpy
.types
.Object
, name
="Target 3", \
3613 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3615 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3616 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3617 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3618 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3621 def sr_inspector( layout
, data
):#{
3622 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3623 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3624 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3625 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3629 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3631 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3632 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3633 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3634 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3635 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3636 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3637 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3638 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3639 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3640 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3641 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3643 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3644 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3645 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3646 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3647 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3648 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3649 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3650 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3651 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3652 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3653 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3655 ent_type
: bpy
.props
.EnumProperty(
3657 items
=sr_entity_list
,
3658 update
=sr_on_type_change
3662 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3664 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3667 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3669 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3672 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3674 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3675 items
=[('0','none',''),
3677 ('2','capsule','')])
3679 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3680 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3682 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3684 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3685 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3686 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3687 conet
: bpy
.props
.FloatProperty( name
='t' )
3690 def sr_inspector( layout
, data
):
3694 box
.prop( data
, 'collider' )
3696 if int(data
.collider
)>0:#{
3698 row
.prop( data
, 'collider_min' )
3700 row
.prop( data
, 'collider_max' )
3704 box
.prop( data
, 'cone_constraint' )
3705 if data
.cone_constraint
:#{
3707 row
.prop( data
, 'conevx' )
3709 row
.prop( data
, 'conevy' )
3711 row
.prop( data
, 'coneva' )
3712 box
.prop( data
, 'conet' )
3717 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3719 shader
: bpy
.props
.EnumProperty(
3722 ('standard',"standard",''),
3723 ('standard_cutout', "standard_cutout", ''),
3724 ('terrain_blend', "terrain_blend", ''),
3725 ('vertex_blend', "vertex_blend", ''),
3726 ('water',"water",''),
3727 ('invisible','Invisible',''),
3728 ('boundary','Boundary',''),
3729 ('fxglow','FX Glow',''),
3730 ('cubemap','Cubemap',''),
3731 ('walking','Walking',''),
3732 ('foliage','Foliage','')
3735 surface_prop
: bpy
.props
.EnumProperty(
3736 name
="Surface Property",
3738 ('0','concrete',''),
3743 ('5','snow (low friction)',''),
3744 ('6','sand (medium friction)','')
3747 collision
: bpy
.props
.BoolProperty( \
3748 name
="Collisions Enabled",\
3750 description
= "Can the player collide with this material?"\
3752 skate_surface
: bpy
.props
.BoolProperty( \
3753 name
="Skate Target", \
3755 description
= "Should the game try to target this surface?" \
3757 grind_surface
: bpy
.props
.BoolProperty( \
3760 description
= "Can you grind on this surface?" \
3762 grow_grass
: bpy
.props
.BoolProperty( \
3763 name
="Grow Grass", \
3765 description
= "Spawn grass sprites on this surface?" \
3767 preview_visibile
: bpy
.props
.BoolProperty( \
3768 name
="Preview visibile", \
3770 description
= "Show this material in preview models?" \
3772 blend_offset
: bpy
.props
.FloatVectorProperty( \
3773 name
="Blend Offset", \
3775 default
=Vector((0.5,0.0)),\
3776 description
="When surface is more than 45 degrees, add this vector " +\
3779 sand_colour
: bpy
.props
.FloatVectorProperty( \
3780 name
="Sand Colour",\
3783 default
=Vector((0.79,0.63,0.48)),\
3784 description
="Blend to this colour near the 0 coordinate on UP axis"\
3786 shore_colour
: bpy
.props
.FloatVectorProperty( \
3787 name
="Shore Colour",\
3790 default
=Vector((0.03,0.32,0.61)),\
3791 description
="Water colour at the shoreline"\
3793 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3794 name
="Ocean Colour",\
3797 default
=Vector((0.0,0.006,0.03)),\
3798 description
="Water colour in the deep bits"\
3800 tint
: bpy
.props
.FloatVectorProperty( \
3805 default
=Vector((1.0,1.0,1.0,1.0)),\
3806 description
="Reflection tint"\
3809 cubemap
: bpy
.props
.PointerProperty( \
3810 type=bpy
.types
.Object
, name
="cubemap", \
3811 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3813 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3816 # ---------------------------------------------------------------------------- #
3820 # ---------------------------------------------------------------------------- #
3822 cv_view_draw_handler
= None
3823 cv_view_pixel_handler
= None
3824 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3826 cv_view_colours
= []
3827 cv_view_course_i
= 0
3829 # Draw axis alligned sphere at position with radius
3831 def cv_draw_sphere( pos
, radius
, colour
):
3833 global cv_view_verts
, cv_view_colours
3835 ly
= pos
+ Vector((0,0,radius
))
3836 lx
= pos
+ Vector((0,radius
,0))
3837 lz
= pos
+ Vector((0,0,radius
))
3839 pi
= 3.14159265358979323846264
3841 for i
in range(16):#{
3842 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3846 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3847 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3848 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3850 cv_view_verts
+= [ px
, lx
]
3851 cv_view_verts
+= [ py
, ly
]
3852 cv_view_verts
+= [ pz
, lz
]
3854 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3863 # Draw axis alligned sphere at position with radius
3865 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3867 global cv_view_verts
, cv_view_colours
3869 ly
= pos
+ tz
*radius
3870 lx
= pos
+ ty
*radius
3871 lz
= pos
+ tz
*radius
3873 pi
= 3.14159265358979323846264
3875 for i
in range(16):#{
3876 t
= ((i
+1.0) * 1.0/16.0) * pi
3880 s1
= math
.sin(t
*2.0)
3881 c1
= math
.cos(t
*2.0)
3883 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3884 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3885 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3887 cv_view_verts
+= [ px
, lx
]
3888 cv_view_verts
+= [ py
, ly
]
3889 cv_view_verts
+= [ pz
, lz
]
3891 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3900 # Draw transformed -1 -> 1 cube
3902 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3904 global cv_view_verts
, cv_view_colours
3910 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3911 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3912 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3913 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3914 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3915 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3916 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3917 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3919 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3920 (0,4),(1,5),(2,6),(3,7)]
3925 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3926 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3927 cv_view_colours
+= [colour
, colour
]
3932 # Draw line with colour
3934 def cv_draw_line( p0
, p1
, colour
):
3936 global cv_view_verts
, cv_view_colours
3938 cv_view_verts
+= [p0
,p1
]
3939 cv_view_colours
+= [colour
, colour
]
3943 # Draw line with colour(s)
3945 def cv_draw_line2( p0
, p1
, c0
, c1
):
3947 global cv_view_verts
, cv_view_colours
3949 cv_view_verts
+= [p0
,p1
]
3950 cv_view_colours
+= [c0
,c1
]
3956 def cv_tangent_basis( n
, tx
, ty
):
3958 if abs( n
[0] ) >= 0.57735027:#{
3977 # Draw coloured arrow
3979 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
3981 global cv_view_verts
, cv_view_colours
3987 tx
= Vector((1,0,0))
3988 ty
= Vector((1,0,0))
3989 cv_tangent_basis( n
, tx
, ty
)
3995 gpu
.state
.line_width_set(1.0)
3998 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3999 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
4003 gpu
.state
.line_width_set(3.0)
4004 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
4006 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
4008 gpu
.state
.line_width_set(2.0)
4012 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
4014 global cv_view_verts
, cv_view_colours
4016 for i
in range(dots
):#{
4020 p2
= p0
*(1.0-t0
)+p1
*t0
4021 p3
= p0
*(1.0-t1
)+p1
*t1
4023 cv_view_verts
+= [p2
,p3
]
4024 cv_view_colours
+= [c0
,c0
]
4029 # Drawhandles of a bezier control point
4031 def cv_draw_bhandle( obj
, direction
, colour
):
4033 global cv_view_verts
, cv_view_colours
4036 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
4038 cv_view_verts
+= [p0
]
4039 cv_view_verts
+= [h0
]
4040 cv_view_colours
+= [colour
,colour
]
4044 # Draw a bezier curve (at fixed resolution 10)
4046 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
4048 global cv_view_verts
, cv_view_colours
4051 for i
in range(10):#{
4057 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
4059 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
4060 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
4061 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
4068 # I think this one extends the handles of the bezier otwards......
4070 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
4072 global cv_view_course_i
4074 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
4076 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
4077 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
4078 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
4079 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
4081 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
4085 # Flush the lines buffers. This is called often because god help you if you want
4086 # to do fixed, fast buffers in this catastrophic programming language.
4088 def cv_draw_lines():
4090 global cv_view_shader
, cv_view_verts
, cv_view_colours
4092 if len(cv_view_verts
) < 2:
4095 lines
= batch_for_shader(\
4096 cv_view_shader
, 'LINES', \
4097 { "pos":cv_view_verts
, "color":cv_view_colours
})
4099 if bpy
.context
.scene
.SR_data
.gizmos
:
4100 lines
.draw( cv_view_shader
)
4103 cv_view_colours
= []
4106 # I dont remember what this does exactly
4108 def cv_draw_bpath( o0
,o1
,c0
,c1
):
4110 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
4113 # Semi circle to show the limit. and some lines
4115 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
4117 global cv_view_verts
, cv_view_colours
4122 for x
in range(16):#{
4125 a0
= amin
*(1.0-t0
)+amax
*t0
4126 a1
= amin
*(1.0-t1
)+amax
*t1
4128 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
4129 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
4131 p0
=obj
.matrix_world
@ p0
4132 p1
=obj
.matrix_world
@ p1
4133 cv_view_verts
+= [p0
,p1
]
4134 cv_view_colours
+= [colour
,colour
]
4137 cv_view_verts
+= [p0
,center
]
4138 cv_view_colours
+= [colour
,colour
]
4141 cv_view_verts
+= [p1
,center
]
4142 cv_view_colours
+= [colour
,colour
]
4146 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
4147 cv_view_colours
+= [colour
,colour
]
4152 # Cone and twist limit
4154 def draw_cone_twist( center
, vx
, vy
, va
):
4156 global cv_view_verts
, cv_view_colours
4157 axis
= vy
.cross( vx
)
4162 cv_view_verts
+= [center
, center
+va
*size
]
4163 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4165 for x
in range(32):#{
4166 t0
= (x
/32) * math
.tau
4167 t1
= ((x
+1)/32) * math
.tau
4174 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4175 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4177 col0
= ( abs(c0
), abs(s0
), 0.0 )
4178 col1
= ( abs(c1
), abs(s1
), 0.0 )
4180 cv_view_verts
+= [center
, p0
, p0
, p1
]
4181 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4187 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4189 def draw_skeleton_helpers( obj
):
4191 global cv_view_verts
, cv_view_colours
4193 if obj
.data
.pose_position
!= 'REST':#{
4197 for bone
in obj
.data
.bones
:#{
4199 a
= Vector((bone
.SR_data
.collider_min
[0],
4200 bone
.SR_data
.collider_min
[1],
4201 bone
.SR_data
.collider_min
[2]))
4202 b
= Vector((bone
.SR_data
.collider_max
[0],
4203 bone
.SR_data
.collider_max
[1],
4204 bone
.SR_data
.collider_max
[2]))
4206 if bone
.SR_data
.collider
== '1':#{
4208 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4209 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4210 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4211 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4212 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4213 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4214 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4215 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4217 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4218 (0,4),(1,5),(2,6),(3,7)]
4224 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4225 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4226 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4229 elif bone
.SR_data
.collider
== '2':#{
4234 for i
in range(3):#{
4235 if abs(v0
[i
]) > largest
:#{
4236 largest
= abs(v0
[i
])
4241 v1
= Vector((0,0,0))
4242 v1
[major_axis
] = 1.0
4244 tx
= Vector((0,0,0))
4245 ty
= Vector((0,0,0))
4247 cv_tangent_basis( v1
, tx
, ty
)
4248 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4249 l
= v0
[ major_axis
] - r
*2
4251 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4252 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4254 colour
= [0.2,0.2,0.2]
4255 colour
[major_axis
] = 0.5
4257 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4258 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4259 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4260 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4261 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4262 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4268 center
= obj
.matrix_world
@ c
4269 if bone
.SR_data
.cone_constraint
:#{
4270 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4271 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4272 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4273 draw_cone_twist( center
, vx
, vy
, va
)
4278 def cv_draw_wireframe( mdl
, points
, colour
):#{
4279 for i
in range(len(points
)//2):#{
4280 p0
= mdl
@points[i
*2+0]
4281 p1
= mdl
@points[i
*2+1]
4282 cv_draw_line( p0
, p1
, colour
)
4286 def cv_ent_gate( obj
):
4288 global cv_view_verts
, cv_view_colours
4290 if obj
.type != 'MESH': return
4292 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4293 data
= obj
.SR_data
.ent_gate
[0]
4294 dims
= mesh_data
.dimensions
4297 c
= Vector((0,0,dims
[2]))
4299 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4300 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4301 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4302 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4303 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4304 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4305 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4306 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4307 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4309 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4311 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4313 p0
= r3d
.view_matrix
.inverted().translation
4314 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4315 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4317 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4323 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4324 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4325 cv_view_colours
+= [cc
,cc
]
4329 if data
.target
!= None:
4330 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4333 def cv_ent_volume( obj
):
4335 global cv_view_verts
, cv_view_colours
4337 data
= obj
.SR_data
.ent_volume
[0]
4339 if data
.subtype
== '0':#{
4340 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4343 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4346 elif data
.subtype
== '1':#{
4347 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4350 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4355 def dijkstra( graph
, start_node
, target_node
):
4357 unvisited
= [_
for _
in graph
]
4362 shortest_path
[n
] = 9999999.999999
4363 shortest_path
[start_node
] = 0
4366 current_min_node
= None
4367 for n
in unvisited
:#{
4368 if current_min_node
== None:
4369 current_min_node
= n
4370 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4371 current_min_node
= n
4374 for branch
in graph
[current_min_node
]:#{
4375 tentative_value
= shortest_path
[current_min_node
]
4376 tentative_value
+= graph
[current_min_node
][branch
]
4377 if tentative_value
< shortest_path
[branch
]:#{
4378 shortest_path
[branch
] = tentative_value
4379 previous_nodes
[branch
] = current_min_node
4383 unvisited
.remove(current_min_node
)
4388 while node
!= start_node
:#{
4391 if node
not in previous_nodes
: return None
4392 node
= previous_nodes
[node
]
4395 # Add the start node manually
4396 path
.append(start_node
)
4402 def __init__(_
,points
,graph
,subsections
):#{
4405 _
.subsections
= subsections
4409 def create_node_graph( curves
, gates
):
4411 # add endpoints of curves
4418 for c
in range(len(curves
)):#{
4419 for s
in range(len(curves
[c
].data
.splines
)):#{
4420 spline
= curves
[c
].data
.splines
[s
]
4421 l
= len(spline
.points
)
4424 dist
= round(spline
.calc_length(),2)
4427 ib
= point_count
+l
-1
4429 graph
[ia
] = { ib
: dist
}
4430 graph
[ib
] = { ia
: dist
}
4432 for i
in range(len(spline
.points
)):#{
4433 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4434 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4439 if i
== 0: previous
= -1
4440 if i
== len(spline
.points
)-1: proxima
= -1
4442 subsections
.append((spline_count
,previous
,proxima
))
4451 graph_keys
= list(graph
)
4452 for i
in range(len(graph_keys
)-1):#{
4453 for j
in range(i
+1, len(graph_keys
)):#{
4454 if i
%2==0 and i
+1==j
: continue
4458 pi
= route_points
[ni
]
4459 pj
= route_points
[nj
]
4461 dist
= round((pj
-pi
).magnitude
,2)
4464 graph
[ni
][nj
] = dist
4465 graph
[nj
][ni
] = dist
4470 # add and link gates( by name )
4471 for gate
in gates
:#{
4472 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4473 if gate
.SR_data
.ent_gate
[0].target
:
4476 graph
[ gate
.name
] = {}
4478 for i
in range(len(graph_keys
)):#{
4480 pi
= route_points
[ni
]
4482 v0
= pi
-gate
.location
4483 if v0
.dot(v1
) < 0.0: continue
4485 dist
= round(v0
.magnitude
,2)
4488 graph
[ gate
.name
][ ni
] = dist
4489 graph
[ ni
][ gate
.name
] = dist
4494 return dij_graph(route_points
,graph
,subsections
)
4497 def solve_graph( dij
, start
, end
):
4499 path
= dijkstra( dij
.graph
, end
, start
)
4503 for sj
in range(1,len(path
)-2):#{
4506 map0
= dij
.subsections
[i0
]
4507 map1
= dij
.subsections
[i1
]
4509 if map0
[0] == map1
[0]:#{
4510 if map0
[1] == -1: direction
= 2
4515 map0
= dij
.subsections
[i0
]
4516 i1
= map0
[direction
]
4530 full
.append( path
[-2] )
4535 def cv_draw_route( route
, dij
):
4537 pole
= Vector((0.2,0.2,10))
4538 hat
= Vector((1,8,0.2))
4539 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4540 route
.SR_data
.ent_route
[0].colour
[1],
4541 route
.SR_data
.ent_route
[0].colour
[2])
4543 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4544 Vector((0,-6.5,5.5)))
4545 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4546 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4547 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4548 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4550 checkpoints
= route
.SR_data
.ent_route
[0].gates
4552 for i
in range(len(checkpoints
)):#{
4553 gi
= checkpoints
[i
].target
4554 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4557 dest
= gi
.SR_data
.ent_gate
[0].target
4559 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4563 if gi
==gj
: continue # error?
4564 if not gi
or not gj
: continue
4566 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4569 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4570 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4571 for j
in range(len(path
)-1):#{
4574 o0
= dij
.points
[ i0
]
4575 o1
= dij
.points
[ i1
]
4576 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4580 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4586 global cv_view_shader
4587 global cv_view_verts
4588 global cv_view_colours
4589 global cv_view_course_i
4591 cv_view_course_i
= 0
4593 cv_view_colours
= []
4595 cv_view_shader
.bind()
4596 gpu
.state
.depth_mask_set(True)
4597 gpu
.state
.line_width_set(2.0)
4598 gpu
.state
.face_culling_set('BACK')
4599 gpu
.state
.depth_test_set('LESS')
4600 gpu
.state
.blend_set('NONE')
4606 for obj
in bpy
.context
.collection
.objects
:#{
4607 if obj
.type == 'ARMATURE':#{
4608 if obj
.data
.pose_position
== 'REST':
4609 draw_skeleton_helpers( obj
)
4612 ent_type
= obj_ent_type( obj
)
4614 if ent_type
== 'ent_gate':#{
4616 route_gates
+= [obj
]
4618 elif ent_type
== 'ent_route_node':#{
4619 if obj
.type == 'CURVE':#{
4620 route_curves
+= [obj
]
4623 elif ent_type
== 'ent_route':
4625 elif ent_type
== 'ent_volume':#{
4626 cv_ent_volume( obj
)
4628 elif ent_type
== 'ent_objective':#{
4629 data
= obj
.SR_data
.ent_objective
[0]
4631 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4634 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4636 elif ent_type
== 'ent_relay':#{
4637 data
= obj
.SR_data
.ent_relay
[0]
4639 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4641 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4643 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4645 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4647 elif ent_type
== 'ent_challenge':#{
4648 data
= obj
.SR_data
.ent_challenge
[0]
4650 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4652 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4654 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4657 info_cu
= Vector((1.2,0.01,0.72))*0.5
4658 info_co
= Vector((0.0,0.0,0.72))*0.5
4659 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4661 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4663 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4664 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4665 Vector(( 0.1,0.0,0.30))]
4666 for v
in range(len(vs
)):#{
4667 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4670 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4671 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4673 elif ent_type
== 'ent_audio':#{
4674 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4675 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4677 elif ent_type
== 'ent_font':#{
4678 data
= obj
.SR_data
.ent_font
[0]
4680 for i
in range(len(data
.variants
)):#{
4681 sub
= data
.variants
[i
].mesh
4682 if not sub
: continue
4684 for ch
in data
.glyphs
:#{
4685 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4686 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4687 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4688 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4689 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4690 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4692 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4695 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4696 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4700 elif ent_type
== 'ent_glider':#{
4701 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4702 Vector(( 1.13982, 0.137084, -0.026358)), \
4703 Vector(( 0.0, 1.6, 1.0)), \
4704 Vector(( 0.0, -3.0, 1.0)), \
4705 Vector(( -3.45, -1.78, 0.9)), \
4706 Vector(( 0.0, 1.6, 1.0)), \
4707 Vector(( 3.45, -1.78, 0.9)), \
4708 Vector(( 0.0, 1.6, 1.0)), \
4709 Vector(( 3.45, -1.78, 0.9)), \
4710 Vector(( -3.45, -1.78, 0.9))]
4712 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4714 elif ent_type
== 'ent_skateshop':#{
4715 data
= obj
.SR_data
.ent_skateshop
[0]
4716 display
= data
.mark_display
4717 info
= data
.mark_info
4719 if data
.tipo
== '0':#{
4724 rack
= data
.mark_rack
4726 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4727 rack_co
= Vector((0.0,0.0,0.0))
4728 display_cu
= Vector((0.3,1.2,0.1))*0.5
4729 display_co
= Vector((0.0,0.0,0.1))*0.5
4730 info_cu
= Vector((1.2,0.01,0.3))*0.5
4731 info_co
= Vector((0.0,0.0,0.0))*0.5
4733 elif data
.tipo
== '1':#{
4737 display_cu
= Vector((0.4,0.4,2.0))*0.5
4738 display_co
= Vector((0.0,0.0,1.0))*0.5
4739 info_cu
= Vector((1.2,0.01,0.3))*0.5
4740 info_co
= Vector((0.0,0.0,0.0))*0.5
4742 elif data
.tipo
== '2':#{
4746 display_cu
= Vector((1.0,1.0,0.5))*0.5
4747 display_co
= Vector((0.0,0.0,0.5))*0.5
4748 info_cu
= Vector((1.2,0.01,0.3))*0.5
4749 info_co
= Vector((0.0,0.0,0.0))*0.5
4751 elif data
.tipo
== '3':#{
4756 elif data
.tipo
== '4':#{
4763 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4765 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4767 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4769 elif ent_type
== 'ent_swspreview':#{
4771 data
= obj
.SR_data
.ent_swspreview
[0]
4772 display
= data
.mark_display
4773 display1
= data
.mark_display1
4774 display_cu
= Vector((0.3,1.2,0.1))*0.5
4775 display_co
= Vector((0.0,0.0,0.1))*0.5
4777 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4779 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4781 # elif ent_type == 'ent_list':#{
4782 # data = obj.SR_data.ent_list[0]
4783 # for child in data.entities:#{
4784 # if child.target:#{
4785 # cv_draw_arrow( obj.location, child.target.location, \
4790 elif ent_type
== 'ent_region':#{
4791 data
= obj
.SR_data
.ent_region
[0]
4793 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4797 elif ent_type
== 'ent_menuitem':#{
4798 for i
,col
in enumerate(obj
.users_collection
):#{
4799 colour32
= hash_djb2( col
.name
)
4800 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4801 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4802 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4804 vs
= [None for _
in range(8)]
4806 for j
in range(8):#{
4807 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4808 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4810 vs
[j
] = obj
.matrix_world
@ v0
4812 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4813 (0,4),(1,5),(2,6),(3,7)]
4817 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4818 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4819 cv_view_colours
+= [cc
,cc
]
4824 data
= obj
.SR_data
.ent_menuitem
[0]
4825 if data
.tipo
== '4':#{
4826 if data
.slider_minloc
and data
.slider_maxloc
:#{
4827 v0
= data
.slider_minloc
.location
4828 v1
= data
.slider_maxloc
.location
4829 cv_draw_line( v0
, v1
, cc
)
4833 colour32
= hash_djb2(obj
.name
)
4834 r
= ((colour32
) & 0xff) / 255.0
4835 g
= ((colour32
>>8 ) & 0xff) / 255.0
4836 b
= ((colour32
>>16) & 0xff) / 255.0
4838 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4843 if data
.tipo
!= '0':#{
4844 if data
.tipo
== '4':#{
4846 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4849 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4854 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4857 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4860 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4863 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4871 dij
= create_node_graph( route_curves
, route_gates
)
4873 #cv_draw_route_map( route_nodes )
4874 for route
in routes
:#{
4875 cv_draw_route( route
, dij
)
4881 def pos3d_to_2d( pos
):#{
4882 return view3d_utils
.location_3d_to_region_2d( \
4883 bpy
.context
.region
, \
4884 bpy
.context
.space_data
.region_3d
, pos
)
4887 def cv_draw_pixel():#{
4888 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4890 blf
.color(0, 1.0,1.0,1.0,0.9)
4891 blf
.enable(0,blf
.SHADOW
)
4892 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4893 for obj
in bpy
.context
.collection
.objects
:#{
4894 ent_type
= obj_ent_type( obj
)
4896 if ent_type
!= 'none':#{
4897 co
= pos3d_to_2d( obj
.location
)
4900 blf
.position(0,co
[0],co
[1],0)
4901 blf
.draw(0,ent_type
)
4906 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4907 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4908 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4910 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4911 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4912 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4913 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4914 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4915 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4916 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4917 SR_OT_COPY_ENTITY_DATA
, \
4918 SR_OBJECT_ENT_VOLUME
, \
4919 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4920 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4921 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4922 SR_OBJECT_ENT_FONT_VARIANT
,
4923 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4924 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4925 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4926 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4927 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4928 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4929 SR_OBJECT_ENT_REGION
,\
4930 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4931 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4932 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4933 SR_OBJECT_ENT_GLIDER
, \
4935 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4936 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4942 bpy
.utils
.register_class(c
)
4944 bpy
.types
.Scene
.SR_data
= \
4945 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4946 bpy
.types
.Collection
.SR_data
= \
4947 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4949 bpy
.types
.Object
.SR_data
= \
4950 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4951 bpy
.types
.Light
.SR_data
= \
4952 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4953 bpy
.types
.Bone
.SR_data
= \
4954 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4955 bpy
.types
.Mesh
.SR_data
= \
4956 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4957 bpy
.types
.Material
.SR_data
= \
4958 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4960 global cv_view_draw_handler
, cv_view_pixel_handler
4961 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4962 cv_draw
,(),'WINDOW','POST_VIEW')
4963 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4964 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4970 bpy
.utils
.unregister_class(c
)
4972 global cv_view_draw_handler
, cv_view_pixel_handler
4973 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4974 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')
4977 # ---------------------------------------------------------------------------- #
4981 # ---------------------------------------------------------------------------- #
4983 # Transliteration of: #
4984 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
4986 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
4987 # SPDX-License-Identifier: MIT #
4988 # QOI - The "Quite OK Image" format for fast, lossless image compression #
4990 # ---------------------------------------------------------------------------- #
4992 class qoi_rgba_t(Structure
):
4995 _fields_
= [("r",c_uint8
),
5001 QOI_OP_INDEX
= 0x00 # 00xxxxxx
5002 QOI_OP_DIFF
= 0x40 # 01xxxxxx
5003 QOI_OP_LUMA
= 0x80 # 10xxxxxx
5004 QOI_OP_RUN
= 0xc0 # 11xxxxxx
5005 QOI_OP_RGB
= 0xfe # 11111110
5006 QOI_OP_RGBA
= 0xff # 11111111
5008 QOI_MASK_2
= 0xc0 # 11000000
5010 def qoi_colour_hash( c
):
5012 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
5017 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
5022 return bytearray([ (0xff000000 & v
) >> 24, \
5023 (0x00ff0000 & v
) >> 16, \
5024 (0x0000ff00 & v
) >> 8, \
5028 def qoi_encode( img
):
5032 print(F
"{' ':<30}",end
='\r')
5033 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
5035 index
= [ qoi_rgba_t() for _
in range(64) ]
5039 data
.extend( bytearray(c_uint32(0x66696f71)) )
5040 data
.extend( qoi_32bit( img
.size
[0] ) )
5041 data
.extend( qoi_32bit( img
.size
[1] ) )
5042 data
.extend( bytearray(c_uint8(4)) )
5043 data
.extend( bytearray(c_uint8(0)) )
5046 px_prev
= qoi_rgba_t()
5047 px_prev
.r
= c_uint8(0)
5048 px_prev
.g
= c_uint8(0)
5049 px_prev
.b
= c_uint8(0)
5050 px_prev
.a
= c_uint8(255)
5058 px_len
= img
.size
[0] * img
.size
[1]
5059 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
5061 for px_pos
in range( px_len
): #{
5062 idx
= px_pos
* img
.channels
5065 px
.r
= paxels
[idx
+min(0,nc
)]
5066 px
.g
= paxels
[idx
+min(1,nc
)]
5067 px
.b
= paxels
[idx
+min(2,nc
)]
5068 px
.a
= paxels
[idx
+min(3,nc
)]
5070 if qoi_eq( px
, px_prev
): #{
5073 if (run
== 62) or (px_pos
== px_len
-1): #{
5074 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
5080 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
5084 index_pos
= qoi_colour_hash(px
) % 64
5086 if qoi_eq( index
[index_pos
], px
): #{
5087 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
5090 index
[ index_pos
].r
= px
.r
5091 index
[ index_pos
].g
= px
.g
5092 index
[ index_pos
].b
= px
.b
5093 index
[ index_pos
].a
= px
.a
5095 if px
.a
== px_prev
.a
: #{
5096 vr
= int(px
.r
) - int(px_prev
.r
)
5097 vg
= int(px
.g
) - int(px_prev
.g
)
5098 vb
= int(px
.b
) - int(px_prev
.b
)
5103 if (vr
> -3) and (vr
< 2) and\
5104 (vg
> -3) and (vg
< 2) and\
5105 (vb
> -3) and (vb
< 2):
5107 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
5108 data
.extend( bytearray( c_uint8(op
) ))
5110 elif (vg_r
> -9) and (vg_r
< 8) and\
5111 (vg
> -33) and (vg
< 32 ) and\
5112 (vg_b
> -9) and (vg_b
< 8):
5114 op
= QOI_OP_LUMA |
(vg
+32)
5115 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
5116 data
.extend( bytearray( c_uint8(op
) ) )
5117 data
.extend( bytearray( c_uint8(delta
) ))
5120 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
5121 data
.extend( bytearray( c_uint8(px
.r
) ))
5122 data
.extend( bytearray( c_uint8(px
.g
) ))
5123 data
.extend( bytearray( c_uint8(px
.b
) ))
5127 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
5128 data
.extend( bytearray( c_uint8(px
.r
) ))
5129 data
.extend( bytearray( c_uint8(px
.g
) ))
5130 data
.extend( bytearray( c_uint8(px
.b
) ))
5131 data
.extend( bytearray( c_uint8(px
.a
) ))
5144 data
.extend( bytearray( c_uint8(0) ))
5145 data
.extend( bytearray( c_uint8(1) ))
5146 bytearray_align_to( data
, 16, b
'\x00' )