1 import bpy
, math
, gpu
, os
4 from mathutils
import *
5 from gpu_extras
.batch
import batch_for_shader
6 from bpy_extras
import mesh_utils
9 "name":"Skaterift .mdl exporter",
10 "author": "Harry Godden (hgn)",
17 "category":"Import/Export",
21 ('none', 'None', '', 0 ),
22 ('ent_gate', 'Gate', '', 1 ),
23 ('ent_spawn', 'Spawn Point', '', 2 ),
24 ('ent_route_node', 'Routing Path', '', 3 ),
25 ('ent_route', 'Skate Course', '', 4 ),
26 ('ent_water', 'Water Surface', '', 5 ),
27 ('ent_volume', 'Volume/Trigger', '', 6 ),
28 ('ent_audio', 'Audio', '', 7 ),
29 ('ent_marker', 'Marker', '', 8 ),
30 ('ent_font', 'Font', '', 9 ),
31 ('ent_font_variant', 'Font:Variant', '', 10 ),
32 ('ent_traffic', 'Traffic Model', '', 11 ),
33 ('ent_skateshop', 'Skate Shop', '', 12 ),
34 ('ent_camera', 'Camera', '', 13 ),
35 ('ent_swspreview', 'Workshop Preview', '', 14 ),
36 ('ent_menuitem', 'Menu Item', '', 15 ),
37 ('ent_worldinfo', 'World Info', '', 16 ),
38 ('ent_ccmd', 'CCmd', '', 17 )
41 def get_entity_enum_id( alias
):
43 for et
in sr_entity_list
:#{
52 class mdl_vert(Structure
): # 48 bytes. Quite large. Could compress
53 #{ # the normals and uvs to i16s. Not an
54 _pack_
= 1 # real issue, yet.
55 _fields_
= [("co",c_float
*3),
59 ("weights",c_uint16
*4),
63 class mdl_transform(Structure
):
65 _fields_
= [("co",c_float
*3),
70 class mdl_submesh(Structure
):
72 _fields_
= [("indice_start",c_uint32
),
73 ("indice_count",c_uint32
),
74 ("vertex_start",c_uint32
),
75 ("vertex_count",c_uint32
),
76 ("bbx",(c_float
*3)*2),
77 ("material_id",c_uint16
), # index into the material array
81 class mdl_material(Structure
):
83 _fields_
= [("pstr_name",c_uint32
),
86 ("surface_prop",c_uint32
),
88 ("colour1",c_float
*4),
89 ("tex_diffuse",c_uint32
),
90 ("tex_none0",c_uint32
),
91 ("tex_none1",c_uint32
)]
94 class mdl_bone(Structure
):
96 _fields_
= [("co",c_float
*3),("end",c_float
*3),
98 ("collider",c_uint32
),
99 ("ik_target",c_uint32
),
100 ("ik_pole",c_uint32
),
102 ("pstr_name",c_uint32
),
103 ("hitbox",(c_float
*3)*2),
104 ("conevx",c_float
*3),("conevy",c_float
*3),("coneva",c_float
*3),
108 class mdl_armature(Structure
):
110 _fields_
= [("transform",mdl_transform
),
111 ("bone_start",c_uint32
),
112 ("bone_count",c_uint32
),
113 ("anim_start",c_uint32
),
114 ("anim_count",c_uint32
)]
117 class mdl_animation(Structure
):
119 _fields_
= [("pstr_name",c_uint32
),
122 ("keyframe_start",c_uint32
)]
125 class mdl_mesh(Structure
):
127 _fields_
= [("transform",mdl_transform
),
128 ("submesh_start",c_uint32
),
129 ("submesh_count",c_uint32
),
130 ("pstr_name",c_uint32
),
131 ("entity_id",c_uint32
),
132 ("armature_id",c_uint32
)]
135 class mdl_file(Structure
):
137 _fields_
= [("path",c_uint32
),
138 ("pack_offset",c_uint32
),
139 ("pack_size",c_uint32
)]
142 class mdl_texture(Structure
):
144 _fields_
= [("file",mdl_file
),
148 class mdl_array(Structure
):
150 _fields_
= [("file_offset",c_uint32
),
151 ("item_count",c_uint32
),
152 ("item_size",c_uint32
),
156 class mdl_header(Structure
):
158 _fields_
= [("version",c_uint32
),
159 ("arrays",mdl_array
)]
162 class ent_spawn(Structure
):
164 _fields_
= [("transform",mdl_transform
),
165 ("pstr_name",c_uint32
)]
168 class ent_light(Structure
):
170 _fields_
= [("transform",mdl_transform
),
171 ("daytime",c_uint32
),
173 ("colour",c_float
*4),
176 ("inverse_world",(c_float
*3)*4), # Runtime
177 ("angle_sin_cos",(c_float
*2))] # Runtime
180 class version_refcount_union(Union
):
182 _fields_
= [("timing_version",c_uint32
),
183 ("ref_count",c_uint8
)]
186 class ent_gate(Structure
):
188 _fields_
= [("type",c_uint32
),
189 ("target", c_uint32
),
191 ("dimensions", c_float
*3),
192 ("co", (c_float
*3)*2),
193 ("q", (c_float
*4)*2),
194 ("to_world",(c_float
*3)*4),
195 ("transport",(c_float
*3)*4),
196 ("_anonymous_union",version_refcount_union
),
197 ("timing_time",c_double
),
198 ("routes",c_uint16
*4),
199 ("route_count",c_uint8
)]
202 class ent_route_node(Structure
):
204 _fields_
= [("co",c_float
*3),
205 ("ref_count",c_uint8
),
206 ("ref_total",c_uint8
)]
209 class ent_path_index(Structure
):
211 _fields_
= [("index",c_uint16
)]
214 class vg_audio_clip(Structure
):
216 _fields_
= [("path",c_uint64
),
222 class union_file_audio_clip(Union
):
224 _fields_
= [("file",mdl_file
),
225 ("reserved",vg_audio_clip
)]
228 class ent_audio_clip(Structure
):
230 _fields_
= [("_anon",union_file_audio_clip
),
231 ("probability",c_float
)]
234 class ent_checkpoint(Structure
):
236 _fields_
= [("gate_index",c_uint16
),
237 ("path_start",c_uint16
),
238 ("path_count",c_uint16
)]
241 class ent_route(Structure
):
243 _fields_
= [("transform",mdl_transform
),
244 ("pstr_name",c_uint32
),
245 ("checkpoints_start",c_uint16
),
246 ("checkpoints_count",c_uint16
),
247 ("colour",c_float
*4),
248 ("active",c_uint32
), #runtime
250 ("board_transform",(c_float
*3)*4),
252 ("latest_pass",c_double
)]
255 class ent_water(Structure
):
257 _fields_
= [("transform",mdl_transform
),
258 ("max_dist",c_float
),
259 ("reserved0",c_uint32
),
260 ("reserved1",c_uint32
)]
263 class volume_trigger(Structure
):
265 _fields_
= [("event",c_uint32
),
269 class volume_particles(Structure
):
271 _fields_
= [("blank",c_uint32
),
275 class volume_union(Union
):
277 _fields_
= [("trigger",volume_trigger
),
278 ("particles",volume_particles
)]
281 class ent_volume(Structure
):
283 _fields_
= [("transform",mdl_transform
),
284 ("to_world",(c_float
*3)*4),
285 ("to_local",(c_float
*3)*4),
288 ("_anon",volume_union
)]
291 class ent_audio(Structure
):
293 _fields_
= [("transform",mdl_transform
),
295 ("clip_start",c_uint32
),
296 ("clip_count",c_uint32
),
298 ("crossfade",c_float
),
299 ("channel_behaviour",c_uint32
),
301 ("probability_curve",c_uint32
),
302 ("max_channels",c_uint32
)]
305 class ent_marker(Structure
):
307 _fields_
= [("transform",mdl_transform
),
311 class ent_glyph(Structure
):
313 _fields_
= [("size",c_float
*2),
314 ("indice_start",c_uint32
),
315 ("indice_count",c_uint32
)]
318 class ent_font_variant(Structure
):
320 _fields_
= [("name",c_uint32
),
321 ("material_id",c_uint32
)]
324 class ent_font(Structure
):
326 _fields_
= [("alias",c_uint32
),
327 ("variant_start",c_uint32
),
328 ("variant_count",c_uint32
),
329 ("glyph_start",c_uint32
),
330 ("glyph_count",c_uint32
),
331 ("glyph_utf32_base",c_uint32
)]
334 class ent_traffic(Structure
):
336 _fields_
= [("transform",mdl_transform
),
337 ("submesh_start",c_uint32
),
338 ("submesh_count",c_uint32
),
339 ("start_node",c_uint32
),
340 ("node_count",c_uint32
),
347 # ---------------------------------------------------------------
348 class ent_skateshop_characters(Structure
):
350 _fields_
= [("id_display",c_uint32
),
351 ("id_info",c_uint32
)]
353 class ent_skateshop_boards(Structure
):
355 _fields_
= [("id_display",c_uint32
),
356 ("id_info",c_uint32
),
357 ("id_rack",c_uint32
)]
359 class ent_skateshop_worlds(Structure
):
361 _fields_
= [("id_display",c_uint32
),
362 ("id_info",c_uint32
)]
364 class ent_skateshop_anon_union(Union
):
366 _fields_
= [("boards",ent_skateshop_boards
),
367 ("character",ent_skateshop_characters
),
368 ("worlds",ent_skateshop_worlds
)]
370 class ent_skateshop(Structure
):
372 _fields_
= [("transform",mdl_transform
), ("type",c_uint32
),
373 ("id_camera",c_uint32
),
374 ("_anonymous_union",ent_skateshop_anon_union
)]
377 class ent_swspreview(Structure
):
379 _fields_
= [("id_camera",c_uint32
),
380 ("id_display",c_uint32
),
381 ("id_display1",c_uint32
)]
385 # -----------------------------------------------------------------
386 class ent_menuitem_slider(Structure
):
388 _fields_
= [("id_min",c_uint32
),
390 ("id_handle",c_uint32
),
391 ("pstr_data",c_uint32
)]
393 class ent_menuitem_button(Structure
):
395 _fields_
= [("pstr",c_uint32
)]
397 class ent_menuitem_checkmark(Structure
):
399 _fields_
= [("id_check",c_uint32
),
400 ("pstr_data",c_uint32
),
401 ("offset",c_float
*3)]
403 class ent_menuitem_page(Structure
):
405 _fields_
= [("pstr_name",c_uint32
),
406 ("id_entrypoint",c_uint32
),
407 ("id_viewpoint",c_uint32
)]
409 class ent_menuitem_anon_union(Union
):
411 _fields_
= [("slider",ent_menuitem_slider
),
412 ("button",ent_menuitem_button
),
413 ("checkmark",ent_menuitem_checkmark
),
414 ("page",ent_menuitem_page
)]
416 class ent_menuitem(Structure
):
418 _fields_
= [("type",c_uint32
), ("groups",c_uint32
),
419 ("id_links",c_uint32
*4),
420 ("factive",c_float
), ("fvisible",c_float
),
421 #-- TODO: Refactor this into a simple mesh structure
422 ("transform",mdl_transform
),
423 ("submesh_start",c_uint32
),("submesh_count",c_uint32
),
426 ("_anonymous_union", ent_menuitem_anon_union
)]
429 class ent_camera(Structure
):
431 _fields_
= [("transform",mdl_transform
),
435 class ent_worldinfo(Structure
):
437 _fields_
= [("pstr_name",c_uint32
),
438 ("pstr_author",c_uint32
), # unused
439 ("pstr_desc",c_uint32
), # unused
440 ("timezone",c_float
)]
443 class ent_ccmd(Structure
):
445 _fields_
= [("pstr_command",c_uint32
)]
448 def obj_ent_type( obj
):
450 if obj
.type == 'ARMATURE': return 'mdl_armature'
451 elif obj
.type == 'LIGHT': return 'ent_light'
452 elif obj
.type == 'CAMERA': return 'ent_camera'
453 else: return obj
.SR_data
.ent_type
456 def sr_filter_ent_type( obj
, ent_types
):
458 if obj
== bpy
.context
.active_object
: return False
460 for c0
in obj
.users_collection
:#{
461 for c1
in bpy
.context
.active_object
.users_collection
:#{
463 return obj_ent_type( obj
) in ent_types
471 def compile_obj_transform( obj
, transform
):
473 co
= obj
.matrix_world
@ Vector((0,0,0))
475 # This was changed from matrix_local on 09.05.23
476 q
= obj
.matrix_world
.to_quaternion()
481 transform
.co
[0] = co
[0]
482 transform
.co
[1] = co
[2]
483 transform
.co
[2] = -co
[1]
484 transform
.q
[0] = q
[1]
485 transform
.q
[1] = q
[3]
486 transform
.q
[2] = -q
[2]
487 transform
.q
[3] = q
[0]
488 transform
.s
[0] = s
[0]
489 transform
.s
[1] = s
[2]
490 transform
.s
[2] = s
[1]
493 def int_align_to( v
, align
):
495 while(v
%align
)!=0: v
+= 1
499 def bytearray_align_to( buffer, align
, w
=b
'\xaa' ):
501 while (len(buffer) % align
) != 0: buffer.extend(w
)
505 def bytearray_print_hex( s
, w
=16 ):
507 for r
in range((len(s
)+(w
-1))//w
):#{
509 i1
=min((r
+1)*w
,len(s
))
510 print( F
'{r*w:06x}| \x1B[31m', end
='')
511 print( F
"{' '.join('{:02x}'.format(x) for x in s[i0:i1]):<48}",end
='' )
512 print( "\x1B[0m", end
='')
513 print( ''.join(chr(x
) if (x
>=33 and x
<=126) else '.' for x
in s
[i0
:i1
] ) )
517 def sr_compile_string( s
):
519 if s
in sr_compile
.string_cache
: return sr_compile
.string_cache
[s
]
521 index
= len( sr_compile
.string_data
)
522 sr_compile
.string_cache
[s
] = index
523 sr_compile
.string_data
.extend( c_uint32(hash_djb2(s
)) )
524 sr_compile
.string_data
.extend( s
.encode('utf-8') )
525 sr_compile
.string_data
.extend( b
'\0' )
527 bytearray_align_to( sr_compile
.string_data
, 4 )
531 def material_tex_image(v
):
541 cxr_graph_mapping
= \
543 # Default shader setup
550 "image": "tex_diffuse"
554 "A": material_tex_image("tex_diffuse"),
555 "B": material_tex_image("tex_decal")
562 "Color": material_tex_image("tex_normal")
568 "Color": material_tex_image("tex_diffuse")
572 # https://harrygodden.com/git/?p=convexer.git;a=blob;f=__init__.py;#l1164
574 def material_info(mat
):
578 # Using the cxr_graph_mapping as a reference, go through the shader
579 # graph and gather all $props from it.
581 def _graph_read( node_def
, node
=None, depth
=0 ):#{
588 _graph_read
.extracted
= []
590 for node_idname
in node_def
:#{
591 for n
in mat
.node_tree
.nodes
:#{
592 if n
.name
== node_idname
:#{
593 node_def
= node_def
[node_idname
]
601 for link
in node_def
:#{
602 link_def
= node_def
[link
]
604 if isinstance( link_def
, dict ):#{
606 for x
in node
.inputs
:#{
607 if isinstance( x
, bpy
.types
.NodeSocketColor
):#{
615 if node_link
and node_link
.is_linked
:#{
616 # look for definitions for the connected node type
618 from_node
= node_link
.links
[0].from_node
620 node_name
= from_node
.name
.split('.')[0]
621 if node_name
in link_def
:#{
622 from_node_def
= link_def
[ node_name
]
624 _graph_read( from_node_def
, from_node
, depth
+1 )
628 if "default" in link_def
:#{
629 prop
= link_def
['default']
630 info
[prop
] = node_link
.default_value
636 info
[prop
] = getattr( node
, link
)
641 _graph_read( cxr_graph_mapping
)
647 decoded
= bytearray()
648 for i
in range(len(s
)//2):#{
649 c
= (ord(s
[i
*2+0])-0x41)
650 c |
= (ord(s
[i
*2+1])-0x41)<<4
651 decoded
.extend(bytearray(c_uint8(c
))) #??
656 def sr_pack_file( file, path
, data
):
658 file.path
= sr_compile_string( path
)
659 file.pack_offset
= len( sr_compile
.pack_data
)
660 file.pack_size
= len( data
)
662 sr_compile
.pack_data
.extend( data
)
663 bytearray_align_to( sr_compile
.pack_data
, 16 )
666 def sr_compile_texture( img
):
671 name
= os
.path
.splitext( img
.name
)[0]
673 if name
in sr_compile
.texture_cache
:
674 return sr_compile
.texture_cache
[name
]
676 texture_index
= (len(sr_compile
.texture_data
)//sizeof(mdl_texture
)) +1
681 if sr_compile
.pack_textures
:#{
682 filedata
= qoi_encode( img
)
683 sr_pack_file( tex
.file, name
, filedata
)
686 sr_compile
.texture_cache
[name
] = texture_index
687 sr_compile
.texture_data
.extend( bytearray(tex
) )
691 def sr_compile_material( mat
):
695 if mat
.name
in sr_compile
.material_cache
:
696 return sr_compile
.material_cache
[mat
.name
]
698 index
= (len(sr_compile
.material_data
)//sizeof(mdl_material
))+1
699 sr_compile
.material_cache
[mat
.name
] = index
702 m
.pstr_name
= sr_compile_string( mat
.name
)
705 if mat
.SR_data
.collision
:#{
706 flags |
= 0x2 # collision flag
707 if (mat
.SR_data
.shader
!= 'invisible') and \
708 (mat
.SR_data
.shader
!= 'boundary'):#{
709 if mat
.SR_data
.skate_surface
: flags |
= 0x1
710 if mat
.SR_data
.grow_grass
: flags |
= 0x4
711 if mat
.SR_data
.grind_surface
: flags |
= 0x8
712 if mat
.SR_data
.preview_visibile
: flags |
= 0x40
714 if mat
.SR_data
.shader
== 'invisible': flags |
= 0x10
715 if mat
.SR_data
.shader
== 'boundary': flags |
= (0x10|
0x20)
720 m
.surface_prop
= int(mat
.SR_data
.surface_prop
)
722 if mat
.SR_data
.shader
== 'standard': m
.shader
= 0
723 if mat
.SR_data
.shader
== 'standard_cutout': m
.shader
= 1
724 if mat
.SR_data
.shader
== 'terrain_blend':#{
727 m
.colour
[0] = pow( mat
.SR_data
.sand_colour
[0], 1.0/2.2 )
728 m
.colour
[1] = pow( mat
.SR_data
.sand_colour
[1], 1.0/2.2 )
729 m
.colour
[2] = pow( mat
.SR_data
.sand_colour
[2], 1.0/2.2 )
732 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
733 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
736 if mat
.SR_data
.shader
== 'vertex_blend':#{
739 m
.colour1
[0] = mat
.SR_data
.blend_offset
[0]
740 m
.colour1
[1] = mat
.SR_data
.blend_offset
[1]
743 if mat
.SR_data
.shader
== 'water':#{
746 m
.colour
[0] = pow( mat
.SR_data
.shore_colour
[0], 1.0/2.2 )
747 m
.colour
[1] = pow( mat
.SR_data
.shore_colour
[1], 1.0/2.2 )
748 m
.colour
[2] = pow( mat
.SR_data
.shore_colour
[2], 1.0/2.2 )
750 m
.colour1
[0] = pow( mat
.SR_data
.ocean_colour
[0], 1.0/2.2 )
751 m
.colour1
[1] = pow( mat
.SR_data
.ocean_colour
[1], 1.0/2.2 )
752 m
.colour1
[2] = pow( mat
.SR_data
.ocean_colour
[2], 1.0/2.2 )
756 if mat
.SR_data
.shader
== 'invisible':#{
760 if mat
.SR_data
.shader
== 'boundary':#{
764 inf
= material_info( mat
)
766 if mat
.SR_data
.shader
== 'standard' or \
767 mat
.SR_data
.shader
== 'standard_cutout' or \
768 mat
.SR_data
.shader
== 'terrain_blend' or \
769 mat
.SR_data
.shader
== 'vertex_blend':
771 if 'tex_diffuse' in inf
:
772 m
.tex_diffuse
= sr_compile_texture(inf
['tex_diffuse'])
775 sr_compile
.material_data
.extend( bytearray(m
) )
779 def sr_armature_bones( armature
):
781 def _recurse_bone( b
):
784 for c
in b
.children
: yield from _recurse_bone( c
)
787 for b
in armature
.data
.bones
:
789 yield from _recurse_bone( b
)
792 def sr_entity_id( obj
):
794 tipo
= get_entity_enum_id( obj_ent_type(obj
) )
795 index
= sr_compile
.entity_ids
[ obj
.name
]
797 return (tipo
&0xffff)<<16 |
(index
&0xffff)
800 # Returns submesh_start,count and armature_id
801 def sr_compile_mesh_internal( obj
):
810 for mod
in obj
.modifiers
:#{
811 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
812 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
815 can_use_cache
= False
818 if mod
.type == 'ARMATURE': #{
819 armature
= mod
.object
820 rig_weight_groups
= \
821 ['0 [ROOT]']+[_
.name
for _
in sr_armature_bones(mod
.object)]
822 armature_id
= sr_compile
.entity_ids
[armature
.name
]
824 POSE_OR_REST_CACHE
= armature
.data
.pose_position
825 armature
.data
.pose_position
= 'REST'
829 # Check the cache first
831 if can_use_cache
and (obj
.data
.name
in sr_compile
.mesh_cache
):#{
832 ref
= sr_compile
.mesh_cache
[obj
.data
.name
]
833 submesh_start
= ref
[0]
834 submesh_count
= ref
[1]
835 return (submesh_start
,submesh_count
,armature_id
)
838 # Compile a whole new mesh
840 submesh_start
= len(sr_compile
.submesh_data
)//sizeof(mdl_submesh
)
843 dgraph
= bpy
.context
.evaluated_depsgraph_get()
844 data
= obj
.evaluated_get(dgraph
).data
845 data
.calc_loop_triangles()
846 data
.calc_normals_split()
848 # Mesh is split into submeshes based on their material
850 mat_list
= data
.materials
if len(data
.materials
) > 0 else [None]
851 for material_id
, mat
in enumerate(mat_list
): #{
855 sm
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
856 sm
.vertex_start
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
859 sm
.material_id
= sr_compile_material( mat
)
861 INF
=99999999.99999999
867 # Keep a reference to very very very similar vertices
868 # i have no idea how to speed it up.
870 vertex_reference
= {}
872 # Write the vertex / indice data
874 for tri_index
, tri
in enumerate(data
.loop_triangles
):#{
875 if tri
.material_index
!= material_id
: continue
878 vert
= data
.vertices
[tri
.vertices
[j
]]
880 vi
= data
.loops
[li
].vertex_index
882 # Gather vertex information
885 norm
= data
.loops
[li
].normal
887 colour
= (255,255,255,255)
894 uv
= data
.uv_layers
.active
.data
[li
].uv
898 if data
.vertex_colors
:#{
899 colour
= data
.vertex_colors
.active
.data
[li
].color
900 colour
= (int(colour
[0]*255.0),\
901 int(colour
[1]*255.0),\
902 int(colour
[2]*255.0),\
903 int(colour
[3]*255.0))
906 # Weight groups: truncates to the 3 with the most influence. The
907 # fourth bone ID is never used by the shader so it
911 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
912 if obj
.vertex_groups
[_
.group
].name
in \
915 weight_groups
= sorted( src_groups
, key
= \
916 lambda a
: a
.weight
, reverse
=True )
918 for ml
in range(3):#{
919 if len(weight_groups
) > ml
:#{
920 g
= weight_groups
[ml
]
921 name
= obj
.vertex_groups
[g
.group
].name
924 groups
[ml
] = rig_weight_groups
.index(name
)
929 if len(weight_groups
) > 0:#{
930 inv_norm
= (1.0/tot
) * 65535.0
931 for ml
in range(3):#{
932 weights
[ml
] = int( weights
[ml
] * inv_norm
)
933 weights
[ml
] = min( weights
[ml
], 65535 )
934 weights
[ml
] = max( weights
[ml
], 0 )
939 li1
= tri
.loops
[(j
+1)%3]
940 vi1
= data
.loops
[li1
].vertex_index
941 e0
= data
.edges
[ data
.loops
[li
].edge_index
]
943 if e0
.use_freestyle_mark
and \
944 ((e0
.vertices
[0] == vi
and e0
.vertices
[1] == vi1
) or \
945 (e0
.vertices
[0] == vi1
and e0
.vertices
[1] == vi
)):
951 TOLERENCE
= float(10**4)
952 key
= (int(co
[0]*TOLERENCE
+0.5),
953 int(co
[1]*TOLERENCE
+0.5),
954 int(co
[2]*TOLERENCE
+0.5),
955 int(norm
[0]*TOLERENCE
+0.5),
956 int(norm
[1]*TOLERENCE
+0.5),
957 int(norm
[2]*TOLERENCE
+0.5),
958 int(uv
[0]*TOLERENCE
+0.5),
959 int(uv
[1]*TOLERENCE
+0.5),
960 colour
[0], # these guys are already quantized
973 if key
in vertex_reference
:
974 index
= vertex_reference
[key
]
976 index
= bytearray(c_uint32(sm
.vertex_count
))
979 vertex_reference
[key
] = index
989 v
.colour
[0] = colour
[0]
990 v
.colour
[1] = colour
[1]
991 v
.colour
[2] = colour
[2]
992 v
.colour
[3] = colour
[3]
993 v
.weights
[0] = weights
[0]
994 v
.weights
[1] = weights
[1]
995 v
.weights
[2] = weights
[2]
996 v
.weights
[3] = weights
[3]
997 v
.groups
[0] = groups
[0]
998 v
.groups
[1] = groups
[1]
999 v
.groups
[2] = groups
[2]
1000 v
.groups
[3] = groups
[3]
1002 for i
in range(3):#{
1003 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
1004 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
1007 sr_compile
.vertex_data
.extend(bytearray(v
))
1010 sm
.indice_count
+= 1
1011 sr_compile
.indice_data
.extend( index
)
1015 # Make sure bounding box isn't -inf -> inf if no vertices
1017 if sm
.vertex_count
== 0:
1022 # Add submesh to encoder
1024 sr_compile
.submesh_data
.extend( bytearray(sm
) )
1029 armature
.data
.pose_position
= POSE_OR_REST_CACHE
1032 # Save a reference to this mesh since we want to reuse the submesh indices
1034 sr_compile
.mesh_cache
[obj
.data
.name
]=(submesh_start
,submesh_count
)
1035 return (submesh_start
,submesh_count
,armature_id
)
1038 def sr_compile_mesh( obj
):
1041 compile_obj_transform(obj
, node
.transform
)
1042 node
.pstr_name
= sr_compile_string(obj
.name
)
1043 ent_type
= obj_ent_type( obj
)
1047 if ent_type
!= 'none':#{
1048 ent_id_lwr
= sr_compile
.entity_ids
[obj
.name
]
1049 ent_id_upr
= get_entity_enum_id( obj_ent_type(obj
) )
1050 node
.entity_id
= (ent_id_upr
<< 16) | ent_id_lwr
1053 node
.submesh_start
, node
.submesh_count
, node
.armature_id
= \
1054 sr_compile_mesh_internal( obj
)
1056 sr_compile
.mesh_data
.extend(bytearray(node
))
1059 def sr_compile_fonts( collection
):
1061 print( F
"[SR] Compiling fonts" )
1066 for obj
in collection
.all_objects
:#{
1067 if obj_ent_type(obj
) != 'ent_font': continue
1069 data
= obj
.SR_data
.ent_font
[0]
1072 font
.alias
= sr_compile_string( data
.alias
)
1073 font
.variant_start
= variant_count
1074 font
.variant_count
= 0
1075 font
.glyph_start
= glyph_count
1077 glyph_base
= data
.glyphs
[0].utf32
1078 glyph_range
= data
.glyphs
[-1].utf32
+1 - glyph_base
1080 font
.glyph_utf32_base
= glyph_base
1081 font
.glyph_count
= glyph_range
1083 for i
in range(len(data
.variants
)):#{
1084 data_var
= data
.variants
[i
]
1085 if not data_var
.mesh
: continue
1087 mesh
= data_var
.mesh
.data
1089 variant
= ent_font_variant()
1090 variant
.name
= sr_compile_string( data_var
.tipo
)
1092 # fonts (variants) only support one material each
1094 if len(mesh
.materials
) != 0:
1095 mat
= mesh
.materials
[0]
1096 variant
.material_id
= sr_compile_material( mat
)
1098 font
.variant_count
+= 1
1100 islands
= mesh_utils
.mesh_linked_triangles(mesh
)
1101 centroids
= [Vector((0,0)) for _
in range(len(islands
))]
1103 for j
in range(len(islands
)):#{
1104 for tri
in islands
[j
]:#{
1105 centroids
[j
].x
+= tri
.center
[0]
1106 centroids
[j
].y
+= tri
.center
[2]
1109 centroids
[j
] /= len(islands
[j
])
1112 for j
in range(glyph_range
):#{
1113 data_glyph
= data
.glyphs
[j
]
1115 glyph
.indice_start
= len(sr_compile
.indice_data
)//sizeof(c_uint32
)
1116 glyph
.indice_count
= 0
1117 glyph
.size
[0] = data_glyph
.bounds
[2]
1118 glyph
.size
[1] = data_glyph
.bounds
[3]
1120 vertex_reference
= {}
1122 for k
in range(len(islands
)):#{
1123 if centroids
[k
].x
< data_glyph
.bounds
[0] or \
1124 centroids
[k
].x
> data_glyph
.bounds
[0]+data_glyph
.bounds
[2] or\
1125 centroids
[k
].y
< data_glyph
.bounds
[1] or \
1126 centroids
[k
].y
> data_glyph
.bounds
[1]+data_glyph
.bounds
[3]:
1131 for l
in range(len(islands
[k
])):#{
1133 for m
in range(3):#{
1134 vert
= mesh
.vertices
[tri
.vertices
[m
]]
1136 vi
= mesh
.loops
[li
].vertex_index
1138 # Gather vertex information
1140 co
= [vert
.co
[_
] for _
in range(3)]
1141 co
[0] -= data_glyph
.bounds
[0]
1142 co
[2] -= data_glyph
.bounds
[1]
1143 norm
= mesh
.loops
[li
].normal
1145 if mesh
.uv_layers
: uv
= mesh
.uv_layers
.active
.data
[li
].uv
1147 TOLERENCE
= float(10**4)
1148 key
= (int(co
[0]*TOLERENCE
+0.5),
1149 int(co
[1]*TOLERENCE
+0.5),
1150 int(co
[2]*TOLERENCE
+0.5),
1151 int(norm
[0]*TOLERENCE
+0.5),
1152 int(norm
[1]*TOLERENCE
+0.5),
1153 int(norm
[2]*TOLERENCE
+0.5),
1154 int(uv
[0]*TOLERENCE
+0.5),
1155 int(uv
[1]*TOLERENCE
+0.5))
1157 if key
in vertex_reference
:
1158 index
= vertex_reference
[key
]
1160 vindex
= len(sr_compile
.vertex_data
)//sizeof(mdl_vert
)
1161 index
= bytearray(c_uint32(vindex
))
1162 vertex_reference
[key
] = index
1169 v
.norm
[2] = -norm
[1]
1173 sr_compile
.vertex_data
.extend(bytearray(v
))
1176 glyph
.indice_count
+= 1
1177 sr_compile
.indice_data
.extend( index
)
1181 sr_ent_push( glyph
)
1183 sr_ent_push( variant
)
1189 def sr_compile_menus( collection
):
1191 print( "[SR1] Compiling menus" )
1194 for obj
in collection
.all_objects
:#{
1195 if obj_ent_type(obj
) != 'ent_menuitem': continue
1196 obj_data
= obj
.SR_data
.ent_menuitem
[0]
1198 bitmask
= 0x00000000
1200 for col
in obj
.users_collection
:#{
1202 if name
not in groups
: groups
.append( name
)
1203 bitmask |
= (0x1 << groups
.index(name
))
1206 item
= ent_menuitem()
1207 item
.type = int( obj_data
.tipo
)
1208 item
.groups
= bitmask
1210 compile_obj_transform( obj
, item
.transform
)
1211 if obj
.type == 'MESH':#{
1212 item
.submesh_start
, item
.submesh_count
, _
= \
1213 sr_compile_mesh_internal( obj
)
1216 if item
.type == 1 or item
.type == 2:#{
1217 item_button
= item
._anonymous
_union
.button
1218 item_button
.pstr
= sr_compile_string( obj_data
.string
)
1220 elif item
.type == 3:#{
1221 item_checkmark
= item
._anonymous
_union
.checkmark
1222 item_checkmark
.pstr_data
= sr_compile_string( obj_data
.string
)
1223 item_checkmark
.id_check
= sr_entity_id( obj_data
.checkmark
)
1224 delta
= obj_data
.checkmark
.location
- obj
.location
1225 item_checkmark
.offset
[0] = delta
[0]
1226 item_checkmark
.offset
[1] = delta
[2]
1227 item_checkmark
.offset
[2] = -delta
[1]
1229 elif item
.type == 4:#{
1230 item_slider
= item
._anonymous
_union
.slider
1231 item_slider
.id_min
= sr_entity_id( obj_data
.slider_minloc
)
1232 item_slider
.id_max
= sr_entity_id( obj_data
.slider_maxloc
)
1233 item_slider
.id_handle
= sr_entity_id( obj_data
.slider_handle
)
1234 item_slider
.pstr_data
= sr_compile_string( obj_data
.string
)
1236 elif item
.type == 5:#{
1237 item_page
= item
._anonymous
_union
.page
1238 item_page
.pstr_name
= sr_compile_string( obj_data
.string
)
1239 item_page
.id_entrypoint
= sr_entity_id( obj_data
.newloc
)
1240 item_page
.id_viewpoint
= sr_entity_id( obj_data
.camera
)
1244 item
.id_links
[0] = sr_entity_id( obj_data
.link0
)
1246 item
.id_links
[1] = sr_entity_id( obj_data
.link1
)
1247 if item
.type != 4:#{
1249 item
.id_links
[2] = sr_entity_id( obj_data
.link2
)
1251 item
.id_links
[3] = sr_entity_id( obj_data
.link3
)
1258 def sr_compile_armature( obj
):
1260 node
= mdl_armature()
1261 node
.bone_start
= len(sr_compile
.bone_data
)//sizeof(mdl_bone
)
1263 node
.anim_start
= len(sr_compile
.anim_data
)//sizeof(mdl_animation
)
1266 bones
= [_
for _
in sr_armature_bones(obj
)]
1267 bones_names
= [None]+[_
.name
for _
in bones
]
1271 if b
.use_deform
: bone
.flags
= 0x1
1272 if b
.parent
: bone
.parent
= bones_names
.index(b
.parent
.name
)
1274 bone
.collider
= int(b
.SR_data
.collider
)
1276 if bone
.collider
>0:#{
1277 bone
.hitbox
[0][0] = b
.SR_data
.collider_min
[0]
1278 bone
.hitbox
[0][1] = b
.SR_data
.collider_min
[2]
1279 bone
.hitbox
[0][2] = -b
.SR_data
.collider_max
[1]
1280 bone
.hitbox
[1][0] = b
.SR_data
.collider_max
[0]
1281 bone
.hitbox
[1][1] = b
.SR_data
.collider_max
[2]
1282 bone
.hitbox
[1][2] = -b
.SR_data
.collider_min
[1]
1285 if b
.SR_data
.cone_constraint
:#{
1287 bone
.conevx
[0] = b
.SR_data
.conevx
[0]
1288 bone
.conevx
[1] = b
.SR_data
.conevx
[2]
1289 bone
.conevx
[2] = -b
.SR_data
.conevx
[1]
1290 bone
.conevy
[0] = b
.SR_data
.conevy
[0]
1291 bone
.conevy
[1] = b
.SR_data
.conevy
[2]
1292 bone
.conevy
[2] = -b
.SR_data
.conevy
[1]
1293 bone
.coneva
[0] = b
.SR_data
.coneva
[0]
1294 bone
.coneva
[1] = b
.SR_data
.coneva
[2]
1295 bone
.coneva
[2] = -b
.SR_data
.coneva
[1]
1296 bone
.conet
= b
.SR_data
.conet
1299 bone
.co
[0] = b
.head_local
[0]
1300 bone
.co
[1] = b
.head_local
[2]
1301 bone
.co
[2] = -b
.head_local
[1]
1302 bone
.end
[0] = b
.tail_local
[0] - bone
.co
[0]
1303 bone
.end
[1] = b
.tail_local
[2] - bone
.co
[1]
1304 bone
.end
[2] = -b
.tail_local
[1] - bone
.co
[2]
1305 bone
.pstr_name
= sr_compile_string( b
.name
)
1307 for c
in obj
.pose
.bones
[b
.name
].constraints
:#{
1308 if c
.type == 'IK':#{
1310 bone
.ik_target
= bones_names
.index(c
.subtarget
)
1311 bone
.ik_pole
= bones_names
.index(c
.pole_subtarget
)
1315 node
.bone_count
+= 1
1316 sr_compile
.bone_data
.extend(bytearray(bone
))
1321 if obj
.animation_data
and sr_compile
.pack_animations
: #{
1322 # So we can restore later
1324 previous_frame
= bpy
.context
.scene
.frame_current
1325 previous_action
= obj
.animation_data
.action
1326 POSE_OR_REST_CACHE
= obj
.data
.pose_position
1327 obj
.data
.pose_position
= 'POSE'
1329 for NLALayer
in obj
.animation_data
.nla_tracks
:#{
1330 for NLAStrip
in NLALayer
.strips
:#{
1333 for a
in bpy
.data
.actions
:#{
1334 if a
.name
== NLAStrip
.name
:#{
1335 obj
.animation_data
.action
= a
1340 # Clip to NLA settings
1342 anim_start
= int(NLAStrip
.action_frame_start
)
1343 anim_end
= int(NLAStrip
.action_frame_end
)
1347 anim
= mdl_animation()
1348 anim
.pstr_name
= sr_compile_string( NLAStrip
.action
.name
)
1350 anim
.keyframe_start
= len(sr_compile
.keyframe_data
)//\
1351 sizeof(mdl_transform
)
1352 anim
.length
= anim_end
-anim_start
1355 # Export the keyframes
1356 for frame
in range(anim_start
,anim_end
):#{
1357 bpy
.context
.scene
.frame_set(frame
)
1360 pb
= obj
.pose
.bones
[rb
.name
]
1362 # relative bone matrix
1363 if rb
.parent
is not None:#{
1364 offset_mtx
= rb
.parent
.matrix_local
1365 offset_mtx
= offset_mtx
.inverted_safe() @ \
1368 inv_parent
= pb
.parent
.matrix
@ offset_mtx
1369 inv_parent
.invert_safe()
1370 fpm
= inv_parent
@ pb
.matrix
1373 bone_mtx
= rb
.matrix
.to_4x4()
1374 local_inv
= rb
.matrix_local
.inverted_safe()
1375 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
1378 loc
, rot
, sca
= fpm
.decompose()
1381 lc_m
= pb
.matrix_channel
.to_3x3()
1382 if pb
.parent
is not None:#{
1383 smtx
= pb
.parent
.matrix_channel
.to_3x3()
1384 lc_m
= smtx
.inverted() @ lc_m
1386 rq
= lc_m
.to_quaternion()
1388 kf
= mdl_transform()
1399 sr_compile
.keyframe_data
.extend(bytearray(kf
))
1405 # Add to animation buffer
1407 sr_compile
.anim_data
.extend(bytearray(anim
))
1408 node
.anim_count
+= 1
1412 print( F
"[SR] | anim( {NLAStrip.action.name} )" )
1416 # Restore context to how it was before
1418 bpy
.context
.scene
.frame_set( previous_frame
)
1419 obj
.animation_data
.action
= previous_action
1420 obj
.data
.pose_position
= POSE_OR_REST_CACHE
1423 sr_compile
.armature_data
.extend(bytearray(node
))
1426 def sr_ent_push( struct
):
1428 clase
= type(struct
).__name
__
1430 if clase
not in sr_compile
.entity_data
:#{
1431 sr_compile
.entity_data
[ clase
] = bytearray()
1432 sr_compile
.entity_info
[ clase
] = { 'size': sizeof(struct
) }
1435 index
= len(sr_compile
.entity_data
[ clase
])//sizeof(struct
)
1436 sr_compile
.entity_data
[ clase
].extend( bytearray(struct
) )
1440 def sr_array_title( arr
, name
, count
, size
, offset
):
1442 for i
in range(len(name
)):#{
1443 arr
.name
[i
] = ord(name
[i
])
1445 arr
.file_offset
= offset
1446 arr
.item_count
= count
1447 arr
.item_size
= size
1454 picadillo
= (((picadillo
<< 5) + picadillo
) + ord(x
)) & 0xFFFFFFFF
1459 def sr_compile( collection
):
1461 print( F
"[SR] compiler begin ({collection.name}.mdl)" )
1464 sr_compile
.pack_textures
= collection
.SR_data
.pack_textures
1465 sr_compile
.pack_animations
= collection
.SR_data
.animations
1468 sr_compile
.string_cache
= {}
1469 sr_compile
.mesh_cache
= {}
1470 sr_compile
.material_cache
= {}
1471 sr_compile
.texture_cache
= {}
1474 sr_compile
.mesh_data
= bytearray()
1475 sr_compile
.submesh_data
= bytearray()
1476 sr_compile
.vertex_data
= bytearray()
1477 sr_compile
.indice_data
= bytearray()
1478 sr_compile
.bone_data
= bytearray()
1479 sr_compile
.material_data
= bytearray()
1480 sr_compile
.armature_data
= bytearray()
1481 sr_compile
.anim_data
= bytearray()
1482 sr_compile
.keyframe_data
= bytearray()
1483 sr_compile
.texture_data
= bytearray()
1485 # just bytes not structures
1486 sr_compile
.string_data
= bytearray()
1487 sr_compile
.pack_data
= bytearray()
1490 sr_compile
.entity_data
= {}
1491 sr_compile
.entity_info
= {}
1493 print( F
"[SR] assign entity ID's" )
1494 sr_compile
.entities
= {}
1495 sr_compile
.entity_ids
= {}
1498 # -------------------------------------------------------
1500 sr_compile_string( "null" )
1503 for obj
in collection
.all_objects
: #{
1504 if obj
.type == 'MESH':#{
1508 ent_type
= obj_ent_type( obj
)
1509 if ent_type
== 'none': continue
1511 if ent_type
not in sr_compile
.entities
: sr_compile
.entities
[ent_type
] = []
1512 sr_compile
.entity_ids
[obj
.name
] = len( sr_compile
.entities
[ent_type
] )
1513 sr_compile
.entities
[ent_type
] += [obj
]
1516 print( F
"[SR] Compiling geometry" )
1518 for obj
in collection
.all_objects
:#{
1519 if obj
.type == 'MESH':#{
1522 ent_type
= obj_ent_type( obj
)
1524 # entity ignore mesh list
1526 if ent_type
== 'ent_traffic': continue
1527 if ent_type
== 'ent_font': continue
1528 if ent_type
== 'ent_font_variant': continue
1529 if ent_type
== 'ent_menuitem': continue
1530 #--------------------------
1532 print( F
'[SR] {i: 3}/{mesh_count} {obj.name:<40}', end
='\r' )
1533 sr_compile_mesh( obj
)
1537 audio_clip_count
= 0
1539 for ent_type
, arr
in sr_compile
.entities
.items():#{
1540 print(F
"[SR] Compiling {len(arr)} {ent_type}{'s' if len(arr)>1 else ''}")
1542 for i
in range(len(arr
)):#{
1545 print( F
"[SR] {i+1: 3}/{len(arr)} {obj.name:<40} ",end
='\r' )
1547 if ent_type
== 'mdl_armature': sr_compile_armature(obj
)
1548 elif ent_type
== 'ent_light': #{
1550 compile_obj_transform( obj
, light
.transform
)
1551 light
.daytime
= obj
.data
.SR_data
.daytime
1552 if obj
.data
.type == 'POINT':#{
1555 elif obj
.data
.type == 'SPOT':#{
1557 light
.angle
= obj
.data
.spot_size
*0.5
1559 light
.range = obj
.data
.cutoff_distance
1560 light
.colour
[0] = obj
.data
.color
[0]
1561 light
.colour
[1] = obj
.data
.color
[1]
1562 light
.colour
[2] = obj
.data
.color
[2]
1563 light
.colour
[3] = obj
.data
.energy
1564 sr_ent_push( light
)
1566 elif ent_type
== 'ent_camera': #{
1568 compile_obj_transform( obj
, cam
.transform
)
1569 cam
.fov
= obj
.data
.angle
* 45.0
1572 elif ent_type
== 'ent_gate': #{
1574 obj_data
= obj
.SR_data
.ent_gate
[0]
1575 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
1577 if obj_data
.tipo
== 'default':#{
1578 if obj_data
.target
:#{
1579 gate
.target
= sr_compile
.entity_ids
[obj_data
.target
.name
]
1583 elif obj_data
.tipo
== 'nonlocal':#{
1585 gate
.key
= sr_compile_string(obj_data
.key
)
1590 gate
.dimensions
[0] = mesh_data
.dimensions
[0]
1591 gate
.dimensions
[1] = mesh_data
.dimensions
[1]
1592 gate
.dimensions
[2] = mesh_data
.dimensions
[2]
1594 q
= [obj
.matrix_local
.to_quaternion(), (0,0,0,1)]
1595 co
= [obj
.matrix_world
@ Vector((0,0,0)), (0,0,0)]
1597 if obj_data
.target
:#{
1598 q
[1] = obj_data
.target
.matrix_local
.to_quaternion()
1599 co
[1]= obj_data
.target
.matrix_world
@ Vector((0,0,0))
1604 for x
in range(2):#{
1605 gate
.co
[x
][0] = co
[x
][0]
1606 gate
.co
[x
][1] = co
[x
][2]
1607 gate
.co
[x
][2] = -co
[x
][1]
1608 gate
.q
[x
][0] = q
[x
][1]
1609 gate
.q
[x
][1] = q
[x
][3]
1610 gate
.q
[x
][2] = -q
[x
][2]
1611 gate
.q
[x
][3] = q
[x
][0]
1616 elif ent_type
== 'ent_spawn': #{
1618 compile_obj_transform( obj
, spawn
.transform
)
1619 obj_data
= obj
.SR_data
.ent_spawn
[0]
1620 spawn
.pstr_name
= sr_compile_string( obj_data
.alias
)
1621 sr_ent_push( spawn
)
1623 elif ent_type
== 'ent_water':#{
1625 compile_obj_transform( obj
, water
.transform
)
1626 water
.max_dist
= 0.0
1627 sr_ent_push( water
)
1629 elif ent_type
== 'ent_audio':#{
1630 obj_data
= obj
.SR_data
.ent_audio
[0]
1632 compile_obj_transform( obj
, audio
.transform
)
1633 audio
.clip_start
= audio_clip_count
1634 audio
.clip_count
= len(obj_data
.files
)
1635 audio_clip_count
+= audio
.clip_count
1636 audio
.max_channels
= obj_data
.max_channels
1637 audio
.volume
= obj_data
.volume
1640 # - allow/disable doppler
1641 # - channel group tags with random colours
1642 # - transition properties
1644 if obj_data
.flag_loop
: audio
.flags |
= 0x1
1645 if obj_data
.flag_nodoppler
: audio
.flags |
= 0x2
1646 if obj_data
.flag_3d
: audio
.flags |
= 0x4
1647 if obj_data
.flag_auto
: audio
.flags |
= 0x8
1648 if obj_data
.formato
== '0': audio
.flags |
= 0x000
1649 elif obj_data
.formato
== '1': audio
.flags |
= 0x400
1650 elif obj_data
.formato
== '2': audio
.flags |
= 0x1000
1652 audio
.channel_behaviour
= int(obj_data
.channel_behaviour
)
1653 if audio
.channel_behaviour
>= 1:#{
1654 audio
.group
= obj_data
.group
1656 if audio
.channel_behaviour
== 2:#{
1657 audio
.crossfade
= obj_data
.transition_duration
1659 audio
.probability_curve
= int(obj_data
.probability_curve
)
1661 for ci
in range(audio
.clip_count
):#{
1662 entry
= obj_data
.files
[ci
]
1663 clip
= ent_audio_clip()
1664 clip
.probability
= entry
.probability
1665 if obj_data
.formato
== '2':#{
1666 sr_pack_file( clip
._anon
.file, '', vg_str_bin(entry
.path
) )
1669 clip
._anon
.file.path
= sr_compile_string( entry
.path
)
1670 clip
._anon
.file.pack_offset
= 0
1671 clip
._anon
.file.pack_size
= 0
1675 sr_ent_push( audio
)
1677 elif ent_type
== 'ent_volume':#{
1678 obj_data
= obj
.SR_data
.ent_volume
[0]
1679 volume
= ent_volume()
1680 volume
.type = int(obj_data
.subtype
)
1681 compile_obj_transform( obj
, volume
.transform
)
1683 if obj_data
.target
:#{
1684 volume
.target
= sr_entity_id( obj_data
.target
)
1689 elif ent_type
== 'ent_marker':#{
1690 marker
= ent_marker()
1691 marker
.name
= sr_compile_string( obj
.SR_data
.ent_marker
[0].alias
)
1692 compile_obj_transform( obj
, marker
.transform
)
1695 elif ent_type
== 'ent_skateshop':#{
1696 skateshop
= ent_skateshop()
1697 obj_data
= obj
.SR_data
.ent_skateshop
[0]
1698 skateshop
.type = int(obj_data
.tipo
)
1699 if skateshop
.type == 0:#{
1700 boardshop
= skateshop
._anonymous
_union
.boards
1701 boardshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1702 boardshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1703 boardshop
.id_rack
= sr_entity_id( obj_data
.mark_rack
)
1705 elif skateshop
.type == 1:#{
1706 charshop
= skateshop
._anonymous
_union
.character
1707 charshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1708 charshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1710 elif skateshop
.type == 2:#{
1711 worldshop
= skateshop
._anonymous
_union
.worlds
1712 worldshop
.id_display
= sr_entity_id( obj_data
.mark_display
)
1713 worldshop
.id_info
= sr_entity_id( obj_data
.mark_info
)
1715 skateshop
.id_camera
= sr_entity_id( obj_data
.cam
)
1716 compile_obj_transform( obj
, skateshop
.transform
)
1717 sr_ent_push(skateshop
)
1719 elif ent_type
== 'ent_swspreview':#{
1720 workshop_preview
= ent_swspreview()
1721 obj_data
= obj
.SR_data
.ent_swspreview
[0]
1722 workshop_preview
.id_display
= sr_entity_id( obj_data
.mark_display
)
1723 workshop_preview
.id_display1
= sr_entity_id( obj_data
.mark_display1
)
1724 workshop_preview
.id_camera
= sr_entity_id( obj_data
.cam
)
1725 sr_ent_push( workshop_preview
)
1727 elif ent_type
== 'ent_worldinfo':#{
1728 worldinfo
= ent_worldinfo()
1729 obj_data
= obj
.SR_data
.ent_worldinfo
[0]
1730 worldinfo
.pstr_name
= sr_compile_string( obj_data
.name
)
1731 worldinfo
.pstr_author
= sr_compile_string( obj_data
.author
)
1732 worldinfo
.pstr_desc
= sr_compile_string( obj_data
.desc
)
1733 worldinfo
.timezone
= obj_data
.timezone
1734 sr_ent_push( worldinfo
)
1736 elif ent_type
== 'ent_ccmd':#{
1738 obj_data
= obj
.SR_data
.ent_ccmd
[0]
1739 ccmd
.pstr_command
= sr_compile_string( obj_data
.command
)
1745 sr_compile_menus( collection
)
1746 sr_compile_fonts( collection
)
1748 def _children( col
):#{
1750 for c
in col
.children
:#{
1751 yield from _children(c
)
1755 checkpoint_count
= 0
1756 pathindice_count
= 0
1759 for col
in _children(collection
):#{
1760 print( F
"Adding routes for subcollection: {col.name}" )
1766 for obj
in col
.objects
:#{
1767 if obj
.type == 'ARMATURE': pass
1769 ent_type
= obj_ent_type( obj
)
1771 if ent_type
== 'ent_gate':
1772 route_gates
+= [obj
]
1773 elif ent_type
== 'ent_route_node':#{
1774 if obj
.type == 'CURVE':#{
1775 route_curves
+= [obj
]
1778 elif ent_type
== 'ent_route':
1780 elif ent_type
== 'ent_traffic':
1785 dij
= create_node_graph( route_curves
, route_gates
)
1787 for obj
in routes
:#{
1788 obj_data
= obj
.SR_data
.ent_route
[0]
1790 route
.pstr_name
= sr_compile_string( obj_data
.alias
)
1791 route
.checkpoints_start
= checkpoint_count
1792 route
.checkpoints_count
= 0
1795 route
.colour
[ci
] = obj_data
.colour
[ci
]
1796 route
.colour
[3] = 1.0
1798 compile_obj_transform( obj
, route
.transform
)
1799 checkpoints
= obj_data
.gates
1801 for i
in range(len(checkpoints
)):#{
1802 gi
= checkpoints
[i
].target
1803 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
1807 dest
= gi
.SR_data
.ent_gate
[0].target
1811 if gi
==gj
: continue # error?
1812 if not gi
or not gj
: continue
1814 checkpoint
= ent_checkpoint()
1815 checkpoint
.gate_index
= sr_compile
.entity_ids
[gate
.name
]
1816 checkpoint
.path_start
= pathindice_count
1817 checkpoint
.path_count
= 0
1819 path
= solve_graph( dij
, gi
.name
, gj
.name
)
1822 for pi
in range(len(path
)):#{
1823 pathindice
= ent_path_index()
1824 pathindice
.index
= routenode_count
+ path
[pi
]
1825 sr_ent_push( pathindice
)
1827 checkpoint
.path_count
+= 1
1828 pathindice_count
+= 1
1832 sr_ent_push( checkpoint
)
1833 route
.checkpoints_count
+= 1
1834 checkpoint_count
+= 1
1837 sr_ent_push( route
)
1840 for obj
in traffics
:#{
1841 traffic
= ent_traffic()
1842 compile_obj_transform( obj
, traffic
.transform
)
1843 traffic
.submesh_start
, traffic
.submesh_count
, _
= \
1844 sr_compile_mesh_internal( obj
)
1846 # find best subsection
1848 graph_keys
= list(dij
.graph
)
1852 for j
in range(len(dij
.points
)):#{
1853 point
= dij
.points
[j
]
1854 dist
= (point
-obj
.location
).magnitude
1856 if dist
< min_dist
:#{
1863 best_begin
= best_point
1864 best_end
= best_point
1867 map0
= dij
.subsections
[best_begin
]
1868 if map0
[1] == -1: break
1869 best_begin
= map0
[1]
1872 map1
= dij
.subsections
[best_end
]
1873 if map1
[2] == -1: break
1877 traffic
.start_node
= routenode_count
+ best_begin
1878 traffic
.node_count
= best_end
- best_begin
1879 traffic
.index
= best_point
- best_begin
1880 traffic
.speed
= obj
.SR_data
.ent_traffic
[0].speed
1883 sr_ent_push(traffic
)
1886 for point
in dij
.points
:#{
1887 rn
= ent_route_node()
1890 rn
.co
[2] = -point
[1]
1894 routenode_count
+= len(dij
.points
)
1897 print( F
"[SR] Writing file" )
1899 file_array_instructions
= {}
1902 def _write_array( name
, item_size
, data
):#{
1903 nonlocal file_array_instructions
, file_offset
1905 count
= len(data
)//item_size
1906 file_array_instructions
[name
] = {'count':count
, 'size':item_size
,\
1907 'data':data
, 'offset': file_offset
}
1908 file_offset
+= len(data
)
1909 file_offset
= int_align_to( file_offset
, 8 )
1912 _write_array( 'strings', 1, sr_compile
.string_data
)
1913 _write_array( 'mdl_mesh', sizeof(mdl_mesh
), sr_compile
.mesh_data
)
1914 _write_array( 'mdl_submesh', sizeof(mdl_submesh
), sr_compile
.submesh_data
)
1915 _write_array( 'mdl_material', sizeof(mdl_material
), sr_compile
.material_data
)
1916 _write_array( 'mdl_texture', sizeof(mdl_texture
), sr_compile
.texture_data
)
1917 _write_array( 'mdl_armature', sizeof(mdl_armature
), sr_compile
.armature_data
)
1918 _write_array( 'mdl_bone', sizeof(mdl_bone
), sr_compile
.bone_data
)
1920 for name
, buffer in sr_compile
.entity_data
.items():#{
1921 _write_array( name
, sr_compile
.entity_info
[name
]['size'], buffer )
1924 _write_array( 'mdl_animation', sizeof(mdl_animation
), sr_compile
.anim_data
)
1925 _write_array( 'mdl_keyframe', sizeof(mdl_transform
),sr_compile
.keyframe_data
)
1926 _write_array( 'mdl_vert', sizeof(mdl_vert
), sr_compile
.vertex_data
)
1927 _write_array( 'mdl_indice', sizeof(c_uint32
), sr_compile
.indice_data
)
1928 _write_array( 'pack', 1, sr_compile
.pack_data
)
1930 header_size
= int_align_to( sizeof(mdl_header
), 8 )
1931 index_size
= int_align_to( sizeof(mdl_array
)*len(file_array_instructions
),8 )
1933 folder
= bpy
.path
.abspath(bpy
.context
.scene
.SR_data
.export_dir
)
1934 path
= F
"{folder}{collection.name}.mdl"
1937 os
.makedirs(os
.path
.dirname(path
),exist_ok
=True)
1938 fp
= open( path
, "wb" )
1939 header
= mdl_header()
1940 header
.version
= 101
1941 sr_array_title( header
.arrays
, \
1942 'index', len(file_array_instructions
), \
1943 sizeof(mdl_array
), header_size
)
1945 fp
.write( bytearray_align_to( bytearray(header
), 8 ) )
1947 print( F
'[SR] {"name":>16}| count | offset' )
1949 for name
,info
in file_array_instructions
.items():#{
1951 offset
= info
['offset'] + header_size
+ index_size
1952 sr_array_title( arr
, name
, info
['count'], info
['size'], offset
)
1953 index
.extend( bytearray(arr
) )
1955 print( F
'[SR] {name:>16}| {info["count"]: 8} '+\
1956 F
' 0x{info["offset"]:02x}' )
1958 fp
.write( bytearray_align_to( index
, 8 ) )
1959 #bytearray_print_hex( index )
1961 for name
,info
in file_array_instructions
.items():#{
1962 fp
.write( bytearray_align_to( info
['data'], 8 ) )
1967 print( '[SR] done' )
1970 class SR_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
1972 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
1973 export_dir
: bpy
.props
.StringProperty( name
="Export Dir", subtype
='DIR_PATH' )
1974 gizmos
: bpy
.props
.BoolProperty( name
="Draw Gizmos", default
=True )
1976 panel
: bpy
.props
.EnumProperty(
1980 ('EXPORT', 'Export', '', 'MOD_BUILD',0),
1981 ('ENTITY', 'Entity', '', 'MONKEY',1),
1982 ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
1987 class SR_COLLECTION_SETTINGS(bpy
.types
.PropertyGroup
):
1989 pack_textures
: bpy
.props
.BoolProperty( name
="Pack Textures", default
=False )
1990 animations
: bpy
.props
.BoolProperty( name
="Export animation", default
=True)
1993 def sr_get_mirror_bone( bones
):
1995 side
= bones
.active
.name
[-1:]
1996 other_name
= bones
.active
.name
[:-1]
1997 if side
== 'L': other_name
+= 'R'
1998 elif side
== 'R': other_name
+= 'L'
2002 if b
.name
== other_name
:
2009 class SR_MIRROR_BONE_X(bpy
.types
.Operator
):
2011 bl_idname
="skaterift.mirror_bone"
2012 bl_label
="Mirror bone attributes - SkateRift"
2014 def execute(_
,context
):
2016 active_object
= context
.active_object
2017 bones
= active_object
.data
.bones
2019 b
= sr_get_mirror_bone( bones
)
2021 if not b
: return {'FINISHED'}
2023 b
.SR_data
.collider
= a
.SR_data
.collider
2025 def _v3copyflipy( a
, b
):#{
2031 _v3copyflipy( a
.SR_data
.collider_min
, b
.SR_data
.collider_min
)
2032 _v3copyflipy( a
.SR_data
.collider_max
, b
.SR_data
.collider_max
)
2033 b
.SR_data
.collider_min
[1] = -a
.SR_data
.collider_max
[1]
2034 b
.SR_data
.collider_max
[1] = -a
.SR_data
.collider_min
[1]
2036 b
.SR_data
.cone_constraint
= a
.SR_data
.cone_constraint
2038 _v3copyflipy( a
.SR_data
.conevx
, b
.SR_data
.conevy
)
2039 _v3copyflipy( a
.SR_data
.conevy
, b
.SR_data
.conevx
)
2040 _v3copyflipy( a
.SR_data
.coneva
, b
.SR_data
.coneva
)
2042 b
.SR_data
.conet
= a
.SR_data
.conet
2045 ob
= bpy
.context
.scene
.objects
[0]
2046 ob
.hide_render
= ob
.hide_render
2051 class SR_COMPILE(bpy
.types
.Operator
):
2053 bl_idname
="skaterift.compile_all"
2054 bl_label
="Compile All"
2056 def execute(_
,context
):
2058 view_layer
= bpy
.context
.view_layer
2059 for col
in view_layer
.layer_collection
.children
["export"].children
:
2060 if not col
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2061 sr_compile( bpy
.data
.collections
[col
.name
] )
2067 class SR_COMPILE_THIS(bpy
.types
.Operator
):
2069 bl_idname
="skaterift.compile_this"
2070 bl_label
="Compile This collection"
2072 def execute(_
,context
):
2074 col
= bpy
.context
.collection
2081 class SR_INTERFACE(bpy
.types
.Panel
):
2083 bl_idname
= "VIEW3D_PT_skate_rift"
2084 bl_label
= "Skate Rift"
2085 bl_space_type
= 'VIEW_3D'
2086 bl_region_type
= 'UI'
2087 bl_category
= "Skate Rift"
2089 def draw(_
, context
):
2093 row
= _
.layout
.row()
2095 row
.prop( context
.scene
.SR_data
, 'panel', expand
=True )
2097 if context
.scene
.SR_data
.panel
== 'SETTINGS': #{
2098 _
.layout
.prop( context
.scene
.SR_data
, 'gizmos' )
2100 elif context
.scene
.SR_data
.panel
== 'EXPORT': #{
2101 _
.layout
.prop( context
.scene
.SR_data
, "export_dir" )
2102 col
= bpy
.context
.collection
2104 found_in_export
= False
2106 view_layer
= bpy
.context
.view_layer
2107 for c1
in view_layer
.layer_collection
.children
["export"].children
: #{
2108 if not c1
.hide_viewport
or bpy
.context
.scene
.SR_data
.use_hidden
:
2111 if c1
.name
== col
.name
: #{
2112 found_in_export
= True
2116 box
= _
.layout
.box()
2118 row
.alignment
= 'CENTER'
2121 if found_in_export
: #{
2122 row
.label( text
=col
.name
+ ".mdl" )
2123 box
.prop( col
.SR_data
, "pack_textures" )
2124 box
.prop( col
.SR_data
, "animations" )
2125 box
.operator( "skaterift.compile_this" )
2129 row
.label( text
=col
.name
)
2133 row
.alignment
= 'CENTER'
2135 row
.label( text
="This collection is not in the export group" )
2138 box
= _
.layout
.box()
2141 split
= row
.split( factor
=0.3, align
=True )
2142 split
.prop( context
.scene
.SR_data
, "use_hidden", text
="hidden" )
2145 if export_count
== 0:
2147 row1
.operator( "skaterift.compile_all", \
2148 text
=F
"Compile all ({export_count} collections)" )
2150 elif context
.scene
.SR_data
.panel
== 'ENTITY': #{
2151 active_object
= context
.active_object
2152 if not active_object
: return
2154 _
.layout
.operator( 'skaterift.copy_entity_data', \
2155 text
=F
'Copy entity data to {len(context.selected_objects)-1} '+\
2158 box
= _
.layout
.box()
2160 row
.alignment
= 'CENTER'
2161 row
.label( text
=active_object
.name
)
2164 def _draw_prop_collection( data
): #{
2167 row
.alignment
= 'CENTER'
2170 row
.label( text
=F
'{data[0]}' )
2172 if hasattr(type(data
[0]),'sr_inspector'):#{
2173 type(data
[0]).sr_inspector( box
, data
)
2176 for a
in data
[0].__annotations
__:
2177 box
.prop( data
[0], a
)
2181 if active_object
.type == 'ARMATURE': #{
2182 if active_object
.mode
== 'POSE': #{
2183 bones
= active_object
.data
.bones
2184 mb
= sr_get_mirror_bone( bones
)
2186 box
.operator( "skaterift.mirror_bone", \
2187 text
=F
'Mirror attributes to {mb.name}' )
2190 _draw_prop_collection( [bones
.active
.SR_data
] )
2194 row
.alignment
='CENTER'
2197 row
.label( text
="Enter pose mode to modify bone properties" )
2200 elif active_object
.type == 'LIGHT': #{
2201 _draw_prop_collection( [active_object
.data
.SR_data
] )
2203 elif active_object
.type in ['EMPTY','CURVE','MESH']:#{
2204 box
.prop( active_object
.SR_data
, "ent_type" )
2205 ent_type
= active_object
.SR_data
.ent_type
2207 col
= getattr( active_object
.SR_data
, ent_type
, None )
2208 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
2210 if active_object
.type == 'MESH':#{
2211 col
= getattr( active_object
.data
.SR_data
, ent_type
, None )
2212 if col
!= None and len(col
)!=0: _draw_prop_collection( col
)
2219 class SR_MATERIAL_PANEL(bpy
.types
.Panel
):
2221 bl_label
="Skate Rift material"
2222 bl_idname
="MATERIAL_PT_sr_material"
2223 bl_space_type
='PROPERTIES'
2224 bl_region_type
='WINDOW'
2225 bl_context
="material"
2227 def draw(_
,context
):
2229 active_object
= bpy
.context
.active_object
2230 if active_object
== None: return
2231 active_mat
= active_object
.active_material
2232 if active_mat
== None: return
2234 info
= material_info( active_mat
)
2236 if 'tex_diffuse' in info
:#{
2237 _
.layout
.label( icon
='INFO', \
2238 text
=F
"{info['tex_diffuse'].name} will be compiled" )
2241 _
.layout
.prop( active_mat
.SR_data
, "shader" )
2242 _
.layout
.prop( active_mat
.SR_data
, "surface_prop" )
2243 _
.layout
.prop( active_mat
.SR_data
, "collision" )
2245 if active_mat
.SR_data
.collision
:#{
2246 box
= _
.layout
.box()
2249 if (active_mat
.SR_data
.shader
!= 'invisible') and \
2250 (active_mat
.SR_data
.shader
!= 'boundary'):#{
2251 row
.prop( active_mat
.SR_data
, "skate_surface" )
2252 row
.prop( active_mat
.SR_data
, "grind_surface" )
2253 row
.prop( active_mat
.SR_data
, "grow_grass" )
2254 row
.prop( active_mat
.SR_data
, "preview_visibile" )
2258 if active_mat
.SR_data
.shader
== "terrain_blend":#{
2259 box
= _
.layout
.box()
2260 box
.prop( active_mat
.SR_data
, "blend_offset" )
2261 box
.prop( active_mat
.SR_data
, "sand_colour" )
2263 elif active_mat
.SR_data
.shader
== "vertex_blend":#{
2264 box
= _
.layout
.box()
2265 box
.label( icon
='INFO', text
="Uses vertex colours, the R channel" )
2266 box
.prop( active_mat
.SR_data
, "blend_offset" )
2268 elif active_mat
.SR_data
.shader
== "water":#{
2269 box
= _
.layout
.box()
2270 box
.label( icon
='INFO', text
="Depth scale of 16 meters" )
2271 box
.prop( active_mat
.SR_data
, "shore_colour" )
2272 box
.prop( active_mat
.SR_data
, "ocean_colour" )
2277 def sr_get_type_enum( scene
, context
):
2279 items
= [('none','None',"")]
2280 mesh_entities
=['ent_gate','ent_water']
2281 point_entities
=['ent_spawn','ent_route_node','ent_route']
2283 for e
in point_entities
: items
+= [(e
,e
,'')]
2285 if context
.scene
.SR_data
.panel
== 'ENTITY': #{
2286 if context
.active_object
.type == 'MESH': #{
2287 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2291 for e
in mesh_entities
: items
+= [(e
,e
,'')]
2297 def sr_on_type_change( _
, context
):
2299 obj
= context
.active_object
2300 ent_type
= obj
.SR_data
.ent_type
2301 if ent_type
== 'none': return
2302 if obj
.type == 'MESH':#{
2303 col
= getattr( obj
.data
.SR_data
, ent_type
, None )
2304 if col
!= None and len(col
)==0: col
.add()
2307 col
= getattr( obj
.SR_data
, ent_type
, None )
2308 if col
!= None and len(col
)==0: col
.add()
2311 class SR_OBJECT_ENT_SPAWN(bpy
.types
.PropertyGroup
):
2313 alias
: bpy
.props
.StringProperty( name
='alias' )
2316 class SR_OBJECT_ENT_GATE(bpy
.types
.PropertyGroup
):
2318 target
: bpy
.props
.PointerProperty( \
2319 type=bpy
.types
.Object
, name
="destination", \
2320 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2322 key
: bpy
.props
.StringProperty()
2323 tipo
: bpy
.props
.EnumProperty(items
=(('default', 'Default', ""),
2324 ('nonlocal', 'Non-Local', ""),))
2327 def sr_inspector( layout
, data
):
2330 box
.prop( data
[0], 'tipo', text
="subtype" )
2332 if data
[0].tipo
== 'default': box
.prop( data
[0], 'target' )
2333 elif data
[0].tipo
== 'nonlocal': box
.prop( data
[0], 'key' )
2337 class SR_MESH_ENT_GATE(bpy
.types
.PropertyGroup
):
2339 dimensions
: bpy
.props
.FloatVectorProperty(name
="dimensions",size
=3)
2342 class SR_OBJECT_ENT_ROUTE_ENTRY(bpy
.types
.PropertyGroup
):
2344 target
: bpy
.props
.PointerProperty( \
2345 type=bpy
.types
.Object
, name
='target', \
2346 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_gate']))
2349 class SR_UL_ROUTE_NODE_LIST(bpy
.types
.UIList
):
2351 bl_idname
= 'SR_UL_ROUTE_NODE_LIST'
2353 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2355 layout
.prop( item
, 'target', text
='', emboss
=False )
2359 def internal_listdel_execute(self
,context
,ent_name
,collection_name
):
2361 active_object
= context
.active_object
2362 data
= getattr(active_object
.SR_data
,ent_name
)[0]
2363 lista
= getattr(data
,collection_name
)
2364 index
= getattr(data
,F
'{collection_name}_index')
2368 setattr(data
,F
'{collection_name}_index', min(max(0,index
-1), len(lista
)-1))
2372 def internal_listadd_execute(self
,context
,ent_name
,collection_name
):
2374 active_object
= context
.active_object
2375 getattr(getattr(active_object
.SR_data
,ent_name
)[0],collection_name
).add()
2379 def copy_propgroup( de
, to
):
2381 for a
in de
.__annotations
__:#{
2382 if isinstance(getattr(de
,a
), bpy
.types
.bpy_prop_collection
):#{
2386 while len(cb
) != len(ca
):#{
2387 if len(cb
) < len(ca
): cb
.add()
2390 for i
in range(len(ca
)):#{
2391 copy_propgroup(ca
[i
],cb
[i
])
2395 setattr(to
,a
,getattr(de
,a
))
2400 class SR_OT_COPY_ENTITY_DATA(bpy
.types
.Operator
):
2402 bl_idname
= "skaterift.copy_entity_data"
2403 bl_label
= "Copy entity data"
2405 def execute(self
, context
):#{
2406 data
= context
.active_object
.SR_data
2407 new_type
= data
.ent_type
2408 print( F
"Copy entity data from: {context.active_object.name}" )
2410 for obj
in context
.selected_objects
:#{
2411 if obj
!= context
.active_object
:#{
2412 print( F
" To: {obj.name}" )
2414 obj
.SR_data
.ent_type
= new_type
2416 if active_object
.type == 'MESH':#{
2417 col
= getattr( obj
.data
.SR_data
, new_type
, None )
2418 if col
!= None and len(col
)==0: col
.add()
2419 mdata
= context
.active_object
.data
.SR_data
2420 copy_propgroup( getattr(mdata
,new_type
)[0], col
[0] )
2423 col
= getattr( obj
.SR_data
, new_type
, None )
2424 if col
!= None and len(col
)==0: col
.add()
2425 copy_propgroup( getattr(data
,new_type
)[0], col
[0] )
2432 class SR_OT_ROUTE_LIST_NEW_ITEM(bpy
.types
.Operator
):
2434 bl_idname
= "skaterift.new_entry"
2435 bl_label
= "Add gate"
2437 def execute(self
, context
):#{
2438 return internal_listadd_execute(self
,context
,'ent_route','gates')
2442 class SR_OT_ROUTE_LIST_DEL_ITEM(bpy
.types
.Operator
):
2444 bl_idname
= "skaterift.del_entry"
2445 bl_label
= "Remove gate"
2448 def poll(cls
, context
):#{
2449 active_object
= context
.active_object
2450 if obj_ent_type(active_object
) == 'ent_route':#{
2451 return active_object
.SR_data
.ent_route
[0].gates
2456 def execute(self
, context
):#{
2457 return internal_listdel_execute(self
,context
,'ent_route','gates')
2461 class SR_OT_AUDIO_LIST_NEW_ITEM(bpy
.types
.Operator
):
2463 bl_idname
= "skaterift.al_new_entry"
2464 bl_label
= "Add file"
2466 def execute(self
, context
):#{
2467 return internal_listadd_execute(self
,context
,'ent_audio','files')
2471 class SR_OT_AUDIO_LIST_DEL_ITEM(bpy
.types
.Operator
):
2473 bl_idname
= "skaterift.al_del_entry"
2474 bl_label
= "Remove file"
2477 def poll(cls
, context
):#{
2478 active_object
= context
.active_object
2479 if obj_ent_type(active_object
) == 'ent_audio':#{
2480 return active_object
.SR_data
.ent_audio
[0].files
2485 def execute(self
, context
):#{
2486 return internal_listdel_execute(self
,context
,'ent_audio','files')
2491 class SR_OT_GLYPH_LIST_NEW_ITEM(bpy
.types
.Operator
):
2493 bl_idname
= "skaterift.gl_new_entry"
2494 bl_label
= "Add glyph"
2496 def execute(self
, context
):#{
2497 active_object
= context
.active_object
2499 font
= active_object
.SR_data
.ent_font
[0]
2502 if len(font
.glyphs
) > 1:#{
2503 prev
= font
.glyphs
[-2]
2504 cur
= font
.glyphs
[-1]
2506 cur
.bounds
= prev
.bounds
2507 cur
.utf32
= prev
.utf32
+1
2514 class SR_OT_GLYPH_LIST_DEL_ITEM(bpy
.types
.Operator
):
2516 bl_idname
= "skaterift.gl_del_entry"
2517 bl_label
= "Remove Glyph"
2520 def poll(cls
, context
):#{
2521 active_object
= context
.active_object
2522 if obj_ent_type(active_object
) == 'ent_font':#{
2523 return active_object
.SR_data
.ent_font
[0].glyphs
2528 def execute(self
, context
):#{
2529 return internal_listdel_execute(self
,context
,'ent_font','glyphs')
2533 class SR_OT_GLYPH_LIST_MOVE_ITEM(bpy
.types
.Operator
):
2535 bl_idname
= "skaterift.gl_move_item"
2537 direction
: bpy
.props
.EnumProperty(items
=(('UP', 'Up', ""),
2538 ('DOWN', 'Down', ""),))
2541 def poll(cls
, context
):#{
2542 active_object
= context
.active_object
2543 if obj_ent_type(active_object
) == 'ent_font':#{
2544 return active_object
.SR_data
.ent_font
[0].glyphs
2549 def execute(_
, context
):#{
2550 active_object
= context
.active_object
2551 data
= active_object
.SR_data
.ent_font
[0]
2553 index
= data
.glyphs_index
2554 neighbor
= index
+ (-1 if _
.direction
== 'UP' else 1)
2555 data
.glyphs
.move( neighbor
, index
)
2557 list_length
= len(data
.glyphs
) - 1
2558 new_index
= index
+ (-1 if _
.direction
== 'UP' else 1)
2560 data
.glyphs_index
= max(0, min(new_index
, list_length
))
2566 class SR_OT_FONT_VARIANT_LIST_NEW_ITEM(bpy
.types
.Operator
):
2568 bl_idname
= "skaterift.fv_new_entry"
2569 bl_label
= "Add variant"
2571 def execute(self
, context
):#{
2572 return internal_listadd_execute(self
,context
,'ent_font','variants')
2576 class SR_OT_FONT_VARIANT_LIST_DEL_ITEM(bpy
.types
.Operator
):
2578 bl_idname
= "skaterift.fv_del_entry"
2579 bl_label
= "Remove variant"
2582 def poll(cls
, context
):#{
2583 active_object
= context
.active_object
2584 if obj_ent_type(active_object
) == 'ent_font':#{
2585 return active_object
.SR_data
.ent_font
[0].variants
2590 def execute(self
, context
):#{
2591 return internal_listdel_execute(self
,context
,'ent_font','variants')
2595 class SR_OBJECT_ENT_AUDIO_FILE_ENTRY(bpy
.types
.PropertyGroup
):
2597 path
: bpy
.props
.StringProperty( name
="Path" )
2598 probability
: bpy
.props
.FloatProperty( name
="Probability",default
=100.0 )
2601 class SR_UL_AUDIO_LIST(bpy
.types
.UIList
):
2603 bl_idname
= 'SR_UL_AUDIO_LIST'
2605 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2607 split
= layout
.split(factor
=0.7)
2609 c
.prop( item
, 'path', text
='', emboss
=False )
2611 c
.prop( item
, 'probability', text
='%', emboss
=True )
2615 class SR_UL_FONT_VARIANT_LIST(bpy
.types
.UIList
):
2617 bl_idname
= 'SR_UL_FONT_VARIANT_LIST'
2619 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2621 layout
.prop( item
, 'mesh', emboss
=False )
2622 layout
.prop( item
, 'tipo' )
2626 class SR_UL_FONT_GLYPH_LIST(bpy
.types
.UIList
):
2628 bl_idname
= 'SR_UL_FONT_GLYPH_LIST'
2630 def draw_item(_
,context
,layout
,data
,item
,icon
,active_data
,active_propname
):
2632 s0
= layout
.split(factor
=0.3)
2634 s1
= c
.split(factor
=0.3)
2637 lbl
= chr(item
.utf32
) if item
.utf32
>= 32 and item
.utf32
<= 126 else \
2641 c
.prop( item
, 'utf32', text
='', emboss
=True )
2644 row
.prop( item
, 'bounds', text
='', emboss
=False )
2648 class SR_OBJECT_ENT_ROUTE(bpy
.types
.PropertyGroup
):
2650 gates
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE_ENTRY
)
2651 gates_index
: bpy
.props
.IntProperty()
2653 colour
: bpy
.props
.FloatVectorProperty( \
2657 default
=Vector((0.79,0.63,0.48)),\
2658 description
="Route colour"\
2661 alias
: bpy
.props
.StringProperty(\
2663 default
="Untitled Course")
2666 def sr_inspector( layout
, data
):
2668 layout
.prop( data
[0], 'alias' )
2669 layout
.prop( data
[0], 'colour' )
2671 layout
.label( text
='Checkpoints' )
2672 layout
.template_list('SR_UL_ROUTE_NODE_LIST', 'Checkpoints', \
2673 data
[0], 'gates', data
[0], 'gates_index', rows
=5)
2676 row
.operator( 'skaterift.new_entry', text
='Add' )
2677 row
.operator( 'skaterift.del_entry', text
='Remove' )
2681 class SR_OBJECT_ENT_VOLUME(bpy
.types
.PropertyGroup
):
2683 subtype
: bpy
.props
.EnumProperty(
2685 items
=[('0','Trigger',''),
2686 ('1','Particles (0.1s)','')]
2689 target
: bpy
.props
.PointerProperty( \
2690 type=bpy
.types
.Object
, name
="Target", \
2691 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,\
2692 ['ent_audio','ent_skateshop','ent_ccmd']))
2695 def sr_inspector( layout
, data
):
2698 layout
.prop( data
, 'subtype' )
2699 layout
.prop( data
, 'target' )
2703 class SR_OBJECT_ENT_AUDIO(bpy
.types
.PropertyGroup
):
2705 files
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO_FILE_ENTRY
)
2706 files_index
: bpy
.props
.IntProperty()
2708 flag_3d
: bpy
.props
.BoolProperty( name
="3D audio",default
=True )
2709 flag_loop
: bpy
.props
.BoolProperty( name
="Loop",default
=False )
2710 flag_auto
: bpy
.props
.BoolProperty( name
="Play at start",default
=False )
2711 flag_nodoppler
: bpy
.props
.BoolProperty( name
="No Doppler",default
=False )
2713 group
: bpy
.props
.IntProperty( name
="Group ID", default
=0 )
2714 formato
: bpy
.props
.EnumProperty(
2716 items
=[('0','Uncompressed Mono',''),
2717 ('1','Compressed Vorbis',''),
2718 ('2','[vg] Bird Synthesis','')]
2720 probability_curve
: bpy
.props
.EnumProperty(
2721 name
="Probability Curve",
2722 items
=[('0','Constant',''),
2723 ('1','Wildlife Daytime',''),
2724 ('2','Wildlife Nighttime','')])
2725 channel_behaviour
: bpy
.props
.EnumProperty(
2726 name
="Channel Behaviour",
2727 items
=[('0','Unlimited',''),
2728 ('1','Discard if group full', ''),
2729 ('2','Crossfade if group full','')])
2731 transition_duration
: bpy
.props
.FloatProperty(name
="Transition Time",\
2734 max_channels
: bpy
.props
.IntProperty( name
="Max Channels", default
=1 )
2735 volume
: bpy
.props
.FloatProperty( name
="Volume",default
=1.0 )
2738 def sr_inspector( layout
, data
):
2740 layout
.prop( data
[0], 'formato' )
2741 layout
.prop( data
[0], 'volume' )
2744 box
.label( text
='Channels' )
2745 split
= box
.split(factor
=0.3)
2747 c
.prop( data
[0], 'max_channels' )
2749 c
.prop( data
[0], 'channel_behaviour', text
='Behaviour' )
2750 if data
[0].channel_behaviour
>= '1':
2751 box
.prop( data
[0], 'group' )
2752 if data
[0].channel_behaviour
== '2':
2753 box
.prop( data
[0], 'transition_duration' )
2756 box
.label( text
='Flags' )
2757 box
.prop( data
[0], 'flag_3d' )
2758 if data
[0].flag_3d
: box
.prop( data
[0], 'flag_nodoppler' )
2760 box
.prop( data
[0], 'flag_loop' )
2761 box
.prop( data
[0], 'flag_auto' )
2763 split
= layout
.split(factor
=0.7)
2765 c
.label( text
='Filepath' )
2767 c
.label( text
='Chance (0.1s)' )
2769 layout
.prop( data
[0], 'probability_curve' )
2771 layout
.template_list('SR_UL_AUDIO_LIST', 'Files', \
2772 data
[0], 'files', data
[0], 'file_index', rows
=5)
2775 row
.operator( 'skaterift.al_new_entry', text
='Add' )
2776 row
.operator( 'skaterift.al_del_entry', text
='Remove' )
2780 class SR_OBJECT_ENT_MARKER(bpy
.types
.PropertyGroup
):
2782 alias
: bpy
.props
.StringProperty()
2785 class SR_OBJECT_ENT_GLYPH(bpy
.types
.PropertyGroup
):
2787 mini
: bpy
.props
.FloatVectorProperty(size
=2)
2788 maxi
: bpy
.props
.FloatVectorProperty(size
=2)
2789 utf32
: bpy
.props
.IntProperty()
2792 class SR_OBJECT_ENT_GLYPH_ENTRY(bpy
.types
.PropertyGroup
):
2794 bounds
: bpy
.props
.FloatVectorProperty(size
=4,subtype
='NONE')
2795 utf32
: bpy
.props
.IntProperty()
2798 class SR_OBJECT_ENT_FONT_VARIANT(bpy
.types
.PropertyGroup
):
2800 mesh
: bpy
.props
.PointerProperty(type=bpy
.types
.Object
)
2801 tipo
: bpy
.props
.StringProperty()
2804 class SR_OBJECT_ENT_FONT(bpy
.types
.PropertyGroup
):
2806 variants
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT_VARIANT
)
2807 glyphs
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH_ENTRY
)
2808 alias
: bpy
.props
.StringProperty()
2810 glyphs_index
: bpy
.props
.IntProperty()
2811 variants_index
: bpy
.props
.IntProperty()
2814 def sr_inspector( layout
, data
):
2816 layout
.prop( data
[0], 'alias' )
2818 layout
.label( text
='Variants' )
2819 layout
.template_list('SR_UL_FONT_VARIANT_LIST', 'Variants', \
2820 data
[0], 'variants', data
[0], 'variants_index',\
2823 row
.operator( 'skaterift.fv_new_entry', text
='Add' )
2824 row
.operator( 'skaterift.fv_del_entry', text
='Remove' )
2826 layout
.label( text
='ASCII Glyphs' )
2827 layout
.template_list('SR_UL_FONT_GLYPH_LIST', 'Glyphs', \
2828 data
[0], 'glyphs', data
[0], 'glyphs_index', rows
=5)
2831 row
.operator( 'skaterift.gl_new_entry', text
='Add' )
2832 row
.operator( 'skaterift.gl_del_entry', text
='Remove' )
2833 row
.operator( 'skaterift.gl_move_item', text
='^' ).direction
='UP'
2834 row
.operator( 'skaterift.gl_move_item', text
='v' ).direction
='DOWN'
2838 class SR_OBJECT_ENT_TRAFFIC(bpy
.types
.PropertyGroup
):
2840 speed
: bpy
.props
.FloatProperty(default
=1.0)
2843 class SR_OBJECT_ENT_SKATESHOP(bpy
.types
.PropertyGroup
):
2845 tipo
: bpy
.props
.EnumProperty( name
='Type',
2846 items
=[('0','boards',''),
2847 ('1','character',''),
2849 mark_rack
: bpy
.props
.PointerProperty( \
2850 type=bpy
.types
.Object
, name
="Board Rack", \
2851 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2852 mark_display
: bpy
.props
.PointerProperty( \
2853 type=bpy
.types
.Object
, name
="Selected Board Display", \
2854 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2855 mark_info
: bpy
.props
.PointerProperty( \
2856 type=bpy
.types
.Object
, name
="Selected Board Info", \
2857 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2858 cam
: bpy
.props
.PointerProperty( \
2859 type=bpy
.types
.Object
, name
="Viewpoint", \
2860 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2863 class SR_OBJECT_ENT_WORKSHOP_PREVIEW(bpy
.types
.PropertyGroup
):
2865 mark_display
: bpy
.props
.PointerProperty( \
2866 type=bpy
.types
.Object
, name
="Board Display", \
2867 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2868 mark_display1
: bpy
.props
.PointerProperty( \
2869 type=bpy
.types
.Object
, name
="Board Display (other side)", \
2870 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2871 cam
: bpy
.props
.PointerProperty( \
2872 type=bpy
.types
.Object
, name
="Viewpoint", \
2873 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2876 class SR_OBJECT_ENT_MENU_ITEM(bpy
.types
.PropertyGroup
):
2878 link0
: bpy
.props
.PointerProperty( \
2879 type=bpy
.types
.Object
, name
="Link 0", \
2880 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2881 link1
: bpy
.props
.PointerProperty( \
2882 type=bpy
.types
.Object
, name
="Link 1", \
2883 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2884 link2
: bpy
.props
.PointerProperty( \
2885 type=bpy
.types
.Object
, name
="Link 2", \
2886 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2887 link3
: bpy
.props
.PointerProperty( \
2888 type=bpy
.types
.Object
, name
="Link 3", \
2889 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2891 newloc
: bpy
.props
.PointerProperty( \
2892 type=bpy
.types
.Object
, name
="New location", \
2893 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2894 camera
: bpy
.props
.PointerProperty( \
2895 type=bpy
.types
.Object
, name
="Camera", \
2896 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_camera']))
2898 slider_minloc
: bpy
.props
.PointerProperty( \
2899 type=bpy
.types
.Object
, name
="Slider min", \
2900 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2901 slider_maxloc
: bpy
.props
.PointerProperty( \
2902 type=bpy
.types
.Object
, name
="Slider max", \
2903 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_marker']))
2904 slider_handle
: bpy
.props
.PointerProperty( \
2905 type=bpy
.types
.Object
, name
="Slider handle", \
2906 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2908 checkmark
: bpy
.props
.PointerProperty( \
2909 type=bpy
.types
.Object
, name
="Checked", \
2910 poll
=lambda self
,obj
: sr_filter_ent_type(obj
,['ent_menuitem']))
2912 string
: bpy
.props
.StringProperty( name
="String" )
2913 tipo
: bpy
.props
.EnumProperty( name
='Type',
2914 items
=[('0','visual',''),
2915 ('1','event button',''),
2916 ('2','page button',''),
2922 def sr_inspector( layout
, data
):
2926 box
.prop( data
, 'tipo' )
2928 if data
.tipo
== '0':#{
2931 elif data
.tipo
== '1':#{
2932 box
.prop( data
, 'string', text
='Event' )
2934 elif data
.tipo
== '2':#{
2935 box
.prop( data
, 'string', text
='Page' )
2936 box
.prop( data
, 'newloc' )
2938 elif data
.tipo
== '3':#{
2939 box
.prop( data
, 'string', text
='Data (i32)' )
2940 box
.prop( data
, 'checkmark' )
2942 elif data
.tipo
== '4':#{
2943 box
.prop( data
, 'string', text
='Data (f32)' )
2944 box
.prop( data
, 'slider_minloc' )
2945 box
.prop( data
, 'slider_maxloc' )
2946 box
.prop( data
, 'slider_handle' )
2948 box
.label( text
="Links" )
2949 box
.prop( data
, 'link0', text
='v0' )
2950 box
.prop( data
, 'link1', text
='v1' )
2953 elif data
.tipo
== '5':#{
2954 box
.prop( data
, 'string', text
='Page Name' )
2955 box
.prop( data
, 'newloc', text
='Entry Point' )
2956 box
.prop( data
, 'camera', text
='Viewpoint' )
2961 box
.label( text
="Links" )
2962 box
.prop( data
, 'link0' )
2963 box
.prop( data
, 'link1' )
2964 box
.prop( data
, 'link2' )
2965 box
.prop( data
, 'link3' )
2969 class SR_OBJECT_ENT_WORLD_INFO(bpy
.types
.PropertyGroup
):
2971 name
: bpy
.props
.StringProperty(name
="Name")
2972 desc
: bpy
.props
.StringProperty(name
="Description")
2973 author
: bpy
.props
.StringProperty(name
="Author")
2974 timezone
: bpy
.props
.FloatProperty(name
="Timezone(hrs) (UTC0 +hrs)")
2977 class SR_OBJECT_ENT_CCMD(bpy
.types
.PropertyGroup
):
2979 command
: bpy
.props
.StringProperty(name
="Command Line")
2982 class SR_OBJECT_PROPERTIES(bpy
.types
.PropertyGroup
):
2984 ent_gate
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GATE
)
2985 ent_spawn
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SPAWN
)
2986 ent_route
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_ROUTE
)
2987 ent_volume
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_VOLUME
)
2988 ent_audio
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_AUDIO
)
2989 ent_marker
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MARKER
)
2990 ent_glyph
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_GLYPH
)
2991 ent_font
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_FONT
)
2992 ent_traffic
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_TRAFFIC
)
2993 ent_skateshop
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_SKATESHOP
)
2995 bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORKSHOP_PREVIEW
)
2996 ent_menuitem
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_MENU_ITEM
)
2997 ent_worldinfo
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_WORLD_INFO
)
2998 ent_ccmd
: bpy
.props
.CollectionProperty(type=SR_OBJECT_ENT_CCMD
)
3000 ent_type
: bpy
.props
.EnumProperty(
3002 items
=sr_entity_list
,
3003 update
=sr_on_type_change
3007 class SR_MESH_PROPERTIES(bpy
.types
.PropertyGroup
):
3009 ent_gate
: bpy
.props
.CollectionProperty(type=SR_MESH_ENT_GATE
)
3012 class SR_LIGHT_PROPERTIES(bpy
.types
.PropertyGroup
):
3014 daytime
: bpy
.props
.BoolProperty( name
='Daytime' )
3017 class SR_BONE_PROPERTIES(bpy
.types
.PropertyGroup
):
3019 collider
: bpy
.props
.EnumProperty( name
='Collider Type',
3020 items
=[('0','none',''),
3022 ('2','capsule','')])
3024 collider_min
: bpy
.props
.FloatVectorProperty( name
='Collider Min', size
=3 )
3025 collider_max
: bpy
.props
.FloatVectorProperty( name
='Collider Max', size
=3 )
3027 cone_constraint
: bpy
.props
.BoolProperty( name
='Cone constraint' )
3029 conevx
: bpy
.props
.FloatVectorProperty( name
='vx' )
3030 conevy
: bpy
.props
.FloatVectorProperty( name
='vy' )
3031 coneva
: bpy
.props
.FloatVectorProperty( name
='va' )
3032 conet
: bpy
.props
.FloatProperty( name
='t' )
3035 def sr_inspector( layout
, data
):
3039 box
.prop( data
, 'collider' )
3041 if int(data
.collider
)>0:#{
3043 row
.prop( data
, 'collider_min' )
3045 row
.prop( data
, 'collider_max' )
3049 box
.prop( data
, 'cone_constraint' )
3050 if data
.cone_constraint
:#{
3052 row
.prop( data
, 'conevx' )
3054 row
.prop( data
, 'conevy' )
3056 row
.prop( data
, 'coneva' )
3057 box
.prop( data
, 'conet' )
3062 class SR_MATERIAL_PROPERTIES(bpy
.types
.PropertyGroup
):
3064 shader
: bpy
.props
.EnumProperty(
3067 ('standard',"standard",''),
3068 ('standard_cutout', "standard_cutout", ''),
3069 ('terrain_blend', "terrain_blend", ''),
3070 ('vertex_blend', "vertex_blend", ''),
3071 ('water',"water",''),
3072 ('invisible','Invisible',''),
3073 ('boundary','Boundary','')
3076 surface_prop
: bpy
.props
.EnumProperty(
3077 name
="Surface Property",
3079 ('0','concrete',''),
3086 collision
: bpy
.props
.BoolProperty( \
3087 name
="Collisions Enabled",\
3089 description
= "Can the player collide with this material?"\
3091 skate_surface
: bpy
.props
.BoolProperty( \
3092 name
="Skate Target", \
3094 description
= "Should the game try to target this surface?" \
3096 grind_surface
: bpy
.props
.BoolProperty( \
3099 description
= "Can you grind on this surface?" \
3101 grow_grass
: bpy
.props
.BoolProperty( \
3102 name
="Grow Grass", \
3104 description
= "Spawn grass sprites on this surface?" \
3106 preview_visibile
: bpy
.props
.BoolProperty( \
3107 name
="Preview visibile", \
3109 description
= "Show this material in preview models?" \
3111 blend_offset
: bpy
.props
.FloatVectorProperty( \
3112 name
="Blend Offset", \
3114 default
=Vector((0.5,0.0)),\
3115 description
="When surface is more than 45 degrees, add this vector " +\
3118 sand_colour
: bpy
.props
.FloatVectorProperty( \
3119 name
="Sand Colour",\
3122 default
=Vector((0.79,0.63,0.48)),\
3123 description
="Blend to this colour near the 0 coordinate on UP axis"\
3125 shore_colour
: bpy
.props
.FloatVectorProperty( \
3126 name
="Shore Colour",\
3129 default
=Vector((0.03,0.32,0.61)),\
3130 description
="Water colour at the shoreline"\
3132 ocean_colour
: bpy
.props
.FloatVectorProperty( \
3133 name
="Ocean Colour",\
3136 default
=Vector((0.0,0.006,0.03)),\
3137 description
="Water colour in the deep bits"\
3141 # ---------------------------------------------------------------------------- #
3145 # ---------------------------------------------------------------------------- #
3147 cv_view_draw_handler
= None
3148 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
3150 cv_view_colours
= []
3151 cv_view_course_i
= 0
3153 # Draw axis alligned sphere at position with radius
3155 def cv_draw_sphere( pos
, radius
, colour
):
3157 global cv_view_verts
, cv_view_colours
3159 ly
= pos
+ Vector((0,0,radius
))
3160 lx
= pos
+ Vector((0,radius
,0))
3161 lz
= pos
+ Vector((0,0,radius
))
3163 pi
= 3.14159265358979323846264
3165 for i
in range(16):#{
3166 t
= ((i
+1.0) * 1.0/16.0) * pi
* 2.0
3170 py
= pos
+ Vector((s
*radius
,0.0,c
*radius
))
3171 px
= pos
+ Vector((s
*radius
,c
*radius
,0.0))
3172 pz
= pos
+ Vector((0.0,s
*radius
,c
*radius
))
3174 cv_view_verts
+= [ px
, lx
]
3175 cv_view_verts
+= [ py
, ly
]
3176 cv_view_verts
+= [ pz
, lz
]
3178 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3187 # Draw axis alligned sphere at position with radius
3189 def cv_draw_halfsphere( pos
, tx
, ty
, tz
, radius
, colour
):
3191 global cv_view_verts
, cv_view_colours
3193 ly
= pos
+ tz
*radius
3194 lx
= pos
+ ty
*radius
3195 lz
= pos
+ tz
*radius
3197 pi
= 3.14159265358979323846264
3199 for i
in range(16):#{
3200 t
= ((i
+1.0) * 1.0/16.0) * pi
3204 s1
= math
.sin(t
*2.0)
3205 c1
= math
.cos(t
*2.0)
3207 py
= pos
+ s
*tx
*radius
+ c
*tz
*radius
3208 px
= pos
+ s
*tx
*radius
+ c
*ty
*radius
3209 pz
= pos
+ s1
*ty
*radius
+ c1
*tz
*radius
3211 cv_view_verts
+= [ px
, lx
]
3212 cv_view_verts
+= [ py
, ly
]
3213 cv_view_verts
+= [ pz
, lz
]
3215 cv_view_colours
+= [ colour
, colour
, colour
, colour
, colour
, colour
]
3224 # Draw transformed -1 -> 1 cube
3226 def cv_draw_ucube( transform
, colour
, s
=Vector((1,1,1)), o
=Vector((0,0,0)) ):
3228 global cv_view_verts
, cv_view_colours
3234 vs
[0] = transform
@ Vector((a
[0], a
[1], a
[2]))
3235 vs
[1] = transform
@ Vector((a
[0], b
[1], a
[2]))
3236 vs
[2] = transform
@ Vector((b
[0], b
[1], a
[2]))
3237 vs
[3] = transform
@ Vector((b
[0], a
[1], a
[2]))
3238 vs
[4] = transform
@ Vector((a
[0], a
[1], b
[2]))
3239 vs
[5] = transform
@ Vector((a
[0], b
[1], b
[2]))
3240 vs
[6] = transform
@ Vector((b
[0], b
[1], b
[2]))
3241 vs
[7] = transform
@ Vector((b
[0], a
[1], b
[2]))
3243 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3244 (0,4),(1,5),(2,6),(3,7)]
3249 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3250 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3251 cv_view_colours
+= [colour
, colour
]
3256 # Draw line with colour
3258 def cv_draw_line( p0
, p1
, colour
):
3260 global cv_view_verts
, cv_view_colours
3262 cv_view_verts
+= [p0
,p1
]
3263 cv_view_colours
+= [colour
, colour
]
3267 # Draw line with colour(s)
3269 def cv_draw_line2( p0
, p1
, c0
, c1
):
3271 global cv_view_verts
, cv_view_colours
3273 cv_view_verts
+= [p0
,p1
]
3274 cv_view_colours
+= [c0
,c1
]
3280 def cv_tangent_basis( n
, tx
, ty
):
3282 if abs( n
[0] ) >= 0.57735027:#{
3301 # Draw coloured arrow
3303 def cv_draw_arrow( p0
, p1
, c0
, size
=0.15 ):
3305 global cv_view_verts
, cv_view_colours
3311 tx
= Vector((1,0,0))
3312 ty
= Vector((1,0,0))
3313 cv_tangent_basis( n
, tx
, ty
)
3315 cv_view_verts
+= [p0
,p1
, midpt
+(tx
-n
)*size
,midpt
, midpt
+(-tx
-n
)*size
,midpt
]
3316 cv_view_colours
+= [c0
,c0
,c0
,c0
,c0
,c0
]
3320 def cv_draw_line_dotted( p0
, p1
, c0
, dots
=10 ):
3322 global cv_view_verts
, cv_view_colours
3324 for i
in range(dots
):#{
3328 p2
= p0
*(1.0-t0
)+p1
*t0
3329 p3
= p0
*(1.0-t1
)+p1
*t1
3331 cv_view_verts
+= [p2
,p3
]
3332 cv_view_colours
+= [c0
,c0
]
3337 # Drawhandles of a bezier control point
3339 def cv_draw_bhandle( obj
, direction
, colour
):
3341 global cv_view_verts
, cv_view_colours
3344 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
3346 cv_view_verts
+= [p0
]
3347 cv_view_verts
+= [h0
]
3348 cv_view_colours
+= [colour
,colour
]
3352 # Draw a bezier curve (at fixed resolution 10)
3354 def cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
):
3356 global cv_view_verts
, cv_view_colours
3359 for i
in range(10):#{
3365 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
3367 cv_view_verts
+= [(last
[0],last
[1],last
[2])]
3368 cv_view_verts
+= [(p
[0],p
[1],p
[2])]
3369 cv_view_colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
3376 # I think this one extends the handles of the bezier otwards......
3378 def cv_draw_sbpath( o0
,o1
,c0
,c1
,s0
,s1
):
3380 global cv_view_course_i
3382 offs
= ((cv_view_course_i
% 2)*2-1) * cv_view_course_i
* 0.02
3384 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
3385 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
3386 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
3387 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
3389 cv_draw_bezier( p0
,h0
,p1
,h1
,c0
,c1
)
3393 # Flush the lines buffers. This is called often because god help you if you want
3394 # to do fixed, fast buffers in this catastrophic programming language.
3396 def cv_draw_lines():
3398 global cv_view_shader
, cv_view_verts
, cv_view_colours
3400 if len(cv_view_verts
) < 2:
3403 lines
= batch_for_shader(\
3404 cv_view_shader
, 'LINES', \
3405 { "pos":cv_view_verts
, "color":cv_view_colours
})
3407 lines
.draw( cv_view_shader
)
3410 cv_view_colours
= []
3413 # I dont remember what this does exactly
3415 def cv_draw_bpath( o0
,o1
,c0
,c1
):
3417 cv_draw_sbpath( o0
,o1
,c0
,c1
,1.0,1.0 )
3420 # Semi circle to show the limit. and some lines
3422 def draw_limit( obj
, center
, major
, minor
, amin
, amax
, colour
):
3424 global cv_view_verts
, cv_view_colours
3429 for x
in range(16):#{
3432 a0
= amin
*(1.0-t0
)+amax
*t0
3433 a1
= amin
*(1.0-t1
)+amax
*t1
3435 p0
= center
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
3436 p1
= center
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
3438 p0
=obj
.matrix_world
@ p0
3439 p1
=obj
.matrix_world
@ p1
3440 cv_view_verts
+= [p0
,p1
]
3441 cv_view_colours
+= [colour
,colour
]
3444 cv_view_verts
+= [p0
,center
]
3445 cv_view_colours
+= [colour
,colour
]
3448 cv_view_verts
+= [p1
,center
]
3449 cv_view_colours
+= [colour
,colour
]
3453 cv_view_verts
+= [center
+major
*1.2*f
,center
+major
*f
*0.8]
3454 cv_view_colours
+= [colour
,colour
]
3459 # Cone and twist limit
3461 def draw_cone_twist( center
, vx
, vy
, va
):
3463 global cv_view_verts
, cv_view_colours
3464 axis
= vy
.cross( vx
)
3469 cv_view_verts
+= [center
, center
+va
*size
]
3470 cv_view_colours
+= [ (1,1,1), (1,1,1) ]
3472 for x
in range(32):#{
3473 t0
= (x
/32) * math
.tau
3474 t1
= ((x
+1)/32) * math
.tau
3481 p0
= center
+ (axis
+ vx
*c0
+ vy
*s0
).normalized() * size
3482 p1
= center
+ (axis
+ vx
*c1
+ vy
*s1
).normalized() * size
3484 col0
= ( abs(c0
), abs(s0
), 0.0, 1.0 )
3485 col1
= ( abs(c1
), abs(s1
), 0.0, 1.0 )
3487 cv_view_verts
+= [center
, p0
, p0
, p1
]
3488 cv_view_colours
+= [ (0,0,0), col0
, col0
, col1
]
3494 # Draws constraints and stuff for the skeleton. This isnt documented and wont be
3496 def draw_skeleton_helpers( obj
):
3498 global cv_view_verts
, cv_view_colours
3500 if obj
.data
.pose_position
!= 'REST':#{
3504 for bone
in obj
.data
.bones
:#{
3506 a
= Vector((bone
.SR_data
.collider_min
[0],
3507 bone
.SR_data
.collider_min
[1],
3508 bone
.SR_data
.collider_min
[2]))
3509 b
= Vector((bone
.SR_data
.collider_max
[0],
3510 bone
.SR_data
.collider_max
[1],
3511 bone
.SR_data
.collider_max
[2]))
3513 if bone
.SR_data
.collider
== '1':#{
3515 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
3516 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
3517 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
3518 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
3519 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
3520 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
3521 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
3522 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
3524 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
3525 (0,4),(1,5),(2,6),(3,7)]
3531 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3532 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3533 cv_view_colours
+= [(0.5,0.5,0.5),(0.5,0.5,0.5)]
3536 elif bone
.SR_data
.collider
== '2':#{
3541 for i
in range(3):#{
3542 if abs(v0
[i
]) > largest
:#{
3543 largest
= abs(v0
[i
])
3548 v1
= Vector((0,0,0))
3549 v1
[major_axis
] = 1.0
3551 tx
= Vector((0,0,0))
3552 ty
= Vector((0,0,0))
3554 cv_tangent_basis( v1
, tx
, ty
)
3555 r
= (abs(tx
.dot( v0
)) + abs(ty
.dot( v0
))) * 0.25
3556 l
= v0
[ major_axis
] - r
*2
3558 p0
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
*-0.5 )
3559 p1
= obj
.matrix_world
@Vector( c
+ (a
+b
)*0.5 + v1
*l
* 0.5 )
3561 colour
= [0.2,0.2,0.2]
3562 colour
[major_axis
] = 0.5
3564 cv_draw_halfsphere( p0
, -v1
, ty
, tx
, r
, colour
)
3565 cv_draw_halfsphere( p1
, v1
, ty
, tx
, r
, colour
)
3566 cv_draw_line( p0
+tx
* r
, p1
+tx
* r
, colour
)
3567 cv_draw_line( p0
+tx
*-r
, p1
+tx
*-r
, colour
)
3568 cv_draw_line( p0
+ty
* r
, p1
+ty
* r
, colour
)
3569 cv_draw_line( p0
+ty
*-r
, p1
+ty
*-r
, colour
)
3575 center
= obj
.matrix_world
@ c
3576 if bone
.SR_data
.cone_constraint
:#{
3577 vx
= Vector([bone
.SR_data
.conevx
[_
] for _
in range(3)])
3578 vy
= Vector([bone
.SR_data
.conevy
[_
] for _
in range(3)])
3579 va
= Vector([bone
.SR_data
.coneva
[_
] for _
in range(3)])
3580 draw_cone_twist( center
, vx
, vy
, va
)
3585 def cv_ent_gate( obj
):
3587 global cv_view_verts
, cv_view_colours
3589 if obj
.type != 'MESH': return
3591 mesh_data
= obj
.data
.SR_data
.ent_gate
[0]
3592 data
= obj
.SR_data
.ent_gate
[0]
3593 dims
= mesh_data
.dimensions
3596 c
= Vector((0,0,dims
[2]))
3598 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
3599 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
3600 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
3601 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
3602 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
3603 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
3604 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
3605 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
3606 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
3608 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
3610 r3d
= bpy
.context
.area
.spaces
.active
.region_3d
3612 p0
= r3d
.view_matrix
.inverted().translation
3613 v0
= (obj
.matrix_world
@Vector((0,0,0))) - p0
3614 v1
= obj
.matrix_world
.to_3x3() @ Vector((0,1,0))
3616 if v0
.dot(v1
) > 0.0: cc
= (0,1,0)
3622 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
3623 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
3624 cv_view_colours
+= [cc
,cc
]
3628 if data
.target
!= None:
3629 cv_draw_arrow( obj
.location
, data
.target
.location
, sw
)
3632 def cv_ent_volume( obj
):
3634 global cv_view_verts
, cv_view_colours
3636 data
= obj
.SR_data
.ent_volume
[0]
3638 if data
.subtype
== '0':#{
3639 cv_draw_ucube( obj
.matrix_world
, (0,1,0) )
3642 cv_draw_line( obj
.location
, data
.target
.location
, (0,1,0) )
3645 elif data
.subtype
== '1':#{
3646 cv_draw_ucube( obj
.matrix_world
, (1,1,0) )
3649 cv_draw_line( obj
.location
, data
.target
.location
, (1,1,0) )
3654 def dijkstra( graph
, start_node
, target_node
):
3656 unvisited
= [_
for _
in graph
]
3661 shortest_path
[n
] = 9999999.999999
3662 shortest_path
[start_node
] = 0
3665 current_min_node
= None
3666 for n
in unvisited
:#{
3667 if current_min_node
== None:
3668 current_min_node
= n
3669 elif shortest_path
[n
] < shortest_path
[current_min_node
]:
3670 current_min_node
= n
3673 for branch
in graph
[current_min_node
]:#{
3674 tentative_value
= shortest_path
[current_min_node
]
3675 tentative_value
+= graph
[current_min_node
][branch
]
3676 if tentative_value
< shortest_path
[branch
]:#{
3677 shortest_path
[branch
] = tentative_value
3678 previous_nodes
[branch
] = current_min_node
3682 unvisited
.remove(current_min_node
)
3687 while node
!= start_node
:#{
3690 if node
not in previous_nodes
: return None
3691 node
= previous_nodes
[node
]
3694 # Add the start node manually
3695 path
.append(start_node
)
3701 def __init__(_
,points
,graph
,subsections
):#{
3704 _
.subsections
= subsections
3708 def create_node_graph( curves
, gates
):
3710 # add endpoints of curves
3717 for c
in range(len(curves
)):#{
3718 for s
in range(len(curves
[c
].data
.splines
)):#{
3719 spline
= curves
[c
].data
.splines
[s
]
3720 l
= len(spline
.points
)
3723 dist
= round(spline
.calc_length(),2)
3726 ib
= point_count
+l
-1
3728 graph
[ia
] = { ib
: dist
}
3729 graph
[ib
] = { ia
: dist
}
3731 for i
in range(len(spline
.points
)):#{
3732 wco
= curves
[c
].matrix_world
@ spline
.points
[i
].co
3733 route_points
.append(Vector((wco
[0],wco
[1],wco
[2]+0.5)))
3738 if i
== 0: previous
= -1
3739 if i
== len(spline
.points
)-1: proxima
= -1
3741 subsections
.append((spline_count
,previous
,proxima
))
3750 graph_keys
= list(graph
)
3751 for i
in range(len(graph_keys
)-1):#{
3752 for j
in range(i
+1, len(graph_keys
)):#{
3753 if i
%2==0 and i
+1==j
: continue
3757 pi
= route_points
[ni
]
3758 pj
= route_points
[nj
]
3760 dist
= round((pj
-pi
).magnitude
,2)
3763 graph
[ni
][nj
] = dist
3764 graph
[nj
][ni
] = dist
3769 # add and link gates( by name )
3770 for gate
in gates
:#{
3771 v1
= gate
.matrix_world
.to_3x3() @ Vector((0,1,0))
3772 if gate
.SR_data
.ent_gate
[0].target
:
3775 graph
[ gate
.name
] = {}
3777 for i
in range(len(graph_keys
)):#{
3779 pi
= route_points
[ni
]
3781 v0
= pi
-gate
.location
3782 if v0
.dot(v1
) < 0.0: continue
3784 dist
= round(v0
.magnitude
,2)
3787 graph
[ gate
.name
][ ni
] = dist
3788 graph
[ ni
][ gate
.name
] = dist
3793 return dij_graph(route_points
,graph
,subsections
)
3796 def solve_graph( dij
, start
, end
):
3798 path
= dijkstra( dij
.graph
, end
, start
)
3802 for sj
in range(1,len(path
)-2):#{
3805 map0
= dij
.subsections
[i0
]
3806 map1
= dij
.subsections
[i1
]
3808 if map0
[0] == map1
[0]:#{
3809 if map0
[1] == -1: direction
= 2
3814 map0
= dij
.subsections
[i0
]
3815 i1
= map0
[direction
]
3829 full
.append( path
[-2] )
3834 def cv_draw_route( route
, dij
):
3836 pole
= Vector((0.2,0.2,10))
3837 hat
= Vector((1,8,0.2))
3838 cc
= (route
.SR_data
.ent_route
[0].colour
[0],
3839 route
.SR_data
.ent_route
[0].colour
[1],
3840 route
.SR_data
.ent_route
[0].colour
[2])
3842 cv_draw_ucube(route
.matrix_world
,cc
,Vector((0.5,-7.5,6)),\
3843 Vector((0,-6.5,5.5)))
3844 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5, 0.5,0)) )
3845 cv_draw_ucube(route
.matrix_world
,cc
,pole
, Vector(( 0.5,-13.5,0)) )
3846 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5, 12)) )
3847 cv_draw_ucube(route
.matrix_world
,cc
,hat
, Vector((-0.5,-6.5,-1)) )
3849 checkpoints
= route
.SR_data
.ent_route
[0].gates
3851 for i
in range(len(checkpoints
)):#{
3852 gi
= checkpoints
[i
].target
3853 gj
= checkpoints
[(i
+1)%len(checkpoints
)].target
3856 dest
= gi
.SR_data
.ent_gate
[0].target
3858 cv_draw_line_dotted( gi
.location
, dest
.location
, cc
)
3862 if gi
==gj
: continue # error?
3863 if not gi
or not gj
: continue
3865 path
= solve_graph( dij
, gi
.name
, gj
.name
)
3868 cv_draw_arrow(gi
.location
,dij
.points
[path
[0]],cc
,1.5)
3869 cv_draw_arrow(dij
.points
[path
[len(path
)-1]],gj
.location
,cc
,1.5)
3870 for j
in range(len(path
)-1):#{
3873 o0
= dij
.points
[ i0
]
3874 o1
= dij
.points
[ i1
]
3875 cv_draw_arrow(o0
,o1
,cc
,1.5)
3879 cv_draw_line_dotted( gi
.location
, gj
.location
, cc
)
3886 global cv_view_shader
3887 global cv_view_verts
3888 global cv_view_colours
3889 global cv_view_course_i
3891 cv_view_course_i
= 0
3893 cv_view_colours
= []
3895 cv_view_shader
.bind()
3896 gpu
.state
.depth_mask_set(False)
3897 gpu
.state
.line_width_set(2.0)
3898 gpu
.state
.face_culling_set('BACK')
3899 gpu
.state
.depth_test_set('LESS')
3900 gpu
.state
.blend_set('NONE')
3906 for obj
in bpy
.context
.collection
.objects
:#{
3907 if obj
.type == 'ARMATURE':#{
3908 if obj
.data
.pose_position
== 'REST':
3909 draw_skeleton_helpers( obj
)
3912 ent_type
= obj_ent_type( obj
)
3914 if ent_type
== 'ent_gate':#{
3916 route_gates
+= [obj
]
3918 elif ent_type
== 'ent_route_node':#{
3919 if obj
.type == 'CURVE':#{
3920 route_curves
+= [obj
]
3923 elif ent_type
== 'ent_route':
3925 elif ent_type
== 'ent_volume':#{
3926 cv_ent_volume( obj
)
3928 elif ent_type
== 'ent_audio':#{
3929 if obj
.SR_data
.ent_audio
[0].flag_3d
:
3930 cv_draw_sphere( obj
.location
, obj
.scale
[0], (1,1,0) )
3932 elif ent_type
== 'ent_font':#{
3933 data
= obj
.SR_data
.ent_font
[0]
3935 for i
in range(len(data
.variants
)):#{
3936 sub
= data
.variants
[i
].mesh
3937 if not sub
: continue
3939 for ch
in data
.glyphs
:#{
3940 mini
= (ch
.bounds
[0],ch
.bounds
[1])
3941 maxi
= (ch
.bounds
[2]+mini
[0],ch
.bounds
[3]+mini
[1])
3942 p0
= sub
.matrix_world
@ Vector((mini
[0],0.0,mini
[1]))
3943 p1
= sub
.matrix_world
@ Vector((maxi
[0],0.0,mini
[1]))
3944 p2
= sub
.matrix_world
@ Vector((maxi
[0],0.0,maxi
[1]))
3945 p3
= sub
.matrix_world
@ Vector((mini
[0],0.0,maxi
[1]))
3947 if i
== data
.variants_index
: cc
= (0.5,0.5,0.5)
3950 cv_view_verts
+= [p0
,p1
,p1
,p2
,p2
,p3
,p3
,p0
]
3951 cv_view_colours
+= [cc
,cc
,cc
,cc
,cc
,cc
,cc
,cc
]
3955 elif ent_type
== 'ent_skateshop':#{
3956 data
= obj
.SR_data
.ent_skateshop
[0]
3957 display
= data
.mark_display
3958 info
= data
.mark_info
3960 if data
.tipo
== '0':#{
3965 rack
= data
.mark_rack
3967 rack_cu
= Vector((3.15,2.0,0.1))*0.5
3968 rack_co
= Vector((0.0,0.0,0.0))
3969 display_cu
= Vector((0.3,1.2,0.1))*0.5
3970 display_co
= Vector((0.0,0.0,0.1))*0.5
3971 info_cu
= Vector((1.2,0.01,0.3))*0.5
3972 info_co
= Vector((0.0,0.0,0.0))*0.5
3974 elif data
.tipo
== '1':#{
3978 display_cu
= Vector((0.4,0.4,2.0))*0.5
3979 display_co
= Vector((0.0,0.0,1.0))*0.5
3980 info_cu
= Vector((1.2,0.01,0.3))*0.5
3981 info_co
= Vector((0.0,0.0,0.0))*0.5
3983 elif data
.tipo
== '2':#{
3987 display_cu
= Vector((1.0,1.0,0.5))*0.5
3988 display_co
= Vector((0.0,0.0,0.5))*0.5
3989 info_cu
= Vector((1.2,0.01,0.3))*0.5
3990 info_co
= Vector((0.0,0.0,0.0))*0.5
3994 cv_draw_ucube( rack
.matrix_world
, cc
, rack_cu
, rack_co
)
3996 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
3998 cv_draw_ucube( info
.matrix_world
, cc2
, info_cu
, info_co
)
4000 elif ent_type
== 'ent_swspreview':#{
4002 data
= obj
.SR_data
.ent_swspreview
[0]
4003 display
= data
.mark_display
4004 display1
= data
.mark_display1
4005 display_cu
= Vector((0.3,1.2,0.1))*0.5
4006 display_co
= Vector((0.0,0.0,0.1))*0.5
4008 cv_draw_ucube( display
.matrix_world
, cc1
, display_cu
, display_co
)
4010 cv_draw_ucube(display1
.matrix_world
, cc1
, display_cu
, display_co
)
4012 elif ent_type
== 'ent_menuitem':#{
4013 for i
,col
in enumerate(obj
.users_collection
):#{
4014 colour32
= hash_djb2( col
.name
)
4015 r
= pow(((colour32
) & 0xff) / 255.0, 2.2 )
4016 g
= pow(((colour32
>>8 ) & 0xff) / 255.0, 2.2 )
4017 b
= pow(((colour32
>>16) & 0xff) / 255.0, 2.2 )
4019 vs
= [None for _
in range(8)]
4021 for j
in range(8):#{
4022 v0
= Vector([(obj
.bound_box
[j
][z
]+\
4023 ((-1.0 if obj
.bound_box
[j
][z
]<0.0 else 1.0)*scale
)) \
4025 vs
[j
] = obj
.matrix_world
@ v0
4027 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
4028 (0,4),(1,5),(2,6),(3,7)]
4032 cv_view_verts
+= [(v0
[0],v0
[1],v0
[2])]
4033 cv_view_verts
+= [(v1
[0],v1
[1],v1
[2])]
4034 cv_view_colours
+= [cc
,cc
]
4039 data
= obj
.SR_data
.ent_menuitem
[0]
4040 if data
.tipo
== '4':#{
4041 if data
.slider_minloc
and data
.slider_maxloc
:#{
4042 v0
= data
.slider_minloc
.location
4043 v1
= data
.slider_maxloc
.location
4044 cv_draw_line( v0
, v1
, cc
)
4048 colour32
= hash_djb2(obj
.name
)
4049 r
= ((colour32
) & 0xff) / 255.0
4050 g
= ((colour32
>>8 ) & 0xff) / 255.0
4051 b
= ((colour32
>>16) & 0xff) / 255.0
4053 origin
= obj
.location
+ (Vector((r
,g
,b
))*2.0-Vector((1.0,1.0,1.0)))\
4058 if data
.tipo
!= '0':#{
4059 if data
.tipo
== '4':#{
4061 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4064 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4069 cv_draw_arrow( origin
, data
.link0
.location
, cc
, size
)
4072 cv_draw_arrow( origin
, data
.link1
.location
, cc
, size
)
4075 cv_draw_arrow( origin
, data
.link2
.location
, cc
, size
)
4078 cv_draw_arrow( origin
, data
.link3
.location
, cc
, size
)
4086 dij
= create_node_graph( route_curves
, route_gates
)
4088 #cv_draw_route_map( route_nodes )
4089 for route
in routes
:#{
4090 cv_draw_route( route
, dij
)
4097 classes
= [ SR_INTERFACE
, SR_MATERIAL_PANEL
,\
4098 SR_COLLECTION_SETTINGS
, SR_SCENE_SETTINGS
, \
4099 SR_COMPILE
, SR_COMPILE_THIS
, SR_MIRROR_BONE_X
,\
4101 SR_OBJECT_ENT_GATE
, SR_MESH_ENT_GATE
, SR_OBJECT_ENT_SPAWN
, \
4102 SR_OBJECT_ENT_ROUTE_ENTRY
, SR_UL_ROUTE_NODE_LIST
, \
4103 SR_OBJECT_ENT_ROUTE
, SR_OT_ROUTE_LIST_NEW_ITEM
,\
4104 SR_OT_GLYPH_LIST_NEW_ITEM
, SR_OT_GLYPH_LIST_DEL_ITEM
,\
4105 SR_OT_GLYPH_LIST_MOVE_ITEM
,\
4106 SR_OT_AUDIO_LIST_NEW_ITEM
,SR_OT_AUDIO_LIST_DEL_ITEM
,\
4107 SR_OT_FONT_VARIANT_LIST_NEW_ITEM
,SR_OT_FONT_VARIANT_LIST_DEL_ITEM
,\
4108 SR_OT_COPY_ENTITY_DATA
, \
4109 SR_OBJECT_ENT_VOLUME
, \
4110 SR_UL_AUDIO_LIST
, SR_OBJECT_ENT_AUDIO_FILE_ENTRY
,\
4111 SR_OT_ROUTE_LIST_DEL_ITEM
,\
4112 SR_OBJECT_ENT_AUDIO
,SR_OBJECT_ENT_MARKER
,SR_OBJECT_ENT_GLYPH
,\
4113 SR_OBJECT_ENT_FONT_VARIANT
,
4114 SR_OBJECT_ENT_GLYPH_ENTRY
,\
4115 SR_UL_FONT_VARIANT_LIST
,SR_UL_FONT_GLYPH_LIST
,\
4116 SR_OBJECT_ENT_FONT
,SR_OBJECT_ENT_TRAFFIC
,SR_OBJECT_ENT_SKATESHOP
,\
4117 SR_OBJECT_ENT_WORKSHOP_PREVIEW
,SR_OBJECT_ENT_MENU_ITEM
,\
4118 SR_OBJECT_ENT_WORLD_INFO
,SR_OBJECT_ENT_CCMD
,\
4120 SR_OBJECT_PROPERTIES
, SR_LIGHT_PROPERTIES
, SR_BONE_PROPERTIES
,
4121 SR_MESH_PROPERTIES
, SR_MATERIAL_PROPERTIES \
4127 bpy
.utils
.register_class(c
)
4129 bpy
.types
.Scene
.SR_data
= \
4130 bpy
.props
.PointerProperty(type=SR_SCENE_SETTINGS
)
4131 bpy
.types
.Collection
.SR_data
= \
4132 bpy
.props
.PointerProperty(type=SR_COLLECTION_SETTINGS
)
4134 bpy
.types
.Object
.SR_data
= \
4135 bpy
.props
.PointerProperty(type=SR_OBJECT_PROPERTIES
)
4136 bpy
.types
.Light
.SR_data
= \
4137 bpy
.props
.PointerProperty(type=SR_LIGHT_PROPERTIES
)
4138 bpy
.types
.Bone
.SR_data
= \
4139 bpy
.props
.PointerProperty(type=SR_BONE_PROPERTIES
)
4140 bpy
.types
.Mesh
.SR_data
= \
4141 bpy
.props
.PointerProperty(type=SR_MESH_PROPERTIES
)
4142 bpy
.types
.Material
.SR_data
= \
4143 bpy
.props
.PointerProperty(type=SR_MATERIAL_PROPERTIES
)
4145 global cv_view_draw_handler
4146 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
4147 cv_draw
,(),'WINDOW','POST_VIEW')
4153 bpy
.utils
.unregister_class(c
)
4155 global cv_view_draw_handler
4156 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')
4159 # ---------------------------------------------------------------------------- #
4163 # ---------------------------------------------------------------------------- #
4165 # Transliteration of: #
4166 # https://github.com/phoboslab/qoi/blob/master/qoi.h #
4168 # Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org #
4169 # SPDX-License-Identifier: MIT #
4170 # QOI - The "Quite OK Image" format for fast, lossless image compression #
4172 # ---------------------------------------------------------------------------- #
4174 class qoi_rgba_t(Structure
):
4177 _fields_
= [("r",c_uint8
),
4183 QOI_OP_INDEX
= 0x00 # 00xxxxxx
4184 QOI_OP_DIFF
= 0x40 # 01xxxxxx
4185 QOI_OP_LUMA
= 0x80 # 10xxxxxx
4186 QOI_OP_RUN
= 0xc0 # 11xxxxxx
4187 QOI_OP_RGB
= 0xfe # 11111110
4188 QOI_OP_RGBA
= 0xff # 11111111
4190 QOI_MASK_2
= 0xc0 # 11000000
4192 def qoi_colour_hash( c
):
4194 return c
.r
*3 + c
.g
*5 + c
.b
*7 + c
.a
*11
4199 return (a
.r
==b
.r
) and (a
.g
==b
.g
) and (a
.b
==b
.b
) and (a
.a
==b
.a
)
4204 return bytearray([ (0xff000000 & v
) >> 24, \
4205 (0x00ff0000 & v
) >> 16, \
4206 (0x0000ff00 & v
) >> 8, \
4210 def qoi_encode( img
):
4214 print(F
"{' ':<30}",end
='\r')
4215 print(F
"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end
='\r')
4217 index
= [ qoi_rgba_t() for _
in range(64) ]
4221 data
.extend( bytearray(c_uint32(0x66696f71)) )
4222 data
.extend( qoi_32bit( img
.size
[0] ) )
4223 data
.extend( qoi_32bit( img
.size
[1] ) )
4224 data
.extend( bytearray(c_uint8(4)) )
4225 data
.extend( bytearray(c_uint8(0)) )
4228 px_prev
= qoi_rgba_t()
4229 px_prev
.r
= c_uint8(0)
4230 px_prev
.g
= c_uint8(0)
4231 px_prev
.b
= c_uint8(0)
4232 px_prev
.a
= c_uint8(255)
4240 px_len
= img
.size
[0] * img
.size
[1]
4241 paxels
= [ int(min(max(_
,0),1)*255) for _
in img
.pixels
]
4243 for px_pos
in range( px_len
): #{
4244 idx
= px_pos
* img
.channels
4247 px
.r
= paxels
[idx
+min(0,nc
)]
4248 px
.g
= paxels
[idx
+min(1,nc
)]
4249 px
.b
= paxels
[idx
+min(2,nc
)]
4250 px
.a
= paxels
[idx
+min(3,nc
)]
4252 if qoi_eq( px
, px_prev
): #{
4255 if (run
== 62) or (px_pos
== px_len
-1): #{
4256 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4262 data
.extend( bytearray( c_uint8(QOI_OP_RUN |
(run
-1))) )
4266 index_pos
= qoi_colour_hash(px
) % 64
4268 if qoi_eq( index
[index_pos
], px
): #{
4269 data
.extend( bytearray( c_uint8(QOI_OP_INDEX | index_pos
)) )
4272 index
[ index_pos
].r
= px
.r
4273 index
[ index_pos
].g
= px
.g
4274 index
[ index_pos
].b
= px
.b
4275 index
[ index_pos
].a
= px
.a
4277 if px
.a
== px_prev
.a
: #{
4278 vr
= int(px
.r
) - int(px_prev
.r
)
4279 vg
= int(px
.g
) - int(px_prev
.g
)
4280 vb
= int(px
.b
) - int(px_prev
.b
)
4285 if (vr
> -3) and (vr
< 2) and\
4286 (vg
> -3) and (vg
< 2) and\
4287 (vb
> -3) and (vb
< 2):
4289 op
= QOI_OP_DIFF |
(vr
+2) << 4 |
(vg
+2) << 2 |
(vb
+2)
4290 data
.extend( bytearray( c_uint8(op
) ))
4292 elif (vg_r
> -9) and (vg_r
< 8) and\
4293 (vg
> -33) and (vg
< 32 ) and\
4294 (vg_b
> -9) and (vg_b
< 8):
4296 op
= QOI_OP_LUMA |
(vg
+32)
4297 delta
= (vg_r
+8) << 4 |
(vg_b
+ 8)
4298 data
.extend( bytearray( c_uint8(op
) ) )
4299 data
.extend( bytearray( c_uint8(delta
) ))
4302 data
.extend( bytearray( c_uint8(QOI_OP_RGB
) ) )
4303 data
.extend( bytearray( c_uint8(px
.r
) ))
4304 data
.extend( bytearray( c_uint8(px
.g
) ))
4305 data
.extend( bytearray( c_uint8(px
.b
) ))
4309 data
.extend( bytearray( c_uint8(QOI_OP_RGBA
) ) )
4310 data
.extend( bytearray( c_uint8(px
.r
) ))
4311 data
.extend( bytearray( c_uint8(px
.g
) ))
4312 data
.extend( bytearray( c_uint8(px
.b
) ))
4313 data
.extend( bytearray( c_uint8(px
.a
) ))
4326 data
.extend( bytearray( c_uint8(0) ))
4327 data
.extend( bytearray( c_uint8(1) ))
4328 bytearray_align_to( data
, 16, b
'\x00' )