3 import bpy
, blf
, math
, gpu
, os
, time
7 from mathutils
import *
8 from gpu_extras
.batch
import batch_for_shader
9 from bpy_extras
import mesh_utils
10 from bpy_extras
import view3d_utils
13 "name":"Skaterift .mdl exporter",
14 "author": "Harry Godden (hgn)",
21 "category":"Import/Export",
25 ('none', 'None', '', 0 ),
26 ('ent_gate', 'Gate', '', 1 ),
27 ('ent_spawn', 'Spawn Point', '', 2 ),
28 ('ent_route_node', 'Routing Path', '', 3 ),
29 ('ent_route', 'Skate Course', '', 4 ),
30 ('ent_water', 'Water Surface', '', 5 ),
31 ('ent_volume', 'Volume/Trigger', '', 6 ),
32 ('ent_audio', 'Audio', '', 7 ),
33 ('ent_marker', 'Marker', '', 8 ),
34 ('ent_font', 'Font', '', 9 ),
35 ('ent_font_variant', 'Font:Variant', '', 10 ),
36 ('ent_traffic', 'Traffic Model', '', 11 ),
37 ('ent_skateshop', 'Skate Shop', '', 12 ),
38 ('ent_camera', 'Camera', '', 13 ),
39 ('ent_swspreview', 'Workshop Preview', '', 14 ),
40 ('ent_menuitem', 'Menu Item', '', 15 ),
41 ('ent_worldinfo', 'World Info', '', 16 ),
42 ('ent_ccmd', 'CCmd', '', 17 ),
43 ('ent_objective', 'Objective', '', 18 ),
44 ('ent_challenge', 'Challenge', '', 19 ),
45 ('ent_relay', 'Relay', '', 20 ),
46 ('ent_miniworld', 'Mini World', '', 22 ),
47 ('ent_prop', 'Prop', '', 23 ),
48 ('ent_list', 'Entity List', '', 24 ),
49 ('ent_region', 'Region', '', 25 ),
50 ('ent_glider', 'Glider', '', 26 ),
51 ('ent_npc', 'npc', '', 27 )
55 SR_TRIGGERABLE
= [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \
56 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\
57 'ent_miniworld', 'ent_region', 'ent_glider', 'ent_list',\
60 def get_entity_enum_id( alias
):
62 for et
in sr_entity_list
:#{
68 if alias
== 'ent_cubemap': return 21
73 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
74 #{ # the normals and uvs to i16s. Not an
75 _pack_
= 1 # real issue, yet.
76 _fields_
= [("co",c_float
*3),
80 ("weights",c_uint16
*4),
84 class mdl_transform(Structure
):
86 _fields_
= [("co",c_float
*3),
91 class mdl_submesh(Structure
):
93 _fields_
= [("indice_start",c_uint32
),
94 ("indice_count",c_uint32
),
95 ("vertex_start",c_uint32
),
96 ("vertex_count",c_uint32
),
97 ("bbx",(c_float
*3)*2),
98 ("material_id",c_uint16
), # index into the material array
103 # =================================================
105 class mdl_file(Structure
):
107 _fields_
= [("path",c_uint32
),
108 ("pack_offset",c_uint32
),
109 ("pack_size",c_uint32
)]
112 class mdl_material_kvs(Structure
):
114 _fields_
= [("offset",c_uint32
),
118 class mdl_material_properties_union(Union
):
120 _fields_
= [("kvs",mdl_material_kvs
),
121 ("compiled",c_void_p
)]
124 class mdl_material(Structure
):
126 _fields_
= [("pstr_name",c_uint32
),
129 ("surface_prop",c_uint32
),
130 ("props",mdl_material_properties_union
)]
132 # ("colour",c_float*4), (old) v105
133 # ("colour1",c_float*4),
134 # ("tex_diffuse",c_uint32),
135 # ("tex_none0",c_uint32),
136 # ("tex_none1",c_uint32)]
139 class mdl_bone(Structure
):
141 _fields_
= [("co",c_float
*3),("end",c_float
*3),
143 ("collider",c_uint32
),
144 ("ik_target",c_uint32
),
145 ("ik_pole",c_uint32
),
147 ("pstr_name",c_uint32
),
148 ("hitbox",(c_float
*3)*2),
149 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
153 class mdl_armature(Structure
):
155 _fields_
= [("transform",mdl_transform
),
156 ("bone_start",c_uint32
),
157 ("bone_count",c_uint32
),
158 ("anim_start",c_uint32
),
159 ("anim_count",c_uint32
)]
162 class mdl_animation(Structure
):
164 _fields_
= [("pstr_name",c_uint32
),
167 ("keyframe_start",c_uint32
)]
170 class mdl_mesh(Structure
):
172 _fields_
= [("transform",mdl_transform
),
173 ("submesh_start",c_uint32
),
174 ("submesh_count",c_uint32
),
175 ("pstr_name",c_uint32
),
176 ("entity_id",c_uint32
),
177 ("armature_id",c_uint32
)]
180 class mdl_texture(Structure
):
182 _fields_
= [("file",mdl_file
),
186 class mdl_array(Structure
):
188 _fields_
= [("file_offset",c_uint32
),
189 ("item_count",c_uint32
),
190 ("item_size",c_uint32
),
194 class mdl_header(Structure
):
196 _fields_
= [("version",c_uint32
),
197 ("arrays",mdl_array
)]
200 class ent_spawn(Structure
):
202 _fields_
= [("transform",mdl_transform
),
203 ("pstr_name",c_uint32
)]
206 class ent_light(Structure
):
208 _fields_
= [("transform",mdl_transform
),
209 ("daytime",c_uint32
),
211 ("colour",c_float
*4),
214 ("inverse_world",(c_float
*3)*4), # Runtime
215 ("angle_sin_cos",(c_float
*2))] # Runtime
218 class version_refcount_union(Union
):
220 _fields_
= [("timing_version",c_uint32
),
221 ("ref_count",c_uint8
)]
224 class ent_gate(Structure
):
226 _fields_
= [("flags",c_uint32
),
227 ("target", c_uint32
),
229 ("dimensions", c_float
*3),
230 ("co", (c_float
*3)*2),
231 ("q", (c_float
*4)*2),
232 ("to_world",(c_float
*3)*4),
233 ("transport",(c_float
*3)*4),
234 ("_anonymous_union",version_refcount_union
),
235 ("timing_time",c_double
),
236 ("routes",c_uint16
*4),
237 ("route_count",c_uint8
),
238 ("submesh_start",c_uint32
), # v102+
239 ("submesh_count",c_uint32
), # v102+ (can be 0)
241 sr_functions
= { 0: 'unlock' }
244 class ent_route_node(Structure
):
246 _fields_
= [("co",c_float
*3),
247 ("ref_count",c_uint8
),
248 ("ref_total",c_uint8
)]
251 class ent_path_index(Structure
):
253 _fields_
= [("index",c_uint16
)]
256 class vg_audio_clip(Structure
):
258 _fields_
= [("path",c_uint64
),
264 class union_file_audio_clip(Union
):
266 _fields_
= [("file",mdl_file
),
267 ("reserved",vg_audio_clip
)]
270 # NOTE: not really an entity. no reason for ent_ -- makes more sense as file_,
271 # but then again, too late to change because compat.
272 class ent_audio_clip(Structure
):
274 _fields_
= [("_anon",union_file_audio_clip
),
275 ("probability",c_float
)]
278 class ent_list(Structure
):
280 _fields_
= [("entity_ref_start",c_uint32
),
281 ("entity_ref_count",c_uint32
)]
285 class file_entity_ref(Structure
):
287 _fields_
= [("index",c_uint32
)]
290 class ent_checkpoint(Structure
):
292 _fields_
= [("gate_index",c_uint16
),
293 ("path_start",c_uint16
),
294 ("path_count",c_uint16
)]
297 class ent_route(Structure
):
299 _fields_
= [("transform",mdl_transform
),
300 ("pstr_name",c_uint32
),
301 ("checkpoints_start",c_uint16
),
302 ("checkpoints_count",c_uint16
),
303 ("colour",c_float
*4),
304 ("active",c_uint32
), #runtime
306 ("board_transform",(c_float
*3)*4),
308 ("latest_pass",c_double
),
309 ("id_camera",c_uint32
), # v103+
312 sr_functions
= { 0: 'view' }
315 class ent_list(Structure
):#{
316 _fields_
= [("start",c_uint16
),("count",c_uint16
)]
319 class ent_glider(Structure
):#{
320 _fields_
= [("transform",mdl_transform
),
322 ("cooldown",c_float
)]
323 sr_functions
= { 0: 'unlock',
327 class ent_npc(Structure
):#{
328 _fields_
= [("transform",mdl_transform
),
330 ("context",c_uint32
),
332 sr_functions
= { 0: 'proximity', -1: 'leave' }
335 class ent_water(Structure
):
337 _fields_
= [("transform",mdl_transform
),
338 ("max_dist",c_float
),
339 ("reserved0",c_uint32
),
340 ("reserved1",c_uint32
)]
343 class volume_trigger(Structure
):
345 _fields_
= [("event",c_uint32
),
346 ("event_leave",c_int32
)]
349 class volume_particles(Structure
):
351 _fields_
= [("blank",c_uint32
),
355 class volume_union(Union
):
357 _fields_
= [("trigger",volume_trigger
),
358 ("particles",volume_particles
)]
361 class ent_volume(Structure
):
363 _fields_
= [("transform",mdl_transform
),
364 ("to_world",(c_float
*3)*4),
365 ("to_local",(c_float
*3)*4),
368 ("_anon",volume_union
)]
371 class ent_audio(Structure
):
373 _fields_
= [("transform",mdl_transform
),
375 ("clip_start",c_uint32
),
376 ("clip_count",c_uint32
),
378 ("crossfade",c_float
),
379 ("channel_behaviour",c_uint32
),
381 ("probability_curve",c_uint32
),
382 ("max_channels",c_uint32
)]
385 class ent_marker(Structure
):
387 _fields_
= [("transform",mdl_transform
),
391 class ent_glyph(Structure
):
393 _fields_
= [("size",c_float
*2),
394 ("indice_start",c_uint32
),
395 ("indice_count",c_uint32
)]
398 class ent_font_variant(Structure
):
400 _fields_
= [("name",c_uint32
),
401 ("material_id",c_uint32
)]
404 class ent_font(Structure
):
406 _fields_
= [("alias",c_uint32
),
407 ("variant_start",c_uint32
),
408 ("variant_count",c_uint32
),
409 ("glyph_start",c_uint32
),
410 ("glyph_count",c_uint32
),
411 ("glyph_utf32_base",c_uint32
)]
414 class ent_traffic(Structure
):
416 _fields_
= [("transform",mdl_transform
),
417 ("submesh_start",c_uint32
),
418 ("submesh_count",c_uint32
),
419 ("start_node",c_uint32
),
420 ("node_count",c_uint32
),
427 # ---------------------------------------------------------------
428 class ent_skateshop_characters(Structure
):
430 _fields_
= [("id_display",c_uint32
),
431 ("id_info",c_uint32
)]
433 class ent_skateshop_boards(Structure
):
435 _fields_
= [("id_display",c_uint32
),
436 ("id_info",c_uint32
),
437 ("id_rack",c_uint32
)]
439 class ent_skateshop_worlds(Structure
):
441 _fields_
= [("id_display",c_uint32
),
442 ("id_info",c_uint32
)]
444 class ent_skateshop_server(Structure
):
446 _fields_
= [("id_lever",c_uint32
)]
448 class ent_skateshop_anon_union(Union
):
450 _fields_
= [("boards",ent_skateshop_boards
),
451 ("character",ent_skateshop_characters
),
452 ("worlds",ent_skateshop_worlds
),
453 ("server",ent_skateshop_server
)]
455 class ent_skateshop(Structure
):
457 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
458 ("id_camera",c_uint32
),
459 ("_anonymous_union",ent_skateshop_anon_union
)]
461 sr_functions
= { 0: 'trigger' }
464 class ent_swspreview(Structure
):
466 _fields_
= [("id_camera",c_uint32
),
467 ("id_display",c_uint32
),
468 ("id_display1",c_uint32
)]
472 # -----------------------------------------------------------------
473 class ent_menuitem_visual(Structure
):
475 _fields_
= [("pstr_name",c_uint32
)]
477 class ent_menuitem_slider(Structure
):
479 _fields_
= [("id_min",c_uint32
),
481 ("id_handle",c_uint32
),
482 ("pstr_data",c_uint32
)]
484 class ent_menuitem_button(Structure
):
486 _fields_
= [("pstr",c_uint32
),
487 ("stack_behaviour",c_uint32
)]
489 class ent_menuitem_checkmark(Structure
):
491 _fields_
= [("id_check",c_uint32
),
492 ("pstr_data",c_uint32
),
493 ("offset",c_float
*3)]
495 class ent_menuitem_page(Structure
):
497 _fields_
= [("pstr_name",c_uint32
),
498 ("id_entrypoint",c_uint32
),
499 ("id_viewpoint",c_uint32
)]
501 class ent_menuitem_binding(Structure
):
503 _fields_
= [("pstr_bind",c_uint32
),
504 ("font_variant",c_uint32
)]
506 class ent_menuitem_anon_union(Union
):
508 _fields_
= [("slider",ent_menuitem_slider
),
509 ("button",ent_menuitem_button
),
510 ("checkmark",ent_menuitem_checkmark
),
511 ("page",ent_menuitem_page
),
512 ("visual",ent_menuitem_visual
),
513 ("binding",ent_menuitem_binding
)]
515 class ent_menuitem(Structure
):
517 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
518 ("id_links",c_uint32
*4),
519 ("factive",c_float
), ("fvisible",c_float
),
520 #-- TODO: Refactor this into a simple mesh structure
521 ("transform",mdl_transform
),
522 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
525 ("_anonymous_union", ent_menuitem_anon_union
)]
528 class ent_camera(Structure
):
530 _fields_
= [("transform",mdl_transform
),
534 class ent_worldinfo(Structure
):
536 _fields_
= [("pstr_name",c_uint32
),
537 ("pstr_author",c_uint32
), # unused
538 ("pstr_desc",c_uint32
), # unused
539 ("timezone",c_float
),
540 ("pstr_skybox",c_uint32
),
544 class ent_ccmd(Structure
):
546 _fields_
= [("pstr_command",c_uint32
)]
549 class ent_objective(Structure
):#{
550 _fields_
= [("transform",mdl_transform
),
551 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
553 ("id_next",c_uint32
),
554 ("filter",c_uint32
),("filter2",c_uint32
),
556 ("win_event",c_int32
),
557 ("time_limit",c_float
)]
559 sr_functions
= { 0: 'trigger',
564 class ent_challenge(Structure
):#{
565 _fields_
= [("transform",mdl_transform
),
566 ("pstr_alias",c_uint32
),
569 ("target_event",c_int32
),
571 ("reset_event",c_int32
),
574 ("status",c_uint32
)] #runtime
575 sr_functions
= { 0: 'unlock',
579 class ent_region(Structure
):#{
580 _fields_
= [("transform",mdl_transform
),
581 ("submesh_start",c_uint32
), ("submesh_count",c_uint32
),
582 ("pstr_title",c_uint32
),
584 ("zone_volume",c_uint32
),
586 ("target0",c_uint32
*2)]
587 sr_functions
= { 0: 'enter', 1: 'leave' }
590 class ent_relay(Structure
):#{
591 _fields_
= [("targets",(c_uint32
*2)*4),
592 ("targets_events",c_int32
*4)]
593 sr_functions
= { 0: 'trigger' }
596 class ent_cubemap(Structure
):#{
597 _fields_
= [("co",c_float
*3),
598 ("resolution",c_uint32
), #placeholder
599 ("live",c_uint32
), #placeholder
600 ("texture_id",c_uint32
), #engine
601 ("framebuffer_id",c_uint32
),#engine
602 ("renderbuffer_id",c_uint32
),#engine
603 ("placeholder",c_uint32
*2)]
606 class ent_miniworld(Structure
):#{
607 _fields_
= [("transform",mdl_transform
),
608 ("pstr_world",c_uint32
),
612 sr_functions
= { 0: 'zone', 1: 'leave' }
615 class ent_prop(Structure
):#{
616 _fields_
= [("transform",mdl_transform
),
617 ("submesh_start",c_uint32
),
618 ("submesh_count",c_uint32
),
620 ("pstr_alias",c_uint32
)]
623 def obj_ent_type( obj
):
625 if obj
.type == 'ARMATURE': return 'mdl_armature'
626 elif obj
.type == 'LIGHT': return 'ent_light'
627 elif obj
.type == 'CAMERA': return 'ent_camera'
628 elif obj
.type == 'LIGHT_PROBE' and obj
.data
.type == 'CUBEMAP':
630 else: return obj
.SR_data
.ent_type
633 def sr_filter_ent_type( obj
, ent_types
):
635 if obj
== bpy
.context
.active_object
: return False
637 for c0
in obj
.users_collection
:#{
638 for c1
in bpy
.context
.active_object
.users_collection
:#{
640 return obj_ent_type( obj
) in ent_types
648 def v4_dot( a
, b
):#{
649 return a
[0]*b
[0] + a
[1]*b
[1] + a
[2]*b
[2] + a
[3]*b
[3]
652 def q_identity( q
):#{
659 def q_normalize( q
):#{
661 if( l2
< 0.00001 ):#{
665 s
= 1.0/math
.sqrt(l2
)
673 def compile_obj_transform( obj
, transform
):
675 co
= obj
.matrix_world
@ Vector((0,0,0))
677 # This was changed from matrix_local on 09.05.23
678 q
= obj
.matrix_world
.to_quaternion()
684 transform
.co
[0] = co
[0]
685 transform
.co
[1] = co
[2]
686 transform
.co
[2] = -co
[1]
687 transform
.q
[0] = q
[1]
688 transform
.q
[1] = q
[3]
689 transform
.q
[2] = -q
[2]
690 transform
.q
[3] = q
[0]
691 transform
.s
[0] = s
[0]
692 transform
.s
[1] = s
[2]
693 transform
.s
[2] = s
[1]
696 def int_align_to( v
, align
):
698 while(v
%align
)!=0: v
+= 1
702 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
704 while (len(buffer) % align
) != 0: buffer.extend(w
)
708 def bytearray_print_hex( s
, w
=16 ):
710 for r
in range((len(s
)+(w
-1))//w
):#{
712 i1
=min((r
+1)*w
,len(s
))
713 print( F
'{r*w:06x}| \x1B[31m', end
='')
714 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
715 print( "\x1B[0m", end
='')
716 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
720 def sr_compile_string( s
):
722 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
724 index
= len( sr_compile
.string_data
)
725 sr_compile
.string_cache
[s
] = index
726 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
727 sr_compile
.string_data
.extend( s
.encode('utf-8') )
728 sr_compile
.string_data
.extend( b
'\0' )
730 bytearray_align_to( sr_compile
.string_data
, 4 )
736 decoded
= bytearray()
737 for i
in range(len(s
)//2):#{
738 c
= (ord(s
[i
*2+0])-0x41)
739 c |
= (ord(s
[i
*2+1])-0x41)<<4
740 decoded
.extend(bytearray(c_uint8(c
))) #??
745 def sr_pack_file( file, path
, data
):
747 file.path
= sr_compile_string( path
)
748 file.pack_offset
= len( sr_compile
.pack_data
)
749 file.pack_size
= len( data
)
751 sr_compile
.pack_data
.extend( data
)
752 bytearray_align_to( sr_compile
.pack_data
, 16 )
755 def sr_compile_texture( img
):
760 name
= os
.path
.splitext( img
.name
)[0]
762 if name
in sr_compile
.texture_cache
:
763 return sr_compile
.texture_cache
[name
]
765 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
770 if sr_compile
.pack_textures
:#{
771 filedata
= qoi_encode( img
)
772 sr_pack_file( tex
.file, name
, filedata
)
775 sr_compile
.texture_cache
[name
] = texture_index
776 sr_compile
.texture_data
.extend( bytearray(tex
) )
780 def sr_armature_bones( armature
):
782 def _recurse_bone( b
):
785 for c
in b
.children
: yield from _recurse_bone( c
)
788 for b
in armature
.data
.bones
:
790 yield from _recurse_bone( b
)
793 def sr_entity_id( obj
):#{
796 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
797 index
= sr_compile
.entity_ids
[ obj
.name
]
799 return (tipo
&0xffff)<<16 |
(index
&0xffff)
802 # Returns submesh_start,count and armature_id
803 def sr_compile_mesh_internal( obj
):
812 for mod
in obj
.modifiers
:#{
813 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
814 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
817 can_use_cache
= False
820 if mod
.type == 'ARMATURE': #{
821 armature
= mod
.object
822 rig_weight_groups
= \
823 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
824 armature_id
= sr_compile
.entity_ids
[armature
.name
]
826 POSE_OR_REST_CACHE
= armature
.data
.pose_position
827 armature
.data
.pose_position
= 'REST'
831 # Check the cache first
833 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
834 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
835 submesh_start
= ref
[0]
836 submesh_count
= ref
[1]
837 return (submesh_start
,submesh_count
,armature_id
)
840 # Compile a whole new mesh
842 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
845 dgraph
= bpy
.context
.evaluated_depsgraph_get()
846 data
= obj
.evaluated_get(dgraph
).data
847 data
.calc_loop_triangles()
848 data
.calc_normals_split()
850 # Mesh is split into submeshes based on their material
852 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
853 for material_id
, mat
in enumerate(mat_list
): #{
857 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
858 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
861 sm
.material_id
= sr_compile_material( mat
)
863 INF
=99999999.99999999
869 # Keep a reference to very very very similar vertices
870 # i have no idea how to speed it up.
872 vertex_reference
= {}
874 # Write the vertex / indice data
876 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
877 if tri
.material_index
!= material_id
: continue
880 vert
= data
.vertices
[tri
.vertices
[j
]]
882 vi
= data
.loops
[li
].vertex_index
884 # Gather vertex information
887 norm
= data
.loops
[li
].normal
889 colour
= (255,255,255,255)
896 uv
= data
.uv_layers
.active
.data
[li
].uv
900 if data
.vertex_colors
:#{
901 colour
= data
.vertex_colors
.active
.data
[li
].color
902 colour
= (int(colour
[0]*255.0),\
903 int(colour
[1]*255.0),\
904 int(colour
[2]*255.0),\
905 int(colour
[3]*255.0))
908 # Weight groups: truncates to the 3 with the most influence. The
909 # fourth bone ID is never used by the shader so it
913 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
914 if obj
.vertex_groups
[_
.group
].name
in \
917 weight_groups
= sorted( src_groups
, key
= \
918 lambda a
: a
.weight
, reverse
=True )
920 for ml
in range(3):#{
921 if len(weight_groups
) > ml
:#{
922 g
= weight_groups
[ml
]
923 name
= obj
.vertex_groups
[g
.group
].name
926 groups
[ml
] = rig_weight_groups
.index(name
)
931 if len(weight_groups
) > 0:#{
932 inv_norm
= (1.0/tot
) * 65535.0
933 for ml
in range(3):#{
934 weights
[ml
] = int( weights
[ml
] * inv_norm
)
935 weights
[ml
] = min( weights
[ml
], 65535 )
936 weights
[ml
] = max( weights
[ml
], 0 )
941 li1
= tri
.loops
[(j
+1)%3]
942 vi1
= data
.loops
[li1
].vertex_index
943 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
945 if e0
.use_freestyle_mark
and \
946 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
947 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
953 TOLERENCE
= float(10**4)
954 key
= (int(co
[0]*TOLERENCE
+0.5),
955 int(co
[1]*TOLERENCE
+0.5),
956 int(co
[2]*TOLERENCE
+0.5),
957 int(norm
[0]*TOLERENCE
+0.5),
958 int(norm
[1]*TOLERENCE
+0.5),
959 int(norm
[2]*TOLERENCE
+0.5),
960 int(uv
[0]*TOLERENCE
+0.5),
961 int(uv
[1]*TOLERENCE
+0.5),
962 colour
[0], # these guys are already quantized
975 if key
in vertex_reference
:
976 index
= vertex_reference
[key
]
978 index
= bytearray(c_uint32(sm
.vertex_count
))
981 vertex_reference
[key
] = index
991 v
.colour
[0] = colour
[0]
992 v
.colour
[1] = colour
[1]
993 v
.colour
[2] = colour
[2]
994 v
.colour
[3] = colour
[3]
995 v
.weights
[0] = weights
[0]
996 v
.weights
[1] = weights
[1]
997 v
.weights
[2] = weights
[2]
998 v
.weights
[3] = weights
[3]
999 v
.groups
[0] = groups
[0]
1000 v
.groups
[1] = groups
[1]
1001 v
.groups
[2] = groups
[2]
1002 v
.groups
[3] = groups
[3]
1004 for i
in range(3):#{
1005 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1006 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1009 sr_compile
.vertex_data
.extend(bytearray(v
))
1012 sm
.indice_count
+= 1
1013 sr_compile
.indice_data
.extend( index
)
1017 # Make sure bounding box isn't -inf -> inf if no vertices
1019 if sm
.vertex_count
== 0:
1024 # Add submesh to encoder
1026 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1031 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1034 # Save a reference to this mesh since we want to reuse the submesh indices
1036 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1037 return (submesh_start
,submesh_count
,armature_id
)
1040 def sr_compile_mesh( obj
):
1043 compile_obj_transform(obj
, node
.transform
)
1044 node
.pstr_name
= sr_compile_string(obj
.name
)
1045 ent_type
= obj_ent_type( obj
)
1049 if ent_type
!= 'none':#{
1050 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1051 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1052 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1055 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1056 sr_compile_mesh_internal( obj
)
1058 sr_compile
.mesh_data
.extend(bytearray(node
))
1061 def sr_compile_fonts( collection
):
1063 print( F
"[SR] Compiling fonts" )
1068 for obj
in collection
.all_objects
:#{
1069 if obj_ent_type(obj
) != 'ent_font': continue
1071 data
= obj
.SR_data
.ent_font
[0]
1074 font
.alias
= sr_compile_string( data
.alias
)
1075 font
.variant_start
= variant_count
1076 font
.variant_count
= 0
1077 font
.glyph_start
= glyph_count
1079 glyph_base
= data
.glyphs
[0].utf32
1080 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1082 font
.glyph_utf32_base
= glyph_base
1083 font
.glyph_count
= glyph_range
1085 for i
in range(len(data
.variants
)):#{
1086 data_var
= data
.variants
[i
]
1087 if not data_var
.mesh
: continue
1089 mesh
= data_var
.mesh
.data
1091 variant
= ent_font_variant()
1092 variant
.name
= sr_compile_string( data_var
.tipo
)
1094 # fonts (variants) only support one material each
1096 if len(mesh
.materials
) != 0:
1097 mat
= mesh
.materials
[0]
1098 variant
.material_id
= sr_compile_material( mat
)
1100 font
.variant_count
+= 1
1102 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1103 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1105 for j
in range(len(islands
)):#{
1106 for tri
in islands
[j
]:#{
1107 centroids
[j
].x
+= tri
.center
[0]
1108 centroids
[j
].y
+= tri
.center
[2]
1111 centroids
[j
] /= len(islands
[j
])
1114 for j
in range(glyph_range
):#{
1115 data_glyph
= data
.glyphs
[j
]
1117 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1118 glyph
.indice_count
= 0
1119 glyph
.size
[0] = data_glyph
.bounds
[2]
1120 glyph
.size
[1] = data_glyph
.bounds
[3]
1122 vertex_reference
= {}
1124 for k
in range(len(islands
)):#{
1125 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1126 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1127 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1128 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1133 for l
in range(len(islands
[k
])):#{
1135 for m
in range(3):#{
1136 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1138 vi
= mesh
.loops
[li
].vertex_index
1140 # Gather vertex information
1142 co
= [vert
.co
[_
] for _
in range(3)]
1143 co
[0] -= data_glyph
.bounds
[0]
1144 co
[2] -= data_glyph
.bounds
[1]
1145 norm
= mesh
.loops
[li
].normal
1147 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1149 TOLERENCE
= float(10**4)
1150 key
= (int(co
[0]*TOLERENCE
+0.5),
1151 int(co
[1]*TOLERENCE
+0.5),
1152 int(co
[2]*TOLERENCE
+0.5),
1153 int(norm
[0]*TOLERENCE
+0.5),
1154 int(norm
[1]*TOLERENCE
+0.5),
1155 int(norm
[2]*TOLERENCE
+0.5),
1156 int(uv
[0]*TOLERENCE
+0.5),
1157 int(uv
[1]*TOLERENCE
+0.5))
1159 if key
in vertex_reference
:
1160 index
= vertex_reference
[key
]
1162 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1163 index
= bytearray(c_uint32(vindex
))
1164 vertex_reference
[key
] = index
1171 v
.norm
[2] = -norm
[1]
1175 sr_compile
.vertex_data
.extend(bytearray(v
))
1178 glyph
.indice_count
+= 1
1179 sr_compile
.indice_data
.extend( index
)
1183 sr_ent_push( glyph
)
1185 sr_ent_push( variant
)
1191 def sr_compile_menus( collection
):
1193 print( "[SR1] Compiling menus" )
1196 for obj
in collection
.all_objects
:#{
1197 if obj_ent_type(obj
) != 'ent_menuitem': continue
1198 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1200 bitmask
= 0x00000000
1202 for col
in obj
.users_collection
:#{
1204 if name
not in groups
: groups
.append( name
)
1205 bitmask |
= (0x1 << groups
.index(name
))
1208 item
= ent_menuitem()
1209 item
.type = int( obj_data
.tipo
)
1210 item
.groups
= bitmask
1212 compile_obj_transform( obj
, item
.transform
)
1213 if obj
.type == 'MESH':#{
1214 item
.submesh_start
, item
.submesh_count
, _
= \
1215 sr_compile_mesh_internal( obj
)
1218 if item
.type == 1 or item
.type == 2 or item
.type == 7:#{
1219 item_button
= item
._anonymous
_union
.button
1220 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1221 item_button
.stack_behaviour
= int( obj_data
.stack_behaviour
)
1223 elif item
.type == 0:#{
1224 item_visual
= item
._anonymous
_union
.visual
1225 item_visual
.pstr_name
= sr_compile_string( obj_data
.string
)
1227 elif item
.type == 3:#{
1228 item_checkmark
= item
._anonymous
_union
.checkmark
1229 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1230 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1231 delta
= obj_data
.checkmark
.location
- obj
.location
1232 item_checkmark
.offset
[0] = delta
[0]
1233 item_checkmark
.offset
[1] = delta
[2]
1234 item_checkmark
.offset
[2] = -delta
[1]
1236 elif item
.type == 4:#{
1237 item_slider
= item
._anonymous
_union
.slider
1238 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1239 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1240 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1241 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1243 elif item
.type == 5:#{
1244 item_page
= item
._anonymous
_union
.page
1245 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1246 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1247 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1249 elif item
.type == 6:#{
1250 item_binding
= item
._anonymous
_union
.binding
1251 item_binding
.pstr_bind
= sr_compile_string( obj_data
.string
)
1252 item_binding
.font_variant
= obj_data
.font_variant
1256 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1258 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1259 if item
.type != 4:#{
1261 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1263 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1270 def sr_compile_armature( obj
):
1272 node
= mdl_armature()
1273 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1275 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1278 bones
= [_
for _
in sr_armature_bones(obj
)]
1279 bones_names
= [None]+[_
.name
for _
in bones
]
1283 if b
.use_deform
: bone
.flags
= 0x1
1284 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1286 bone
.collider
= int(b
.SR_data
.collider
)
1288 if bone
.collider
>0:#{
1289 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1290 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1291 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1292 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1293 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1294 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1297 if b
.SR_data
.cone_constraint
:#{
1299 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1300 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1301 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1302 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1303 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1304 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1305 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1306 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1307 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1308 bone
.conet
= b
.SR_data
.conet
1311 bone
.co
[0] = b
.head_local
[0]
1312 bone
.co
[1] = b
.head_local
[2]
1313 bone
.co
[2] = -b
.head_local
[1]
1314 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1315 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1316 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1317 bone
.pstr_name
= sr_compile_string( b
.name
)
1319 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1320 if c
.type == 'IK':#{
1322 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1323 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1327 node
.bone_count
+= 1
1328 sr_compile
.bone_data
.extend(bytearray(bone
))
1333 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1334 # So we can restore later
1336 previous_frame
= bpy
.context
.scene
.frame_current
1337 previous_action
= obj
.animation_data
.action
1338 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1339 obj
.data
.pose_position
= 'POSE'
1341 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1342 for NLAStrip
in NLALayer
.strips
:#{
1345 for a
in bpy
.data
.actions
:#{
1346 if a
.name
== NLAStrip
.name
:#{
1347 obj
.animation_data
.action
= a
1352 # Clip to NLA settings
1354 anim_start
= int(NLAStrip
.action_frame_start
)
1355 anim_end
= int(NLAStrip
.action_frame_end
)
1359 anim
= mdl_animation()
1360 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1362 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1363 sizeof(mdl_transform
)
1364 anim
.length
= anim_end
-anim_start
1367 # Export the keyframes
1368 for frame
in range(anim_start
,anim_end
):#{
1369 bpy
.context
.scene
.frame_set(frame
)
1372 pb
= obj
.pose
.bones
[rb
.name
]
1374 # relative bone matrix
1375 if rb
.parent
is not None:#{
1376 offset_mtx
= rb
.parent
.matrix_local
1377 offset_mtx
= offset_mtx
.inverted_safe() @ \
1380 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1381 inv_parent
.invert_safe()
1382 fpm
= inv_parent
@ pb
.matrix
1385 bone_mtx
= rb
.matrix
.to_4x4()
1386 local_inv
= rb
.matrix_local
.inverted_safe()
1387 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1390 loc
, rot
, sca
= fpm
.decompose()
1393 lc_m
= pb
.matrix_channel
.to_3x3()
1394 if pb
.parent
is not None:#{
1395 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1396 lc_m
= smtx
.inverted() @ lc_m
1398 rq
= lc_m
.to_quaternion()
1401 kf
= mdl_transform()
1412 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1418 # Add to animation buffer
1420 sr_compile
.anim_data
.extend(bytearray(anim
))
1421 node
.anim_count
+= 1
1425 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1429 # Restore context to how it was before
1431 bpy
.context
.scene
.frame_set( previous_frame
)
1432 obj
.animation_data
.action
= previous_action
1433 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1436 sr_compile
.armature_data
.extend(bytearray(node
))
1439 def sr_ent_push( struct
):
1441 clase
= type(struct
).__name
__
1443 if clase
not in sr_compile
.entity_data
:#{
1444 sr_compile
.entity_data
[ clase
] = bytearray()
1445 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1448 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1449 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1453 def sr_array_title( arr
, name
, count
, size
, offset
):
1455 for i
in range(len(name
)):#{
1456 arr
.name
[i
] = ord(name
[i
])
1458 arr
.file_offset
= offset
1459 arr
.item_count
= count
1460 arr
.item_size
= size
1467 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1472 def sr_compile( collection
):
1474 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1478 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1479 sr_compile
.pack_animations
= collection
.SR_data
.animations
1482 sr_compile
.string_cache
= {}
1483 sr_compile
.mesh_cache
= {}
1484 sr_compile
.material_cache
= {}
1485 sr_compile
.texture_cache
= {}
1488 sr_compile
.mesh_data
= bytearray()
1489 sr_compile
.submesh_data
= bytearray()
1490 sr_compile
.vertex_data
= bytearray()
1491 sr_compile
.indice_data
= bytearray()
1492 sr_compile
.bone_data
= bytearray()
1493 sr_compile
.material_data
= bytearray()
1494 sr_compile
.shader_data
= bytearray()
1495 sr_compile
.armature_data
= bytearray()
1496 sr_compile
.anim_data
= bytearray()
1497 sr_compile
.keyframe_data
= bytearray()
1498 sr_compile
.texture_data
= bytearray()
1500 # just bytes not structures
1501 sr_compile
.string_data
= bytearray()
1502 sr_compile
.pack_data
= bytearray()
1505 sr_compile
.entity_data
= {}
1506 sr_compile
.entity_info
= {}
1508 print( F
"[SR] assign entity ID's" )
1509 sr_compile
.entities
= {}
1510 sr_compile
.entity_ids
= {}
1513 # -------------------------------------------------------
1515 sr_compile_string( "null" )
1518 for obj
in collection
.all_objects
: #{
1519 if obj
.type == 'MESH':#{
1523 ent_type
= obj_ent_type( obj
)
1524 if ent_type
== 'none': continue
1526 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1527 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1528 sr_compile
.entities
[ent_type
] += [obj
]
1531 print( F
"[SR] Compiling geometry" )
1533 for obj
in collection
.all_objects
:#{
1534 if obj
.type == 'MESH':#{
1537 ent_type
= obj_ent_type( obj
)
1539 # entity ignore mesh list
1541 if ent_type
== 'ent_traffic': continue
1542 if ent_type
== 'ent_prop': continue
1543 if ent_type
== 'ent_font': continue
1544 if ent_type
== 'ent_font_variant': continue
1545 if ent_type
== 'ent_menuitem': continue
1546 if ent_type
== 'ent_objective': continue
1547 if ent_type
== 'ent_region': continue
1549 #TODO: This is messy.
1550 if ent_type
== 'ent_gate':#{
1551 obj_data
= obj
.SR_data
.ent_gate
[0]
1552 if obj_data
.custom
: continue
1554 #--------------------------
1556 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}' )
1557 sr_compile_mesh( obj
)
1561 audio_clip_count
= 0
1562 entity_file_ref_count
= 0
1564 for ent_type
, arr
in sr_compile
.entities
.items():#{
1565 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1567 for i
in range(len(arr
)):#{
1570 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1572 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1573 elif ent_type
== 'ent_light': #{
1575 compile_obj_transform( obj
, light
.transform
)
1576 light
.daytime
= obj
.data
.SR_data
.daytime
1577 if obj
.data
.type == 'POINT':#{
1580 elif obj
.data
.type == 'SPOT':#{
1582 light
.angle
= obj
.data
.spot_size
*0.5
1584 light
.range = obj
.data
.cutoff_distance
1585 light
.colour
[0] = obj
.data
.color
[0]
1586 light
.colour
[1] = obj
.data
.color
[1]
1587 light
.colour
[2] = obj
.data
.color
[2]
1588 light
.colour
[3] = obj
.data
.energy
1589 sr_ent_push( light
)
1591 elif ent_type
== 'ent_camera': #{
1593 compile_obj_transform( obj
, cam
.transform
)
1594 cam
.fov
= obj
.data
.angle
* 45.0
1597 elif ent_type
== 'ent_gate': #{
1599 obj_data
= obj
.SR_data
.ent_gate
[0]
1600 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1604 if obj_data
.tipo
== 'default':#{
1605 if obj_data
.target
:#{
1606 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1610 elif obj_data
.tipo
== 'nonlocal':#{
1612 gate
.key
= sr_compile_string(obj_data
.key
)
1616 if obj_data
.flip
: flags |
= 0x0004
1617 if obj_data
.custom
:#{
1619 gate
.submesh_start
, gate
.submesh_count
, _
= \
1620 sr_compile_mesh_internal( obj
)
1622 if obj_data
.locked
: flags |
= 0x0010
1625 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1626 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1627 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1629 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1630 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1632 if obj_data
.target
:#{
1633 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1634 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1639 for x
in range(2):#{
1640 gate
.co
[x
][0] = co
[x
][0]
1641 gate
.co
[x
][1] = co
[x
][2]
1642 gate
.co
[x
][2] = -co
[x
][1]
1643 gate
.q
[x
][0] = q
[x
][1]
1644 gate
.q
[x
][1] = q
[x
][3]
1645 gate
.q
[x
][2] = -q
[x
][2]
1646 gate
.q
[x
][3] = q
[x
][0]
1651 elif ent_type
== 'ent_spawn': #{
1653 compile_obj_transform( obj
, spawn
.transform
)
1654 obj_data
= obj
.SR_data
.ent_spawn
[0]
1655 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1656 sr_ent_push( spawn
)
1658 elif ent_type
== 'ent_water':#{
1660 compile_obj_transform( obj
, water
.transform
)
1661 water
.max_dist
= 0.0
1662 sr_ent_push( water
)
1664 elif ent_type
== 'ent_audio':#{
1665 obj_data
= obj
.SR_data
.ent_audio
[0]
1667 compile_obj_transform( obj
, audio
.transform
)
1668 audio
.clip_start
= audio_clip_count
1669 audio
.clip_count
= len(obj_data
.files
)
1670 audio_clip_count
+= audio
.clip_count
1671 audio
.max_channels
= obj_data
.max_channels
1672 audio
.volume
= obj_data
.volume
1675 # - allow/disable doppler
1676 # - channel group tags with random colours
1677 # - transition properties
1679 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1680 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1681 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1682 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1683 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1684 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1685 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1687 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1688 if audio
.channel_behaviour
>= 1:#{
1689 audio
.group
= obj_data
.group
1691 if audio
.channel_behaviour
== 2:#{
1692 audio
.crossfade
= obj_data
.transition_duration
1694 audio
.probability_curve
= int(obj_data
.probability_curve
)
1696 for ci
in range(audio
.clip_count
):#{
1697 entry
= obj_data
.files
[ci
]
1698 clip
= ent_audio_clip()
1699 clip
.probability
= entry
.probability
1700 if obj_data
.formato
== '2':#{
1701 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1704 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1705 clip
._anon
.file.pack_offset
= 0
1706 clip
._anon
.file.pack_size
= 0
1710 sr_ent_push( audio
)
1712 elif ent_type
== 'ent_volume':#{
1713 obj_data
= obj
.SR_data
.ent_volume
[0]
1714 volume
= ent_volume()
1715 volume
.type = int(obj_data
.subtype
)
1716 compile_obj_transform( obj
, volume
.transform
)
1718 if obj_data
.target
:#{
1719 volume
.target
= sr_entity_id( obj_data
.target
)
1720 volume
._anon
.trigger
.event
= obj_data
.target_event
1721 volume
._anon
.trigger
.event_leave
= obj_data
.target_event_leave
1726 elif ent_type
== 'ent_marker':#{
1727 marker
= ent_marker()
1728 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1729 compile_obj_transform( obj
, marker
.transform
)
1732 elif ent_type
== 'ent_skateshop':#{
1733 skateshop
= ent_skateshop()
1734 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1735 skateshop
.type = int(obj_data
.tipo
)
1736 if skateshop
.type == 0:#{
1737 boardshop
= skateshop
._anonymous
_union
.boards
1738 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1739 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1740 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1742 elif skateshop
.type == 1:#{
1743 charshop
= skateshop
._anonymous
_union
.character
1744 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1745 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1747 elif skateshop
.type == 2:#{
1748 worldshop
= skateshop
._anonymous
_union
.worlds
1749 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1750 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1752 elif skateshop
.type == 3:#{
1753 server
= skateshop
._anonymous
_union
.server
1754 server
.id_lever
= sr_entity_id( obj_data
.mark_display
)
1756 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1757 compile_obj_transform( obj
, skateshop
.transform
)
1758 sr_ent_push(skateshop
)
1760 elif ent_type
== 'ent_swspreview':#{
1761 workshop_preview
= ent_swspreview()
1762 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1763 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1764 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1765 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1766 sr_ent_push( workshop_preview
)
1768 elif ent_type
== 'ent_worldinfo':#{
1769 worldinfo
= ent_worldinfo()
1770 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1771 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1772 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1773 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1777 if obj_data
.fix_time
:#{
1778 worldinfo
.timezone
= obj_data
.fixed_time
1782 worldinfo
.timezone
= obj_data
.timezone
1784 worldinfo
.flags
= flags
1785 worldinfo
.pstr_skybox
= sr_compile_string( obj_data
.skybox
)
1786 sr_ent_push( worldinfo
)
1788 elif ent_type
== 'ent_ccmd':#{
1790 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1791 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1794 elif ent_type
== 'ent_objective':#{
1795 objective
= ent_objective()
1796 obj_data
= obj
.SR_data
.ent_objective
[0]
1797 objective
.id_next
= sr_entity_id( obj_data
.proxima
)
1798 objective
.id_win
= sr_entity_id( obj_data
.target
)
1799 objective
.win_event
= obj_data
.target_event
1800 objective
.filter = int(obj_data
.filtrar
)
1801 objective
.filter2
= 0
1802 objective
.time_limit
= obj_data
.time_limit
1804 compile_obj_transform( obj
, objective
.transform
)
1805 objective
.submesh_start
, objective
.submesh_count
, _
= \
1806 sr_compile_mesh_internal( obj
)
1808 sr_ent_push( objective
)
1810 elif ent_type
== 'ent_challenge':#{
1811 challenge
= ent_challenge()
1812 obj_data
= obj
.SR_data
.ent_challenge
[0]
1813 compile_obj_transform( obj
, challenge
.transform
)
1814 challenge
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1815 challenge
.target
= sr_entity_id( obj_data
.target
)
1816 challenge
.target_event
= obj_data
.target_event
1817 challenge
.reset
= sr_entity_id( obj_data
.reset
)
1818 challenge
.reset_event
= obj_data
.reset_event
1819 challenge
.first
= sr_entity_id( obj_data
.first
)
1820 challenge
.flags
= 0x00
1821 challenge
.camera
= sr_entity_id( obj_data
.camera
)
1822 if obj_data
.time_limit
: challenge
.flags |
= 0x01
1823 challenge
.status
= 0
1824 sr_ent_push( challenge
)
1826 elif ent_type
== 'ent_region':#{
1827 region
= ent_region()
1828 obj_data
= obj
.SR_data
.ent_region
[0]
1829 compile_obj_transform( obj
, region
.transform
)
1830 region
.submesh_start
, region
.submesh_count
, _
= \
1831 sr_compile_mesh_internal( obj
)
1832 region
.pstr_title
= sr_compile_string( obj_data
.title
)
1833 region
.zone_volume
= sr_entity_id( obj_data
.zone_volume
)
1834 region
.target0
[0] = sr_entity_id( obj_data
.target0
)
1835 region
.target0
[1] = obj_data
.target0_event
1836 sr_ent_push( region
)
1838 elif ent_type
== 'ent_relay':#{
1840 obj_data
= obj
.SR_data
.ent_relay
[0]
1841 relay
.targets
[0][0] = sr_entity_id( obj_data
.target0
)
1842 relay
.targets
[1][0] = sr_entity_id( obj_data
.target1
)
1843 relay
.targets
[2][0] = sr_entity_id( obj_data
.target2
)
1844 relay
.targets
[3][0] = sr_entity_id( obj_data
.target3
)
1845 relay
.targets
[0][1] = obj_data
.target0_event
1846 relay
.targets
[1][1] = obj_data
.target1_event
1847 relay
.targets
[2][1] = obj_data
.target2_event
1848 relay
.targets
[3][1] = obj_data
.target3_event
1849 sr_ent_push( relay
)
1851 # elif ent_type == 'ent_list':#{
1852 # lista = ent_list()
1853 # obj_data = obj.SR_data.ent_list[0]
1855 # lista.entity_ref_start = entity_file_ref_count
1856 # lista.entity_ref_count = len( obj_data.entities )
1857 # entity_file_ref_count += lista.entity_ref_count
1859 # for child in obj_data.entities:#{
1860 # reference_struct = file_entity_ref()
1861 # reference_struct.index = sr_entity_id( child.target )
1862 # sr_ent_push( reference_struct )
1865 # sr_ent_push( lista )
1867 elif ent_type
== 'ent_glider':#{
1868 glider
= ent_glider()
1869 compile_obj_transform( obj
, glider
.transform
)
1870 sr_ent_push( glider
)
1872 elif ent_type
== 'ent_npc':#{
1873 obj_data
= obj
.SR_data
.ent_npc
[0]
1875 compile_obj_transform( obj
, npc
.transform
)
1876 npc
.id = obj_data
.au
1877 npc
.context
= obj_data
.context
1878 npc
.camera
= sr_entity_id( obj_data
.cam
)
1881 elif ent_type
== 'ent_cubemap':#{
1882 cubemap
= ent_cubemap()
1883 co
= obj
.matrix_world
@ Vector((0,0,0))
1884 cubemap
.co
[0] = co
[0]
1885 cubemap
.co
[1] = co
[2]
1886 cubemap
.co
[2] = -co
[1]
1887 cubemap
.resolution
= 0
1889 sr_ent_push( cubemap
)
1891 elif ent_type
== 'ent_miniworld':#{
1892 miniworld
= ent_miniworld()
1893 obj_data
= obj
.SR_data
.ent_miniworld
[0]
1895 compile_obj_transform( obj
, miniworld
.transform
)
1896 miniworld
.pstr_world
= sr_compile_string( obj_data
.world
)
1897 miniworld
.proxy
= sr_entity_id( obj_data
.proxy
)
1898 miniworld
.camera
= sr_entity_id( obj_data
.camera
)
1899 sr_ent_push( miniworld
)
1901 elif ent_type
== 'ent_prop':#{
1903 obj_data
= obj
.SR_data
.ent_prop
[0]
1904 compile_obj_transform( obj
, prop
.transform
)
1905 prop
.submesh_start
, prop
.submesh_count
, _
= \
1906 sr_compile_mesh_internal( obj
)
1907 prop
.flags
= obj_data
.flags
1908 prop
.pstr_alias
= sr_compile_string( obj_data
.alias
)
1914 sr_compile_menus( collection
)
1915 sr_compile_fonts( collection
)
1917 def _children( col
):#{
1919 for c
in col
.children
:#{
1920 yield from _children(c
)
1924 checkpoint_count
= 0
1925 pathindice_count
= 0
1928 for col
in _children(collection
):#{
1929 print( F
"Adding routes for subcollection: {col.name}" )
1935 for obj
in col
.objects
:#{
1936 if obj
.type == 'ARMATURE': pass
1938 ent_type
= obj_ent_type( obj
)
1940 if ent_type
== 'ent_gate':
1941 route_gates
+= [obj
]
1942 elif ent_type
== 'ent_route_node':#{
1943 if obj
.type == 'CURVE':#{
1944 route_curves
+= [obj
]
1947 elif ent_type
== 'ent_route':
1949 elif ent_type
== 'ent_traffic':
1954 dij
= create_node_graph( route_curves
, route_gates
)
1956 for obj
in routes
:#{
1957 obj_data
= obj
.SR_data
.ent_route
[0]
1959 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1960 route
.checkpoints_start
= checkpoint_count
1961 route
.checkpoints_count
= 0
1962 route
.id_camera
= sr_entity_id( obj_data
.cam
)
1965 route
.colour
[ci
] = obj_data
.colour
[ci
]
1966 route
.colour
[3] = 1.0
1968 compile_obj_transform( obj
, route
.transform
)
1969 checkpoints
= obj_data
.gates
1971 for i
in range(len(checkpoints
)):#{
1972 gi
= checkpoints
[i
].target
1973 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1977 dest
= gi
.SR_data
.ent_gate
[0].target
1981 if gi
==gj
: continue # error?
1982 if not gi
or not gj
: continue
1984 checkpoint
= ent_checkpoint()
1985 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1986 checkpoint
.path_start
= pathindice_count
1987 checkpoint
.path_count
= 0
1989 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1992 for pi
in range(len(path
)):#{
1993 pathindice
= ent_path_index()
1994 pathindice
.index
= routenode_count
+ path
[pi
]
1995 sr_ent_push( pathindice
)
1997 checkpoint
.path_count
+= 1
1998 pathindice_count
+= 1
2002 sr_ent_push( checkpoint
)
2003 route
.checkpoints_count
+= 1
2004 checkpoint_count
+= 1
2007 sr_ent_push( route
)
2010 for obj
in traffics
:#{
2011 traffic
= ent_traffic()
2012 compile_obj_transform( obj
, traffic
.transform
)
2013 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
2014 sr_compile_mesh_internal( obj
)
2016 # find best subsection
2018 graph_keys
= list(dij
.graph
)
2022 for j
in range(len(dij
.points
)):#{
2023 point
= dij
.points
[j
]
2024 dist
= (point
-obj
.location
).magnitude
2026 if dist
< min_dist
:#{
2033 best_begin
= best_point
2034 best_end
= best_point
2037 map0
= dij
.subsections
[best_begin
]
2038 if map0
[1] == -1: break
2039 best_begin
= map0
[1]
2042 map1
= dij
.subsections
[best_end
]
2043 if map1
[2] == -1: break
2047 traffic
.start_node
= routenode_count
+ best_begin
2048 traffic
.node_count
= best_end
- best_begin
2049 traffic
.index
= best_point
- best_begin
2050 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
2053 sr_ent_push(traffic
)
2056 for point
in dij
.points
:#{
2057 rn
= ent_route_node()
2060 rn
.co
[2] = -point
[1]
2064 routenode_count
+= len(dij
.points
)
2067 print( F
"[SR] Writing file" )
2069 file_array_instructions
= {}
2072 def _write_array( name
, item_size
, data
):#{
2073 nonlocal file_array_instructions
, file_offset
2075 count
= len(data
)//item_size
2076 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
2077 'data':data
, 'offset': file_offset
}
2078 file_offset
+= len(data
)
2079 file_offset
= int_align_to( file_offset
, 8 )
2082 _write_array( 'strings', 1, sr_compile
.string_data
)
2083 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
2084 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
2085 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
2086 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
2087 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
2088 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
2090 for name
, buffer in sr_compile
.entity_data
.items():#{
2091 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
2094 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
2095 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
2096 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
2097 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
2098 _write_array( 'pack', 1, sr_compile
.pack_data
)
2099 _write_array( 'shader_data', 1, sr_compile
.shader_data
)
2101 header_size
= int_align_to( sizeof(mdl_header
), 8 )
2102 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
2104 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
2105 path
= F
"{folder}{collection.name}.mdl"
2108 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
2109 fp
= open( path
, "wb" )
2110 header
= mdl_header()
2111 header
.version
= MDL_VERSION_NR
2112 sr_array_title( header
.arrays
, \
2113 'index', len(file_array_instructions
), \
2114 sizeof(mdl_array
), header_size
)
2116 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
2118 print( F
'[SR] {"name":>16}| count | offset' )
2120 for name
,info
in file_array_instructions
.items():#{
2122 offset
= info
['offset'] + header_size
+ index_size
2123 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
2124 index
.extend( bytearray(arr
) )
2126 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
2127 F
' 0x{info["offset"]:02x}' )
2129 fp
.write( bytearray_align_to( index
, 8 ) )
2130 #bytearray_print_hex( index )
2132 for name
,info
in file_array_instructions
.items():#{
2133 fp
.write( bytearray_align_to( info
['data'], 8 ) )
2138 print( '[SR] done' )
2141 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
2143 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
2144 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
2145 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=False )
2147 panel
: bpy
.props
.EnumProperty(
2151 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
2152 ('ENTITY', 'Entity', '', 'MONKEY',1),
2153 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
2158 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
2160 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
2161 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
2164 def sr_get_mirror_bone( bones
):
2166 side
= bones
.active
.name
[-1:]
2167 other_name
= bones
.active
.name
[:-1]
2168 if side
== 'L': other_name
+= 'R'
2169 elif side
== 'R': other_name
+= 'L'
2173 if b
.name
== other_name
:
2180 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2182 bl_idname
="skaterift.mirror_bone"
2183 bl_label
="Mirror bone attributes - SkateRift"
2185 def execute(_
,context
):
2187 active_object
= context
.active_object
2188 bones
= active_object
.data
.bones
2190 b
= sr_get_mirror_bone( bones
)
2192 if not b
: return {'FINISHED'}
2194 b
.SR_data
.collider
= a
.SR_data
.collider
2196 def _v3copyflipy( a
, b
):#{
2202 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2203 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2204 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2205 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2207 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2209 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2210 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2211 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2213 b
.SR_data
.conet
= a
.SR_data
.conet
2216 ob
= bpy
.context
.scene
.objects
[0]
2217 ob
.hide_render
= ob
.hide_render
2222 class SR_COMPILE(bpy
.types
.Operator
):
2224 bl_idname
="skaterift.compile_all"
2225 bl_label
="Compile All"
2227 def execute(_
,context
):
2229 view_layer
= bpy
.context
.view_layer
2230 for col
in view_layer
.layer_collection
.children
["export"].children
:
2231 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2232 sr_compile( bpy
.data
.collections
[col
.name
] )
2238 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2240 bl_idname
="skaterift.compile_this"
2241 bl_label
="Compile This collection"
2243 def execute(_
,context
):
2245 col
= bpy
.context
.collection
2252 class SR_INTERFACE(bpy
.types
.Panel
):
2254 bl_idname
= "VIEW3D_PT_skate_rift"
2255 bl_label
= "Skate Rift"
2256 bl_space_type
= 'VIEW_3D'
2257 bl_region_type
= 'UI'
2258 bl_category
= "Skate Rift"
2260 def draw(_
, context
):
2264 row
= _
.layout
.row()
2266 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2268 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2269 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2271 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2272 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2273 col
= bpy
.context
.collection
2275 found_in_export
= False
2277 view_layer
= bpy
.context
.view_layer
2278 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2279 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2282 if c1
.name
== col
.name
: #{
2283 found_in_export
= True
2287 box
= _
.layout
.box()
2289 row
.alignment
= 'CENTER'
2292 if found_in_export
: #{
2293 row
.label( text
=col
.name
+ ".mdl" )
2294 box
.prop( col
.SR_data
, "pack_textures" )
2295 box
.prop( col
.SR_data
, "animations" )
2296 box
.operator( "skaterift.compile_this" )
2300 row
.label( text
=col
.name
)
2304 row
.alignment
= 'CENTER'
2306 row
.label( text
="This collection is not in the export group" )
2309 box
= _
.layout
.box()
2312 split
= row
.split( factor
=0.3, align
=True )
2313 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2316 if export_count
== 0:
2318 row1
.operator( "skaterift.compile_all", \
2319 text
=F
"Compile all ({export_count} collections)" )
2321 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2322 active_object
= context
.active_object
2323 if not active_object
: return
2325 amount
= max( 0, len(context
.selected_objects
)-1 )
2327 row
= _
.layout
.row()
2328 row
.operator( 'skaterift.copy_entity_data', \
2329 text
=F
'Copy entity data to {amount} other objects' )
2330 if amount
== 0: row
.enabled
=False
2332 box
= _
.layout
.box()
2334 row
.alignment
= 'CENTER'
2335 row
.label( text
=active_object
.name
)
2338 def _draw_prop_collection( source
, data
): #{
2341 row
.alignment
= 'CENTER'
2344 row
.label( text
=F
'{source}' )
2346 if hasattr(type(data
[0]),'sr_inspector'):#{
2347 type(data
[0]).sr_inspector( box
, data
)
2350 for a
in data
[0].__annotations
__:
2351 box
.prop( data
[0], a
)
2355 if active_object
.type == 'ARMATURE': #{
2356 if active_object
.mode
== 'POSE': #{
2357 bones
= active_object
.data
.bones
2358 mb
= sr_get_mirror_bone( bones
)
2360 box
.operator( "skaterift.mirror_bone", \
2361 text
=F
'Mirror attributes to {mb.name}' )
2364 _draw_prop_collection( \
2365 F
'bpy.types.Bone["{bones.active.name}"].SR_data',\
2366 [bones
.active
.SR_data
] )
2370 row
.alignment
='CENTER'
2373 row
.label( text
="Enter pose mode to modify bone properties" )
2376 elif active_object
.type == 'LIGHT': #{
2377 _draw_prop_collection( \
2378 F
'bpy.types.Light["{active_object.data.name}"].SR_data', \
2379 [active_object
.data
.SR_data
] )
2381 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2382 box
.prop( active_object
.SR_data
, "ent_type" )
2383 ent_type
= active_object
.SR_data
.ent_type
2385 col
= getattr( active_object
.SR_data
, ent_type
, None )
2386 if col
!= None and len(col
)!=0:
2387 _draw_prop_collection( \
2388 F
'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \
2391 if active_object
.type == 'MESH':#{
2392 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2393 if col
!= None and len(col
)!=0:
2394 _draw_prop_collection( \
2395 F
'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \
2403 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2405 bl_label
="Skate Rift material"
2406 bl_idname
="MATERIAL_PT_sr_material"
2407 bl_space_type
='PROPERTIES'
2408 bl_region_type
='WINDOW'
2409 bl_context
="material"
2411 def draw(_
,context
):
2413 active_object
= bpy
.context
.active_object
2414 if active_object
== None: return
2415 active_mat
= active_object
.active_material
2416 if active_mat
== None: return
2418 info
= material_info( active_mat
)
2420 if 'tex_diffuse' in info
:#{
2421 _
.layout
.label( icon
='INFO', \
2422 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2425 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2426 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2427 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2429 if active_mat
.SR_data
.collision
:#{
2430 box
= _
.layout
.box()
2433 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2434 (active_mat
.SR_data
.shader
!= 'boundary') and \
2435 (active_mat
.SR_data
.shader
!= 'walking'):#{
2436 row
.prop( active_mat
.SR_data
, "skate_surface" )
2437 row
.prop( active_mat
.SR_data
, "grind_surface" )
2438 row
.prop( active_mat
.SR_data
, "grow_grass" )
2439 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2443 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2444 box
= _
.layout
.box()
2445 box
.prop( active_mat
.SR_data
, "blend_offset" )
2446 box
.prop( active_mat
.SR_data
, "sand_colour" )
2448 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2449 box
= _
.layout
.box()
2450 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2451 box
.prop( active_mat
.SR_data
, "blend_offset" )
2453 elif active_mat
.SR_data
.shader
== "water":#{
2454 box
= _
.layout
.box()
2455 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2456 box
.prop( active_mat
.SR_data
, "shore_colour" )
2457 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2458 box
.prop( active_mat
.SR_data
, "water_fog" )
2459 box
.prop( active_mat
.SR_data
, "water_fresnel" )
2460 box
.prop( active_mat
.SR_data
, "water_scale" )
2461 box
.prop( active_mat
.SR_data
, "water_rate" )
2463 elif active_mat
.SR_data
.shader
== "cubemap":#{
2464 box
= _
.layout
.box()
2465 box
.prop( active_mat
.SR_data
, "cubemap" )
2466 box
.prop( active_mat
.SR_data
, "tint" )
2469 _
.layout
.label( text
="" )
2470 _
.layout
.label( text
="advanced (you probably don't want to edit these)" )
2471 _
.layout
.prop( active_mat
.SR_data
, "tex_diffuse_rt" )
2475 def sr_get_type_enum( scene
, context
):
2477 items
= [('none','None',"")]
2478 mesh_entities
=['ent_gate','ent_water']
2479 point_entities
=['ent_spawn','ent_route_node','ent_route']
2481 for e
in point_entities
: items
+= [(e
,e
,'')]
2483 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2484 if context
.active_object
.type == 'MESH': #{
2485 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2489 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2495 def sr_on_type_change( _
, context
):
2497 obj
= context
.active_object
2498 ent_type
= obj
.SR_data
.ent_type
2499 if ent_type
== 'none': return
2500 if obj
.type == 'MESH':#{
2501 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2502 if col
!= None and len(col
)==0: col
.add()
2505 col
= getattr( obj
.SR_data
, ent_type
, None )
2506 if col
!= None and len(col
)==0: col
.add()
2509 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2511 alias
: bpy
.props
.StringProperty( name
='alias' )
2514 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2516 target
: bpy
.props
.PointerProperty( \
2517 type=bpy
.types
.Object
, name
="destination", \
2518 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2520 key
: bpy
.props
.StringProperty()
2521 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2522 ('nonlocal', 'Non-Local', "")))
2524 flip
: bpy
.props
.BoolProperty( name
="Flip exit", default
=False )
2525 custom
: bpy
.props
.BoolProperty( name
="Mesh is surface", default
=False )
2526 locked
: bpy
.props
.BoolProperty( name
="Start Locked", default
=False )
2529 def sr_inspector( layout
, data
):
2532 box
.prop( data
[0], 'tipo', text
="subtype" )
2534 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2535 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2538 flags
.prop( data
[0], 'flip' )
2539 flags
.prop( data
[0], 'custom' )
2540 flags
.prop( data
[0], 'locked' )
2544 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2546 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2549 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2551 target
: bpy
.props
.PointerProperty( \
2552 type=bpy
.types
.Object
, name
='target', \
2553 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2556 class SR_OBJECT_ENT_MINIWORLD(bpy
.types
.PropertyGroup
):
2558 world
: bpy
.props
.StringProperty( name
='world UID' )
2559 proxy
: bpy
.props
.PointerProperty( \
2560 type=bpy
.types
.Object
, name
='proxy', \
2561 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_prop']))
2562 camera
: bpy
.props
.PointerProperty( \
2563 type=bpy
.types
.Object
, name
="Camera", \
2564 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2567 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2569 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2571 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2573 layout
.prop( item
, 'target', text
='', emboss
=False )
2577 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2579 active_object
= context
.active_object
2580 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2581 lista
= getattr(data
,collection_name
)
2582 index
= getattr(data
,F
'{collection_name}_index')
2586 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2590 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2592 active_object
= context
.active_object
2593 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2597 def copy_propgroup( de
, to
):
2599 for a
in de
.__annotations
__:#{
2600 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2604 while len(cb
) != len(ca
):#{
2605 if len(cb
) < len(ca
): cb
.add()
2608 for i
in range(len(ca
)):#{
2609 copy_propgroup(ca
[i
],cb
[i
])
2613 setattr(to
,a
,getattr(de
,a
))
2618 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2620 bl_idname
= "skaterift.copy_entity_data"
2621 bl_label
= "Copy entity data"
2623 def execute(self
, context
):#{
2624 data
= context
.active_object
.SR_data
2625 new_type
= data
.ent_type
2626 print( F
"Copy entity data from: {context.active_object.name}" )
2628 for obj
in context
.selected_objects
:#{
2629 if obj
!= context
.active_object
:#{
2630 print( F
" To: {obj.name}" )
2632 obj
.SR_data
.ent_type
= new_type
2634 if active_object
.type == 'MESH':#{
2635 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2636 if col
!= None and len(col
)==0: col
.add()
2637 mdata
= context
.active_object
.data
.SR_data
2638 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2641 col
= getattr( obj
.SR_data
, new_type
, None )
2642 if col
!= None and len(col
)==0: col
.add()
2643 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2650 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2652 bl_idname
= "skaterift.new_entry"
2653 bl_label
= "Add gate"
2655 def execute(self
, context
):#{
2656 return internal_listadd_execute(self
,context
,'ent_route','gates')
2660 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2662 bl_idname
= "skaterift.del_entry"
2663 bl_label
= "Remove gate"
2666 def poll(cls
, context
):#{
2667 active_object
= context
.active_object
2668 if obj_ent_type(active_object
) == 'ent_route':#{
2669 return active_object
.SR_data
.ent_route
[0].gates
2674 def execute(self
, context
):#{
2675 return internal_listdel_execute(self
,context
,'ent_route','gates')
2679 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2681 bl_idname
= "skaterift.al_new_entry"
2682 bl_label
= "Add file"
2684 def execute(self
, context
):#{
2685 return internal_listadd_execute(self
,context
,'ent_audio','files')
2689 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2691 bl_idname
= "skaterift.al_del_entry"
2692 bl_label
= "Remove file"
2695 def poll(cls
, context
):#{
2696 active_object
= context
.active_object
2697 if obj_ent_type(active_object
) == 'ent_audio':#{
2698 return active_object
.SR_data
.ent_audio
[0].files
2703 def execute(self
, context
):#{
2704 return internal_listdel_execute(self
,context
,'ent_audio','files')
2709 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2711 bl_idname
= "skaterift.gl_new_entry"
2712 bl_label
= "Add glyph"
2714 def execute(self
, context
):#{
2715 active_object
= context
.active_object
2717 font
= active_object
.SR_data
.ent_font
[0]
2720 if len(font
.glyphs
) > 1:#{
2721 prev
= font
.glyphs
[-2]
2722 cur
= font
.glyphs
[-1]
2724 cur
.bounds
= prev
.bounds
2725 cur
.utf32
= prev
.utf32
+1
2732 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2734 bl_idname
= "skaterift.gl_del_entry"
2735 bl_label
= "Remove Glyph"
2738 def poll(cls
, context
):#{
2739 active_object
= context
.active_object
2740 if obj_ent_type(active_object
) == 'ent_font':#{
2741 return active_object
.SR_data
.ent_font
[0].glyphs
2746 def execute(self
, context
):#{
2747 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2751 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2753 bl_idname
= "skaterift.gl_move_item"
2755 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2756 ('DOWN', 'Down', ""),))
2759 def poll(cls
, context
):#{
2760 active_object
= context
.active_object
2761 if obj_ent_type(active_object
) == 'ent_font':#{
2762 return active_object
.SR_data
.ent_font
[0].glyphs
2767 def execute(_
, context
):#{
2768 active_object
= context
.active_object
2769 data
= active_object
.SR_data
.ent_font
[0]
2771 index
= data
.glyphs_index
2772 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2773 data
.glyphs
.move( neighbor
, index
)
2775 list_length
= len(data
.glyphs
) - 1
2776 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2778 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2784 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2786 bl_idname
= "skaterift.fv_new_entry"
2787 bl_label
= "Add variant"
2789 def execute(self
, context
):#{
2790 return internal_listadd_execute(self
,context
,'ent_font','variants')
2794 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2796 bl_idname
= "skaterift.fv_del_entry"
2797 bl_label
= "Remove variant"
2800 def poll(cls
, context
):#{
2801 active_object
= context
.active_object
2802 if obj_ent_type(active_object
) == 'ent_font':#{
2803 return active_object
.SR_data
.ent_font
[0].variants
2808 def execute(self
, context
):#{
2809 return internal_listdel_execute(self
,context
,'ent_font','variants')
2813 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2815 path
: bpy
.props
.StringProperty( name
="Path" )
2816 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2819 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2821 bl_idname
= 'SR_UL_AUDIO_LIST'
2823 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2825 split
= layout
.split(factor
=0.7)
2827 c
.prop( item
, 'path', text
='', emboss
=False )
2829 c
.prop( item
, 'probability', text
='%', emboss
=True )
2833 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2835 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2837 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2839 layout
.prop( item
, 'mesh', emboss
=False )
2840 layout
.prop( item
, 'tipo' )
2844 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2846 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2848 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2850 s0
= layout
.split(factor
=0.3)
2852 s1
= c
.split(factor
=0.3)
2855 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2859 c
.prop( item
, 'utf32', text
='', emboss
=True )
2862 row
.prop( item
, 'bounds', text
='', emboss
=False )
2866 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2868 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2869 gates_index
: bpy
.props
.IntProperty()
2871 colour
: bpy
.props
.FloatVectorProperty( \
2875 default
=Vector((0.79,0.63,0.48)),\
2876 description
="Route colour"\
2879 alias
: bpy
.props
.StringProperty(\
2881 default
="Untitled Course")
2883 cam
: bpy
.props
.PointerProperty( \
2884 type=bpy
.types
.Object
, name
="Viewpoint", \
2885 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2888 def sr_inspector( layout
, data
):
2890 layout
.prop( data
[0], 'alias' )
2891 layout
.prop( data
[0], 'colour' )
2892 layout
.prop( data
[0], 'cam' )
2894 layout
.label( text
='Checkpoints' )
2895 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2896 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2899 row
.operator( 'skaterift.new_entry', text
='Add' )
2900 row
.operator( 'skaterift.del_entry', text
='Remove' )
2905 class SR_OT_ENT_LIST_NEW_ITEM(bpy
.types
.Operator
):#{
2906 bl_idname
= "skaterift.ent_list_new_entry"
2907 bl_label
= "Add entity"
2909 def execute(self
, context
):#{
2910 return internal_listadd_execute(self
,context
,'ent_list','entities')
2914 class SR_OT_ENT_LIST_DEL_ITEM(bpy
.types
.Operator
):#{
2915 bl_idname
= "skaterift.ent_list_del_entry"
2916 bl_label
= "Remove entity"
2919 def poll(cls
, context
):#{
2920 active_object
= context
.active_object
2921 if obj_ent_type(active_object
) == 'ent_list':#{
2922 return active_object
.SR_data
.ent_list
[0].entities
2927 def execute(self
, context
):#{
2928 return internal_listdel_execute(self
,context
,'ent_list','entities')
2932 class SR_OBJECT_ENT_LIST_ENTRY(bpy
.types
.PropertyGroup
):
2934 target
: bpy
.props
.PointerProperty( \
2935 type=bpy
.types
.Object
, name
='target' )
2938 class SR_UL_ENT_LIST(bpy
.types
.UIList
):#{
2939 bl_idname
= 'SR_UL_ENT_LIST'
2941 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):#{
2942 layout
.prop( item
, 'target', text
='', emboss
=False )
2946 class SR_OBJECT_ENT_LIST(bpy
.types
.PropertyGroup
):#{
2947 entities
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST_ENTRY
)
2948 entities_index
: bpy
.props
.IntProperty()
2951 def sr_inspector( layout
, data
):#{
2952 layout
.label( text
='Entities' )
2953 layout
.template_list('SR_UL_ENT_LIST', 'Entities', \
2954 data
[0], 'entities', data
[0], \
2955 'entities_index', rows
=5)
2958 row
.operator( 'skaterift.ent_list_new_entry', text
='Add' )
2959 row
.operator( 'skaterift.ent_list_del_entry', text
='Remove' )
2963 class SR_OBJECT_ENT_GLIDER(bpy
.types
.PropertyGroup
):#{
2964 nothing
: bpy
.props
.StringProperty()
2967 class SR_OBJECT_ENT_NPC(bpy
.types
.PropertyGroup
):#{
2968 au
: bpy
.props
.IntProperty()
2969 context
: bpy
.props
.IntProperty()
2970 cam
: bpy
.props
.PointerProperty( \
2971 type=bpy
.types
.Object
, name
="Viewpoint", \
2972 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2975 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):#{
2976 subtype
: bpy
.props
.EnumProperty(
2978 items
=[('0','Trigger',''),
2979 ('1','Particles (0.1s)','')]
2982 target
: bpy
.props
.PointerProperty( \
2983 type=bpy
.types
.Object
, name
="Target", \
2984 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
2985 target_event
: bpy
.props
.IntProperty( name
="Enter Ev" )
2986 target_event_leave
: bpy
.props
.IntProperty( name
="Leave Ev", default
=-1 )
2989 def inspect_target( layout
, data
, propname
, evs
= ['_event'] ):#{
2991 box
.prop( data
[0], propname
)
2993 for evname
in evs
:#{
2995 row
.prop( data
[0], propname
+ evname
)
2997 target
= getattr( data
[0], propname
)
2999 tipo
= target
.SR_data
.ent_type
3000 cls
= globals()[ tipo
]
3002 table
= getattr( cls
, 'sr_functions', None )
3004 index
= getattr( data
[0], propname
+ evname
)
3006 row
.label( text
=table
[index
] )
3008 row
.label( text
="undefined function" )
3012 row
.label( text
="..." )
3019 def sr_inspector( layout
, data
):#{
3020 layout
.prop( data
[0], 'subtype' )
3021 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target', \
3022 ['_event','_event_leave'] )
3026 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
3028 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
3029 files_index
: bpy
.props
.IntProperty()
3031 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
3032 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
3033 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
3034 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
3036 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
3037 formato
: bpy
.props
.EnumProperty(
3039 items
=[('0','Uncompressed Mono',''),
3040 ('1','Compressed Vorbis',''),
3041 ('2','[vg] Bird Synthesis','')]
3043 probability_curve
: bpy
.props
.EnumProperty(
3044 name
="Probability Curve",
3045 items
=[('0','Constant',''),
3046 ('1','Wildlife Daytime',''),
3047 ('2','Wildlife Nighttime','')])
3048 channel_behaviour
: bpy
.props
.EnumProperty(
3049 name
="Channel Behaviour",
3050 items
=[('0','Unlimited',''),
3051 ('1','Discard if group full', ''),
3052 ('2','Crossfade if group full','')])
3054 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
3057 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
3058 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
3061 def sr_inspector( layout
, data
):
3063 layout
.prop( data
[0], 'formato' )
3064 layout
.prop( data
[0], 'volume' )
3067 box
.label( text
='Channels' )
3068 split
= box
.split(factor
=0.3)
3070 c
.prop( data
[0], 'max_channels' )
3072 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
3073 if data
[0].channel_behaviour
>= '1':
3074 box
.prop( data
[0], 'group' )
3075 if data
[0].channel_behaviour
== '2':
3076 box
.prop( data
[0], 'transition_duration' )
3079 box
.label( text
='Flags' )
3080 box
.prop( data
[0], 'flag_3d' )
3081 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
3083 box
.prop( data
[0], 'flag_loop' )
3084 box
.prop( data
[0], 'flag_auto' )
3086 layout
.prop( data
[0], 'probability_curve' )
3088 split
= layout
.split(factor
=0.7)
3090 c
.label( text
='Filepath' )
3092 c
.label( text
='Chance' )
3093 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
3094 data
[0], 'files', data
[0], 'files_index', rows
=5)
3097 row
.operator( 'skaterift.al_new_entry', text
='Add' )
3098 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
3102 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
3104 alias
: bpy
.props
.StringProperty()
3105 flags
: bpy
.props
.IntProperty()
3108 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
3110 mini
: bpy
.props
.FloatVectorProperty(size
=2)
3111 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
3112 utf32
: bpy
.props
.IntProperty()
3115 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
3117 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
3118 utf32
: bpy
.props
.IntProperty()
3121 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
3123 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
3124 tipo
: bpy
.props
.StringProperty()
3127 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
3129 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
3130 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
3131 alias
: bpy
.props
.StringProperty()
3133 glyphs_index
: bpy
.props
.IntProperty()
3134 variants_index
: bpy
.props
.IntProperty()
3137 def sr_inspector( layout
, data
):
3139 layout
.prop( data
[0], 'alias' )
3141 layout
.label( text
='Variants' )
3142 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
3143 data
[0], 'variants', data
[0], 'variants_index',\
3146 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
3147 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
3149 layout
.label( text
='ASCII Glyphs' )
3150 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
3151 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
3154 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
3155 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
3156 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
3157 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
3161 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
3163 speed
: bpy
.props
.FloatProperty(default
=1.0)
3166 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
3168 tipo
: bpy
.props
.EnumProperty( name
='Type',
3169 items
=[('0','boards',''),
3170 ('1','character',''),
3172 ('4','server','')] )
3173 mark_rack
: bpy
.props
.PointerProperty( \
3174 type=bpy
.types
.Object
, name
="Board Rack", \
3175 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3176 mark_display
: bpy
.props
.PointerProperty( \
3177 type=bpy
.types
.Object
, name
="Selected Board Display", \
3178 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3179 mark_info
: bpy
.props
.PointerProperty( \
3180 type=bpy
.types
.Object
, name
="Selected Board Info", \
3181 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
3182 ['ent_marker','ent_prop']))
3183 cam
: bpy
.props
.PointerProperty( \
3184 type=bpy
.types
.Object
, name
="Viewpoint", \
3185 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3188 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
3190 mark_display
: bpy
.props
.PointerProperty( \
3191 type=bpy
.types
.Object
, name
="Board Display", \
3192 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3193 mark_display1
: bpy
.props
.PointerProperty( \
3194 type=bpy
.types
.Object
, name
="Board Display (other side)", \
3195 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3196 cam
: bpy
.props
.PointerProperty( \
3197 type=bpy
.types
.Object
, name
="Viewpoint", \
3198 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3201 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
3203 link0
: bpy
.props
.PointerProperty( \
3204 type=bpy
.types
.Object
, name
="Link 0", \
3205 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3206 link1
: bpy
.props
.PointerProperty( \
3207 type=bpy
.types
.Object
, name
="Link 1", \
3208 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3209 link2
: bpy
.props
.PointerProperty( \
3210 type=bpy
.types
.Object
, name
="Link 2", \
3211 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3212 link3
: bpy
.props
.PointerProperty( \
3213 type=bpy
.types
.Object
, name
="Link 3", \
3214 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3216 newloc
: bpy
.props
.PointerProperty( \
3217 type=bpy
.types
.Object
, name
="New location", \
3218 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3219 stack_behaviour
: bpy
.props
.EnumProperty( name
='Stack Behaviour',
3220 items
=[('0','append',''),
3221 ('1','replace','')])
3223 camera
: bpy
.props
.PointerProperty( \
3224 type=bpy
.types
.Object
, name
="Camera", \
3225 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3227 slider_minloc
: bpy
.props
.PointerProperty( \
3228 type=bpy
.types
.Object
, name
="Slider min", \
3229 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3230 slider_maxloc
: bpy
.props
.PointerProperty( \
3231 type=bpy
.types
.Object
, name
="Slider max", \
3232 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
3233 slider_handle
: bpy
.props
.PointerProperty( \
3234 type=bpy
.types
.Object
, name
="Slider handle", \
3235 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3237 checkmark
: bpy
.props
.PointerProperty( \
3238 type=bpy
.types
.Object
, name
="Checked", \
3239 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
3241 font_variant
: bpy
.props
.IntProperty( name
="Font Variant" )
3243 string
: bpy
.props
.StringProperty( name
="String" )
3244 tipo
: bpy
.props
.EnumProperty( name
='Type',
3245 items
=[('0','visual',''),
3246 ('1','event button',''),
3247 ('2','page button',''),
3252 ('7','visual(no colourize)','')])
3255 def sr_inspector( layout
, data
):
3259 box
.prop( data
, 'tipo' )
3261 if data
.tipo
== '0' or data
.tipo
== '7':#{
3262 box
.prop( data
, 'string', text
='Name' )
3265 elif data
.tipo
== '1':#{
3266 box
.prop( data
, 'string', text
='Event' )
3268 elif data
.tipo
== '2':#{
3269 box
.prop( data
, 'string', text
='Page' )
3270 box
.prop( data
, 'stack_behaviour' )
3272 elif data
.tipo
== '3':#{
3273 box
.prop( data
, 'string', text
='Data (i32)' )
3274 box
.prop( data
, 'checkmark' )
3276 elif data
.tipo
== '4':#{
3277 box
.prop( data
, 'string', text
='Data (f32)' )
3278 box
.prop( data
, 'slider_minloc' )
3279 box
.prop( data
, 'slider_maxloc' )
3280 box
.prop( data
, 'slider_handle' )
3282 box
.label( text
="Links" )
3283 box
.prop( data
, 'link0', text
='v0' )
3284 box
.prop( data
, 'link1', text
='v1' )
3287 elif data
.tipo
== '5':#{
3288 box
.prop( data
, 'string', text
='Page Name' )
3289 box
.prop( data
, 'newloc', text
='Entry Point' )
3290 box
.prop( data
, 'camera', text
='Viewpoint' )
3293 elif data
.tipo
== '6':#{
3294 box
.prop( data
, 'string', text
='ID' )
3295 box
.prop( data
, 'font_variant' )
3300 box
.label( text
="Links" )
3301 box
.prop( data
, 'link0' )
3302 box
.prop( data
, 'link1' )
3303 box
.prop( data
, 'link2' )
3304 box
.prop( data
, 'link3' )
3308 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
3310 name
: bpy
.props
.StringProperty(name
="Name")
3311 desc
: bpy
.props
.StringProperty(name
="Description")
3312 author
: bpy
.props
.StringProperty(name
="Author")
3313 skybox
: bpy
.props
.StringProperty(name
="Skybox")
3315 fix_time
: bpy
.props
.BoolProperty(name
="Fix Time")
3316 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
3317 fixed_time
: bpy
.props
.FloatProperty(name
="Fixed Time (0-1)")
3320 def sr_inspector( layout
, data
):#{
3321 layout
.prop( data
[0], 'name' )
3322 layout
.prop( data
[0], 'desc' )
3323 layout
.prop( data
[0], 'author' )
3325 layout
.prop( data
[0], 'fix_time' )
3326 if data
[0].fix_time
:
3327 layout
.prop( data
[0], 'fixed_time' )
3329 layout
.prop( data
[0], 'timezone' )
3333 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
3335 command
: bpy
.props
.StringProperty(name
="Command Line")
3338 class SR_OBJECT_ENT_OBJECTIVE(bpy
.types
.PropertyGroup
):#{
3339 proxima
: bpy
.props
.PointerProperty( \
3340 type=bpy
.types
.Object
, name
="Next", \
3341 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3342 target
: bpy
.props
.PointerProperty( \
3343 type=bpy
.types
.Object
, name
="Win", \
3344 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3345 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3346 time_limit
: bpy
.props
.FloatProperty( name
="Time Limit", default
=1.0 )
3347 filtrar
: bpy
.props
.EnumProperty( name
='Filter',\
3348 items
=[('0','none',''),
3349 (str(0x1),'trick_shuvit',''),
3350 (str(0x2),'trick_kickflip',''),
3351 (str(0x4),'trick_treflip',''),
3352 (str(0x1|
0x2|
0x4),'trick_any',''),
3353 (str(0x8),'flip_back',''),
3354 (str(0x10),'flip_front',''),
3355 (str(0x8|
0x10),'flip_any',''),
3356 (str(0x20),'grind_truck_any',''),
3357 (str(0x40),'grind_board_any',''),
3358 (str(0x20|
0x40),'grind_any',''),
3359 (str(0x80),'footplant',''),
3360 (str(0x100),'passthrough',''),
3364 def sr_inspector( layout
, data
):#{
3365 layout
.prop( data
[0], 'proxima' )
3366 layout
.prop( data
[0], 'time_limit' )
3367 layout
.prop( data
[0], 'filtrar' )
3368 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3372 class SR_OBJECT_ENT_CHALLENGE(bpy
.types
.PropertyGroup
):#{
3373 alias
: bpy
.props
.StringProperty( name
="Alias" )
3375 target
: bpy
.props
.PointerProperty( \
3376 type=bpy
.types
.Object
, name
="On Complete", \
3377 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3378 target_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3379 reset
: bpy
.props
.PointerProperty( \
3380 type=bpy
.types
.Object
, name
="On Reset", \
3381 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3382 reset_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3384 time_limit
: bpy
.props
.BoolProperty( name
="Time Limit" )
3386 first
: bpy
.props
.PointerProperty( \
3387 type=bpy
.types
.Object
, name
="First Objective", \
3388 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_objective']))
3390 camera
: bpy
.props
.PointerProperty( \
3391 type=bpy
.types
.Object
, name
="Camera", \
3392 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
3396 def sr_inspector( layout
, data
):#{
3397 layout
.prop( data
[0], 'alias' )
3398 layout
.prop( data
[0], 'camera' )
3399 layout
.prop( data
[0], 'first' )
3400 layout
.prop( data
[0], 'time_limit' )
3401 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target' )
3402 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'reset' )
3406 class SR_OBJECT_ENT_REGION(bpy
.types
.PropertyGroup
):#{
3407 title
: bpy
.props
.StringProperty( name
="Title" )
3408 zone_volume
: bpy
.props
.PointerProperty(
3409 type=bpy
.types
.Object
, name
="Zone Volume", \
3410 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_volume']))
3412 target0
: bpy
.props
.PointerProperty( \
3413 type=bpy
.types
.Object
, name
="Triger on unlock", \
3414 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3415 target0_event
: bpy
.props
.IntProperty( name
="Event/Method" )
3418 def sr_inspector( layout
, data
):#{
3419 layout
.prop( data
[0], 'title' )
3420 layout
.prop( data
[0], 'zone_volume' )
3421 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3425 class SR_OBJECT_ENT_RELAY(bpy
.types
.PropertyGroup
):#{
3426 target0
: bpy
.props
.PointerProperty( \
3427 type=bpy
.types
.Object
, name
="Target 0", \
3428 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3429 target1
: bpy
.props
.PointerProperty( \
3430 type=bpy
.types
.Object
, name
="Target 1", \
3431 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3432 target2
: bpy
.props
.PointerProperty( \
3433 type=bpy
.types
.Object
, name
="Target 2", \
3434 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3435 target3
: bpy
.props
.PointerProperty( \
3436 type=bpy
.types
.Object
, name
="Target 3", \
3437 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,SR_TRIGGERABLE
))
3439 target0_event
: bpy
.props
.IntProperty( name
="Event" )
3440 target1_event
: bpy
.props
.IntProperty( name
="Event" )
3441 target2_event
: bpy
.props
.IntProperty( name
="Event" )
3442 target3_event
: bpy
.props
.IntProperty( name
="Event" )
3445 def sr_inspector( layout
, data
):#{
3446 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target0' )
3447 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target1' )
3448 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target2' )
3449 SR_OBJECT_ENT_VOLUME
.inspect_target( layout
, data
, 'target3' )
3453 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
3455 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
3456 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
3457 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
3458 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
3459 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
3460 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3461 ent_prop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
3462 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
3463 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
3464 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
3465 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
3467 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
3468 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
3469 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
3470 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3471 ent_objective
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE
)
3472 ent_challenge
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE
)
3473 ent_region
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_REGION
)
3474 ent_relay
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_RELAY
)
3475 ent_miniworld
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD
)
3476 ent_list
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_LIST
)
3477 ent_glider
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLIDER
)
3478 ent_npc
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_NPC
)
3480 ent_type
: bpy
.props
.EnumProperty(
3482 items
=sr_entity_list
,
3483 update
=sr_on_type_change
3487 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3489 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3492 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3494 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3497 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3499 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3500 items
=[('0','none',''),
3502 ('2','capsule','')])
3504 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3505 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3507 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3509 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3510 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3511 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3512 conet
: bpy
.props
.FloatProperty( name
='t' )
3515 def sr_inspector( layout
, data
):
3519 box
.prop( data
, 'collider' )
3521 if int(data
.collider
)>0:#{
3523 row
.prop( data
, 'collider_min' )
3525 row
.prop( data
, 'collider_max' )
3529 box
.prop( data
, 'cone_constraint' )
3530 if data
.cone_constraint
:#{
3532 row
.prop( data
, 'conevx' )
3534 row
.prop( data
, 'conevy' )
3536 row
.prop( data
, 'coneva' )
3537 box
.prop( data
, 'conet' )
3542 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3544 shader
: bpy
.props
.EnumProperty(
3547 ('standard',"standard",''),
3548 ('standard_cutout', "standard_cutout", ''),
3549 ('terrain_blend', "terrain_blend", ''),
3550 ('vertex_blend', "vertex_blend", ''),
3551 ('water',"water",''),
3552 ('invisible','Invisible',''),
3553 ('boundary','Boundary',''),
3554 ('fxglow','FX Glow',''),
3555 ('cubemap','Cubemap',''),
3556 ('walking','Walking',''),
3557 ('foliage','Foliage','')
3560 surface_prop
: bpy
.props
.EnumProperty(
3561 name
="Surface Property",
3563 ('0','concrete',''),
3568 ('5','snow (low friction)',''),
3569 ('6','sand (medium friction)','')
3572 collision
: bpy
.props
.BoolProperty( \
3573 name
="Collisions Enabled",\
3575 description
= "Can the player collide with this material?"\
3577 skate_surface
: bpy
.props
.BoolProperty( \
3578 name
="Skate Target", \
3580 description
= "Should the game try to target this surface?" \
3582 grind_surface
: bpy
.props
.BoolProperty( \
3585 description
= "Can you grind on this surface?" \
3587 grow_grass
: bpy
.props
.BoolProperty( \
3588 name
="Grow Grass", \
3590 description
= "Spawn grass sprites on this surface?" \
3592 preview_visibile
: bpy
.props
.BoolProperty( \
3593 name
="Preview visibile", \
3595 description
= "Show this material in preview models?" \
3597 blend_offset
: bpy
.props
.FloatVectorProperty( \
3598 name
="Blend Offset", \
3600 default
=Vector((0.5,0.0)),\
3601 description
="When surface is more than 45 degrees, add this vector " +\
3604 sand_colour
: bpy
.props
.FloatVectorProperty( \
3605 name
="Sand Colour",\
3608 default
=Vector((0.79,0.63,0.48)),\
3609 description
="Blend to this colour near the 0 coordinate on UP axis"\
3611 shore_colour
: bpy
.props
.FloatVectorProperty( \
3612 name
="Shore Colour",\
3615 default
=Vector((0.03,0.32,0.61)),\
3616 description
="Water colour at the shoreline"\
3618 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3619 name
="Ocean Colour",\
3622 default
=Vector((0.0,0.006,0.03)),\
3623 description
="Water colour in the deep bits"\
3625 tint
: bpy
.props
.FloatVectorProperty( \
3630 default
=Vector((1.0,1.0,1.0,1.0)),\
3631 description
="Reflection tint"\
3634 water_fog
: bpy
.props
.FloatProperty( \
3637 description
="(default: 0.04) Cloudiness of water"\
3639 water_fresnel
: bpy
.props
.FloatProperty( \
3640 name
="Water Fresnel", \
3642 description
="(default: 5.0) Reflection/Fog Fresnel Ratio"\
3644 water_scale
: bpy
.props
.FloatProperty( \
3645 name
="Water Scale", \
3647 description
="(default: 0.008) Size of water texture"\
3649 water_rate
: bpy
.props
.FloatVectorProperty( \
3650 name
= "Water Wave Rate",\
3652 default
=Vector(( 0.008, 0.006, 0.003, 0.03 )),\
3654 "(default: 0.008, 0.006, 0.003, 0.03) Rate which water bump texture moves"\
3657 cubemap
: bpy
.props
.PointerProperty( \
3658 type=bpy
.types
.Object
, name
="cubemap", \
3659 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_cubemap']))
3661 tex_diffuse_rt
: bpy
.props
.IntProperty( name
="diffuse: RT index", default
=-1 )
3664 # ---------------------------------------------------------------------------- #
3668 # ---------------------------------------------------------------------------- #
3670 cv_view_draw_handler
= None
3671 cv_view_pixel_handler
= None
3672 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3674 cv_view_colours
= []
3675 cv_view_course_i
= 0
3677 # Draw axis alligned sphere at position with radius
3679 def cv_draw_sphere( pos
, radius
, colour
):
3681 global cv_view_verts
, cv_view_colours
3683 ly
= pos
+ Vector((0,0,radius
))
3684 lx
= pos
+ Vector((0,radius
,0))
3685 lz
= pos
+ Vector((0,0,radius
))
3687 pi
= 3.14159265358979323846264
3689 for i
in range(16):#{
3690 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3694 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3695 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3696 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3698 cv_view_verts
+= [ px
, lx
]
3699 cv_view_verts
+= [ py
, ly
]
3700 cv_view_verts
+= [ pz
, lz
]
3702 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3711 # Draw axis alligned sphere at position with radius
3713 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3715 global cv_view_verts
, cv_view_colours
3717 ly
= pos
+ tz
*radius
3718 lx
= pos
+ ty
*radius
3719 lz
= pos
+ tz
*radius
3721 pi
= 3.14159265358979323846264
3723 for i
in range(16):#{
3724 t
= ((i
+1.0) * 1.0/16.0) * pi
3728 s1
= math
.sin(t
*2.0)
3729 c1
= math
.cos(t
*2.0)
3731 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3732 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3733 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3735 cv_view_verts
+= [ px
, lx
]
3736 cv_view_verts
+= [ py
, ly
]
3737 cv_view_verts
+= [ pz
, lz
]
3739 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3748 # Draw transformed -1 -> 1 cube
3750 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3752 global cv_view_verts
, cv_view_colours
3758 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3759 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3760 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3761 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3762 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3763 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3764 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3765 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3767 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3768 (0,4),(1,5),(2,6),(3,7)]
3773 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3774 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3775 cv_view_colours
+= [colour
, colour
]
3780 # Draw line with colour
3782 def cv_draw_line( p0
, p1
, colour
):
3784 global cv_view_verts
, cv_view_colours
3786 cv_view_verts
+= [p0
,p1
]
3787 cv_view_colours
+= [colour
, colour
]
3791 # Draw line with colour(s)
3793 def cv_draw_line2( p0
, p1
, c0
, c1
):
3795 global cv_view_verts
, cv_view_colours
3797 cv_view_verts
+= [p0
,p1
]
3798 cv_view_colours
+= [c0
,c1
]
3804 def cv_tangent_basis( n
, tx
, ty
):
3806 if abs( n
[0] ) >= 0.57735027:#{
3825 # Draw coloured arrow
3827 def cv_draw_arrow( p0
, p1
, c0
, size
=0.25, outline
=True ):
3829 global cv_view_verts
, cv_view_colours
3835 tx
= Vector((1,0,0))
3836 ty
= Vector((1,0,0))
3837 cv_tangent_basis( n
, tx
, ty
)
3843 gpu
.state
.line_width_set(1.0)
3846 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3847 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3851 gpu
.state
.line_width_set(3.0)
3852 cv_view_verts
+= [p0
,p1
,midpt
+(tx
-n
)*size
,midpt
,midpt
+(-tx
-n
)*size
,midpt
]
3854 cv_view_colours
+= [b0
,b0
,b0
,b0
,b0
,b0
]
3856 gpu
.state
.line_width_set(2.0)
3860 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3862 global cv_view_verts
, cv_view_colours
3864 for i
in range(dots
):#{
3868 p2
= p0
*(1.0-t0
)+p1
*t0
3869 p3
= p0
*(1.0-t1
)+p1
*t1
3871 cv_view_verts
+= [p2
,p3
]
3872 cv_view_colours
+= [c0
,c0
]
3877 # Drawhandles of a bezier control point
3879 def cv_draw_bhandle( obj
, direction
, colour
):
3881 global cv_view_verts
, cv_view_colours
3884 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3886 cv_view_verts
+= [p0
]
3887 cv_view_verts
+= [h0
]
3888 cv_view_colours
+= [colour
,colour
]
3892 # Draw a bezier curve (at fixed resolution 10)
3894 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3896 global cv_view_verts
, cv_view_colours
3899 for i
in range(10):#{
3905 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3907 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3908 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3909 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3916 # I think this one extends the handles of the bezier otwards......
3918 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3920 global cv_view_course_i
3922 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3924 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3925 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3926 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3927 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3929 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3933 # Flush the lines buffers. This is called often because god help you if you want
3934 # to do fixed, fast buffers in this catastrophic programming language.
3936 def cv_draw_lines():
3938 global cv_view_shader
, cv_view_verts
, cv_view_colours
3940 if len(cv_view_verts
) < 2:
3943 lines
= batch_for_shader(\
3944 cv_view_shader
, 'LINES', \
3945 { "pos":cv_view_verts
, "color":cv_view_colours
})
3947 if bpy
.context
.scene
.SR_data
.gizmos
:
3948 lines
.draw( cv_view_shader
)
3951 cv_view_colours
= []
3954 # I dont remember what this does exactly
3956 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3958 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3961 # Semi circle to show the limit. and some lines
3963 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3965 global cv_view_verts
, cv_view_colours
3970 for x
in range(16):#{
3973 a0
= amin
*(1.0-t0
)+amax
*t0
3974 a1
= amin
*(1.0-t1
)+amax
*t1
3976 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3977 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3979 p0
=obj
.matrix_world
@ p0
3980 p1
=obj
.matrix_world
@ p1
3981 cv_view_verts
+= [p0
,p1
]
3982 cv_view_colours
+= [colour
,colour
]
3985 cv_view_verts
+= [p0
,center
]
3986 cv_view_colours
+= [colour
,colour
]
3989 cv_view_verts
+= [p1
,center
]
3990 cv_view_colours
+= [colour
,colour
]
3994 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
3995 cv_view_colours
+= [colour
,colour
]
4000 # Cone and twist limit
4002 def draw_cone_twist( center
, vx
, vy
, va
):
4004 global cv_view_verts
, cv_view_colours
4005 axis
= vy
.cross( vx
)
4010 cv_view_verts
+= [center
, center
+va
*size
]
4011 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
4013 for x
in range(32):#{
4014 t0
= (x
/32) * math
.tau
4015 t1
= ((x
+1)/32) * math
.tau
4022 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
4023 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
4025 col0
= ( abs(c0
), abs(s0
), 0.0 )
4026 col1
= ( abs(c1
), abs(s1
), 0.0 )
4028 cv_view_verts
+= [center
, p0
, p0
, p1
]
4029 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
4035 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
4037 def draw_skeleton_helpers( obj
):
4039 global cv_view_verts
, cv_view_colours
4041 if obj
.data
.pose_position
!= 'REST':#{
4045 for bone
in obj
.data
.bones
:#{
4047 a
= Vector((bone
.SR_data
.collider_min
[0],
4048 bone
.SR_data
.collider_min
[1],
4049 bone
.SR_data
.collider_min
[2]))
4050 b
= Vector((bone
.SR_data
.collider_max
[0],
4051 bone
.SR_data
.collider_max
[1],
4052 bone
.SR_data
.collider_max
[2]))
4054 if bone
.SR_data
.collider
== '1':#{
4056 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
4057 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
4058 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
4059 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
4060 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
4061 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
4062 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
4063 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
4065 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4066 (0,4),(1,5),(2,6),(3,7)]
4072 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4073 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4074 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
4077 elif bone
.SR_data
.collider
== '2':#{
4082 for i
in range(3):#{
4083 if abs(v0
[i
]) > largest
:#{
4084 largest
= abs(v0
[i
])
4089 v1
= Vector((0,0,0))
4090 v1
[major_axis
] = 1.0
4092 tx
= Vector((0,0,0))
4093 ty
= Vector((0,0,0))
4095 cv_tangent_basis( v1
, tx
, ty
)
4096 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
4097 l
= v0
[ major_axis
] - r
*2
4099 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
4100 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
4102 colour
= [0.2,0.2,0.2]
4103 colour
[major_axis
] = 0.5
4105 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
4106 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
4107 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
4108 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
4109 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
4110 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
4116 center
= obj
.matrix_world
@ c
4117 if bone
.SR_data
.cone_constraint
:#{
4118 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
4119 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
4120 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
4121 draw_cone_twist( center
, vx
, vy
, va
)
4126 def cv_draw_wireframe( mdl
, points
, colour
):#{
4127 for i
in range(len(points
)//2):#{
4128 p0
= mdl
@points[i
*2+0]
4129 p1
= mdl
@points[i
*2+1]
4130 cv_draw_line( p0
, p1
, colour
)
4134 def cv_ent_gate( obj
):
4136 global cv_view_verts
, cv_view_colours
4138 if obj
.type != 'MESH': return
4140 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
4141 data
= obj
.SR_data
.ent_gate
[0]
4142 dims
= mesh_data
.dimensions
4145 c
= Vector((0,0,dims
[2]))
4147 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
4148 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
4149 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
4150 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
4151 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
4152 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
4153 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
4154 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
4155 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
4157 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
4159 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
4161 p0
= r3d
.view_matrix
.inverted().translation
4162 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
4163 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
4165 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
4171 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4172 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4173 cv_view_colours
+= [cc
,cc
]
4177 if data
.target
!= None:
4178 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
4181 def cv_ent_volume( obj
):
4183 global cv_view_verts
, cv_view_colours
4185 data
= obj
.SR_data
.ent_volume
[0]
4187 if data
.subtype
== '0':#{
4188 cv_draw_ucube( obj
.matrix_world
, (0,1,0), Vector((0.99,0.99,0.99)) )
4191 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4194 elif data
.subtype
== '1':#{
4195 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
4198 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4203 def dijkstra( graph
, start_node
, target_node
):
4205 unvisited
= [_
for _
in graph
]
4210 shortest_path
[n
] = 9999999.999999
4211 shortest_path
[start_node
] = 0
4214 current_min_node
= None
4215 for n
in unvisited
:#{
4216 if current_min_node
== None:
4217 current_min_node
= n
4218 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
4219 current_min_node
= n
4222 for branch
in graph
[current_min_node
]:#{
4223 tentative_value
= shortest_path
[current_min_node
]
4224 tentative_value
+= graph
[current_min_node
][branch
]
4225 if tentative_value
< shortest_path
[branch
]:#{
4226 shortest_path
[branch
] = tentative_value
4227 previous_nodes
[branch
] = current_min_node
4231 unvisited
.remove(current_min_node
)
4236 while node
!= start_node
:#{
4239 if node
not in previous_nodes
: return None
4240 node
= previous_nodes
[node
]
4243 # Add the start node manually
4244 path
.append(start_node
)
4250 def __init__(_
,points
,graph
,subsections
):#{
4253 _
.subsections
= subsections
4257 def create_node_graph( curves
, gates
):
4259 # add endpoints of curves
4266 for c
in range(len(curves
)):#{
4267 for s
in range(len(curves
[c
].data
.splines
)):#{
4268 spline
= curves
[c
].data
.splines
[s
]
4269 l
= len(spline
.points
)
4272 dist
= round(spline
.calc_length(),2)
4275 ib
= point_count
+l
-1
4277 graph
[ia
] = { ib
: dist
}
4278 graph
[ib
] = { ia
: dist
}
4280 for i
in range(len(spline
.points
)):#{
4281 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
4282 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
4287 if i
== 0: previous
= -1
4288 if i
== len(spline
.points
)-1: proxima
= -1
4290 subsections
.append((spline_count
,previous
,proxima
))
4299 graph_keys
= list(graph
)
4300 for i
in range(len(graph_keys
)-1):#{
4301 for j
in range(i
+1, len(graph_keys
)):#{
4302 if i
%2==0 and i
+1==j
: continue
4306 pi
= route_points
[ni
]
4307 pj
= route_points
[nj
]
4309 dist
= round((pj
-pi
).magnitude
,2)
4312 graph
[ni
][nj
] = dist
4313 graph
[nj
][ni
] = dist
4318 # add and link gates( by name )
4319 for gate
in gates
:#{
4320 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
4321 if gate
.SR_data
.ent_gate
[0].target
:
4324 graph
[ gate
.name
] = {}
4326 for i
in range(len(graph_keys
)):#{
4328 pi
= route_points
[ni
]
4330 v0
= pi
-gate
.location
4331 if v0
.dot(v1
) < 0.0: continue
4333 dist
= round(v0
.magnitude
,2)
4336 graph
[ gate
.name
][ ni
] = dist
4337 graph
[ ni
][ gate
.name
] = dist
4342 return dij_graph(route_points
,graph
,subsections
)
4345 def solve_graph( dij
, start
, end
):
4347 path
= dijkstra( dij
.graph
, end
, start
)
4351 for sj
in range(1,len(path
)-2):#{
4354 map0
= dij
.subsections
[i0
]
4355 map1
= dij
.subsections
[i1
]
4357 if map0
[0] == map1
[0]:#{
4358 if map0
[1] == -1: direction
= 2
4363 map0
= dij
.subsections
[i0
]
4364 i1
= map0
[direction
]
4378 full
.append( path
[-2] )
4383 def cv_draw_route( route
, dij
):
4385 pole
= Vector((0.2,0.2,10))
4386 hat
= Vector((1,8,0.2))
4387 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
4388 route
.SR_data
.ent_route
[0].colour
[1],
4389 route
.SR_data
.ent_route
[0].colour
[2])
4391 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
4392 Vector((0,-6.5,5.5)))
4393 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
4394 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
4395 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
4396 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
4398 checkpoints
= route
.SR_data
.ent_route
[0].gates
4400 for i
in range(len(checkpoints
)):#{
4401 gi
= checkpoints
[i
].target
4402 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
4405 dest
= gi
.SR_data
.ent_gate
[0].target
4407 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
4411 if gi
==gj
: continue # error?
4412 if not gi
or not gj
: continue
4414 path
= solve_graph( dij
, gi
.name
, gj
.name
)
4417 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5,False)
4418 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5,False)
4419 for j
in range(len(path
)-1):#{
4422 o0
= dij
.points
[ i0
]
4423 o1
= dij
.points
[ i1
]
4424 cv_draw_arrow(o0
,o1
,cc
,1.5,False)
4428 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
4434 global cv_view_shader
4435 global cv_view_verts
4436 global cv_view_colours
4437 global cv_view_course_i
4439 cv_view_course_i
= 0
4441 cv_view_colours
= []
4443 cv_view_shader
.bind()
4444 gpu
.state
.depth_mask_set(True)
4445 gpu
.state
.line_width_set(2.0)
4446 gpu
.state
.face_culling_set('BACK')
4447 gpu
.state
.depth_test_set('LESS')
4448 gpu
.state
.blend_set('NONE')
4454 for obj
in bpy
.context
.collection
.objects
:#{
4455 if obj
.type == 'ARMATURE':#{
4456 if obj
.data
.pose_position
== 'REST':
4457 draw_skeleton_helpers( obj
)
4460 ent_type
= obj_ent_type( obj
)
4462 if ent_type
== 'ent_gate':#{
4464 route_gates
+= [obj
]
4466 elif ent_type
== 'ent_route_node':#{
4467 if obj
.type == 'CURVE':#{
4468 route_curves
+= [obj
]
4471 elif ent_type
== 'ent_route':
4473 elif ent_type
== 'ent_volume':#{
4474 cv_ent_volume( obj
)
4476 elif ent_type
== 'ent_objective':#{
4477 data
= obj
.SR_data
.ent_objective
[0]
4479 cv_draw_arrow( obj
.location
, data
.proxima
.location
, (1,0.6,0.2) )
4482 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4484 elif ent_type
== 'ent_relay':#{
4485 data
= obj
.SR_data
.ent_relay
[0]
4487 cv_draw_arrow( obj
.location
, data
.target0
.location
, (1,1,1) )
4489 cv_draw_arrow( obj
.location
, data
.target1
.location
, (1,1,1) )
4491 cv_draw_arrow( obj
.location
, data
.target2
.location
, (1,1,1) )
4493 cv_draw_arrow( obj
.location
, data
.target3
.location
, (1,1,1) )
4495 elif ent_type
== 'ent_challenge':#{
4496 data
= obj
.SR_data
.ent_challenge
[0]
4498 cv_draw_arrow( obj
.location
, data
.target
.location
, (1,1,1) )
4500 cv_draw_arrow( obj
.location
, data
.reset
.location
, (0.9,0,0) )
4502 cv_draw_arrow( obj
.location
, data
.first
.location
, (1,0.6,0.2) )
4505 info_cu
= Vector((1.2,0.01,0.72))*0.5
4506 info_co
= Vector((0.0,0.0,0.72))*0.5
4507 cv_draw_ucube( obj
.matrix_world
, cc1
, info_cu
, info_co
)
4509 cv_draw_line_dotted( obj
.location
, data
.camera
.location
, (1,1,1))
4511 vs
= [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
4512 Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
4513 Vector(( 0.1,0.0,0.30))]
4514 for v
in range(len(vs
)):#{
4515 vs
[v
] = obj
.matrix_world
@ vs
[v
]
4518 cv_view_verts
+= [vs
[0],vs
[1],vs
[1],vs
[2],vs
[3],vs
[4]]
4519 cv_view_colours
+= [cc1
,cc1
,cc1
,cc1
,cc1
,cc1
]
4521 elif ent_type
== 'ent_audio':#{
4522 if obj
.SR_data
.ent_audio
[0].flag_3d
:
4523 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
4525 elif ent_type
== 'ent_font':#{
4526 data
= obj
.SR_data
.ent_font
[0]
4528 for i
in range(len(data
.variants
)):#{
4529 sub
= data
.variants
[i
].mesh
4530 if not sub
: continue
4532 for ch
in data
.glyphs
:#{
4533 mini
= (ch
.bounds
[0],ch
.bounds
[1])
4534 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
4535 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
4536 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
4537 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
4538 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
4540 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
4543 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
4544 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
4548 elif ent_type
== 'ent_glider':#{
4549 mesh
= [Vector((-1.13982, 0.137084, -0.026358)), \
4550 Vector(( 1.13982, 0.137084, -0.026358)), \
4551 Vector(( 0.0, 1.6, 1.0)), \
4552 Vector(( 0.0, -3.0, 1.0)), \
4553 Vector(( -3.45, -1.78, 0.9)), \
4554 Vector(( 0.0, 1.6, 1.0)), \
4555 Vector(( 3.45, -1.78, 0.9)), \
4556 Vector(( 0.0, 1.6, 1.0)), \
4557 Vector(( 3.45, -1.78, 0.9)), \
4558 Vector(( -3.45, -1.78, 0.9))]
4560 cv_draw_wireframe( obj
.matrix_world
, mesh
, (1,1,1) )
4562 elif ent_type
== 'ent_skateshop':#{
4563 data
= obj
.SR_data
.ent_skateshop
[0]
4564 display
= data
.mark_display
4565 info
= data
.mark_info
4567 if data
.tipo
== '0':#{
4572 rack
= data
.mark_rack
4574 rack_cu
= Vector((3.15,2.0,0.1))*0.5
4575 rack_co
= Vector((0.0,0.0,0.0))
4576 display_cu
= Vector((0.3,1.2,0.1))*0.5
4577 display_co
= Vector((0.0,0.0,0.1))*0.5
4578 info_cu
= Vector((1.2,0.01,0.3))*0.5
4579 info_co
= Vector((0.0,0.0,0.0))*0.5
4581 elif data
.tipo
== '1':#{
4585 display_cu
= Vector((0.4,0.4,2.0))*0.5
4586 display_co
= Vector((0.0,0.0,1.0))*0.5
4587 info_cu
= Vector((1.2,0.01,0.3))*0.5
4588 info_co
= Vector((0.0,0.0,0.0))*0.5
4590 elif data
.tipo
== '2':#{
4594 display_cu
= Vector((1.0,1.0,0.5))*0.5
4595 display_co
= Vector((0.0,0.0,0.5))*0.5
4596 info_cu
= Vector((1.2,0.01,0.3))*0.5
4597 info_co
= Vector((0.0,0.0,0.0))*0.5
4599 elif data
.tipo
== '3':#{
4604 elif data
.tipo
== '4':#{
4611 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
4613 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4615 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4617 elif ent_type
== 'ent_swspreview':#{
4619 data
= obj
.SR_data
.ent_swspreview
[0]
4620 display
= data
.mark_display
4621 display1
= data
.mark_display1
4622 display_cu
= Vector((0.3,1.2,0.1))*0.5
4623 display_co
= Vector((0.0,0.0,0.1))*0.5
4625 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4627 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4629 # elif ent_type == 'ent_list':#{
4630 # data = obj.SR_data.ent_list[0]
4631 # for child in data.entities:#{
4632 # if child.target:#{
4633 # cv_draw_arrow( obj.location, child.target.location, \
4638 elif ent_type
== 'ent_region':#{
4639 data
= obj
.SR_data
.ent_region
[0]
4641 cv_draw_arrow( obj
.location
, data
.target0
.location
, \
4645 elif ent_type
== 'ent_menuitem':#{
4646 for i
,col
in enumerate(obj
.users_collection
):#{
4647 colour32
= hash_djb2( col
.name
)
4648 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4649 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4650 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4652 vs
= [None for _
in range(8)]
4654 for j
in range(8):#{
4655 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4656 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4658 vs
[j
] = obj
.matrix_world
@ v0
4660 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4661 (0,4),(1,5),(2,6),(3,7)]
4665 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4666 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4667 cv_view_colours
+= [cc
,cc
]
4672 data
= obj
.SR_data
.ent_menuitem
[0]
4673 if data
.tipo
== '4':#{
4674 if data
.slider_minloc
and data
.slider_maxloc
:#{
4675 v0
= data
.slider_minloc
.location
4676 v1
= data
.slider_maxloc
.location
4677 cv_draw_line( v0
, v1
, cc
)
4681 colour32
= hash_djb2(obj
.name
)
4682 r
= ((colour32
) & 0xff) / 255.0
4683 g
= ((colour32
>>8 ) & 0xff) / 255.0
4684 b
= ((colour32
>>16) & 0xff) / 255.0
4686 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4691 if data
.tipo
!= '0':#{
4692 if data
.tipo
== '4':#{
4694 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4697 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4702 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4705 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4708 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4711 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4719 dij
= create_node_graph( route_curves
, route_gates
)
4721 #cv_draw_route_map( route_nodes )
4722 for route
in routes
:#{
4723 cv_draw_route( route
, dij
)
4729 def pos3d_to_2d( pos
):#{
4730 return view3d_utils
.location_3d_to_region_2d( \
4731 bpy
.context
.region
, \
4732 bpy
.context
.space_data
.region_3d
, pos
)
4735 def cv_draw_pixel():#{
4736 if not bpy
.context
.scene
.SR_data
.gizmos
: return
4738 blf
.color(0, 1.0,1.0,1.0,0.9)
4739 blf
.enable(0,blf
.SHADOW
)
4740 blf
.shadow(0,3,0.0,0.0,0.0,1.0)
4741 for obj
in bpy
.context
.collection
.objects
:#{
4742 ent_type
= obj_ent_type( obj
)
4744 if ent_type
!= 'none':#{
4745 co
= pos3d_to_2d( obj
.location
)
4748 blf
.position(0,co
[0],co
[1],0)
4749 blf
.draw(0,ent_type
)
4754 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4755 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4756 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4758 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4759 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4760 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4761 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4762 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4763 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4764 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4765 SR_OT_COPY_ENTITY_DATA
, \
4766 SR_OBJECT_ENT_VOLUME
, \
4767 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4768 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4769 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4770 SR_OBJECT_ENT_FONT_VARIANT
,
4771 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4772 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4773 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4774 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4775 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4776 SR_OBJECT_ENT_OBJECTIVE
,SR_OBJECT_ENT_CHALLENGE
,\
4777 SR_OBJECT_ENT_REGION
,\
4778 SR_OBJECT_ENT_RELAY
,SR_OBJECT_ENT_MINIWORLD
,\
4779 SR_OBJECT_ENT_LIST_ENTRY
, SR_UL_ENT_LIST
, SR_OBJECT_ENT_LIST
, \
4780 SR_OT_ENT_LIST_NEW_ITEM
, SR_OT_ENT_LIST_DEL_ITEM
,\
4781 SR_OBJECT_ENT_GLIDER
, SR_OBJECT_ENT_NPC
, \
4783 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4784 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4790 bpy
.utils
.register_class(c
)
4792 bpy
.types
.Scene
.SR_data
= \
4793 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4794 bpy
.types
.Collection
.SR_data
= \
4795 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4797 bpy
.types
.Object
.SR_data
= \
4798 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4799 bpy
.types
.Light
.SR_data
= \
4800 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4801 bpy
.types
.Bone
.SR_data
= \
4802 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4803 bpy
.types
.Mesh
.SR_data
= \
4804 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4805 bpy
.types
.Material
.SR_data
= \
4806 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4808 global cv_view_draw_handler
, cv_view_pixel_handler
4809 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4810 cv_draw
,(),'WINDOW','POST_VIEW')
4811 cv_view_pixel_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4812 cv_draw_pixel
,(),'WINDOW','POST_PIXEL')
4818 bpy
.utils
.unregister_class(c
)
4820 global cv_view_draw_handler
, cv_view_pixel_handler
4821 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4822 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_pixel_handler
,'WINDOW')