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 ('none', 'None', '', 0 ),
14 ('ent_gate', 'Gate', '', 1 ),
15 ('ent_spawn', 'Spawn Point', '', 2 ),
16 ('ent_route_node', 'Routing Path', '', 3 ),
17 ('ent_route', 'Skate Course', '', 4 ),
18 ('ent_water', 'Water Surface', '', 5 ),
19 ('ent_volume', 'Volume/Trigger', '', 6 ),
20 ('ent_audio', 'Audio', '', 7 ),
21 ('ent_marker', 'Marker', '', 8 ),
22 ('ent_font', 'Font', '', 9 ),
23 ('ent_font_variant', 'Font:Variant', '', 10 ),
24 ('ent_traffic', 'Traffic Model', '', 11 ),
25 ('ent_skateshop', 'Skate Shop', '', 12 ),
26 ('ent_camera', 'Camera', '', 13 ),
27 ('ent_swspreview', 'Workshop Preview', '', 14 ),
28 ('ent_menuitem', 'Menu Item', '', 15 ),
29 ('ent_worldinfo', 'World Info', '', 16 ),
30 ('ent_ccmd', 'CCmd', '', 17 ),
31 ('ent_objective', 'Objective', '', 18 ),
32 ('ent_challenge', 'Challenge', '', 19 ),
33 ('ent_relay', 'Relay', '', 20 ),
34 ('ent_miniworld', 'Mini World', '', 22 ),
35 ('ent_prop', 'Prop', '', 23 ),
36 ('ent_list', 'Entity List', '', 24 ),
37 ('ent_region', 'Region', '', 25 ),
38 ('ent_glider', 'Glider', '', 26 ),
39 ('ent_npc', 'npc', '', 27 )
43 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
44 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
45 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
46 'ent_npc', 'ent_water' ]
48 def get_entity_enum_id( alias
):
50 for et
in sr_entity_list
:#{
56 if alias
== 'ent_cubemap': return 21
61 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
62 #{ # the normals and uvs to i16s. Not an
63 _pack_
= 1 # real issue, yet.
64 _fields_
= [("co",c_float
*3),
68 ("weights",c_uint16
*4),
72 class mdl_transform(Structure
):
74 _fields_
= [("co",c_float
*3),
79 class mdl_submesh(Structure
):
81 _fields_
= [("indice_start",c_uint32
),
82 ("indice_count",c_uint32
),
83 ("vertex_start",c_uint32
),
84 ("vertex_count",c_uint32
),
85 ("bbx",(c_float
*3)*2),
86 ("material_id",c_uint16
), # index into the material array
91 # =================================================
93 class mdl_file(Structure
):
95 _fields_
= [("path",c_uint32
),
96 ("pack_offset",c_uint32
),
97 ("pack_size",c_uint32
)]
100 class mdl_material_kvs(Structure
):
102 _fields_
= [("offset",c_uint32
),
106 class mdl_material_properties_union(Union
):
108 _fields_
= [("kvs",mdl_material_kvs
),
109 ("compiled",c_void_p
)]
112 class mdl_material(Structure
):
114 _fields_
= [("pstr_name",c_uint32
),
117 ("surface_prop",c_uint32
),
118 ("props",mdl_material_properties_union
)]
120 # ("colour",c_float*4), (old) v105
121 # ("colour1",c_float*4),
122 # ("tex_diffuse",c_uint32),
123 # ("tex_none0",c_uint32),
124 # ("tex_none1",c_uint32)]
127 class mdl_bone(Structure
):
129 _fields_
= [("co",c_float
*3),("end",c_float
*3),
131 ("collider",c_uint32
),
132 ("ik_target",c_uint32
),
133 ("ik_pole",c_uint32
),
135 ("pstr_name",c_uint32
),
136 ("hitbox",(c_float
*3)*2),
137 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
141 class mdl_armature(Structure
):
143 _fields_
= [("transform",mdl_transform
),
144 ("bone_start",c_uint32
),
145 ("bone_count",c_uint32
),
146 ("anim_start",c_uint32
),
147 ("anim_count",c_uint32
)]
150 class mdl_animation(Structure
):
152 _fields_
= [("pstr_name",c_uint32
),
155 ("keyframe_start",c_uint32
)]
158 class mdl_mesh(Structure
):
160 _fields_
= [("transform",mdl_transform
),
161 ("submesh_start",c_uint32
),
162 ("submesh_count",c_uint32
),
163 ("pstr_name",c_uint32
),
164 ("entity_id",c_uint32
),
165 ("armature_id",c_uint32
)]
168 class mdl_texture(Structure
):
170 _fields_
= [("file",mdl_file
),
174 class mdl_array(Structure
):
176 _fields_
= [("file_offset",c_uint32
),
177 ("item_count",c_uint32
),
178 ("item_size",c_uint32
),
182 class mdl_header(Structure
):
184 _fields_
= [("version",c_uint32
),
185 ("arrays",mdl_array
)]
188 class ent_spawn(Structure
):
190 _fields_
= [("transform",mdl_transform
),
191 ("pstr_name",c_uint32
)]
194 class ent_light(Structure
):
196 _fields_
= [("transform",mdl_transform
),
197 ("daytime",c_uint32
),
199 ("colour",c_float
*4),
202 ("inverse_world",(c_float
*3)*4), # Runtime
203 ("angle_sin_cos",(c_float
*2))] # Runtime
206 class version_refcount_union(Union
):
208 _fields_
= [("timing_version",c_uint32
),
209 ("ref_count",c_uint8
)]
212 class ent_gate(Structure
):
214 _fields_
= [("flags",c_uint32
),
215 ("target", c_uint32
),
217 ("dimensions", c_float
*3),
218 ("co", (c_float
*3)*2),
219 ("q", (c_float
*4)*2),
220 ("to_world",(c_float
*3)*4),
221 ("transport",(c_float
*3)*4),
222 ("_anonymous_union",version_refcount_union
),
223 ("timing_time",c_double
),
224 ("routes",c_uint16
*4),
225 ("route_count",c_uint8
),
226 ("submesh_start",c_uint32
), # v102+
227 ("submesh_count",c_uint32
), # v102+ (can be 0)
229 sr_functions
= { 0: 'unlock' }
232 class ent_route_node(Structure
):
234 _fields_
= [("co",c_float
*3),
235 ("ref_count",c_uint8
),
236 ("ref_total",c_uint8
)]
239 class ent_path_index(Structure
):
241 _fields_
= [("index",c_uint16
)]
244 class vg_audio_clip(Structure
):
246 _fields_
= [("path",c_uint64
),
252 class union_file_audio_clip(Union
):
254 _fields_
= [("file",mdl_file
),
255 ("reserved",vg_audio_clip
)]
258 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
259 # but then again, too late to change because compat.
260 class ent_audio_clip(Structure
):
262 _fields_
= [("_anon",union_file_audio_clip
),
263 ("probability",c_float
)]
266 class ent_list(Structure
):
268 _fields_
= [("entity_ref_start",c_uint32
),
269 ("entity_ref_count",c_uint32
)]
273 class file_entity_ref(Structure
):
275 _fields_
= [("index",c_uint32
)]
278 class ent_checkpoint(Structure
):
280 _fields_
= [("gate_index",c_uint16
),
281 ("path_start",c_uint16
),
282 ("path_count",c_uint16
)]
285 class ent_route(Structure
):
287 _fields_
= [("transform",mdl_transform
),
288 ("pstr_name",c_uint32
),
289 ("checkpoints_start",c_uint16
),
290 ("checkpoints_count",c_uint16
),
291 ("colour",c_float
*4),
292 ("active",c_uint32
), #runtime
294 ("board_transform",(c_float
*3)*4),
296 ("latest_pass",c_double
),
297 ("id_camera",c_uint32
), # v103+
300 sr_functions
= { 0: 'view' }
303 class ent_list(Structure
):#{
304 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
307 class ent_glider(Structure
):#{
308 _fields_
= [("transform",mdl_transform
),
310 ("cooldown",c_float
)]
311 sr_functions
= { 0: 'unlock',
315 class ent_npc(Structure
):#{
316 _fields_
= [("transform",mdl_transform
),
318 ("context",c_uint32
),
320 sr_functions
= { 0: 'proximity', -1: 'leave' }
323 class ent_water(Structure
):
325 _fields_
= [("transform",mdl_transform
),
326 ("max_dist",c_float
),
327 ("reserved0",c_uint32
),
328 ("reserved1",c_uint32
)]
329 sr_functions
= { 0: "drown" }
332 class volume_trigger(Structure
):
334 _fields_
= [("event",c_uint32
),
335 ("event_leave",c_int32
)]
338 class volume_particles(Structure
):
340 _fields_
= [("blank",c_uint32
),
344 class volume_union(Union
):
346 _fields_
= [("trigger",volume_trigger
),
347 ("particles",volume_particles
)]
350 class ent_volume(Structure
):
352 _fields_
= [("transform",mdl_transform
),
353 ("to_world",(c_float
*3)*4),
354 ("to_local",(c_float
*3)*4),
357 ("_anon",volume_union
)]
360 class ent_audio(Structure
):
362 _fields_
= [("transform",mdl_transform
),
364 ("clip_start",c_uint32
),
365 ("clip_count",c_uint32
),
367 ("crossfade",c_float
),
368 ("channel_behaviour",c_uint32
),
370 ("probability_curve",c_uint32
),
371 ("max_channels",c_uint32
)]
374 class ent_marker(Structure
):
376 _fields_
= [("transform",mdl_transform
),
380 class ent_glyph(Structure
):
382 _fields_
= [("size",c_float
*2),
383 ("indice_start",c_uint32
),
384 ("indice_count",c_uint32
)]
387 class ent_font_variant(Structure
):
389 _fields_
= [("name",c_uint32
),
390 ("material_id",c_uint32
)]
393 class ent_font(Structure
):
395 _fields_
= [("alias",c_uint32
),
396 ("variant_start",c_uint32
),
397 ("variant_count",c_uint32
),
398 ("glyph_start",c_uint32
),
399 ("glyph_count",c_uint32
),
400 ("glyph_utf32_base",c_uint32
)]
403 class ent_traffic(Structure
):
405 _fields_
= [("transform",mdl_transform
),
406 ("submesh_start",c_uint32
),
407 ("submesh_count",c_uint32
),
408 ("start_node",c_uint32
),
409 ("node_count",c_uint32
),
416 # ---------------------------------------------------------------
417 class ent_skateshop_characters(Structure
):
419 _fields_
= [("id_display",c_uint32
),
420 ("id_info",c_uint32
)]
422 class ent_skateshop_boards(Structure
):
424 _fields_
= [("id_display",c_uint32
),
425 ("id_info",c_uint32
),
426 ("id_rack",c_uint32
)]
428 class ent_skateshop_worlds(Structure
):
430 _fields_
= [("id_display",c_uint32
),
431 ("id_info",c_uint32
)]
433 class ent_skateshop_server(Structure
):
435 _fields_
= [("id_lever",c_uint32
)]
437 class ent_skateshop_anon_union(Union
):
439 _fields_
= [("boards",ent_skateshop_boards
),
440 ("character",ent_skateshop_characters
),
441 ("worlds",ent_skateshop_worlds
),
442 ("server",ent_skateshop_server
)]
444 class ent_skateshop(Structure
):
446 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
447 ("id_camera",c_uint32
),
448 ("_anonymous_union",ent_skateshop_anon_union
)]
450 sr_functions
= { 0: 'trigger' }
453 class ent_swspreview(Structure
):
455 _fields_
= [("id_camera",c_uint32
),
456 ("id_display",c_uint32
),
457 ("id_display1",c_uint32
)]
461 # -----------------------------------------------------------------
462 class ent_menuitem_visual(Structure
):
464 _fields_
= [("pstr_name",c_uint32
)]
466 class ent_menuitem_slider(Structure
):
468 _fields_
= [("id_min",c_uint32
),
470 ("id_handle",c_uint32
),
471 ("pstr_data",c_uint32
)]
473 class ent_menuitem_button(Structure
):
475 _fields_
= [("pstr",c_uint32
),
476 ("stack_behaviour",c_uint32
)]
478 class ent_menuitem_checkmark(Structure
):
480 _fields_
= [("id_check",c_uint32
),
481 ("pstr_data",c_uint32
),
482 ("offset",c_float
*3)]
484 class ent_menuitem_page(Structure
):
486 _fields_
= [("pstr_name",c_uint32
),
487 ("id_entrypoint",c_uint32
),
488 ("id_viewpoint",c_uint32
)]
490 class ent_menuitem_binding(Structure
):
492 _fields_
= [("pstr_bind",c_uint32
),
493 ("font_variant",c_uint32
)]
495 class ent_menuitem_anon_union(Union
):
497 _fields_
= [("slider",ent_menuitem_slider
),
498 ("button",ent_menuitem_button
),
499 ("checkmark",ent_menuitem_checkmark
),
500 ("page",ent_menuitem_page
),
501 ("visual",ent_menuitem_visual
),
502 ("binding",ent_menuitem_binding
)]
504 class ent_menuitem(Structure
):
506 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
507 ("id_links",c_uint32
*4),
508 ("factive",c_float
), ("fvisible",c_float
),
509 #-- TODO: Refactor this into a simple mesh structure
510 ("transform",mdl_transform
),
511 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
514 ("_anonymous_union", ent_menuitem_anon_union
)]
517 class ent_camera(Structure
):
519 _fields_
= [("transform",mdl_transform
),
523 class ent_worldinfo(Structure
):
525 _fields_
= [("pstr_name",c_uint32
),
526 ("pstr_author",c_uint32
), # unused
527 ("pstr_desc",c_uint32
), # unused
528 ("timezone",c_float
),
529 ("pstr_skybox",c_uint32
),
533 class ent_ccmd(Structure
):
535 _fields_
= [("pstr_command",c_uint32
)]
538 class ent_objective(Structure
):#{
539 _fields_
= [("transform",mdl_transform
),
540 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
542 ("id_next",c_uint32
),
543 ("filter",c_uint32
),("filter2",c_uint32
),
545 ("win_event",c_int32
),
546 ("time_limit",c_float
)]
548 sr_functions
= { 0: 'trigger',
553 class ent_challenge(Structure
):#{
554 _fields_
= [("transform",mdl_transform
),
555 ("pstr_alias",c_uint32
),
558 ("target_event",c_int32
),
560 ("reset_event",c_int32
),
563 ("status",c_uint32
)] #runtime
564 sr_functions
= { 0: 'unlock',
568 class ent_region(Structure
):#{
569 _fields_
= [("transform",mdl_transform
),
570 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
571 ("pstr_title",c_uint32
),
573 ("zone_volume",c_uint32
),
575 ("target0",c_uint32
*2)]
576 sr_functions
= { 0: 'enter', 1: 'leave' }
579 class ent_relay(Structure
):#{
580 _fields_
= [("targets",(c_uint32
*2)*4),
581 ("targets_events",c_int32
*4)]
582 sr_functions
= { 0: 'trigger' }
585 class ent_cubemap(Structure
):#{
586 _fields_
= [("co",c_float
*3),
587 ("resolution",c_uint32
), #placeholder
588 ("live",c_uint32
), #placeholder
589 ("texture_id",c_uint32
), #engine
590 ("framebuffer_id",c_uint32
),#engine
591 ("renderbuffer_id",c_uint32
),#engine
592 ("placeholder",c_uint32
*2)]
595 class ent_miniworld(Structure
):#{
596 _fields_
= [("transform",mdl_transform
),
597 ("pstr_world",c_uint32
),
601 sr_functions
= { 0: 'zone', 1: 'leave' }
604 class ent_prop(Structure
):#{
605 _fields_
= [("transform",mdl_transform
),
606 ("submesh_start",c_uint32
),
607 ("submesh_count",c_uint32
),
609 ("pstr_alias",c_uint32
)]
612 def obj_ent_type( obj
):
614 if obj
.type == 'ARMATURE': return 'mdl_armature'
615 elif obj
.type == 'LIGHT': return 'ent_light'
616 elif obj
.type == 'CAMERA': return 'ent_camera'
617 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
619 else: return obj
.SR_data
.ent_type
622 def sr_filter_ent_type( obj
, ent_types
):
624 if obj
== bpy
.context
.active_object
: return False
626 for c0
in obj
.users_collection
:#{
627 for c1
in bpy
.context
.active_object
.users_collection
:#{
629 return obj_ent_type( obj
) in ent_types
637 def v4_dot( a
, b
):#{
638 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
641 def q_identity( q
):#{
648 def q_normalize( q
):#{
650 if( l2
< 0.00001 ):#{
654 s
= 1.0/math
.sqrt(l2
)
662 def compile_obj_transform( obj
, transform
):
664 co
= obj
.matrix_world
@ Vector((0,0,0))
666 # This was changed from matrix_local on 09.05.23
667 q
= obj
.matrix_world
.to_quaternion()
673 transform
.co
[0] = co
[0]
674 transform
.co
[1] = co
[2]
675 transform
.co
[2] = -co
[1]
676 transform
.q
[0] = q
[1]
677 transform
.q
[1] = q
[3]
678 transform
.q
[2] = -q
[2]
679 transform
.q
[3] = q
[0]
680 transform
.s
[0] = s
[0]
681 transform
.s
[1] = s
[2]
682 transform
.s
[2] = s
[1]
685 def int_align_to( v
, align
):
687 while(v
%align
)!=0: v
+= 1
691 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
693 while (len(buffer) % align
) != 0: buffer.extend(w
)
697 def bytearray_print_hex( s
, w
=16 ):
699 for r
in range((len(s
)+(w
-1))//w
):#{
701 i1
=min((r
+1)*w
,len(s
))
702 print( F
'{r*w:06x}| \x1B[31m', end
='')
703 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
704 print( "\x1B[0m", end
='')
705 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
709 def sr_compile_string( s
):
711 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
713 index
= len( sr_compile
.string_data
)
714 sr_compile
.string_cache
[s
] = index
715 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
716 sr_compile
.string_data
.extend( s
.encode('utf-8') )
717 sr_compile
.string_data
.extend( b
'\0' )
719 bytearray_align_to( sr_compile
.string_data
, 4 )
725 decoded
= bytearray()
726 for i
in range(len(s
)//2):#{
727 c
= (ord(s
[i
*2+0])-0x41)
728 c |
= (ord(s
[i
*2+1])-0x41)<<4
729 decoded
.extend(bytearray(c_uint8(c
))) #??
734 def sr_pack_file( file, path
, data
):
736 file.path
= sr_compile_string( path
)
737 file.pack_offset
= len( sr_compile
.pack_data
)
738 file.pack_size
= len( data
)
740 sr_compile
.pack_data
.extend( data
)
741 bytearray_align_to( sr_compile
.pack_data
, 16 )
744 def sr_compile_texture( img
):
749 name
= os
.path
.splitext( img
.name
)[0]
751 if name
in sr_compile
.texture_cache
:
752 return sr_compile
.texture_cache
[name
]
754 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
759 if sr_compile
.pack_textures
:#{
760 filedata
= qoi_encode( img
)
761 sr_pack_file( tex
.file, name
, filedata
)
764 sr_compile
.texture_cache
[name
] = texture_index
765 sr_compile
.texture_data
.extend( bytearray(tex
) )
769 def sr_armature_bones( armature
):
771 def _recurse_bone( b
):
774 for c
in b
.children
: yield from _recurse_bone( c
)
777 for b
in armature
.data
.bones
:
779 yield from _recurse_bone( b
)
782 def sr_entity_id( obj
):#{
785 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
786 index
= sr_compile
.entity_ids
[ obj
.name
]
788 return (tipo
&0xffff)<<16 |
(index
&0xffff)
791 # Returns submesh_start,count and armature_id
792 def sr_compile_mesh_internal( obj
):
801 for mod
in obj
.modifiers
:#{
802 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
803 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
806 can_use_cache
= False
809 if mod
.type == 'ARMATURE': #{
810 armature
= mod
.object
811 rig_weight_groups
= \
812 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
813 armature_id
= sr_compile
.entity_ids
[armature
.name
]
815 POSE_OR_REST_CACHE
= armature
.data
.pose_position
816 armature
.data
.pose_position
= 'REST'
820 # Check the cache first
822 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
823 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
824 submesh_start
= ref
[0]
825 submesh_count
= ref
[1]
826 return (submesh_start
,submesh_count
,armature_id
)
829 # Compile a whole new mesh
831 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
834 dgraph
= bpy
.context
.evaluated_depsgraph_get()
835 data
= obj
.evaluated_get(dgraph
).data
836 data
.calc_loop_triangles()
837 data
.calc_normals_split()
839 # Mesh is split into submeshes based on their material
841 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
842 for material_id
, mat
in enumerate(mat_list
): #{
846 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
847 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
850 sm
.material_id
= sr_compile_material( mat
)
852 INF
=99999999.99999999
858 # Keep a reference to very very very similar vertices
859 # i have no idea how to speed it up.
861 vertex_reference
= {}
863 # Write the vertex / indice data
865 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
866 if tri
.material_index
!= material_id
: continue
869 vert
= data
.vertices
[tri
.vertices
[j
]]
871 vi
= data
.loops
[li
].vertex_index
873 # Gather vertex information
876 norm
= data
.loops
[li
].normal
878 colour
= (255,255,255,255)
885 uv
= data
.uv_layers
.active
.data
[li
].uv
889 if data
.vertex_colors
:#{
890 colour
= data
.vertex_colors
.active
.data
[li
].color
891 colour
= (int(colour
[0]*255.0),\
892 int(colour
[1]*255.0),\
893 int(colour
[2]*255.0),\
894 int(colour
[3]*255.0))
897 # Weight groups: truncates to the 3 with the most influence. The
898 # fourth bone ID is never used by the shader so it
902 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
903 if obj
.vertex_groups
[_
.group
].name
in \
906 weight_groups
= sorted( src_groups
, key
= \
907 lambda a
: a
.weight
, reverse
=True )
909 for ml
in range(3):#{
910 if len(weight_groups
) > ml
:#{
911 g
= weight_groups
[ml
]
912 name
= obj
.vertex_groups
[g
.group
].name
915 groups
[ml
] = rig_weight_groups
.index(name
)
920 if len(weight_groups
) > 0:#{
921 inv_norm
= (1.0/tot
) * 65535.0
922 for ml
in range(3):#{
923 weights
[ml
] = int( weights
[ml
] * inv_norm
)
924 weights
[ml
] = min( weights
[ml
], 65535 )
925 weights
[ml
] = max( weights
[ml
], 0 )
930 li1
= tri
.loops
[(j
+1)%3]
931 vi1
= data
.loops
[li1
].vertex_index
932 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
934 if e0
.use_freestyle_mark
and \
935 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
936 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
942 TOLERENCE
= float(10**4)
943 key
= (int(co
[0]*TOLERENCE
+0.5),
944 int(co
[1]*TOLERENCE
+0.5),
945 int(co
[2]*TOLERENCE
+0.5),
946 int(norm
[0]*TOLERENCE
+0.5),
947 int(norm
[1]*TOLERENCE
+0.5),
948 int(norm
[2]*TOLERENCE
+0.5),
949 int(uv
[0]*TOLERENCE
+0.5),
950 int(uv
[1]*TOLERENCE
+0.5),
951 colour
[0], # these guys are already quantized
964 if key
in vertex_reference
:
965 index
= vertex_reference
[key
]
967 index
= bytearray(c_uint32(sm
.vertex_count
))
970 vertex_reference
[key
] = index
980 v
.colour
[0] = colour
[0]
981 v
.colour
[1] = colour
[1]
982 v
.colour
[2] = colour
[2]
983 v
.colour
[3] = colour
[3]
984 v
.weights
[0] = weights
[0]
985 v
.weights
[1] = weights
[1]
986 v
.weights
[2] = weights
[2]
987 v
.weights
[3] = weights
[3]
988 v
.groups
[0] = groups
[0]
989 v
.groups
[1] = groups
[1]
990 v
.groups
[2] = groups
[2]
991 v
.groups
[3] = groups
[3]
994 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
995 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
998 sr_compile
.vertex_data
.extend(bytearray(v
))
1001 sm
.indice_count
+= 1
1002 sr_compile
.indice_data
.extend( index
)
1006 # Make sure bounding box isn't -inf -> inf if no vertices
1008 if sm
.vertex_count
== 0:
1013 # Add submesh to encoder
1015 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1020 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1023 # Save a reference to this mesh since we want to reuse the submesh indices
1025 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1026 return (submesh_start
,submesh_count
,armature_id
)
1029 def sr_compile_mesh( obj
):
1032 compile_obj_transform(obj
, node
.transform
)
1033 node
.pstr_name
= sr_compile_string(obj
.name
)
1034 ent_type
= obj_ent_type( obj
)
1038 if ent_type
!= 'none':#{
1039 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1040 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1041 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1044 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1045 sr_compile_mesh_internal( obj
)
1047 sr_compile
.mesh_data
.extend(bytearray(node
))
1050 def sr_compile_fonts( collection
):
1052 print( F
"[SR] Compiling fonts" )
1057 for obj
in collection
.all_objects
:#{
1058 if obj_ent_type(obj
) != 'ent_font': continue
1060 data
= obj
.SR_data
.ent_font
[0]
1063 font
.alias
= sr_compile_string( data
.alias
)
1064 font
.variant_start
= variant_count
1065 font
.variant_count
= 0
1066 font
.glyph_start
= glyph_count
1068 glyph_base
= data
.glyphs
[0].utf32
1069 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1071 font
.glyph_utf32_base
= glyph_base
1072 font
.glyph_count
= glyph_range
1074 for i
in range(len(data
.variants
)):#{
1075 data_var
= data
.variants
[i
]
1076 if not data_var
.mesh
: continue
1078 mesh
= data_var
.mesh
.data
1080 variant
= ent_font_variant()
1081 variant
.name
= sr_compile_string( data_var
.tipo
)
1083 # fonts (variants) only support one material each
1085 if len(mesh
.materials
) != 0:
1086 mat
= mesh
.materials
[0]
1087 variant
.material_id
= sr_compile_material( mat
)
1089 font
.variant_count
+= 1
1091 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1092 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1094 for j
in range(len(islands
)):#{
1095 for tri
in islands
[j
]:#{
1096 centroids
[j
].x
+= tri
.center
[0]
1097 centroids
[j
].y
+= tri
.center
[2]
1100 centroids
[j
] /= len(islands
[j
])
1103 for j
in range(glyph_range
):#{
1104 data_glyph
= data
.glyphs
[j
]
1106 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1107 glyph
.indice_count
= 0
1108 glyph
.size
[0] = data_glyph
.bounds
[2]
1109 glyph
.size
[1] = data_glyph
.bounds
[3]
1111 vertex_reference
= {}
1113 for k
in range(len(islands
)):#{
1114 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1115 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1116 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1117 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1122 for l
in range(len(islands
[k
])):#{
1124 for m
in range(3):#{
1125 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1127 vi
= mesh
.loops
[li
].vertex_index
1129 # Gather vertex information
1131 co
= [vert
.co
[_
] for _
in range(3)]
1132 co
[0] -= data_glyph
.bounds
[0]
1133 co
[2] -= data_glyph
.bounds
[1]
1134 norm
= mesh
.loops
[li
].normal
1136 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1138 TOLERENCE
= float(10**4)
1139 key
= (int(co
[0]*TOLERENCE
+0.5),
1140 int(co
[1]*TOLERENCE
+0.5),
1141 int(co
[2]*TOLERENCE
+0.5),
1142 int(norm
[0]*TOLERENCE
+0.5),
1143 int(norm
[1]*TOLERENCE
+0.5),
1144 int(norm
[2]*TOLERENCE
+0.5),
1145 int(uv
[0]*TOLERENCE
+0.5),
1146 int(uv
[1]*TOLERENCE
+0.5))
1148 if key
in vertex_reference
:
1149 index
= vertex_reference
[key
]
1151 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1152 index
= bytearray(c_uint32(vindex
))
1153 vertex_reference
[key
] = index
1160 v
.norm
[2] = -norm
[1]
1164 sr_compile
.vertex_data
.extend(bytearray(v
))
1167 glyph
.indice_count
+= 1
1168 sr_compile
.indice_data
.extend( index
)
1172 sr_ent_push( glyph
)
1174 sr_ent_push( variant
)
1180 def sr_compile_menus( collection
):
1182 print( "[SR1] Compiling menus" )
1185 for obj
in collection
.all_objects
:#{
1186 if obj_ent_type(obj
) != 'ent_menuitem': continue
1187 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1189 bitmask
= 0x00000000
1191 for col
in obj
.users_collection
:#{
1193 if name
not in groups
: groups
.append( name
)
1194 bitmask |
= (0x1 << groups
.index(name
))
1197 item
= ent_menuitem()
1198 item
.type = int( obj_data
.tipo
)
1199 item
.groups
= bitmask
1201 compile_obj_transform( obj
, item
.transform
)
1202 if obj
.type == 'MESH':#{
1203 item
.submesh_start
, item
.submesh_count
, _
= \
1204 sr_compile_mesh_internal( obj
)
1207 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1208 item_button
= item
._anonymous
_union
.button
1209 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1210 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1212 elif item
.type == 0:#{
1213 item_visual
= item
._anonymous
_union
.visual
1214 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1216 elif item
.type == 3:#{
1217 item_checkmark
= item
._anonymous
_union
.checkmark
1218 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1219 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1220 delta
= obj_data
.checkmark
.location
- obj
.location
1221 item_checkmark
.offset
[0] = delta
[0]
1222 item_checkmark
.offset
[1] = delta
[2]
1223 item_checkmark
.offset
[2] = -delta
[1]
1225 elif item
.type == 4:#{
1226 item_slider
= item
._anonymous
_union
.slider
1227 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1228 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1229 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1230 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1232 elif item
.type == 5:#{
1233 item_page
= item
._anonymous
_union
.page
1234 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1235 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1236 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1238 elif item
.type == 6:#{
1239 item_binding
= item
._anonymous
_union
.binding
1240 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1241 item_binding
.font_variant
= obj_data
.font_variant
1245 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1247 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1248 if item
.type != 4:#{
1250 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1252 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1259 def sr_compile_armature( obj
):
1261 node
= mdl_armature()
1262 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1264 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1267 bones
= [_
for _
in sr_armature_bones(obj
)]
1268 bones_names
= [None]+[_
.name
for _
in bones
]
1272 if b
.use_deform
: bone
.flags
= 0x1
1273 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1275 bone
.collider
= int(b
.SR_data
.collider
)
1277 if bone
.collider
>0:#{
1278 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1279 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1280 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1281 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1282 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1283 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1286 if b
.SR_data
.cone_constraint
:#{
1288 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1289 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1290 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1291 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1292 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1293 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1294 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1295 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1296 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1297 bone
.conet
= b
.SR_data
.conet
1300 bone
.co
[0] = b
.head_local
[0]
1301 bone
.co
[1] = b
.head_local
[2]
1302 bone
.co
[2] = -b
.head_local
[1]
1303 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1304 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1305 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1306 bone
.pstr_name
= sr_compile_string( b
.name
)
1308 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1309 if c
.type == 'IK':#{
1311 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1312 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1316 node
.bone_count
+= 1
1317 sr_compile
.bone_data
.extend(bytearray(bone
))
1322 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1323 # So we can restore later
1325 previous_frame
= bpy
.context
.scene
.frame_current
1326 previous_action
= obj
.animation_data
.action
1327 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1328 obj
.data
.pose_position
= 'POSE'
1330 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1331 for NLAStrip
in NLALayer
.strips
:#{
1334 for a
in bpy
.data
.actions
:#{
1335 if a
.name
== NLAStrip
.name
:#{
1336 obj
.animation_data
.action
= a
1341 # Clip to NLA settings
1343 anim_start
= int(NLAStrip
.action_frame_start
)
1344 anim_end
= int(NLAStrip
.action_frame_end
)
1348 anim
= mdl_animation()
1349 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1351 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1352 sizeof(mdl_transform
)
1353 anim
.length
= anim_end
-anim_start
1356 # Export the keyframes
1357 for frame
in range(anim_start
,anim_end
):#{
1358 bpy
.context
.scene
.frame_set(frame
)
1361 pb
= obj
.pose
.bones
[rb
.name
]
1363 # relative bone matrix
1364 if rb
.parent
is not None:#{
1365 offset_mtx
= rb
.parent
.matrix_local
1366 offset_mtx
= offset_mtx
.inverted_safe() @ \
1369 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1370 inv_parent
.invert_safe()
1371 fpm
= inv_parent
@ pb
.matrix
1374 bone_mtx
= rb
.matrix
.to_4x4()
1375 local_inv
= rb
.matrix_local
.inverted_safe()
1376 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1379 loc
, rot
, sca
= fpm
.decompose()
1382 lc_m
= pb
.matrix_channel
.to_3x3()
1383 if pb
.parent
is not None:#{
1384 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1385 lc_m
= smtx
.inverted() @ lc_m
1387 rq
= lc_m
.to_quaternion()
1390 kf
= mdl_transform()
1401 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1407 # Add to animation buffer
1409 sr_compile
.anim_data
.extend(bytearray(anim
))
1410 node
.anim_count
+= 1
1414 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1418 # Restore context to how it was before
1420 bpy
.context
.scene
.frame_set( previous_frame
)
1421 obj
.animation_data
.action
= previous_action
1422 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1425 sr_compile
.armature_data
.extend(bytearray(node
))
1428 def sr_ent_push( struct
):
1430 clase
= type(struct
).__name
__
1432 if clase
not in sr_compile
.entity_data
:#{
1433 sr_compile
.entity_data
[ clase
] = bytearray()
1434 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1437 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1438 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1442 def sr_array_title( arr
, name
, count
, size
, offset
):
1444 for i
in range(len(name
)):#{
1445 arr
.name
[i
] = ord(name
[i
])
1447 arr
.file_offset
= offset
1448 arr
.item_count
= count
1449 arr
.item_size
= size
1456 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1461 def sr_compile( collection
):
1463 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1467 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1468 sr_compile
.pack_animations
= collection
.SR_data
.animations
1471 sr_compile
.string_cache
= {}
1472 sr_compile
.mesh_cache
= {}
1473 sr_compile
.material_cache
= {}
1474 sr_compile
.texture_cache
= {}
1477 sr_compile
.mesh_data
= bytearray()
1478 sr_compile
.submesh_data
= bytearray()
1479 sr_compile
.vertex_data
= bytearray()
1480 sr_compile
.indice_data
= bytearray()
1481 sr_compile
.bone_data
= bytearray()
1482 sr_compile
.material_data
= bytearray()
1483 sr_compile
.shader_data
= bytearray()
1484 sr_compile
.armature_data
= bytearray()
1485 sr_compile
.anim_data
= bytearray()
1486 sr_compile
.keyframe_data
= bytearray()
1487 sr_compile
.texture_data
= bytearray()
1489 # just bytes not structures
1490 sr_compile
.string_data
= bytearray()
1491 sr_compile
.pack_data
= bytearray()
1494 sr_compile
.entity_data
= {}
1495 sr_compile
.entity_info
= {}
1497 print( F
"[SR] assign entity ID's" )
1498 sr_compile
.entities
= {}
1499 sr_compile
.entity_ids
= {}
1502 # -------------------------------------------------------
1504 sr_compile_string( "null" )
1507 for obj
in collection
.all_objects
: #{
1508 if obj
.type == 'MESH':#{
1512 ent_type
= obj_ent_type( obj
)
1513 if ent_type
== 'none': continue
1515 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1516 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1517 sr_compile
.entities
[ent_type
] += [obj
]
1520 print( F
"[SR] Compiling geometry" )
1522 for obj
in collection
.all_objects
:#{
1523 if obj
.type == 'MESH':#{
1526 ent_type
= obj_ent_type( obj
)
1528 # entity ignore mesh list
1530 if ent_type
== 'ent_traffic': continue
1531 if ent_type
== 'ent_prop': continue
1532 if ent_type
== 'ent_font': continue
1533 if ent_type
== 'ent_font_variant': continue
1534 if ent_type
== 'ent_menuitem': continue
1535 if ent_type
== 'ent_objective': continue
1536 if ent_type
== 'ent_region': continue
1538 #TODO: This is messy.
1539 if ent_type
== 'ent_gate':#{
1540 obj_data
= obj
.SR_data
.ent_gate
[0]
1541 if obj_data
.custom
: continue
1543 #--------------------------
1545 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1546 sr_compile_mesh( obj
)
1550 audio_clip_count
= 0
1551 entity_file_ref_count
= 0
1553 for ent_type
, arr
in sr_compile
.entities
.items():#{
1554 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1556 for i
in range(len(arr
)):#{
1559 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1561 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1562 elif ent_type
== 'ent_light': #{
1564 compile_obj_transform( obj
, light
.transform
)
1565 light
.daytime
= obj
.data
.SR_data
.daytime
1566 if obj
.data
.type == 'POINT':#{
1569 elif obj
.data
.type == 'SPOT':#{
1571 light
.angle
= obj
.data
.spot_size
*0.5
1573 light
.range = obj
.data
.cutoff_distance
1574 light
.colour
[0] = obj
.data
.color
[0]
1575 light
.colour
[1] = obj
.data
.color
[1]
1576 light
.colour
[2] = obj
.data
.color
[2]
1577 light
.colour
[3] = obj
.data
.energy
1578 sr_ent_push( light
)
1580 elif ent_type
== 'ent_camera': #{
1582 compile_obj_transform( obj
, cam
.transform
)
1583 cam
.fov
= obj
.data
.angle
* 45.0
1586 elif ent_type
== 'ent_gate': #{
1588 obj_data
= obj
.SR_data
.ent_gate
[0]
1589 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1593 if obj_data
.tipo
== 'default':#{
1594 if obj_data
.target
:#{
1595 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1599 elif obj_data
.tipo
== 'nonlocal':#{
1601 gate
.key
= sr_compile_string(obj_data
.key
)
1605 if obj_data
.flip
: flags |
= 0x0004
1606 if obj_data
.custom
:#{
1608 gate
.submesh_start
, gate
.submesh_count
, _
= \
1609 sr_compile_mesh_internal( obj
)
1611 if obj_data
.locked
: flags |
= 0x0010
1614 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1615 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1616 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1618 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1619 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1621 if obj_data
.target
:#{
1622 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1623 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1628 for x
in range(2):#{
1629 gate
.co
[x
][0] = co
[x
][0]
1630 gate
.co
[x
][1] = co
[x
][2]
1631 gate
.co
[x
][2] = -co
[x
][1]
1632 gate
.q
[x
][0] = q
[x
][1]
1633 gate
.q
[x
][1] = q
[x
][3]
1634 gate
.q
[x
][2] = -q
[x
][2]
1635 gate
.q
[x
][3] = q
[x
][0]
1640 elif ent_type
== 'ent_spawn': #{
1642 compile_obj_transform( obj
, spawn
.transform
)
1643 obj_data
= obj
.SR_data
.ent_spawn
[0]
1644 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1645 sr_ent_push( spawn
)
1647 elif ent_type
== 'ent_water':#{
1649 compile_obj_transform( obj
, water
.transform
)
1650 water
.max_dist
= 0.0
1651 sr_ent_push( water
)
1653 elif ent_type
== 'ent_audio':#{
1654 obj_data
= obj
.SR_data
.ent_audio
[0]
1656 compile_obj_transform( obj
, audio
.transform
)
1657 audio
.clip_start
= audio_clip_count
1658 audio
.clip_count
= len(obj_data
.files
)
1659 audio_clip_count
+= audio
.clip_count
1660 audio
.max_channels
= obj_data
.max_channels
1661 audio
.volume
= obj_data
.volume
1664 # - allow/disable doppler
1665 # - channel group tags with random colours
1666 # - transition properties
1668 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1669 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1670 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1671 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1672 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1673 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1674 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1676 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1677 if audio
.channel_behaviour
>= 1:#{
1678 audio
.group
= obj_data
.group
1680 if audio
.channel_behaviour
== 2:#{
1681 audio
.crossfade
= obj_data
.transition_duration
1683 audio
.probability_curve
= int(obj_data
.probability_curve
)
1685 for ci
in range(audio
.clip_count
):#{
1686 entry
= obj_data
.files
[ci
]
1687 clip
= ent_audio_clip()
1688 clip
.probability
= entry
.probability
1689 if obj_data
.formato
== '2':#{
1690 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1693 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1694 clip
._anon
.file.pack_offset
= 0
1695 clip
._anon
.file.pack_size
= 0
1699 sr_ent_push( audio
)
1701 elif ent_type
== 'ent_volume':#{
1702 obj_data
= obj
.SR_data
.ent_volume
[0]
1703 volume
= ent_volume()
1704 volume
.type = int(obj_data
.subtype
)
1705 compile_obj_transform( obj
, volume
.transform
)
1707 if obj_data
.target
:#{
1708 volume
.target
= sr_entity_id( obj_data
.target
)
1709 volume
._anon
.trigger
.event
= obj_data
.target_event
1710 volume
._anon
.trigger
.event_leave
= obj_data
.target_event_leave
1715 elif ent_type
== 'ent_marker':#{
1716 marker
= ent_marker()
1717 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1718 compile_obj_transform( obj
, marker
.transform
)
1721 elif ent_type
== 'ent_skateshop':#{
1722 skateshop
= ent_skateshop()
1723 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1724 skateshop
.type = int(obj_data
.tipo
)
1725 if skateshop
.type == 0:#{
1726 boardshop
= skateshop
._anonymous
_union
.boards
1727 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1728 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1729 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1731 elif skateshop
.type == 1:#{
1732 charshop
= skateshop
._anonymous
_union
.character
1733 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1734 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1736 elif skateshop
.type == 2:#{
1737 worldshop
= skateshop
._anonymous
_union
.worlds
1738 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1739 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1741 elif skateshop
.type == 3:#{
1742 server
= skateshop
._anonymous
_union
.server
1743 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1745 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1746 compile_obj_transform( obj
, skateshop
.transform
)
1747 sr_ent_push(skateshop
)
1749 elif ent_type
== 'ent_swspreview':#{
1750 workshop_preview
= ent_swspreview()
1751 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1752 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1753 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1754 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1755 sr_ent_push( workshop_preview
)
1757 elif ent_type
== 'ent_worldinfo':#{
1758 worldinfo
= ent_worldinfo()
1759 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1760 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1761 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1762 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1766 if obj_data
.fix_time
:#{
1767 worldinfo
.timezone
= obj_data
.fixed_time
1771 worldinfo
.timezone
= obj_data
.timezone
1773 if obj_data
.water_safe
:
1776 worldinfo
.flags
= flags
1777 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1778 sr_ent_push( worldinfo
)
1780 elif ent_type
== 'ent_ccmd':#{
1782 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1783 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1786 elif ent_type
== 'ent_objective':#{
1787 objective
= ent_objective()
1788 obj_data
= obj
.SR_data
.ent_objective
[0]
1789 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
1790 objective
.id_win
= sr_entity_id( obj_data
.target
)
1791 objective
.win_event
= obj_data
.target_event
1792 objective
.filter = int(obj_data
.filtrar
)
1793 objective
.filter2
= 0
1794 objective
.time_limit
= obj_data
.time_limit
1796 compile_obj_transform( obj
, objective
.transform
)
1797 objective
.submesh_start
, objective
.submesh_count
, _
= \
1798 sr_compile_mesh_internal( obj
)
1800 sr_ent_push( objective
)
1802 elif ent_type
== 'ent_challenge':#{
1803 challenge
= ent_challenge()
1804 obj_data
= obj
.SR_data
.ent_challenge
[0]
1805 compile_obj_transform( obj
, challenge
.transform
)
1806 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1807 challenge
.target
= sr_entity_id( obj_data
.target
)
1808 challenge
.target_event
= obj_data
.target_event
1809 challenge
.reset
= sr_entity_id( obj_data
.reset
)
1810 challenge
.reset_event
= obj_data
.reset_event
1811 challenge
.first
= sr_entity_id( obj_data
.first
)
1812 challenge
.flags
= 0x00
1813 challenge
.camera
= sr_entity_id( obj_data
.camera
)
1814 if obj_data
.time_limit
: challenge
.flags |
= 0x01
1815 challenge
.status
= 0
1816 sr_ent_push( challenge
)
1818 elif ent_type
== 'ent_region':#{
1819 region
= ent_region()
1820 obj_data
= obj
.SR_data
.ent_region
[0]
1821 compile_obj_transform( obj
, region
.transform
)
1822 region
.submesh_start
, region
.submesh_count
, _
= \
1823 sr_compile_mesh_internal( obj
)
1824 region
.pstr_title
= sr_compile_string( obj_data
.title
)
1825 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
1826 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
1827 region
.target0
[1] = obj_data
.target0_event
1828 sr_ent_push( region
)
1830 elif ent_type
== 'ent_relay':#{
1832 obj_data
= obj
.SR_data
.ent_relay
[0]
1833 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
1834 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
1835 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
1836 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
1837 relay
.targets
[0][1] = obj_data
.target0_event
1838 relay
.targets
[1][1] = obj_data
.target1_event
1839 relay
.targets
[2][1] = obj_data
.target2_event
1840 relay
.targets
[3][1] = obj_data
.target3_event
1841 sr_ent_push( relay
)
1843 # elif ent_type == 'ent_list':#{
1844 # lista = ent_list()
1845 # obj_data = obj.SR_data.ent_list[0]
1847 # lista.entity_ref_start = entity_file_ref_count
1848 # lista.entity_ref_count = len( obj_data.entities )
1849 # entity_file_ref_count += lista.entity_ref_count
1851 # for child in obj_data.entities:#{
1852 # reference_struct = file_entity_ref()
1853 # reference_struct.index = sr_entity_id( child.target )
1854 # sr_ent_push( reference_struct )
1857 # sr_ent_push( lista )
1859 elif ent_type
== 'ent_glider':#{
1860 glider
= ent_glider()
1861 compile_obj_transform( obj
, glider
.transform
)
1862 sr_ent_push( glider
)
1864 elif ent_type
== 'ent_npc':#{
1865 obj_data
= obj
.SR_data
.ent_npc
[0]
1867 compile_obj_transform( obj
, npc
.transform
)
1868 npc
.id = obj_data
.au
1869 npc
.context
= obj_data
.context
1870 npc
.camera
= sr_entity_id( obj_data
.cam
)
1873 elif ent_type
== 'ent_cubemap':#{
1874 cubemap
= ent_cubemap()
1875 co
= obj
.matrix_world
@ Vector((0,0,0))
1876 cubemap
.co
[0] = co
[0]
1877 cubemap
.co
[1] = co
[2]
1878 cubemap
.co
[2] = -co
[1]
1879 cubemap
.resolution
= 0
1881 sr_ent_push( cubemap
)
1883 elif ent_type
== 'ent_miniworld':#{
1884 miniworld
= ent_miniworld()
1885 obj_data
= obj
.SR_data
.ent_miniworld
[0]
1887 compile_obj_transform( obj
, miniworld
.transform
)
1888 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
1889 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
1890 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
1891 sr_ent_push( miniworld
)
1893 elif ent_type
== 'ent_prop':#{
1895 obj_data
= obj
.SR_data
.ent_prop
[0]
1896 compile_obj_transform( obj
, prop
.transform
)
1897 prop
.submesh_start
, prop
.submesh_count
, _
= \
1898 sr_compile_mesh_internal( obj
)
1899 prop
.flags
= obj_data
.flags
1900 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1906 sr_compile_menus( collection
)
1907 sr_compile_fonts( collection
)
1909 def _children( col
):#{
1911 for c
in col
.children
:#{
1912 yield from _children(c
)
1916 checkpoint_count
= 0
1917 pathindice_count
= 0
1920 for col
in _children(collection
):#{
1921 print( F
"Adding routes for subcollection: {col.name}" )
1927 for obj
in col
.objects
:#{
1928 if obj
.type == 'ARMATURE': pass
1930 ent_type
= obj_ent_type( obj
)
1932 if ent_type
== 'ent_gate':
1933 route_gates
+= [obj
]
1934 elif ent_type
== 'ent_route_node':#{
1935 if obj
.type == 'CURVE':#{
1936 route_curves
+= [obj
]
1939 elif ent_type
== 'ent_route':
1941 elif ent_type
== 'ent_traffic':
1946 dij
= create_node_graph( route_curves
, route_gates
)
1948 for obj
in routes
:#{
1949 obj_data
= obj
.SR_data
.ent_route
[0]
1951 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1952 route
.checkpoints_start
= checkpoint_count
1953 route
.checkpoints_count
= 0
1954 route
.id_camera
= sr_entity_id( obj_data
.cam
)
1957 route
.colour
[ci
] = obj_data
.colour
[ci
]
1958 route
.colour
[3] = 1.0
1960 compile_obj_transform( obj
, route
.transform
)
1961 checkpoints
= obj_data
.gates
1963 for i
in range(len(checkpoints
)):#{
1964 gi
= checkpoints
[i
].target
1965 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1969 dest
= gi
.SR_data
.ent_gate
[0].target
1973 if gi
==gj
: continue # error?
1974 if not gi
or not gj
: continue
1976 checkpoint
= ent_checkpoint()
1977 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1978 checkpoint
.path_start
= pathindice_count
1979 checkpoint
.path_count
= 0
1981 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1984 for pi
in range(len(path
)):#{
1985 pathindice
= ent_path_index()
1986 pathindice
.index
= routenode_count
+ path
[pi
]
1987 sr_ent_push( pathindice
)
1989 checkpoint
.path_count
+= 1
1990 pathindice_count
+= 1
1994 sr_ent_push( checkpoint
)
1995 route
.checkpoints_count
+= 1
1996 checkpoint_count
+= 1
1999 sr_ent_push( route
)
2002 for obj
in traffics
:#{
2003 traffic
= ent_traffic()
2004 compile_obj_transform( obj
, traffic
.transform
)
2005 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2006 sr_compile_mesh_internal( obj
)
2008 # find best subsection
2010 graph_keys
= list(dij
.graph
)
2014 for j
in range(len(dij
.points
)):#{
2015 point
= dij
.points
[j
]
2016 dist
= (point
-obj
.location
).magnitude
2018 if dist
< min_dist
:#{
2025 best_begin
= best_point
2026 best_end
= best_point
2029 map0
= dij
.subsections
[best_begin
]
2030 if map0
[1] == -1: break
2031 best_begin
= map0
[1]
2034 map1
= dij
.subsections
[best_end
]
2035 if map1
[2] == -1: break
2039 traffic
.start_node
= routenode_count
+ best_begin
2040 traffic
.node_count
= best_end
- best_begin
2041 traffic
.index
= best_point
- best_begin
2042 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2045 sr_ent_push(traffic
)
2048 for point
in dij
.points
:#{
2049 rn
= ent_route_node()
2052 rn
.co
[2] = -point
[1]
2056 routenode_count
+= len(dij
.points
)
2059 print( F
"[SR] Writing file" )
2061 file_array_instructions
= {}
2064 def _write_array( name
, item_size
, data
):#{
2065 nonlocal file_array_instructions
, file_offset
2067 count
= len(data
)//item_size
2068 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2069 'data':data
, 'offset': file_offset
}
2070 file_offset
+= len(data
)
2071 file_offset
= int_align_to( file_offset
, 8 )
2074 _write_array( 'strings', 1, sr_compile
.string_data
)
2075 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2076 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2077 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2078 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2079 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2080 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2082 for name
, buffer in sr_compile
.entity_data
.items():#{
2083 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2086 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2087 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2088 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2089 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2090 _write_array( 'pack', 1, sr_compile
.pack_data
)
2091 _write_array( 'shader_data', 1, sr_compile
.shader_data
)
2093 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2094 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2096 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2097 path
= F
"{folder}{collection.name}.mdl"
2100 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2101 fp
= open( path
, "wb" )
2102 header
= mdl_header()
2103 header
.version
= MDL_VERSION_NR
2104 sr_array_title( header
.arrays
, \
2105 'index', len(file_array_instructions
), \
2106 sizeof(mdl_array
), header_size
)
2108 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2110 print( F
'[SR] {"name":>16}| count | offset' )
2112 for name
,info
in file_array_instructions
.items():#{
2114 offset
= info
['offset'] + header_size
+ index_size
2115 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2116 index
.extend( bytearray(arr
) )
2118 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2119 F
' 0x{info["offset"]:02x}' )
2121 fp
.write( bytearray_align_to( index
, 8 ) )
2122 #bytearray_print_hex( index )
2124 for name
,info
in file_array_instructions
.items():#{
2125 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2130 print( '[SR] done' )
2133 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2135 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2136 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2137 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2139 panel
: bpy
.props
.EnumProperty(
2143 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2144 ('ENTITY', 'Entity', '', 'MONKEY',1),
2145 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2150 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2152 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2153 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2156 def sr_get_mirror_bone( bones
):
2158 side
= bones
.active
.name
[-1:]
2159 other_name
= bones
.active
.name
[:-1]
2160 if side
== 'L': other_name
+= 'R'
2161 elif side
== 'R': other_name
+= 'L'
2165 if b
.name
== other_name
:
2172 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2174 bl_idname
="skaterift.mirror_bone"
2175 bl_label
="Mirror bone attributes - SkateRift"
2177 def execute(_
,context
):
2179 active_object
= context
.active_object
2180 bones
= active_object
.data
.bones
2182 b
= sr_get_mirror_bone( bones
)
2184 if not b
: return {'FINISHED'}
2186 b
.SR_data
.collider
= a
.SR_data
.collider
2188 def _v3copyflipy( a
, b
):#{
2194 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2195 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2196 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2197 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2199 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2201 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2202 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2203 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2205 b
.SR_data
.conet
= a
.SR_data
.conet
2208 ob
= bpy
.context
.scene
.objects
[0]
2209 ob
.hide_render
= ob
.hide_render
2214 class SR_COMPILE(bpy
.types
.Operator
):
2216 bl_idname
="skaterift.compile_all"
2217 bl_label
="Compile All"
2219 def execute(_
,context
):
2221 view_layer
= bpy
.context
.view_layer
2222 for col
in view_layer
.layer_collection
.children
["export"].children
:
2223 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2224 sr_compile( bpy
.data
.collections
[col
.name
] )
2230 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2232 bl_idname
="skaterift.compile_this"
2233 bl_label
="Compile This collection"
2235 def execute(_
,context
):
2237 col
= bpy
.context
.collection
2244 class SR_INTERFACE(bpy
.types
.Panel
):
2246 bl_idname
= "VIEW3D_PT_skate_rift"
2247 bl_label
= "Skate Rift"
2248 bl_space_type
= 'VIEW_3D'
2249 bl_region_type
= 'UI'
2250 bl_category
= "Skate Rift"
2252 def draw(_
, context
):
2256 row
= _
.layout
.row()
2258 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2260 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2261 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2263 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2264 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2265 col
= bpy
.context
.collection
2267 found_in_export
= False
2269 view_layer
= bpy
.context
.view_layer
2270 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2271 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2274 if c1
.name
== col
.name
: #{
2275 found_in_export
= True
2279 box
= _
.layout
.box()
2281 row
.alignment
= 'CENTER'
2284 if found_in_export
: #{
2285 row
.label( text
=col
.name
+ ".mdl" )
2286 box
.prop( col
.SR_data
, "pack_textures" )
2287 box
.prop( col
.SR_data
, "animations" )
2288 box
.operator( "skaterift.compile_this" )
2292 row
.label( text
=col
.name
)
2296 row
.alignment
= 'CENTER'
2298 row
.label( text
="This collection is not in the export group" )
2301 box
= _
.layout
.box()
2304 split
= row
.split( factor
=0.3, align
=True )
2305 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2308 if export_count
== 0:
2310 row1
.operator( "skaterift.compile_all", \
2311 text
=F
"Compile all ({export_count} collections)" )
2313 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2314 active_object
= context
.active_object
2315 if not active_object
: return
2317 amount
= max( 0, len(context
.selected_objects
)-1 )
2319 row
= _
.layout
.row()
2320 row
.operator( 'skaterift.copy_entity_data', \
2321 text
=F
'Copy entity data to {amount} other objects' )
2322 if amount
== 0: row
.enabled
=False
2324 box
= _
.layout
.box()
2326 row
.alignment
= 'CENTER'
2327 row
.label( text
=active_object
.name
)
2330 def _draw_prop_collection( source
, data
): #{
2333 row
.alignment
= 'CENTER'
2336 row
.label( text
=F
'{source}' )
2338 if hasattr(type(data
[0]),'sr_inspector'):#{
2339 type(data
[0]).sr_inspector( box
, data
)
2342 for a
in data
[0].__annotations
__:
2343 box
.prop( data
[0], a
)
2347 if active_object
.type == 'ARMATURE': #{
2348 if active_object
.mode
== 'POSE': #{
2349 bones
= active_object
.data
.bones
2350 mb
= sr_get_mirror_bone( bones
)
2352 box
.operator( "skaterift.mirror_bone", \
2353 text
=F
'Mirror attributes to {mb.name}' )
2356 _draw_prop_collection( \
2357 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2358 [bones
.active
.SR_data
] )
2362 row
.alignment
='CENTER'
2365 row
.label( text
="Enter pose mode to modify bone properties" )
2368 elif active_object
.type == 'LIGHT': #{
2369 _draw_prop_collection( \
2370 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2371 [active_object
.data
.SR_data
] )
2373 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2374 box
.prop( active_object
.SR_data
, "ent_type" )
2375 ent_type
= active_object
.SR_data
.ent_type
2377 col
= getattr( active_object
.SR_data
, ent_type
, None )
2378 if col
!= None and len(col
)!=0:
2379 _draw_prop_collection( \
2380 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2383 if active_object
.type == 'MESH':#{
2384 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2385 if col
!= None and len(col
)!=0:
2386 _draw_prop_collection( \
2387 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2395 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2397 bl_label
="Skate Rift material"
2398 bl_idname
="MATERIAL_PT_sr_material"
2399 bl_space_type
='PROPERTIES'
2400 bl_region_type
='WINDOW'
2401 bl_context
="material"
2403 def draw(_
,context
):
2405 active_object
= bpy
.context
.active_object
2406 if active_object
== None: return
2407 active_mat
= active_object
.active_material
2408 if active_mat
== None: return
2410 info
= material_info( active_mat
)
2412 if 'tex_diffuse' in info
:#{
2413 _
.layout
.label( icon
='INFO', \
2414 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2417 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2418 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2419 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2421 if active_mat
.SR_data
.collision
:#{
2422 box
= _
.layout
.box()
2425 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2426 (active_mat
.SR_data
.shader
!= 'boundary') and \
2427 (active_mat
.SR_data
.shader
!= 'walking'):#{
2428 row
.prop( active_mat
.SR_data
, "skate_surface" )
2429 row
.prop( active_mat
.SR_data
, "grind_surface" )
2430 row
.prop( active_mat
.SR_data
, "grow_grass" )
2431 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2435 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2436 box
= _
.layout
.box()
2437 box
.prop( active_mat
.SR_data
, "blend_offset" )
2438 box
.prop( active_mat
.SR_data
, "sand_colour" )
2440 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2441 box
= _
.layout
.box()
2442 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2443 box
.prop( active_mat
.SR_data
, "blend_offset" )
2445 elif active_mat
.SR_data
.shader
== "water":#{
2446 box
= _
.layout
.box()
2447 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2448 box
.prop( active_mat
.SR_data
, "shore_colour" )
2449 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2450 box
.prop( active_mat
.SR_data
, "water_fog" )
2451 box
.prop( active_mat
.SR_data
, "water_fresnel" )
2452 box
.prop( active_mat
.SR_data
, "water_scale" )
2453 box
.prop( active_mat
.SR_data
, "water_rate" )
2455 elif active_mat
.SR_data
.shader
== "cubemap":#{
2456 box
= _
.layout
.box()
2457 box
.prop( active_mat
.SR_data
, "cubemap" )
2458 box
.prop( active_mat
.SR_data
, "tint" )
2461 _
.layout
.label( text
="" )
2462 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2463 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2467 def sr_get_type_enum( scene
, context
):
2469 items
= [('none','None',"")]
2470 mesh_entities
=['ent_gate','ent_water']
2471 point_entities
=['ent_spawn','ent_route_node','ent_route']
2473 for e
in point_entities
: items
+= [(e
,e
,'')]
2475 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2476 if context
.active_object
.type == 'MESH': #{
2477 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2481 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2487 def sr_on_type_change( _
, context
):
2489 obj
= context
.active_object
2490 ent_type
= obj
.SR_data
.ent_type
2491 if ent_type
== 'none': return
2492 if obj
.type == 'MESH':#{
2493 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2494 if col
!= None and len(col
)==0: col
.add()
2497 col
= getattr( obj
.SR_data
, ent_type
, None )
2498 if col
!= None and len(col
)==0: col
.add()
2501 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2503 alias
: bpy
.props
.StringProperty( name
='alias' )
2506 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2508 target
: bpy
.props
.PointerProperty( \
2509 type=bpy
.types
.Object
, name
="destination", \
2510 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2512 key
: bpy
.props
.StringProperty()
2513 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2514 ('nonlocal', 'Non-Local', "")))
2516 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2517 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2518 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2521 def sr_inspector( layout
, data
):
2524 box
.prop( data
[0], 'tipo', text
="subtype" )
2526 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2527 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2530 flags
.prop( data
[0], 'flip' )
2531 flags
.prop( data
[0], 'custom' )
2532 flags
.prop( data
[0], 'locked' )
2536 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2538 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2541 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2543 target
: bpy
.props
.PointerProperty( \
2544 type=bpy
.types
.Object
, name
='target', \
2545 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2548 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2550 world
: bpy
.props
.StringProperty( name
='world UID' )
2551 proxy
: bpy
.props
.PointerProperty( \
2552 type=bpy
.types
.Object
, name
='proxy', \
2553 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2554 camera
: bpy
.props
.PointerProperty( \
2555 type=bpy
.types
.Object
, name
="Camera", \
2556 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2559 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2561 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2563 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2565 layout
.prop( item
, 'target', text
='', emboss
=False )
2569 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2571 active_object
= context
.active_object
2572 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2573 lista
= getattr(data
,collection_name
)
2574 index
= getattr(data
,F
'{collection_name}_index')
2578 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2582 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2584 active_object
= context
.active_object
2585 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2589 def copy_propgroup( de
, to
):
2591 for a
in de
.__annotations
__:#{
2592 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2596 while len(cb
) != len(ca
):#{
2597 if len(cb
) < len(ca
): cb
.add()
2600 for i
in range(len(ca
)):#{
2601 copy_propgroup(ca
[i
],cb
[i
])
2605 setattr(to
,a
,getattr(de
,a
))
2610 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2612 bl_idname
= "skaterift.copy_entity_data"
2613 bl_label
= "Copy entity data"
2615 def execute(self
, context
):#{
2616 data
= context
.active_object
.SR_data
2617 new_type
= data
.ent_type
2618 print( F
"Copy entity data from: {context.active_object.name}" )
2620 for obj
in context
.selected_objects
:#{
2621 if obj
!= context
.active_object
:#{
2622 print( F
" To: {obj.name}" )
2624 obj
.SR_data
.ent_type
= new_type
2626 if active_object
.type == 'MESH':#{
2627 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2628 if col
!= None and len(col
)==0: col
.add()
2629 mdata
= context
.active_object
.data
.SR_data
2630 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2633 col
= getattr( obj
.SR_data
, new_type
, None )
2634 if col
!= None and len(col
)==0: col
.add()
2635 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2642 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2644 bl_idname
= "skaterift.new_entry"
2645 bl_label
= "Add gate"
2647 def execute(self
, context
):#{
2648 return internal_listadd_execute(self
,context
,'ent_route','gates')
2652 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2654 bl_idname
= "skaterift.del_entry"
2655 bl_label
= "Remove gate"
2658 def poll(cls
, context
):#{
2659 active_object
= context
.active_object
2660 if obj_ent_type(active_object
) == 'ent_route':#{
2661 return active_object
.SR_data
.ent_route
[0].gates
2666 def execute(self
, context
):#{
2667 return internal_listdel_execute(self
,context
,'ent_route','gates')
2671 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2673 bl_idname
= "skaterift.al_new_entry"
2674 bl_label
= "Add file"
2676 def execute(self
, context
):#{
2677 return internal_listadd_execute(self
,context
,'ent_audio','files')
2681 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2683 bl_idname
= "skaterift.al_del_entry"
2684 bl_label
= "Remove file"
2687 def poll(cls
, context
):#{
2688 active_object
= context
.active_object
2689 if obj_ent_type(active_object
) == 'ent_audio':#{
2690 return active_object
.SR_data
.ent_audio
[0].files
2695 def execute(self
, context
):#{
2696 return internal_listdel_execute(self
,context
,'ent_audio','files')
2701 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2703 bl_idname
= "skaterift.gl_new_entry"
2704 bl_label
= "Add glyph"
2706 def execute(self
, context
):#{
2707 active_object
= context
.active_object
2709 font
= active_object
.SR_data
.ent_font
[0]
2712 if len(font
.glyphs
) > 1:#{
2713 prev
= font
.glyphs
[-2]
2714 cur
= font
.glyphs
[-1]
2716 cur
.bounds
= prev
.bounds
2717 cur
.utf32
= prev
.utf32
+1
2724 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2726 bl_idname
= "skaterift.gl_del_entry"
2727 bl_label
= "Remove Glyph"
2730 def poll(cls
, context
):#{
2731 active_object
= context
.active_object
2732 if obj_ent_type(active_object
) == 'ent_font':#{
2733 return active_object
.SR_data
.ent_font
[0].glyphs
2738 def execute(self
, context
):#{
2739 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2743 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2745 bl_idname
= "skaterift.gl_move_item"
2747 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2748 ('DOWN', 'Down', ""),))
2751 def poll(cls
, context
):#{
2752 active_object
= context
.active_object
2753 if obj_ent_type(active_object
) == 'ent_font':#{
2754 return active_object
.SR_data
.ent_font
[0].glyphs
2759 def execute(_
, context
):#{
2760 active_object
= context
.active_object
2761 data
= active_object
.SR_data
.ent_font
[0]
2763 index
= data
.glyphs_index
2764 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2765 data
.glyphs
.move( neighbor
, index
)
2767 list_length
= len(data
.glyphs
) - 1
2768 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2770 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2776 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2778 bl_idname
= "skaterift.fv_new_entry"
2779 bl_label
= "Add variant"
2781 def execute(self
, context
):#{
2782 return internal_listadd_execute(self
,context
,'ent_font','variants')
2786 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2788 bl_idname
= "skaterift.fv_del_entry"
2789 bl_label
= "Remove variant"
2792 def poll(cls
, context
):#{
2793 active_object
= context
.active_object
2794 if obj_ent_type(active_object
) == 'ent_font':#{
2795 return active_object
.SR_data
.ent_font
[0].variants
2800 def execute(self
, context
):#{
2801 return internal_listdel_execute(self
,context
,'ent_font','variants')
2805 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2807 path
: bpy
.props
.StringProperty( name
="Path" )
2808 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2811 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2813 bl_idname
= 'SR_UL_AUDIO_LIST'
2815 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2817 split
= layout
.split(factor
=0.7)
2819 c
.prop( item
, 'path', text
='', emboss
=False )
2821 c
.prop( item
, 'probability', text
='%', emboss
=True )
2825 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2827 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2829 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2831 layout
.prop( item
, 'mesh', emboss
=False )
2832 layout
.prop( item
, 'tipo' )
2836 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2838 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2840 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2842 s0
= layout
.split(factor
=0.3)
2844 s1
= c
.split(factor
=0.3)
2847 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2851 c
.prop( item
, 'utf32', text
='', emboss
=True )
2854 row
.prop( item
, 'bounds', text
='', emboss
=False )
2858 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2860 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2861 gates_index
: bpy
.props
.IntProperty()
2863 colour
: bpy
.props
.FloatVectorProperty( \
2867 default
=Vector((0.79,0.63,0.48)),\
2868 description
="Route colour"\
2871 alias
: bpy
.props
.StringProperty(\
2873 default
="Untitled Course")
2875 cam
: bpy
.props
.PointerProperty( \
2876 type=bpy
.types
.Object
, name
="Viewpoint", \
2877 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2880 def sr_inspector( layout
, data
):
2882 layout
.prop( data
[0], 'alias' )
2883 layout
.prop( data
[0], 'colour' )
2884 layout
.prop( data
[0], 'cam' )
2886 layout
.label( text
='Checkpoints' )
2887 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2888 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2891 row
.operator( 'skaterift.new_entry', text
='Add' )
2892 row
.operator( 'skaterift.del_entry', text
='Remove' )
2897 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
2898 bl_idname
= "skaterift.ent_list_new_entry"
2899 bl_label
= "Add entity"
2901 def execute(self
, context
):#{
2902 return internal_listadd_execute(self
,context
,'ent_list','entities')
2906 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
2907 bl_idname
= "skaterift.ent_list_del_entry"
2908 bl_label
= "Remove entity"
2911 def poll(cls
, context
):#{
2912 active_object
= context
.active_object
2913 if obj_ent_type(active_object
) == 'ent_list':#{
2914 return active_object
.SR_data
.ent_list
[0].entities
2919 def execute(self
, context
):#{
2920 return internal_listdel_execute(self
,context
,'ent_list','entities')
2924 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
2926 target
: bpy
.props
.PointerProperty( \
2927 type=bpy
.types
.Object
, name
='target' )
2930 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
2931 bl_idname
= 'SR_UL_ENT_LIST'
2933 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
2934 layout
.prop( item
, 'target', text
='', emboss
=False )
2938 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
2939 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
2940 entities_index
: bpy
.props
.IntProperty()
2943 def sr_inspector( layout
, data
):#{
2944 layout
.label( text
='Entities' )
2945 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
2946 data
[0], 'entities', data
[0], \
2947 'entities_index', rows
=5)
2950 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
2951 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
2955 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
2956 nothing
: bpy
.props
.StringProperty()
2959 class SR_OBJECT_ENT_NPC(bpy
.types
.PropertyGroup
):#{
2960 au
: bpy
.props
.IntProperty()
2961 context
: bpy
.props
.IntProperty()
2962 cam
: bpy
.props
.PointerProperty( \
2963 type=bpy
.types
.Object
, name
="Viewpoint", \
2964 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2967 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
2968 subtype
: bpy
.props
.EnumProperty(
2970 items
=[('0','Trigger',''),
2971 ('1','Particles (0.1s)','')]
2974 target
: bpy
.props
.PointerProperty( \
2975 type=bpy
.types
.Object
, name
="Target", \
2976 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
2977 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
2978 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
2981 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
2983 box
.prop( data
[0], propname
)
2985 for evname
in evs
:#{
2987 row
.prop( data
[0], propname
+ evname
)
2989 target
= getattr( data
[0], propname
)
2991 tipo
= target
.SR_data
.ent_type
2992 cls
= globals()[ tipo
]
2994 table
= getattr( cls
, 'sr_functions', None )
2996 index
= getattr( data
[0], propname
+ evname
)
2998 row
.label( text
=table
[index
] )
3000 row
.label( text
="undefined function" )
3004 row
.label( text
="..." )
3011 def sr_inspector( layout
, data
):#{
3012 layout
.prop( data
[0], 'subtype' )
3013 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3014 ['_event','_event_leave'] )
3018 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3020 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3021 files_index
: bpy
.props
.IntProperty()
3023 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3024 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3025 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3026 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3028 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3029 formato
: bpy
.props
.EnumProperty(
3031 items
=[('0','Uncompressed Mono',''),
3032 ('1','Compressed Vorbis',''),
3033 ('2','[vg] Bird Synthesis','')]
3035 probability_curve
: bpy
.props
.EnumProperty(
3036 name
="Probability Curve",
3037 items
=[('0','Constant',''),
3038 ('1','Wildlife Daytime',''),
3039 ('2','Wildlife Nighttime','')])
3040 channel_behaviour
: bpy
.props
.EnumProperty(
3041 name
="Channel Behaviour",
3042 items
=[('0','Unlimited',''),
3043 ('1','Discard if group full', ''),
3044 ('2','Crossfade if group full','')])
3046 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3049 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3050 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3053 def sr_inspector( layout
, data
):
3055 layout
.prop( data
[0], 'formato' )
3056 layout
.prop( data
[0], 'volume' )
3059 box
.label( text
='Channels' )
3060 split
= box
.split(factor
=0.3)
3062 c
.prop( data
[0], 'max_channels' )
3064 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3065 if data
[0].channel_behaviour
>= '1':
3066 box
.prop( data
[0], 'group' )
3067 if data
[0].channel_behaviour
== '2':
3068 box
.prop( data
[0], 'transition_duration' )
3071 box
.label( text
='Flags' )
3072 box
.prop( data
[0], 'flag_3d' )
3073 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3075 box
.prop( data
[0], 'flag_loop' )
3076 box
.prop( data
[0], 'flag_auto' )
3078 layout
.prop( data
[0], 'probability_curve' )
3080 split
= layout
.split(factor
=0.7)
3082 c
.label( text
='Filepath' )
3084 c
.label( text
='Chance' )
3085 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3086 data
[0], 'files', data
[0], 'files_index', rows
=5)
3089 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3090 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3094 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3096 alias
: bpy
.props
.StringProperty()
3097 flags
: bpy
.props
.IntProperty()
3100 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3102 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3103 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3104 utf32
: bpy
.props
.IntProperty()
3107 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3109 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3110 utf32
: bpy
.props
.IntProperty()
3113 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3115 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3116 tipo
: bpy
.props
.StringProperty()
3119 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3121 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3122 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3123 alias
: bpy
.props
.StringProperty()
3125 glyphs_index
: bpy
.props
.IntProperty()
3126 variants_index
: bpy
.props
.IntProperty()
3129 def sr_inspector( layout
, data
):
3131 layout
.prop( data
[0], 'alias' )
3133 layout
.label( text
='Variants' )
3134 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3135 data
[0], 'variants', data
[0], 'variants_index',\
3138 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3139 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3141 layout
.label( text
='ASCII Glyphs' )
3142 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3143 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3146 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3147 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3148 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3149 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3153 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3155 speed
: bpy
.props
.FloatProperty(default
=1.0)
3158 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3160 tipo
: bpy
.props
.EnumProperty( name
='Type',
3161 items
=[('0','boards',''),
3162 ('1','character',''),
3164 ('4','server','')] )
3165 mark_rack
: bpy
.props
.PointerProperty( \
3166 type=bpy
.types
.Object
, name
="Board Rack", \
3167 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3168 mark_display
: bpy
.props
.PointerProperty( \
3169 type=bpy
.types
.Object
, name
="Selected Board Display", \
3170 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3171 mark_info
: bpy
.props
.PointerProperty( \
3172 type=bpy
.types
.Object
, name
="Selected Board Info", \
3173 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3174 ['ent_marker','ent_prop']))
3175 cam
: bpy
.props
.PointerProperty( \
3176 type=bpy
.types
.Object
, name
="Viewpoint", \
3177 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3180 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3182 mark_display
: bpy
.props
.PointerProperty( \
3183 type=bpy
.types
.Object
, name
="Board Display", \
3184 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3185 mark_display1
: bpy
.props
.PointerProperty( \
3186 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3187 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3188 cam
: bpy
.props
.PointerProperty( \
3189 type=bpy
.types
.Object
, name
="Viewpoint", \
3190 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3193 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3195 link0
: bpy
.props
.PointerProperty( \
3196 type=bpy
.types
.Object
, name
="Link 0", \
3197 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3198 link1
: bpy
.props
.PointerProperty( \
3199 type=bpy
.types
.Object
, name
="Link 1", \
3200 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3201 link2
: bpy
.props
.PointerProperty( \
3202 type=bpy
.types
.Object
, name
="Link 2", \
3203 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3204 link3
: bpy
.props
.PointerProperty( \
3205 type=bpy
.types
.Object
, name
="Link 3", \
3206 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3208 newloc
: bpy
.props
.PointerProperty( \
3209 type=bpy
.types
.Object
, name
="New location", \
3210 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3211 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3212 items
=[('0','append',''),
3213 ('1','replace','')])
3215 camera
: bpy
.props
.PointerProperty( \
3216 type=bpy
.types
.Object
, name
="Camera", \
3217 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3219 slider_minloc
: bpy
.props
.PointerProperty( \
3220 type=bpy
.types
.Object
, name
="Slider min", \
3221 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3222 slider_maxloc
: bpy
.props
.PointerProperty( \
3223 type=bpy
.types
.Object
, name
="Slider max", \
3224 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3225 slider_handle
: bpy
.props
.PointerProperty( \
3226 type=bpy
.types
.Object
, name
="Slider handle", \
3227 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3229 checkmark
: bpy
.props
.PointerProperty( \
3230 type=bpy
.types
.Object
, name
="Checked", \
3231 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3233 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3235 string
: bpy
.props
.StringProperty( name
="String" )
3236 tipo
: bpy
.props
.EnumProperty( name
='Type',
3237 items
=[('0','visual',''),
3238 ('1','event button',''),
3239 ('2','page button',''),
3244 ('7','visual(no colourize)','')])
3247 def sr_inspector( layout
, data
):
3251 box
.prop( data
, 'tipo' )
3253 if data
.tipo
== '0' or data
.tipo
== '7':#{
3254 box
.prop( data
, 'string', text
='Name' )
3257 elif data
.tipo
== '1':#{
3258 box
.prop( data
, 'string', text
='Event' )
3260 elif data
.tipo
== '2':#{
3261 box
.prop( data
, 'string', text
='Page' )
3262 box
.prop( data
, 'stack_behaviour' )
3264 elif data
.tipo
== '3':#{
3265 box
.prop( data
, 'string', text
='Data (i32)' )
3266 box
.prop( data
, 'checkmark' )
3268 elif data
.tipo
== '4':#{
3269 box
.prop( data
, 'string', text
='Data (f32)' )
3270 box
.prop( data
, 'slider_minloc' )
3271 box
.prop( data
, 'slider_maxloc' )
3272 box
.prop( data
, 'slider_handle' )
3274 box
.label( text
="Links" )
3275 box
.prop( data
, 'link0', text
='v0' )
3276 box
.prop( data
, 'link1', text
='v1' )
3279 elif data
.tipo
== '5':#{
3280 box
.prop( data
, 'string', text
='Page Name' )
3281 box
.prop( data
, 'newloc', text
='Entry Point' )
3282 box
.prop( data
, 'camera', text
='Viewpoint' )
3285 elif data
.tipo
== '6':#{
3286 box
.prop( data
, 'string', text
='ID' )
3287 box
.prop( data
, 'font_variant' )
3292 box
.label( text
="Links" )
3293 box
.prop( data
, 'link0' )
3294 box
.prop( data
, 'link1' )
3295 box
.prop( data
, 'link2' )
3296 box
.prop( data
, 'link3' )
3300 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3302 name
: bpy
.props
.StringProperty(name
="Name")
3303 desc
: bpy
.props
.StringProperty(name
="Description")
3304 author
: bpy
.props
.StringProperty(name
="Author")
3305 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3307 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3308 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3309 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3311 water_safe
: bpy
.props
.BoolProperty(name
="Water is Safe")
3314 def sr_inspector( layout
, data
):
3316 layout
.prop( data
[0], 'name' )
3317 layout
.prop( data
[0], 'desc' )
3318 layout
.prop( data
[0], 'author' )
3320 layout
.prop( data
[0], 'fix_time' )
3321 if data
[0].fix_time
:
3322 layout
.prop( data
[0], 'fixed_time' )
3324 layout
.prop( data
[0], 'timezone' )
3326 layout
.prop( data
[0], 'water_safe' )
3330 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3332 command
: bpy
.props
.StringProperty(name
="Command Line")
3335 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3336 proxima
: bpy
.props
.PointerProperty( \
3337 type=bpy
.types
.Object
, name
="Next", \
3338 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3339 target
: bpy
.props
.PointerProperty( \
3340 type=bpy
.types
.Object
, name
="Win", \
3341 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3342 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3343 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3344 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3345 items
=[('0','none',''),
3346 (str(0x1),'trick_shuvit',''),
3347 (str(0x2),'trick_kickflip',''),
3348 (str(0x4),'trick_treflip',''),
3349 (str(0x1|
0x2|
0x4),'trick_any',''),
3350 (str(0x8),'flip_back',''),
3351 (str(0x10),'flip_front',''),
3352 (str(0x8|
0x10),'flip_any',''),
3353 (str(0x20),'grind_truck_any',''),
3354 (str(0x40),'grind_board_any',''),
3355 (str(0x20|
0x40),'grind_any',''),
3356 (str(0x80),'footplant',''),
3357 (str(0x100),'passthrough',''),
3361 def sr_inspector( layout
, data
):#{
3362 layout
.prop( data
[0], 'proxima' )
3363 layout
.prop( data
[0], 'time_limit' )
3364 layout
.prop( data
[0], 'filtrar' )
3365 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3369 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3370 alias
: bpy
.props
.StringProperty( name
="Alias" )
3372 target
: bpy
.props
.PointerProperty( \
3373 type=bpy
.types
.Object
, name
="On Complete", \
3374 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3375 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3376 reset
: bpy
.props
.PointerProperty( \
3377 type=bpy
.types
.Object
, name
="On Reset", \
3378 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3379 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3381 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3383 first
: bpy
.props
.PointerProperty( \
3384 type=bpy
.types
.Object
, name
="First Objective", \
3385 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3387 camera
: bpy
.props
.PointerProperty( \
3388 type=bpy
.types
.Object
, name
="Camera", \
3389 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3393 def sr_inspector( layout
, data
):#{
3394 layout
.prop( data
[0], 'alias' )
3395 layout
.prop( data
[0], 'camera' )
3396 layout
.prop( data
[0], 'first' )
3397 layout
.prop( data
[0], 'time_limit' )
3398 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3399 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3403 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3404 title
: bpy
.props
.StringProperty( name
="Title" )
3405 zone_volume
: bpy
.props
.PointerProperty(
3406 type=bpy
.types
.Object
, name
="Zone Volume", \
3407 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3409 target0
: bpy
.props
.PointerProperty( \
3410 type=bpy
.types
.Object
, name
="Triger on unlock", \
3411 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3412 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3415 def sr_inspector( layout
, data
):#{
3416 layout
.prop( data
[0], 'title' )
3417 layout
.prop( data
[0], 'zone_volume' )
3418 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3422 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3423 target0
: bpy
.props
.PointerProperty( \
3424 type=bpy
.types
.Object
, name
="Target 0", \
3425 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3426 target1
: bpy
.props
.PointerProperty( \
3427 type=bpy
.types
.Object
, name
="Target 1", \
3428 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3429 target2
: bpy
.props
.PointerProperty( \
3430 type=bpy
.types
.Object
, name
="Target 2", \
3431 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3432 target3
: bpy
.props
.PointerProperty( \
3433 type=bpy
.types
.Object
, name
="Target 3", \
3434 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3436 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3437 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3438 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3439 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3442 def sr_inspector( layout
, data
):#{
3443 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3444 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3445 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3446 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3450 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3452 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3453 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3454 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3455 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3456 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3457 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3458 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3459 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3460 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3461 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3462 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3464 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3465 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3466 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3467 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3468 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3469 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3470 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3471 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3472 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3473 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3474 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3475 ent_npc
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_NPC
)
3477 ent_type
: bpy
.props
.EnumProperty(
3479 items
=sr_entity_list
,
3480 update
=sr_on_type_change
3484 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3486 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3489 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3491 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3494 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3496 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3497 items
=[('0','none',''),
3499 ('2','capsule','')])
3501 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3502 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3504 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3506 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3507 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3508 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3509 conet
: bpy
.props
.FloatProperty( name
='t' )
3512 def sr_inspector( layout
, data
):
3516 box
.prop( data
, 'collider' )
3518 if int(data
.collider
)>0:#{
3520 row
.prop( data
, 'collider_min' )
3522 row
.prop( data
, 'collider_max' )
3526 box
.prop( data
, 'cone_constraint' )
3527 if data
.cone_constraint
:#{
3529 row
.prop( data
, 'conevx' )
3531 row
.prop( data
, 'conevy' )
3533 row
.prop( data
, 'coneva' )
3534 box
.prop( data
, 'conet' )
3539 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3541 shader
: bpy
.props
.EnumProperty(
3544 ('standard',"standard",''),
3545 ('standard_cutout', "standard_cutout", ''),
3546 ('terrain_blend', "terrain_blend", ''),
3547 ('vertex_blend', "vertex_blend", ''),
3548 ('water',"water",''),
3549 ('invisible','Invisible',''),
3550 ('boundary','Boundary',''),
3551 ('fxglow','FX Glow',''),
3552 ('cubemap','Cubemap',''),
3553 ('walking','Walking',''),
3554 ('foliage','Foliage','')
3557 surface_prop
: bpy
.props
.EnumProperty(
3558 name
="Surface Property",
3560 ('0','concrete',''),
3565 ('5','snow (low friction)',''),
3566 ('6','sand (medium friction)','')
3569 collision
: bpy
.props
.BoolProperty( \
3570 name
="Collisions Enabled",\
3572 description
= "Can the player collide with this material?"\
3574 skate_surface
: bpy
.props
.BoolProperty( \
3575 name
="Skate Target", \
3577 description
= "Should the game try to target this surface?" \
3579 grind_surface
: bpy
.props
.BoolProperty( \
3582 description
= "Can you grind on this surface?" \
3584 grow_grass
: bpy
.props
.BoolProperty( \
3585 name
="Grow Grass", \
3587 description
= "Spawn grass sprites on this surface?" \
3589 preview_visibile
: bpy
.props
.BoolProperty( \
3590 name
="Preview visibile", \
3592 description
= "Show this material in preview models?" \
3594 blend_offset
: bpy
.props
.FloatVectorProperty( \
3595 name
="Blend Offset", \
3597 default
=Vector((0.5,0.0)),\
3598 description
="When surface is more than 45 degrees, add this vector " +\
3601 sand_colour
: bpy
.props
.FloatVectorProperty( \
3602 name
="Sand Colour",\
3604 min=0.0,max=1.0,size
=4,\
3605 default
=Vector((0.79,0.63,0.48,1.0)),\
3606 description
="Blend to this colour near the 0 coordinate on UP axis"\
3608 shore_colour
: bpy
.props
.FloatVectorProperty( \
3609 name
="Shore Colour",\
3612 default
=Vector((0.03,0.32,0.61)),\
3613 description
="Water colour at the shoreline"\
3615 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3616 name
="Ocean Colour",\
3619 default
=Vector((0.0,0.006,0.03)),\
3620 description
="Water colour in the deep bits"\
3622 tint
: bpy
.props
.FloatVectorProperty( \
3627 default
=Vector((1.0,1.0,1.0,1.0)),\
3628 description
="Reflection tint"\
3631 water_fog
: bpy
.props
.FloatProperty( \
3634 description
="(default: 0.04) Cloudiness of water"\
3636 water_fresnel
: bpy
.props
.FloatProperty( \
3637 name
="Water Fresnel", \
3639 description
="(default: 5.0) Reflection/Fog Fresnel Ratio"\
3641 water_scale
: bpy
.props
.FloatProperty( \
3642 name
="Water Scale", \
3644 description
="(default: 0.008) Size of water texture"\
3646 water_rate
: bpy
.props
.FloatVectorProperty( \
3647 name
= "Water Wave Rate",\
3649 default
=Vector(( 0.008, 0.006, 0.003, 0.03 )),\
3651 "(default: 0.008, 0.006, 0.003, 0.03) Rate which water bump texture moves"\
3654 cubemap
: bpy
.props
.PointerProperty( \
3655 type=bpy
.types
.Object
, name
="cubemap", \
3656 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3658 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3661 # ---------------------------------------------------------------------------- #
3665 # ---------------------------------------------------------------------------- #
3667 cv_view_draw_handler
= None
3668 cv_view_pixel_handler
= None
3669 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3671 cv_view_colours
= []
3672 cv_view_course_i
= 0
3674 # Draw axis alligned sphere at position with radius
3676 def cv_draw_sphere( pos
, radius
, colour
):
3678 global cv_view_verts
, cv_view_colours
3680 ly
= pos
+ Vector((0,0,radius
))
3681 lx
= pos
+ Vector((0,radius
,0))
3682 lz
= pos
+ Vector((0,0,radius
))
3684 pi
= 3.14159265358979323846264
3686 for i
in range(16):#{
3687 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3691 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3692 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3693 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3695 cv_view_verts
+= [ px
, lx
]
3696 cv_view_verts
+= [ py
, ly
]
3697 cv_view_verts
+= [ pz
, lz
]
3699 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3708 # Draw axis alligned sphere at position with radius
3710 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3712 global cv_view_verts
, cv_view_colours
3714 ly
= pos
+ tz
*radius
3715 lx
= pos
+ ty
*radius
3716 lz
= pos
+ tz
*radius
3718 pi
= 3.14159265358979323846264
3720 for i
in range(16):#{
3721 t
= ((i
+1.0) * 1.0/16.0) * pi
3725 s1
= math
.sin(t
*2.0)
3726 c1
= math
.cos(t
*2.0)
3728 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3729 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3730 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3732 cv_view_verts
+= [ px
, lx
]
3733 cv_view_verts
+= [ py
, ly
]
3734 cv_view_verts
+= [ pz
, lz
]
3736 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3745 # Draw transformed -1 -> 1 cube
3747 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3749 global cv_view_verts
, cv_view_colours
3755 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3756 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3757 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3758 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3759 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3760 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3761 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3762 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3764 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3765 (0,4),(1,5),(2,6),(3,7)]
3770 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3771 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3772 cv_view_colours
+= [colour
, colour
]
3777 # Draw line with colour
3779 def cv_draw_line( p0
, p1
, colour
):
3781 global cv_view_verts
, cv_view_colours
3783 cv_view_verts
+= [p0
,p1
]
3784 cv_view_colours
+= [colour
, colour
]
3788 # Draw line with colour(s)
3790 def cv_draw_line2( p0
, p1
, c0
, c1
):
3792 global cv_view_verts
, cv_view_colours
3794 cv_view_verts
+= [p0
,p1
]
3795 cv_view_colours
+= [c0
,c1
]
3801 def cv_tangent_basis( n
, tx
, ty
):
3803 if abs( n
[0] ) >= 0.57735027:#{
3822 # Draw coloured arrow
3824 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
3826 global cv_view_verts
, cv_view_colours
3832 tx
= Vector((1,0,0))
3833 ty
= Vector((1,0,0))
3834 cv_tangent_basis( n
, tx
, ty
)
3840 gpu
.state
.line_width_set(1.0)
3843 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3844 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3848 gpu
.state
.line_width_set(3.0)
3849 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
3851 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
3853 gpu
.state
.line_width_set(2.0)
3857 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3859 global cv_view_verts
, cv_view_colours
3861 for i
in range(dots
):#{
3865 p2
= p0
*(1.0-t0
)+p1
*t0
3866 p3
= p0
*(1.0-t1
)+p1
*t1
3868 cv_view_verts
+= [p2
,p3
]
3869 cv_view_colours
+= [c0
,c0
]
3874 # Drawhandles of a bezier control point
3876 def cv_draw_bhandle( obj
, direction
, colour
):
3878 global cv_view_verts
, cv_view_colours
3881 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3883 cv_view_verts
+= [p0
]
3884 cv_view_verts
+= [h0
]
3885 cv_view_colours
+= [colour
,colour
]
3889 # Draw a bezier curve (at fixed resolution 10)
3891 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3893 global cv_view_verts
, cv_view_colours
3896 for i
in range(10):#{
3902 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3904 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3905 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3906 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3913 # I think this one extends the handles of the bezier otwards......
3915 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3917 global cv_view_course_i
3919 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3921 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3922 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3923 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3924 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3926 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3930 # Flush the lines buffers. This is called often because god help you if you want
3931 # to do fixed, fast buffers in this catastrophic programming language.
3933 def cv_draw_lines():
3935 global cv_view_shader
, cv_view_verts
, cv_view_colours
3937 if len(cv_view_verts
) < 2:
3940 lines
= batch_for_shader(\
3941 cv_view_shader
, 'LINES', \
3942 { "pos":cv_view_verts
, "color":cv_view_colours
})
3944 if bpy
.context
.scene
.SR_data
.gizmos
:
3945 lines
.draw( cv_view_shader
)
3948 cv_view_colours
= []
3951 # I dont remember what this does exactly
3953 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3955 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3958 # Semi circle to show the limit. and some lines
3960 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3962 global cv_view_verts
, cv_view_colours
3967 for x
in range(16):#{
3970 a0
= amin
*(1.0-t0
)+amax
*t0
3971 a1
= amin
*(1.0-t1
)+amax
*t1
3973 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3974 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3976 p0
=obj
.matrix_world
@ p0
3977 p1
=obj
.matrix_world
@ p1
3978 cv_view_verts
+= [p0
,p1
]
3979 cv_view_colours
+= [colour
,colour
]
3982 cv_view_verts
+= [p0
,center
]
3983 cv_view_colours
+= [colour
,colour
]
3986 cv_view_verts
+= [p1
,center
]
3987 cv_view_colours
+= [colour
,colour
]
3991 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
3992 cv_view_colours
+= [colour
,colour
]
3997 # Cone and twist limit
3999 def draw_cone_twist( center
, vx
, vy
, va
):
4001 global cv_view_verts
, cv_view_colours
4002 axis
= vy
.cross( vx
)
4007 cv_view_verts
+= [center
, center
+va
*size
]
4008 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4010 for x
in range(32):#{
4011 t0
= (x
/32) * math
.tau
4012 t1
= ((x
+1)/32) * math
.tau
4019 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4020 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4022 col0
= ( abs(c0
), abs(s0
), 0.0 )
4023 col1
= ( abs(c1
), abs(s1
), 0.0 )
4025 cv_view_verts
+= [center
, p0
, p0
, p1
]
4026 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4032 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4034 def draw_skeleton_helpers( obj
):
4036 global cv_view_verts
, cv_view_colours
4038 if obj
.data
.pose_position
!= 'REST':#{
4042 for bone
in obj
.data
.bones
:#{
4044 a
= Vector((bone
.SR_data
.collider_min
[0],
4045 bone
.SR_data
.collider_min
[1],
4046 bone
.SR_data
.collider_min
[2]))
4047 b
= Vector((bone
.SR_data
.collider_max
[0],
4048 bone
.SR_data
.collider_max
[1],
4049 bone
.SR_data
.collider_max
[2]))
4051 if bone
.SR_data
.collider
== '1':#{
4053 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4054 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4055 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4056 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4057 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4058 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4059 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4060 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4062 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4063 (0,4),(1,5),(2,6),(3,7)]
4069 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4070 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4071 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4074 elif bone
.SR_data
.collider
== '2':#{
4079 for i
in range(3):#{
4080 if abs(v0
[i
]) > largest
:#{
4081 largest
= abs(v0
[i
])
4086 v1
= Vector((0,0,0))
4087 v1
[major_axis
] = 1.0
4089 tx
= Vector((0,0,0))
4090 ty
= Vector((0,0,0))
4092 cv_tangent_basis( v1
, tx
, ty
)
4093 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4094 l
= v0
[ major_axis
] - r
*2
4096 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4097 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4099 colour
= [0.2,0.2,0.2]
4100 colour
[major_axis
] = 0.5
4102 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4103 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4104 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4105 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4106 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4107 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4113 center
= obj
.matrix_world
@ c
4114 if bone
.SR_data
.cone_constraint
:#{
4115 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4116 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4117 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4118 draw_cone_twist( center
, vx
, vy
, va
)
4123 def cv_draw_wireframe( mdl
, points
, colour
):#{
4124 for i
in range(len(points
)//2):#{
4125 p0
= mdl
@points[i
*2+0]
4126 p1
= mdl
@points[i
*2+1]
4127 cv_draw_line( p0
, p1
, colour
)
4131 def cv_ent_gate( obj
):
4133 global cv_view_verts
, cv_view_colours
4135 if obj
.type != 'MESH': return
4137 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4138 data
= obj
.SR_data
.ent_gate
[0]
4139 dims
= mesh_data
.dimensions
4142 c
= Vector((0,0,dims
[2]))
4144 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4145 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4146 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4147 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4148 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4149 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4150 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4151 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4152 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4154 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4156 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4158 p0
= r3d
.view_matrix
.inverted().translation
4159 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4160 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4162 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4168 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4169 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4170 cv_view_colours
+= [cc
,cc
]
4174 if data
.target
!= None:
4175 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4178 def cv_ent_volume( obj
):
4180 global cv_view_verts
, cv_view_colours
4182 data
= obj
.SR_data
.ent_volume
[0]
4184 if data
.subtype
== '0':#{
4185 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4188 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4191 elif data
.subtype
== '1':#{
4192 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4195 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4200 def dijkstra( graph
, start_node
, target_node
):
4202 unvisited
= [_
for _
in graph
]
4207 shortest_path
[n
] = 9999999.999999
4208 shortest_path
[start_node
] = 0
4211 current_min_node
= None
4212 for n
in unvisited
:#{
4213 if current_min_node
== None:
4214 current_min_node
= n
4215 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4216 current_min_node
= n
4219 for branch
in graph
[current_min_node
]:#{
4220 tentative_value
= shortest_path
[current_min_node
]
4221 tentative_value
+= graph
[current_min_node
][branch
]
4222 if tentative_value
< shortest_path
[branch
]:#{
4223 shortest_path
[branch
] = tentative_value
4224 previous_nodes
[branch
] = current_min_node
4228 unvisited
.remove(current_min_node
)
4233 while node
!= start_node
:#{
4236 if node
not in previous_nodes
: return None
4237 node
= previous_nodes
[node
]
4240 # Add the start node manually
4241 path
.append(start_node
)
4247 def __init__(_
,points
,graph
,subsections
):#{
4250 _
.subsections
= subsections
4254 def create_node_graph( curves
, gates
):
4256 # add endpoints of curves
4263 for c
in range(len(curves
)):#{
4264 for s
in range(len(curves
[c
].data
.splines
)):#{
4265 spline
= curves
[c
].data
.splines
[s
]
4266 l
= len(spline
.points
)
4269 dist
= round(spline
.calc_length(),2)
4272 ib
= point_count
+l
-1
4274 graph
[ia
] = { ib
: dist
}
4275 graph
[ib
] = { ia
: dist
}
4277 for i
in range(len(spline
.points
)):#{
4278 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4279 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4284 if i
== 0: previous
= -1
4285 if i
== len(spline
.points
)-1: proxima
= -1
4287 subsections
.append((spline_count
,previous
,proxima
))
4296 graph_keys
= list(graph
)
4297 for i
in range(len(graph_keys
)-1):#{
4298 for j
in range(i
+1, len(graph_keys
)):#{
4299 if i
%2==0 and i
+1==j
: continue
4303 pi
= route_points
[ni
]
4304 pj
= route_points
[nj
]
4306 dist
= round((pj
-pi
).magnitude
,2)
4309 graph
[ni
][nj
] = dist
4310 graph
[nj
][ni
] = dist
4315 # add and link gates( by name )
4316 for gate
in gates
:#{
4317 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4318 if gate
.SR_data
.ent_gate
[0].target
:
4321 graph
[ gate
.name
] = {}
4323 for i
in range(len(graph_keys
)):#{
4325 pi
= route_points
[ni
]
4327 v0
= pi
-gate
.location
4328 if v0
.dot(v1
) < 0.0: continue
4330 dist
= round(v0
.magnitude
,2)
4333 graph
[ gate
.name
][ ni
] = dist
4334 graph
[ ni
][ gate
.name
] = dist
4339 return dij_graph(route_points
,graph
,subsections
)
4342 def solve_graph( dij
, start
, end
):
4344 path
= dijkstra( dij
.graph
, end
, start
)
4348 for sj
in range(1,len(path
)-2):#{
4351 map0
= dij
.subsections
[i0
]
4352 map1
= dij
.subsections
[i1
]
4354 if map0
[0] == map1
[0]:#{
4355 if map0
[1] == -1: direction
= 2
4360 map0
= dij
.subsections
[i0
]
4361 i1
= map0
[direction
]
4375 full
.append( path
[-2] )
4380 def cv_draw_route( route
, dij
):
4382 pole
= Vector((0.2,0.2,10))
4383 hat
= Vector((1,8,0.2))
4384 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4385 route
.SR_data
.ent_route
[0].colour
[1],
4386 route
.SR_data
.ent_route
[0].colour
[2])
4388 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4389 Vector((0,-6.5,5.5)))
4390 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4391 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4392 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4393 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4395 checkpoints
= route
.SR_data
.ent_route
[0].gates
4397 for i
in range(len(checkpoints
)):#{
4398 gi
= checkpoints
[i
].target
4399 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4402 dest
= gi
.SR_data
.ent_gate
[0].target
4404 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4408 if gi
==gj
: continue # error?
4409 if not gi
or not gj
: continue
4411 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4414 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4415 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4416 for j
in range(len(path
)-1):#{
4419 o0
= dij
.points
[ i0
]
4420 o1
= dij
.points
[ i1
]
4421 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4425 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4431 global cv_view_shader
4432 global cv_view_verts
4433 global cv_view_colours
4434 global cv_view_course_i
4436 cv_view_course_i
= 0
4438 cv_view_colours
= []
4440 cv_view_shader
.bind()
4441 gpu
.state
.depth_mask_set(True)
4442 gpu
.state
.line_width_set(2.0)
4443 gpu
.state
.face_culling_set('BACK')
4444 gpu
.state
.depth_test_set('LESS')
4445 gpu
.state
.blend_set('NONE')
4451 for obj
in bpy
.context
.collection
.objects
:#{
4452 if obj
.type == 'ARMATURE':#{
4453 if obj
.data
.pose_position
== 'REST':
4454 draw_skeleton_helpers( obj
)
4457 ent_type
= obj_ent_type( obj
)
4459 if ent_type
== 'ent_gate':#{
4461 route_gates
+= [obj
]
4463 elif ent_type
== 'ent_route_node':#{
4464 if obj
.type == 'CURVE':#{
4465 route_curves
+= [obj
]
4468 elif ent_type
== 'ent_route':
4470 elif ent_type
== 'ent_volume':#{
4471 cv_ent_volume( obj
)
4473 elif ent_type
== 'ent_objective':#{
4474 data
= obj
.SR_data
.ent_objective
[0]
4476 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4479 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4481 elif ent_type
== 'ent_relay':#{
4482 data
= obj
.SR_data
.ent_relay
[0]
4484 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4486 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4488 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4490 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4492 elif ent_type
== 'ent_challenge':#{
4493 data
= obj
.SR_data
.ent_challenge
[0]
4495 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4497 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4499 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4502 info_cu
= Vector((1.2,0.01,0.72))*0.5
4503 info_co
= Vector((0.0,0.0,0.72))*0.5
4504 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4506 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4508 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4509 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4510 Vector(( 0.1,0.0,0.30))]
4511 for v
in range(len(vs
)):#{
4512 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4515 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4516 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4518 elif ent_type
== 'ent_audio':#{
4519 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4520 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4522 elif ent_type
== 'ent_font':#{
4523 data
= obj
.SR_data
.ent_font
[0]
4525 for i
in range(len(data
.variants
)):#{
4526 sub
= data
.variants
[i
].mesh
4527 if not sub
: continue
4529 for ch
in data
.glyphs
:#{
4530 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4531 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4532 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4533 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4534 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4535 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4537 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4540 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4541 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4545 elif ent_type
== 'ent_glider':#{
4546 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4547 Vector(( 1.13982, 0.137084, -0.026358)), \
4548 Vector(( 0.0, 1.6, 1.0)), \
4549 Vector(( 0.0, -3.0, 1.0)), \
4550 Vector(( -3.45, -1.78, 0.9)), \
4551 Vector(( 0.0, 1.6, 1.0)), \
4552 Vector(( 3.45, -1.78, 0.9)), \
4553 Vector(( 0.0, 1.6, 1.0)), \
4554 Vector(( 3.45, -1.78, 0.9)), \
4555 Vector(( -3.45, -1.78, 0.9))]
4557 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4559 elif ent_type
== 'ent_skateshop':#{
4560 data
= obj
.SR_data
.ent_skateshop
[0]
4561 display
= data
.mark_display
4562 info
= data
.mark_info
4564 if data
.tipo
== '0':#{
4569 rack
= data
.mark_rack
4571 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4572 rack_co
= Vector((0.0,0.0,0.0))
4573 display_cu
= Vector((0.3,1.2,0.1))*0.5
4574 display_co
= Vector((0.0,0.0,0.1))*0.5
4575 info_cu
= Vector((1.2,0.01,0.3))*0.5
4576 info_co
= Vector((0.0,0.0,0.0))*0.5
4578 elif data
.tipo
== '1':#{
4582 display_cu
= Vector((0.4,0.4,2.0))*0.5
4583 display_co
= Vector((0.0,0.0,1.0))*0.5
4584 info_cu
= Vector((1.2,0.01,0.3))*0.5
4585 info_co
= Vector((0.0,0.0,0.0))*0.5
4587 elif data
.tipo
== '2':#{
4591 display_cu
= Vector((1.0,1.0,0.5))*0.5
4592 display_co
= Vector((0.0,0.0,0.5))*0.5
4593 info_cu
= Vector((1.2,0.01,0.3))*0.5
4594 info_co
= Vector((0.0,0.0,0.0))*0.5
4596 elif data
.tipo
== '3':#{
4601 elif data
.tipo
== '4':#{
4608 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4610 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4612 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4614 elif ent_type
== 'ent_swspreview':#{
4616 data
= obj
.SR_data
.ent_swspreview
[0]
4617 display
= data
.mark_display
4618 display1
= data
.mark_display1
4619 display_cu
= Vector((0.3,1.2,0.1))*0.5
4620 display_co
= Vector((0.0,0.0,0.1))*0.5
4622 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4624 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4626 # elif ent_type == 'ent_list':#{
4627 # data = obj.SR_data.ent_list[0]
4628 # for child in data.entities:#{
4629 # if child.target:#{
4630 # cv_draw_arrow( obj.location, child.target.location, \
4635 elif ent_type
== 'ent_region':#{
4636 data
= obj
.SR_data
.ent_region
[0]
4638 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4642 elif ent_type
== 'ent_menuitem':#{
4643 for i
,col
in enumerate(obj
.users_collection
):#{
4644 colour32
= hash_djb2( col
.name
)
4645 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4646 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4647 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4649 vs
= [None for _
in range(8)]
4651 for j
in range(8):#{
4652 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4653 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4655 vs
[j
] = obj
.matrix_world
@ v0
4657 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4658 (0,4),(1,5),(2,6),(3,7)]
4662 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4663 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4664 cv_view_colours
+= [cc
,cc
]
4669 data
= obj
.SR_data
.ent_menuitem
[0]
4670 if data
.tipo
== '4':#{
4671 if data
.slider_minloc
and data
.slider_maxloc
:#{
4672 v0
= data
.slider_minloc
.location
4673 v1
= data
.slider_maxloc
.location
4674 cv_draw_line( v0
, v1
, cc
)
4678 colour32
= hash_djb2(obj
.name
)
4679 r
= ((colour32
) & 0xff) / 255.0
4680 g
= ((colour32
>>8 ) & 0xff) / 255.0
4681 b
= ((colour32
>>16) & 0xff) / 255.0
4683 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4688 if data
.tipo
!= '0':#{
4689 if data
.tipo
== '4':#{
4691 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4694 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4699 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4702 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4705 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4708 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4716 dij
= create_node_graph( route_curves
, route_gates
)
4718 #cv_draw_route_map( route_nodes )
4719 for route
in routes
:#{
4720 cv_draw_route( route
, dij
)
4726 def pos3d_to_2d( pos
):#{
4727 return view3d_utils
.location_3d_to_region_2d( \
4728 bpy
.context
.region
, \
4729 bpy
.context
.space_data
.region_3d
, pos
)
4732 def cv_draw_pixel():#{
4733 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4735 blf
.color(0, 1.0,1.0,1.0,0.9)
4736 blf
.enable(0,blf
.SHADOW
)
4737 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4738 for obj
in bpy
.context
.collection
.objects
:#{
4739 ent_type
= obj_ent_type( obj
)
4741 if ent_type
!= 'none':#{
4742 co
= pos3d_to_2d( obj
.location
)
4745 blf
.position(0,co
[0],co
[1],0)
4746 blf
.draw(0,ent_type
)
4751 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4752 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4753 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4755 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4756 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4757 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4758 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4759 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4760 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4761 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4762 SR_OT_COPY_ENTITY_DATA
, \
4763 SR_OBJECT_ENT_VOLUME
, \
4764 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4765 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4766 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4767 SR_OBJECT_ENT_FONT_VARIANT
,
4768 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4769 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4770 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4771 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4772 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4773 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4774 SR_OBJECT_ENT_REGION
,\
4775 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4776 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4777 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4778 SR_OBJECT_ENT_GLIDER
, SR_OBJECT_ENT_NPC
, \
4780 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4781 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4787 bpy
.utils
.register_class(c
)
4789 bpy
.types
.Scene
.SR_data
= \
4790 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4791 bpy
.types
.Collection
.SR_data
= \
4792 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4794 bpy
.types
.Object
.SR_data
= \
4795 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4796 bpy
.types
.Light
.SR_data
= \
4797 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4798 bpy
.types
.Bone
.SR_data
= \
4799 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4800 bpy
.types
.Mesh
.SR_data
= \
4801 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4802 bpy
.types
.Material
.SR_data
= \
4803 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4805 global cv_view_draw_handler
, cv_view_pixel_handler
4806 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4807 cv_draw
,(),'WINDOW','POST_VIEW')
4808 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4809 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4815 bpy
.utils
.unregister_class(c
)
4817 global cv_view_draw_handler
, cv_view_pixel_handler
4818 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4819 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')