3 import bpy
, blf
, math
, gpu
, os
, time
7 from mathutils
import *
8 from gpu_extras
.batch
import batch_for_shader
9 from bpy_extras
import mesh_utils
10 from bpy_extras
import view3d_utils
13 "name":"Skaterift .mdl exporter",
14 "author": "Harry Godden (hgn)",
21 "category":"Import/Export",
25 ('none', 'None', '', 0 ),
26 ('ent_gate', 'Gate', '', 1 ),
27 ('ent_spawn', 'Spawn Point', '', 2 ),
28 ('ent_route_node', 'Routing Path', '', 3 ),
29 ('ent_route', 'Skate Course', '', 4 ),
30 ('ent_water', 'Water Surface', '', 5 ),
31 ('ent_volume', 'Volume/Trigger', '', 6 ),
32 ('ent_audio', 'Audio', '', 7 ),
33 ('ent_marker', 'Marker', '', 8 ),
34 ('ent_font', 'Font', '', 9 ),
35 ('ent_font_variant', 'Font:Variant', '', 10 ),
36 ('ent_traffic', 'Traffic Model', '', 11 ),
37 ('ent_skateshop', 'Skate Shop', '', 12 ),
38 ('ent_camera', 'Camera', '', 13 ),
39 ('ent_swspreview', 'Workshop Preview', '', 14 ),
40 ('ent_menuitem', 'Menu Item', '', 15 ),
41 ('ent_worldinfo', 'World Info', '', 16 ),
42 ('ent_ccmd', 'CCmd', '', 17 ),
43 ('ent_objective', 'Objective', '', 18 ),
44 ('ent_challenge', 'Challenge', '', 19 ),
45 ('ent_relay', 'Relay', '', 20 ),
46 ('ent_miniworld', 'Mini World', '', 22 ),
47 ('ent_prop', 'Prop', '', 23 ),
48 ('ent_list', 'Entity List', '', 24 ),
49 ('ent_region', 'Region', '', 25 ),
50 ('ent_glider', 'Glider', '', 26 ),
51 ('ent_npc', 'npc', '', 27 )
55 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
56 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
57 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
58 'ent_npc', 'ent_water' ]
60 def get_entity_enum_id( alias
):
62 for et
in sr_entity_list
:#{
68 if alias
== 'ent_cubemap': return 21
73 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
74 #{ # the normals and uvs to i16s. Not an
75 _pack_
= 1 # real issue, yet.
76 _fields_
= [("co",c_float
*3),
80 ("weights",c_uint16
*4),
84 class mdl_transform(Structure
):
86 _fields_
= [("co",c_float
*3),
91 class mdl_submesh(Structure
):
93 _fields_
= [("indice_start",c_uint32
),
94 ("indice_count",c_uint32
),
95 ("vertex_start",c_uint32
),
96 ("vertex_count",c_uint32
),
97 ("bbx",(c_float
*3)*2),
98 ("material_id",c_uint16
), # index into the material array
103 # =================================================
105 class mdl_file(Structure
):
107 _fields_
= [("path",c_uint32
),
108 ("pack_offset",c_uint32
),
109 ("pack_size",c_uint32
)]
112 class mdl_material_kvs(Structure
):
114 _fields_
= [("offset",c_uint32
),
118 class mdl_material_properties_union(Union
):
120 _fields_
= [("kvs",mdl_material_kvs
),
121 ("compiled",c_void_p
)]
124 class mdl_material(Structure
):
126 _fields_
= [("pstr_name",c_uint32
),
129 ("surface_prop",c_uint32
),
130 ("props",mdl_material_properties_union
)]
132 # ("colour",c_float*4), (old) v105
133 # ("colour1",c_float*4),
134 # ("tex_diffuse",c_uint32),
135 # ("tex_none0",c_uint32),
136 # ("tex_none1",c_uint32)]
139 class mdl_bone(Structure
):
141 _fields_
= [("co",c_float
*3),("end",c_float
*3),
143 ("collider",c_uint32
),
144 ("ik_target",c_uint32
),
145 ("ik_pole",c_uint32
),
147 ("pstr_name",c_uint32
),
148 ("hitbox",(c_float
*3)*2),
149 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
153 class mdl_armature(Structure
):
155 _fields_
= [("transform",mdl_transform
),
156 ("bone_start",c_uint32
),
157 ("bone_count",c_uint32
),
158 ("anim_start",c_uint32
),
159 ("anim_count",c_uint32
)]
162 class mdl_animation(Structure
):
164 _fields_
= [("pstr_name",c_uint32
),
167 ("keyframe_start",c_uint32
)]
170 class mdl_mesh(Structure
):
172 _fields_
= [("transform",mdl_transform
),
173 ("submesh_start",c_uint32
),
174 ("submesh_count",c_uint32
),
175 ("pstr_name",c_uint32
),
176 ("entity_id",c_uint32
),
177 ("armature_id",c_uint32
)]
180 class mdl_texture(Structure
):
182 _fields_
= [("file",mdl_file
),
186 class mdl_array(Structure
):
188 _fields_
= [("file_offset",c_uint32
),
189 ("item_count",c_uint32
),
190 ("item_size",c_uint32
),
194 class mdl_header(Structure
):
196 _fields_
= [("version",c_uint32
),
197 ("arrays",mdl_array
)]
200 class ent_spawn(Structure
):
202 _fields_
= [("transform",mdl_transform
),
203 ("pstr_name",c_uint32
)]
206 class ent_light(Structure
):
208 _fields_
= [("transform",mdl_transform
),
209 ("daytime",c_uint32
),
211 ("colour",c_float
*4),
214 ("inverse_world",(c_float
*3)*4), # Runtime
215 ("angle_sin_cos",(c_float
*2))] # Runtime
218 class version_refcount_union(Union
):
220 _fields_
= [("timing_version",c_uint32
),
221 ("ref_count",c_uint8
)]
224 class ent_gate(Structure
):
226 _fields_
= [("flags",c_uint32
),
227 ("target", c_uint32
),
229 ("dimensions", c_float
*3),
230 ("co", (c_float
*3)*2),
231 ("q", (c_float
*4)*2),
232 ("to_world",(c_float
*3)*4),
233 ("transport",(c_float
*3)*4),
234 ("_anonymous_union",version_refcount_union
),
235 ("timing_time",c_double
),
236 ("routes",c_uint16
*4),
237 ("route_count",c_uint8
),
238 ("submesh_start",c_uint32
), # v102+
239 ("submesh_count",c_uint32
), # v102+ (can be 0)
241 sr_functions
= { 0: 'unlock' }
244 class ent_route_node(Structure
):
246 _fields_
= [("co",c_float
*3),
247 ("ref_count",c_uint8
),
248 ("ref_total",c_uint8
)]
251 class ent_path_index(Structure
):
253 _fields_
= [("index",c_uint16
)]
256 class vg_audio_clip(Structure
):
258 _fields_
= [("path",c_uint64
),
264 class union_file_audio_clip(Union
):
266 _fields_
= [("file",mdl_file
),
267 ("reserved",vg_audio_clip
)]
270 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
271 # but then again, too late to change because compat.
272 class ent_audio_clip(Structure
):
274 _fields_
= [("_anon",union_file_audio_clip
),
275 ("probability",c_float
)]
278 class ent_list(Structure
):
280 _fields_
= [("entity_ref_start",c_uint32
),
281 ("entity_ref_count",c_uint32
)]
285 class file_entity_ref(Structure
):
287 _fields_
= [("index",c_uint32
)]
290 class ent_checkpoint(Structure
):
292 _fields_
= [("gate_index",c_uint16
),
293 ("path_start",c_uint16
),
294 ("path_count",c_uint16
)]
297 class ent_route(Structure
):
299 _fields_
= [("transform",mdl_transform
),
300 ("pstr_name",c_uint32
),
301 ("checkpoints_start",c_uint16
),
302 ("checkpoints_count",c_uint16
),
303 ("colour",c_float
*4),
304 ("active",c_uint32
), #runtime
306 ("board_transform",(c_float
*3)*4),
308 ("latest_pass",c_double
),
309 ("id_camera",c_uint32
), # v103+
312 sr_functions
= { 0: 'view' }
315 class ent_list(Structure
):#{
316 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
319 class ent_glider(Structure
):#{
320 _fields_
= [("transform",mdl_transform
),
322 ("cooldown",c_float
)]
323 sr_functions
= { 0: 'unlock',
327 class ent_npc(Structure
):#{
328 _fields_
= [("transform",mdl_transform
),
330 ("context",c_uint32
),
332 sr_functions
= { 0: 'proximity', -1: 'leave' }
335 class ent_water(Structure
):
337 _fields_
= [("transform",mdl_transform
),
338 ("max_dist",c_float
),
339 ("reserved0",c_uint32
),
340 ("reserved1",c_uint32
)]
341 sr_functions
= { 0: "drown" }
344 class volume_trigger(Structure
):
346 _fields_
= [("event",c_uint32
),
347 ("event_leave",c_int32
)]
350 class volume_particles(Structure
):
352 _fields_
= [("blank",c_uint32
),
356 class volume_union(Union
):
358 _fields_
= [("trigger",volume_trigger
),
359 ("particles",volume_particles
)]
362 class ent_volume(Structure
):
364 _fields_
= [("transform",mdl_transform
),
365 ("to_world",(c_float
*3)*4),
366 ("to_local",(c_float
*3)*4),
369 ("_anon",volume_union
)]
372 class ent_audio(Structure
):
374 _fields_
= [("transform",mdl_transform
),
376 ("clip_start",c_uint32
),
377 ("clip_count",c_uint32
),
379 ("crossfade",c_float
),
380 ("channel_behaviour",c_uint32
),
382 ("probability_curve",c_uint32
),
383 ("max_channels",c_uint32
)]
386 class ent_marker(Structure
):
388 _fields_
= [("transform",mdl_transform
),
392 class ent_glyph(Structure
):
394 _fields_
= [("size",c_float
*2),
395 ("indice_start",c_uint32
),
396 ("indice_count",c_uint32
)]
399 class ent_font_variant(Structure
):
401 _fields_
= [("name",c_uint32
),
402 ("material_id",c_uint32
)]
405 class ent_font(Structure
):
407 _fields_
= [("alias",c_uint32
),
408 ("variant_start",c_uint32
),
409 ("variant_count",c_uint32
),
410 ("glyph_start",c_uint32
),
411 ("glyph_count",c_uint32
),
412 ("glyph_utf32_base",c_uint32
)]
415 class ent_traffic(Structure
):
417 _fields_
= [("transform",mdl_transform
),
418 ("submesh_start",c_uint32
),
419 ("submesh_count",c_uint32
),
420 ("start_node",c_uint32
),
421 ("node_count",c_uint32
),
428 # ---------------------------------------------------------------
429 class ent_skateshop_characters(Structure
):
431 _fields_
= [("id_display",c_uint32
),
432 ("id_info",c_uint32
)]
434 class ent_skateshop_boards(Structure
):
436 _fields_
= [("id_display",c_uint32
),
437 ("id_info",c_uint32
),
438 ("id_rack",c_uint32
)]
440 class ent_skateshop_worlds(Structure
):
442 _fields_
= [("id_display",c_uint32
),
443 ("id_info",c_uint32
)]
445 class ent_skateshop_server(Structure
):
447 _fields_
= [("id_lever",c_uint32
)]
449 class ent_skateshop_anon_union(Union
):
451 _fields_
= [("boards",ent_skateshop_boards
),
452 ("character",ent_skateshop_characters
),
453 ("worlds",ent_skateshop_worlds
),
454 ("server",ent_skateshop_server
)]
456 class ent_skateshop(Structure
):
458 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
459 ("id_camera",c_uint32
),
460 ("_anonymous_union",ent_skateshop_anon_union
)]
462 sr_functions
= { 0: 'trigger' }
465 class ent_swspreview(Structure
):
467 _fields_
= [("id_camera",c_uint32
),
468 ("id_display",c_uint32
),
469 ("id_display1",c_uint32
)]
473 # -----------------------------------------------------------------
474 class ent_menuitem_visual(Structure
):
476 _fields_
= [("pstr_name",c_uint32
)]
478 class ent_menuitem_slider(Structure
):
480 _fields_
= [("id_min",c_uint32
),
482 ("id_handle",c_uint32
),
483 ("pstr_data",c_uint32
)]
485 class ent_menuitem_button(Structure
):
487 _fields_
= [("pstr",c_uint32
),
488 ("stack_behaviour",c_uint32
)]
490 class ent_menuitem_checkmark(Structure
):
492 _fields_
= [("id_check",c_uint32
),
493 ("pstr_data",c_uint32
),
494 ("offset",c_float
*3)]
496 class ent_menuitem_page(Structure
):
498 _fields_
= [("pstr_name",c_uint32
),
499 ("id_entrypoint",c_uint32
),
500 ("id_viewpoint",c_uint32
)]
502 class ent_menuitem_binding(Structure
):
504 _fields_
= [("pstr_bind",c_uint32
),
505 ("font_variant",c_uint32
)]
507 class ent_menuitem_anon_union(Union
):
509 _fields_
= [("slider",ent_menuitem_slider
),
510 ("button",ent_menuitem_button
),
511 ("checkmark",ent_menuitem_checkmark
),
512 ("page",ent_menuitem_page
),
513 ("visual",ent_menuitem_visual
),
514 ("binding",ent_menuitem_binding
)]
516 class ent_menuitem(Structure
):
518 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
519 ("id_links",c_uint32
*4),
520 ("factive",c_float
), ("fvisible",c_float
),
521 #-- TODO: Refactor this into a simple mesh structure
522 ("transform",mdl_transform
),
523 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
526 ("_anonymous_union", ent_menuitem_anon_union
)]
529 class ent_camera(Structure
):
531 _fields_
= [("transform",mdl_transform
),
535 class ent_worldinfo(Structure
):
537 _fields_
= [("pstr_name",c_uint32
),
538 ("pstr_author",c_uint32
), # unused
539 ("pstr_desc",c_uint32
), # unused
540 ("timezone",c_float
),
541 ("pstr_skybox",c_uint32
),
545 class ent_ccmd(Structure
):
547 _fields_
= [("pstr_command",c_uint32
)]
550 class ent_objective(Structure
):#{
551 _fields_
= [("transform",mdl_transform
),
552 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
554 ("id_next",c_uint32
),
555 ("filter",c_uint32
),("filter2",c_uint32
),
557 ("win_event",c_int32
),
558 ("time_limit",c_float
)]
560 sr_functions
= { 0: 'trigger',
565 class ent_challenge(Structure
):#{
566 _fields_
= [("transform",mdl_transform
),
567 ("pstr_alias",c_uint32
),
570 ("target_event",c_int32
),
572 ("reset_event",c_int32
),
575 ("status",c_uint32
)] #runtime
576 sr_functions
= { 0: 'unlock',
580 class ent_region(Structure
):#{
581 _fields_
= [("transform",mdl_transform
),
582 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
583 ("pstr_title",c_uint32
),
585 ("zone_volume",c_uint32
),
587 ("target0",c_uint32
*2)]
588 sr_functions
= { 0: 'enter', 1: 'leave' }
591 class ent_relay(Structure
):#{
592 _fields_
= [("targets",(c_uint32
*2)*4),
593 ("targets_events",c_int32
*4)]
594 sr_functions
= { 0: 'trigger' }
597 class ent_cubemap(Structure
):#{
598 _fields_
= [("co",c_float
*3),
599 ("resolution",c_uint32
), #placeholder
600 ("live",c_uint32
), #placeholder
601 ("texture_id",c_uint32
), #engine
602 ("framebuffer_id",c_uint32
),#engine
603 ("renderbuffer_id",c_uint32
),#engine
604 ("placeholder",c_uint32
*2)]
607 class ent_miniworld(Structure
):#{
608 _fields_
= [("transform",mdl_transform
),
609 ("pstr_world",c_uint32
),
613 sr_functions
= { 0: 'zone', 1: 'leave' }
616 class ent_prop(Structure
):#{
617 _fields_
= [("transform",mdl_transform
),
618 ("submesh_start",c_uint32
),
619 ("submesh_count",c_uint32
),
621 ("pstr_alias",c_uint32
)]
624 def obj_ent_type( obj
):
626 if obj
.type == 'ARMATURE': return 'mdl_armature'
627 elif obj
.type == 'LIGHT': return 'ent_light'
628 elif obj
.type == 'CAMERA': return 'ent_camera'
629 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
631 else: return obj
.SR_data
.ent_type
634 def sr_filter_ent_type( obj
, ent_types
):
636 if obj
== bpy
.context
.active_object
: return False
638 for c0
in obj
.users_collection
:#{
639 for c1
in bpy
.context
.active_object
.users_collection
:#{
641 return obj_ent_type( obj
) in ent_types
649 def v4_dot( a
, b
):#{
650 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
653 def q_identity( q
):#{
660 def q_normalize( q
):#{
662 if( l2
< 0.00001 ):#{
666 s
= 1.0/math
.sqrt(l2
)
674 def compile_obj_transform( obj
, transform
):
676 co
= obj
.matrix_world
@ Vector((0,0,0))
678 # This was changed from matrix_local on 09.05.23
679 q
= obj
.matrix_world
.to_quaternion()
685 transform
.co
[0] = co
[0]
686 transform
.co
[1] = co
[2]
687 transform
.co
[2] = -co
[1]
688 transform
.q
[0] = q
[1]
689 transform
.q
[1] = q
[3]
690 transform
.q
[2] = -q
[2]
691 transform
.q
[3] = q
[0]
692 transform
.s
[0] = s
[0]
693 transform
.s
[1] = s
[2]
694 transform
.s
[2] = s
[1]
697 def int_align_to( v
, align
):
699 while(v
%align
)!=0: v
+= 1
703 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
705 while (len(buffer) % align
) != 0: buffer.extend(w
)
709 def bytearray_print_hex( s
, w
=16 ):
711 for r
in range((len(s
)+(w
-1))//w
):#{
713 i1
=min((r
+1)*w
,len(s
))
714 print( F
'{r*w:06x}| \x1B[31m', end
='')
715 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
716 print( "\x1B[0m", end
='')
717 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
721 def sr_compile_string( s
):
723 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
725 index
= len( sr_compile
.string_data
)
726 sr_compile
.string_cache
[s
] = index
727 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
728 sr_compile
.string_data
.extend( s
.encode('utf-8') )
729 sr_compile
.string_data
.extend( b
'\0' )
731 bytearray_align_to( sr_compile
.string_data
, 4 )
737 decoded
= bytearray()
738 for i
in range(len(s
)//2):#{
739 c
= (ord(s
[i
*2+0])-0x41)
740 c |
= (ord(s
[i
*2+1])-0x41)<<4
741 decoded
.extend(bytearray(c_uint8(c
))) #??
746 def sr_pack_file( file, path
, data
):
748 file.path
= sr_compile_string( path
)
749 file.pack_offset
= len( sr_compile
.pack_data
)
750 file.pack_size
= len( data
)
752 sr_compile
.pack_data
.extend( data
)
753 bytearray_align_to( sr_compile
.pack_data
, 16 )
756 def sr_compile_texture( img
):
761 name
= os
.path
.splitext( img
.name
)[0]
763 if name
in sr_compile
.texture_cache
:
764 return sr_compile
.texture_cache
[name
]
766 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
771 if sr_compile
.pack_textures
:#{
772 filedata
= qoi_encode( img
)
773 sr_pack_file( tex
.file, name
, filedata
)
776 sr_compile
.texture_cache
[name
] = texture_index
777 sr_compile
.texture_data
.extend( bytearray(tex
) )
781 def sr_armature_bones( armature
):
783 def _recurse_bone( b
):
786 for c
in b
.children
: yield from _recurse_bone( c
)
789 for b
in armature
.data
.bones
:
791 yield from _recurse_bone( b
)
794 def sr_entity_id( obj
):#{
797 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
798 index
= sr_compile
.entity_ids
[ obj
.name
]
800 return (tipo
&0xffff)<<16 |
(index
&0xffff)
803 # Returns submesh_start,count and armature_id
804 def sr_compile_mesh_internal( obj
):
813 for mod
in obj
.modifiers
:#{
814 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
815 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
818 can_use_cache
= False
821 if mod
.type == 'ARMATURE': #{
822 armature
= mod
.object
823 rig_weight_groups
= \
824 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
825 armature_id
= sr_compile
.entity_ids
[armature
.name
]
827 POSE_OR_REST_CACHE
= armature
.data
.pose_position
828 armature
.data
.pose_position
= 'REST'
832 # Check the cache first
834 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
835 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
836 submesh_start
= ref
[0]
837 submesh_count
= ref
[1]
838 return (submesh_start
,submesh_count
,armature_id
)
841 # Compile a whole new mesh
843 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
846 dgraph
= bpy
.context
.evaluated_depsgraph_get()
847 data
= obj
.evaluated_get(dgraph
).data
848 data
.calc_loop_triangles()
849 data
.calc_normals_split()
851 # Mesh is split into submeshes based on their material
853 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
854 for material_id
, mat
in enumerate(mat_list
): #{
858 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
859 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
862 sm
.material_id
= sr_compile_material( mat
)
864 INF
=99999999.99999999
870 # Keep a reference to very very very similar vertices
871 # i have no idea how to speed it up.
873 vertex_reference
= {}
875 # Write the vertex / indice data
877 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
878 if tri
.material_index
!= material_id
: continue
881 vert
= data
.vertices
[tri
.vertices
[j
]]
883 vi
= data
.loops
[li
].vertex_index
885 # Gather vertex information
888 norm
= data
.loops
[li
].normal
890 colour
= (255,255,255,255)
897 uv
= data
.uv_layers
.active
.data
[li
].uv
901 if data
.vertex_colors
:#{
902 colour
= data
.vertex_colors
.active
.data
[li
].color
903 colour
= (int(colour
[0]*255.0),\
904 int(colour
[1]*255.0),\
905 int(colour
[2]*255.0),\
906 int(colour
[3]*255.0))
909 # Weight groups: truncates to the 3 with the most influence. The
910 # fourth bone ID is never used by the shader so it
914 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
915 if obj
.vertex_groups
[_
.group
].name
in \
918 weight_groups
= sorted( src_groups
, key
= \
919 lambda a
: a
.weight
, reverse
=True )
921 for ml
in range(3):#{
922 if len(weight_groups
) > ml
:#{
923 g
= weight_groups
[ml
]
924 name
= obj
.vertex_groups
[g
.group
].name
927 groups
[ml
] = rig_weight_groups
.index(name
)
932 if len(weight_groups
) > 0:#{
933 inv_norm
= (1.0/tot
) * 65535.0
934 for ml
in range(3):#{
935 weights
[ml
] = int( weights
[ml
] * inv_norm
)
936 weights
[ml
] = min( weights
[ml
], 65535 )
937 weights
[ml
] = max( weights
[ml
], 0 )
942 li1
= tri
.loops
[(j
+1)%3]
943 vi1
= data
.loops
[li1
].vertex_index
944 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
946 if e0
.use_freestyle_mark
and \
947 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
948 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
954 TOLERENCE
= float(10**4)
955 key
= (int(co
[0]*TOLERENCE
+0.5),
956 int(co
[1]*TOLERENCE
+0.5),
957 int(co
[2]*TOLERENCE
+0.5),
958 int(norm
[0]*TOLERENCE
+0.5),
959 int(norm
[1]*TOLERENCE
+0.5),
960 int(norm
[2]*TOLERENCE
+0.5),
961 int(uv
[0]*TOLERENCE
+0.5),
962 int(uv
[1]*TOLERENCE
+0.5),
963 colour
[0], # these guys are already quantized
976 if key
in vertex_reference
:
977 index
= vertex_reference
[key
]
979 index
= bytearray(c_uint32(sm
.vertex_count
))
982 vertex_reference
[key
] = index
992 v
.colour
[0] = colour
[0]
993 v
.colour
[1] = colour
[1]
994 v
.colour
[2] = colour
[2]
995 v
.colour
[3] = colour
[3]
996 v
.weights
[0] = weights
[0]
997 v
.weights
[1] = weights
[1]
998 v
.weights
[2] = weights
[2]
999 v
.weights
[3] = weights
[3]
1000 v
.groups
[0] = groups
[0]
1001 v
.groups
[1] = groups
[1]
1002 v
.groups
[2] = groups
[2]
1003 v
.groups
[3] = groups
[3]
1005 for i
in range(3):#{
1006 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1007 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1010 sr_compile
.vertex_data
.extend(bytearray(v
))
1013 sm
.indice_count
+= 1
1014 sr_compile
.indice_data
.extend( index
)
1018 # Make sure bounding box isn't -inf -> inf if no vertices
1020 if sm
.vertex_count
== 0:
1025 # Add submesh to encoder
1027 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1032 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1035 # Save a reference to this mesh since we want to reuse the submesh indices
1037 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1038 return (submesh_start
,submesh_count
,armature_id
)
1041 def sr_compile_mesh( obj
):
1044 compile_obj_transform(obj
, node
.transform
)
1045 node
.pstr_name
= sr_compile_string(obj
.name
)
1046 ent_type
= obj_ent_type( obj
)
1050 if ent_type
!= 'none':#{
1051 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1052 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1053 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1056 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1057 sr_compile_mesh_internal( obj
)
1059 sr_compile
.mesh_data
.extend(bytearray(node
))
1062 def sr_compile_fonts( collection
):
1064 print( F
"[SR] Compiling fonts" )
1069 for obj
in collection
.all_objects
:#{
1070 if obj_ent_type(obj
) != 'ent_font': continue
1072 data
= obj
.SR_data
.ent_font
[0]
1075 font
.alias
= sr_compile_string( data
.alias
)
1076 font
.variant_start
= variant_count
1077 font
.variant_count
= 0
1078 font
.glyph_start
= glyph_count
1080 glyph_base
= data
.glyphs
[0].utf32
1081 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1083 font
.glyph_utf32_base
= glyph_base
1084 font
.glyph_count
= glyph_range
1086 for i
in range(len(data
.variants
)):#{
1087 data_var
= data
.variants
[i
]
1088 if not data_var
.mesh
: continue
1090 mesh
= data_var
.mesh
.data
1092 variant
= ent_font_variant()
1093 variant
.name
= sr_compile_string( data_var
.tipo
)
1095 # fonts (variants) only support one material each
1097 if len(mesh
.materials
) != 0:
1098 mat
= mesh
.materials
[0]
1099 variant
.material_id
= sr_compile_material( mat
)
1101 font
.variant_count
+= 1
1103 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1104 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1106 for j
in range(len(islands
)):#{
1107 for tri
in islands
[j
]:#{
1108 centroids
[j
].x
+= tri
.center
[0]
1109 centroids
[j
].y
+= tri
.center
[2]
1112 centroids
[j
] /= len(islands
[j
])
1115 for j
in range(glyph_range
):#{
1116 data_glyph
= data
.glyphs
[j
]
1118 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1119 glyph
.indice_count
= 0
1120 glyph
.size
[0] = data_glyph
.bounds
[2]
1121 glyph
.size
[1] = data_glyph
.bounds
[3]
1123 vertex_reference
= {}
1125 for k
in range(len(islands
)):#{
1126 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1127 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1128 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1129 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1134 for l
in range(len(islands
[k
])):#{
1136 for m
in range(3):#{
1137 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1139 vi
= mesh
.loops
[li
].vertex_index
1141 # Gather vertex information
1143 co
= [vert
.co
[_
] for _
in range(3)]
1144 co
[0] -= data_glyph
.bounds
[0]
1145 co
[2] -= data_glyph
.bounds
[1]
1146 norm
= mesh
.loops
[li
].normal
1148 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1150 TOLERENCE
= float(10**4)
1151 key
= (int(co
[0]*TOLERENCE
+0.5),
1152 int(co
[1]*TOLERENCE
+0.5),
1153 int(co
[2]*TOLERENCE
+0.5),
1154 int(norm
[0]*TOLERENCE
+0.5),
1155 int(norm
[1]*TOLERENCE
+0.5),
1156 int(norm
[2]*TOLERENCE
+0.5),
1157 int(uv
[0]*TOLERENCE
+0.5),
1158 int(uv
[1]*TOLERENCE
+0.5))
1160 if key
in vertex_reference
:
1161 index
= vertex_reference
[key
]
1163 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1164 index
= bytearray(c_uint32(vindex
))
1165 vertex_reference
[key
] = index
1172 v
.norm
[2] = -norm
[1]
1176 sr_compile
.vertex_data
.extend(bytearray(v
))
1179 glyph
.indice_count
+= 1
1180 sr_compile
.indice_data
.extend( index
)
1184 sr_ent_push( glyph
)
1186 sr_ent_push( variant
)
1192 def sr_compile_menus( collection
):
1194 print( "[SR1] Compiling menus" )
1197 for obj
in collection
.all_objects
:#{
1198 if obj_ent_type(obj
) != 'ent_menuitem': continue
1199 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1201 bitmask
= 0x00000000
1203 for col
in obj
.users_collection
:#{
1205 if name
not in groups
: groups
.append( name
)
1206 bitmask |
= (0x1 << groups
.index(name
))
1209 item
= ent_menuitem()
1210 item
.type = int( obj_data
.tipo
)
1211 item
.groups
= bitmask
1213 compile_obj_transform( obj
, item
.transform
)
1214 if obj
.type == 'MESH':#{
1215 item
.submesh_start
, item
.submesh_count
, _
= \
1216 sr_compile_mesh_internal( obj
)
1219 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1220 item_button
= item
._anonymous
_union
.button
1221 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1222 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1224 elif item
.type == 0:#{
1225 item_visual
= item
._anonymous
_union
.visual
1226 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1228 elif item
.type == 3:#{
1229 item_checkmark
= item
._anonymous
_union
.checkmark
1230 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1231 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1232 delta
= obj_data
.checkmark
.location
- obj
.location
1233 item_checkmark
.offset
[0] = delta
[0]
1234 item_checkmark
.offset
[1] = delta
[2]
1235 item_checkmark
.offset
[2] = -delta
[1]
1237 elif item
.type == 4:#{
1238 item_slider
= item
._anonymous
_union
.slider
1239 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1240 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1241 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1242 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1244 elif item
.type == 5:#{
1245 item_page
= item
._anonymous
_union
.page
1246 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1247 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1248 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1250 elif item
.type == 6:#{
1251 item_binding
= item
._anonymous
_union
.binding
1252 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1253 item_binding
.font_variant
= obj_data
.font_variant
1257 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1259 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1260 if item
.type != 4:#{
1262 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1264 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1271 def sr_compile_armature( obj
):
1273 node
= mdl_armature()
1274 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1276 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1279 bones
= [_
for _
in sr_armature_bones(obj
)]
1280 bones_names
= [None]+[_
.name
for _
in bones
]
1284 if b
.use_deform
: bone
.flags
= 0x1
1285 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1287 bone
.collider
= int(b
.SR_data
.collider
)
1289 if bone
.collider
>0:#{
1290 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1291 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1292 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1293 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1294 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1295 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1298 if b
.SR_data
.cone_constraint
:#{
1300 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1301 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1302 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1303 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1304 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1305 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1306 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1307 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1308 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1309 bone
.conet
= b
.SR_data
.conet
1312 bone
.co
[0] = b
.head_local
[0]
1313 bone
.co
[1] = b
.head_local
[2]
1314 bone
.co
[2] = -b
.head_local
[1]
1315 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1316 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1317 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1318 bone
.pstr_name
= sr_compile_string( b
.name
)
1320 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1321 if c
.type == 'IK':#{
1323 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1324 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1328 node
.bone_count
+= 1
1329 sr_compile
.bone_data
.extend(bytearray(bone
))
1334 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1335 # So we can restore later
1337 previous_frame
= bpy
.context
.scene
.frame_current
1338 previous_action
= obj
.animation_data
.action
1339 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1340 obj
.data
.pose_position
= 'POSE'
1342 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1343 for NLAStrip
in NLALayer
.strips
:#{
1346 for a
in bpy
.data
.actions
:#{
1347 if a
.name
== NLAStrip
.name
:#{
1348 obj
.animation_data
.action
= a
1353 # Clip to NLA settings
1355 anim_start
= int(NLAStrip
.action_frame_start
)
1356 anim_end
= int(NLAStrip
.action_frame_end
)
1360 anim
= mdl_animation()
1361 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1363 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1364 sizeof(mdl_transform
)
1365 anim
.length
= anim_end
-anim_start
1368 # Export the keyframes
1369 for frame
in range(anim_start
,anim_end
):#{
1370 bpy
.context
.scene
.frame_set(frame
)
1373 pb
= obj
.pose
.bones
[rb
.name
]
1375 # relative bone matrix
1376 if rb
.parent
is not None:#{
1377 offset_mtx
= rb
.parent
.matrix_local
1378 offset_mtx
= offset_mtx
.inverted_safe() @ \
1381 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1382 inv_parent
.invert_safe()
1383 fpm
= inv_parent
@ pb
.matrix
1386 bone_mtx
= rb
.matrix
.to_4x4()
1387 local_inv
= rb
.matrix_local
.inverted_safe()
1388 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1391 loc
, rot
, sca
= fpm
.decompose()
1394 lc_m
= pb
.matrix_channel
.to_3x3()
1395 if pb
.parent
is not None:#{
1396 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1397 lc_m
= smtx
.inverted() @ lc_m
1399 rq
= lc_m
.to_quaternion()
1402 kf
= mdl_transform()
1413 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1419 # Add to animation buffer
1421 sr_compile
.anim_data
.extend(bytearray(anim
))
1422 node
.anim_count
+= 1
1426 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1430 # Restore context to how it was before
1432 bpy
.context
.scene
.frame_set( previous_frame
)
1433 obj
.animation_data
.action
= previous_action
1434 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1437 sr_compile
.armature_data
.extend(bytearray(node
))
1440 def sr_ent_push( struct
):
1442 clase
= type(struct
).__name
__
1444 if clase
not in sr_compile
.entity_data
:#{
1445 sr_compile
.entity_data
[ clase
] = bytearray()
1446 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1449 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1450 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1454 def sr_array_title( arr
, name
, count
, size
, offset
):
1456 for i
in range(len(name
)):#{
1457 arr
.name
[i
] = ord(name
[i
])
1459 arr
.file_offset
= offset
1460 arr
.item_count
= count
1461 arr
.item_size
= size
1468 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1473 def sr_compile( collection
):
1475 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1479 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1480 sr_compile
.pack_animations
= collection
.SR_data
.animations
1483 sr_compile
.string_cache
= {}
1484 sr_compile
.mesh_cache
= {}
1485 sr_compile
.material_cache
= {}
1486 sr_compile
.texture_cache
= {}
1489 sr_compile
.mesh_data
= bytearray()
1490 sr_compile
.submesh_data
= bytearray()
1491 sr_compile
.vertex_data
= bytearray()
1492 sr_compile
.indice_data
= bytearray()
1493 sr_compile
.bone_data
= bytearray()
1494 sr_compile
.material_data
= bytearray()
1495 sr_compile
.shader_data
= bytearray()
1496 sr_compile
.armature_data
= bytearray()
1497 sr_compile
.anim_data
= bytearray()
1498 sr_compile
.keyframe_data
= bytearray()
1499 sr_compile
.texture_data
= bytearray()
1501 # just bytes not structures
1502 sr_compile
.string_data
= bytearray()
1503 sr_compile
.pack_data
= bytearray()
1506 sr_compile
.entity_data
= {}
1507 sr_compile
.entity_info
= {}
1509 print( F
"[SR] assign entity ID's" )
1510 sr_compile
.entities
= {}
1511 sr_compile
.entity_ids
= {}
1514 # -------------------------------------------------------
1516 sr_compile_string( "null" )
1519 for obj
in collection
.all_objects
: #{
1520 if obj
.type == 'MESH':#{
1524 ent_type
= obj_ent_type( obj
)
1525 if ent_type
== 'none': continue
1527 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1528 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1529 sr_compile
.entities
[ent_type
] += [obj
]
1532 print( F
"[SR] Compiling geometry" )
1534 for obj
in collection
.all_objects
:#{
1535 if obj
.type == 'MESH':#{
1538 ent_type
= obj_ent_type( obj
)
1540 # entity ignore mesh list
1542 if ent_type
== 'ent_traffic': continue
1543 if ent_type
== 'ent_prop': continue
1544 if ent_type
== 'ent_font': continue
1545 if ent_type
== 'ent_font_variant': continue
1546 if ent_type
== 'ent_menuitem': continue
1547 if ent_type
== 'ent_objective': continue
1548 if ent_type
== 'ent_region': continue
1550 #TODO: This is messy.
1551 if ent_type
== 'ent_gate':#{
1552 obj_data
= obj
.SR_data
.ent_gate
[0]
1553 if obj_data
.custom
: continue
1555 #--------------------------
1557 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1558 sr_compile_mesh( obj
)
1562 audio_clip_count
= 0
1563 entity_file_ref_count
= 0
1565 for ent_type
, arr
in sr_compile
.entities
.items():#{
1566 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1568 for i
in range(len(arr
)):#{
1571 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1573 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1574 elif ent_type
== 'ent_light': #{
1576 compile_obj_transform( obj
, light
.transform
)
1577 light
.daytime
= obj
.data
.SR_data
.daytime
1578 if obj
.data
.type == 'POINT':#{
1581 elif obj
.data
.type == 'SPOT':#{
1583 light
.angle
= obj
.data
.spot_size
*0.5
1585 light
.range = obj
.data
.cutoff_distance
1586 light
.colour
[0] = obj
.data
.color
[0]
1587 light
.colour
[1] = obj
.data
.color
[1]
1588 light
.colour
[2] = obj
.data
.color
[2]
1589 light
.colour
[3] = obj
.data
.energy
1590 sr_ent_push( light
)
1592 elif ent_type
== 'ent_camera': #{
1594 compile_obj_transform( obj
, cam
.transform
)
1595 cam
.fov
= obj
.data
.angle
* 45.0
1598 elif ent_type
== 'ent_gate': #{
1600 obj_data
= obj
.SR_data
.ent_gate
[0]
1601 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1605 if obj_data
.tipo
== 'default':#{
1606 if obj_data
.target
:#{
1607 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1611 elif obj_data
.tipo
== 'nonlocal':#{
1613 gate
.key
= sr_compile_string(obj_data
.key
)
1617 if obj_data
.flip
: flags |
= 0x0004
1618 if obj_data
.custom
:#{
1620 gate
.submesh_start
, gate
.submesh_count
, _
= \
1621 sr_compile_mesh_internal( obj
)
1623 if obj_data
.locked
: flags |
= 0x0010
1626 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1627 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1628 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1630 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1631 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1633 if obj_data
.target
:#{
1634 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1635 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1640 for x
in range(2):#{
1641 gate
.co
[x
][0] = co
[x
][0]
1642 gate
.co
[x
][1] = co
[x
][2]
1643 gate
.co
[x
][2] = -co
[x
][1]
1644 gate
.q
[x
][0] = q
[x
][1]
1645 gate
.q
[x
][1] = q
[x
][3]
1646 gate
.q
[x
][2] = -q
[x
][2]
1647 gate
.q
[x
][3] = q
[x
][0]
1652 elif ent_type
== 'ent_spawn': #{
1654 compile_obj_transform( obj
, spawn
.transform
)
1655 obj_data
= obj
.SR_data
.ent_spawn
[0]
1656 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1657 sr_ent_push( spawn
)
1659 elif ent_type
== 'ent_water':#{
1661 compile_obj_transform( obj
, water
.transform
)
1662 water
.max_dist
= 0.0
1663 sr_ent_push( water
)
1665 elif ent_type
== 'ent_audio':#{
1666 obj_data
= obj
.SR_data
.ent_audio
[0]
1668 compile_obj_transform( obj
, audio
.transform
)
1669 audio
.clip_start
= audio_clip_count
1670 audio
.clip_count
= len(obj_data
.files
)
1671 audio_clip_count
+= audio
.clip_count
1672 audio
.max_channels
= obj_data
.max_channels
1673 audio
.volume
= obj_data
.volume
1676 # - allow/disable doppler
1677 # - channel group tags with random colours
1678 # - transition properties
1680 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1681 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1682 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1683 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1684 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1685 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1686 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1688 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1689 if audio
.channel_behaviour
>= 1:#{
1690 audio
.group
= obj_data
.group
1692 if audio
.channel_behaviour
== 2:#{
1693 audio
.crossfade
= obj_data
.transition_duration
1695 audio
.probability_curve
= int(obj_data
.probability_curve
)
1697 for ci
in range(audio
.clip_count
):#{
1698 entry
= obj_data
.files
[ci
]
1699 clip
= ent_audio_clip()
1700 clip
.probability
= entry
.probability
1701 if obj_data
.formato
== '2':#{
1702 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1705 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1706 clip
._anon
.file.pack_offset
= 0
1707 clip
._anon
.file.pack_size
= 0
1711 sr_ent_push( audio
)
1713 elif ent_type
== 'ent_volume':#{
1714 obj_data
= obj
.SR_data
.ent_volume
[0]
1715 volume
= ent_volume()
1716 volume
.type = int(obj_data
.subtype
)
1717 compile_obj_transform( obj
, volume
.transform
)
1719 if obj_data
.target
:#{
1720 volume
.target
= sr_entity_id( obj_data
.target
)
1721 volume
._anon
.trigger
.event
= obj_data
.target_event
1722 volume
._anon
.trigger
.event_leave
= obj_data
.target_event_leave
1727 elif ent_type
== 'ent_marker':#{
1728 marker
= ent_marker()
1729 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1730 compile_obj_transform( obj
, marker
.transform
)
1733 elif ent_type
== 'ent_skateshop':#{
1734 skateshop
= ent_skateshop()
1735 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1736 skateshop
.type = int(obj_data
.tipo
)
1737 if skateshop
.type == 0:#{
1738 boardshop
= skateshop
._anonymous
_union
.boards
1739 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1740 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1741 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1743 elif skateshop
.type == 1:#{
1744 charshop
= skateshop
._anonymous
_union
.character
1745 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1746 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1748 elif skateshop
.type == 2:#{
1749 worldshop
= skateshop
._anonymous
_union
.worlds
1750 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1751 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1753 elif skateshop
.type == 3:#{
1754 server
= skateshop
._anonymous
_union
.server
1755 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1757 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1758 compile_obj_transform( obj
, skateshop
.transform
)
1759 sr_ent_push(skateshop
)
1761 elif ent_type
== 'ent_swspreview':#{
1762 workshop_preview
= ent_swspreview()
1763 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1764 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1765 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1766 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1767 sr_ent_push( workshop_preview
)
1769 elif ent_type
== 'ent_worldinfo':#{
1770 worldinfo
= ent_worldinfo()
1771 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1772 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1773 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1774 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1778 if obj_data
.fix_time
:#{
1779 worldinfo
.timezone
= obj_data
.fixed_time
1783 worldinfo
.timezone
= obj_data
.timezone
1785 if obj_data
.water_safe
:
1788 worldinfo
.flags
= flags
1789 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1790 sr_ent_push( worldinfo
)
1792 elif ent_type
== 'ent_ccmd':#{
1794 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1795 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1798 elif ent_type
== 'ent_objective':#{
1799 objective
= ent_objective()
1800 obj_data
= obj
.SR_data
.ent_objective
[0]
1801 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
1802 objective
.id_win
= sr_entity_id( obj_data
.target
)
1803 objective
.win_event
= obj_data
.target_event
1804 objective
.filter = int(obj_data
.filtrar
)
1805 objective
.filter2
= 0
1806 objective
.time_limit
= obj_data
.time_limit
1808 compile_obj_transform( obj
, objective
.transform
)
1809 objective
.submesh_start
, objective
.submesh_count
, _
= \
1810 sr_compile_mesh_internal( obj
)
1812 sr_ent_push( objective
)
1814 elif ent_type
== 'ent_challenge':#{
1815 challenge
= ent_challenge()
1816 obj_data
= obj
.SR_data
.ent_challenge
[0]
1817 compile_obj_transform( obj
, challenge
.transform
)
1818 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1819 challenge
.target
= sr_entity_id( obj_data
.target
)
1820 challenge
.target_event
= obj_data
.target_event
1821 challenge
.reset
= sr_entity_id( obj_data
.reset
)
1822 challenge
.reset_event
= obj_data
.reset_event
1823 challenge
.first
= sr_entity_id( obj_data
.first
)
1824 challenge
.flags
= 0x00
1825 challenge
.camera
= sr_entity_id( obj_data
.camera
)
1826 if obj_data
.time_limit
: challenge
.flags |
= 0x01
1827 challenge
.status
= 0
1828 sr_ent_push( challenge
)
1830 elif ent_type
== 'ent_region':#{
1831 region
= ent_region()
1832 obj_data
= obj
.SR_data
.ent_region
[0]
1833 compile_obj_transform( obj
, region
.transform
)
1834 region
.submesh_start
, region
.submesh_count
, _
= \
1835 sr_compile_mesh_internal( obj
)
1836 region
.pstr_title
= sr_compile_string( obj_data
.title
)
1837 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
1838 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
1839 region
.target0
[1] = obj_data
.target0_event
1840 sr_ent_push( region
)
1842 elif ent_type
== 'ent_relay':#{
1844 obj_data
= obj
.SR_data
.ent_relay
[0]
1845 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
1846 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
1847 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
1848 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
1849 relay
.targets
[0][1] = obj_data
.target0_event
1850 relay
.targets
[1][1] = obj_data
.target1_event
1851 relay
.targets
[2][1] = obj_data
.target2_event
1852 relay
.targets
[3][1] = obj_data
.target3_event
1853 sr_ent_push( relay
)
1855 # elif ent_type == 'ent_list':#{
1856 # lista = ent_list()
1857 # obj_data = obj.SR_data.ent_list[0]
1859 # lista.entity_ref_start = entity_file_ref_count
1860 # lista.entity_ref_count = len( obj_data.entities )
1861 # entity_file_ref_count += lista.entity_ref_count
1863 # for child in obj_data.entities:#{
1864 # reference_struct = file_entity_ref()
1865 # reference_struct.index = sr_entity_id( child.target )
1866 # sr_ent_push( reference_struct )
1869 # sr_ent_push( lista )
1871 elif ent_type
== 'ent_glider':#{
1872 glider
= ent_glider()
1873 compile_obj_transform( obj
, glider
.transform
)
1874 sr_ent_push( glider
)
1876 elif ent_type
== 'ent_npc':#{
1877 obj_data
= obj
.SR_data
.ent_npc
[0]
1879 compile_obj_transform( obj
, npc
.transform
)
1880 npc
.id = obj_data
.au
1881 npc
.context
= obj_data
.context
1882 npc
.camera
= sr_entity_id( obj_data
.cam
)
1885 elif ent_type
== 'ent_cubemap':#{
1886 cubemap
= ent_cubemap()
1887 co
= obj
.matrix_world
@ Vector((0,0,0))
1888 cubemap
.co
[0] = co
[0]
1889 cubemap
.co
[1] = co
[2]
1890 cubemap
.co
[2] = -co
[1]
1891 cubemap
.resolution
= 0
1893 sr_ent_push( cubemap
)
1895 elif ent_type
== 'ent_miniworld':#{
1896 miniworld
= ent_miniworld()
1897 obj_data
= obj
.SR_data
.ent_miniworld
[0]
1899 compile_obj_transform( obj
, miniworld
.transform
)
1900 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
1901 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
1902 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
1903 sr_ent_push( miniworld
)
1905 elif ent_type
== 'ent_prop':#{
1907 obj_data
= obj
.SR_data
.ent_prop
[0]
1908 compile_obj_transform( obj
, prop
.transform
)
1909 prop
.submesh_start
, prop
.submesh_count
, _
= \
1910 sr_compile_mesh_internal( obj
)
1911 prop
.flags
= obj_data
.flags
1912 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1918 sr_compile_menus( collection
)
1919 sr_compile_fonts( collection
)
1921 def _children( col
):#{
1923 for c
in col
.children
:#{
1924 yield from _children(c
)
1928 checkpoint_count
= 0
1929 pathindice_count
= 0
1932 for col
in _children(collection
):#{
1933 print( F
"Adding routes for subcollection: {col.name}" )
1939 for obj
in col
.objects
:#{
1940 if obj
.type == 'ARMATURE': pass
1942 ent_type
= obj_ent_type( obj
)
1944 if ent_type
== 'ent_gate':
1945 route_gates
+= [obj
]
1946 elif ent_type
== 'ent_route_node':#{
1947 if obj
.type == 'CURVE':#{
1948 route_curves
+= [obj
]
1951 elif ent_type
== 'ent_route':
1953 elif ent_type
== 'ent_traffic':
1958 dij
= create_node_graph( route_curves
, route_gates
)
1960 for obj
in routes
:#{
1961 obj_data
= obj
.SR_data
.ent_route
[0]
1963 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1964 route
.checkpoints_start
= checkpoint_count
1965 route
.checkpoints_count
= 0
1966 route
.id_camera
= sr_entity_id( obj_data
.cam
)
1969 route
.colour
[ci
] = obj_data
.colour
[ci
]
1970 route
.colour
[3] = 1.0
1972 compile_obj_transform( obj
, route
.transform
)
1973 checkpoints
= obj_data
.gates
1975 for i
in range(len(checkpoints
)):#{
1976 gi
= checkpoints
[i
].target
1977 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1981 dest
= gi
.SR_data
.ent_gate
[0].target
1985 if gi
==gj
: continue # error?
1986 if not gi
or not gj
: continue
1988 checkpoint
= ent_checkpoint()
1989 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1990 checkpoint
.path_start
= pathindice_count
1991 checkpoint
.path_count
= 0
1993 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1996 for pi
in range(len(path
)):#{
1997 pathindice
= ent_path_index()
1998 pathindice
.index
= routenode_count
+ path
[pi
]
1999 sr_ent_push( pathindice
)
2001 checkpoint
.path_count
+= 1
2002 pathindice_count
+= 1
2006 sr_ent_push( checkpoint
)
2007 route
.checkpoints_count
+= 1
2008 checkpoint_count
+= 1
2011 sr_ent_push( route
)
2014 for obj
in traffics
:#{
2015 traffic
= ent_traffic()
2016 compile_obj_transform( obj
, traffic
.transform
)
2017 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2018 sr_compile_mesh_internal( obj
)
2020 # find best subsection
2022 graph_keys
= list(dij
.graph
)
2026 for j
in range(len(dij
.points
)):#{
2027 point
= dij
.points
[j
]
2028 dist
= (point
-obj
.location
).magnitude
2030 if dist
< min_dist
:#{
2037 best_begin
= best_point
2038 best_end
= best_point
2041 map0
= dij
.subsections
[best_begin
]
2042 if map0
[1] == -1: break
2043 best_begin
= map0
[1]
2046 map1
= dij
.subsections
[best_end
]
2047 if map1
[2] == -1: break
2051 traffic
.start_node
= routenode_count
+ best_begin
2052 traffic
.node_count
= best_end
- best_begin
2053 traffic
.index
= best_point
- best_begin
2054 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2057 sr_ent_push(traffic
)
2060 for point
in dij
.points
:#{
2061 rn
= ent_route_node()
2064 rn
.co
[2] = -point
[1]
2068 routenode_count
+= len(dij
.points
)
2071 print( F
"[SR] Writing file" )
2073 file_array_instructions
= {}
2076 def _write_array( name
, item_size
, data
):#{
2077 nonlocal file_array_instructions
, file_offset
2079 count
= len(data
)//item_size
2080 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2081 'data':data
, 'offset': file_offset
}
2082 file_offset
+= len(data
)
2083 file_offset
= int_align_to( file_offset
, 8 )
2086 _write_array( 'strings', 1, sr_compile
.string_data
)
2087 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2088 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2089 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2090 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2091 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2092 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2094 for name
, buffer in sr_compile
.entity_data
.items():#{
2095 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2098 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2099 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2100 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2101 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2102 _write_array( 'pack', 1, sr_compile
.pack_data
)
2103 _write_array( 'shader_data', 1, sr_compile
.shader_data
)
2105 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2106 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2108 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2109 path
= F
"{folder}{collection.name}.mdl"
2112 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2113 fp
= open( path
, "wb" )
2114 header
= mdl_header()
2115 header
.version
= MDL_VERSION_NR
2116 sr_array_title( header
.arrays
, \
2117 'index', len(file_array_instructions
), \
2118 sizeof(mdl_array
), header_size
)
2120 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2122 print( F
'[SR] {"name":>16}| count | offset' )
2124 for name
,info
in file_array_instructions
.items():#{
2126 offset
= info
['offset'] + header_size
+ index_size
2127 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2128 index
.extend( bytearray(arr
) )
2130 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2131 F
' 0x{info["offset"]:02x}' )
2133 fp
.write( bytearray_align_to( index
, 8 ) )
2134 #bytearray_print_hex( index )
2136 for name
,info
in file_array_instructions
.items():#{
2137 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2142 print( '[SR] done' )
2145 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2147 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2148 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2149 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2151 panel
: bpy
.props
.EnumProperty(
2155 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2156 ('ENTITY', 'Entity', '', 'MONKEY',1),
2157 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2162 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2164 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2165 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2168 def sr_get_mirror_bone( bones
):
2170 side
= bones
.active
.name
[-1:]
2171 other_name
= bones
.active
.name
[:-1]
2172 if side
== 'L': other_name
+= 'R'
2173 elif side
== 'R': other_name
+= 'L'
2177 if b
.name
== other_name
:
2184 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2186 bl_idname
="skaterift.mirror_bone"
2187 bl_label
="Mirror bone attributes - SkateRift"
2189 def execute(_
,context
):
2191 active_object
= context
.active_object
2192 bones
= active_object
.data
.bones
2194 b
= sr_get_mirror_bone( bones
)
2196 if not b
: return {'FINISHED'}
2198 b
.SR_data
.collider
= a
.SR_data
.collider
2200 def _v3copyflipy( a
, b
):#{
2206 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2207 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2208 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2209 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2211 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2213 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2214 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2215 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2217 b
.SR_data
.conet
= a
.SR_data
.conet
2220 ob
= bpy
.context
.scene
.objects
[0]
2221 ob
.hide_render
= ob
.hide_render
2226 class SR_COMPILE(bpy
.types
.Operator
):
2228 bl_idname
="skaterift.compile_all"
2229 bl_label
="Compile All"
2231 def execute(_
,context
):
2233 view_layer
= bpy
.context
.view_layer
2234 for col
in view_layer
.layer_collection
.children
["export"].children
:
2235 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2236 sr_compile( bpy
.data
.collections
[col
.name
] )
2242 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2244 bl_idname
="skaterift.compile_this"
2245 bl_label
="Compile This collection"
2247 def execute(_
,context
):
2249 col
= bpy
.context
.collection
2256 class SR_INTERFACE(bpy
.types
.Panel
):
2258 bl_idname
= "VIEW3D_PT_skate_rift"
2259 bl_label
= "Skate Rift"
2260 bl_space_type
= 'VIEW_3D'
2261 bl_region_type
= 'UI'
2262 bl_category
= "Skate Rift"
2264 def draw(_
, context
):
2268 row
= _
.layout
.row()
2270 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2272 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2273 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2275 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2276 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2277 col
= bpy
.context
.collection
2279 found_in_export
= False
2281 view_layer
= bpy
.context
.view_layer
2282 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2283 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2286 if c1
.name
== col
.name
: #{
2287 found_in_export
= True
2291 box
= _
.layout
.box()
2293 row
.alignment
= 'CENTER'
2296 if found_in_export
: #{
2297 row
.label( text
=col
.name
+ ".mdl" )
2298 box
.prop( col
.SR_data
, "pack_textures" )
2299 box
.prop( col
.SR_data
, "animations" )
2300 box
.operator( "skaterift.compile_this" )
2304 row
.label( text
=col
.name
)
2308 row
.alignment
= 'CENTER'
2310 row
.label( text
="This collection is not in the export group" )
2313 box
= _
.layout
.box()
2316 split
= row
.split( factor
=0.3, align
=True )
2317 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2320 if export_count
== 0:
2322 row1
.operator( "skaterift.compile_all", \
2323 text
=F
"Compile all ({export_count} collections)" )
2325 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2326 active_object
= context
.active_object
2327 if not active_object
: return
2329 amount
= max( 0, len(context
.selected_objects
)-1 )
2331 row
= _
.layout
.row()
2332 row
.operator( 'skaterift.copy_entity_data', \
2333 text
=F
'Copy entity data to {amount} other objects' )
2334 if amount
== 0: row
.enabled
=False
2336 box
= _
.layout
.box()
2338 row
.alignment
= 'CENTER'
2339 row
.label( text
=active_object
.name
)
2342 def _draw_prop_collection( source
, data
): #{
2345 row
.alignment
= 'CENTER'
2348 row
.label( text
=F
'{source}' )
2350 if hasattr(type(data
[0]),'sr_inspector'):#{
2351 type(data
[0]).sr_inspector( box
, data
)
2354 for a
in data
[0].__annotations
__:
2355 box
.prop( data
[0], a
)
2359 if active_object
.type == 'ARMATURE': #{
2360 if active_object
.mode
== 'POSE': #{
2361 bones
= active_object
.data
.bones
2362 mb
= sr_get_mirror_bone( bones
)
2364 box
.operator( "skaterift.mirror_bone", \
2365 text
=F
'Mirror attributes to {mb.name}' )
2368 _draw_prop_collection( \
2369 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2370 [bones
.active
.SR_data
] )
2374 row
.alignment
='CENTER'
2377 row
.label( text
="Enter pose mode to modify bone properties" )
2380 elif active_object
.type == 'LIGHT': #{
2381 _draw_prop_collection( \
2382 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2383 [active_object
.data
.SR_data
] )
2385 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2386 box
.prop( active_object
.SR_data
, "ent_type" )
2387 ent_type
= active_object
.SR_data
.ent_type
2389 col
= getattr( active_object
.SR_data
, ent_type
, None )
2390 if col
!= None and len(col
)!=0:
2391 _draw_prop_collection( \
2392 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2395 if active_object
.type == 'MESH':#{
2396 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2397 if col
!= None and len(col
)!=0:
2398 _draw_prop_collection( \
2399 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2407 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2409 bl_label
="Skate Rift material"
2410 bl_idname
="MATERIAL_PT_sr_material"
2411 bl_space_type
='PROPERTIES'
2412 bl_region_type
='WINDOW'
2413 bl_context
="material"
2415 def draw(_
,context
):
2417 active_object
= bpy
.context
.active_object
2418 if active_object
== None: return
2419 active_mat
= active_object
.active_material
2420 if active_mat
== None: return
2422 info
= material_info( active_mat
)
2424 if 'tex_diffuse' in info
:#{
2425 _
.layout
.label( icon
='INFO', \
2426 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2429 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2430 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2431 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2433 if active_mat
.SR_data
.collision
:#{
2434 box
= _
.layout
.box()
2437 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2438 (active_mat
.SR_data
.shader
!= 'boundary') and \
2439 (active_mat
.SR_data
.shader
!= 'walking'):#{
2440 row
.prop( active_mat
.SR_data
, "skate_surface" )
2441 row
.prop( active_mat
.SR_data
, "grind_surface" )
2442 row
.prop( active_mat
.SR_data
, "grow_grass" )
2443 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2447 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2448 box
= _
.layout
.box()
2449 box
.prop( active_mat
.SR_data
, "blend_offset" )
2450 box
.prop( active_mat
.SR_data
, "sand_colour" )
2452 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2453 box
= _
.layout
.box()
2454 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2455 box
.prop( active_mat
.SR_data
, "blend_offset" )
2457 elif active_mat
.SR_data
.shader
== "water":#{
2458 box
= _
.layout
.box()
2459 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2460 box
.prop( active_mat
.SR_data
, "shore_colour" )
2461 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2462 box
.prop( active_mat
.SR_data
, "water_fog" )
2463 box
.prop( active_mat
.SR_data
, "water_fresnel" )
2464 box
.prop( active_mat
.SR_data
, "water_scale" )
2465 box
.prop( active_mat
.SR_data
, "water_rate" )
2467 elif active_mat
.SR_data
.shader
== "cubemap":#{
2468 box
= _
.layout
.box()
2469 box
.prop( active_mat
.SR_data
, "cubemap" )
2470 box
.prop( active_mat
.SR_data
, "tint" )
2473 _
.layout
.label( text
="" )
2474 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2475 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2479 def sr_get_type_enum( scene
, context
):
2481 items
= [('none','None',"")]
2482 mesh_entities
=['ent_gate','ent_water']
2483 point_entities
=['ent_spawn','ent_route_node','ent_route']
2485 for e
in point_entities
: items
+= [(e
,e
,'')]
2487 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2488 if context
.active_object
.type == 'MESH': #{
2489 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2493 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2499 def sr_on_type_change( _
, context
):
2501 obj
= context
.active_object
2502 ent_type
= obj
.SR_data
.ent_type
2503 if ent_type
== 'none': return
2504 if obj
.type == 'MESH':#{
2505 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2506 if col
!= None and len(col
)==0: col
.add()
2509 col
= getattr( obj
.SR_data
, ent_type
, None )
2510 if col
!= None and len(col
)==0: col
.add()
2513 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2515 alias
: bpy
.props
.StringProperty( name
='alias' )
2518 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2520 target
: bpy
.props
.PointerProperty( \
2521 type=bpy
.types
.Object
, name
="destination", \
2522 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2524 key
: bpy
.props
.StringProperty()
2525 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2526 ('nonlocal', 'Non-Local', "")))
2528 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2529 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2530 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2533 def sr_inspector( layout
, data
):
2536 box
.prop( data
[0], 'tipo', text
="subtype" )
2538 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2539 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2542 flags
.prop( data
[0], 'flip' )
2543 flags
.prop( data
[0], 'custom' )
2544 flags
.prop( data
[0], 'locked' )
2548 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2550 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2553 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2555 target
: bpy
.props
.PointerProperty( \
2556 type=bpy
.types
.Object
, name
='target', \
2557 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2560 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2562 world
: bpy
.props
.StringProperty( name
='world UID' )
2563 proxy
: bpy
.props
.PointerProperty( \
2564 type=bpy
.types
.Object
, name
='proxy', \
2565 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2566 camera
: bpy
.props
.PointerProperty( \
2567 type=bpy
.types
.Object
, name
="Camera", \
2568 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2571 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2573 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2575 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2577 layout
.prop( item
, 'target', text
='', emboss
=False )
2581 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2583 active_object
= context
.active_object
2584 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2585 lista
= getattr(data
,collection_name
)
2586 index
= getattr(data
,F
'{collection_name}_index')
2590 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2594 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2596 active_object
= context
.active_object
2597 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2601 def copy_propgroup( de
, to
):
2603 for a
in de
.__annotations
__:#{
2604 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2608 while len(cb
) != len(ca
):#{
2609 if len(cb
) < len(ca
): cb
.add()
2612 for i
in range(len(ca
)):#{
2613 copy_propgroup(ca
[i
],cb
[i
])
2617 setattr(to
,a
,getattr(de
,a
))
2622 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2624 bl_idname
= "skaterift.copy_entity_data"
2625 bl_label
= "Copy entity data"
2627 def execute(self
, context
):#{
2628 data
= context
.active_object
.SR_data
2629 new_type
= data
.ent_type
2630 print( F
"Copy entity data from: {context.active_object.name}" )
2632 for obj
in context
.selected_objects
:#{
2633 if obj
!= context
.active_object
:#{
2634 print( F
" To: {obj.name}" )
2636 obj
.SR_data
.ent_type
= new_type
2638 if active_object
.type == 'MESH':#{
2639 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2640 if col
!= None and len(col
)==0: col
.add()
2641 mdata
= context
.active_object
.data
.SR_data
2642 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2645 col
= getattr( obj
.SR_data
, new_type
, None )
2646 if col
!= None and len(col
)==0: col
.add()
2647 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2654 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2656 bl_idname
= "skaterift.new_entry"
2657 bl_label
= "Add gate"
2659 def execute(self
, context
):#{
2660 return internal_listadd_execute(self
,context
,'ent_route','gates')
2664 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2666 bl_idname
= "skaterift.del_entry"
2667 bl_label
= "Remove gate"
2670 def poll(cls
, context
):#{
2671 active_object
= context
.active_object
2672 if obj_ent_type(active_object
) == 'ent_route':#{
2673 return active_object
.SR_data
.ent_route
[0].gates
2678 def execute(self
, context
):#{
2679 return internal_listdel_execute(self
,context
,'ent_route','gates')
2683 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2685 bl_idname
= "skaterift.al_new_entry"
2686 bl_label
= "Add file"
2688 def execute(self
, context
):#{
2689 return internal_listadd_execute(self
,context
,'ent_audio','files')
2693 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2695 bl_idname
= "skaterift.al_del_entry"
2696 bl_label
= "Remove file"
2699 def poll(cls
, context
):#{
2700 active_object
= context
.active_object
2701 if obj_ent_type(active_object
) == 'ent_audio':#{
2702 return active_object
.SR_data
.ent_audio
[0].files
2707 def execute(self
, context
):#{
2708 return internal_listdel_execute(self
,context
,'ent_audio','files')
2713 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2715 bl_idname
= "skaterift.gl_new_entry"
2716 bl_label
= "Add glyph"
2718 def execute(self
, context
):#{
2719 active_object
= context
.active_object
2721 font
= active_object
.SR_data
.ent_font
[0]
2724 if len(font
.glyphs
) > 1:#{
2725 prev
= font
.glyphs
[-2]
2726 cur
= font
.glyphs
[-1]
2728 cur
.bounds
= prev
.bounds
2729 cur
.utf32
= prev
.utf32
+1
2736 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2738 bl_idname
= "skaterift.gl_del_entry"
2739 bl_label
= "Remove Glyph"
2742 def poll(cls
, context
):#{
2743 active_object
= context
.active_object
2744 if obj_ent_type(active_object
) == 'ent_font':#{
2745 return active_object
.SR_data
.ent_font
[0].glyphs
2750 def execute(self
, context
):#{
2751 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2755 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2757 bl_idname
= "skaterift.gl_move_item"
2759 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2760 ('DOWN', 'Down', ""),))
2763 def poll(cls
, context
):#{
2764 active_object
= context
.active_object
2765 if obj_ent_type(active_object
) == 'ent_font':#{
2766 return active_object
.SR_data
.ent_font
[0].glyphs
2771 def execute(_
, context
):#{
2772 active_object
= context
.active_object
2773 data
= active_object
.SR_data
.ent_font
[0]
2775 index
= data
.glyphs_index
2776 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2777 data
.glyphs
.move( neighbor
, index
)
2779 list_length
= len(data
.glyphs
) - 1
2780 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2782 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2788 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2790 bl_idname
= "skaterift.fv_new_entry"
2791 bl_label
= "Add variant"
2793 def execute(self
, context
):#{
2794 return internal_listadd_execute(self
,context
,'ent_font','variants')
2798 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2800 bl_idname
= "skaterift.fv_del_entry"
2801 bl_label
= "Remove variant"
2804 def poll(cls
, context
):#{
2805 active_object
= context
.active_object
2806 if obj_ent_type(active_object
) == 'ent_font':#{
2807 return active_object
.SR_data
.ent_font
[0].variants
2812 def execute(self
, context
):#{
2813 return internal_listdel_execute(self
,context
,'ent_font','variants')
2817 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2819 path
: bpy
.props
.StringProperty( name
="Path" )
2820 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2823 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2825 bl_idname
= 'SR_UL_AUDIO_LIST'
2827 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2829 split
= layout
.split(factor
=0.7)
2831 c
.prop( item
, 'path', text
='', emboss
=False )
2833 c
.prop( item
, 'probability', text
='%', emboss
=True )
2837 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2839 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2841 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2843 layout
.prop( item
, 'mesh', emboss
=False )
2844 layout
.prop( item
, 'tipo' )
2848 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2850 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2852 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2854 s0
= layout
.split(factor
=0.3)
2856 s1
= c
.split(factor
=0.3)
2859 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2863 c
.prop( item
, 'utf32', text
='', emboss
=True )
2866 row
.prop( item
, 'bounds', text
='', emboss
=False )
2870 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2872 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2873 gates_index
: bpy
.props
.IntProperty()
2875 colour
: bpy
.props
.FloatVectorProperty( \
2879 default
=Vector((0.79,0.63,0.48)),\
2880 description
="Route colour"\
2883 alias
: bpy
.props
.StringProperty(\
2885 default
="Untitled Course")
2887 cam
: bpy
.props
.PointerProperty( \
2888 type=bpy
.types
.Object
, name
="Viewpoint", \
2889 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2892 def sr_inspector( layout
, data
):
2894 layout
.prop( data
[0], 'alias' )
2895 layout
.prop( data
[0], 'colour' )
2896 layout
.prop( data
[0], 'cam' )
2898 layout
.label( text
='Checkpoints' )
2899 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2900 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2903 row
.operator( 'skaterift.new_entry', text
='Add' )
2904 row
.operator( 'skaterift.del_entry', text
='Remove' )
2909 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
2910 bl_idname
= "skaterift.ent_list_new_entry"
2911 bl_label
= "Add entity"
2913 def execute(self
, context
):#{
2914 return internal_listadd_execute(self
,context
,'ent_list','entities')
2918 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
2919 bl_idname
= "skaterift.ent_list_del_entry"
2920 bl_label
= "Remove entity"
2923 def poll(cls
, context
):#{
2924 active_object
= context
.active_object
2925 if obj_ent_type(active_object
) == 'ent_list':#{
2926 return active_object
.SR_data
.ent_list
[0].entities
2931 def execute(self
, context
):#{
2932 return internal_listdel_execute(self
,context
,'ent_list','entities')
2936 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
2938 target
: bpy
.props
.PointerProperty( \
2939 type=bpy
.types
.Object
, name
='target' )
2942 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
2943 bl_idname
= 'SR_UL_ENT_LIST'
2945 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
2946 layout
.prop( item
, 'target', text
='', emboss
=False )
2950 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
2951 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
2952 entities_index
: bpy
.props
.IntProperty()
2955 def sr_inspector( layout
, data
):#{
2956 layout
.label( text
='Entities' )
2957 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
2958 data
[0], 'entities', data
[0], \
2959 'entities_index', rows
=5)
2962 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
2963 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
2967 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
2968 nothing
: bpy
.props
.StringProperty()
2971 class SR_OBJECT_ENT_NPC(bpy
.types
.PropertyGroup
):#{
2972 au
: bpy
.props
.IntProperty()
2973 context
: bpy
.props
.IntProperty()
2974 cam
: bpy
.props
.PointerProperty( \
2975 type=bpy
.types
.Object
, name
="Viewpoint", \
2976 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2979 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
2980 subtype
: bpy
.props
.EnumProperty(
2982 items
=[('0','Trigger',''),
2983 ('1','Particles (0.1s)','')]
2986 target
: bpy
.props
.PointerProperty( \
2987 type=bpy
.types
.Object
, name
="Target", \
2988 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
2989 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
2990 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
2993 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
2995 box
.prop( data
[0], propname
)
2997 for evname
in evs
:#{
2999 row
.prop( data
[0], propname
+ evname
)
3001 target
= getattr( data
[0], propname
)
3003 tipo
= target
.SR_data
.ent_type
3004 cls
= globals()[ tipo
]
3006 table
= getattr( cls
, 'sr_functions', None )
3008 index
= getattr( data
[0], propname
+ evname
)
3010 row
.label( text
=table
[index
] )
3012 row
.label( text
="undefined function" )
3016 row
.label( text
="..." )
3023 def sr_inspector( layout
, data
):#{
3024 layout
.prop( data
[0], 'subtype' )
3025 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3026 ['_event','_event_leave'] )
3030 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3032 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3033 files_index
: bpy
.props
.IntProperty()
3035 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3036 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3037 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3038 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3040 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3041 formato
: bpy
.props
.EnumProperty(
3043 items
=[('0','Uncompressed Mono',''),
3044 ('1','Compressed Vorbis',''),
3045 ('2','[vg] Bird Synthesis','')]
3047 probability_curve
: bpy
.props
.EnumProperty(
3048 name
="Probability Curve",
3049 items
=[('0','Constant',''),
3050 ('1','Wildlife Daytime',''),
3051 ('2','Wildlife Nighttime','')])
3052 channel_behaviour
: bpy
.props
.EnumProperty(
3053 name
="Channel Behaviour",
3054 items
=[('0','Unlimited',''),
3055 ('1','Discard if group full', ''),
3056 ('2','Crossfade if group full','')])
3058 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3061 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3062 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3065 def sr_inspector( layout
, data
):
3067 layout
.prop( data
[0], 'formato' )
3068 layout
.prop( data
[0], 'volume' )
3071 box
.label( text
='Channels' )
3072 split
= box
.split(factor
=0.3)
3074 c
.prop( data
[0], 'max_channels' )
3076 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3077 if data
[0].channel_behaviour
>= '1':
3078 box
.prop( data
[0], 'group' )
3079 if data
[0].channel_behaviour
== '2':
3080 box
.prop( data
[0], 'transition_duration' )
3083 box
.label( text
='Flags' )
3084 box
.prop( data
[0], 'flag_3d' )
3085 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3087 box
.prop( data
[0], 'flag_loop' )
3088 box
.prop( data
[0], 'flag_auto' )
3090 layout
.prop( data
[0], 'probability_curve' )
3092 split
= layout
.split(factor
=0.7)
3094 c
.label( text
='Filepath' )
3096 c
.label( text
='Chance' )
3097 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3098 data
[0], 'files', data
[0], 'files_index', rows
=5)
3101 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3102 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3106 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3108 alias
: bpy
.props
.StringProperty()
3109 flags
: bpy
.props
.IntProperty()
3112 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3114 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3115 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3116 utf32
: bpy
.props
.IntProperty()
3119 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3121 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3122 utf32
: bpy
.props
.IntProperty()
3125 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3127 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3128 tipo
: bpy
.props
.StringProperty()
3131 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3133 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3134 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3135 alias
: bpy
.props
.StringProperty()
3137 glyphs_index
: bpy
.props
.IntProperty()
3138 variants_index
: bpy
.props
.IntProperty()
3141 def sr_inspector( layout
, data
):
3143 layout
.prop( data
[0], 'alias' )
3145 layout
.label( text
='Variants' )
3146 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3147 data
[0], 'variants', data
[0], 'variants_index',\
3150 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3151 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3153 layout
.label( text
='ASCII Glyphs' )
3154 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3155 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3158 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3159 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3160 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3161 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3165 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3167 speed
: bpy
.props
.FloatProperty(default
=1.0)
3170 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3172 tipo
: bpy
.props
.EnumProperty( name
='Type',
3173 items
=[('0','boards',''),
3174 ('1','character',''),
3176 ('4','server','')] )
3177 mark_rack
: bpy
.props
.PointerProperty( \
3178 type=bpy
.types
.Object
, name
="Board Rack", \
3179 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3180 mark_display
: bpy
.props
.PointerProperty( \
3181 type=bpy
.types
.Object
, name
="Selected Board Display", \
3182 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3183 mark_info
: bpy
.props
.PointerProperty( \
3184 type=bpy
.types
.Object
, name
="Selected Board Info", \
3185 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3186 ['ent_marker','ent_prop']))
3187 cam
: bpy
.props
.PointerProperty( \
3188 type=bpy
.types
.Object
, name
="Viewpoint", \
3189 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3192 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3194 mark_display
: bpy
.props
.PointerProperty( \
3195 type=bpy
.types
.Object
, name
="Board Display", \
3196 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3197 mark_display1
: bpy
.props
.PointerProperty( \
3198 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3199 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3200 cam
: bpy
.props
.PointerProperty( \
3201 type=bpy
.types
.Object
, name
="Viewpoint", \
3202 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3205 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3207 link0
: bpy
.props
.PointerProperty( \
3208 type=bpy
.types
.Object
, name
="Link 0", \
3209 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3210 link1
: bpy
.props
.PointerProperty( \
3211 type=bpy
.types
.Object
, name
="Link 1", \
3212 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3213 link2
: bpy
.props
.PointerProperty( \
3214 type=bpy
.types
.Object
, name
="Link 2", \
3215 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3216 link3
: bpy
.props
.PointerProperty( \
3217 type=bpy
.types
.Object
, name
="Link 3", \
3218 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3220 newloc
: bpy
.props
.PointerProperty( \
3221 type=bpy
.types
.Object
, name
="New location", \
3222 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3223 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3224 items
=[('0','append',''),
3225 ('1','replace','')])
3227 camera
: bpy
.props
.PointerProperty( \
3228 type=bpy
.types
.Object
, name
="Camera", \
3229 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3231 slider_minloc
: bpy
.props
.PointerProperty( \
3232 type=bpy
.types
.Object
, name
="Slider min", \
3233 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3234 slider_maxloc
: bpy
.props
.PointerProperty( \
3235 type=bpy
.types
.Object
, name
="Slider max", \
3236 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3237 slider_handle
: bpy
.props
.PointerProperty( \
3238 type=bpy
.types
.Object
, name
="Slider handle", \
3239 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3241 checkmark
: bpy
.props
.PointerProperty( \
3242 type=bpy
.types
.Object
, name
="Checked", \
3243 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3245 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3247 string
: bpy
.props
.StringProperty( name
="String" )
3248 tipo
: bpy
.props
.EnumProperty( name
='Type',
3249 items
=[('0','visual',''),
3250 ('1','event button',''),
3251 ('2','page button',''),
3256 ('7','visual(no colourize)','')])
3259 def sr_inspector( layout
, data
):
3263 box
.prop( data
, 'tipo' )
3265 if data
.tipo
== '0' or data
.tipo
== '7':#{
3266 box
.prop( data
, 'string', text
='Name' )
3269 elif data
.tipo
== '1':#{
3270 box
.prop( data
, 'string', text
='Event' )
3272 elif data
.tipo
== '2':#{
3273 box
.prop( data
, 'string', text
='Page' )
3274 box
.prop( data
, 'stack_behaviour' )
3276 elif data
.tipo
== '3':#{
3277 box
.prop( data
, 'string', text
='Data (i32)' )
3278 box
.prop( data
, 'checkmark' )
3280 elif data
.tipo
== '4':#{
3281 box
.prop( data
, 'string', text
='Data (f32)' )
3282 box
.prop( data
, 'slider_minloc' )
3283 box
.prop( data
, 'slider_maxloc' )
3284 box
.prop( data
, 'slider_handle' )
3286 box
.label( text
="Links" )
3287 box
.prop( data
, 'link0', text
='v0' )
3288 box
.prop( data
, 'link1', text
='v1' )
3291 elif data
.tipo
== '5':#{
3292 box
.prop( data
, 'string', text
='Page Name' )
3293 box
.prop( data
, 'newloc', text
='Entry Point' )
3294 box
.prop( data
, 'camera', text
='Viewpoint' )
3297 elif data
.tipo
== '6':#{
3298 box
.prop( data
, 'string', text
='ID' )
3299 box
.prop( data
, 'font_variant' )
3304 box
.label( text
="Links" )
3305 box
.prop( data
, 'link0' )
3306 box
.prop( data
, 'link1' )
3307 box
.prop( data
, 'link2' )
3308 box
.prop( data
, 'link3' )
3312 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3314 name
: bpy
.props
.StringProperty(name
="Name")
3315 desc
: bpy
.props
.StringProperty(name
="Description")
3316 author
: bpy
.props
.StringProperty(name
="Author")
3317 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3319 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3320 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3321 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3323 water_safe
: bpy
.props
.BoolProperty(name
="Water is Safe")
3326 def sr_inspector( layout
, data
):
3328 layout
.prop( data
[0], 'name' )
3329 layout
.prop( data
[0], 'desc' )
3330 layout
.prop( data
[0], 'author' )
3332 layout
.prop( data
[0], 'fix_time' )
3333 if data
[0].fix_time
:
3334 layout
.prop( data
[0], 'fixed_time' )
3336 layout
.prop( data
[0], 'timezone' )
3338 layout
.prop( data
[0], 'water_safe' )
3342 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3344 command
: bpy
.props
.StringProperty(name
="Command Line")
3347 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3348 proxima
: bpy
.props
.PointerProperty( \
3349 type=bpy
.types
.Object
, name
="Next", \
3350 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3351 target
: bpy
.props
.PointerProperty( \
3352 type=bpy
.types
.Object
, name
="Win", \
3353 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3354 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3355 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3356 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3357 items
=[('0','none',''),
3358 (str(0x1),'trick_shuvit',''),
3359 (str(0x2),'trick_kickflip',''),
3360 (str(0x4),'trick_treflip',''),
3361 (str(0x1|
0x2|
0x4),'trick_any',''),
3362 (str(0x8),'flip_back',''),
3363 (str(0x10),'flip_front',''),
3364 (str(0x8|
0x10),'flip_any',''),
3365 (str(0x20),'grind_truck_any',''),
3366 (str(0x40),'grind_board_any',''),
3367 (str(0x20|
0x40),'grind_any',''),
3368 (str(0x80),'footplant',''),
3369 (str(0x100),'passthrough',''),
3373 def sr_inspector( layout
, data
):#{
3374 layout
.prop( data
[0], 'proxima' )
3375 layout
.prop( data
[0], 'time_limit' )
3376 layout
.prop( data
[0], 'filtrar' )
3377 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3381 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3382 alias
: bpy
.props
.StringProperty( name
="Alias" )
3384 target
: bpy
.props
.PointerProperty( \
3385 type=bpy
.types
.Object
, name
="On Complete", \
3386 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3387 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3388 reset
: bpy
.props
.PointerProperty( \
3389 type=bpy
.types
.Object
, name
="On Reset", \
3390 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3391 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3393 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3395 first
: bpy
.props
.PointerProperty( \
3396 type=bpy
.types
.Object
, name
="First Objective", \
3397 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3399 camera
: bpy
.props
.PointerProperty( \
3400 type=bpy
.types
.Object
, name
="Camera", \
3401 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3405 def sr_inspector( layout
, data
):#{
3406 layout
.prop( data
[0], 'alias' )
3407 layout
.prop( data
[0], 'camera' )
3408 layout
.prop( data
[0], 'first' )
3409 layout
.prop( data
[0], 'time_limit' )
3410 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3411 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3415 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3416 title
: bpy
.props
.StringProperty( name
="Title" )
3417 zone_volume
: bpy
.props
.PointerProperty(
3418 type=bpy
.types
.Object
, name
="Zone Volume", \
3419 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3421 target0
: bpy
.props
.PointerProperty( \
3422 type=bpy
.types
.Object
, name
="Triger on unlock", \
3423 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3424 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3427 def sr_inspector( layout
, data
):#{
3428 layout
.prop( data
[0], 'title' )
3429 layout
.prop( data
[0], 'zone_volume' )
3430 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3434 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3435 target0
: bpy
.props
.PointerProperty( \
3436 type=bpy
.types
.Object
, name
="Target 0", \
3437 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3438 target1
: bpy
.props
.PointerProperty( \
3439 type=bpy
.types
.Object
, name
="Target 1", \
3440 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3441 target2
: bpy
.props
.PointerProperty( \
3442 type=bpy
.types
.Object
, name
="Target 2", \
3443 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3444 target3
: bpy
.props
.PointerProperty( \
3445 type=bpy
.types
.Object
, name
="Target 3", \
3446 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3448 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3449 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3450 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3451 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3454 def sr_inspector( layout
, data
):#{
3455 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3456 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3457 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3458 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3462 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3464 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3465 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3466 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3467 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3468 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3469 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3470 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3471 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3472 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3473 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3474 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3476 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3477 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3478 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3479 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3480 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3481 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3482 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3483 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3484 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3485 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3486 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3487 ent_npc
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_NPC
)
3489 ent_type
: bpy
.props
.EnumProperty(
3491 items
=sr_entity_list
,
3492 update
=sr_on_type_change
3496 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3498 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3501 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3503 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3506 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3508 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3509 items
=[('0','none',''),
3511 ('2','capsule','')])
3513 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3514 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3516 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3518 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3519 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3520 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3521 conet
: bpy
.props
.FloatProperty( name
='t' )
3524 def sr_inspector( layout
, data
):
3528 box
.prop( data
, 'collider' )
3530 if int(data
.collider
)>0:#{
3532 row
.prop( data
, 'collider_min' )
3534 row
.prop( data
, 'collider_max' )
3538 box
.prop( data
, 'cone_constraint' )
3539 if data
.cone_constraint
:#{
3541 row
.prop( data
, 'conevx' )
3543 row
.prop( data
, 'conevy' )
3545 row
.prop( data
, 'coneva' )
3546 box
.prop( data
, 'conet' )
3551 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3553 shader
: bpy
.props
.EnumProperty(
3556 ('standard',"standard",''),
3557 ('standard_cutout', "standard_cutout", ''),
3558 ('terrain_blend', "terrain_blend", ''),
3559 ('vertex_blend', "vertex_blend", ''),
3560 ('water',"water",''),
3561 ('invisible','Invisible',''),
3562 ('boundary','Boundary',''),
3563 ('fxglow','FX Glow',''),
3564 ('cubemap','Cubemap',''),
3565 ('walking','Walking',''),
3566 ('foliage','Foliage','')
3569 surface_prop
: bpy
.props
.EnumProperty(
3570 name
="Surface Property",
3572 ('0','concrete',''),
3577 ('5','snow (low friction)',''),
3578 ('6','sand (medium friction)','')
3581 collision
: bpy
.props
.BoolProperty( \
3582 name
="Collisions Enabled",\
3584 description
= "Can the player collide with this material?"\
3586 skate_surface
: bpy
.props
.BoolProperty( \
3587 name
="Skate Target", \
3589 description
= "Should the game try to target this surface?" \
3591 grind_surface
: bpy
.props
.BoolProperty( \
3594 description
= "Can you grind on this surface?" \
3596 grow_grass
: bpy
.props
.BoolProperty( \
3597 name
="Grow Grass", \
3599 description
= "Spawn grass sprites on this surface?" \
3601 preview_visibile
: bpy
.props
.BoolProperty( \
3602 name
="Preview visibile", \
3604 description
= "Show this material in preview models?" \
3606 blend_offset
: bpy
.props
.FloatVectorProperty( \
3607 name
="Blend Offset", \
3609 default
=Vector((0.5,0.0)),\
3610 description
="When surface is more than 45 degrees, add this vector " +\
3613 sand_colour
: bpy
.props
.FloatVectorProperty( \
3614 name
="Sand Colour",\
3617 default
=Vector((0.79,0.63,0.48)),\
3618 description
="Blend to this colour near the 0 coordinate on UP axis"\
3620 shore_colour
: bpy
.props
.FloatVectorProperty( \
3621 name
="Shore Colour",\
3624 default
=Vector((0.03,0.32,0.61)),\
3625 description
="Water colour at the shoreline"\
3627 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3628 name
="Ocean Colour",\
3631 default
=Vector((0.0,0.006,0.03)),\
3632 description
="Water colour in the deep bits"\
3634 tint
: bpy
.props
.FloatVectorProperty( \
3639 default
=Vector((1.0,1.0,1.0,1.0)),\
3640 description
="Reflection tint"\
3643 water_fog
: bpy
.props
.FloatProperty( \
3646 description
="(default: 0.04) Cloudiness of water"\
3648 water_fresnel
: bpy
.props
.FloatProperty( \
3649 name
="Water Fresnel", \
3651 description
="(default: 5.0) Reflection/Fog Fresnel Ratio"\
3653 water_scale
: bpy
.props
.FloatProperty( \
3654 name
="Water Scale", \
3656 description
="(default: 0.008) Size of water texture"\
3658 water_rate
: bpy
.props
.FloatVectorProperty( \
3659 name
= "Water Wave Rate",\
3661 default
=Vector(( 0.008, 0.006, 0.003, 0.03 )),\
3663 "(default: 0.008, 0.006, 0.003, 0.03) Rate which water bump texture moves"\
3666 cubemap
: bpy
.props
.PointerProperty( \
3667 type=bpy
.types
.Object
, name
="cubemap", \
3668 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3670 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3673 # ---------------------------------------------------------------------------- #
3677 # ---------------------------------------------------------------------------- #
3679 cv_view_draw_handler
= None
3680 cv_view_pixel_handler
= None
3681 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3683 cv_view_colours
= []
3684 cv_view_course_i
= 0
3686 # Draw axis alligned sphere at position with radius
3688 def cv_draw_sphere( pos
, radius
, colour
):
3690 global cv_view_verts
, cv_view_colours
3692 ly
= pos
+ Vector((0,0,radius
))
3693 lx
= pos
+ Vector((0,radius
,0))
3694 lz
= pos
+ Vector((0,0,radius
))
3696 pi
= 3.14159265358979323846264
3698 for i
in range(16):#{
3699 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3703 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3704 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3705 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3707 cv_view_verts
+= [ px
, lx
]
3708 cv_view_verts
+= [ py
, ly
]
3709 cv_view_verts
+= [ pz
, lz
]
3711 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3720 # Draw axis alligned sphere at position with radius
3722 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3724 global cv_view_verts
, cv_view_colours
3726 ly
= pos
+ tz
*radius
3727 lx
= pos
+ ty
*radius
3728 lz
= pos
+ tz
*radius
3730 pi
= 3.14159265358979323846264
3732 for i
in range(16):#{
3733 t
= ((i
+1.0) * 1.0/16.0) * pi
3737 s1
= math
.sin(t
*2.0)
3738 c1
= math
.cos(t
*2.0)
3740 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3741 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3742 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3744 cv_view_verts
+= [ px
, lx
]
3745 cv_view_verts
+= [ py
, ly
]
3746 cv_view_verts
+= [ pz
, lz
]
3748 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3757 # Draw transformed -1 -> 1 cube
3759 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3761 global cv_view_verts
, cv_view_colours
3767 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3768 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3769 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3770 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3771 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3772 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3773 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3774 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3776 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3777 (0,4),(1,5),(2,6),(3,7)]
3782 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3783 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3784 cv_view_colours
+= [colour
, colour
]
3789 # Draw line with colour
3791 def cv_draw_line( p0
, p1
, colour
):
3793 global cv_view_verts
, cv_view_colours
3795 cv_view_verts
+= [p0
,p1
]
3796 cv_view_colours
+= [colour
, colour
]
3800 # Draw line with colour(s)
3802 def cv_draw_line2( p0
, p1
, c0
, c1
):
3804 global cv_view_verts
, cv_view_colours
3806 cv_view_verts
+= [p0
,p1
]
3807 cv_view_colours
+= [c0
,c1
]
3813 def cv_tangent_basis( n
, tx
, ty
):
3815 if abs( n
[0] ) >= 0.57735027:#{
3834 # Draw coloured arrow
3836 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
3838 global cv_view_verts
, cv_view_colours
3844 tx
= Vector((1,0,0))
3845 ty
= Vector((1,0,0))
3846 cv_tangent_basis( n
, tx
, ty
)
3852 gpu
.state
.line_width_set(1.0)
3855 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3856 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3860 gpu
.state
.line_width_set(3.0)
3861 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
3863 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
3865 gpu
.state
.line_width_set(2.0)
3869 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3871 global cv_view_verts
, cv_view_colours
3873 for i
in range(dots
):#{
3877 p2
= p0
*(1.0-t0
)+p1
*t0
3878 p3
= p0
*(1.0-t1
)+p1
*t1
3880 cv_view_verts
+= [p2
,p3
]
3881 cv_view_colours
+= [c0
,c0
]
3886 # Drawhandles of a bezier control point
3888 def cv_draw_bhandle( obj
, direction
, colour
):
3890 global cv_view_verts
, cv_view_colours
3893 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3895 cv_view_verts
+= [p0
]
3896 cv_view_verts
+= [h0
]
3897 cv_view_colours
+= [colour
,colour
]
3901 # Draw a bezier curve (at fixed resolution 10)
3903 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3905 global cv_view_verts
, cv_view_colours
3908 for i
in range(10):#{
3914 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3916 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3917 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3918 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3925 # I think this one extends the handles of the bezier otwards......
3927 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3929 global cv_view_course_i
3931 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3933 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3934 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3935 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3936 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3938 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3942 # Flush the lines buffers. This is called often because god help you if you want
3943 # to do fixed, fast buffers in this catastrophic programming language.
3945 def cv_draw_lines():
3947 global cv_view_shader
, cv_view_verts
, cv_view_colours
3949 if len(cv_view_verts
) < 2:
3952 lines
= batch_for_shader(\
3953 cv_view_shader
, 'LINES', \
3954 { "pos":cv_view_verts
, "color":cv_view_colours
})
3956 if bpy
.context
.scene
.SR_data
.gizmos
:
3957 lines
.draw( cv_view_shader
)
3960 cv_view_colours
= []
3963 # I dont remember what this does exactly
3965 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3967 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3970 # Semi circle to show the limit. and some lines
3972 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3974 global cv_view_verts
, cv_view_colours
3979 for x
in range(16):#{
3982 a0
= amin
*(1.0-t0
)+amax
*t0
3983 a1
= amin
*(1.0-t1
)+amax
*t1
3985 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3986 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3988 p0
=obj
.matrix_world
@ p0
3989 p1
=obj
.matrix_world
@ p1
3990 cv_view_verts
+= [p0
,p1
]
3991 cv_view_colours
+= [colour
,colour
]
3994 cv_view_verts
+= [p0
,center
]
3995 cv_view_colours
+= [colour
,colour
]
3998 cv_view_verts
+= [p1
,center
]
3999 cv_view_colours
+= [colour
,colour
]
4003 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
4004 cv_view_colours
+= [colour
,colour
]
4009 # Cone and twist limit
4011 def draw_cone_twist( center
, vx
, vy
, va
):
4013 global cv_view_verts
, cv_view_colours
4014 axis
= vy
.cross( vx
)
4019 cv_view_verts
+= [center
, center
+va
*size
]
4020 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4022 for x
in range(32):#{
4023 t0
= (x
/32) * math
.tau
4024 t1
= ((x
+1)/32) * math
.tau
4031 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4032 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4034 col0
= ( abs(c0
), abs(s0
), 0.0 )
4035 col1
= ( abs(c1
), abs(s1
), 0.0 )
4037 cv_view_verts
+= [center
, p0
, p0
, p1
]
4038 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4044 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4046 def draw_skeleton_helpers( obj
):
4048 global cv_view_verts
, cv_view_colours
4050 if obj
.data
.pose_position
!= 'REST':#{
4054 for bone
in obj
.data
.bones
:#{
4056 a
= Vector((bone
.SR_data
.collider_min
[0],
4057 bone
.SR_data
.collider_min
[1],
4058 bone
.SR_data
.collider_min
[2]))
4059 b
= Vector((bone
.SR_data
.collider_max
[0],
4060 bone
.SR_data
.collider_max
[1],
4061 bone
.SR_data
.collider_max
[2]))
4063 if bone
.SR_data
.collider
== '1':#{
4065 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4066 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4067 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4068 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4069 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4070 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4071 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4072 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4074 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4075 (0,4),(1,5),(2,6),(3,7)]
4081 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4082 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4083 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4086 elif bone
.SR_data
.collider
== '2':#{
4091 for i
in range(3):#{
4092 if abs(v0
[i
]) > largest
:#{
4093 largest
= abs(v0
[i
])
4098 v1
= Vector((0,0,0))
4099 v1
[major_axis
] = 1.0
4101 tx
= Vector((0,0,0))
4102 ty
= Vector((0,0,0))
4104 cv_tangent_basis( v1
, tx
, ty
)
4105 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4106 l
= v0
[ major_axis
] - r
*2
4108 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4109 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4111 colour
= [0.2,0.2,0.2]
4112 colour
[major_axis
] = 0.5
4114 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4115 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4116 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4117 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4118 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4119 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4125 center
= obj
.matrix_world
@ c
4126 if bone
.SR_data
.cone_constraint
:#{
4127 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4128 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4129 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4130 draw_cone_twist( center
, vx
, vy
, va
)
4135 def cv_draw_wireframe( mdl
, points
, colour
):#{
4136 for i
in range(len(points
)//2):#{
4137 p0
= mdl
@points[i
*2+0]
4138 p1
= mdl
@points[i
*2+1]
4139 cv_draw_line( p0
, p1
, colour
)
4143 def cv_ent_gate( obj
):
4145 global cv_view_verts
, cv_view_colours
4147 if obj
.type != 'MESH': return
4149 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4150 data
= obj
.SR_data
.ent_gate
[0]
4151 dims
= mesh_data
.dimensions
4154 c
= Vector((0,0,dims
[2]))
4156 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4157 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4158 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4159 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4160 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4161 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4162 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4163 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4164 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4166 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4168 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4170 p0
= r3d
.view_matrix
.inverted().translation
4171 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4172 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4174 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4180 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4181 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4182 cv_view_colours
+= [cc
,cc
]
4186 if data
.target
!= None:
4187 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4190 def cv_ent_volume( obj
):
4192 global cv_view_verts
, cv_view_colours
4194 data
= obj
.SR_data
.ent_volume
[0]
4196 if data
.subtype
== '0':#{
4197 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4200 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4203 elif data
.subtype
== '1':#{
4204 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4207 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4212 def dijkstra( graph
, start_node
, target_node
):
4214 unvisited
= [_
for _
in graph
]
4219 shortest_path
[n
] = 9999999.999999
4220 shortest_path
[start_node
] = 0
4223 current_min_node
= None
4224 for n
in unvisited
:#{
4225 if current_min_node
== None:
4226 current_min_node
= n
4227 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4228 current_min_node
= n
4231 for branch
in graph
[current_min_node
]:#{
4232 tentative_value
= shortest_path
[current_min_node
]
4233 tentative_value
+= graph
[current_min_node
][branch
]
4234 if tentative_value
< shortest_path
[branch
]:#{
4235 shortest_path
[branch
] = tentative_value
4236 previous_nodes
[branch
] = current_min_node
4240 unvisited
.remove(current_min_node
)
4245 while node
!= start_node
:#{
4248 if node
not in previous_nodes
: return None
4249 node
= previous_nodes
[node
]
4252 # Add the start node manually
4253 path
.append(start_node
)
4259 def __init__(_
,points
,graph
,subsections
):#{
4262 _
.subsections
= subsections
4266 def create_node_graph( curves
, gates
):
4268 # add endpoints of curves
4275 for c
in range(len(curves
)):#{
4276 for s
in range(len(curves
[c
].data
.splines
)):#{
4277 spline
= curves
[c
].data
.splines
[s
]
4278 l
= len(spline
.points
)
4281 dist
= round(spline
.calc_length(),2)
4284 ib
= point_count
+l
-1
4286 graph
[ia
] = { ib
: dist
}
4287 graph
[ib
] = { ia
: dist
}
4289 for i
in range(len(spline
.points
)):#{
4290 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4291 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4296 if i
== 0: previous
= -1
4297 if i
== len(spline
.points
)-1: proxima
= -1
4299 subsections
.append((spline_count
,previous
,proxima
))
4308 graph_keys
= list(graph
)
4309 for i
in range(len(graph_keys
)-1):#{
4310 for j
in range(i
+1, len(graph_keys
)):#{
4311 if i
%2==0 and i
+1==j
: continue
4315 pi
= route_points
[ni
]
4316 pj
= route_points
[nj
]
4318 dist
= round((pj
-pi
).magnitude
,2)
4321 graph
[ni
][nj
] = dist
4322 graph
[nj
][ni
] = dist
4327 # add and link gates( by name )
4328 for gate
in gates
:#{
4329 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4330 if gate
.SR_data
.ent_gate
[0].target
:
4333 graph
[ gate
.name
] = {}
4335 for i
in range(len(graph_keys
)):#{
4337 pi
= route_points
[ni
]
4339 v0
= pi
-gate
.location
4340 if v0
.dot(v1
) < 0.0: continue
4342 dist
= round(v0
.magnitude
,2)
4345 graph
[ gate
.name
][ ni
] = dist
4346 graph
[ ni
][ gate
.name
] = dist
4351 return dij_graph(route_points
,graph
,subsections
)
4354 def solve_graph( dij
, start
, end
):
4356 path
= dijkstra( dij
.graph
, end
, start
)
4360 for sj
in range(1,len(path
)-2):#{
4363 map0
= dij
.subsections
[i0
]
4364 map1
= dij
.subsections
[i1
]
4366 if map0
[0] == map1
[0]:#{
4367 if map0
[1] == -1: direction
= 2
4372 map0
= dij
.subsections
[i0
]
4373 i1
= map0
[direction
]
4387 full
.append( path
[-2] )
4392 def cv_draw_route( route
, dij
):
4394 pole
= Vector((0.2,0.2,10))
4395 hat
= Vector((1,8,0.2))
4396 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4397 route
.SR_data
.ent_route
[0].colour
[1],
4398 route
.SR_data
.ent_route
[0].colour
[2])
4400 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4401 Vector((0,-6.5,5.5)))
4402 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4403 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4404 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4405 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4407 checkpoints
= route
.SR_data
.ent_route
[0].gates
4409 for i
in range(len(checkpoints
)):#{
4410 gi
= checkpoints
[i
].target
4411 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4414 dest
= gi
.SR_data
.ent_gate
[0].target
4416 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4420 if gi
==gj
: continue # error?
4421 if not gi
or not gj
: continue
4423 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4426 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4427 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4428 for j
in range(len(path
)-1):#{
4431 o0
= dij
.points
[ i0
]
4432 o1
= dij
.points
[ i1
]
4433 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4437 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4443 global cv_view_shader
4444 global cv_view_verts
4445 global cv_view_colours
4446 global cv_view_course_i
4448 cv_view_course_i
= 0
4450 cv_view_colours
= []
4452 cv_view_shader
.bind()
4453 gpu
.state
.depth_mask_set(True)
4454 gpu
.state
.line_width_set(2.0)
4455 gpu
.state
.face_culling_set('BACK')
4456 gpu
.state
.depth_test_set('LESS')
4457 gpu
.state
.blend_set('NONE')
4463 for obj
in bpy
.context
.collection
.objects
:#{
4464 if obj
.type == 'ARMATURE':#{
4465 if obj
.data
.pose_position
== 'REST':
4466 draw_skeleton_helpers( obj
)
4469 ent_type
= obj_ent_type( obj
)
4471 if ent_type
== 'ent_gate':#{
4473 route_gates
+= [obj
]
4475 elif ent_type
== 'ent_route_node':#{
4476 if obj
.type == 'CURVE':#{
4477 route_curves
+= [obj
]
4480 elif ent_type
== 'ent_route':
4482 elif ent_type
== 'ent_volume':#{
4483 cv_ent_volume( obj
)
4485 elif ent_type
== 'ent_objective':#{
4486 data
= obj
.SR_data
.ent_objective
[0]
4488 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4491 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4493 elif ent_type
== 'ent_relay':#{
4494 data
= obj
.SR_data
.ent_relay
[0]
4496 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4498 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4500 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4502 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4504 elif ent_type
== 'ent_challenge':#{
4505 data
= obj
.SR_data
.ent_challenge
[0]
4507 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4509 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4511 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4514 info_cu
= Vector((1.2,0.01,0.72))*0.5
4515 info_co
= Vector((0.0,0.0,0.72))*0.5
4516 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4518 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4520 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4521 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4522 Vector(( 0.1,0.0,0.30))]
4523 for v
in range(len(vs
)):#{
4524 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4527 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4528 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4530 elif ent_type
== 'ent_audio':#{
4531 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4532 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4534 elif ent_type
== 'ent_font':#{
4535 data
= obj
.SR_data
.ent_font
[0]
4537 for i
in range(len(data
.variants
)):#{
4538 sub
= data
.variants
[i
].mesh
4539 if not sub
: continue
4541 for ch
in data
.glyphs
:#{
4542 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4543 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4544 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4545 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4546 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4547 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4549 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4552 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4553 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4557 elif ent_type
== 'ent_glider':#{
4558 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4559 Vector(( 1.13982, 0.137084, -0.026358)), \
4560 Vector(( 0.0, 1.6, 1.0)), \
4561 Vector(( 0.0, -3.0, 1.0)), \
4562 Vector(( -3.45, -1.78, 0.9)), \
4563 Vector(( 0.0, 1.6, 1.0)), \
4564 Vector(( 3.45, -1.78, 0.9)), \
4565 Vector(( 0.0, 1.6, 1.0)), \
4566 Vector(( 3.45, -1.78, 0.9)), \
4567 Vector(( -3.45, -1.78, 0.9))]
4569 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4571 elif ent_type
== 'ent_skateshop':#{
4572 data
= obj
.SR_data
.ent_skateshop
[0]
4573 display
= data
.mark_display
4574 info
= data
.mark_info
4576 if data
.tipo
== '0':#{
4581 rack
= data
.mark_rack
4583 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4584 rack_co
= Vector((0.0,0.0,0.0))
4585 display_cu
= Vector((0.3,1.2,0.1))*0.5
4586 display_co
= Vector((0.0,0.0,0.1))*0.5
4587 info_cu
= Vector((1.2,0.01,0.3))*0.5
4588 info_co
= Vector((0.0,0.0,0.0))*0.5
4590 elif data
.tipo
== '1':#{
4594 display_cu
= Vector((0.4,0.4,2.0))*0.5
4595 display_co
= Vector((0.0,0.0,1.0))*0.5
4596 info_cu
= Vector((1.2,0.01,0.3))*0.5
4597 info_co
= Vector((0.0,0.0,0.0))*0.5
4599 elif data
.tipo
== '2':#{
4603 display_cu
= Vector((1.0,1.0,0.5))*0.5
4604 display_co
= Vector((0.0,0.0,0.5))*0.5
4605 info_cu
= Vector((1.2,0.01,0.3))*0.5
4606 info_co
= Vector((0.0,0.0,0.0))*0.5
4608 elif data
.tipo
== '3':#{
4613 elif data
.tipo
== '4':#{
4620 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4622 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4624 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4626 elif ent_type
== 'ent_swspreview':#{
4628 data
= obj
.SR_data
.ent_swspreview
[0]
4629 display
= data
.mark_display
4630 display1
= data
.mark_display1
4631 display_cu
= Vector((0.3,1.2,0.1))*0.5
4632 display_co
= Vector((0.0,0.0,0.1))*0.5
4634 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4636 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4638 # elif ent_type == 'ent_list':#{
4639 # data = obj.SR_data.ent_list[0]
4640 # for child in data.entities:#{
4641 # if child.target:#{
4642 # cv_draw_arrow( obj.location, child.target.location, \
4647 elif ent_type
== 'ent_region':#{
4648 data
= obj
.SR_data
.ent_region
[0]
4650 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4654 elif ent_type
== 'ent_menuitem':#{
4655 for i
,col
in enumerate(obj
.users_collection
):#{
4656 colour32
= hash_djb2( col
.name
)
4657 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4658 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4659 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4661 vs
= [None for _
in range(8)]
4663 for j
in range(8):#{
4664 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4665 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4667 vs
[j
] = obj
.matrix_world
@ v0
4669 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4670 (0,4),(1,5),(2,6),(3,7)]
4674 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4675 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4676 cv_view_colours
+= [cc
,cc
]
4681 data
= obj
.SR_data
.ent_menuitem
[0]
4682 if data
.tipo
== '4':#{
4683 if data
.slider_minloc
and data
.slider_maxloc
:#{
4684 v0
= data
.slider_minloc
.location
4685 v1
= data
.slider_maxloc
.location
4686 cv_draw_line( v0
, v1
, cc
)
4690 colour32
= hash_djb2(obj
.name
)
4691 r
= ((colour32
) & 0xff) / 255.0
4692 g
= ((colour32
>>8 ) & 0xff) / 255.0
4693 b
= ((colour32
>>16) & 0xff) / 255.0
4695 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4700 if data
.tipo
!= '0':#{
4701 if data
.tipo
== '4':#{
4703 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4706 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4711 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4714 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4717 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4720 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4728 dij
= create_node_graph( route_curves
, route_gates
)
4730 #cv_draw_route_map( route_nodes )
4731 for route
in routes
:#{
4732 cv_draw_route( route
, dij
)
4738 def pos3d_to_2d( pos
):#{
4739 return view3d_utils
.location_3d_to_region_2d( \
4740 bpy
.context
.region
, \
4741 bpy
.context
.space_data
.region_3d
, pos
)
4744 def cv_draw_pixel():#{
4745 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4747 blf
.color(0, 1.0,1.0,1.0,0.9)
4748 blf
.enable(0,blf
.SHADOW
)
4749 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4750 for obj
in bpy
.context
.collection
.objects
:#{
4751 ent_type
= obj_ent_type( obj
)
4753 if ent_type
!= 'none':#{
4754 co
= pos3d_to_2d( obj
.location
)
4757 blf
.position(0,co
[0],co
[1],0)
4758 blf
.draw(0,ent_type
)
4763 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4764 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4765 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4767 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4768 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4769 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4770 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4771 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4772 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4773 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4774 SR_OT_COPY_ENTITY_DATA
, \
4775 SR_OBJECT_ENT_VOLUME
, \
4776 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4777 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4778 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4779 SR_OBJECT_ENT_FONT_VARIANT
,
4780 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4781 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4782 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4783 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4784 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4785 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4786 SR_OBJECT_ENT_REGION
,\
4787 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4788 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4789 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4790 SR_OBJECT_ENT_GLIDER
, SR_OBJECT_ENT_NPC
, \
4792 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4793 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4799 bpy
.utils
.register_class(c
)
4801 bpy
.types
.Scene
.SR_data
= \
4802 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4803 bpy
.types
.Collection
.SR_data
= \
4804 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4806 bpy
.types
.Object
.SR_data
= \
4807 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4808 bpy
.types
.Light
.SR_data
= \
4809 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4810 bpy
.types
.Bone
.SR_data
= \
4811 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4812 bpy
.types
.Mesh
.SR_data
= \
4813 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4814 bpy
.types
.Material
.SR_data
= \
4815 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4817 global cv_view_draw_handler
, cv_view_pixel_handler
4818 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4819 cv_draw
,(),'WINDOW','POST_VIEW')
4820 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4821 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4827 bpy
.utils
.unregister_class(c
)
4829 global cv_view_draw_handler
, cv_view_pixel_handler
4830 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4831 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')