1 import bpy
, math
, gpu
, os
4 from mathutils
import *
5 from gpu_extras
.batch
import batch_for_shader
6 from bpy_extras
import mesh_utils
9 "name":"Skaterift .mdl exporter",
10 "author": "Harry Godden (hgn)",
17 "category":"Import/Export",
21 ('none', 'None', '', 0 ),
22 ('ent_gate', 'Gate', '', 1 ),
23 ('ent_spawn', 'Spawn Point', '', 2 ),
24 ('ent_route_node', 'Routing Path', '', 3 ),
25 ('ent_route', 'Skate Course', '', 4 ),
26 ('ent_water', 'Water Surface', '', 5 ),
27 ('ent_volume', 'Volume/Trigger', '', 6 ),
28 ('ent_audio', 'Audio', '', 7 ),
29 ('ent_marker', 'Marker', '', 8 ),
30 ('ent_font', 'Font', '', 9 ),
31 ('ent_font_variant', 'Font:Variant', '', 10 ),
32 ('ent_traffic', 'Traffic Model', '', 11 ),
33 ('ent_skateshop', 'Skate Shop', '', 12 ),
34 ('ent_camera', 'Camera', '', 13 ),
35 ('ent_swspreview', 'Workshop Preview', '', 14 ),
36 ('ent_menuitem', 'Menu Item', '', 15 ),
37 ('ent_worldinfo', 'World Info', '', 16 ),
38 ('ent_ccmd', 'CCmd', '', 17 ),
39 ('ent_challenge', 'Challenge', '', 18 )
42 def get_entity_enum_id( alias
):
44 for et
in sr_entity_list
:#{
53 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
54 #{ # the normals and uvs to i16s. Not an
55 _pack_
= 1 # real issue, yet.
56 _fields_
= [("co",c_float
*3),
60 ("weights",c_uint16
*4),
64 class mdl_transform(Structure
):
66 _fields_
= [("co",c_float
*3),
71 class mdl_submesh(Structure
):
73 _fields_
= [("indice_start",c_uint32
),
74 ("indice_count",c_uint32
),
75 ("vertex_start",c_uint32
),
76 ("vertex_count",c_uint32
),
77 ("bbx",(c_float
*3)*2),
78 ("material_id",c_uint16
), # index into the material array
82 class mdl_material(Structure
):
84 _fields_
= [("pstr_name",c_uint32
),
87 ("surface_prop",c_uint32
),
89 ("colour1",c_float
*4),
90 ("tex_diffuse",c_uint32
),
91 ("tex_none0",c_uint32
),
92 ("tex_none1",c_uint32
)]
95 class mdl_bone(Structure
):
97 _fields_
= [("co",c_float
*3),("end",c_float
*3),
99 ("collider",c_uint32
),
100 ("ik_target",c_uint32
),
101 ("ik_pole",c_uint32
),
103 ("pstr_name",c_uint32
),
104 ("hitbox",(c_float
*3)*2),
105 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
109 class mdl_armature(Structure
):
111 _fields_
= [("transform",mdl_transform
),
112 ("bone_start",c_uint32
),
113 ("bone_count",c_uint32
),
114 ("anim_start",c_uint32
),
115 ("anim_count",c_uint32
)]
118 class mdl_animation(Structure
):
120 _fields_
= [("pstr_name",c_uint32
),
123 ("keyframe_start",c_uint32
)]
126 class mdl_mesh(Structure
):
128 _fields_
= [("transform",mdl_transform
),
129 ("submesh_start",c_uint32
),
130 ("submesh_count",c_uint32
),
131 ("pstr_name",c_uint32
),
132 ("entity_id",c_uint32
),
133 ("armature_id",c_uint32
)]
136 class mdl_file(Structure
):
138 _fields_
= [("path",c_uint32
),
139 ("pack_offset",c_uint32
),
140 ("pack_size",c_uint32
)]
143 class mdl_texture(Structure
):
145 _fields_
= [("file",mdl_file
),
149 class mdl_array(Structure
):
151 _fields_
= [("file_offset",c_uint32
),
152 ("item_count",c_uint32
),
153 ("item_size",c_uint32
),
157 class mdl_header(Structure
):
159 _fields_
= [("version",c_uint32
),
160 ("arrays",mdl_array
)]
163 class ent_spawn(Structure
):
165 _fields_
= [("transform",mdl_transform
),
166 ("pstr_name",c_uint32
)]
169 class ent_light(Structure
):
171 _fields_
= [("transform",mdl_transform
),
172 ("daytime",c_uint32
),
174 ("colour",c_float
*4),
177 ("inverse_world",(c_float
*3)*4), # Runtime
178 ("angle_sin_cos",(c_float
*2))] # Runtime
181 class version_refcount_union(Union
):
183 _fields_
= [("timing_version",c_uint32
),
184 ("ref_count",c_uint8
)]
187 class ent_gate(Structure
):
189 _fields_
= [("type",c_uint32
),
190 ("target", c_uint32
),
192 ("dimensions", c_float
*3),
193 ("co", (c_float
*3)*2),
194 ("q", (c_float
*4)*2),
195 ("to_world",(c_float
*3)*4),
196 ("transport",(c_float
*3)*4),
197 ("_anonymous_union",version_refcount_union
),
198 ("timing_time",c_double
),
199 ("routes",c_uint16
*4),
200 ("route_count",c_uint8
)]
203 class ent_route_node(Structure
):
205 _fields_
= [("co",c_float
*3),
206 ("ref_count",c_uint8
),
207 ("ref_total",c_uint8
)]
210 class ent_path_index(Structure
):
212 _fields_
= [("index",c_uint16
)]
215 class vg_audio_clip(Structure
):
217 _fields_
= [("path",c_uint64
),
223 class union_file_audio_clip(Union
):
225 _fields_
= [("file",mdl_file
),
226 ("reserved",vg_audio_clip
)]
229 class ent_audio_clip(Structure
):
231 _fields_
= [("_anon",union_file_audio_clip
),
232 ("probability",c_float
)]
235 class ent_checkpoint(Structure
):
237 _fields_
= [("gate_index",c_uint16
),
238 ("path_start",c_uint16
),
239 ("path_count",c_uint16
)]
242 class ent_route(Structure
):
244 _fields_
= [("transform",mdl_transform
),
245 ("pstr_name",c_uint32
),
246 ("checkpoints_start",c_uint16
),
247 ("checkpoints_count",c_uint16
),
248 ("colour",c_float
*4),
249 ("active",c_uint32
), #runtime
251 ("board_transform",(c_float
*3)*4),
253 ("latest_pass",c_double
)]
256 class ent_water(Structure
):
258 _fields_
= [("transform",mdl_transform
),
259 ("max_dist",c_float
),
260 ("reserved0",c_uint32
),
261 ("reserved1",c_uint32
)]
264 class volume_trigger(Structure
):
266 _fields_
= [("event",c_uint32
),
270 class volume_particles(Structure
):
272 _fields_
= [("blank",c_uint32
),
276 class volume_union(Union
):
278 _fields_
= [("trigger",volume_trigger
),
279 ("particles",volume_particles
)]
282 class ent_volume(Structure
):
284 _fields_
= [("transform",mdl_transform
),
285 ("to_world",(c_float
*3)*4),
286 ("to_local",(c_float
*3)*4),
289 ("_anon",volume_union
)]
292 class ent_audio(Structure
):
294 _fields_
= [("transform",mdl_transform
),
296 ("clip_start",c_uint32
),
297 ("clip_count",c_uint32
),
299 ("crossfade",c_float
),
300 ("channel_behaviour",c_uint32
),
302 ("probability_curve",c_uint32
),
303 ("max_channels",c_uint32
)]
306 class ent_marker(Structure
):
308 _fields_
= [("transform",mdl_transform
),
312 class ent_glyph(Structure
):
314 _fields_
= [("size",c_float
*2),
315 ("indice_start",c_uint32
),
316 ("indice_count",c_uint32
)]
319 class ent_font_variant(Structure
):
321 _fields_
= [("name",c_uint32
),
322 ("material_id",c_uint32
)]
325 class ent_font(Structure
):
327 _fields_
= [("alias",c_uint32
),
328 ("variant_start",c_uint32
),
329 ("variant_count",c_uint32
),
330 ("glyph_start",c_uint32
),
331 ("glyph_count",c_uint32
),
332 ("glyph_utf32_base",c_uint32
)]
335 class ent_traffic(Structure
):
337 _fields_
= [("transform",mdl_transform
),
338 ("submesh_start",c_uint32
),
339 ("submesh_count",c_uint32
),
340 ("start_node",c_uint32
),
341 ("node_count",c_uint32
),
348 # ---------------------------------------------------------------
349 class ent_skateshop_characters(Structure
):
351 _fields_
= [("id_display",c_uint32
),
352 ("id_info",c_uint32
)]
354 class ent_skateshop_boards(Structure
):
356 _fields_
= [("id_display",c_uint32
),
357 ("id_info",c_uint32
),
358 ("id_rack",c_uint32
)]
360 class ent_skateshop_worlds(Structure
):
362 _fields_
= [("id_display",c_uint32
),
363 ("id_info",c_uint32
)]
365 class ent_skateshop_anon_union(Union
):
367 _fields_
= [("boards",ent_skateshop_boards
),
368 ("character",ent_skateshop_characters
),
369 ("worlds",ent_skateshop_worlds
)]
371 class ent_skateshop(Structure
):
373 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
374 ("id_camera",c_uint32
),
375 ("_anonymous_union",ent_skateshop_anon_union
)]
378 class ent_swspreview(Structure
):
380 _fields_
= [("id_camera",c_uint32
),
381 ("id_display",c_uint32
),
382 ("id_display1",c_uint32
)]
386 # -----------------------------------------------------------------
387 class ent_menuitem_slider(Structure
):
389 _fields_
= [("id_min",c_uint32
),
391 ("id_handle",c_uint32
),
392 ("pstr_data",c_uint32
)]
394 class ent_menuitem_button(Structure
):
396 _fields_
= [("pstr",c_uint32
)]
398 class ent_menuitem_checkmark(Structure
):
400 _fields_
= [("id_check",c_uint32
),
401 ("pstr_data",c_uint32
),
402 ("offset",c_float
*3)]
404 class ent_menuitem_page(Structure
):
406 _fields_
= [("pstr_name",c_uint32
),
407 ("id_entrypoint",c_uint32
),
408 ("id_viewpoint",c_uint32
)]
410 class ent_menuitem_anon_union(Union
):
412 _fields_
= [("slider",ent_menuitem_slider
),
413 ("button",ent_menuitem_button
),
414 ("checkmark",ent_menuitem_checkmark
),
415 ("page",ent_menuitem_page
)]
417 class ent_menuitem(Structure
):
419 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
420 ("id_links",c_uint32
*4),
421 ("factive",c_float
), ("fvisible",c_float
),
422 #-- TODO: Refactor this into a simple mesh structure
423 ("transform",mdl_transform
),
424 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
427 ("_anonymous_union", ent_menuitem_anon_union
)]
430 class ent_camera(Structure
):
432 _fields_
= [("transform",mdl_transform
),
436 class ent_worldinfo(Structure
):
438 _fields_
= [("pstr_name",c_uint32
),
439 ("pstr_author",c_uint32
), # unused
440 ("pstr_desc",c_uint32
), # unused
441 ("timezone",c_float
)]
444 class ent_ccmd(Structure
):
446 _fields_
= [("pstr_command",c_uint32
)]
449 class ent_challenge(Structure
):#{
450 _fields_
= [("transform",mdl_transform
),
451 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
452 ("id_next",c_uint32
),
454 ("time_limit",c_float
)]
456 sr_functions
= { 0: 'trigger',
457 1: 'start_challenge' }
460 def obj_ent_type( obj
):
462 if obj
.type == 'ARMATURE': return 'mdl_armature'
463 elif obj
.type == 'LIGHT': return 'ent_light'
464 elif obj
.type == 'CAMERA': return 'ent_camera'
465 else: return obj
.SR_data
.ent_type
468 def sr_filter_ent_type( obj
, ent_types
):
470 if obj
== bpy
.context
.active_object
: return False
472 for c0
in obj
.users_collection
:#{
473 for c1
in bpy
.context
.active_object
.users_collection
:#{
475 return obj_ent_type( obj
) in ent_types
483 def v4_dot( a
, b
):#{
484 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
487 def q_identity( q
):#{
494 def q_normalize( q
):#{
496 if( l2
< 0.00001 ):#{
500 s
= 1.0/math
.sqrt(l2
)
508 def compile_obj_transform( obj
, transform
):
510 co
= obj
.matrix_world
@ Vector((0,0,0))
512 # This was changed from matrix_local on 09.05.23
513 q
= obj
.matrix_world
.to_quaternion()
519 transform
.co
[0] = co
[0]
520 transform
.co
[1] = co
[2]
521 transform
.co
[2] = -co
[1]
522 transform
.q
[0] = q
[1]
523 transform
.q
[1] = q
[3]
524 transform
.q
[2] = -q
[2]
525 transform
.q
[3] = q
[0]
526 transform
.s
[0] = s
[0]
527 transform
.s
[1] = s
[2]
528 transform
.s
[2] = s
[1]
531 def int_align_to( v
, align
):
533 while(v
%align
)!=0: v
+= 1
537 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
539 while (len(buffer) % align
) != 0: buffer.extend(w
)
543 def bytearray_print_hex( s
, w
=16 ):
545 for r
in range((len(s
)+(w
-1))//w
):#{
547 i1
=min((r
+1)*w
,len(s
))
548 print( F
'{r*w:06x}| \x1B[31m', end
='')
549 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
550 print( "\x1B[0m", end
='')
551 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
555 def sr_compile_string( s
):
557 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
559 index
= len( sr_compile
.string_data
)
560 sr_compile
.string_cache
[s
] = index
561 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
562 sr_compile
.string_data
.extend( s
.encode('utf-8') )
563 sr_compile
.string_data
.extend( b
'\0' )
565 bytearray_align_to( sr_compile
.string_data
, 4 )
569 def material_tex_image(v
):
579 cxr_graph_mapping
= \
581 # Default shader setup
588 "image": "tex_diffuse"
592 "A": material_tex_image("tex_diffuse"),
593 "B": material_tex_image("tex_decal")
600 "Color": material_tex_image("tex_normal")
606 "Color": material_tex_image("tex_diffuse")
610 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
612 def material_info(mat
):
616 # Using the cxr_graph_mapping as a reference, go through the shader
617 # graph and gather all $props from it.
619 def _graph_read( node_def
, node
=None, depth
=0 ):#{
626 _graph_read
.extracted
= []
628 for node_idname
in node_def
:#{
629 for n
in mat
.node_tree
.nodes
:#{
630 if n
.name
== node_idname
:#{
631 node_def
= node_def
[node_idname
]
639 for link
in node_def
:#{
640 link_def
= node_def
[link
]
642 if isinstance( link_def
, dict ):#{
644 for x
in node
.inputs
:#{
645 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
653 if node_link
and node_link
.is_linked
:#{
654 # look for definitions for the connected node type
656 from_node
= node_link
.links
[0].from_node
658 node_name
= from_node
.name
.split('.')[0]
659 if node_name
in link_def
:#{
660 from_node_def
= link_def
[ node_name
]
662 _graph_read( from_node_def
, from_node
, depth
+1 )
666 if "default" in link_def
:#{
667 prop
= link_def
['default']
668 info
[prop
] = node_link
.default_value
674 info
[prop
] = getattr( node
, link
)
679 _graph_read( cxr_graph_mapping
)
685 decoded
= bytearray()
686 for i
in range(len(s
)//2):#{
687 c
= (ord(s
[i
*2+0])-0x41)
688 c |
= (ord(s
[i
*2+1])-0x41)<<4
689 decoded
.extend(bytearray(c_uint8(c
))) #??
694 def sr_pack_file( file, path
, data
):
696 file.path
= sr_compile_string( path
)
697 file.pack_offset
= len( sr_compile
.pack_data
)
698 file.pack_size
= len( data
)
700 sr_compile
.pack_data
.extend( data
)
701 bytearray_align_to( sr_compile
.pack_data
, 16 )
704 def sr_compile_texture( img
):
709 name
= os
.path
.splitext( img
.name
)[0]
711 if name
in sr_compile
.texture_cache
:
712 return sr_compile
.texture_cache
[name
]
714 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
719 if sr_compile
.pack_textures
:#{
720 filedata
= qoi_encode( img
)
721 sr_pack_file( tex
.file, name
, filedata
)
724 sr_compile
.texture_cache
[name
] = texture_index
725 sr_compile
.texture_data
.extend( bytearray(tex
) )
729 def sr_compile_material( mat
):
733 if mat
.name
in sr_compile
.material_cache
:
734 return sr_compile
.material_cache
[mat
.name
]
736 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
737 sr_compile
.material_cache
[mat
.name
] = index
740 m
.pstr_name
= sr_compile_string( mat
.name
)
743 if mat
.SR_data
.collision
:#{
744 flags |
= 0x2 # collision flag
745 if (mat
.SR_data
.shader
!= 'invisible') and \
746 (mat
.SR_data
.shader
!= 'boundary'):#{
747 if mat
.SR_data
.skate_surface
: flags |
= 0x1
748 if mat
.SR_data
.grow_grass
: flags |
= 0x4
749 if mat
.SR_data
.grind_surface
: flags |
= 0x8
750 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
752 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
753 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
758 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
760 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
761 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
762 if mat
.SR_data
.shader
== 'terrain_blend':#{
765 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
766 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
767 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
770 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
771 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
774 if mat
.SR_data
.shader
== 'vertex_blend':#{
777 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
778 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
781 if mat
.SR_data
.shader
== 'water':#{
784 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
785 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
786 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
788 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
789 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
790 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
794 if mat
.SR_data
.shader
== 'invisible':#{
798 if mat
.SR_data
.shader
== 'boundary':#{
802 if mat
.SR_data
.shader
== 'fxglow':#{
806 inf
= material_info( mat
)
808 if mat
.SR_data
.shader
== 'standard' or \
809 mat
.SR_data
.shader
== 'standard_cutout' or \
810 mat
.SR_data
.shader
== 'terrain_blend' or \
811 mat
.SR_data
.shader
== 'vertex_blend' or \
812 mat
.SR_data
.shader
== 'fxglow': #{
813 if 'tex_diffuse' in inf
:
814 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
817 sr_compile
.material_data
.extend( bytearray(m
) )
821 def sr_armature_bones( armature
):
823 def _recurse_bone( b
):
826 for c
in b
.children
: yield from _recurse_bone( c
)
829 for b
in armature
.data
.bones
:
831 yield from _recurse_bone( b
)
834 def sr_entity_id( obj
):#{
837 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
838 index
= sr_compile
.entity_ids
[ obj
.name
]
840 return (tipo
&0xffff)<<16 |
(index
&0xffff)
843 # Returns submesh_start,count and armature_id
844 def sr_compile_mesh_internal( obj
):
853 for mod
in obj
.modifiers
:#{
854 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
855 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
858 can_use_cache
= False
861 if mod
.type == 'ARMATURE': #{
862 armature
= mod
.object
863 rig_weight_groups
= \
864 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
865 armature_id
= sr_compile
.entity_ids
[armature
.name
]
867 POSE_OR_REST_CACHE
= armature
.data
.pose_position
868 armature
.data
.pose_position
= 'REST'
872 # Check the cache first
874 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
875 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
876 submesh_start
= ref
[0]
877 submesh_count
= ref
[1]
878 return (submesh_start
,submesh_count
,armature_id
)
881 # Compile a whole new mesh
883 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
886 dgraph
= bpy
.context
.evaluated_depsgraph_get()
887 data
= obj
.evaluated_get(dgraph
).data
888 data
.calc_loop_triangles()
889 data
.calc_normals_split()
891 # Mesh is split into submeshes based on their material
893 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
894 for material_id
, mat
in enumerate(mat_list
): #{
898 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
899 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
902 sm
.material_id
= sr_compile_material( mat
)
904 INF
=99999999.99999999
910 # Keep a reference to very very very similar vertices
911 # i have no idea how to speed it up.
913 vertex_reference
= {}
915 # Write the vertex / indice data
917 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
918 if tri
.material_index
!= material_id
: continue
921 vert
= data
.vertices
[tri
.vertices
[j
]]
923 vi
= data
.loops
[li
].vertex_index
925 # Gather vertex information
928 norm
= data
.loops
[li
].normal
930 colour
= (255,255,255,255)
937 uv
= data
.uv_layers
.active
.data
[li
].uv
941 if data
.vertex_colors
:#{
942 colour
= data
.vertex_colors
.active
.data
[li
].color
943 colour
= (int(colour
[0]*255.0),\
944 int(colour
[1]*255.0),\
945 int(colour
[2]*255.0),\
946 int(colour
[3]*255.0))
949 # Weight groups: truncates to the 3 with the most influence. The
950 # fourth bone ID is never used by the shader so it
954 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
955 if obj
.vertex_groups
[_
.group
].name
in \
958 weight_groups
= sorted( src_groups
, key
= \
959 lambda a
: a
.weight
, reverse
=True )
961 for ml
in range(3):#{
962 if len(weight_groups
) > ml
:#{
963 g
= weight_groups
[ml
]
964 name
= obj
.vertex_groups
[g
.group
].name
967 groups
[ml
] = rig_weight_groups
.index(name
)
972 if len(weight_groups
) > 0:#{
973 inv_norm
= (1.0/tot
) * 65535.0
974 for ml
in range(3):#{
975 weights
[ml
] = int( weights
[ml
] * inv_norm
)
976 weights
[ml
] = min( weights
[ml
], 65535 )
977 weights
[ml
] = max( weights
[ml
], 0 )
982 li1
= tri
.loops
[(j
+1)%3]
983 vi1
= data
.loops
[li1
].vertex_index
984 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
986 if e0
.use_freestyle_mark
and \
987 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
988 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
994 TOLERENCE
= float(10**4)
995 key
= (int(co
[0]*TOLERENCE
+0.5),
996 int(co
[1]*TOLERENCE
+0.5),
997 int(co
[2]*TOLERENCE
+0.5),
998 int(norm
[0]*TOLERENCE
+0.5),
999 int(norm
[1]*TOLERENCE
+0.5),
1000 int(norm
[2]*TOLERENCE
+0.5),
1001 int(uv
[0]*TOLERENCE
+0.5),
1002 int(uv
[1]*TOLERENCE
+0.5),
1003 colour
[0], # these guys are already quantized
1016 if key
in vertex_reference
:
1017 index
= vertex_reference
[key
]
1019 index
= bytearray(c_uint32(sm
.vertex_count
))
1022 vertex_reference
[key
] = index
1029 v
.norm
[2] = -norm
[1]
1032 v
.colour
[0] = colour
[0]
1033 v
.colour
[1] = colour
[1]
1034 v
.colour
[2] = colour
[2]
1035 v
.colour
[3] = colour
[3]
1036 v
.weights
[0] = weights
[0]
1037 v
.weights
[1] = weights
[1]
1038 v
.weights
[2] = weights
[2]
1039 v
.weights
[3] = weights
[3]
1040 v
.groups
[0] = groups
[0]
1041 v
.groups
[1] = groups
[1]
1042 v
.groups
[2] = groups
[2]
1043 v
.groups
[3] = groups
[3]
1045 for i
in range(3):#{
1046 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1047 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1050 sr_compile
.vertex_data
.extend(bytearray(v
))
1053 sm
.indice_count
+= 1
1054 sr_compile
.indice_data
.extend( index
)
1058 # Make sure bounding box isn't -inf -> inf if no vertices
1060 if sm
.vertex_count
== 0:
1065 # Add submesh to encoder
1067 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1072 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1075 # Save a reference to this mesh since we want to reuse the submesh indices
1077 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1078 return (submesh_start
,submesh_count
,armature_id
)
1081 def sr_compile_mesh( obj
):
1084 compile_obj_transform(obj
, node
.transform
)
1085 node
.pstr_name
= sr_compile_string(obj
.name
)
1086 ent_type
= obj_ent_type( obj
)
1090 if ent_type
!= 'none':#{
1091 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1092 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1093 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1096 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1097 sr_compile_mesh_internal( obj
)
1099 sr_compile
.mesh_data
.extend(bytearray(node
))
1102 def sr_compile_fonts( collection
):
1104 print( F
"[SR] Compiling fonts" )
1109 for obj
in collection
.all_objects
:#{
1110 if obj_ent_type(obj
) != 'ent_font': continue
1112 data
= obj
.SR_data
.ent_font
[0]
1115 font
.alias
= sr_compile_string( data
.alias
)
1116 font
.variant_start
= variant_count
1117 font
.variant_count
= 0
1118 font
.glyph_start
= glyph_count
1120 glyph_base
= data
.glyphs
[0].utf32
1121 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1123 font
.glyph_utf32_base
= glyph_base
1124 font
.glyph_count
= glyph_range
1126 for i
in range(len(data
.variants
)):#{
1127 data_var
= data
.variants
[i
]
1128 if not data_var
.mesh
: continue
1130 mesh
= data_var
.mesh
.data
1132 variant
= ent_font_variant()
1133 variant
.name
= sr_compile_string( data_var
.tipo
)
1135 # fonts (variants) only support one material each
1137 if len(mesh
.materials
) != 0:
1138 mat
= mesh
.materials
[0]
1139 variant
.material_id
= sr_compile_material( mat
)
1141 font
.variant_count
+= 1
1143 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1144 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1146 for j
in range(len(islands
)):#{
1147 for tri
in islands
[j
]:#{
1148 centroids
[j
].x
+= tri
.center
[0]
1149 centroids
[j
].y
+= tri
.center
[2]
1152 centroids
[j
] /= len(islands
[j
])
1155 for j
in range(glyph_range
):#{
1156 data_glyph
= data
.glyphs
[j
]
1158 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1159 glyph
.indice_count
= 0
1160 glyph
.size
[0] = data_glyph
.bounds
[2]
1161 glyph
.size
[1] = data_glyph
.bounds
[3]
1163 vertex_reference
= {}
1165 for k
in range(len(islands
)):#{
1166 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1167 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1168 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1169 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1174 for l
in range(len(islands
[k
])):#{
1176 for m
in range(3):#{
1177 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1179 vi
= mesh
.loops
[li
].vertex_index
1181 # Gather vertex information
1183 co
= [vert
.co
[_
] for _
in range(3)]
1184 co
[0] -= data_glyph
.bounds
[0]
1185 co
[2] -= data_glyph
.bounds
[1]
1186 norm
= mesh
.loops
[li
].normal
1188 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1190 TOLERENCE
= float(10**4)
1191 key
= (int(co
[0]*TOLERENCE
+0.5),
1192 int(co
[1]*TOLERENCE
+0.5),
1193 int(co
[2]*TOLERENCE
+0.5),
1194 int(norm
[0]*TOLERENCE
+0.5),
1195 int(norm
[1]*TOLERENCE
+0.5),
1196 int(norm
[2]*TOLERENCE
+0.5),
1197 int(uv
[0]*TOLERENCE
+0.5),
1198 int(uv
[1]*TOLERENCE
+0.5))
1200 if key
in vertex_reference
:
1201 index
= vertex_reference
[key
]
1203 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1204 index
= bytearray(c_uint32(vindex
))
1205 vertex_reference
[key
] = index
1212 v
.norm
[2] = -norm
[1]
1216 sr_compile
.vertex_data
.extend(bytearray(v
))
1219 glyph
.indice_count
+= 1
1220 sr_compile
.indice_data
.extend( index
)
1224 sr_ent_push( glyph
)
1226 sr_ent_push( variant
)
1232 def sr_compile_menus( collection
):
1234 print( "[SR1] Compiling menus" )
1237 for obj
in collection
.all_objects
:#{
1238 if obj_ent_type(obj
) != 'ent_menuitem': continue
1239 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1241 bitmask
= 0x00000000
1243 for col
in obj
.users_collection
:#{
1245 if name
not in groups
: groups
.append( name
)
1246 bitmask |
= (0x1 << groups
.index(name
))
1249 item
= ent_menuitem()
1250 item
.type = int( obj_data
.tipo
)
1251 item
.groups
= bitmask
1253 compile_obj_transform( obj
, item
.transform
)
1254 if obj
.type == 'MESH':#{
1255 item
.submesh_start
, item
.submesh_count
, _
= \
1256 sr_compile_mesh_internal( obj
)
1259 if item
.type == 1 or item
.type == 2:#{
1260 item_button
= item
._anonymous
_union
.button
1261 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1263 elif item
.type == 3:#{
1264 item_checkmark
= item
._anonymous
_union
.checkmark
1265 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1266 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1267 delta
= obj_data
.checkmark
.location
- obj
.location
1268 item_checkmark
.offset
[0] = delta
[0]
1269 item_checkmark
.offset
[1] = delta
[2]
1270 item_checkmark
.offset
[2] = -delta
[1]
1272 elif item
.type == 4:#{
1273 item_slider
= item
._anonymous
_union
.slider
1274 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1275 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1276 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1277 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1279 elif item
.type == 5:#{
1280 item_page
= item
._anonymous
_union
.page
1281 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1282 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1283 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1287 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1289 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1290 if item
.type != 4:#{
1292 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1294 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1301 def sr_compile_armature( obj
):
1303 node
= mdl_armature()
1304 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1306 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1309 bones
= [_
for _
in sr_armature_bones(obj
)]
1310 bones_names
= [None]+[_
.name
for _
in bones
]
1314 if b
.use_deform
: bone
.flags
= 0x1
1315 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1317 bone
.collider
= int(b
.SR_data
.collider
)
1319 if bone
.collider
>0:#{
1320 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1321 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1322 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1323 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1324 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1325 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1328 if b
.SR_data
.cone_constraint
:#{
1330 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1331 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1332 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1333 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1334 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1335 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1336 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1337 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1338 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1339 bone
.conet
= b
.SR_data
.conet
1342 bone
.co
[0] = b
.head_local
[0]
1343 bone
.co
[1] = b
.head_local
[2]
1344 bone
.co
[2] = -b
.head_local
[1]
1345 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1346 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1347 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1348 bone
.pstr_name
= sr_compile_string( b
.name
)
1350 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1351 if c
.type == 'IK':#{
1353 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1354 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1358 node
.bone_count
+= 1
1359 sr_compile
.bone_data
.extend(bytearray(bone
))
1364 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1365 # So we can restore later
1367 previous_frame
= bpy
.context
.scene
.frame_current
1368 previous_action
= obj
.animation_data
.action
1369 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1370 obj
.data
.pose_position
= 'POSE'
1372 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1373 for NLAStrip
in NLALayer
.strips
:#{
1376 for a
in bpy
.data
.actions
:#{
1377 if a
.name
== NLAStrip
.name
:#{
1378 obj
.animation_data
.action
= a
1383 # Clip to NLA settings
1385 anim_start
= int(NLAStrip
.action_frame_start
)
1386 anim_end
= int(NLAStrip
.action_frame_end
)
1390 anim
= mdl_animation()
1391 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1393 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1394 sizeof(mdl_transform
)
1395 anim
.length
= anim_end
-anim_start
1398 # Export the keyframes
1399 for frame
in range(anim_start
,anim_end
):#{
1400 bpy
.context
.scene
.frame_set(frame
)
1403 pb
= obj
.pose
.bones
[rb
.name
]
1405 # relative bone matrix
1406 if rb
.parent
is not None:#{
1407 offset_mtx
= rb
.parent
.matrix_local
1408 offset_mtx
= offset_mtx
.inverted_safe() @ \
1411 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1412 inv_parent
.invert_safe()
1413 fpm
= inv_parent
@ pb
.matrix
1416 bone_mtx
= rb
.matrix
.to_4x4()
1417 local_inv
= rb
.matrix_local
.inverted_safe()
1418 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1421 loc
, rot
, sca
= fpm
.decompose()
1424 lc_m
= pb
.matrix_channel
.to_3x3()
1425 if pb
.parent
is not None:#{
1426 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1427 lc_m
= smtx
.inverted() @ lc_m
1429 rq
= lc_m
.to_quaternion()
1432 kf
= mdl_transform()
1443 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1449 # Add to animation buffer
1451 sr_compile
.anim_data
.extend(bytearray(anim
))
1452 node
.anim_count
+= 1
1456 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1460 # Restore context to how it was before
1462 bpy
.context
.scene
.frame_set( previous_frame
)
1463 obj
.animation_data
.action
= previous_action
1464 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1467 sr_compile
.armature_data
.extend(bytearray(node
))
1470 def sr_ent_push( struct
):
1472 clase
= type(struct
).__name
__
1474 if clase
not in sr_compile
.entity_data
:#{
1475 sr_compile
.entity_data
[ clase
] = bytearray()
1476 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1479 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1480 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1484 def sr_array_title( arr
, name
, count
, size
, offset
):
1486 for i
in range(len(name
)):#{
1487 arr
.name
[i
] = ord(name
[i
])
1489 arr
.file_offset
= offset
1490 arr
.item_count
= count
1491 arr
.item_size
= size
1498 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1503 def sr_compile( collection
):
1505 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1508 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1509 sr_compile
.pack_animations
= collection
.SR_data
.animations
1512 sr_compile
.string_cache
= {}
1513 sr_compile
.mesh_cache
= {}
1514 sr_compile
.material_cache
= {}
1515 sr_compile
.texture_cache
= {}
1518 sr_compile
.mesh_data
= bytearray()
1519 sr_compile
.submesh_data
= bytearray()
1520 sr_compile
.vertex_data
= bytearray()
1521 sr_compile
.indice_data
= bytearray()
1522 sr_compile
.bone_data
= bytearray()
1523 sr_compile
.material_data
= bytearray()
1524 sr_compile
.armature_data
= bytearray()
1525 sr_compile
.anim_data
= bytearray()
1526 sr_compile
.keyframe_data
= bytearray()
1527 sr_compile
.texture_data
= bytearray()
1529 # just bytes not structures
1530 sr_compile
.string_data
= bytearray()
1531 sr_compile
.pack_data
= bytearray()
1534 sr_compile
.entity_data
= {}
1535 sr_compile
.entity_info
= {}
1537 print( F
"[SR] assign entity ID's" )
1538 sr_compile
.entities
= {}
1539 sr_compile
.entity_ids
= {}
1542 # -------------------------------------------------------
1544 sr_compile_string( "null" )
1547 for obj
in collection
.all_objects
: #{
1548 if obj
.type == 'MESH':#{
1552 ent_type
= obj_ent_type( obj
)
1553 if ent_type
== 'none': continue
1555 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1556 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1557 sr_compile
.entities
[ent_type
] += [obj
]
1560 print( F
"[SR] Compiling geometry" )
1562 for obj
in collection
.all_objects
:#{
1563 if obj
.type == 'MESH':#{
1566 ent_type
= obj_ent_type( obj
)
1568 # entity ignore mesh list
1570 if ent_type
== 'ent_traffic': continue
1571 if ent_type
== 'ent_font': continue
1572 if ent_type
== 'ent_font_variant': continue
1573 if ent_type
== 'ent_menuitem': continue
1574 if ent_type
== 'ent_challenge': continue
1575 #--------------------------
1577 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end
='\r' )
1578 sr_compile_mesh( obj
)
1582 audio_clip_count
= 0
1584 for ent_type
, arr
in sr_compile
.entities
.items():#{
1585 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1587 for i
in range(len(arr
)):#{
1590 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1592 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1593 elif ent_type
== 'ent_light': #{
1595 compile_obj_transform( obj
, light
.transform
)
1596 light
.daytime
= obj
.data
.SR_data
.daytime
1597 if obj
.data
.type == 'POINT':#{
1600 elif obj
.data
.type == 'SPOT':#{
1602 light
.angle
= obj
.data
.spot_size
*0.5
1604 light
.range = obj
.data
.cutoff_distance
1605 light
.colour
[0] = obj
.data
.color
[0]
1606 light
.colour
[1] = obj
.data
.color
[1]
1607 light
.colour
[2] = obj
.data
.color
[2]
1608 light
.colour
[3] = obj
.data
.energy
1609 sr_ent_push( light
)
1611 elif ent_type
== 'ent_camera': #{
1613 compile_obj_transform( obj
, cam
.transform
)
1614 cam
.fov
= obj
.data
.angle
* 45.0
1617 elif ent_type
== 'ent_gate': #{
1619 obj_data
= obj
.SR_data
.ent_gate
[0]
1620 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1622 if obj_data
.tipo
== 'default':#{
1623 if obj_data
.target
:#{
1624 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1628 elif obj_data
.tipo
== 'nonlocal':#{
1630 gate
.key
= sr_compile_string(obj_data
.key
)
1635 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1636 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1637 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1639 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1640 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1642 if obj_data
.target
:#{
1643 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1644 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1649 for x
in range(2):#{
1650 gate
.co
[x
][0] = co
[x
][0]
1651 gate
.co
[x
][1] = co
[x
][2]
1652 gate
.co
[x
][2] = -co
[x
][1]
1653 gate
.q
[x
][0] = q
[x
][1]
1654 gate
.q
[x
][1] = q
[x
][3]
1655 gate
.q
[x
][2] = -q
[x
][2]
1656 gate
.q
[x
][3] = q
[x
][0]
1661 elif ent_type
== 'ent_spawn': #{
1663 compile_obj_transform( obj
, spawn
.transform
)
1664 obj_data
= obj
.SR_data
.ent_spawn
[0]
1665 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1666 sr_ent_push( spawn
)
1668 elif ent_type
== 'ent_water':#{
1670 compile_obj_transform( obj
, water
.transform
)
1671 water
.max_dist
= 0.0
1672 sr_ent_push( water
)
1674 elif ent_type
== 'ent_audio':#{
1675 obj_data
= obj
.SR_data
.ent_audio
[0]
1677 compile_obj_transform( obj
, audio
.transform
)
1678 audio
.clip_start
= audio_clip_count
1679 audio
.clip_count
= len(obj_data
.files
)
1680 audio_clip_count
+= audio
.clip_count
1681 audio
.max_channels
= obj_data
.max_channels
1682 audio
.volume
= obj_data
.volume
1685 # - allow/disable doppler
1686 # - channel group tags with random colours
1687 # - transition properties
1689 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1690 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1691 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1692 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1693 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1694 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1695 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1697 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1698 if audio
.channel_behaviour
>= 1:#{
1699 audio
.group
= obj_data
.group
1701 if audio
.channel_behaviour
== 2:#{
1702 audio
.crossfade
= obj_data
.transition_duration
1704 audio
.probability_curve
= int(obj_data
.probability_curve
)
1706 for ci
in range(audio
.clip_count
):#{
1707 entry
= obj_data
.files
[ci
]
1708 clip
= ent_audio_clip()
1709 clip
.probability
= entry
.probability
1710 if obj_data
.formato
== '2':#{
1711 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1714 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1715 clip
._anon
.file.pack_offset
= 0
1716 clip
._anon
.file.pack_size
= 0
1720 sr_ent_push( audio
)
1722 elif ent_type
== 'ent_volume':#{
1723 obj_data
= obj
.SR_data
.ent_volume
[0]
1724 volume
= ent_volume()
1725 volume
.type = int(obj_data
.subtype
)
1726 compile_obj_transform( obj
, volume
.transform
)
1728 if obj_data
.target
:#{
1729 volume
.target
= sr_entity_id( obj_data
.target
)
1730 volume
._anon
.trigger
.event
= obj_data
.event
1735 elif ent_type
== 'ent_marker':#{
1736 marker
= ent_marker()
1737 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1738 compile_obj_transform( obj
, marker
.transform
)
1741 elif ent_type
== 'ent_skateshop':#{
1742 skateshop
= ent_skateshop()
1743 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1744 skateshop
.type = int(obj_data
.tipo
)
1745 if skateshop
.type == 0:#{
1746 boardshop
= skateshop
._anonymous
_union
.boards
1747 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1748 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1749 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1751 elif skateshop
.type == 1:#{
1752 charshop
= skateshop
._anonymous
_union
.character
1753 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1754 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1756 elif skateshop
.type == 2:#{
1757 worldshop
= skateshop
._anonymous
_union
.worlds
1758 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1759 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1761 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1762 compile_obj_transform( obj
, skateshop
.transform
)
1763 sr_ent_push(skateshop
)
1765 elif ent_type
== 'ent_swspreview':#{
1766 workshop_preview
= ent_swspreview()
1767 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1768 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1769 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1770 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1771 sr_ent_push( workshop_preview
)
1773 elif ent_type
== 'ent_worldinfo':#{
1774 worldinfo
= ent_worldinfo()
1775 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1776 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1777 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1778 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1779 worldinfo
.timezone
= obj_data
.timezone
1780 sr_ent_push( worldinfo
)
1782 elif ent_type
== 'ent_ccmd':#{
1784 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1785 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1788 elif ent_type
== 'ent_challenge':#{
1789 challenge
= ent_challenge()
1790 obj_data
= obj
.SR_data
.ent_challenge
[0]
1791 challenge
.id_next
= sr_entity_id( obj_data
.proxima
)
1792 challenge
.filter = 0
1793 challenge
.time_limit
= obj_data
.time_limit
1795 compile_obj_transform( obj
, challenge
.transform
)
1796 challenge
.submesh_start
, challenge
.submesh_count
, _
= \
1797 sr_compile_mesh_internal( obj
)
1799 sr_ent_push( challenge
)
1804 sr_compile_menus( collection
)
1805 sr_compile_fonts( collection
)
1807 def _children( col
):#{
1809 for c
in col
.children
:#{
1810 yield from _children(c
)
1814 checkpoint_count
= 0
1815 pathindice_count
= 0
1818 for col
in _children(collection
):#{
1819 print( F
"Adding routes for subcollection: {col.name}" )
1825 for obj
in col
.objects
:#{
1826 if obj
.type == 'ARMATURE': pass
1828 ent_type
= obj_ent_type( obj
)
1830 if ent_type
== 'ent_gate':
1831 route_gates
+= [obj
]
1832 elif ent_type
== 'ent_route_node':#{
1833 if obj
.type == 'CURVE':#{
1834 route_curves
+= [obj
]
1837 elif ent_type
== 'ent_route':
1839 elif ent_type
== 'ent_traffic':
1844 dij
= create_node_graph( route_curves
, route_gates
)
1846 for obj
in routes
:#{
1847 obj_data
= obj
.SR_data
.ent_route
[0]
1849 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1850 route
.checkpoints_start
= checkpoint_count
1851 route
.checkpoints_count
= 0
1854 route
.colour
[ci
] = obj_data
.colour
[ci
]
1855 route
.colour
[3] = 1.0
1857 compile_obj_transform( obj
, route
.transform
)
1858 checkpoints
= obj_data
.gates
1860 for i
in range(len(checkpoints
)):#{
1861 gi
= checkpoints
[i
].target
1862 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1866 dest
= gi
.SR_data
.ent_gate
[0].target
1870 if gi
==gj
: continue # error?
1871 if not gi
or not gj
: continue
1873 checkpoint
= ent_checkpoint()
1874 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1875 checkpoint
.path_start
= pathindice_count
1876 checkpoint
.path_count
= 0
1878 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1881 for pi
in range(len(path
)):#{
1882 pathindice
= ent_path_index()
1883 pathindice
.index
= routenode_count
+ path
[pi
]
1884 sr_ent_push( pathindice
)
1886 checkpoint
.path_count
+= 1
1887 pathindice_count
+= 1
1891 sr_ent_push( checkpoint
)
1892 route
.checkpoints_count
+= 1
1893 checkpoint_count
+= 1
1896 sr_ent_push( route
)
1899 for obj
in traffics
:#{
1900 traffic
= ent_traffic()
1901 compile_obj_transform( obj
, traffic
.transform
)
1902 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
1903 sr_compile_mesh_internal( obj
)
1905 # find best subsection
1907 graph_keys
= list(dij
.graph
)
1911 for j
in range(len(dij
.points
)):#{
1912 point
= dij
.points
[j
]
1913 dist
= (point
-obj
.location
).magnitude
1915 if dist
< min_dist
:#{
1922 best_begin
= best_point
1923 best_end
= best_point
1926 map0
= dij
.subsections
[best_begin
]
1927 if map0
[1] == -1: break
1928 best_begin
= map0
[1]
1931 map1
= dij
.subsections
[best_end
]
1932 if map1
[2] == -1: break
1936 traffic
.start_node
= routenode_count
+ best_begin
1937 traffic
.node_count
= best_end
- best_begin
1938 traffic
.index
= best_point
- best_begin
1939 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
1942 sr_ent_push(traffic
)
1945 for point
in dij
.points
:#{
1946 rn
= ent_route_node()
1949 rn
.co
[2] = -point
[1]
1953 routenode_count
+= len(dij
.points
)
1956 print( F
"[SR] Writing file" )
1958 file_array_instructions
= {}
1961 def _write_array( name
, item_size
, data
):#{
1962 nonlocal file_array_instructions
, file_offset
1964 count
= len(data
)//item_size
1965 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
1966 'data':data
, 'offset': file_offset
}
1967 file_offset
+= len(data
)
1968 file_offset
= int_align_to( file_offset
, 8 )
1971 _write_array( 'strings', 1, sr_compile
.string_data
)
1972 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
1973 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
1974 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
1975 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
1976 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
1977 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
1979 for name
, buffer in sr_compile
.entity_data
.items():#{
1980 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
1983 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
1984 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
1985 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
1986 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
1987 _write_array( 'pack', 1, sr_compile
.pack_data
)
1989 header_size
= int_align_to( sizeof(mdl_header
), 8 )
1990 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
1992 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
1993 path
= F
"{folder}{collection.name}.mdl"
1996 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
1997 fp
= open( path
, "wb" )
1998 header
= mdl_header()
1999 header
.version
= 101
2000 sr_array_title( header
.arrays
, \
2001 'index', len(file_array_instructions
), \
2002 sizeof(mdl_array
), header_size
)
2004 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2006 print( F
'[SR] {"name":>16}| count | offset' )
2008 for name
,info
in file_array_instructions
.items():#{
2010 offset
= info
['offset'] + header_size
+ index_size
2011 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2012 index
.extend( bytearray(arr
) )
2014 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2015 F
' 0x{info["offset"]:02x}' )
2017 fp
.write( bytearray_align_to( index
, 8 ) )
2018 #bytearray_print_hex( index )
2020 for name
,info
in file_array_instructions
.items():#{
2021 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2026 print( '[SR] done' )
2029 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2031 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2032 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2033 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=True )
2035 panel
: bpy
.props
.EnumProperty(
2039 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2040 ('ENTITY', 'Entity', '', 'MONKEY',1),
2041 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2046 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2048 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2049 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2052 def sr_get_mirror_bone( bones
):
2054 side
= bones
.active
.name
[-1:]
2055 other_name
= bones
.active
.name
[:-1]
2056 if side
== 'L': other_name
+= 'R'
2057 elif side
== 'R': other_name
+= 'L'
2061 if b
.name
== other_name
:
2068 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2070 bl_idname
="skaterift.mirror_bone"
2071 bl_label
="Mirror bone attributes - SkateRift"
2073 def execute(_
,context
):
2075 active_object
= context
.active_object
2076 bones
= active_object
.data
.bones
2078 b
= sr_get_mirror_bone( bones
)
2080 if not b
: return {'FINISHED'}
2082 b
.SR_data
.collider
= a
.SR_data
.collider
2084 def _v3copyflipy( a
, b
):#{
2090 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2091 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2092 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2093 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2095 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2097 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2098 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2099 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2101 b
.SR_data
.conet
= a
.SR_data
.conet
2104 ob
= bpy
.context
.scene
.objects
[0]
2105 ob
.hide_render
= ob
.hide_render
2110 class SR_COMPILE(bpy
.types
.Operator
):
2112 bl_idname
="skaterift.compile_all"
2113 bl_label
="Compile All"
2115 def execute(_
,context
):
2117 view_layer
= bpy
.context
.view_layer
2118 for col
in view_layer
.layer_collection
.children
["export"].children
:
2119 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2120 sr_compile( bpy
.data
.collections
[col
.name
] )
2126 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2128 bl_idname
="skaterift.compile_this"
2129 bl_label
="Compile This collection"
2131 def execute(_
,context
):
2133 col
= bpy
.context
.collection
2140 class SR_INTERFACE(bpy
.types
.Panel
):
2142 bl_idname
= "VIEW3D_PT_skate_rift"
2143 bl_label
= "Skate Rift"
2144 bl_space_type
= 'VIEW_3D'
2145 bl_region_type
= 'UI'
2146 bl_category
= "Skate Rift"
2148 def draw(_
, context
):
2152 row
= _
.layout
.row()
2154 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2156 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2157 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2159 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2160 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2161 col
= bpy
.context
.collection
2163 found_in_export
= False
2165 view_layer
= bpy
.context
.view_layer
2166 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2167 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2170 if c1
.name
== col
.name
: #{
2171 found_in_export
= True
2175 box
= _
.layout
.box()
2177 row
.alignment
= 'CENTER'
2180 if found_in_export
: #{
2181 row
.label( text
=col
.name
+ ".mdl" )
2182 box
.prop( col
.SR_data
, "pack_textures" )
2183 box
.prop( col
.SR_data
, "animations" )
2184 box
.operator( "skaterift.compile_this" )
2188 row
.label( text
=col
.name
)
2192 row
.alignment
= 'CENTER'
2194 row
.label( text
="This collection is not in the export group" )
2197 box
= _
.layout
.box()
2200 split
= row
.split( factor
=0.3, align
=True )
2201 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2204 if export_count
== 0:
2206 row1
.operator( "skaterift.compile_all", \
2207 text
=F
"Compile all ({export_count} collections)" )
2209 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2210 active_object
= context
.active_object
2211 if not active_object
: return
2213 _
.layout
.operator( 'skaterift.copy_entity_data', \
2214 text
=F
'Copy entity data to {len(context.selected_objects)-1} '+\
2217 box
= _
.layout
.box()
2219 row
.alignment
= 'CENTER'
2220 row
.label( text
=active_object
.name
)
2223 def _draw_prop_collection( data
): #{
2226 row
.alignment
= 'CENTER'
2229 row
.label( text
=F
'{data[0]}' )
2231 if hasattr(type(data
[0]),'sr_inspector'):#{
2232 type(data
[0]).sr_inspector( box
, data
)
2235 for a
in data
[0].__annotations
__:
2236 box
.prop( data
[0], a
)
2240 if active_object
.type == 'ARMATURE': #{
2241 if active_object
.mode
== 'POSE': #{
2242 bones
= active_object
.data
.bones
2243 mb
= sr_get_mirror_bone( bones
)
2245 box
.operator( "skaterift.mirror_bone", \
2246 text
=F
'Mirror attributes to {mb.name}' )
2249 _draw_prop_collection( [bones
.active
.SR_data
] )
2253 row
.alignment
='CENTER'
2256 row
.label( text
="Enter pose mode to modify bone properties" )
2259 elif active_object
.type == 'LIGHT': #{
2260 _draw_prop_collection( [active_object
.data
.SR_data
] )
2262 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2263 box
.prop( active_object
.SR_data
, "ent_type" )
2264 ent_type
= active_object
.SR_data
.ent_type
2266 col
= getattr( active_object
.SR_data
, ent_type
, None )
2267 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
2269 if active_object
.type == 'MESH':#{
2270 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2271 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
2278 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2280 bl_label
="Skate Rift material"
2281 bl_idname
="MATERIAL_PT_sr_material"
2282 bl_space_type
='PROPERTIES'
2283 bl_region_type
='WINDOW'
2284 bl_context
="material"
2286 def draw(_
,context
):
2288 active_object
= bpy
.context
.active_object
2289 if active_object
== None: return
2290 active_mat
= active_object
.active_material
2291 if active_mat
== None: return
2293 info
= material_info( active_mat
)
2295 if 'tex_diffuse' in info
:#{
2296 _
.layout
.label( icon
='INFO', \
2297 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2300 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2301 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2302 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2304 if active_mat
.SR_data
.collision
:#{
2305 box
= _
.layout
.box()
2308 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2309 (active_mat
.SR_data
.shader
!= 'boundary'):#{
2310 row
.prop( active_mat
.SR_data
, "skate_surface" )
2311 row
.prop( active_mat
.SR_data
, "grind_surface" )
2312 row
.prop( active_mat
.SR_data
, "grow_grass" )
2313 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2317 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2318 box
= _
.layout
.box()
2319 box
.prop( active_mat
.SR_data
, "blend_offset" )
2320 box
.prop( active_mat
.SR_data
, "sand_colour" )
2322 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2323 box
= _
.layout
.box()
2324 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2325 box
.prop( active_mat
.SR_data
, "blend_offset" )
2327 elif active_mat
.SR_data
.shader
== "water":#{
2328 box
= _
.layout
.box()
2329 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2330 box
.prop( active_mat
.SR_data
, "shore_colour" )
2331 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2336 def sr_get_type_enum( scene
, context
):
2338 items
= [('none','None',"")]
2339 mesh_entities
=['ent_gate','ent_water']
2340 point_entities
=['ent_spawn','ent_route_node','ent_route']
2342 for e
in point_entities
: items
+= [(e
,e
,'')]
2344 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2345 if context
.active_object
.type == 'MESH': #{
2346 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2350 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2356 def sr_on_type_change( _
, context
):
2358 obj
= context
.active_object
2359 ent_type
= obj
.SR_data
.ent_type
2360 if ent_type
== 'none': return
2361 if obj
.type == 'MESH':#{
2362 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2363 if col
!= None and len(col
)==0: col
.add()
2366 col
= getattr( obj
.SR_data
, ent_type
, None )
2367 if col
!= None and len(col
)==0: col
.add()
2370 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2372 alias
: bpy
.props
.StringProperty( name
='alias' )
2375 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2377 target
: bpy
.props
.PointerProperty( \
2378 type=bpy
.types
.Object
, name
="destination", \
2379 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2381 key
: bpy
.props
.StringProperty()
2382 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2383 ('nonlocal', 'Non-Local', ""),))
2386 def sr_inspector( layout
, data
):
2389 box
.prop( data
[0], 'tipo', text
="subtype" )
2391 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2392 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2396 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2398 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2401 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2403 target
: bpy
.props
.PointerProperty( \
2404 type=bpy
.types
.Object
, name
='target', \
2405 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2408 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2410 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2412 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2414 layout
.prop( item
, 'target', text
='', emboss
=False )
2418 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2420 active_object
= context
.active_object
2421 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2422 lista
= getattr(data
,collection_name
)
2423 index
= getattr(data
,F
'{collection_name}_index')
2427 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2431 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2433 active_object
= context
.active_object
2434 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2438 def copy_propgroup( de
, to
):
2440 for a
in de
.__annotations
__:#{
2441 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2445 while len(cb
) != len(ca
):#{
2446 if len(cb
) < len(ca
): cb
.add()
2449 for i
in range(len(ca
)):#{
2450 copy_propgroup(ca
[i
],cb
[i
])
2454 setattr(to
,a
,getattr(de
,a
))
2459 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2461 bl_idname
= "skaterift.copy_entity_data"
2462 bl_label
= "Copy entity data"
2464 def execute(self
, context
):#{
2465 data
= context
.active_object
.SR_data
2466 new_type
= data
.ent_type
2467 print( F
"Copy entity data from: {context.active_object.name}" )
2469 for obj
in context
.selected_objects
:#{
2470 if obj
!= context
.active_object
:#{
2471 print( F
" To: {obj.name}" )
2473 obj
.SR_data
.ent_type
= new_type
2475 if active_object
.type == 'MESH':#{
2476 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2477 if col
!= None and len(col
)==0: col
.add()
2478 mdata
= context
.active_object
.data
.SR_data
2479 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2482 col
= getattr( obj
.SR_data
, new_type
, None )
2483 if col
!= None and len(col
)==0: col
.add()
2484 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2491 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2493 bl_idname
= "skaterift.new_entry"
2494 bl_label
= "Add gate"
2496 def execute(self
, context
):#{
2497 return internal_listadd_execute(self
,context
,'ent_route','gates')
2501 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2503 bl_idname
= "skaterift.del_entry"
2504 bl_label
= "Remove gate"
2507 def poll(cls
, context
):#{
2508 active_object
= context
.active_object
2509 if obj_ent_type(active_object
) == 'ent_route':#{
2510 return active_object
.SR_data
.ent_route
[0].gates
2515 def execute(self
, context
):#{
2516 return internal_listdel_execute(self
,context
,'ent_route','gates')
2520 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2522 bl_idname
= "skaterift.al_new_entry"
2523 bl_label
= "Add file"
2525 def execute(self
, context
):#{
2526 return internal_listadd_execute(self
,context
,'ent_audio','files')
2530 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2532 bl_idname
= "skaterift.al_del_entry"
2533 bl_label
= "Remove file"
2536 def poll(cls
, context
):#{
2537 active_object
= context
.active_object
2538 if obj_ent_type(active_object
) == 'ent_audio':#{
2539 return active_object
.SR_data
.ent_audio
[0].files
2544 def execute(self
, context
):#{
2545 return internal_listdel_execute(self
,context
,'ent_audio','files')
2550 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2552 bl_idname
= "skaterift.gl_new_entry"
2553 bl_label
= "Add glyph"
2555 def execute(self
, context
):#{
2556 active_object
= context
.active_object
2558 font
= active_object
.SR_data
.ent_font
[0]
2561 if len(font
.glyphs
) > 1:#{
2562 prev
= font
.glyphs
[-2]
2563 cur
= font
.glyphs
[-1]
2565 cur
.bounds
= prev
.bounds
2566 cur
.utf32
= prev
.utf32
+1
2573 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2575 bl_idname
= "skaterift.gl_del_entry"
2576 bl_label
= "Remove Glyph"
2579 def poll(cls
, context
):#{
2580 active_object
= context
.active_object
2581 if obj_ent_type(active_object
) == 'ent_font':#{
2582 return active_object
.SR_data
.ent_font
[0].glyphs
2587 def execute(self
, context
):#{
2588 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2592 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2594 bl_idname
= "skaterift.gl_move_item"
2596 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2597 ('DOWN', 'Down', ""),))
2600 def poll(cls
, context
):#{
2601 active_object
= context
.active_object
2602 if obj_ent_type(active_object
) == 'ent_font':#{
2603 return active_object
.SR_data
.ent_font
[0].glyphs
2608 def execute(_
, context
):#{
2609 active_object
= context
.active_object
2610 data
= active_object
.SR_data
.ent_font
[0]
2612 index
= data
.glyphs_index
2613 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2614 data
.glyphs
.move( neighbor
, index
)
2616 list_length
= len(data
.glyphs
) - 1
2617 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2619 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2625 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2627 bl_idname
= "skaterift.fv_new_entry"
2628 bl_label
= "Add variant"
2630 def execute(self
, context
):#{
2631 return internal_listadd_execute(self
,context
,'ent_font','variants')
2635 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2637 bl_idname
= "skaterift.fv_del_entry"
2638 bl_label
= "Remove variant"
2641 def poll(cls
, context
):#{
2642 active_object
= context
.active_object
2643 if obj_ent_type(active_object
) == 'ent_font':#{
2644 return active_object
.SR_data
.ent_font
[0].variants
2649 def execute(self
, context
):#{
2650 return internal_listdel_execute(self
,context
,'ent_font','variants')
2654 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2656 path
: bpy
.props
.StringProperty( name
="Path" )
2657 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2660 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2662 bl_idname
= 'SR_UL_AUDIO_LIST'
2664 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2666 split
= layout
.split(factor
=0.7)
2668 c
.prop( item
, 'path', text
='', emboss
=False )
2670 c
.prop( item
, 'probability', text
='%', emboss
=True )
2674 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2676 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2678 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2680 layout
.prop( item
, 'mesh', emboss
=False )
2681 layout
.prop( item
, 'tipo' )
2685 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2687 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2689 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2691 s0
= layout
.split(factor
=0.3)
2693 s1
= c
.split(factor
=0.3)
2696 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2700 c
.prop( item
, 'utf32', text
='', emboss
=True )
2703 row
.prop( item
, 'bounds', text
='', emboss
=False )
2707 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2709 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2710 gates_index
: bpy
.props
.IntProperty()
2712 colour
: bpy
.props
.FloatVectorProperty( \
2716 default
=Vector((0.79,0.63,0.48)),\
2717 description
="Route colour"\
2720 alias
: bpy
.props
.StringProperty(\
2722 default
="Untitled Course")
2725 def sr_inspector( layout
, data
):
2727 layout
.prop( data
[0], 'alias' )
2728 layout
.prop( data
[0], 'colour' )
2730 layout
.label( text
='Checkpoints' )
2731 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2732 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2735 row
.operator( 'skaterift.new_entry', text
='Add' )
2736 row
.operator( 'skaterift.del_entry', text
='Remove' )
2740 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
2741 subtype
: bpy
.props
.EnumProperty(
2743 items
=[('0','Trigger',''),
2744 ('1','Particles (0.1s)','')]
2747 target
: bpy
.props
.PointerProperty( \
2748 type=bpy
.types
.Object
, name
="Target", \
2749 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
2750 ['ent_audio','ent_skateshop','ent_ccmd',\
2753 event
: bpy
.props
.IntProperty( name
="Event/Method" )
2756 def sr_inspector( layout
, data
):#{
2757 layout
.prop( data
[0], 'subtype' )
2758 layout
.prop( data
[0], 'target' )
2761 row
.prop( data
[0], 'event' )
2763 if data
[0].target
:#{
2764 tipo
= data
[0].target
.SR_data
.ent_type
2765 cls
= globals()[ tipo
]
2767 table
= getattr( cls
, 'sr_functions', None )
2769 if data
[0].event
in table
:#{
2770 row
.label( text
=table
[data
[0].event
] )
2773 row
.label( text
="undefined function" )
2780 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
2782 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
2783 files_index
: bpy
.props
.IntProperty()
2785 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
2786 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
2787 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
2788 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
2790 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
2791 formato
: bpy
.props
.EnumProperty(
2793 items
=[('0','Uncompressed Mono',''),
2794 ('1','Compressed Vorbis',''),
2795 ('2','[vg] Bird Synthesis','')]
2797 probability_curve
: bpy
.props
.EnumProperty(
2798 name
="Probability Curve",
2799 items
=[('0','Constant',''),
2800 ('1','Wildlife Daytime',''),
2801 ('2','Wildlife Nighttime','')])
2802 channel_behaviour
: bpy
.props
.EnumProperty(
2803 name
="Channel Behaviour",
2804 items
=[('0','Unlimited',''),
2805 ('1','Discard if group full', ''),
2806 ('2','Crossfade if group full','')])
2808 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
2811 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
2812 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
2815 def sr_inspector( layout
, data
):
2817 layout
.prop( data
[0], 'formato' )
2818 layout
.prop( data
[0], 'volume' )
2821 box
.label( text
='Channels' )
2822 split
= box
.split(factor
=0.3)
2824 c
.prop( data
[0], 'max_channels' )
2826 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
2827 if data
[0].channel_behaviour
>= '1':
2828 box
.prop( data
[0], 'group' )
2829 if data
[0].channel_behaviour
== '2':
2830 box
.prop( data
[0], 'transition_duration' )
2833 box
.label( text
='Flags' )
2834 box
.prop( data
[0], 'flag_3d' )
2835 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
2837 box
.prop( data
[0], 'flag_loop' )
2838 box
.prop( data
[0], 'flag_auto' )
2840 layout
.prop( data
[0], 'probability_curve' )
2842 split
= layout
.split(factor
=0.7)
2844 c
.label( text
='Filepath' )
2846 c
.label( text
='Chance' )
2847 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
2848 data
[0], 'files', data
[0], 'files_index', rows
=5)
2851 row
.operator( 'skaterift.al_new_entry', text
='Add' )
2852 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
2856 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
2858 alias
: bpy
.props
.StringProperty()
2861 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
2863 mini
: bpy
.props
.FloatVectorProperty(size
=2)
2864 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
2865 utf32
: bpy
.props
.IntProperty()
2868 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
2870 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
2871 utf32
: bpy
.props
.IntProperty()
2874 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
2876 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
2877 tipo
: bpy
.props
.StringProperty()
2880 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
2882 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
2883 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
2884 alias
: bpy
.props
.StringProperty()
2886 glyphs_index
: bpy
.props
.IntProperty()
2887 variants_index
: bpy
.props
.IntProperty()
2890 def sr_inspector( layout
, data
):
2892 layout
.prop( data
[0], 'alias' )
2894 layout
.label( text
='Variants' )
2895 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
2896 data
[0], 'variants', data
[0], 'variants_index',\
2899 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
2900 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
2902 layout
.label( text
='ASCII Glyphs' )
2903 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
2904 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
2907 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
2908 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
2909 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
2910 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
2914 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
2916 speed
: bpy
.props
.FloatProperty(default
=1.0)
2919 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
2921 tipo
: bpy
.props
.EnumProperty( name
='Type',
2922 items
=[('0','boards',''),
2923 ('1','character',''),
2925 mark_rack
: bpy
.props
.PointerProperty( \
2926 type=bpy
.types
.Object
, name
="Board Rack", \
2927 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2928 mark_display
: bpy
.props
.PointerProperty( \
2929 type=bpy
.types
.Object
, name
="Selected Board Display", \
2930 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2931 mark_info
: bpy
.props
.PointerProperty( \
2932 type=bpy
.types
.Object
, name
="Selected Board Info", \
2933 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2934 cam
: bpy
.props
.PointerProperty( \
2935 type=bpy
.types
.Object
, name
="Viewpoint", \
2936 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2939 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
2941 mark_display
: bpy
.props
.PointerProperty( \
2942 type=bpy
.types
.Object
, name
="Board Display", \
2943 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2944 mark_display1
: bpy
.props
.PointerProperty( \
2945 type=bpy
.types
.Object
, name
="Board Display (other side)", \
2946 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2947 cam
: bpy
.props
.PointerProperty( \
2948 type=bpy
.types
.Object
, name
="Viewpoint", \
2949 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2952 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
2954 link0
: bpy
.props
.PointerProperty( \
2955 type=bpy
.types
.Object
, name
="Link 0", \
2956 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2957 link1
: bpy
.props
.PointerProperty( \
2958 type=bpy
.types
.Object
, name
="Link 1", \
2959 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2960 link2
: bpy
.props
.PointerProperty( \
2961 type=bpy
.types
.Object
, name
="Link 2", \
2962 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2963 link3
: bpy
.props
.PointerProperty( \
2964 type=bpy
.types
.Object
, name
="Link 3", \
2965 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2967 newloc
: bpy
.props
.PointerProperty( \
2968 type=bpy
.types
.Object
, name
="New location", \
2969 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2970 camera
: bpy
.props
.PointerProperty( \
2971 type=bpy
.types
.Object
, name
="Camera", \
2972 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2974 slider_minloc
: bpy
.props
.PointerProperty( \
2975 type=bpy
.types
.Object
, name
="Slider min", \
2976 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2977 slider_maxloc
: bpy
.props
.PointerProperty( \
2978 type=bpy
.types
.Object
, name
="Slider max", \
2979 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2980 slider_handle
: bpy
.props
.PointerProperty( \
2981 type=bpy
.types
.Object
, name
="Slider handle", \
2982 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2984 checkmark
: bpy
.props
.PointerProperty( \
2985 type=bpy
.types
.Object
, name
="Checked", \
2986 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2988 string
: bpy
.props
.StringProperty( name
="String" )
2989 tipo
: bpy
.props
.EnumProperty( name
='Type',
2990 items
=[('0','visual',''),
2991 ('1','event button',''),
2992 ('2','page button',''),
2998 def sr_inspector( layout
, data
):
3002 box
.prop( data
, 'tipo' )
3004 if data
.tipo
== '0':#{
3007 elif data
.tipo
== '1':#{
3008 box
.prop( data
, 'string', text
='Event' )
3010 elif data
.tipo
== '2':#{
3011 box
.prop( data
, 'string', text
='Page' )
3012 box
.prop( data
, 'newloc' )
3014 elif data
.tipo
== '3':#{
3015 box
.prop( data
, 'string', text
='Data (i32)' )
3016 box
.prop( data
, 'checkmark' )
3018 elif data
.tipo
== '4':#{
3019 box
.prop( data
, 'string', text
='Data (f32)' )
3020 box
.prop( data
, 'slider_minloc' )
3021 box
.prop( data
, 'slider_maxloc' )
3022 box
.prop( data
, 'slider_handle' )
3024 box
.label( text
="Links" )
3025 box
.prop( data
, 'link0', text
='v0' )
3026 box
.prop( data
, 'link1', text
='v1' )
3029 elif data
.tipo
== '5':#{
3030 box
.prop( data
, 'string', text
='Page Name' )
3031 box
.prop( data
, 'newloc', text
='Entry Point' )
3032 box
.prop( data
, 'camera', text
='Viewpoint' )
3037 box
.label( text
="Links" )
3038 box
.prop( data
, 'link0' )
3039 box
.prop( data
, 'link1' )
3040 box
.prop( data
, 'link2' )
3041 box
.prop( data
, 'link3' )
3045 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3047 name
: bpy
.props
.StringProperty(name
="Name")
3048 desc
: bpy
.props
.StringProperty(name
="Description")
3049 author
: bpy
.props
.StringProperty(name
="Author")
3050 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3053 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3055 command
: bpy
.props
.StringProperty(name
="Command Line")
3058 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3059 proxima
: bpy
.props
.PointerProperty( \
3060 type=bpy
.types
.Object
, name
="Next", \
3061 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_challenge']))
3062 target
: bpy
.props
.PointerProperty( \
3063 type=bpy
.types
.Object
, name
="Target", \
3064 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3065 ['ent_audio','ent_ccmd']))
3066 event
: bpy
.props
.IntProperty( name
="Event/Method" )
3067 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3070 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3072 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3073 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3074 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3075 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3076 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3077 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3078 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3079 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3080 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3081 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3083 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3084 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3085 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3086 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3087 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3089 ent_type
: bpy
.props
.EnumProperty(
3091 items
=sr_entity_list
,
3092 update
=sr_on_type_change
3096 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3098 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3101 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3103 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3106 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3108 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3109 items
=[('0','none',''),
3111 ('2','capsule','')])
3113 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3114 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3116 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3118 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3119 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3120 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3121 conet
: bpy
.props
.FloatProperty( name
='t' )
3124 def sr_inspector( layout
, data
):
3128 box
.prop( data
, 'collider' )
3130 if int(data
.collider
)>0:#{
3132 row
.prop( data
, 'collider_min' )
3134 row
.prop( data
, 'collider_max' )
3138 box
.prop( data
, 'cone_constraint' )
3139 if data
.cone_constraint
:#{
3141 row
.prop( data
, 'conevx' )
3143 row
.prop( data
, 'conevy' )
3145 row
.prop( data
, 'coneva' )
3146 box
.prop( data
, 'conet' )
3151 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3153 shader
: bpy
.props
.EnumProperty(
3156 ('standard',"standard",''),
3157 ('standard_cutout', "standard_cutout", ''),
3158 ('terrain_blend', "terrain_blend", ''),
3159 ('vertex_blend', "vertex_blend", ''),
3160 ('water',"water",''),
3161 ('invisible','Invisible',''),
3162 ('boundary','Boundary',''),
3163 ('fxglow','FX Glow',''),
3166 surface_prop
: bpy
.props
.EnumProperty(
3167 name
="Surface Property",
3169 ('0','concrete',''),
3176 collision
: bpy
.props
.BoolProperty( \
3177 name
="Collisions Enabled",\
3179 description
= "Can the player collide with this material?"\
3181 skate_surface
: bpy
.props
.BoolProperty( \
3182 name
="Skate Target", \
3184 description
= "Should the game try to target this surface?" \
3186 grind_surface
: bpy
.props
.BoolProperty( \
3189 description
= "Can you grind on this surface?" \
3191 grow_grass
: bpy
.props
.BoolProperty( \
3192 name
="Grow Grass", \
3194 description
= "Spawn grass sprites on this surface?" \
3196 preview_visibile
: bpy
.props
.BoolProperty( \
3197 name
="Preview visibile", \
3199 description
= "Show this material in preview models?" \
3201 blend_offset
: bpy
.props
.FloatVectorProperty( \
3202 name
="Blend Offset", \
3204 default
=Vector((0.5,0.0)),\
3205 description
="When surface is more than 45 degrees, add this vector " +\
3208 sand_colour
: bpy
.props
.FloatVectorProperty( \
3209 name
="Sand Colour",\
3212 default
=Vector((0.79,0.63,0.48)),\
3213 description
="Blend to this colour near the 0 coordinate on UP axis"\
3215 shore_colour
: bpy
.props
.FloatVectorProperty( \
3216 name
="Shore Colour",\
3219 default
=Vector((0.03,0.32,0.61)),\
3220 description
="Water colour at the shoreline"\
3222 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3223 name
="Ocean Colour",\
3226 default
=Vector((0.0,0.006,0.03)),\
3227 description
="Water colour in the deep bits"\
3231 # ---------------------------------------------------------------------------- #
3235 # ---------------------------------------------------------------------------- #
3237 cv_view_draw_handler
= None
3238 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3240 cv_view_colours
= []
3241 cv_view_course_i
= 0
3243 # Draw axis alligned sphere at position with radius
3245 def cv_draw_sphere( pos
, radius
, colour
):
3247 global cv_view_verts
, cv_view_colours
3249 ly
= pos
+ Vector((0,0,radius
))
3250 lx
= pos
+ Vector((0,radius
,0))
3251 lz
= pos
+ Vector((0,0,radius
))
3253 pi
= 3.14159265358979323846264
3255 for i
in range(16):#{
3256 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3260 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3261 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3262 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3264 cv_view_verts
+= [ px
, lx
]
3265 cv_view_verts
+= [ py
, ly
]
3266 cv_view_verts
+= [ pz
, lz
]
3268 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3277 # Draw axis alligned sphere at position with radius
3279 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3281 global cv_view_verts
, cv_view_colours
3283 ly
= pos
+ tz
*radius
3284 lx
= pos
+ ty
*radius
3285 lz
= pos
+ tz
*radius
3287 pi
= 3.14159265358979323846264
3289 for i
in range(16):#{
3290 t
= ((i
+1.0) * 1.0/16.0) * pi
3294 s1
= math
.sin(t
*2.0)
3295 c1
= math
.cos(t
*2.0)
3297 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3298 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3299 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3301 cv_view_verts
+= [ px
, lx
]
3302 cv_view_verts
+= [ py
, ly
]
3303 cv_view_verts
+= [ pz
, lz
]
3305 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3314 # Draw transformed -1 -> 1 cube
3316 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3318 global cv_view_verts
, cv_view_colours
3324 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3325 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3326 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3327 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3328 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3329 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3330 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3331 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3333 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3334 (0,4),(1,5),(2,6),(3,7)]
3339 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3340 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3341 cv_view_colours
+= [colour
, colour
]
3346 # Draw line with colour
3348 def cv_draw_line( p0
, p1
, colour
):
3350 global cv_view_verts
, cv_view_colours
3352 cv_view_verts
+= [p0
,p1
]
3353 cv_view_colours
+= [colour
, colour
]
3357 # Draw line with colour(s)
3359 def cv_draw_line2( p0
, p1
, c0
, c1
):
3361 global cv_view_verts
, cv_view_colours
3363 cv_view_verts
+= [p0
,p1
]
3364 cv_view_colours
+= [c0
,c1
]
3370 def cv_tangent_basis( n
, tx
, ty
):
3372 if abs( n
[0] ) >= 0.57735027:#{
3391 # Draw coloured arrow
3393 def cv_draw_arrow( p0
, p1
, c0
, size
=0.15 ):
3395 global cv_view_verts
, cv_view_colours
3401 tx
= Vector((1,0,0))
3402 ty
= Vector((1,0,0))
3403 cv_tangent_basis( n
, tx
, ty
)
3405 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3406 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3410 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3412 global cv_view_verts
, cv_view_colours
3414 for i
in range(dots
):#{
3418 p2
= p0
*(1.0-t0
)+p1
*t0
3419 p3
= p0
*(1.0-t1
)+p1
*t1
3421 cv_view_verts
+= [p2
,p3
]
3422 cv_view_colours
+= [c0
,c0
]
3427 # Drawhandles of a bezier control point
3429 def cv_draw_bhandle( obj
, direction
, colour
):
3431 global cv_view_verts
, cv_view_colours
3434 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3436 cv_view_verts
+= [p0
]
3437 cv_view_verts
+= [h0
]
3438 cv_view_colours
+= [colour
,colour
]
3442 # Draw a bezier curve (at fixed resolution 10)
3444 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3446 global cv_view_verts
, cv_view_colours
3449 for i
in range(10):#{
3455 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3457 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3458 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3459 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3466 # I think this one extends the handles of the bezier otwards......
3468 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3470 global cv_view_course_i
3472 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3474 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3475 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3476 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3477 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3479 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3483 # Flush the lines buffers. This is called often because god help you if you want
3484 # to do fixed, fast buffers in this catastrophic programming language.
3486 def cv_draw_lines():
3488 global cv_view_shader
, cv_view_verts
, cv_view_colours
3490 if len(cv_view_verts
) < 2:
3493 lines
= batch_for_shader(\
3494 cv_view_shader
, 'LINES', \
3495 { "pos":cv_view_verts
, "color":cv_view_colours
})
3497 if bpy
.context
.scene
.SR_data
.gizmos
:
3498 lines
.draw( cv_view_shader
)
3501 cv_view_colours
= []
3504 # I dont remember what this does exactly
3506 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3508 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3511 # Semi circle to show the limit. and some lines
3513 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3515 global cv_view_verts
, cv_view_colours
3520 for x
in range(16):#{
3523 a0
= amin
*(1.0-t0
)+amax
*t0
3524 a1
= amin
*(1.0-t1
)+amax
*t1
3526 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3527 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3529 p0
=obj
.matrix_world
@ p0
3530 p1
=obj
.matrix_world
@ p1
3531 cv_view_verts
+= [p0
,p1
]
3532 cv_view_colours
+= [colour
,colour
]
3535 cv_view_verts
+= [p0
,center
]
3536 cv_view_colours
+= [colour
,colour
]
3539 cv_view_verts
+= [p1
,center
]
3540 cv_view_colours
+= [colour
,colour
]
3544 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
3545 cv_view_colours
+= [colour
,colour
]
3550 # Cone and twist limit
3552 def draw_cone_twist( center
, vx
, vy
, va
):
3554 global cv_view_verts
, cv_view_colours
3555 axis
= vy
.cross( vx
)
3560 cv_view_verts
+= [center
, center
+va
*size
]
3561 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
3563 for x
in range(32):#{
3564 t0
= (x
/32) * math
.tau
3565 t1
= ((x
+1)/32) * math
.tau
3572 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
3573 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
3575 col0
= ( abs(c0
), abs(s0
), 0.0 )
3576 col1
= ( abs(c1
), abs(s1
), 0.0 )
3578 cv_view_verts
+= [center
, p0
, p0
, p1
]
3579 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
3585 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
3587 def draw_skeleton_helpers( obj
):
3589 global cv_view_verts
, cv_view_colours
3591 if obj
.data
.pose_position
!= 'REST':#{
3595 for bone
in obj
.data
.bones
:#{
3597 a
= Vector((bone
.SR_data
.collider_min
[0],
3598 bone
.SR_data
.collider_min
[1],
3599 bone
.SR_data
.collider_min
[2]))
3600 b
= Vector((bone
.SR_data
.collider_max
[0],
3601 bone
.SR_data
.collider_max
[1],
3602 bone
.SR_data
.collider_max
[2]))
3604 if bone
.SR_data
.collider
== '1':#{
3606 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
3607 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
3608 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
3609 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
3610 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
3611 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
3612 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
3613 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
3615 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3616 (0,4),(1,5),(2,6),(3,7)]
3622 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3623 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3624 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
3627 elif bone
.SR_data
.collider
== '2':#{
3632 for i
in range(3):#{
3633 if abs(v0
[i
]) > largest
:#{
3634 largest
= abs(v0
[i
])
3639 v1
= Vector((0,0,0))
3640 v1
[major_axis
] = 1.0
3642 tx
= Vector((0,0,0))
3643 ty
= Vector((0,0,0))
3645 cv_tangent_basis( v1
, tx
, ty
)
3646 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
3647 l
= v0
[ major_axis
] - r
*2
3649 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
3650 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
3652 colour
= [0.2,0.2,0.2]
3653 colour
[major_axis
] = 0.5
3655 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
3656 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
3657 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
3658 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
3659 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
3660 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
3666 center
= obj
.matrix_world
@ c
3667 if bone
.SR_data
.cone_constraint
:#{
3668 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
3669 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
3670 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
3671 draw_cone_twist( center
, vx
, vy
, va
)
3676 def cv_ent_gate( obj
):
3678 global cv_view_verts
, cv_view_colours
3680 if obj
.type != 'MESH': return
3682 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
3683 data
= obj
.SR_data
.ent_gate
[0]
3684 dims
= mesh_data
.dimensions
3687 c
= Vector((0,0,dims
[2]))
3689 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
3690 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
3691 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
3692 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
3693 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
3694 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
3695 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
3696 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
3697 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
3699 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
3701 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
3703 p0
= r3d
.view_matrix
.inverted().translation
3704 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
3705 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
3707 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
3713 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3714 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3715 cv_view_colours
+= [cc
,cc
]
3719 if data
.target
!= None:
3720 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
3723 def cv_ent_volume( obj
):
3725 global cv_view_verts
, cv_view_colours
3727 data
= obj
.SR_data
.ent_volume
[0]
3729 if data
.subtype
== '0':#{
3730 cv_draw_ucube( obj
.matrix_world
, (0,1,0) )
3733 cv_draw_arrow( obj
.location
, data
.target
.location
, (0,1,0) )
3736 elif data
.subtype
== '1':#{
3737 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
3740 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,0) )
3745 def dijkstra( graph
, start_node
, target_node
):
3747 unvisited
= [_
for _
in graph
]
3752 shortest_path
[n
] = 9999999.999999
3753 shortest_path
[start_node
] = 0
3756 current_min_node
= None
3757 for n
in unvisited
:#{
3758 if current_min_node
== None:
3759 current_min_node
= n
3760 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
3761 current_min_node
= n
3764 for branch
in graph
[current_min_node
]:#{
3765 tentative_value
= shortest_path
[current_min_node
]
3766 tentative_value
+= graph
[current_min_node
][branch
]
3767 if tentative_value
< shortest_path
[branch
]:#{
3768 shortest_path
[branch
] = tentative_value
3769 previous_nodes
[branch
] = current_min_node
3773 unvisited
.remove(current_min_node
)
3778 while node
!= start_node
:#{
3781 if node
not in previous_nodes
: return None
3782 node
= previous_nodes
[node
]
3785 # Add the start node manually
3786 path
.append(start_node
)
3792 def __init__(_
,points
,graph
,subsections
):#{
3795 _
.subsections
= subsections
3799 def create_node_graph( curves
, gates
):
3801 # add endpoints of curves
3808 for c
in range(len(curves
)):#{
3809 for s
in range(len(curves
[c
].data
.splines
)):#{
3810 spline
= curves
[c
].data
.splines
[s
]
3811 l
= len(spline
.points
)
3814 dist
= round(spline
.calc_length(),2)
3817 ib
= point_count
+l
-1
3819 graph
[ia
] = { ib
: dist
}
3820 graph
[ib
] = { ia
: dist
}
3822 for i
in range(len(spline
.points
)):#{
3823 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
3824 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
3829 if i
== 0: previous
= -1
3830 if i
== len(spline
.points
)-1: proxima
= -1
3832 subsections
.append((spline_count
,previous
,proxima
))
3841 graph_keys
= list(graph
)
3842 for i
in range(len(graph_keys
)-1):#{
3843 for j
in range(i
+1, len(graph_keys
)):#{
3844 if i
%2==0 and i
+1==j
: continue
3848 pi
= route_points
[ni
]
3849 pj
= route_points
[nj
]
3851 dist
= round((pj
-pi
).magnitude
,2)
3854 graph
[ni
][nj
] = dist
3855 graph
[nj
][ni
] = dist
3860 # add and link gates( by name )
3861 for gate
in gates
:#{
3862 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
3863 if gate
.SR_data
.ent_gate
[0].target
:
3866 graph
[ gate
.name
] = {}
3868 for i
in range(len(graph_keys
)):#{
3870 pi
= route_points
[ni
]
3872 v0
= pi
-gate
.location
3873 if v0
.dot(v1
) < 0.0: continue
3875 dist
= round(v0
.magnitude
,2)
3878 graph
[ gate
.name
][ ni
] = dist
3879 graph
[ ni
][ gate
.name
] = dist
3884 return dij_graph(route_points
,graph
,subsections
)
3887 def solve_graph( dij
, start
, end
):
3889 path
= dijkstra( dij
.graph
, end
, start
)
3893 for sj
in range(1,len(path
)-2):#{
3896 map0
= dij
.subsections
[i0
]
3897 map1
= dij
.subsections
[i1
]
3899 if map0
[0] == map1
[0]:#{
3900 if map0
[1] == -1: direction
= 2
3905 map0
= dij
.subsections
[i0
]
3906 i1
= map0
[direction
]
3920 full
.append( path
[-2] )
3925 def cv_draw_route( route
, dij
):
3927 pole
= Vector((0.2,0.2,10))
3928 hat
= Vector((1,8,0.2))
3929 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
3930 route
.SR_data
.ent_route
[0].colour
[1],
3931 route
.SR_data
.ent_route
[0].colour
[2])
3933 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
3934 Vector((0,-6.5,5.5)))
3935 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
3936 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
3937 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
3938 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
3940 checkpoints
= route
.SR_data
.ent_route
[0].gates
3942 for i
in range(len(checkpoints
)):#{
3943 gi
= checkpoints
[i
].target
3944 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
3947 dest
= gi
.SR_data
.ent_gate
[0].target
3949 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
3953 if gi
==gj
: continue # error?
3954 if not gi
or not gj
: continue
3956 path
= solve_graph( dij
, gi
.name
, gj
.name
)
3959 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5)
3960 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5)
3961 for j
in range(len(path
)-1):#{
3964 o0
= dij
.points
[ i0
]
3965 o1
= dij
.points
[ i1
]
3966 cv_draw_arrow(o0
,o1
,cc
,1.5)
3970 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
3977 global cv_view_shader
3978 global cv_view_verts
3979 global cv_view_colours
3980 global cv_view_course_i
3982 cv_view_course_i
= 0
3984 cv_view_colours
= []
3986 cv_view_shader
.bind()
3987 gpu
.state
.depth_mask_set(False)
3988 gpu
.state
.line_width_set(2.0)
3989 gpu
.state
.face_culling_set('BACK')
3990 gpu
.state
.depth_test_set('LESS')
3991 gpu
.state
.blend_set('NONE')
3997 for obj
in bpy
.context
.collection
.objects
:#{
3998 if obj
.type == 'ARMATURE':#{
3999 if obj
.data
.pose_position
== 'REST':
4000 draw_skeleton_helpers( obj
)
4003 ent_type
= obj_ent_type( obj
)
4005 if ent_type
== 'ent_gate':#{
4007 route_gates
+= [obj
]
4009 elif ent_type
== 'ent_route_node':#{
4010 if obj
.type == 'CURVE':#{
4011 route_curves
+= [obj
]
4014 elif ent_type
== 'ent_route':
4016 elif ent_type
== 'ent_volume':#{
4017 cv_ent_volume( obj
)
4019 elif ent_type
== 'ent_challenge':#{
4020 data
= obj
.SR_data
.ent_challenge
[0]
4022 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (0,0.2,1.0) )
4025 elif ent_type
== 'ent_audio':#{
4026 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4027 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4029 elif ent_type
== 'ent_font':#{
4030 data
= obj
.SR_data
.ent_font
[0]
4032 for i
in range(len(data
.variants
)):#{
4033 sub
= data
.variants
[i
].mesh
4034 if not sub
: continue
4036 for ch
in data
.glyphs
:#{
4037 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4038 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4039 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4040 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4041 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4042 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4044 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4047 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4048 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4052 elif ent_type
== 'ent_skateshop':#{
4053 data
= obj
.SR_data
.ent_skateshop
[0]
4054 display
= data
.mark_display
4055 info
= data
.mark_info
4057 if data
.tipo
== '0':#{
4062 rack
= data
.mark_rack
4064 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4065 rack_co
= Vector((0.0,0.0,0.0))
4066 display_cu
= Vector((0.3,1.2,0.1))*0.5
4067 display_co
= Vector((0.0,0.0,0.1))*0.5
4068 info_cu
= Vector((1.2,0.01,0.3))*0.5
4069 info_co
= Vector((0.0,0.0,0.0))*0.5
4071 elif data
.tipo
== '1':#{
4075 display_cu
= Vector((0.4,0.4,2.0))*0.5
4076 display_co
= Vector((0.0,0.0,1.0))*0.5
4077 info_cu
= Vector((1.2,0.01,0.3))*0.5
4078 info_co
= Vector((0.0,0.0,0.0))*0.5
4080 elif data
.tipo
== '2':#{
4084 display_cu
= Vector((1.0,1.0,0.5))*0.5
4085 display_co
= Vector((0.0,0.0,0.5))*0.5
4086 info_cu
= Vector((1.2,0.01,0.3))*0.5
4087 info_co
= Vector((0.0,0.0,0.0))*0.5
4091 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4093 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4095 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4097 elif ent_type
== 'ent_swspreview':#{
4099 data
= obj
.SR_data
.ent_swspreview
[0]
4100 display
= data
.mark_display
4101 display1
= data
.mark_display1
4102 display_cu
= Vector((0.3,1.2,0.1))*0.5
4103 display_co
= Vector((0.0,0.0,0.1))*0.5
4105 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4107 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4109 elif ent_type
== 'ent_menuitem':#{
4110 for i
,col
in enumerate(obj
.users_collection
):#{
4111 colour32
= hash_djb2( col
.name
)
4112 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4113 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4114 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4116 vs
= [None for _
in range(8)]
4118 for j
in range(8):#{
4119 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4120 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4122 vs
[j
] = obj
.matrix_world
@ v0
4124 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4125 (0,4),(1,5),(2,6),(3,7)]
4129 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4130 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4131 cv_view_colours
+= [cc
,cc
]
4136 data
= obj
.SR_data
.ent_menuitem
[0]
4137 if data
.tipo
== '4':#{
4138 if data
.slider_minloc
and data
.slider_maxloc
:#{
4139 v0
= data
.slider_minloc
.location
4140 v1
= data
.slider_maxloc
.location
4141 cv_draw_line( v0
, v1
, cc
)
4145 colour32
= hash_djb2(obj
.name
)
4146 r
= ((colour32
) & 0xff) / 255.0
4147 g
= ((colour32
>>8 ) & 0xff) / 255.0
4148 b
= ((colour32
>>16) & 0xff) / 255.0
4150 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4155 if data
.tipo
!= '0':#{
4156 if data
.tipo
== '4':#{
4158 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4161 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4166 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4169 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4172 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4175 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4183 dij
= create_node_graph( route_curves
, route_gates
)
4185 #cv_draw_route_map( route_nodes )
4186 for route
in routes
:#{
4187 cv_draw_route( route
, dij
)
4194 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4195 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4196 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4198 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4199 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4200 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4201 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4202 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4203 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4204 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4205 SR_OT_COPY_ENTITY_DATA
, \
4206 SR_OBJECT_ENT_VOLUME
, \
4207 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4208 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4209 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4210 SR_OBJECT_ENT_FONT_VARIANT
,
4211 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4212 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4213 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4214 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4215 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4216 SR_OBJECT_ENT_CHALLENGE
,\
4218 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4219 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4225 bpy
.utils
.register_class(c
)
4227 bpy
.types
.Scene
.SR_data
= \
4228 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4229 bpy
.types
.Collection
.SR_data
= \
4230 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4232 bpy
.types
.Object
.SR_data
= \
4233 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4234 bpy
.types
.Light
.SR_data
= \
4235 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4236 bpy
.types
.Bone
.SR_data
= \
4237 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4238 bpy
.types
.Mesh
.SR_data
= \
4239 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4240 bpy
.types
.Material
.SR_data
= \
4241 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4243 global cv_view_draw_handler
4244 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4245 cv_draw
,(),'WINDOW','POST_VIEW')
4251 bpy
.utils
.unregister_class(c
)
4253 global cv_view_draw_handler
4254 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4257 # ---------------------------------------------------------------------------- #
4261 # ---------------------------------------------------------------------------- #
4263 # Transliteration of: #
4264 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
4266 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
4267 # SPDX-License-Identifier: MIT #
4268 # QOI - The "Quite OK Image" format for fast, lossless image compression #
4270 # ---------------------------------------------------------------------------- #
4272 class qoi_rgba_t(Structure
):
4275 _fields_
= [("r",c_uint8
),
4281 QOI_OP_INDEX
= 0x00 # 00xxxxxx
4282 QOI_OP_DIFF
= 0x40 # 01xxxxxx
4283 QOI_OP_LUMA
= 0x80 # 10xxxxxx
4284 QOI_OP_RUN
= 0xc0 # 11xxxxxx
4285 QOI_OP_RGB
= 0xfe # 11111110
4286 QOI_OP_RGBA
= 0xff # 11111111
4288 QOI_MASK_2
= 0xc0 # 11000000
4290 def qoi_colour_hash( c
):
4292 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
4297 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
4302 return bytearray([ (0xff000000 & v
) >> 24, \
4303 (0x00ff0000 & v
) >> 16, \
4304 (0x0000ff00 & v
) >> 8, \
4308 def qoi_encode( img
):
4312 print(F
"{' ':<30}",end
='\r')
4313 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
4315 index
= [ qoi_rgba_t() for _
in range(64) ]
4319 data
.extend( bytearray(c_uint32(0x66696f71)) )
4320 data
.extend( qoi_32bit( img
.size
[0] ) )
4321 data
.extend( qoi_32bit( img
.size
[1] ) )
4322 data
.extend( bytearray(c_uint8(4)) )
4323 data
.extend( bytearray(c_uint8(0)) )
4326 px_prev
= qoi_rgba_t()
4327 px_prev
.r
= c_uint8(0)
4328 px_prev
.g
= c_uint8(0)
4329 px_prev
.b
= c_uint8(0)
4330 px_prev
.a
= c_uint8(255)
4338 px_len
= img
.size
[0] * img
.size
[1]
4339 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
4341 for px_pos
in range( px_len
): #{
4342 idx
= px_pos
* img
.channels
4345 px
.r
= paxels
[idx
+min(0,nc
)]
4346 px
.g
= paxels
[idx
+min(1,nc
)]
4347 px
.b
= paxels
[idx
+min(2,nc
)]
4348 px
.a
= paxels
[idx
+min(3,nc
)]
4350 if qoi_eq( px
, px_prev
): #{
4353 if (run
== 62) or (px_pos
== px_len
-1): #{
4354 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4360 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4364 index_pos
= qoi_colour_hash(px
) % 64
4366 if qoi_eq( index
[index_pos
], px
): #{
4367 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
4370 index
[ index_pos
].r
= px
.r
4371 index
[ index_pos
].g
= px
.g
4372 index
[ index_pos
].b
= px
.b
4373 index
[ index_pos
].a
= px
.a
4375 if px
.a
== px_prev
.a
: #{
4376 vr
= int(px
.r
) - int(px_prev
.r
)
4377 vg
= int(px
.g
) - int(px_prev
.g
)
4378 vb
= int(px
.b
) - int(px_prev
.b
)
4383 if (vr
> -3) and (vr
< 2) and\
4384 (vg
> -3) and (vg
< 2) and\
4385 (vb
> -3) and (vb
< 2):
4387 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
4388 data
.extend( bytearray( c_uint8(op
) ))
4390 elif (vg_r
> -9) and (vg_r
< 8) and\
4391 (vg
> -33) and (vg
< 32 ) and\
4392 (vg_b
> -9) and (vg_b
< 8):
4394 op
= QOI_OP_LUMA |
(vg
+32)
4395 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
4396 data
.extend( bytearray( c_uint8(op
) ) )
4397 data
.extend( bytearray( c_uint8(delta
) ))
4400 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
4401 data
.extend( bytearray( c_uint8(px
.r
) ))
4402 data
.extend( bytearray( c_uint8(px
.g
) ))
4403 data
.extend( bytearray( c_uint8(px
.b
) ))
4407 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
4408 data
.extend( bytearray( c_uint8(px
.r
) ))
4409 data
.extend( bytearray( c_uint8(px
.g
) ))
4410 data
.extend( bytearray( c_uint8(px
.b
) ))
4411 data
.extend( bytearray( c_uint8(px
.a
) ))
4424 data
.extend( bytearray( c_uint8(0) ))
4425 data
.extend( bytearray( c_uint8(1) ))
4426 bytearray_align_to( data
, 16, b
'\x00' )