2 # Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
8 from mathutils
import *
9 from gpu_extras
.batch
import batch_for_shader
12 "name":"Carve exporter",
13 "author": "Harry Godden (hgn)",
20 "category":"Import/Export",
23 class mdl_vert(Structure
):
25 _fields_
= [("co",c_float
*3),
29 ("weights",c_uint16
*4),
32 class mdl_submesh(Structure
):
34 _fields_
= [("indice_start",c_uint32
),
35 ("indice_count",c_uint32
),
36 ("vertex_start",c_uint32
),
37 ("vertex_count",c_uint32
),
38 ("bbx",(c_float
*3)*2),
39 ("material_id",c_uint32
)] # index into the material array
41 class mdl_material(Structure
):
43 _fields_
= [("pstr_name",c_uint32
)]
45 class mdl_node(Structure
):
47 _fields_
= [("co",c_float
*3),
50 ("submesh_start",c_uint32
),
51 ("submesh_count",c_uint32
),
52 ("classtype",c_uint32
),
55 ("pstr_name",c_uint32
)]
57 class mdl_header(Structure
):
59 _fields_
= [("identifier",c_uint32
),
61 ("file_length",c_uint32
),
62 ("vertex_count",c_uint32
),
63 ("vertex_offset",c_uint32
),
65 ("indice_count",c_uint32
),
66 ("indice_offset",c_uint32
),
68 ("submesh_count",c_uint32
),
69 ("submesh_offset",c_uint32
),
71 ("material_count",c_uint32
),
72 ("material_offset",c_uint32
),
74 ("node_count",c_uint32
),
75 ("node_offset",c_uint32
),
77 ("anim_count",c_uint32
),
78 ("anim_offset",c_uint32
),
80 ("strings_offset",c_uint32
),
81 ("entdata_offset",c_uint32
),
82 ("animdata_offset",c_uint32
)
85 class mdl_animation(Structure
):
87 _fields_
= [("pstr_name",c_uint32
),
92 class mdl_keyframe(Structure
):
94 _fields_
= [("co",c_float
*3),
99 # ==========================================
101 class classtype_gate(Structure
):
103 _fields_
= [("target",c_uint32
),
106 class classtype_block(Structure
):
108 _fields_
= [("bbx",(c_float
*3)*2)]
110 class classtype_spawn(Structure
):
112 _fields_
= [("temp",c_uint32
)]
114 class classtype_water(Structure
):
116 _fields_
= [("temp",c_uint32
)]
118 class classtype_car_path(Structure
):
120 _fields_
= [("target",c_uint32
),
121 ("target1",c_uint32
)]
123 class classtype_instance(Structure
):
125 _fields_
= [("pstr_file",c_uint32
)]
127 class classtype_capsule(Structure
):
129 _fields_
= [("height",c_float
),
132 class classtype_route_node(Structure
):
134 _fields_
= [("target",c_uint32
),
135 ("target1",c_uint32
)]
137 class classtype_route(Structure
):
139 _fields_
= [("id_start",c_uint32
),
140 ("colour",c_float
*3)]
142 class classtype_skin(Structure
):
144 _fields_
= [("skeleton",c_uint32
)]
146 class classtype_skeleton(Structure
):
148 _fields_
= [("channels",c_uint32
),
149 ("ik_count",c_uint32
),
150 ("collider_count",c_uint32
),
151 ("anim_start",c_uint32
),
152 ("anim_count",c_uint32
)]
154 class classtype_bone(Structure
):
156 _fields_
= [("deform",c_uint32
),
157 ("ik_target",c_uint32
),
158 ("ik_pole",c_uint32
),
159 ("collider",c_uint32
),
160 ("use_limits",c_uint32
),
161 ("angle_limits",(c_float
*3)*2),
162 ("hitbox",(c_float
*3)*2)]
164 class classtype_achievement_box(Structure
):
166 _fields_
= [("pstr_name",c_uint32
),
167 ("trigger",c_uint32
)]
169 class classtype_audio(Structure
):
171 _fields_
= [("pstr_file",c_uint32
),
176 # ==============================================================================
178 def write_model(collection_name
):
179 print( F
"Model graph | Create mode '{collection_name}'" )
181 header
= mdl_header()
182 header
.identifier
= 0xABCD0000
184 header
.vertex_count
= 0
185 header
.indice_count
= 0
186 header
.submesh_count
= 0
187 header
.node_count
= 0
188 header
.material_count
= 0
189 header
.file_length
= 0
209 def emplace_string( s
):
210 nonlocal string_cache
, strings_buffer
212 if s
in string_cache
:
213 return string_cache
[s
]
215 string_cache
[s
] = len( strings_buffer
)
216 strings_buffer
+= (s
+'\0').encode('utf-8')
217 return string_cache
[s
]
219 def emplace_material( mat
):
220 nonlocal material_cache
, material_buffer
225 if mat
.name
in material_cache
:
226 return material_cache
[mat
.name
]
228 material_cache
[mat
.name
] = header
.material_count
229 dest
= mdl_material()
230 dest
.pstr_name
= emplace_string( mat
.name
)
231 material_buffer
+= [dest
]
233 header
.material_count
+= 1
234 return material_cache
[mat
.name
]
236 # Create root or empty node and materials
237 # this is to designate id 0 as 'NULL'
239 none_material
= c_uint32(69)
240 none_material
.name
= ""
241 emplace_material( none_material
)
254 root
.pstr_name
= emplace_string('')
255 root
.submesh_start
= 0
256 root
.submesh_count
= 0
259 node_buffer
+= [root
]
263 print( " assigning ids" )
264 collection
= bpy
.data
.collections
[collection_name
]
267 # ==========================================
269 header
.node_count
= 0
272 uid
= header
.node_count
273 header
.node_count
+= 1
276 print( " creating scene graph" )
280 graph
["children"] = []
281 graph
["uid"] = _uid()
282 graph
["parent"] = None
284 graph_lookup
= {} # object can lookup its graph def here
286 for obj
in collection
.all_objects
:
289 def _extend( p
, n
, d
):
293 tree
["children"] = []
299 if n
.type == 'ARMATURE':
300 tree
["bones"] = [None] # None is the root transform
302 tree
["collider_count"] = 0
304 def _extendb( p
, n
, d
):
309 btree
["uid"] = _uid()
310 btree
["children"] = []
313 tree
["bones"] += [n
.name
]
316 _extendb( btree
, c
, d
+1 )
318 for c
in tree
['obj'].pose
.bones
[n
.name
].constraints
:
320 btree
["target"] = c
.subtarget
321 btree
["pole"] = c
.pole_subtarget
322 tree
["ik_count"] += 1
324 if n
.cv_data
.collider
:
325 tree
['collider_count'] += 1
327 btree
['deform'] = n
.use_deform
328 p
['children'] += [btree
]
330 for b
in n
.data
.bones
:
332 _extendb( tree
, b
, d
+1 )
334 for obj1
in n
.children
:
336 for c1
in obj1
.users_collection
:
338 _extend( tree
, obj1
, d
+1 )
341 p
["children"] += [tree
]
342 graph_lookup
[n
] = tree
344 _extend( graph
, obj
, 1 )
348 for c
in p
['children']:
350 yield from _graph_iter(c
)
352 it
= _graph_iter(graph
)
354 root
.parent
= 0xffffffff
357 # ==============================================
358 it
= _graph_iter(graph
)
359 print( " compiling data" )
361 if 'obj' in node_def
:
362 obj
= node_def
['obj']
365 elif 'bone' in node_def
:
366 obj
= node_def
['bone']
368 objco
= obj
.head_local
370 depth
= node_def
['depth']
371 uid
= node_def
['uid']
374 node
.co
[0] = objco
[0]
375 node
.co
[1] = objco
[2]
376 node
.co
[2] = -objco
[1]
378 # Convert rotation quat to our space type
379 quat
= obj
.matrix_local
.to_quaternion()
386 node
.s
[0] = obj
.tail_local
[0] - node
.co
[0]
387 node
.s
[1] = obj
.tail_local
[2] - node
.co
[1]
388 node
.s
[2] = -obj
.tail_local
[1] - node
.co
[2]
390 node
.s
[0] = obj
.scale
[0]
391 node
.s
[1] = obj
.scale
[2]
392 node
.s
[2] = obj
.scale
[1]
394 node
.pstr_name
= emplace_string( obj
.name
)
396 if node_def
["parent"]:
397 node
.parent
= node_def
["parent"]["uid"]
400 classtype
= 'k_classtype_bone'
401 elif objt
== 'ARMATURE':
402 classtype
= 'k_classtype_skeleton'
404 classtype
= obj
.cv_data
.classtype
407 # =================================================================
410 # Dont use the cache if we have modifiers that affect the normals
418 for mod
in obj
.modifiers
:
419 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
420 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
422 can_use_cache
= False
424 if mod
.type == 'ARMATURE':
425 classtype
= 'k_classtype_skin'
426 armature_def
= graph_lookup
[mod
.object]
427 POSE_OR_REST_CACHE
= armature_def
['obj'].data
.pose_position
429 armature_def
['obj'].data
.pose_position
= 'REST'
431 if can_use_cache
and obj
.data
.name
in mesh_cache
:
432 ref
= mesh_cache
[obj
.data
.name
]
433 node
.submesh_start
= ref
.submesh_start
434 node
.submesh_count
= ref
.submesh_count
438 node
.submesh_start
= header
.submesh_count
439 node
.submesh_count
= 0
441 default_mat
= c_uint32(69)
442 default_mat
.name
= ""
444 dgraph
= bpy
.context
.evaluated_depsgraph_get()
445 data
= obj
.evaluated_get(dgraph
).data
446 data
.calc_loop_triangles()
447 data
.calc_normals_split()
449 mat_list
= data
.materials
if len(data
.materials
) > 0 else [default_mat
]
450 for material_id
, mat
in enumerate(mat_list
):
454 sm
.indice_start
= header
.indice_count
455 sm
.vertex_start
= header
.vertex_count
458 sm
.material_id
= emplace_material( mat
)
461 sm
.bbx
[0][i
] = 999999
462 sm
.bbx
[1][i
] = -999999
466 # Write the vertex / indice data
468 for tri_index
, tri
in enumerate(data
.loop_triangles
):
469 if tri
.material_index
!= material_id
:
473 vert
= data
.vertices
[tri
.vertices
[j
]]
475 vi
= data
.loops
[li
].vertex_index
478 norm
= data
.loops
[li
].normal
480 colour
= (255,255,255,255)
485 uv
= data
.uv_layers
.active
.data
[li
].uv
487 if data
.vertex_colors
:
488 colour
= data
.vertex_colors
.active
.data
[li
].color
489 colour
= (int(colour
[0]*255.0),\
490 int(colour
[1]*255.0),\
491 int(colour
[2]*255.0),\
492 int(colour
[3]*255.0))
497 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
498 if obj
.vertex_groups
[_
.group
].name
in \
499 armature_def
['bones']]
501 weight_groups
= sorted( src_groups
, key
= \
502 lambda a
: a
.weight
, reverse
=True )
505 if len(weight_groups
) > ml
:
506 g
= weight_groups
[ml
]
507 name
= obj
.vertex_groups
[g
.group
].name
511 groups
[ml
] = armature_def
['bones'].index(name
)
514 if len(weight_groups
) > 0:
515 inv_norm
= (1.0/tot
) * 65535.0
517 weights
[ml
] = int( weights
[ml
] * inv_norm
)
518 weights
[ml
] = min( weights
[ml
], 65535 )
519 weights
[ml
] = max( weights
[ml
], 0 )
522 m
= float(10**TOLERENCE
)
524 key
= (int(co
[0]*m
+0.5),\
546 indice_buffer
+= [boffa
[key
]]
548 index
= c_uint32(sm
.vertex_count
)
552 indice_buffer
+= [index
]
563 v
.colour
[0] = colour
[0]
564 v
.colour
[1] = colour
[1]
565 v
.colour
[2] = colour
[2]
566 v
.colour
[3] = colour
[3]
567 v
.weights
[0] = weights
[0]
568 v
.weights
[1] = weights
[1]
569 v
.weights
[2] = weights
[2]
570 v
.weights
[3] = weights
[3]
571 v
.groups
[0] = groups
[0]
572 v
.groups
[1] = groups
[1]
573 v
.groups
[2] = groups
[2]
574 v
.groups
[3] = groups
[3]
579 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
580 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
584 if sm
.vertex_count
== 0:
589 submesh_buffer
+= [sm
]
590 node
.submesh_count
+= 1
591 header
.submesh_count
+= 1
592 header
.vertex_count
+= sm
.vertex_count
593 header
.indice_count
+= sm
.indice_count
595 mesh_cache
[obj
.data
.name
] = node
597 # Process entity data
598 # ==================================================================
599 node
.offset
= entdata_length
601 if classtype
!= 'k_classtype_none':
606 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
607 s001
= F
" L {obj.name}"
610 s004
= F
"{node.parent: 3}"
613 if classtype
== 'k_classtype_skin':
614 armature_def
['obj'].data
.pose_position
= POSE_OR_REST_CACHE
615 s005
= F
" [armature -> {armature_def['obj'].cv_data.uid}]"
617 scmp
= F
"{s002:<32} {s003:<22} {s004} {s005}"
620 if classtype
== 'k_classtype_INSTANCE' or \
621 classtype
== 'k_classtype_BONE' or \
622 classtype
== 'k_classtype_SKELETON' or \
623 classtype
== 'k_classtype_SKIN':
624 print( "ERROR: user classtype cannot be _INSTANCE or _BONE" )
628 elif classtype
== 'k_classtype_skin':
631 armature
= armature_def
['obj']
632 entdata_length
+= sizeof( classtype_skin
)
634 skin
= classtype_skin()
635 skin
.skeleton
= armature
.cv_data
.uid
636 entdata_buffer
+= [skin
]
638 elif classtype
== 'k_classtype_skeleton':
640 entdata_length
+= sizeof( classtype_skeleton
)
641 skeleton
= classtype_skeleton()
643 armature_def
= graph_lookup
[obj
]
645 bones
= armature_def
['bones']
646 skeleton
.channels
= len(bones
)
647 skeleton
.ik_count
= armature_def
["ik_count"]
648 skeleton
.collider_count
= armature_def
["collider_count"]
650 if armature
.animation_data
:
651 previous_frame
= bpy
.context
.scene
.frame_current
652 previous_action
= armature
.animation_data
.action
654 skeleton
.anim_start
= len(anim_buffer
)
655 skeleton
.anim_count
= 0
657 for NLALayer
in obj
.animation_data
.nla_tracks
:
658 for NLAStrip
in NLALayer
.strips
:
660 for a
in bpy
.data
.actions
:
661 if a
.name
== NLAStrip
.name
:
662 armature
.animation_data
.action
= a
665 anim_start
= int(NLAStrip
.action_frame_start
)
666 anim_end
= int(NLAStrip
.action_frame_end
)
669 anim
= mdl_animation()
670 anim
.pstr_name
= emplace_string( NLAStrip
.action
.name
)
672 anim
.offset
= animdata_length
673 anim
.length
= anim_end
-anim_start
675 # Export the fucking keyframes
676 for frame
in range(anim_start
,anim_end
):
677 bpy
.context
.scene
.frame_set(frame
)
679 for bone_name
in bones
:
680 for pb
in armature
.pose
.bones
:
681 if pb
.name
== bone_name
:
682 rb
= armature
.data
.bones
[ bone_name
]
684 # relative bone matrix
685 if rb
.parent
is not None:
686 offset_mtx
= rb
.parent
.matrix_local
687 offset_mtx
= offset_mtx
.inverted_safe() @ \
690 inv_parent
= pb
.parent
.matrix
@ offset_mtx
691 inv_parent
.invert_safe()
692 fpm
= inv_parent
@ pb
.matrix
694 bone_mtx
= rb
.matrix
.to_4x4()
695 local_inv
= rb
.matrix_local
.inverted_safe()
696 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
698 loc
, rot
, sca
= fpm
.decompose()
701 final_pos
= Vector(( loc
[0], loc
[2], -loc
[1] ))
704 lc_m
= pb
.matrix_channel
.to_3x3()
705 if pb
.parent
is not None:
706 smtx
= pb
.parent
.matrix_channel
.to_3x3()
707 lc_m
= smtx
.inverted() @ lc_m
708 rq
= lc_m
.to_quaternion()
711 kf
.co
[0] = final_pos
[0]
712 kf
.co
[1] = final_pos
[1]
713 kf
.co
[2] = final_pos
[2]
725 animdata_buffer
+= [kf
]
726 animdata_length
+= sizeof(mdl_keyframe
)
729 anim_buffer
+= [anim
]
730 skeleton
.anim_count
+= 1
732 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
733 print( F
"{s000} | *anim: {NLAStrip.action.name}" )
735 bpy
.context
.scene
.frame_set( previous_frame
)
736 armature
.animation_data
.action
= previous_action
738 entdata_buffer
+= [skeleton
]
740 elif classtype
== 'k_classtype_bone':
742 entdata_length
+= sizeof( classtype_bone
)
744 bone
= classtype_bone()
745 bone
.deform
= node_def
['deform']
747 if 'target' in node_def
:
748 bone
.ik_target
= armature_def
['bones'].index( node_def
['target'] )
749 bone
.ik_pole
= armature_def
['bones'].index( node_def
['pole'] )
754 bone
.collider
= 1 if obj
.cv_data
.collider
else 0
755 if obj
.cv_data
.collider
:
756 bone
.hitbox
[0][0] = obj
.cv_data
.v0
[0]
757 bone
.hitbox
[0][1] = obj
.cv_data
.v0
[2]
758 bone
.hitbox
[0][2] = -obj
.cv_data
.v1
[1]
759 bone
.hitbox
[1][0] = obj
.cv_data
.v1
[0]
760 bone
.hitbox
[1][1] = obj
.cv_data
.v1
[2]
761 bone
.hitbox
[1][2] = -obj
.cv_data
.v0
[1]
763 bone
.hitbox
[0][0] = 0.0
764 bone
.hitbox
[0][1] = 0.0
765 bone
.hitbox
[0][2] = 0.0
766 bone
.hitbox
[1][0] = 0.0
767 bone
.hitbox
[1][1] = 0.0
768 bone
.hitbox
[1][2] = 0.0
772 bone
.angle_limits
[0][0] = obj
.cv_data
.mins
[0]
773 bone
.angle_limits
[0][1] = obj
.cv_data
.mins
[2]
774 bone
.angle_limits
[0][2] = -obj
.cv_data
.maxs
[1]
775 bone
.angle_limits
[1][0] = obj
.cv_data
.maxs
[0]
776 bone
.angle_limits
[1][1] = obj
.cv_data
.maxs
[2]
777 bone
.angle_limits
[1][2] = -obj
.cv_data
.mins
[1]
780 bone
.angle_limits
[0][0] = 0.0
781 bone
.angle_limits
[0][1] = 0.0
782 bone
.angle_limits
[0][2] = 0.0
783 bone
.angle_limits
[1][0] = 0.0
784 bone
.angle_limits
[1][1] = 0.0
785 bone
.angle_limits
[1][2] = 0.0
787 bone
.deform
= node_def
['deform']
788 entdata_buffer
+= [bone
]
790 elif classtype
== 'k_classtype_gate':
792 entdata_length
+= sizeof( classtype_gate
)
794 gate
= classtype_gate()
796 if obj
.cv_data
.target
!= None:
797 gate
.target
= obj
.cv_data
.target
.cv_data
.uid
799 if obj
.type == 'MESH':
800 gate
.dims
[0] = obj
.data
.cv_data
.v0
[0]
801 gate
.dims
[1] = obj
.data
.cv_data
.v0
[1]
802 gate
.dims
[2] = obj
.data
.cv_data
.v0
[2]
804 gate
.dims
[0] = obj
.cv_data
.v0
[0]
805 gate
.dims
[1] = obj
.cv_data
.v0
[1]
806 gate
.dims
[2] = obj
.cv_data
.v0
[2]
808 entdata_buffer
+= [gate
]
810 elif classtype
== 'k_classtype_block':
812 entdata_length
+= sizeof( classtype_block
)
814 source
= obj
.data
.cv_data
816 block
= classtype_block()
817 block
.bbx
[0][0] = source
.v0
[0]
818 block
.bbx
[0][1] = source
.v0
[2]
819 block
.bbx
[0][2] = -source
.v1
[1]
821 block
.bbx
[1][0] = source
.v1
[0]
822 block
.bbx
[1][1] = source
.v1
[2]
823 block
.bbx
[1][2] = -source
.v0
[1]
824 entdata_buffer
+= [block
]
826 elif classtype
== 'k_classtype_achievement_box':
829 entdata_length
+= sizeof( classtype_achievement_box
)
830 ach
= classtype_achievement_box()
831 ach
.pstr_name
= emplace_string( obj
.cv_data
.strp
)
834 if obj
.cv_data
.target
!= None:
835 ach
.trigger
= obj
.cv_data
.target
.cv_data
.uid
837 entdata_buffer
+= [ach
]
839 elif classtype
== 'k_classtype_audio':
842 entdata_length
+= sizeof( classtype_audio
)
843 aud
= classtype_audio()
844 aud
.pstr_file
= emplace_string( obj
.cv_data
.strp
)
845 aud
.flags
= obj
.cv_data
.intp
846 aud
.volume
= obj
.cv_data
.fltp
848 entdata_buffer
+= [aud
]
850 elif classtype
== 'k_classtype_spawn':
853 elif classtype
== 'k_classtype_water':
856 elif classtype
== 'k_classtype_car_path':
858 entdata_length
+= sizeof( classtype_car_path
)
860 pn
= classtype_car_path()
864 if obj
.cv_data
.target
!= None:
865 pn
.target
= obj
.cv_data
.target
.cv_data
.uid
866 if obj
.cv_data
.target1
!= None:
867 pn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
869 entdata_buffer
+= [pn
]
871 elif obj
.is_instancer
:
872 target
= obj
.instance_collection
875 entdata_length
+= sizeof( classtype_instance
)
877 inst
= classtype_instance()
878 inst
.pstr_file
= emplace_string( F
"models/{target.name}.mdl" )
879 entdata_buffer
+= [inst
]
881 elif classtype
== 'k_classtype_capsule':
884 elif classtype
== 'k_classtype_route_node':
886 entdata_length
+= sizeof( classtype_route_node
)
888 rn
= classtype_route_node()
889 if obj
.cv_data
.target
!= None:
890 rn
.target
= obj
.cv_data
.target
.cv_data
.uid
891 if obj
.cv_data
.target1
!= None:
892 rn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
894 entdata_buffer
+= [rn
]
896 elif classtype
== 'k_classtype_route':
898 entdata_length
+= sizeof( classtype_route
)
899 r
= classtype_route()
900 r
.colour
[0] = obj
.cv_data
.colour
[0]
901 r
.colour
[1] = obj
.cv_data
.colour
[1]
902 r
.colour
[2] = obj
.cv_data
.colour
[2]
904 if obj
.cv_data
.target
!= None:
905 r
.id_start
= obj
.cv_data
.target
.cv_data
.uid
907 entdata_buffer
+= [r
]
909 # classtype == 'k_classtype_none':
914 node_buffer
+= [node
]
918 header
.anim_count
= len(anim_buffer
)
920 print( "Writing data" )
921 fpos
= sizeof(header
)
923 print( F
"Nodes: {header.node_count}" )
924 header
.node_offset
= fpos
925 fpos
+= sizeof(mdl_node
)*header
.node_count
927 print( F
"Submeshes: {header.submesh_count}" )
928 header
.submesh_offset
= fpos
929 fpos
+= sizeof(mdl_submesh
)*header
.submesh_count
931 print( F
"Materials: {header.material_count}" )
932 header
.material_offset
= fpos
933 fpos
+= sizeof(mdl_material
)*header
.material_count
935 print( F
"Animation count: {header.anim_count}" )
936 header
.anim_offset
= fpos
937 fpos
+= sizeof(mdl_animation
)*header
.anim_count
939 print( F
"Entdata length: {entdata_length}" )
940 header
.entdata_offset
= fpos
941 fpos
+= entdata_length
943 print( F
"Vertex count: {header.vertex_count}" )
944 header
.vertex_offset
= fpos
945 fpos
+= sizeof(mdl_vert
)*header
.vertex_count
947 print( F
"Indice count: {header.indice_count}" )
948 header
.indice_offset
= fpos
949 fpos
+= sizeof(c_uint32
)*header
.indice_count
951 print( F
"Keyframe count: {animdata_length}" )
952 header
.animdata_offset
= fpos
953 fpos
+= animdata_length
955 print( F
"Strings length: {len(strings_buffer)}" )
956 header
.strings_offset
= fpos
957 fpos
+= len(strings_buffer
)
959 header
.file_length
= fpos
961 path
= F
"/home/harry/Documents/carve/models_src/{collection_name}.mdl"
962 fp
= open( path
, "wb" )
964 fp
.write( bytearray( header
) )
966 for node
in node_buffer
:
967 fp
.write( bytearray(node
) )
968 for sm
in submesh_buffer
:
969 fp
.write( bytearray(sm
) )
970 for mat
in material_buffer
:
971 fp
.write( bytearray(mat
) )
972 for a
in anim_buffer
:
973 fp
.write( bytearray(a
) )
974 for ed
in entdata_buffer
:
975 fp
.write( bytearray(ed
) )
976 for v
in vertex_buffer
:
977 fp
.write( bytearray(v
) )
978 for i
in indice_buffer
:
979 fp
.write( bytearray(i
) )
980 for kf
in animdata_buffer
:
981 fp
.write( bytearray(kf
) )
983 fp
.write( strings_buffer
)
986 print( F
"Completed {collection_name}.mdl" )
989 # ------------------------------------------------------------------------------
991 cv_view_draw_handler
= None
992 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
995 global cv_view_shader
996 cv_view_shader
.bind()
997 gpu
.state
.depth_mask_set(False)
998 gpu
.state
.line_width_set(2.0)
999 gpu
.state
.face_culling_set('BACK')
1000 gpu
.state
.depth_test_set('LESS')
1001 gpu
.state
.blend_set('NONE')
1006 #def drawbezier(p0,h0,p1,h1,c0,c1):
1007 # nonlocal verts, colours
1011 # colours += [(0.5,0.5,0.5,1.0),(0.5,0.5,0.5,1)]
1014 # colours += [(1.0,1.0,1,1),(1,1,1,1)]
1017 # for i in range(10):
1023 # p=ttt*p1+(3*tt-3*ttt)*h1+(3*ttt-6*tt+3*t)*h0+(3*tt-ttt-3*t+1)*p0
1024 # verts += [(last[0],last[1],last[2])]
1025 # verts += [(p[0],p[1],p[2])]
1026 # colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
1031 def drawbhandle(obj
, direction
, colour
):
1032 nonlocal verts
, colours
1034 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
1037 colours
+= [colour
,colour
]
1039 def drawbezier(p0
,h0
,p1
,h1
,c0
,c1
):
1040 nonlocal verts
, colours
1049 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
1050 verts
+= [(last
[0],last
[1],last
[2])]
1051 verts
+= [(p
[0],p
[1],p
[2])]
1052 colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
1055 def drawsbpath(o0
,o1
,c0
,c1
,s0
,s1
):
1056 nonlocal course_count
1058 offs
= ((course_count
% 2)*2-1) * course_count
* 0.02
1060 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
1061 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
1062 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
1063 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
1064 drawbezier(p0
,h0
,p1
,h1
,c0
,c1
)
1066 def drawbpath(o0
,o1
,c0
,c1
):
1067 drawsbpath(o0
,o1
,c0
,c1
,1.0,1.0)
1069 def drawbline(p0
,p1
,c0
,c1
):
1070 nonlocal verts
, colours
1074 for obj
in bpy
.context
.collection
.objects
:
1075 if obj
.type == 'ARMATURE':
1076 for bone
in obj
.data
.bones
:
1077 if bone
.cv_data
.collider
and obj
.data
.pose_position
== 'REST':
1083 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
1084 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
1085 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
1086 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
1087 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
1088 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
1089 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
1090 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
1092 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1093 (0,4),(1,5),(2,6),(3,7)]
1098 verts
+= [(v0
[0],v0
[1],v0
[2])]
1099 verts
+= [(v1
[0],v1
[1],v1
[2])]
1100 colours
+= [(0.5,0.5,0.5,0.5),(0.5,0.5,0.5,0.5)]
1102 center
=obj
.matrix_world
@c
1104 def _angle_lim( major
, minor
, amin
, amax
, colour
):
1105 nonlocal verts
, colours
1113 a0
= amin
*(1.0-t0
)+amax
*t0
1114 a1
= amin
*(1.0-t1
)+amax
*t1
1116 p0
= c
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
1117 p1
= c
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
1119 p0
=obj
.matrix_world
@ p0
1120 p1
=obj
.matrix_world
@ p1
1122 colours
+= [colour
,colour
]
1126 colours
+= [colour
,colour
]
1129 colours
+= [colour
,colour
]
1131 verts
+= [c
+major
*1.2*f
,c
+major
*f
*0.8]
1132 colours
+= [colour
,colour
]
1134 if bone
.cv_data
.con0
:
1135 _angle_lim( Vector((0,1,0)),Vector((0,0,1)), \
1136 bone
.cv_data
.mins
[0], bone
.cv_data
.maxs
[0], \
1138 _angle_lim( Vector((0,0,1)),Vector((1,0,0)), \
1139 bone
.cv_data
.mins
[1], bone
.cv_data
.maxs
[1], \
1141 _angle_lim( Vector((1,0,0)),Vector((0,1,0)), \
1142 bone
.cv_data
.mins
[2], bone
.cv_data
.maxs
[2], \
1146 if obj
.cv_data
.classtype
== 'k_classtype_gate':
1147 if obj
.type == 'MESH':
1148 dims
= obj
.data
.cv_data
.v0
1150 dims
= obj
.cv_data
.v0
1153 c
= Vector((0,0,dims
[2]))
1155 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
1156 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
1157 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
1158 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
1159 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
1160 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
1161 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
1162 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
1163 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
1165 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
1170 verts
+= [(v0
[0],v0
[1],v0
[2])]
1171 verts
+= [(v1
[0],v1
[1],v1
[2])]
1172 colours
+= [(1,1,0,1),(1,1,0,1)]
1174 sw
= (0.4,0.4,0.4,0.2)
1175 if obj
.cv_data
.target
!= None:
1176 drawbline( obj
.location
, obj
.cv_data
.target
.location
, sw
,sw
)
1178 elif obj
.cv_data
.classtype
== 'k_classtype_route_node':
1179 sw
= Vector((0.4,0.4,0.4,0.2))
1180 sw2
= Vector((1.5,0.2,0.2,0.0))
1181 if obj
.cv_data
.target
!= None:
1182 drawbpath( obj
, obj
.cv_data
.target
, sw
, sw
)
1183 if obj
.cv_data
.target1
!= None:
1184 drawbpath( obj
, obj
.cv_data
.target1
, sw
, sw
)
1186 drawbhandle( obj
, 1.0, (0.8,0.8,0.8,1.0) )
1187 drawbhandle( obj
, -1.0, (0.4,0.4,0.4,1.0) )
1189 p1
= obj
.location
+ \
1190 obj
.matrix_world
.to_quaternion() @ Vector((0,0,-6+1.5))
1191 drawbline( obj
.location
, p1
, sw
,sw2
)
1193 elif obj
.cv_data
.classtype
== 'k_classtype_achievement_box':
1194 a
= Vector((-1,-1,-1))
1198 vs
[0] = obj
.matrix_world
@ Vector((a
[0], a
[1], a
[2]))
1199 vs
[1] = obj
.matrix_world
@ Vector((a
[0], b
[1], a
[2]))
1200 vs
[2] = obj
.matrix_world
@ Vector((b
[0], b
[1], a
[2]))
1201 vs
[3] = obj
.matrix_world
@ Vector((b
[0], a
[1], a
[2]))
1202 vs
[4] = obj
.matrix_world
@ Vector((a
[0], a
[1], b
[2]))
1203 vs
[5] = obj
.matrix_world
@ Vector((a
[0], b
[1], b
[2]))
1204 vs
[6] = obj
.matrix_world
@ Vector((b
[0], b
[1], b
[2]))
1205 vs
[7] = obj
.matrix_world
@ Vector((b
[0], a
[1], b
[2]))
1207 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1208 (0,4),(1,5),(2,6),(3,7)]
1213 verts
+= [(v0
[0],v0
[1],v0
[2])]
1214 verts
+= [(v1
[0],v1
[1],v1
[2])]
1215 colours
+= [(0,1,0,1),(0,1,0,1)]
1217 if obj
.cv_data
.target
!= None:
1219 vs
[0] = obj
.location
1220 vs
[1] = obj
.cv_data
.target
.location
1225 verts
+= [(v0
[0],v0
[1],v0
[2])]
1226 verts
+= [(v1
[0],v1
[1],v1
[2])]
1227 colours
+= [(0,1,1,1),(0,1,1,1)]
1230 elif obj
.cv_data
.classtype
== 'k_classtype_block':
1231 a
= obj
.data
.cv_data
.v0
1232 b
= obj
.data
.cv_data
.v1
1235 vs
[0] = obj
.matrix_world
@ Vector((a
[0], a
[1], a
[2]))
1236 vs
[1] = obj
.matrix_world
@ Vector((a
[0], b
[1], a
[2]))
1237 vs
[2] = obj
.matrix_world
@ Vector((b
[0], b
[1], a
[2]))
1238 vs
[3] = obj
.matrix_world
@ Vector((b
[0], a
[1], a
[2]))
1239 vs
[4] = obj
.matrix_world
@ Vector((a
[0], a
[1], b
[2]))
1240 vs
[5] = obj
.matrix_world
@ Vector((a
[0], b
[1], b
[2]))
1241 vs
[6] = obj
.matrix_world
@ Vector((b
[0], b
[1], b
[2]))
1242 vs
[7] = obj
.matrix_world
@ Vector((b
[0], a
[1], b
[2]))
1244 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1245 (0,4),(1,5),(2,6),(3,7)]
1250 verts
+= [(v0
[0],v0
[1],v0
[2])]
1251 verts
+= [(v1
[0],v1
[1],v1
[2])]
1252 colours
+= [(1,1,0,1),(1,1,0,1)]
1254 elif obj
.cv_data
.classtype
== 'k_classtype_capsule':
1255 h
= obj
.data
.cv_data
.v0
[0]
1256 r
= obj
.data
.cv_data
.v0
[1]
1259 vs
[0] = obj
.matrix_world
@ Vector((0.0,0.0, h
*0.5 ))
1260 vs
[1] = obj
.matrix_world
@ Vector((0.0,0.0,-h
*0.5 ))
1261 vs
[2] = obj
.matrix_world
@ Vector(( r
,0.0, h
*0.5-r
))
1262 vs
[3] = obj
.matrix_world
@ Vector(( -r
,0.0, h
*0.5-r
))
1263 vs
[4] = obj
.matrix_world
@ Vector(( r
,0.0,-h
*0.5+r
))
1264 vs
[5] = obj
.matrix_world
@ Vector(( -r
,0.0,-h
*0.5+r
))
1265 vs
[6] = obj
.matrix_world
@ Vector((0.0, r
, h
*0.5-r
))
1266 vs
[7] = obj
.matrix_world
@ Vector((0.0,-r
, h
*0.5-r
))
1267 vs
[8] = obj
.matrix_world
@ Vector((0.0, r
,-h
*0.5+r
))
1268 vs
[9] = obj
.matrix_world
@ Vector((0.0,-r
,-h
*0.5+r
))
1270 indices
= [(0,1),(2,3),(4,5),(6,7),(8,9)]
1275 verts
+= [(v0
[0],v0
[1],v0
[2])]
1276 verts
+= [(v1
[0],v1
[1],v1
[2])]
1277 colours
+= [(0.5,1,0,1),(0.5,1,0,1)]
1279 elif obj
.cv_data
.classtype
== 'k_classtype_spawn':
1281 vs
[0] = obj
.matrix_world
@ Vector((0,0,0))
1282 vs
[1] = obj
.matrix_world
@ Vector((0,2,0))
1283 vs
[2] = obj
.matrix_world
@ Vector((0.5,1,0))
1284 vs
[3] = obj
.matrix_world
@ Vector((-0.5,1,0))
1285 indices
= [(0,1),(1,2),(1,3)]
1289 verts
+= [(v0
[0],v0
[1],v0
[2])]
1290 verts
+= [(v1
[0],v1
[1],v1
[2])]
1291 colours
+= [(0,1,1,1),(0,1,1,1)]
1293 elif obj
.cv_data
.classtype
== 'k_classtype_route':
1295 vs
[0] = obj
.location
1296 vs
[1] = obj
.cv_data
.target
.location
1301 verts
+= [(v0
[0],v0
[1],v0
[2])]
1302 verts
+= [(v1
[0],v1
[1],v1
[2])]
1303 colours
+= [(0,1,1,1),(0,1,1,1)]
1307 stack
[0] = obj
.cv_data
.target
1309 loop_complete
= False
1312 if stack_i
[si
-1] == 2:
1316 if si
== 0: # Loop failed to complete
1321 targets
= [None,None]
1322 targets
[0] = node
.cv_data
.target
1324 if node
.cv_data
.classtype
== 'k_classtype_route_node':
1325 targets
[1] = node
.cv_data
.target1
1327 nextnode
= targets
[stack_i
[si
-1]]
1330 if nextnode
!= None: # branch
1331 if nextnode
== stack
[0]: # Loop completed
1332 loop_complete
= True
1336 for sj
in range(si
):
1337 if stack
[sj
] == nextnode
: # invalidated path
1343 stack
[si
] = nextnode
1348 cc
= Vector((obj
.cv_data
.colour
[0],\
1349 obj
.cv_data
.colour
[1],\
1350 obj
.cv_data
.colour
[2],\
1353 for sj
in range(si
):
1356 if stack
[sj
].cv_data
.classtype
== 'k_classtype_gate' and \
1357 stack
[sk
].cv_data
.classtype
== 'k_classtype_gate':
1358 dist
= (stack
[sj
].location
-stack
[sk
].location
).magnitude
1359 drawsbpath( stack
[sj
], stack
[sk
], cc
*0.4, cc
, dist
, dist
)
1362 drawbpath( stack
[sj
], stack
[sk
], cc
, cc
)
1366 elif obj
.cv_data
.classtype
== 'k_classtype_car_path':
1367 v0
= obj
.matrix_world
.to_quaternion() @ Vector((0,1,0))
1368 c0
= Vector((v0
.x
*0.5+0.5, v0
.y
*0.5+0.5, 0.0, 1.0))
1369 drawbhandle( obj
, 1.0, (0.9,0.9,0.9,1.0) )
1371 if obj
.cv_data
.target
!= None:
1372 v1
= obj
.cv_data
.target
.matrix_world
.to_quaternion()@Vector((0,1,0))
1373 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1375 drawbhandle( obj
.cv_data
.target
, -1.0, (0.5,0.5,0.5,1.0) )
1376 drawbpath( obj
, obj
.cv_data
.target
, c0
, c1
)
1378 if obj
.cv_data
.target1
!= None:
1379 v1
= obj
.cv_data
.target1
.matrix_world
.to_quaternion()@Vector((0,1,0))
1380 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1382 drawbhandle( obj
.cv_data
.target1
, -1.0, (0.5,0.5,0.5,1.0) )
1383 drawbpath( obj
, obj
.cv_data
.target1
, c0
, c1
)
1385 lines
= batch_for_shader(\
1386 cv_view_shader
, 'LINES', \
1387 { "pos":verts
, "color":colours
})
1389 lines
.draw( cv_view_shader
)
1391 def cv_poll_target(scene
, obj
):
1392 if obj
== bpy
.context
.active_object
:
1394 if obj
.cv_data
.classtype
== 'k_classtype_none':
1398 class CV_MESH_SETTINGS(bpy
.types
.PropertyGroup
):
1399 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1400 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1401 v2
: bpy
.props
.FloatVectorProperty(name
="v2",size
=3)
1402 v3
: bpy
.props
.FloatVectorProperty(name
="v3",size
=3)
1404 class CV_OBJ_SETTINGS(bpy
.types
.PropertyGroup
):
1405 uid
: bpy
.props
.IntProperty( name
="" )
1407 strp
: bpy
.props
.StringProperty( name
="strp" )
1408 intp
: bpy
.props
.IntProperty( name
="intp" )
1409 fltp
: bpy
.props
.FloatProperty( name
="fltp" )
1411 target
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target", \
1412 poll
=cv_poll_target
)
1413 target1
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target1", \
1414 poll
=cv_poll_target
)
1416 colour
: bpy
.props
.FloatVectorProperty(name
="colour",subtype
='COLOR',\
1419 classtype
: bpy
.props
.EnumProperty(
1422 ('k_classtype_none', "k_classtype_none", "", 0),
1423 ('k_classtype_gate', "k_classtype_gate", "", 1),
1424 ('k_classtype_block', "k_classtype_block", "", 2),
1425 ('k_classtype_spawn', "k_classtype_spawn", "", 3),
1426 ('k_classtype_water', "k_classtype_water", "", 4),
1427 ('k_classtype_car_path', "k_classtype_car_path", "", 5),
1428 ('k_classtype_INSTANCE', "","", 6 ),
1429 ('k_classtype_capsule', "k_classtype_capsule", "", 7 ),
1430 ('k_classtype_route_node', "k_classtype_route_node", "", 8 ),
1431 ('k_classtype_route', "k_classtype_route", "", 9 ),
1432 ('k_classtype_bone',"k_classtype_bone","",10),
1433 ('k_classtype_SKELETON', "","", 11 ),
1434 ('k_classtype_SKIN',"","",12),
1435 ('k_classtype_achievement_box',"k_classtype_achievement_box","",13),
1436 ('k_classtype_audio',"k_classtype_audio","",14),
1439 class CV_BONE_SETTINGS(bpy
.types
.PropertyGroup
):
1440 collider
: bpy
.props
.BoolProperty(name
="Collider",default
=False)
1441 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1442 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1444 con0
: bpy
.props
.BoolProperty(name
="Constriant 0",default
=False)
1445 mins
: bpy
.props
.FloatVectorProperty(name
="mins",size
=3)
1446 maxs
: bpy
.props
.FloatVectorProperty(name
="maxs",size
=3)
1448 class CV_BONE_PANEL(bpy
.types
.Panel
):
1449 bl_label
="Bone Config"
1450 bl_idname
="SCENE_PT_cv_bone"
1451 bl_space_type
='PROPERTIES'
1452 bl_region_type
='WINDOW'
1455 def draw(_
,context
):
1456 active_object
= context
.active_object
1457 if active_object
== None: return
1459 bone
= active_object
.data
.bones
.active
1460 if bone
== None: return
1462 _
.layout
.prop( bone
.cv_data
, "collider" )
1463 _
.layout
.prop( bone
.cv_data
, "v0" )
1464 _
.layout
.prop( bone
.cv_data
, "v1" )
1466 _
.layout
.label( text
="Angle Limits" )
1467 _
.layout
.prop( bone
.cv_data
, "con0" )
1468 _
.layout
.prop( bone
.cv_data
, "mins" )
1469 _
.layout
.prop( bone
.cv_data
, "maxs" )
1471 class CV_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
1472 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
1474 class CV_OBJ_PANEL(bpy
.types
.Panel
):
1475 bl_label
="Entity Config"
1476 bl_idname
="SCENE_PT_cv_entity"
1477 bl_space_type
='PROPERTIES'
1478 bl_region_type
='WINDOW'
1481 def draw(_
,context
):
1482 active_object
= bpy
.context
.active_object
1483 if active_object
== None: return
1484 _
.layout
.prop( active_object
.cv_data
, "classtype" )
1486 if active_object
.cv_data
.classtype
== 'k_classtype_gate':
1487 _
.layout
.prop( active_object
.cv_data
, "target" )
1489 mesh
= active_object
.data
1490 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1491 _
.layout
.prop( mesh
.cv_data
, "v0" )
1493 elif active_object
.cv_data
.classtype
== 'k_classtype_car_path' or \
1494 active_object
.cv_data
.classtype
== 'k_classtype_route_node':
1495 _
.layout
.prop( active_object
.cv_data
, "target" )
1496 _
.layout
.prop( active_object
.cv_data
, "target1" )
1498 elif active_object
.cv_data
.classtype
== 'k_classtype_route':
1499 _
.layout
.prop( active_object
.cv_data
, "target" )
1500 _
.layout
.prop( active_object
.cv_data
, "colour" )
1502 elif active_object
.cv_data
.classtype
== 'k_classtype_block':
1503 mesh
= active_object
.data
1505 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1506 _
.layout
.prop( mesh
.cv_data
, "v0" )
1507 _
.layout
.prop( mesh
.cv_data
, "v1" )
1508 _
.layout
.prop( mesh
.cv_data
, "v2" )
1509 _
.layout
.prop( mesh
.cv_data
, "v3" )
1510 elif active_object
.cv_data
.classtype
== 'k_classtype_capsule':
1511 mesh
= active_object
.data
1512 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1513 _
.layout
.prop( mesh
.cv_data
, "v0" )
1514 elif active_object
.cv_data
.classtype
== 'k_classtype_achievement_box':
1515 _
.layout
.prop( active_object
.cv_data
, "strp" )
1516 _
.layout
.prop( active_object
.cv_data
, "target" )
1517 elif active_object
.cv_data
.classtype
== 'k_classtype_audio':
1518 _
.layout
.prop( active_object
.cv_data
, "strp" )
1519 _
.layout
.prop( active_object
.cv_data
, "intp" )
1520 _
.layout
.prop( active_object
.cv_data
, "fltp" )
1522 class CV_INTERFACE(bpy
.types
.Panel
):
1523 bl_idname
= "VIEW3D_PT_carve"
1525 bl_space_type
= 'VIEW_3D'
1526 bl_region_type
= 'UI'
1527 bl_category
= "Carve"
1529 def draw(_
, context
):
1531 layout
.prop( context
.scene
.cv_data
, "use_hidden")
1532 layout
.operator( "carve.compile_all" )
1535 view_layer
= bpy
.context
.view_layer
1536 for col
in view_layer
.layer_collection
.children
["export"].children
:
1537 if not col
.hide_viewport
or bpy
.context
.scene
.cv_data
.use_hidden
:
1538 write_model( col
.name
)
1540 class CV_COMPILE(bpy
.types
.Operator
):
1541 bl_idname
="carve.compile_all"
1542 bl_label
="Compile All"
1544 def execute(_
,context
):
1546 #cProfile.runctx("test_compile()",globals(),locals(),sort=1)
1547 #for col in bpy.data.collections["export"].children:
1548 # write_model( col.name )
1552 classes
= [CV_OBJ_SETTINGS
,CV_OBJ_PANEL
,CV_COMPILE
,CV_INTERFACE
,\
1553 CV_MESH_SETTINGS
, CV_SCENE_SETTINGS
, CV_BONE_SETTINGS
,\
1557 global cv_view_draw_handler
1560 bpy
.utils
.register_class(c
)
1562 bpy
.types
.Object
.cv_data
= bpy
.props
.PointerProperty(type=CV_OBJ_SETTINGS
)
1563 bpy
.types
.Mesh
.cv_data
= bpy
.props
.PointerProperty(type=CV_MESH_SETTINGS
)
1564 bpy
.types
.Scene
.cv_data
= bpy
.props
.PointerProperty(type=CV_SCENE_SETTINGS
)
1565 bpy
.types
.Bone
.cv_data
= bpy
.props
.PointerProperty(type=CV_BONE_SETTINGS
)
1567 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
1568 cv_draw
,(),'WINDOW','POST_VIEW')
1571 global cv_view_draw_handler
1574 bpy
.utils
.unregister_class(c
)
1576 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')