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 )
48 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
49 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
52 def get_entity_enum_id( alias
):
54 for et
in sr_entity_list
:#{
60 if alias
== 'ent_cubemap': return 21
65 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
66 #{ # the normals and uvs to i16s. Not an
67 _pack_
= 1 # real issue, yet.
68 _fields_
= [("co",c_float
*3),
72 ("weights",c_uint16
*4),
76 class mdl_transform(Structure
):
78 _fields_
= [("co",c_float
*3),
83 class mdl_submesh(Structure
):
85 _fields_
= [("indice_start",c_uint32
),
86 ("indice_count",c_uint32
),
87 ("vertex_start",c_uint32
),
88 ("vertex_count",c_uint32
),
89 ("bbx",(c_float
*3)*2),
90 ("material_id",c_uint16
), # index into the material array
94 class mdl_material(Structure
):
96 _fields_
= [("pstr_name",c_uint32
),
99 ("surface_prop",c_uint32
),
100 ("colour",c_float
*4),
101 ("colour1",c_float
*4),
102 ("tex_diffuse",c_uint32
),
103 ("tex_none0",c_uint32
),
104 ("tex_none1",c_uint32
)]
107 class mdl_bone(Structure
):
109 _fields_
= [("co",c_float
*3),("end",c_float
*3),
111 ("collider",c_uint32
),
112 ("ik_target",c_uint32
),
113 ("ik_pole",c_uint32
),
115 ("pstr_name",c_uint32
),
116 ("hitbox",(c_float
*3)*2),
117 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
121 class mdl_armature(Structure
):
123 _fields_
= [("transform",mdl_transform
),
124 ("bone_start",c_uint32
),
125 ("bone_count",c_uint32
),
126 ("anim_start",c_uint32
),
127 ("anim_count",c_uint32
)]
130 class mdl_animation(Structure
):
132 _fields_
= [("pstr_name",c_uint32
),
135 ("keyframe_start",c_uint32
)]
138 class mdl_mesh(Structure
):
140 _fields_
= [("transform",mdl_transform
),
141 ("submesh_start",c_uint32
),
142 ("submesh_count",c_uint32
),
143 ("pstr_name",c_uint32
),
144 ("entity_id",c_uint32
),
145 ("armature_id",c_uint32
)]
148 class mdl_file(Structure
):
150 _fields_
= [("path",c_uint32
),
151 ("pack_offset",c_uint32
),
152 ("pack_size",c_uint32
)]
155 class mdl_texture(Structure
):
157 _fields_
= [("file",mdl_file
),
161 class mdl_array(Structure
):
163 _fields_
= [("file_offset",c_uint32
),
164 ("item_count",c_uint32
),
165 ("item_size",c_uint32
),
169 class mdl_header(Structure
):
171 _fields_
= [("version",c_uint32
),
172 ("arrays",mdl_array
)]
175 class ent_spawn(Structure
):
177 _fields_
= [("transform",mdl_transform
),
178 ("pstr_name",c_uint32
)]
181 class ent_light(Structure
):
183 _fields_
= [("transform",mdl_transform
),
184 ("daytime",c_uint32
),
186 ("colour",c_float
*4),
189 ("inverse_world",(c_float
*3)*4), # Runtime
190 ("angle_sin_cos",(c_float
*2))] # Runtime
193 class version_refcount_union(Union
):
195 _fields_
= [("timing_version",c_uint32
),
196 ("ref_count",c_uint8
)]
199 class ent_gate(Structure
):
201 _fields_
= [("flags",c_uint32
),
202 ("target", c_uint32
),
204 ("dimensions", c_float
*3),
205 ("co", (c_float
*3)*2),
206 ("q", (c_float
*4)*2),
207 ("to_world",(c_float
*3)*4),
208 ("transport",(c_float
*3)*4),
209 ("_anonymous_union",version_refcount_union
),
210 ("timing_time",c_double
),
211 ("routes",c_uint16
*4),
212 ("route_count",c_uint8
),
213 ("submesh_start",c_uint32
), # v102+
214 ("submesh_count",c_uint32
), # v102+ (can be 0)
216 sr_functions
= { 0: 'unlock' }
219 class ent_route_node(Structure
):
221 _fields_
= [("co",c_float
*3),
222 ("ref_count",c_uint8
),
223 ("ref_total",c_uint8
)]
226 class ent_path_index(Structure
):
228 _fields_
= [("index",c_uint16
)]
231 class vg_audio_clip(Structure
):
233 _fields_
= [("path",c_uint64
),
239 class union_file_audio_clip(Union
):
241 _fields_
= [("file",mdl_file
),
242 ("reserved",vg_audio_clip
)]
245 class ent_audio_clip(Structure
):
247 _fields_
= [("_anon",union_file_audio_clip
),
248 ("probability",c_float
)]
251 class ent_checkpoint(Structure
):
253 _fields_
= [("gate_index",c_uint16
),
254 ("path_start",c_uint16
),
255 ("path_count",c_uint16
)]
258 class ent_route(Structure
):
260 _fields_
= [("transform",mdl_transform
),
261 ("pstr_name",c_uint32
),
262 ("checkpoints_start",c_uint16
),
263 ("checkpoints_count",c_uint16
),
264 ("colour",c_float
*4),
265 ("active",c_uint32
), #runtime
267 ("board_transform",(c_float
*3)*4),
269 ("latest_pass",c_double
),
270 ("id_camera",c_uint32
), # v103+
273 sr_functions
= { 0: 'view' }
276 class ent_water(Structure
):
278 _fields_
= [("transform",mdl_transform
),
279 ("max_dist",c_float
),
280 ("reserved0",c_uint32
),
281 ("reserved1",c_uint32
)]
284 class volume_trigger(Structure
):
286 _fields_
= [("event",c_uint32
),
287 ("event_leave",c_uint32
)]
290 class volume_particles(Structure
):
292 _fields_
= [("blank",c_uint32
),
296 class volume_union(Union
):
298 _fields_
= [("trigger",volume_trigger
),
299 ("particles",volume_particles
)]
302 class ent_volume(Structure
):
304 _fields_
= [("transform",mdl_transform
),
305 ("to_world",(c_float
*3)*4),
306 ("to_local",(c_float
*3)*4),
309 ("_anon",volume_union
)]
312 class ent_audio(Structure
):
314 _fields_
= [("transform",mdl_transform
),
316 ("clip_start",c_uint32
),
317 ("clip_count",c_uint32
),
319 ("crossfade",c_float
),
320 ("channel_behaviour",c_uint32
),
322 ("probability_curve",c_uint32
),
323 ("max_channels",c_uint32
)]
326 class ent_marker(Structure
):
328 _fields_
= [("transform",mdl_transform
),
332 class ent_glyph(Structure
):
334 _fields_
= [("size",c_float
*2),
335 ("indice_start",c_uint32
),
336 ("indice_count",c_uint32
)]
339 class ent_font_variant(Structure
):
341 _fields_
= [("name",c_uint32
),
342 ("material_id",c_uint32
)]
345 class ent_font(Structure
):
347 _fields_
= [("alias",c_uint32
),
348 ("variant_start",c_uint32
),
349 ("variant_count",c_uint32
),
350 ("glyph_start",c_uint32
),
351 ("glyph_count",c_uint32
),
352 ("glyph_utf32_base",c_uint32
)]
355 class ent_traffic(Structure
):
357 _fields_
= [("transform",mdl_transform
),
358 ("submesh_start",c_uint32
),
359 ("submesh_count",c_uint32
),
360 ("start_node",c_uint32
),
361 ("node_count",c_uint32
),
368 # ---------------------------------------------------------------
369 class ent_skateshop_characters(Structure
):
371 _fields_
= [("id_display",c_uint32
),
372 ("id_info",c_uint32
)]
374 class ent_skateshop_boards(Structure
):
376 _fields_
= [("id_display",c_uint32
),
377 ("id_info",c_uint32
),
378 ("id_rack",c_uint32
)]
380 class ent_skateshop_worlds(Structure
):
382 _fields_
= [("id_display",c_uint32
),
383 ("id_info",c_uint32
)]
385 class ent_skateshop_anon_union(Union
):
387 _fields_
= [("boards",ent_skateshop_boards
),
388 ("character",ent_skateshop_characters
),
389 ("worlds",ent_skateshop_worlds
)]
391 class ent_skateshop(Structure
):
393 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
394 ("id_camera",c_uint32
),
395 ("_anonymous_union",ent_skateshop_anon_union
)]
398 class ent_swspreview(Structure
):
400 _fields_
= [("id_camera",c_uint32
),
401 ("id_display",c_uint32
),
402 ("id_display1",c_uint32
)]
406 # -----------------------------------------------------------------
407 class ent_menuitem_visual(Structure
):
409 _fields_
= [("pstr_name",c_uint32
)]
411 class ent_menuitem_slider(Structure
):
413 _fields_
= [("id_min",c_uint32
),
415 ("id_handle",c_uint32
),
416 ("pstr_data",c_uint32
)]
418 class ent_menuitem_button(Structure
):
420 _fields_
= [("pstr",c_uint32
),
421 ("stack_behaviour",c_uint32
)]
423 class ent_menuitem_checkmark(Structure
):
425 _fields_
= [("id_check",c_uint32
),
426 ("pstr_data",c_uint32
),
427 ("offset",c_float
*3)]
429 class ent_menuitem_page(Structure
):
431 _fields_
= [("pstr_name",c_uint32
),
432 ("id_entrypoint",c_uint32
),
433 ("id_viewpoint",c_uint32
)]
435 class ent_menuitem_binding(Structure
):
437 _fields_
= [("pstr_bind",c_uint32
),
438 ("font_variant",c_uint32
)]
440 class ent_menuitem_anon_union(Union
):
442 _fields_
= [("slider",ent_menuitem_slider
),
443 ("button",ent_menuitem_button
),
444 ("checkmark",ent_menuitem_checkmark
),
445 ("page",ent_menuitem_page
),
446 ("visual",ent_menuitem_visual
),
447 ("binding",ent_menuitem_binding
)]
449 class ent_menuitem(Structure
):
451 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
452 ("id_links",c_uint32
*4),
453 ("factive",c_float
), ("fvisible",c_float
),
454 #-- TODO: Refactor this into a simple mesh structure
455 ("transform",mdl_transform
),
456 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
459 ("_anonymous_union", ent_menuitem_anon_union
)]
462 class ent_camera(Structure
):
464 _fields_
= [("transform",mdl_transform
),
468 class ent_worldinfo(Structure
):
470 _fields_
= [("pstr_name",c_uint32
),
471 ("pstr_author",c_uint32
), # unused
472 ("pstr_desc",c_uint32
), # unused
473 ("timezone",c_float
),
474 ("pstr_skybox",c_uint32
)]
477 class ent_ccmd(Structure
):
479 _fields_
= [("pstr_command",c_uint32
)]
482 class ent_objective(Structure
):#{
483 _fields_
= [("transform",mdl_transform
),
484 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
486 ("id_next",c_uint32
),
487 ("filter",c_uint32
),("filter2",c_uint32
),
489 ("win_event",c_uint32
),
490 ("time_limit",c_float
)]
492 sr_functions
= { 0: 'trigger',
497 class ent_challenge(Structure
):#{
498 _fields_
= [("transform",mdl_transform
),
499 ("pstr_alias",c_uint32
),
502 ("target_event",c_uint32
),
504 ("reset_event",c_uint32
),
507 ("status",c_uint32
)] #runtime
508 sr_functions
= { 0: 'unlock',
512 class ent_relay(Structure
):#{
513 _fields_
= [("targets",(c_uint32
*2)*4),
514 ("targets_events",c_uint32
*4)]
515 sr_functions
= { 0: 'trigger' }
518 class ent_cubemap(Structure
):#{
519 _fields_
= [("co",c_float
*3),
520 ("resolution",c_uint32
), #placeholder
521 ("live",c_uint32
), #placeholder
522 ("texture_id",c_uint32
), #engine
523 ("framebuffer_id",c_uint32
),#engine
524 ("renderbuffer_id",c_uint32
),#engine
525 ("placeholder",c_uint32
*2)]
528 class ent_miniworld(Structure
):#{
529 _fields_
= [("transform",mdl_transform
),
530 ("pstr_world",c_uint32
),
534 sr_functions
= { 0: 'zone', 1: 'leave' }
537 class ent_prop(Structure
):#{
538 _fields_
= [("transform",mdl_transform
),
539 ("submesh_start",c_uint32
),
540 ("submesh_count",c_uint32
),
544 def obj_ent_type( obj
):
546 if obj
.type == 'ARMATURE': return 'mdl_armature'
547 elif obj
.type == 'LIGHT': return 'ent_light'
548 elif obj
.type == 'CAMERA': return 'ent_camera'
549 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
551 else: return obj
.SR_data
.ent_type
554 def sr_filter_ent_type( obj
, ent_types
):
556 if obj
== bpy
.context
.active_object
: return False
558 for c0
in obj
.users_collection
:#{
559 for c1
in bpy
.context
.active_object
.users_collection
:#{
561 return obj_ent_type( obj
) in ent_types
569 def v4_dot( a
, b
):#{
570 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
573 def q_identity( q
):#{
580 def q_normalize( q
):#{
582 if( l2
< 0.00001 ):#{
586 s
= 1.0/math
.sqrt(l2
)
594 def compile_obj_transform( obj
, transform
):
596 co
= obj
.matrix_world
@ Vector((0,0,0))
598 # This was changed from matrix_local on 09.05.23
599 q
= obj
.matrix_world
.to_quaternion()
605 transform
.co
[0] = co
[0]
606 transform
.co
[1] = co
[2]
607 transform
.co
[2] = -co
[1]
608 transform
.q
[0] = q
[1]
609 transform
.q
[1] = q
[3]
610 transform
.q
[2] = -q
[2]
611 transform
.q
[3] = q
[0]
612 transform
.s
[0] = s
[0]
613 transform
.s
[1] = s
[2]
614 transform
.s
[2] = s
[1]
617 def int_align_to( v
, align
):
619 while(v
%align
)!=0: v
+= 1
623 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
625 while (len(buffer) % align
) != 0: buffer.extend(w
)
629 def bytearray_print_hex( s
, w
=16 ):
631 for r
in range((len(s
)+(w
-1))//w
):#{
633 i1
=min((r
+1)*w
,len(s
))
634 print( F
'{r*w:06x}| \x1B[31m', end
='')
635 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
636 print( "\x1B[0m", end
='')
637 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
641 def sr_compile_string( s
):
643 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
645 index
= len( sr_compile
.string_data
)
646 sr_compile
.string_cache
[s
] = index
647 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
648 sr_compile
.string_data
.extend( s
.encode('utf-8') )
649 sr_compile
.string_data
.extend( b
'\0' )
651 bytearray_align_to( sr_compile
.string_data
, 4 )
655 def material_tex_image(v
):
665 cxr_graph_mapping
= \
667 # Default shader setup
674 "image": "tex_diffuse"
678 "A": material_tex_image("tex_diffuse"),
679 "B": material_tex_image("tex_decal")
686 "Color": material_tex_image("tex_normal")
692 "Color": material_tex_image("tex_diffuse")
696 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
698 def material_info(mat
):
702 # Using the cxr_graph_mapping as a reference, go through the shader
703 # graph and gather all $props from it.
705 def _graph_read( node_def
, node
=None, depth
=0 ):#{
712 _graph_read
.extracted
= []
714 for node_idname
in node_def
:#{
715 for n
in mat
.node_tree
.nodes
:#{
716 if n
.name
== node_idname
:#{
717 node_def
= node_def
[node_idname
]
725 for link
in node_def
:#{
726 link_def
= node_def
[link
]
728 if isinstance( link_def
, dict ):#{
730 for x
in node
.inputs
:#{
731 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
739 if node_link
and node_link
.is_linked
:#{
740 # look for definitions for the connected node type
742 from_node
= node_link
.links
[0].from_node
744 node_name
= from_node
.name
.split('.')[0]
745 if node_name
in link_def
:#{
746 from_node_def
= link_def
[ node_name
]
748 _graph_read( from_node_def
, from_node
, depth
+1 )
752 if "default" in link_def
:#{
753 prop
= link_def
['default']
754 info
[prop
] = node_link
.default_value
760 info
[prop
] = getattr( node
, link
)
765 _graph_read( cxr_graph_mapping
)
771 decoded
= bytearray()
772 for i
in range(len(s
)//2):#{
773 c
= (ord(s
[i
*2+0])-0x41)
774 c |
= (ord(s
[i
*2+1])-0x41)<<4
775 decoded
.extend(bytearray(c_uint8(c
))) #??
780 def sr_pack_file( file, path
, data
):
782 file.path
= sr_compile_string( path
)
783 file.pack_offset
= len( sr_compile
.pack_data
)
784 file.pack_size
= len( data
)
786 sr_compile
.pack_data
.extend( data
)
787 bytearray_align_to( sr_compile
.pack_data
, 16 )
790 def sr_compile_texture( img
):
795 name
= os
.path
.splitext( img
.name
)[0]
797 if name
in sr_compile
.texture_cache
:
798 return sr_compile
.texture_cache
[name
]
800 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
805 if sr_compile
.pack_textures
:#{
806 filedata
= qoi_encode( img
)
807 sr_pack_file( tex
.file, name
, filedata
)
810 sr_compile
.texture_cache
[name
] = texture_index
811 sr_compile
.texture_data
.extend( bytearray(tex
) )
815 def sr_compile_material( mat
):#{
818 if mat
.name
in sr_compile
.material_cache
:
819 return sr_compile
.material_cache
[mat
.name
]
821 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
822 sr_compile
.material_cache
[mat
.name
] = index
825 m
.pstr_name
= sr_compile_string( mat
.name
)
828 if mat
.SR_data
.collision
:#{
829 flags |
= 0x2 # collision flag
830 if (mat
.SR_data
.shader
!= 'invisible') and \
831 (mat
.SR_data
.shader
!= 'boundary'):#{
832 if mat
.SR_data
.skate_surface
: flags |
= 0x1
833 if mat
.SR_data
.grow_grass
: flags |
= 0x4
834 if mat
.SR_data
.grind_surface
: flags |
= 0x8
835 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
837 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
838 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
839 if mat
.SR_data
.shader
== 'walking': flags |
= (0x10|
0x80)
844 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
845 inf
= material_info( mat
)
847 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
848 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
849 if mat
.SR_data
.shader
== 'terrain_blend':#{
852 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
853 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
854 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
857 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
858 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
861 if mat
.SR_data
.shader
== 'vertex_blend':#{
864 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
865 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
868 if mat
.SR_data
.shader
== 'water':#{
871 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
872 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
873 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
875 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
876 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
877 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
881 if mat
.SR_data
.shader
== 'invisible':#{
885 if mat
.SR_data
.shader
== 'boundary':#{
889 if mat
.SR_data
.shader
== 'fxglow':#{
893 if mat
.SR_data
.shader
== 'cubemap':#{
895 m
.tex_none0
= sr_entity_id( mat
.SR_data
.cubemap
)
897 m
.colour
[0] = pow( mat
.SR_data
.tint
[0], 1.0/2.2 )
898 m
.colour
[1] = pow( mat
.SR_data
.tint
[1], 1.0/2.2 )
899 m
.colour
[2] = pow( mat
.SR_data
.tint
[2], 1.0/2.2 )
900 m
.colour
[3] = pow( mat
.SR_data
.tint
[3], 1.0/2.2 )
903 if mat
.SR_data
.shader
== 'walking':#{
907 if mat
.SR_data
.shader
in ['standard', 'standard_cutout', 'terrain_blend', \
908 'vertex_blend', 'fxglow', 'cubemap' ]: #{
909 if 'tex_diffuse' in inf
:
910 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
913 sr_compile
.material_data
.extend( bytearray(m
) )
917 def sr_armature_bones( armature
):
919 def _recurse_bone( b
):
922 for c
in b
.children
: yield from _recurse_bone( c
)
925 for b
in armature
.data
.bones
:
927 yield from _recurse_bone( b
)
930 def sr_entity_id( obj
):#{
933 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
934 index
= sr_compile
.entity_ids
[ obj
.name
]
936 return (tipo
&0xffff)<<16 |
(index
&0xffff)
939 # Returns submesh_start,count and armature_id
940 def sr_compile_mesh_internal( obj
):
949 for mod
in obj
.modifiers
:#{
950 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
951 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
954 can_use_cache
= False
957 if mod
.type == 'ARMATURE': #{
958 armature
= mod
.object
959 rig_weight_groups
= \
960 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
961 armature_id
= sr_compile
.entity_ids
[armature
.name
]
963 POSE_OR_REST_CACHE
= armature
.data
.pose_position
964 armature
.data
.pose_position
= 'REST'
968 # Check the cache first
970 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
971 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
972 submesh_start
= ref
[0]
973 submesh_count
= ref
[1]
974 return (submesh_start
,submesh_count
,armature_id
)
977 # Compile a whole new mesh
979 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
982 dgraph
= bpy
.context
.evaluated_depsgraph_get()
983 data
= obj
.evaluated_get(dgraph
).data
984 data
.calc_loop_triangles()
985 data
.calc_normals_split()
987 # Mesh is split into submeshes based on their material
989 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
990 for material_id
, mat
in enumerate(mat_list
): #{
994 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
995 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
998 sm
.material_id
= sr_compile_material( mat
)
1000 INF
=99999999.99999999
1001 for i
in range(3):#{
1006 # Keep a reference to very very very similar vertices
1007 # i have no idea how to speed it up.
1009 vertex_reference
= {}
1011 # Write the vertex / indice data
1013 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
1014 if tri
.material_index
!= material_id
: continue
1016 for j
in range(3):#{
1017 vert
= data
.vertices
[tri
.vertices
[j
]]
1019 vi
= data
.loops
[li
].vertex_index
1021 # Gather vertex information
1024 norm
= data
.loops
[li
].normal
1026 colour
= (255,255,255,255)
1033 uv
= data
.uv_layers
.active
.data
[li
].uv
1037 if data
.vertex_colors
:#{
1038 colour
= data
.vertex_colors
.active
.data
[li
].color
1039 colour
= (int(colour
[0]*255.0),\
1040 int(colour
[1]*255.0),\
1041 int(colour
[2]*255.0),\
1042 int(colour
[3]*255.0))
1045 # Weight groups: truncates to the 3 with the most influence. The
1046 # fourth bone ID is never used by the shader so it
1050 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
1051 if obj
.vertex_groups
[_
.group
].name
in \
1054 weight_groups
= sorted( src_groups
, key
= \
1055 lambda a
: a
.weight
, reverse
=True )
1057 for ml
in range(3):#{
1058 if len(weight_groups
) > ml
:#{
1059 g
= weight_groups
[ml
]
1060 name
= obj
.vertex_groups
[g
.group
].name
1062 weights
[ml
] = weight
1063 groups
[ml
] = rig_weight_groups
.index(name
)
1068 if len(weight_groups
) > 0:#{
1069 inv_norm
= (1.0/tot
) * 65535.0
1070 for ml
in range(3):#{
1071 weights
[ml
] = int( weights
[ml
] * inv_norm
)
1072 weights
[ml
] = min( weights
[ml
], 65535 )
1073 weights
[ml
] = max( weights
[ml
], 0 )
1078 li1
= tri
.loops
[(j
+1)%3]
1079 vi1
= data
.loops
[li1
].vertex_index
1080 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
1082 if e0
.use_freestyle_mark
and \
1083 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
1084 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
1090 TOLERENCE
= float(10**4)
1091 key
= (int(co
[0]*TOLERENCE
+0.5),
1092 int(co
[1]*TOLERENCE
+0.5),
1093 int(co
[2]*TOLERENCE
+0.5),
1094 int(norm
[0]*TOLERENCE
+0.5),
1095 int(norm
[1]*TOLERENCE
+0.5),
1096 int(norm
[2]*TOLERENCE
+0.5),
1097 int(uv
[0]*TOLERENCE
+0.5),
1098 int(uv
[1]*TOLERENCE
+0.5),
1099 colour
[0], # these guys are already quantized
1112 if key
in vertex_reference
:
1113 index
= vertex_reference
[key
]
1115 index
= bytearray(c_uint32(sm
.vertex_count
))
1118 vertex_reference
[key
] = index
1125 v
.norm
[2] = -norm
[1]
1128 v
.colour
[0] = colour
[0]
1129 v
.colour
[1] = colour
[1]
1130 v
.colour
[2] = colour
[2]
1131 v
.colour
[3] = colour
[3]
1132 v
.weights
[0] = weights
[0]
1133 v
.weights
[1] = weights
[1]
1134 v
.weights
[2] = weights
[2]
1135 v
.weights
[3] = weights
[3]
1136 v
.groups
[0] = groups
[0]
1137 v
.groups
[1] = groups
[1]
1138 v
.groups
[2] = groups
[2]
1139 v
.groups
[3] = groups
[3]
1141 for i
in range(3):#{
1142 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1143 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1146 sr_compile
.vertex_data
.extend(bytearray(v
))
1149 sm
.indice_count
+= 1
1150 sr_compile
.indice_data
.extend( index
)
1154 # Make sure bounding box isn't -inf -> inf if no vertices
1156 if sm
.vertex_count
== 0:
1161 # Add submesh to encoder
1163 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1168 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1171 # Save a reference to this mesh since we want to reuse the submesh indices
1173 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1174 return (submesh_start
,submesh_count
,armature_id
)
1177 def sr_compile_mesh( obj
):
1180 compile_obj_transform(obj
, node
.transform
)
1181 node
.pstr_name
= sr_compile_string(obj
.name
)
1182 ent_type
= obj_ent_type( obj
)
1186 if ent_type
!= 'none':#{
1187 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1188 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1189 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1192 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1193 sr_compile_mesh_internal( obj
)
1195 sr_compile
.mesh_data
.extend(bytearray(node
))
1198 def sr_compile_fonts( collection
):
1200 print( F
"[SR] Compiling fonts" )
1205 for obj
in collection
.all_objects
:#{
1206 if obj_ent_type(obj
) != 'ent_font': continue
1208 data
= obj
.SR_data
.ent_font
[0]
1211 font
.alias
= sr_compile_string( data
.alias
)
1212 font
.variant_start
= variant_count
1213 font
.variant_count
= 0
1214 font
.glyph_start
= glyph_count
1216 glyph_base
= data
.glyphs
[0].utf32
1217 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1219 font
.glyph_utf32_base
= glyph_base
1220 font
.glyph_count
= glyph_range
1222 for i
in range(len(data
.variants
)):#{
1223 data_var
= data
.variants
[i
]
1224 if not data_var
.mesh
: continue
1226 mesh
= data_var
.mesh
.data
1228 variant
= ent_font_variant()
1229 variant
.name
= sr_compile_string( data_var
.tipo
)
1231 # fonts (variants) only support one material each
1233 if len(mesh
.materials
) != 0:
1234 mat
= mesh
.materials
[0]
1235 variant
.material_id
= sr_compile_material( mat
)
1237 font
.variant_count
+= 1
1239 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1240 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1242 for j
in range(len(islands
)):#{
1243 for tri
in islands
[j
]:#{
1244 centroids
[j
].x
+= tri
.center
[0]
1245 centroids
[j
].y
+= tri
.center
[2]
1248 centroids
[j
] /= len(islands
[j
])
1251 for j
in range(glyph_range
):#{
1252 data_glyph
= data
.glyphs
[j
]
1254 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1255 glyph
.indice_count
= 0
1256 glyph
.size
[0] = data_glyph
.bounds
[2]
1257 glyph
.size
[1] = data_glyph
.bounds
[3]
1259 vertex_reference
= {}
1261 for k
in range(len(islands
)):#{
1262 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1263 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1264 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1265 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1270 for l
in range(len(islands
[k
])):#{
1272 for m
in range(3):#{
1273 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1275 vi
= mesh
.loops
[li
].vertex_index
1277 # Gather vertex information
1279 co
= [vert
.co
[_
] for _
in range(3)]
1280 co
[0] -= data_glyph
.bounds
[0]
1281 co
[2] -= data_glyph
.bounds
[1]
1282 norm
= mesh
.loops
[li
].normal
1284 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1286 TOLERENCE
= float(10**4)
1287 key
= (int(co
[0]*TOLERENCE
+0.5),
1288 int(co
[1]*TOLERENCE
+0.5),
1289 int(co
[2]*TOLERENCE
+0.5),
1290 int(norm
[0]*TOLERENCE
+0.5),
1291 int(norm
[1]*TOLERENCE
+0.5),
1292 int(norm
[2]*TOLERENCE
+0.5),
1293 int(uv
[0]*TOLERENCE
+0.5),
1294 int(uv
[1]*TOLERENCE
+0.5))
1296 if key
in vertex_reference
:
1297 index
= vertex_reference
[key
]
1299 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1300 index
= bytearray(c_uint32(vindex
))
1301 vertex_reference
[key
] = index
1308 v
.norm
[2] = -norm
[1]
1312 sr_compile
.vertex_data
.extend(bytearray(v
))
1315 glyph
.indice_count
+= 1
1316 sr_compile
.indice_data
.extend( index
)
1320 sr_ent_push( glyph
)
1322 sr_ent_push( variant
)
1328 def sr_compile_menus( collection
):
1330 print( "[SR1] Compiling menus" )
1333 for obj
in collection
.all_objects
:#{
1334 if obj_ent_type(obj
) != 'ent_menuitem': continue
1335 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1337 bitmask
= 0x00000000
1339 for col
in obj
.users_collection
:#{
1341 if name
not in groups
: groups
.append( name
)
1342 bitmask |
= (0x1 << groups
.index(name
))
1345 item
= ent_menuitem()
1346 item
.type = int( obj_data
.tipo
)
1347 item
.groups
= bitmask
1349 compile_obj_transform( obj
, item
.transform
)
1350 if obj
.type == 'MESH':#{
1351 item
.submesh_start
, item
.submesh_count
, _
= \
1352 sr_compile_mesh_internal( obj
)
1355 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1356 item_button
= item
._anonymous
_union
.button
1357 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1358 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1360 elif item
.type == 0:#{
1361 item_visual
= item
._anonymous
_union
.visual
1362 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1364 elif item
.type == 3:#{
1365 item_checkmark
= item
._anonymous
_union
.checkmark
1366 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1367 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1368 delta
= obj_data
.checkmark
.location
- obj
.location
1369 item_checkmark
.offset
[0] = delta
[0]
1370 item_checkmark
.offset
[1] = delta
[2]
1371 item_checkmark
.offset
[2] = -delta
[1]
1373 elif item
.type == 4:#{
1374 item_slider
= item
._anonymous
_union
.slider
1375 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1376 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1377 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1378 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1380 elif item
.type == 5:#{
1381 item_page
= item
._anonymous
_union
.page
1382 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1383 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1384 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1386 elif item
.type == 6:#{
1387 item_binding
= item
._anonymous
_union
.binding
1388 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1389 item_binding
.font_variant
= obj_data
.font_variant
1393 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1395 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1396 if item
.type != 4:#{
1398 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1400 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1407 def sr_compile_armature( obj
):
1409 node
= mdl_armature()
1410 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1412 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1415 bones
= [_
for _
in sr_armature_bones(obj
)]
1416 bones_names
= [None]+[_
.name
for _
in bones
]
1420 if b
.use_deform
: bone
.flags
= 0x1
1421 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1423 bone
.collider
= int(b
.SR_data
.collider
)
1425 if bone
.collider
>0:#{
1426 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1427 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1428 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1429 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1430 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1431 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1434 if b
.SR_data
.cone_constraint
:#{
1436 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1437 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1438 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1439 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1440 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1441 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1442 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1443 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1444 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1445 bone
.conet
= b
.SR_data
.conet
1448 bone
.co
[0] = b
.head_local
[0]
1449 bone
.co
[1] = b
.head_local
[2]
1450 bone
.co
[2] = -b
.head_local
[1]
1451 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1452 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1453 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1454 bone
.pstr_name
= sr_compile_string( b
.name
)
1456 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1457 if c
.type == 'IK':#{
1459 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1460 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1464 node
.bone_count
+= 1
1465 sr_compile
.bone_data
.extend(bytearray(bone
))
1470 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1471 # So we can restore later
1473 previous_frame
= bpy
.context
.scene
.frame_current
1474 previous_action
= obj
.animation_data
.action
1475 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1476 obj
.data
.pose_position
= 'POSE'
1478 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1479 for NLAStrip
in NLALayer
.strips
:#{
1482 for a
in bpy
.data
.actions
:#{
1483 if a
.name
== NLAStrip
.name
:#{
1484 obj
.animation_data
.action
= a
1489 # Clip to NLA settings
1491 anim_start
= int(NLAStrip
.action_frame_start
)
1492 anim_end
= int(NLAStrip
.action_frame_end
)
1496 anim
= mdl_animation()
1497 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1499 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1500 sizeof(mdl_transform
)
1501 anim
.length
= anim_end
-anim_start
1504 # Export the keyframes
1505 for frame
in range(anim_start
,anim_end
):#{
1506 bpy
.context
.scene
.frame_set(frame
)
1509 pb
= obj
.pose
.bones
[rb
.name
]
1511 # relative bone matrix
1512 if rb
.parent
is not None:#{
1513 offset_mtx
= rb
.parent
.matrix_local
1514 offset_mtx
= offset_mtx
.inverted_safe() @ \
1517 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1518 inv_parent
.invert_safe()
1519 fpm
= inv_parent
@ pb
.matrix
1522 bone_mtx
= rb
.matrix
.to_4x4()
1523 local_inv
= rb
.matrix_local
.inverted_safe()
1524 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1527 loc
, rot
, sca
= fpm
.decompose()
1530 lc_m
= pb
.matrix_channel
.to_3x3()
1531 if pb
.parent
is not None:#{
1532 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1533 lc_m
= smtx
.inverted() @ lc_m
1535 rq
= lc_m
.to_quaternion()
1538 kf
= mdl_transform()
1549 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1555 # Add to animation buffer
1557 sr_compile
.anim_data
.extend(bytearray(anim
))
1558 node
.anim_count
+= 1
1562 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1566 # Restore context to how it was before
1568 bpy
.context
.scene
.frame_set( previous_frame
)
1569 obj
.animation_data
.action
= previous_action
1570 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1573 sr_compile
.armature_data
.extend(bytearray(node
))
1576 def sr_ent_push( struct
):
1578 clase
= type(struct
).__name
__
1580 if clase
not in sr_compile
.entity_data
:#{
1581 sr_compile
.entity_data
[ clase
] = bytearray()
1582 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1585 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1586 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1590 def sr_array_title( arr
, name
, count
, size
, offset
):
1592 for i
in range(len(name
)):#{
1593 arr
.name
[i
] = ord(name
[i
])
1595 arr
.file_offset
= offset
1596 arr
.item_count
= count
1597 arr
.item_size
= size
1604 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1609 def sr_compile( collection
):
1611 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1614 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1615 sr_compile
.pack_animations
= collection
.SR_data
.animations
1618 sr_compile
.string_cache
= {}
1619 sr_compile
.mesh_cache
= {}
1620 sr_compile
.material_cache
= {}
1621 sr_compile
.texture_cache
= {}
1624 sr_compile
.mesh_data
= bytearray()
1625 sr_compile
.submesh_data
= bytearray()
1626 sr_compile
.vertex_data
= bytearray()
1627 sr_compile
.indice_data
= bytearray()
1628 sr_compile
.bone_data
= bytearray()
1629 sr_compile
.material_data
= bytearray()
1630 sr_compile
.armature_data
= bytearray()
1631 sr_compile
.anim_data
= bytearray()
1632 sr_compile
.keyframe_data
= bytearray()
1633 sr_compile
.texture_data
= bytearray()
1635 # just bytes not structures
1636 sr_compile
.string_data
= bytearray()
1637 sr_compile
.pack_data
= bytearray()
1640 sr_compile
.entity_data
= {}
1641 sr_compile
.entity_info
= {}
1643 print( F
"[SR] assign entity ID's" )
1644 sr_compile
.entities
= {}
1645 sr_compile
.entity_ids
= {}
1648 # -------------------------------------------------------
1650 sr_compile_string( "null" )
1653 for obj
in collection
.all_objects
: #{
1654 if obj
.type == 'MESH':#{
1658 ent_type
= obj_ent_type( obj
)
1659 if ent_type
== 'none': continue
1661 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1662 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1663 sr_compile
.entities
[ent_type
] += [obj
]
1666 print( F
"[SR] Compiling geometry" )
1668 for obj
in collection
.all_objects
:#{
1669 if obj
.type == 'MESH':#{
1672 ent_type
= obj_ent_type( obj
)
1674 # entity ignore mesh list
1676 if ent_type
== 'ent_traffic': continue
1677 if ent_type
== 'ent_prop': continue
1678 if ent_type
== 'ent_font': continue
1679 if ent_type
== 'ent_font_variant': continue
1680 if ent_type
== 'ent_menuitem': continue
1681 if ent_type
== 'ent_objective': continue
1683 #TODO: This is messy.
1684 if ent_type
== 'ent_gate':#{
1685 obj_data
= obj
.SR_data
.ent_gate
[0]
1686 if obj_data
.custom
: continue
1688 #--------------------------
1690 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end
='\r' )
1691 sr_compile_mesh( obj
)
1695 audio_clip_count
= 0
1697 for ent_type
, arr
in sr_compile
.entities
.items():#{
1698 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1700 for i
in range(len(arr
)):#{
1703 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1705 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1706 elif ent_type
== 'ent_light': #{
1708 compile_obj_transform( obj
, light
.transform
)
1709 light
.daytime
= obj
.data
.SR_data
.daytime
1710 if obj
.data
.type == 'POINT':#{
1713 elif obj
.data
.type == 'SPOT':#{
1715 light
.angle
= obj
.data
.spot_size
*0.5
1717 light
.range = obj
.data
.cutoff_distance
1718 light
.colour
[0] = obj
.data
.color
[0]
1719 light
.colour
[1] = obj
.data
.color
[1]
1720 light
.colour
[2] = obj
.data
.color
[2]
1721 light
.colour
[3] = obj
.data
.energy
1722 sr_ent_push( light
)
1724 elif ent_type
== 'ent_camera': #{
1726 compile_obj_transform( obj
, cam
.transform
)
1727 cam
.fov
= obj
.data
.angle
* 45.0
1730 elif ent_type
== 'ent_gate': #{
1732 obj_data
= obj
.SR_data
.ent_gate
[0]
1733 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1737 if obj_data
.tipo
== 'default':#{
1738 if obj_data
.target
:#{
1739 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1743 elif obj_data
.tipo
== 'nonlocal':#{
1745 gate
.key
= sr_compile_string(obj_data
.key
)
1749 if obj_data
.flip
: flags |
= 0x0004
1750 if obj_data
.custom
:#{
1752 gate
.submesh_start
, gate
.submesh_count
, _
= \
1753 sr_compile_mesh_internal( obj
)
1755 if obj_data
.locked
: flags |
= 0x0010
1758 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1759 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1760 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1762 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1763 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1765 if obj_data
.target
:#{
1766 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1767 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1772 for x
in range(2):#{
1773 gate
.co
[x
][0] = co
[x
][0]
1774 gate
.co
[x
][1] = co
[x
][2]
1775 gate
.co
[x
][2] = -co
[x
][1]
1776 gate
.q
[x
][0] = q
[x
][1]
1777 gate
.q
[x
][1] = q
[x
][3]
1778 gate
.q
[x
][2] = -q
[x
][2]
1779 gate
.q
[x
][3] = q
[x
][0]
1784 elif ent_type
== 'ent_spawn': #{
1786 compile_obj_transform( obj
, spawn
.transform
)
1787 obj_data
= obj
.SR_data
.ent_spawn
[0]
1788 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1789 sr_ent_push( spawn
)
1791 elif ent_type
== 'ent_water':#{
1793 compile_obj_transform( obj
, water
.transform
)
1794 water
.max_dist
= 0.0
1795 sr_ent_push( water
)
1797 elif ent_type
== 'ent_audio':#{
1798 obj_data
= obj
.SR_data
.ent_audio
[0]
1800 compile_obj_transform( obj
, audio
.transform
)
1801 audio
.clip_start
= audio_clip_count
1802 audio
.clip_count
= len(obj_data
.files
)
1803 audio_clip_count
+= audio
.clip_count
1804 audio
.max_channels
= obj_data
.max_channels
1805 audio
.volume
= obj_data
.volume
1808 # - allow/disable doppler
1809 # - channel group tags with random colours
1810 # - transition properties
1812 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1813 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1814 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1815 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1816 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1817 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1818 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1820 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1821 if audio
.channel_behaviour
>= 1:#{
1822 audio
.group
= obj_data
.group
1824 if audio
.channel_behaviour
== 2:#{
1825 audio
.crossfade
= obj_data
.transition_duration
1827 audio
.probability_curve
= int(obj_data
.probability_curve
)
1829 for ci
in range(audio
.clip_count
):#{
1830 entry
= obj_data
.files
[ci
]
1831 clip
= ent_audio_clip()
1832 clip
.probability
= entry
.probability
1833 if obj_data
.formato
== '2':#{
1834 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1837 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1838 clip
._anon
.file.pack_offset
= 0
1839 clip
._anon
.file.pack_size
= 0
1843 sr_ent_push( audio
)
1845 elif ent_type
== 'ent_volume':#{
1846 obj_data
= obj
.SR_data
.ent_volume
[0]
1847 volume
= ent_volume()
1848 volume
.type = int(obj_data
.subtype
)
1849 compile_obj_transform( obj
, volume
.transform
)
1851 if obj_data
.target
:#{
1852 volume
.target
= sr_entity_id( obj_data
.target
)
1853 volume
._anon
.trigger
.event
= obj_data
.target_event
1855 ev
= 0xffffffff if obj_data
.target_event_leave
< 0 else \
1856 obj_data
.target_event_leave
1857 volume
._anon
.trigger
.event_leave
= ev
1862 elif ent_type
== 'ent_marker':#{
1863 marker
= ent_marker()
1864 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1865 compile_obj_transform( obj
, marker
.transform
)
1868 elif ent_type
== 'ent_skateshop':#{
1869 skateshop
= ent_skateshop()
1870 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1871 skateshop
.type = int(obj_data
.tipo
)
1872 if skateshop
.type == 0:#{
1873 boardshop
= skateshop
._anonymous
_union
.boards
1874 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1875 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1876 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1878 elif skateshop
.type == 1:#{
1879 charshop
= skateshop
._anonymous
_union
.character
1880 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1881 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1883 elif skateshop
.type == 2:#{
1884 worldshop
= skateshop
._anonymous
_union
.worlds
1885 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1886 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1888 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1889 compile_obj_transform( obj
, skateshop
.transform
)
1890 sr_ent_push(skateshop
)
1892 elif ent_type
== 'ent_swspreview':#{
1893 workshop_preview
= ent_swspreview()
1894 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1895 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1896 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1897 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1898 sr_ent_push( workshop_preview
)
1900 elif ent_type
== 'ent_worldinfo':#{
1901 worldinfo
= ent_worldinfo()
1902 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1903 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1904 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1905 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1906 worldinfo
.timezone
= obj_data
.timezone
1907 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1908 sr_ent_push( worldinfo
)
1910 elif ent_type
== 'ent_ccmd':#{
1912 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1913 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1916 elif ent_type
== 'ent_objective':#{
1917 objective
= ent_objective()
1918 obj_data
= obj
.SR_data
.ent_objective
[0]
1919 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
1920 objective
.id_win
= sr_entity_id( obj_data
.target
)
1921 objective
.win_event
= obj_data
.target_event
1922 objective
.filter = int(obj_data
.filtrar
)
1923 objective
.filter2
= 0
1924 objective
.time_limit
= obj_data
.time_limit
1926 compile_obj_transform( obj
, objective
.transform
)
1927 objective
.submesh_start
, objective
.submesh_count
, _
= \
1928 sr_compile_mesh_internal( obj
)
1930 sr_ent_push( objective
)
1932 elif ent_type
== 'ent_challenge':#{
1933 challenge
= ent_challenge()
1934 obj_data
= obj
.SR_data
.ent_challenge
[0]
1935 compile_obj_transform( obj
, challenge
.transform
)
1936 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1937 challenge
.target
= sr_entity_id( obj_data
.target
)
1938 challenge
.target_event
= obj_data
.target_event
1939 challenge
.reset
= sr_entity_id( obj_data
.reset
)
1940 challenge
.reset_event
= obj_data
.reset_event
1941 challenge
.first
= sr_entity_id( obj_data
.first
)
1942 challenge
.flags
= 0x00
1943 challenge
.camera
= sr_entity_id( obj_data
.camera
)
1944 if obj_data
.time_limit
: challenge
.flags |
= 0x01
1945 challenge
.status
= 0
1946 sr_ent_push( challenge
)
1948 elif ent_type
== 'ent_relay':#{
1950 obj_data
= obj
.SR_data
.ent_relay
[0]
1951 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
1952 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
1953 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
1954 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
1955 relay
.targets
[0][1] = obj_data
.target0_event
1956 relay
.targets
[1][1] = obj_data
.target1_event
1957 relay
.targets
[2][1] = obj_data
.target2_event
1958 relay
.targets
[3][1] = obj_data
.target3_event
1959 sr_ent_push( relay
)
1961 elif ent_type
== 'ent_cubemap':#{
1962 cubemap
= ent_cubemap()
1963 co
= obj
.matrix_world
@ Vector((0,0,0))
1964 cubemap
.co
[0] = co
[0]
1965 cubemap
.co
[1] = co
[2]
1966 cubemap
.co
[2] = -co
[1]
1967 cubemap
.resolution
= 0
1969 sr_ent_push( cubemap
)
1971 elif ent_type
== 'ent_miniworld':#{
1972 miniworld
= ent_miniworld()
1973 obj_data
= obj
.SR_data
.ent_miniworld
[0]
1975 compile_obj_transform( obj
, miniworld
.transform
)
1976 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
1977 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
1978 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
1979 sr_ent_push( miniworld
)
1981 elif ent_type
== 'ent_prop':#{
1983 compile_obj_transform( obj
, prop
.transform
)
1984 prop
.submesh_start
, prop
.submesh_count
, _
= \
1985 sr_compile_mesh_internal( obj
)
1992 sr_compile_menus( collection
)
1993 sr_compile_fonts( collection
)
1995 def _children( col
):#{
1997 for c
in col
.children
:#{
1998 yield from _children(c
)
2002 checkpoint_count
= 0
2003 pathindice_count
= 0
2006 for col
in _children(collection
):#{
2007 print( F
"Adding routes for subcollection: {col.name}" )
2013 for obj
in col
.objects
:#{
2014 if obj
.type == 'ARMATURE': pass
2016 ent_type
= obj_ent_type( obj
)
2018 if ent_type
== 'ent_gate':
2019 route_gates
+= [obj
]
2020 elif ent_type
== 'ent_route_node':#{
2021 if obj
.type == 'CURVE':#{
2022 route_curves
+= [obj
]
2025 elif ent_type
== 'ent_route':
2027 elif ent_type
== 'ent_traffic':
2032 dij
= create_node_graph( route_curves
, route_gates
)
2034 for obj
in routes
:#{
2035 obj_data
= obj
.SR_data
.ent_route
[0]
2037 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
2038 route
.checkpoints_start
= checkpoint_count
2039 route
.checkpoints_count
= 0
2040 route
.id_camera
= sr_entity_id( obj_data
.cam
)
2043 route
.colour
[ci
] = obj_data
.colour
[ci
]
2044 route
.colour
[3] = 1.0
2046 compile_obj_transform( obj
, route
.transform
)
2047 checkpoints
= obj_data
.gates
2049 for i
in range(len(checkpoints
)):#{
2050 gi
= checkpoints
[i
].target
2051 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
2055 dest
= gi
.SR_data
.ent_gate
[0].target
2059 if gi
==gj
: continue # error?
2060 if not gi
or not gj
: continue
2062 checkpoint
= ent_checkpoint()
2063 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
2064 checkpoint
.path_start
= pathindice_count
2065 checkpoint
.path_count
= 0
2067 path
= solve_graph( dij
, gi
.name
, gj
.name
)
2070 for pi
in range(len(path
)):#{
2071 pathindice
= ent_path_index()
2072 pathindice
.index
= routenode_count
+ path
[pi
]
2073 sr_ent_push( pathindice
)
2075 checkpoint
.path_count
+= 1
2076 pathindice_count
+= 1
2080 sr_ent_push( checkpoint
)
2081 route
.checkpoints_count
+= 1
2082 checkpoint_count
+= 1
2085 sr_ent_push( route
)
2088 for obj
in traffics
:#{
2089 traffic
= ent_traffic()
2090 compile_obj_transform( obj
, traffic
.transform
)
2091 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2092 sr_compile_mesh_internal( obj
)
2094 # find best subsection
2096 graph_keys
= list(dij
.graph
)
2100 for j
in range(len(dij
.points
)):#{
2101 point
= dij
.points
[j
]
2102 dist
= (point
-obj
.location
).magnitude
2104 if dist
< min_dist
:#{
2111 best_begin
= best_point
2112 best_end
= best_point
2115 map0
= dij
.subsections
[best_begin
]
2116 if map0
[1] == -1: break
2117 best_begin
= map0
[1]
2120 map1
= dij
.subsections
[best_end
]
2121 if map1
[2] == -1: break
2125 traffic
.start_node
= routenode_count
+ best_begin
2126 traffic
.node_count
= best_end
- best_begin
2127 traffic
.index
= best_point
- best_begin
2128 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2131 sr_ent_push(traffic
)
2134 for point
in dij
.points
:#{
2135 rn
= ent_route_node()
2138 rn
.co
[2] = -point
[1]
2142 routenode_count
+= len(dij
.points
)
2145 print( F
"[SR] Writing file" )
2147 file_array_instructions
= {}
2150 def _write_array( name
, item_size
, data
):#{
2151 nonlocal file_array_instructions
, file_offset
2153 count
= len(data
)//item_size
2154 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2155 'data':data
, 'offset': file_offset
}
2156 file_offset
+= len(data
)
2157 file_offset
= int_align_to( file_offset
, 8 )
2160 _write_array( 'strings', 1, sr_compile
.string_data
)
2161 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2162 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2163 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2164 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2165 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2166 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2168 for name
, buffer in sr_compile
.entity_data
.items():#{
2169 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2172 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2173 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2174 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2175 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2176 _write_array( 'pack', 1, sr_compile
.pack_data
)
2178 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2179 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2181 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2182 path
= F
"{folder}{collection.name}.mdl"
2185 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2186 fp
= open( path
, "wb" )
2187 header
= mdl_header()
2188 header
.version
= MDL_VERSION_NR
2189 sr_array_title( header
.arrays
, \
2190 'index', len(file_array_instructions
), \
2191 sizeof(mdl_array
), header_size
)
2193 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2195 print( F
'[SR] {"name":>16}| count | offset' )
2197 for name
,info
in file_array_instructions
.items():#{
2199 offset
= info
['offset'] + header_size
+ index_size
2200 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2201 index
.extend( bytearray(arr
) )
2203 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2204 F
' 0x{info["offset"]:02x}' )
2206 fp
.write( bytearray_align_to( index
, 8 ) )
2207 #bytearray_print_hex( index )
2209 for name
,info
in file_array_instructions
.items():#{
2210 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2215 print( '[SR] done' )
2218 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2220 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2221 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2222 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2224 panel
: bpy
.props
.EnumProperty(
2228 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2229 ('ENTITY', 'Entity', '', 'MONKEY',1),
2230 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2235 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2237 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2238 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2241 def sr_get_mirror_bone( bones
):
2243 side
= bones
.active
.name
[-1:]
2244 other_name
= bones
.active
.name
[:-1]
2245 if side
== 'L': other_name
+= 'R'
2246 elif side
== 'R': other_name
+= 'L'
2250 if b
.name
== other_name
:
2257 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2259 bl_idname
="skaterift.mirror_bone"
2260 bl_label
="Mirror bone attributes - SkateRift"
2262 def execute(_
,context
):
2264 active_object
= context
.active_object
2265 bones
= active_object
.data
.bones
2267 b
= sr_get_mirror_bone( bones
)
2269 if not b
: return {'FINISHED'}
2271 b
.SR_data
.collider
= a
.SR_data
.collider
2273 def _v3copyflipy( a
, b
):#{
2279 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2280 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2281 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2282 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2284 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2286 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2287 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2288 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2290 b
.SR_data
.conet
= a
.SR_data
.conet
2293 ob
= bpy
.context
.scene
.objects
[0]
2294 ob
.hide_render
= ob
.hide_render
2299 class SR_COMPILE(bpy
.types
.Operator
):
2301 bl_idname
="skaterift.compile_all"
2302 bl_label
="Compile All"
2304 def execute(_
,context
):
2306 view_layer
= bpy
.context
.view_layer
2307 for col
in view_layer
.layer_collection
.children
["export"].children
:
2308 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2309 sr_compile( bpy
.data
.collections
[col
.name
] )
2315 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2317 bl_idname
="skaterift.compile_this"
2318 bl_label
="Compile This collection"
2320 def execute(_
,context
):
2322 col
= bpy
.context
.collection
2329 class SR_INTERFACE(bpy
.types
.Panel
):
2331 bl_idname
= "VIEW3D_PT_skate_rift"
2332 bl_label
= "Skate Rift"
2333 bl_space_type
= 'VIEW_3D'
2334 bl_region_type
= 'UI'
2335 bl_category
= "Skate Rift"
2337 def draw(_
, context
):
2341 row
= _
.layout
.row()
2343 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2345 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2346 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2348 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2349 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2350 col
= bpy
.context
.collection
2352 found_in_export
= False
2354 view_layer
= bpy
.context
.view_layer
2355 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2356 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2359 if c1
.name
== col
.name
: #{
2360 found_in_export
= True
2364 box
= _
.layout
.box()
2366 row
.alignment
= 'CENTER'
2369 if found_in_export
: #{
2370 row
.label( text
=col
.name
+ ".mdl" )
2371 box
.prop( col
.SR_data
, "pack_textures" )
2372 box
.prop( col
.SR_data
, "animations" )
2373 box
.operator( "skaterift.compile_this" )
2377 row
.label( text
=col
.name
)
2381 row
.alignment
= 'CENTER'
2383 row
.label( text
="This collection is not in the export group" )
2386 box
= _
.layout
.box()
2389 split
= row
.split( factor
=0.3, align
=True )
2390 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2393 if export_count
== 0:
2395 row1
.operator( "skaterift.compile_all", \
2396 text
=F
"Compile all ({export_count} collections)" )
2398 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2399 active_object
= context
.active_object
2400 if not active_object
: return
2402 amount
= max( 0, len(context
.selected_objects
)-1 )
2404 row
= _
.layout
.row()
2405 row
.operator( 'skaterift.copy_entity_data', \
2406 text
=F
'Copy entity data to {amount} other objects' )
2407 if amount
== 0: row
.enabled
=False
2409 box
= _
.layout
.box()
2411 row
.alignment
= 'CENTER'
2412 row
.label( text
=active_object
.name
)
2415 def _draw_prop_collection( source
, data
): #{
2418 row
.alignment
= 'CENTER'
2421 row
.label( text
=F
'{source}' )
2423 if hasattr(type(data
[0]),'sr_inspector'):#{
2424 type(data
[0]).sr_inspector( box
, data
)
2427 for a
in data
[0].__annotations
__:
2428 box
.prop( data
[0], a
)
2432 if active_object
.type == 'ARMATURE': #{
2433 if active_object
.mode
== 'POSE': #{
2434 bones
= active_object
.data
.bones
2435 mb
= sr_get_mirror_bone( bones
)
2437 box
.operator( "skaterift.mirror_bone", \
2438 text
=F
'Mirror attributes to {mb.name}' )
2441 _draw_prop_collection( \
2442 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2443 [bones
.active
.SR_data
] )
2447 row
.alignment
='CENTER'
2450 row
.label( text
="Enter pose mode to modify bone properties" )
2453 elif active_object
.type == 'LIGHT': #{
2454 _draw_prop_collection( \
2455 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2456 [active_object
.data
.SR_data
] )
2458 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2459 box
.prop( active_object
.SR_data
, "ent_type" )
2460 ent_type
= active_object
.SR_data
.ent_type
2462 col
= getattr( active_object
.SR_data
, ent_type
, None )
2463 if col
!= None and len(col
)!=0:
2464 _draw_prop_collection( \
2465 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2468 if active_object
.type == 'MESH':#{
2469 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2470 if col
!= None and len(col
)!=0:
2471 _draw_prop_collection( \
2472 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2480 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2482 bl_label
="Skate Rift material"
2483 bl_idname
="MATERIAL_PT_sr_material"
2484 bl_space_type
='PROPERTIES'
2485 bl_region_type
='WINDOW'
2486 bl_context
="material"
2488 def draw(_
,context
):
2490 active_object
= bpy
.context
.active_object
2491 if active_object
== None: return
2492 active_mat
= active_object
.active_material
2493 if active_mat
== None: return
2495 info
= material_info( active_mat
)
2497 if 'tex_diffuse' in info
:#{
2498 _
.layout
.label( icon
='INFO', \
2499 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2502 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2503 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2504 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2506 if active_mat
.SR_data
.collision
:#{
2507 box
= _
.layout
.box()
2510 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2511 (active_mat
.SR_data
.shader
!= 'boundary') and \
2512 (active_mat
.SR_data
.shader
!= 'walking'):#{
2513 row
.prop( active_mat
.SR_data
, "skate_surface" )
2514 row
.prop( active_mat
.SR_data
, "grind_surface" )
2515 row
.prop( active_mat
.SR_data
, "grow_grass" )
2516 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2520 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2521 box
= _
.layout
.box()
2522 box
.prop( active_mat
.SR_data
, "blend_offset" )
2523 box
.prop( active_mat
.SR_data
, "sand_colour" )
2525 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2526 box
= _
.layout
.box()
2527 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2528 box
.prop( active_mat
.SR_data
, "blend_offset" )
2530 elif active_mat
.SR_data
.shader
== "water":#{
2531 box
= _
.layout
.box()
2532 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2533 box
.prop( active_mat
.SR_data
, "shore_colour" )
2534 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2536 elif active_mat
.SR_data
.shader
== "cubemap":#{
2537 box
= _
.layout
.box()
2538 box
.prop( active_mat
.SR_data
, "cubemap" )
2539 box
.prop( active_mat
.SR_data
, "tint" )
2544 def sr_get_type_enum( scene
, context
):
2546 items
= [('none','None',"")]
2547 mesh_entities
=['ent_gate','ent_water']
2548 point_entities
=['ent_spawn','ent_route_node','ent_route']
2550 for e
in point_entities
: items
+= [(e
,e
,'')]
2552 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2553 if context
.active_object
.type == 'MESH': #{
2554 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2558 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2564 def sr_on_type_change( _
, context
):
2566 obj
= context
.active_object
2567 ent_type
= obj
.SR_data
.ent_type
2568 if ent_type
== 'none': return
2569 if obj
.type == 'MESH':#{
2570 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2571 if col
!= None and len(col
)==0: col
.add()
2574 col
= getattr( obj
.SR_data
, ent_type
, None )
2575 if col
!= None and len(col
)==0: col
.add()
2578 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2580 alias
: bpy
.props
.StringProperty( name
='alias' )
2583 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2585 target
: bpy
.props
.PointerProperty( \
2586 type=bpy
.types
.Object
, name
="destination", \
2587 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2589 key
: bpy
.props
.StringProperty()
2590 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2591 ('nonlocal', 'Non-Local', "")))
2593 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2594 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2595 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2598 def sr_inspector( layout
, data
):
2601 box
.prop( data
[0], 'tipo', text
="subtype" )
2603 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2604 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2607 flags
.prop( data
[0], 'flip' )
2608 flags
.prop( data
[0], 'custom' )
2609 flags
.prop( data
[0], 'locked' )
2613 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2615 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2618 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2620 target
: bpy
.props
.PointerProperty( \
2621 type=bpy
.types
.Object
, name
='target', \
2622 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2625 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2627 world
: bpy
.props
.StringProperty( name
='world UID' )
2628 proxy
: bpy
.props
.PointerProperty( \
2629 type=bpy
.types
.Object
, name
='proxy', \
2630 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2631 camera
: bpy
.props
.PointerProperty( \
2632 type=bpy
.types
.Object
, name
="Camera", \
2633 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2636 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2638 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2640 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2642 layout
.prop( item
, 'target', text
='', emboss
=False )
2646 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2648 active_object
= context
.active_object
2649 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2650 lista
= getattr(data
,collection_name
)
2651 index
= getattr(data
,F
'{collection_name}_index')
2655 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2659 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2661 active_object
= context
.active_object
2662 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2666 def copy_propgroup( de
, to
):
2668 for a
in de
.__annotations
__:#{
2669 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2673 while len(cb
) != len(ca
):#{
2674 if len(cb
) < len(ca
): cb
.add()
2677 for i
in range(len(ca
)):#{
2678 copy_propgroup(ca
[i
],cb
[i
])
2682 setattr(to
,a
,getattr(de
,a
))
2687 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2689 bl_idname
= "skaterift.copy_entity_data"
2690 bl_label
= "Copy entity data"
2692 def execute(self
, context
):#{
2693 data
= context
.active_object
.SR_data
2694 new_type
= data
.ent_type
2695 print( F
"Copy entity data from: {context.active_object.name}" )
2697 for obj
in context
.selected_objects
:#{
2698 if obj
!= context
.active_object
:#{
2699 print( F
" To: {obj.name}" )
2701 obj
.SR_data
.ent_type
= new_type
2703 if active_object
.type == 'MESH':#{
2704 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2705 if col
!= None and len(col
)==0: col
.add()
2706 mdata
= context
.active_object
.data
.SR_data
2707 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2710 col
= getattr( obj
.SR_data
, new_type
, None )
2711 if col
!= None and len(col
)==0: col
.add()
2712 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2719 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2721 bl_idname
= "skaterift.new_entry"
2722 bl_label
= "Add gate"
2724 def execute(self
, context
):#{
2725 return internal_listadd_execute(self
,context
,'ent_route','gates')
2729 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2731 bl_idname
= "skaterift.del_entry"
2732 bl_label
= "Remove gate"
2735 def poll(cls
, context
):#{
2736 active_object
= context
.active_object
2737 if obj_ent_type(active_object
) == 'ent_route':#{
2738 return active_object
.SR_data
.ent_route
[0].gates
2743 def execute(self
, context
):#{
2744 return internal_listdel_execute(self
,context
,'ent_route','gates')
2748 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2750 bl_idname
= "skaterift.al_new_entry"
2751 bl_label
= "Add file"
2753 def execute(self
, context
):#{
2754 return internal_listadd_execute(self
,context
,'ent_audio','files')
2758 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2760 bl_idname
= "skaterift.al_del_entry"
2761 bl_label
= "Remove file"
2764 def poll(cls
, context
):#{
2765 active_object
= context
.active_object
2766 if obj_ent_type(active_object
) == 'ent_audio':#{
2767 return active_object
.SR_data
.ent_audio
[0].files
2772 def execute(self
, context
):#{
2773 return internal_listdel_execute(self
,context
,'ent_audio','files')
2778 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2780 bl_idname
= "skaterift.gl_new_entry"
2781 bl_label
= "Add glyph"
2783 def execute(self
, context
):#{
2784 active_object
= context
.active_object
2786 font
= active_object
.SR_data
.ent_font
[0]
2789 if len(font
.glyphs
) > 1:#{
2790 prev
= font
.glyphs
[-2]
2791 cur
= font
.glyphs
[-1]
2793 cur
.bounds
= prev
.bounds
2794 cur
.utf32
= prev
.utf32
+1
2801 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2803 bl_idname
= "skaterift.gl_del_entry"
2804 bl_label
= "Remove Glyph"
2807 def poll(cls
, context
):#{
2808 active_object
= context
.active_object
2809 if obj_ent_type(active_object
) == 'ent_font':#{
2810 return active_object
.SR_data
.ent_font
[0].glyphs
2815 def execute(self
, context
):#{
2816 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2820 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2822 bl_idname
= "skaterift.gl_move_item"
2824 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2825 ('DOWN', 'Down', ""),))
2828 def poll(cls
, context
):#{
2829 active_object
= context
.active_object
2830 if obj_ent_type(active_object
) == 'ent_font':#{
2831 return active_object
.SR_data
.ent_font
[0].glyphs
2836 def execute(_
, context
):#{
2837 active_object
= context
.active_object
2838 data
= active_object
.SR_data
.ent_font
[0]
2840 index
= data
.glyphs_index
2841 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2842 data
.glyphs
.move( neighbor
, index
)
2844 list_length
= len(data
.glyphs
) - 1
2845 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2847 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2853 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2855 bl_idname
= "skaterift.fv_new_entry"
2856 bl_label
= "Add variant"
2858 def execute(self
, context
):#{
2859 return internal_listadd_execute(self
,context
,'ent_font','variants')
2863 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2865 bl_idname
= "skaterift.fv_del_entry"
2866 bl_label
= "Remove variant"
2869 def poll(cls
, context
):#{
2870 active_object
= context
.active_object
2871 if obj_ent_type(active_object
) == 'ent_font':#{
2872 return active_object
.SR_data
.ent_font
[0].variants
2877 def execute(self
, context
):#{
2878 return internal_listdel_execute(self
,context
,'ent_font','variants')
2882 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2884 path
: bpy
.props
.StringProperty( name
="Path" )
2885 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2888 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2890 bl_idname
= 'SR_UL_AUDIO_LIST'
2892 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2894 split
= layout
.split(factor
=0.7)
2896 c
.prop( item
, 'path', text
='', emboss
=False )
2898 c
.prop( item
, 'probability', text
='%', emboss
=True )
2902 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2904 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2906 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2908 layout
.prop( item
, 'mesh', emboss
=False )
2909 layout
.prop( item
, 'tipo' )
2913 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2915 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2917 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2919 s0
= layout
.split(factor
=0.3)
2921 s1
= c
.split(factor
=0.3)
2924 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2928 c
.prop( item
, 'utf32', text
='', emboss
=True )
2931 row
.prop( item
, 'bounds', text
='', emboss
=False )
2935 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2937 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2938 gates_index
: bpy
.props
.IntProperty()
2940 colour
: bpy
.props
.FloatVectorProperty( \
2944 default
=Vector((0.79,0.63,0.48)),\
2945 description
="Route colour"\
2948 alias
: bpy
.props
.StringProperty(\
2950 default
="Untitled Course")
2952 cam
: bpy
.props
.PointerProperty( \
2953 type=bpy
.types
.Object
, name
="Viewpoint", \
2954 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2957 def sr_inspector( layout
, data
):
2959 layout
.prop( data
[0], 'alias' )
2960 layout
.prop( data
[0], 'colour' )
2961 layout
.prop( data
[0], 'cam' )
2963 layout
.label( text
='Checkpoints' )
2964 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2965 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2968 row
.operator( 'skaterift.new_entry', text
='Add' )
2969 row
.operator( 'skaterift.del_entry', text
='Remove' )
2973 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
2974 subtype
: bpy
.props
.EnumProperty(
2976 items
=[('0','Trigger',''),
2977 ('1','Particles (0.1s)','')]
2980 target
: bpy
.props
.PointerProperty( \
2981 type=bpy
.types
.Object
, name
="Target", \
2982 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
2983 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
2984 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
2987 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
2989 box
.prop( data
[0], propname
)
2991 for evname
in evs
:#{
2993 row
.prop( data
[0], propname
+ evname
)
2995 target
= getattr( data
[0], propname
)
2997 tipo
= target
.SR_data
.ent_type
2998 cls
= globals()[ tipo
]
3000 table
= getattr( cls
, 'sr_functions', None )
3002 index
= getattr( data
[0], propname
+ evname
)
3004 row
.label( text
=table
[index
] )
3006 row
.label( text
="undefined function" )
3010 row
.label( text
="..." )
3017 def sr_inspector( layout
, data
):#{
3018 layout
.prop( data
[0], 'subtype' )
3019 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3020 ['_event','_event_leave'] )
3024 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3026 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3027 files_index
: bpy
.props
.IntProperty()
3029 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3030 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3031 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3032 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3034 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3035 formato
: bpy
.props
.EnumProperty(
3037 items
=[('0','Uncompressed Mono',''),
3038 ('1','Compressed Vorbis',''),
3039 ('2','[vg] Bird Synthesis','')]
3041 probability_curve
: bpy
.props
.EnumProperty(
3042 name
="Probability Curve",
3043 items
=[('0','Constant',''),
3044 ('1','Wildlife Daytime',''),
3045 ('2','Wildlife Nighttime','')])
3046 channel_behaviour
: bpy
.props
.EnumProperty(
3047 name
="Channel Behaviour",
3048 items
=[('0','Unlimited',''),
3049 ('1','Discard if group full', ''),
3050 ('2','Crossfade if group full','')])
3052 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3055 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3056 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3059 def sr_inspector( layout
, data
):
3061 layout
.prop( data
[0], 'formato' )
3062 layout
.prop( data
[0], 'volume' )
3065 box
.label( text
='Channels' )
3066 split
= box
.split(factor
=0.3)
3068 c
.prop( data
[0], 'max_channels' )
3070 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3071 if data
[0].channel_behaviour
>= '1':
3072 box
.prop( data
[0], 'group' )
3073 if data
[0].channel_behaviour
== '2':
3074 box
.prop( data
[0], 'transition_duration' )
3077 box
.label( text
='Flags' )
3078 box
.prop( data
[0], 'flag_3d' )
3079 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3081 box
.prop( data
[0], 'flag_loop' )
3082 box
.prop( data
[0], 'flag_auto' )
3084 layout
.prop( data
[0], 'probability_curve' )
3086 split
= layout
.split(factor
=0.7)
3088 c
.label( text
='Filepath' )
3090 c
.label( text
='Chance' )
3091 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3092 data
[0], 'files', data
[0], 'files_index', rows
=5)
3095 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3096 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3100 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3102 alias
: bpy
.props
.StringProperty()
3105 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3107 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3108 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3109 utf32
: bpy
.props
.IntProperty()
3112 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3114 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3115 utf32
: bpy
.props
.IntProperty()
3118 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3120 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3121 tipo
: bpy
.props
.StringProperty()
3124 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3126 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3127 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3128 alias
: bpy
.props
.StringProperty()
3130 glyphs_index
: bpy
.props
.IntProperty()
3131 variants_index
: bpy
.props
.IntProperty()
3134 def sr_inspector( layout
, data
):
3136 layout
.prop( data
[0], 'alias' )
3138 layout
.label( text
='Variants' )
3139 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3140 data
[0], 'variants', data
[0], 'variants_index',\
3143 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3144 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3146 layout
.label( text
='ASCII Glyphs' )
3147 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3148 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3151 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3152 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3153 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3154 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3158 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3160 speed
: bpy
.props
.FloatProperty(default
=1.0)
3163 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3165 tipo
: bpy
.props
.EnumProperty( name
='Type',
3166 items
=[('0','boards',''),
3167 ('1','character',''),
3169 mark_rack
: bpy
.props
.PointerProperty( \
3170 type=bpy
.types
.Object
, name
="Board Rack", \
3171 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3172 mark_display
: bpy
.props
.PointerProperty( \
3173 type=bpy
.types
.Object
, name
="Selected Board Display", \
3174 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3175 mark_info
: bpy
.props
.PointerProperty( \
3176 type=bpy
.types
.Object
, name
="Selected Board Info", \
3177 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3178 cam
: bpy
.props
.PointerProperty( \
3179 type=bpy
.types
.Object
, name
="Viewpoint", \
3180 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3183 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3185 mark_display
: bpy
.props
.PointerProperty( \
3186 type=bpy
.types
.Object
, name
="Board Display", \
3187 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3188 mark_display1
: bpy
.props
.PointerProperty( \
3189 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3190 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3191 cam
: bpy
.props
.PointerProperty( \
3192 type=bpy
.types
.Object
, name
="Viewpoint", \
3193 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3196 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3198 link0
: bpy
.props
.PointerProperty( \
3199 type=bpy
.types
.Object
, name
="Link 0", \
3200 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3201 link1
: bpy
.props
.PointerProperty( \
3202 type=bpy
.types
.Object
, name
="Link 1", \
3203 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3204 link2
: bpy
.props
.PointerProperty( \
3205 type=bpy
.types
.Object
, name
="Link 2", \
3206 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3207 link3
: bpy
.props
.PointerProperty( \
3208 type=bpy
.types
.Object
, name
="Link 3", \
3209 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3211 newloc
: bpy
.props
.PointerProperty( \
3212 type=bpy
.types
.Object
, name
="New location", \
3213 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3214 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3215 items
=[('0','append',''),
3216 ('1','replace','')])
3218 camera
: bpy
.props
.PointerProperty( \
3219 type=bpy
.types
.Object
, name
="Camera", \
3220 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3222 slider_minloc
: bpy
.props
.PointerProperty( \
3223 type=bpy
.types
.Object
, name
="Slider min", \
3224 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3225 slider_maxloc
: bpy
.props
.PointerProperty( \
3226 type=bpy
.types
.Object
, name
="Slider max", \
3227 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3228 slider_handle
: bpy
.props
.PointerProperty( \
3229 type=bpy
.types
.Object
, name
="Slider handle", \
3230 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3232 checkmark
: bpy
.props
.PointerProperty( \
3233 type=bpy
.types
.Object
, name
="Checked", \
3234 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3236 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3238 string
: bpy
.props
.StringProperty( name
="String" )
3239 tipo
: bpy
.props
.EnumProperty( name
='Type',
3240 items
=[('0','visual',''),
3241 ('1','event button',''),
3242 ('2','page button',''),
3247 ('7','visual(no colourize)','')])
3250 def sr_inspector( layout
, data
):
3254 box
.prop( data
, 'tipo' )
3256 if data
.tipo
== '0' or data
.tipo
== '7':#{
3257 box
.prop( data
, 'string', text
='Name' )
3260 elif data
.tipo
== '1':#{
3261 box
.prop( data
, 'string', text
='Event' )
3263 elif data
.tipo
== '2':#{
3264 box
.prop( data
, 'string', text
='Page' )
3265 box
.prop( data
, 'stack_behaviour' )
3267 elif data
.tipo
== '3':#{
3268 box
.prop( data
, 'string', text
='Data (i32)' )
3269 box
.prop( data
, 'checkmark' )
3271 elif data
.tipo
== '4':#{
3272 box
.prop( data
, 'string', text
='Data (f32)' )
3273 box
.prop( data
, 'slider_minloc' )
3274 box
.prop( data
, 'slider_maxloc' )
3275 box
.prop( data
, 'slider_handle' )
3277 box
.label( text
="Links" )
3278 box
.prop( data
, 'link0', text
='v0' )
3279 box
.prop( data
, 'link1', text
='v1' )
3282 elif data
.tipo
== '5':#{
3283 box
.prop( data
, 'string', text
='Page Name' )
3284 box
.prop( data
, 'newloc', text
='Entry Point' )
3285 box
.prop( data
, 'camera', text
='Viewpoint' )
3288 elif data
.tipo
== '6':#{
3289 box
.prop( data
, 'string', text
='ID' )
3290 box
.prop( data
, 'font_variant' )
3295 box
.label( text
="Links" )
3296 box
.prop( data
, 'link0' )
3297 box
.prop( data
, 'link1' )
3298 box
.prop( data
, 'link2' )
3299 box
.prop( data
, 'link3' )
3303 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3305 name
: bpy
.props
.StringProperty(name
="Name")
3306 desc
: bpy
.props
.StringProperty(name
="Description")
3307 author
: bpy
.props
.StringProperty(name
="Author")
3308 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3309 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3312 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3314 command
: bpy
.props
.StringProperty(name
="Command Line")
3317 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3318 proxima
: bpy
.props
.PointerProperty( \
3319 type=bpy
.types
.Object
, name
="Next", \
3320 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3321 target
: bpy
.props
.PointerProperty( \
3322 type=bpy
.types
.Object
, name
="Win", \
3323 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3324 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3325 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3326 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3327 items
=[('0','none',''),
3328 (str(0x1),'trick_shuvit',''),
3329 (str(0x2),'trick_kickflip',''),
3330 (str(0x4),'trick_treflip',''),
3331 (str(0x1|
0x2|
0x4),'trick_any',''),
3332 (str(0x8),'flip_back',''),
3333 (str(0x10),'flip_front',''),
3334 (str(0x8|
0x10),'flip_any',''),
3335 (str(0x20),'grind_truck_any',''),
3336 (str(0x40),'grind_board_any',''),
3337 (str(0x20|
0x40),'grind_any',''),
3338 (str(0x80),'footplant',''),
3339 (str(0x100),'passthrough',''),
3343 def sr_inspector( layout
, data
):#{
3344 layout
.prop( data
[0], 'proxima' )
3345 layout
.prop( data
[0], 'time_limit' )
3346 layout
.prop( data
[0], 'filtrar' )
3347 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3351 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3352 alias
: bpy
.props
.StringProperty( name
="Alias" )
3354 target
: bpy
.props
.PointerProperty( \
3355 type=bpy
.types
.Object
, name
="On Complete", \
3356 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3357 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3358 reset
: bpy
.props
.PointerProperty( \
3359 type=bpy
.types
.Object
, name
="On Reset", \
3360 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3361 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3363 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3365 first
: bpy
.props
.PointerProperty( \
3366 type=bpy
.types
.Object
, name
="First Objective", \
3367 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3369 camera
: bpy
.props
.PointerProperty( \
3370 type=bpy
.types
.Object
, name
="Camera", \
3371 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3375 def sr_inspector( layout
, data
):#{
3376 layout
.prop( data
[0], 'alias' )
3377 layout
.prop( data
[0], 'camera' )
3378 layout
.prop( data
[0], 'first' )
3379 layout
.prop( data
[0], 'time_limit' )
3380 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3381 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3385 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3386 target0
: bpy
.props
.PointerProperty( \
3387 type=bpy
.types
.Object
, name
="Target 0", \
3388 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3389 target1
: bpy
.props
.PointerProperty( \
3390 type=bpy
.types
.Object
, name
="Target 1", \
3391 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3392 target2
: bpy
.props
.PointerProperty( \
3393 type=bpy
.types
.Object
, name
="Target 2", \
3394 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3395 target3
: bpy
.props
.PointerProperty( \
3396 type=bpy
.types
.Object
, name
="Target 3", \
3397 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3399 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3400 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3401 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3402 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3405 def sr_inspector( layout
, data
):#{
3406 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3407 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3408 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3409 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3413 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3415 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3416 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3417 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3418 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3419 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3420 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3421 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3422 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3423 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3424 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3426 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3427 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3428 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3429 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3430 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3431 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3432 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3433 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3435 ent_type
: bpy
.props
.EnumProperty(
3437 items
=sr_entity_list
,
3438 update
=sr_on_type_change
3442 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3444 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3447 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3449 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3452 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3454 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3455 items
=[('0','none',''),
3457 ('2','capsule','')])
3459 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3460 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3462 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3464 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3465 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3466 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3467 conet
: bpy
.props
.FloatProperty( name
='t' )
3470 def sr_inspector( layout
, data
):
3474 box
.prop( data
, 'collider' )
3476 if int(data
.collider
)>0:#{
3478 row
.prop( data
, 'collider_min' )
3480 row
.prop( data
, 'collider_max' )
3484 box
.prop( data
, 'cone_constraint' )
3485 if data
.cone_constraint
:#{
3487 row
.prop( data
, 'conevx' )
3489 row
.prop( data
, 'conevy' )
3491 row
.prop( data
, 'coneva' )
3492 box
.prop( data
, 'conet' )
3497 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3499 shader
: bpy
.props
.EnumProperty(
3502 ('standard',"standard",''),
3503 ('standard_cutout', "standard_cutout", ''),
3504 ('terrain_blend', "terrain_blend", ''),
3505 ('vertex_blend', "vertex_blend", ''),
3506 ('water',"water",''),
3507 ('invisible','Invisible',''),
3508 ('boundary','Boundary',''),
3509 ('fxglow','FX Glow',''),
3510 ('cubemap','Cubemap',''),
3511 ('walking','Walking','')
3514 surface_prop
: bpy
.props
.EnumProperty(
3515 name
="Surface Property",
3517 ('0','concrete',''),
3524 collision
: bpy
.props
.BoolProperty( \
3525 name
="Collisions Enabled",\
3527 description
= "Can the player collide with this material?"\
3529 skate_surface
: bpy
.props
.BoolProperty( \
3530 name
="Skate Target", \
3532 description
= "Should the game try to target this surface?" \
3534 grind_surface
: bpy
.props
.BoolProperty( \
3537 description
= "Can you grind on this surface?" \
3539 grow_grass
: bpy
.props
.BoolProperty( \
3540 name
="Grow Grass", \
3542 description
= "Spawn grass sprites on this surface?" \
3544 preview_visibile
: bpy
.props
.BoolProperty( \
3545 name
="Preview visibile", \
3547 description
= "Show this material in preview models?" \
3549 blend_offset
: bpy
.props
.FloatVectorProperty( \
3550 name
="Blend Offset", \
3552 default
=Vector((0.5,0.0)),\
3553 description
="When surface is more than 45 degrees, add this vector " +\
3556 sand_colour
: bpy
.props
.FloatVectorProperty( \
3557 name
="Sand Colour",\
3560 default
=Vector((0.79,0.63,0.48)),\
3561 description
="Blend to this colour near the 0 coordinate on UP axis"\
3563 shore_colour
: bpy
.props
.FloatVectorProperty( \
3564 name
="Shore Colour",\
3567 default
=Vector((0.03,0.32,0.61)),\
3568 description
="Water colour at the shoreline"\
3570 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3571 name
="Ocean Colour",\
3574 default
=Vector((0.0,0.006,0.03)),\
3575 description
="Water colour in the deep bits"\
3577 tint
: bpy
.props
.FloatVectorProperty( \
3582 default
=Vector((1.0,1.0,1.0,1.0)),\
3583 description
="Reflection tint"\
3586 cubemap
: bpy
.props
.PointerProperty( \
3587 type=bpy
.types
.Object
, name
="cubemap", \
3588 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3591 # ---------------------------------------------------------------------------- #
3595 # ---------------------------------------------------------------------------- #
3597 cv_view_draw_handler
= None
3598 cv_view_pixel_handler
= None
3599 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3601 cv_view_colours
= []
3602 cv_view_course_i
= 0
3604 # Draw axis alligned sphere at position with radius
3606 def cv_draw_sphere( pos
, radius
, colour
):
3608 global cv_view_verts
, cv_view_colours
3610 ly
= pos
+ Vector((0,0,radius
))
3611 lx
= pos
+ Vector((0,radius
,0))
3612 lz
= pos
+ Vector((0,0,radius
))
3614 pi
= 3.14159265358979323846264
3616 for i
in range(16):#{
3617 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3621 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3622 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3623 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3625 cv_view_verts
+= [ px
, lx
]
3626 cv_view_verts
+= [ py
, ly
]
3627 cv_view_verts
+= [ pz
, lz
]
3629 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3638 # Draw axis alligned sphere at position with radius
3640 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3642 global cv_view_verts
, cv_view_colours
3644 ly
= pos
+ tz
*radius
3645 lx
= pos
+ ty
*radius
3646 lz
= pos
+ tz
*radius
3648 pi
= 3.14159265358979323846264
3650 for i
in range(16):#{
3651 t
= ((i
+1.0) * 1.0/16.0) * pi
3655 s1
= math
.sin(t
*2.0)
3656 c1
= math
.cos(t
*2.0)
3658 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3659 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3660 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3662 cv_view_verts
+= [ px
, lx
]
3663 cv_view_verts
+= [ py
, ly
]
3664 cv_view_verts
+= [ pz
, lz
]
3666 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3675 # Draw transformed -1 -> 1 cube
3677 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3679 global cv_view_verts
, cv_view_colours
3685 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3686 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3687 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3688 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3689 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3690 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3691 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3692 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3694 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3695 (0,4),(1,5),(2,6),(3,7)]
3700 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3701 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3702 cv_view_colours
+= [colour
, colour
]
3707 # Draw line with colour
3709 def cv_draw_line( p0
, p1
, colour
):
3711 global cv_view_verts
, cv_view_colours
3713 cv_view_verts
+= [p0
,p1
]
3714 cv_view_colours
+= [colour
, colour
]
3718 # Draw line with colour(s)
3720 def cv_draw_line2( p0
, p1
, c0
, c1
):
3722 global cv_view_verts
, cv_view_colours
3724 cv_view_verts
+= [p0
,p1
]
3725 cv_view_colours
+= [c0
,c1
]
3731 def cv_tangent_basis( n
, tx
, ty
):
3733 if abs( n
[0] ) >= 0.57735027:#{
3752 # Draw coloured arrow
3754 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
3756 global cv_view_verts
, cv_view_colours
3762 tx
= Vector((1,0,0))
3763 ty
= Vector((1,0,0))
3764 cv_tangent_basis( n
, tx
, ty
)
3770 gpu
.state
.line_width_set(1.0)
3773 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3774 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3778 gpu
.state
.line_width_set(3.0)
3779 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
3781 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
3783 gpu
.state
.line_width_set(2.0)
3787 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3789 global cv_view_verts
, cv_view_colours
3791 for i
in range(dots
):#{
3795 p2
= p0
*(1.0-t0
)+p1
*t0
3796 p3
= p0
*(1.0-t1
)+p1
*t1
3798 cv_view_verts
+= [p2
,p3
]
3799 cv_view_colours
+= [c0
,c0
]
3804 # Drawhandles of a bezier control point
3806 def cv_draw_bhandle( obj
, direction
, colour
):
3808 global cv_view_verts
, cv_view_colours
3811 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3813 cv_view_verts
+= [p0
]
3814 cv_view_verts
+= [h0
]
3815 cv_view_colours
+= [colour
,colour
]
3819 # Draw a bezier curve (at fixed resolution 10)
3821 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3823 global cv_view_verts
, cv_view_colours
3826 for i
in range(10):#{
3832 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3834 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3835 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3836 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3843 # I think this one extends the handles of the bezier otwards......
3845 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3847 global cv_view_course_i
3849 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3851 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3852 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3853 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3854 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3856 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3860 # Flush the lines buffers. This is called often because god help you if you want
3861 # to do fixed, fast buffers in this catastrophic programming language.
3863 def cv_draw_lines():
3865 global cv_view_shader
, cv_view_verts
, cv_view_colours
3867 if len(cv_view_verts
) < 2:
3870 lines
= batch_for_shader(\
3871 cv_view_shader
, 'LINES', \
3872 { "pos":cv_view_verts
, "color":cv_view_colours
})
3874 if bpy
.context
.scene
.SR_data
.gizmos
:
3875 lines
.draw( cv_view_shader
)
3878 cv_view_colours
= []
3881 # I dont remember what this does exactly
3883 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3885 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3888 # Semi circle to show the limit. and some lines
3890 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3892 global cv_view_verts
, cv_view_colours
3897 for x
in range(16):#{
3900 a0
= amin
*(1.0-t0
)+amax
*t0
3901 a1
= amin
*(1.0-t1
)+amax
*t1
3903 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3904 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3906 p0
=obj
.matrix_world
@ p0
3907 p1
=obj
.matrix_world
@ p1
3908 cv_view_verts
+= [p0
,p1
]
3909 cv_view_colours
+= [colour
,colour
]
3912 cv_view_verts
+= [p0
,center
]
3913 cv_view_colours
+= [colour
,colour
]
3916 cv_view_verts
+= [p1
,center
]
3917 cv_view_colours
+= [colour
,colour
]
3921 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
3922 cv_view_colours
+= [colour
,colour
]
3927 # Cone and twist limit
3929 def draw_cone_twist( center
, vx
, vy
, va
):
3931 global cv_view_verts
, cv_view_colours
3932 axis
= vy
.cross( vx
)
3937 cv_view_verts
+= [center
, center
+va
*size
]
3938 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
3940 for x
in range(32):#{
3941 t0
= (x
/32) * math
.tau
3942 t1
= ((x
+1)/32) * math
.tau
3949 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
3950 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
3952 col0
= ( abs(c0
), abs(s0
), 0.0 )
3953 col1
= ( abs(c1
), abs(s1
), 0.0 )
3955 cv_view_verts
+= [center
, p0
, p0
, p1
]
3956 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
3962 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
3964 def draw_skeleton_helpers( obj
):
3966 global cv_view_verts
, cv_view_colours
3968 if obj
.data
.pose_position
!= 'REST':#{
3972 for bone
in obj
.data
.bones
:#{
3974 a
= Vector((bone
.SR_data
.collider_min
[0],
3975 bone
.SR_data
.collider_min
[1],
3976 bone
.SR_data
.collider_min
[2]))
3977 b
= Vector((bone
.SR_data
.collider_max
[0],
3978 bone
.SR_data
.collider_max
[1],
3979 bone
.SR_data
.collider_max
[2]))
3981 if bone
.SR_data
.collider
== '1':#{
3983 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
3984 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
3985 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
3986 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
3987 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
3988 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
3989 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
3990 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
3992 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3993 (0,4),(1,5),(2,6),(3,7)]
3999 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4000 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4001 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4004 elif bone
.SR_data
.collider
== '2':#{
4009 for i
in range(3):#{
4010 if abs(v0
[i
]) > largest
:#{
4011 largest
= abs(v0
[i
])
4016 v1
= Vector((0,0,0))
4017 v1
[major_axis
] = 1.0
4019 tx
= Vector((0,0,0))
4020 ty
= Vector((0,0,0))
4022 cv_tangent_basis( v1
, tx
, ty
)
4023 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4024 l
= v0
[ major_axis
] - r
*2
4026 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4027 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4029 colour
= [0.2,0.2,0.2]
4030 colour
[major_axis
] = 0.5
4032 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4033 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4034 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4035 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4036 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4037 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4043 center
= obj
.matrix_world
@ c
4044 if bone
.SR_data
.cone_constraint
:#{
4045 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4046 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4047 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4048 draw_cone_twist( center
, vx
, vy
, va
)
4053 def cv_ent_gate( obj
):
4055 global cv_view_verts
, cv_view_colours
4057 if obj
.type != 'MESH': return
4059 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4060 data
= obj
.SR_data
.ent_gate
[0]
4061 dims
= mesh_data
.dimensions
4064 c
= Vector((0,0,dims
[2]))
4066 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4067 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4068 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4069 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4070 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4071 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4072 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4073 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4074 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4076 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4078 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4080 p0
= r3d
.view_matrix
.inverted().translation
4081 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4082 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4084 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4090 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4091 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4092 cv_view_colours
+= [cc
,cc
]
4096 if data
.target
!= None:
4097 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4100 def cv_ent_volume( obj
):
4102 global cv_view_verts
, cv_view_colours
4104 data
= obj
.SR_data
.ent_volume
[0]
4106 if data
.subtype
== '0':#{
4107 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4110 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4113 elif data
.subtype
== '1':#{
4114 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4117 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4122 def dijkstra( graph
, start_node
, target_node
):
4124 unvisited
= [_
for _
in graph
]
4129 shortest_path
[n
] = 9999999.999999
4130 shortest_path
[start_node
] = 0
4133 current_min_node
= None
4134 for n
in unvisited
:#{
4135 if current_min_node
== None:
4136 current_min_node
= n
4137 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4138 current_min_node
= n
4141 for branch
in graph
[current_min_node
]:#{
4142 tentative_value
= shortest_path
[current_min_node
]
4143 tentative_value
+= graph
[current_min_node
][branch
]
4144 if tentative_value
< shortest_path
[branch
]:#{
4145 shortest_path
[branch
] = tentative_value
4146 previous_nodes
[branch
] = current_min_node
4150 unvisited
.remove(current_min_node
)
4155 while node
!= start_node
:#{
4158 if node
not in previous_nodes
: return None
4159 node
= previous_nodes
[node
]
4162 # Add the start node manually
4163 path
.append(start_node
)
4169 def __init__(_
,points
,graph
,subsections
):#{
4172 _
.subsections
= subsections
4176 def create_node_graph( curves
, gates
):
4178 # add endpoints of curves
4185 for c
in range(len(curves
)):#{
4186 for s
in range(len(curves
[c
].data
.splines
)):#{
4187 spline
= curves
[c
].data
.splines
[s
]
4188 l
= len(spline
.points
)
4191 dist
= round(spline
.calc_length(),2)
4194 ib
= point_count
+l
-1
4196 graph
[ia
] = { ib
: dist
}
4197 graph
[ib
] = { ia
: dist
}
4199 for i
in range(len(spline
.points
)):#{
4200 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4201 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4206 if i
== 0: previous
= -1
4207 if i
== len(spline
.points
)-1: proxima
= -1
4209 subsections
.append((spline_count
,previous
,proxima
))
4218 graph_keys
= list(graph
)
4219 for i
in range(len(graph_keys
)-1):#{
4220 for j
in range(i
+1, len(graph_keys
)):#{
4221 if i
%2==0 and i
+1==j
: continue
4225 pi
= route_points
[ni
]
4226 pj
= route_points
[nj
]
4228 dist
= round((pj
-pi
).magnitude
,2)
4231 graph
[ni
][nj
] = dist
4232 graph
[nj
][ni
] = dist
4237 # add and link gates( by name )
4238 for gate
in gates
:#{
4239 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4240 if gate
.SR_data
.ent_gate
[0].target
:
4243 graph
[ gate
.name
] = {}
4245 for i
in range(len(graph_keys
)):#{
4247 pi
= route_points
[ni
]
4249 v0
= pi
-gate
.location
4250 if v0
.dot(v1
) < 0.0: continue
4252 dist
= round(v0
.magnitude
,2)
4255 graph
[ gate
.name
][ ni
] = dist
4256 graph
[ ni
][ gate
.name
] = dist
4261 return dij_graph(route_points
,graph
,subsections
)
4264 def solve_graph( dij
, start
, end
):
4266 path
= dijkstra( dij
.graph
, end
, start
)
4270 for sj
in range(1,len(path
)-2):#{
4273 map0
= dij
.subsections
[i0
]
4274 map1
= dij
.subsections
[i1
]
4276 if map0
[0] == map1
[0]:#{
4277 if map0
[1] == -1: direction
= 2
4282 map0
= dij
.subsections
[i0
]
4283 i1
= map0
[direction
]
4297 full
.append( path
[-2] )
4302 def cv_draw_route( route
, dij
):
4304 pole
= Vector((0.2,0.2,10))
4305 hat
= Vector((1,8,0.2))
4306 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4307 route
.SR_data
.ent_route
[0].colour
[1],
4308 route
.SR_data
.ent_route
[0].colour
[2])
4310 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4311 Vector((0,-6.5,5.5)))
4312 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4313 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4314 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4315 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4317 checkpoints
= route
.SR_data
.ent_route
[0].gates
4319 for i
in range(len(checkpoints
)):#{
4320 gi
= checkpoints
[i
].target
4321 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4324 dest
= gi
.SR_data
.ent_gate
[0].target
4326 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4330 if gi
==gj
: continue # error?
4331 if not gi
or not gj
: continue
4333 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4336 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4337 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4338 for j
in range(len(path
)-1):#{
4341 o0
= dij
.points
[ i0
]
4342 o1
= dij
.points
[ i1
]
4343 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4347 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4353 global cv_view_shader
4354 global cv_view_verts
4355 global cv_view_colours
4356 global cv_view_course_i
4358 cv_view_course_i
= 0
4360 cv_view_colours
= []
4362 cv_view_shader
.bind()
4363 gpu
.state
.depth_mask_set(True)
4364 gpu
.state
.line_width_set(2.0)
4365 gpu
.state
.face_culling_set('BACK')
4366 gpu
.state
.depth_test_set('LESS')
4367 gpu
.state
.blend_set('NONE')
4373 for obj
in bpy
.context
.collection
.objects
:#{
4374 if obj
.type == 'ARMATURE':#{
4375 if obj
.data
.pose_position
== 'REST':
4376 draw_skeleton_helpers( obj
)
4379 ent_type
= obj_ent_type( obj
)
4381 if ent_type
== 'ent_gate':#{
4383 route_gates
+= [obj
]
4385 elif ent_type
== 'ent_route_node':#{
4386 if obj
.type == 'CURVE':#{
4387 route_curves
+= [obj
]
4390 elif ent_type
== 'ent_route':
4392 elif ent_type
== 'ent_volume':#{
4393 cv_ent_volume( obj
)
4395 elif ent_type
== 'ent_objective':#{
4396 data
= obj
.SR_data
.ent_objective
[0]
4398 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4401 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4403 elif ent_type
== 'ent_relay':#{
4404 data
= obj
.SR_data
.ent_relay
[0]
4406 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4408 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4410 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4412 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4414 elif ent_type
== 'ent_challenge':#{
4415 data
= obj
.SR_data
.ent_challenge
[0]
4417 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4419 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4421 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4424 info_cu
= Vector((1.2,0.01,0.72))*0.5
4425 info_co
= Vector((0.0,0.0,0.72))*0.5
4426 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4428 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4430 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4431 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4432 Vector(( 0.1,0.0,0.30))]
4433 for v
in range(len(vs
)):#{
4434 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4437 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4438 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4440 elif ent_type
== 'ent_audio':#{
4441 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4442 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4444 elif ent_type
== 'ent_font':#{
4445 data
= obj
.SR_data
.ent_font
[0]
4447 for i
in range(len(data
.variants
)):#{
4448 sub
= data
.variants
[i
].mesh
4449 if not sub
: continue
4451 for ch
in data
.glyphs
:#{
4452 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4453 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4454 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4455 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4456 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4457 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4459 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4462 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4463 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4467 elif ent_type
== 'ent_skateshop':#{
4468 data
= obj
.SR_data
.ent_skateshop
[0]
4469 display
= data
.mark_display
4470 info
= data
.mark_info
4472 if data
.tipo
== '0':#{
4477 rack
= data
.mark_rack
4479 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4480 rack_co
= Vector((0.0,0.0,0.0))
4481 display_cu
= Vector((0.3,1.2,0.1))*0.5
4482 display_co
= Vector((0.0,0.0,0.1))*0.5
4483 info_cu
= Vector((1.2,0.01,0.3))*0.5
4484 info_co
= Vector((0.0,0.0,0.0))*0.5
4486 elif data
.tipo
== '1':#{
4490 display_cu
= Vector((0.4,0.4,2.0))*0.5
4491 display_co
= Vector((0.0,0.0,1.0))*0.5
4492 info_cu
= Vector((1.2,0.01,0.3))*0.5
4493 info_co
= Vector((0.0,0.0,0.0))*0.5
4495 elif data
.tipo
== '2':#{
4499 display_cu
= Vector((1.0,1.0,0.5))*0.5
4500 display_co
= Vector((0.0,0.0,0.5))*0.5
4501 info_cu
= Vector((1.2,0.01,0.3))*0.5
4502 info_co
= Vector((0.0,0.0,0.0))*0.5
4504 elif data
.tipo
== '3':#{
4511 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4513 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4515 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4517 elif ent_type
== 'ent_swspreview':#{
4519 data
= obj
.SR_data
.ent_swspreview
[0]
4520 display
= data
.mark_display
4521 display1
= data
.mark_display1
4522 display_cu
= Vector((0.3,1.2,0.1))*0.5
4523 display_co
= Vector((0.0,0.0,0.1))*0.5
4525 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4527 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4529 elif ent_type
== 'ent_menuitem':#{
4530 for i
,col
in enumerate(obj
.users_collection
):#{
4531 colour32
= hash_djb2( col
.name
)
4532 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4533 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4534 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4536 vs
= [None for _
in range(8)]
4538 for j
in range(8):#{
4539 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4540 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4542 vs
[j
] = obj
.matrix_world
@ v0
4544 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4545 (0,4),(1,5),(2,6),(3,7)]
4549 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4550 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4551 cv_view_colours
+= [cc
,cc
]
4556 data
= obj
.SR_data
.ent_menuitem
[0]
4557 if data
.tipo
== '4':#{
4558 if data
.slider_minloc
and data
.slider_maxloc
:#{
4559 v0
= data
.slider_minloc
.location
4560 v1
= data
.slider_maxloc
.location
4561 cv_draw_line( v0
, v1
, cc
)
4565 colour32
= hash_djb2(obj
.name
)
4566 r
= ((colour32
) & 0xff) / 255.0
4567 g
= ((colour32
>>8 ) & 0xff) / 255.0
4568 b
= ((colour32
>>16) & 0xff) / 255.0
4570 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4575 if data
.tipo
!= '0':#{
4576 if data
.tipo
== '4':#{
4578 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4581 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4586 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4589 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4592 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4595 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4603 dij
= create_node_graph( route_curves
, route_gates
)
4605 #cv_draw_route_map( route_nodes )
4606 for route
in routes
:#{
4607 cv_draw_route( route
, dij
)
4613 def pos3d_to_2d( pos
):#{
4614 return view3d_utils
.location_3d_to_region_2d( \
4615 bpy
.context
.region
, \
4616 bpy
.context
.space_data
.region_3d
, pos
)
4619 def cv_draw_pixel():#{
4620 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4622 blf
.color(0, 1.0,1.0,1.0,0.9)
4623 blf
.enable(0,blf
.SHADOW
)
4624 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4625 for obj
in bpy
.context
.collection
.objects
:#{
4626 ent_type
= obj_ent_type( obj
)
4628 if ent_type
!= 'none':#{
4629 co
= pos3d_to_2d( obj
.location
)
4632 blf
.position(0,co
[0],co
[1],0)
4633 blf
.draw(0,ent_type
)
4638 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4639 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4640 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4642 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4643 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4644 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4645 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4646 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4647 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4648 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4649 SR_OT_COPY_ENTITY_DATA
, \
4650 SR_OBJECT_ENT_VOLUME
, \
4651 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4652 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4653 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4654 SR_OBJECT_ENT_FONT_VARIANT
,
4655 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4656 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4657 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4658 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4659 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4660 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4661 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4663 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4664 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4670 bpy
.utils
.register_class(c
)
4672 bpy
.types
.Scene
.SR_data
= \
4673 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4674 bpy
.types
.Collection
.SR_data
= \
4675 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4677 bpy
.types
.Object
.SR_data
= \
4678 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4679 bpy
.types
.Light
.SR_data
= \
4680 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4681 bpy
.types
.Bone
.SR_data
= \
4682 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4683 bpy
.types
.Mesh
.SR_data
= \
4684 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4685 bpy
.types
.Material
.SR_data
= \
4686 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4688 global cv_view_draw_handler
, cv_view_pixel_handler
4689 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4690 cv_draw
,(),'WINDOW','POST_VIEW')
4691 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4692 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4698 bpy
.utils
.unregister_class(c
)
4700 global cv_view_draw_handler
, cv_view_pixel_handler
4701 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4702 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')
4705 # ---------------------------------------------------------------------------- #
4709 # ---------------------------------------------------------------------------- #
4711 # Transliteration of: #
4712 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
4714 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
4715 # SPDX-License-Identifier: MIT #
4716 # QOI - The "Quite OK Image" format for fast, lossless image compression #
4718 # ---------------------------------------------------------------------------- #
4720 class qoi_rgba_t(Structure
):
4723 _fields_
= [("r",c_uint8
),
4729 QOI_OP_INDEX
= 0x00 # 00xxxxxx
4730 QOI_OP_DIFF
= 0x40 # 01xxxxxx
4731 QOI_OP_LUMA
= 0x80 # 10xxxxxx
4732 QOI_OP_RUN
= 0xc0 # 11xxxxxx
4733 QOI_OP_RGB
= 0xfe # 11111110
4734 QOI_OP_RGBA
= 0xff # 11111111
4736 QOI_MASK_2
= 0xc0 # 11000000
4738 def qoi_colour_hash( c
):
4740 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
4745 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
4750 return bytearray([ (0xff000000 & v
) >> 24, \
4751 (0x00ff0000 & v
) >> 16, \
4752 (0x0000ff00 & v
) >> 8, \
4756 def qoi_encode( img
):
4760 print(F
"{' ':<30}",end
='\r')
4761 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
4763 index
= [ qoi_rgba_t() for _
in range(64) ]
4767 data
.extend( bytearray(c_uint32(0x66696f71)) )
4768 data
.extend( qoi_32bit( img
.size
[0] ) )
4769 data
.extend( qoi_32bit( img
.size
[1] ) )
4770 data
.extend( bytearray(c_uint8(4)) )
4771 data
.extend( bytearray(c_uint8(0)) )
4774 px_prev
= qoi_rgba_t()
4775 px_prev
.r
= c_uint8(0)
4776 px_prev
.g
= c_uint8(0)
4777 px_prev
.b
= c_uint8(0)
4778 px_prev
.a
= c_uint8(255)
4786 px_len
= img
.size
[0] * img
.size
[1]
4787 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
4789 for px_pos
in range( px_len
): #{
4790 idx
= px_pos
* img
.channels
4793 px
.r
= paxels
[idx
+min(0,nc
)]
4794 px
.g
= paxels
[idx
+min(1,nc
)]
4795 px
.b
= paxels
[idx
+min(2,nc
)]
4796 px
.a
= paxels
[idx
+min(3,nc
)]
4798 if qoi_eq( px
, px_prev
): #{
4801 if (run
== 62) or (px_pos
== px_len
-1): #{
4802 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4808 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4812 index_pos
= qoi_colour_hash(px
) % 64
4814 if qoi_eq( index
[index_pos
], px
): #{
4815 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
4818 index
[ index_pos
].r
= px
.r
4819 index
[ index_pos
].g
= px
.g
4820 index
[ index_pos
].b
= px
.b
4821 index
[ index_pos
].a
= px
.a
4823 if px
.a
== px_prev
.a
: #{
4824 vr
= int(px
.r
) - int(px_prev
.r
)
4825 vg
= int(px
.g
) - int(px_prev
.g
)
4826 vb
= int(px
.b
) - int(px_prev
.b
)
4831 if (vr
> -3) and (vr
< 2) and\
4832 (vg
> -3) and (vg
< 2) and\
4833 (vb
> -3) and (vb
< 2):
4835 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
4836 data
.extend( bytearray( c_uint8(op
) ))
4838 elif (vg_r
> -9) and (vg_r
< 8) and\
4839 (vg
> -33) and (vg
< 32 ) and\
4840 (vg_b
> -9) and (vg_b
< 8):
4842 op
= QOI_OP_LUMA |
(vg
+32)
4843 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
4844 data
.extend( bytearray( c_uint8(op
) ) )
4845 data
.extend( bytearray( c_uint8(delta
) ))
4848 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
4849 data
.extend( bytearray( c_uint8(px
.r
) ))
4850 data
.extend( bytearray( c_uint8(px
.g
) ))
4851 data
.extend( bytearray( c_uint8(px
.b
) ))
4855 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
4856 data
.extend( bytearray( c_uint8(px
.r
) ))
4857 data
.extend( bytearray( c_uint8(px
.g
) ))
4858 data
.extend( bytearray( c_uint8(px
.b
) ))
4859 data
.extend( bytearray( c_uint8(px
.a
) ))
4872 data
.extend( bytearray( c_uint8(0) ))
4873 data
.extend( bytearray( c_uint8(1) ))
4874 bytearray_align_to( data
, 16, b
'\x00' )