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
)]
169 # ==============================================================================
171 def write_model(collection_name
):
172 print( F
"Model graph | Create mode '{collection_name}'" )
174 header
= mdl_header()
175 header
.identifier
= 0xABCD0000
177 header
.vertex_count
= 0
178 header
.indice_count
= 0
179 header
.submesh_count
= 0
180 header
.node_count
= 0
181 header
.material_count
= 0
182 header
.file_length
= 0
202 def emplace_string( s
):
203 nonlocal string_cache
, strings_buffer
205 if s
in string_cache
:
206 return string_cache
[s
]
208 string_cache
[s
] = len( strings_buffer
)
209 strings_buffer
+= (s
+'\0').encode('utf-8')
210 return string_cache
[s
]
212 def emplace_material( mat
):
213 nonlocal material_cache
, material_buffer
218 if mat
.name
in material_cache
:
219 return material_cache
[mat
.name
]
221 material_cache
[mat
.name
] = header
.material_count
222 dest
= mdl_material()
223 dest
.pstr_name
= emplace_string( mat
.name
)
224 material_buffer
+= [dest
]
226 header
.material_count
+= 1
227 return material_cache
[mat
.name
]
229 # Create root or empty node and materials
230 # this is to designate id 0 as 'NULL'
232 none_material
= c_uint32(69)
233 none_material
.name
= ""
234 emplace_material( none_material
)
247 root
.pstr_name
= emplace_string('')
248 root
.submesh_start
= 0
249 root
.submesh_count
= 0
252 node_buffer
+= [root
]
256 print( " assigning ids" )
257 collection
= bpy
.data
.collections
[collection_name
]
260 # ==========================================
262 header
.node_count
= 0
265 uid
= header
.node_count
266 header
.node_count
+= 1
269 print( " creating scene graph" )
273 graph
["children"] = []
274 graph
["uid"] = _uid()
275 graph
["parent"] = None
277 graph_lookup
= {} # object can lookup its graph def here
279 for obj
in collection
.all_objects
:
282 def _extend( p
, n
, d
):
286 tree
["children"] = []
292 if n
.type == 'ARMATURE':
293 tree
["bones"] = [None] # None is the root transform
295 tree
["collider_count"] = 0
297 def _extendb( p
, n
, d
):
302 btree
["uid"] = _uid()
303 btree
["children"] = []
306 tree
["bones"] += [n
.name
]
309 _extendb( btree
, c
, d
+1 )
311 for c
in tree
['obj'].pose
.bones
[n
.name
].constraints
:
313 btree
["target"] = c
.subtarget
314 btree
["pole"] = c
.pole_subtarget
315 tree
["ik_count"] += 1
317 if n
.cv_data
.collider
:
318 tree
['collider_count'] += 1
320 btree
['deform'] = n
.use_deform
321 p
['children'] += [btree
]
323 for b
in n
.data
.bones
:
325 _extendb( tree
, b
, d
+1 )
327 for obj1
in n
.children
:
329 for c1
in obj1
.users_collection
:
331 _extend( tree
, obj1
, d
+1 )
334 p
["children"] += [tree
]
335 graph_lookup
[n
] = tree
337 _extend( graph
, obj
, 1 )
341 for c
in p
['children']:
343 yield from _graph_iter(c
)
345 it
= _graph_iter(graph
)
347 root
.parent
= 0xffffffff
350 # ==============================================
351 it
= _graph_iter(graph
)
352 print( " compiling data" )
354 if 'obj' in node_def
:
355 obj
= node_def
['obj']
358 elif 'bone' in node_def
:
359 obj
= node_def
['bone']
361 objco
= obj
.head_local
363 depth
= node_def
['depth']
364 uid
= node_def
['uid']
367 node
.co
[0] = objco
[0]
368 node
.co
[1] = objco
[2]
369 node
.co
[2] = -objco
[1]
371 # Convert rotation quat to our space type
372 quat
= obj
.matrix_local
.to_quaternion()
379 node
.s
[0] = obj
.tail_local
[0] - node
.co
[0]
380 node
.s
[1] = obj
.tail_local
[2] - node
.co
[1]
381 node
.s
[2] = -obj
.tail_local
[1] - node
.co
[2]
383 node
.s
[0] = obj
.scale
[0]
384 node
.s
[1] = obj
.scale
[2]
385 node
.s
[2] = obj
.scale
[1]
387 node
.pstr_name
= emplace_string( obj
.name
)
389 if node_def
["parent"]:
390 node
.parent
= node_def
["parent"]["uid"]
393 classtype
= 'k_classtype_bone'
394 elif objt
== 'ARMATURE':
395 classtype
= 'k_classtype_skeleton'
397 classtype
= obj
.cv_data
.classtype
400 # =================================================================
403 # Dont use the cache if we have modifiers that affect the normals
411 for mod
in obj
.modifiers
:
412 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
413 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
415 can_use_cache
= False
417 if mod
.type == 'ARMATURE':
418 classtype
= 'k_classtype_skin'
419 armature_def
= graph_lookup
[mod
.object]
420 POSE_OR_REST_CACHE
= armature_def
['obj'].data
.pose_position
422 armature_def
['obj'].data
.pose_position
= 'REST'
424 if can_use_cache
and obj
.data
.name
in mesh_cache
:
425 ref
= mesh_cache
[obj
.data
.name
]
426 node
.submesh_start
= ref
.submesh_start
427 node
.submesh_count
= ref
.submesh_count
431 node
.submesh_start
= header
.submesh_count
432 node
.submesh_count
= 0
434 default_mat
= c_uint32(69)
435 default_mat
.name
= ""
437 dgraph
= bpy
.context
.evaluated_depsgraph_get()
438 data
= obj
.evaluated_get(dgraph
).data
439 data
.calc_loop_triangles()
440 data
.calc_normals_split()
442 mat_list
= data
.materials
if len(data
.materials
) > 0 else [default_mat
]
443 for material_id
, mat
in enumerate(mat_list
):
447 sm
.indice_start
= header
.indice_count
448 sm
.vertex_start
= header
.vertex_count
451 sm
.material_id
= emplace_material( mat
)
454 sm
.bbx
[0][i
] = 999999
455 sm
.bbx
[1][i
] = -999999
459 # Write the vertex / indice data
461 for tri_index
, tri
in enumerate(data
.loop_triangles
):
462 if tri
.material_index
!= material_id
:
466 vert
= data
.vertices
[tri
.vertices
[j
]]
468 vi
= data
.loops
[li
].vertex_index
471 norm
= data
.loops
[li
].normal
473 colour
= (255,255,255,255)
478 uv
= data
.uv_layers
.active
.data
[li
].uv
480 if data
.vertex_colors
:
481 colour
= data
.vertex_colors
.active
.data
[li
].color
482 colour
= (int(colour
[0]*255.0),\
483 int(colour
[1]*255.0),\
484 int(colour
[2]*255.0),\
485 int(colour
[3]*255.0))
490 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
491 if obj
.vertex_groups
[_
.group
].name
in \
492 armature_def
['bones']]
494 weight_groups
= sorted( src_groups
, key
= \
495 lambda a
: a
.weight
, reverse
=True )
498 if len(weight_groups
) > ml
:
499 g
= weight_groups
[ml
]
500 name
= obj
.vertex_groups
[g
.group
].name
504 groups
[ml
] = armature_def
['bones'].index(name
)
507 if len(weight_groups
) > 0:
508 inv_norm
= (1.0/tot
) * 65535.0
510 weights
[ml
] = int( weights
[ml
] * inv_norm
)
511 weights
[ml
] = min( weights
[ml
], 65535 )
512 weights
[ml
] = max( weights
[ml
], 0 )
515 m
= float(10**TOLERENCE
)
517 key
= (int(co
[0]*m
+0.5),\
539 indice_buffer
+= [boffa
[key
]]
541 index
= c_uint32(sm
.vertex_count
)
545 indice_buffer
+= [index
]
556 v
.colour
[0] = colour
[0]
557 v
.colour
[1] = colour
[1]
558 v
.colour
[2] = colour
[2]
559 v
.colour
[3] = colour
[3]
560 v
.weights
[0] = weights
[0]
561 v
.weights
[1] = weights
[1]
562 v
.weights
[2] = weights
[2]
563 v
.weights
[3] = weights
[3]
564 v
.groups
[0] = groups
[0]
565 v
.groups
[1] = groups
[1]
566 v
.groups
[2] = groups
[2]
567 v
.groups
[3] = groups
[3]
572 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
573 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
577 if sm
.vertex_count
== 0:
582 submesh_buffer
+= [sm
]
583 node
.submesh_count
+= 1
584 header
.submesh_count
+= 1
585 header
.vertex_count
+= sm
.vertex_count
586 header
.indice_count
+= sm
.indice_count
588 mesh_cache
[obj
.data
.name
] = node
590 # Process entity data
591 # ==================================================================
592 node
.offset
= entdata_length
594 if classtype
!= 'k_classtype_none':
599 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
600 s001
= F
" L {obj.name}"
603 s004
= F
"{node.parent: 3}"
606 if classtype
== 'k_classtype_skin':
607 armature_def
['obj'].data
.pose_position
= POSE_OR_REST_CACHE
608 s005
= F
" [armature -> {armature_def['obj'].cv_data.uid}]"
610 scmp
= F
"{s002:<32} {s003:<22} {s004} {s005}"
613 if classtype
== 'k_classtype_INSTANCE' or \
614 classtype
== 'k_classtype_BONE' or \
615 classtype
== 'k_classtype_SKELETON' or \
616 classtype
== 'k_classtype_SKIN':
617 print( "ERROR: user classtype cannot be _INSTANCE or _BONE" )
621 elif classtype
== 'k_classtype_skin':
624 armature
= armature_def
['obj']
625 entdata_length
+= sizeof( classtype_skin
)
627 skin
= classtype_skin()
628 skin
.skeleton
= armature
.cv_data
.uid
629 entdata_buffer
+= [skin
]
631 elif classtype
== 'k_classtype_skeleton':
633 entdata_length
+= sizeof( classtype_skeleton
)
634 skeleton
= classtype_skeleton()
636 armature_def
= graph_lookup
[obj
]
638 bones
= armature_def
['bones']
639 skeleton
.channels
= len(bones
)
640 skeleton
.ik_count
= armature_def
["ik_count"]
641 skeleton
.collider_count
= armature_def
["collider_count"]
643 if armature
.animation_data
:
644 previous_frame
= bpy
.context
.scene
.frame_current
645 previous_action
= armature
.animation_data
.action
647 skeleton
.anim_start
= len(anim_buffer
)
648 skeleton
.anim_count
= 0
650 for NLALayer
in obj
.animation_data
.nla_tracks
:
651 for NLAStrip
in NLALayer
.strips
:
653 for a
in bpy
.data
.actions
:
654 if a
.name
== NLAStrip
.name
:
655 armature
.animation_data
.action
= a
658 anim_start
= int(NLAStrip
.action_frame_start
)
659 anim_end
= int(NLAStrip
.action_frame_end
)
662 anim
= mdl_animation()
663 anim
.pstr_name
= emplace_string( NLAStrip
.action
.name
)
665 anim
.offset
= animdata_length
666 anim
.length
= anim_end
-anim_start
668 # Export the fucking keyframes
669 for frame
in range(anim_start
,anim_end
):
670 bpy
.context
.scene
.frame_set(frame
)
672 for bone_name
in bones
:
673 for pb
in armature
.pose
.bones
:
674 if pb
.name
== bone_name
:
675 rb
= armature
.data
.bones
[ bone_name
]
677 # relative bone matrix
678 if rb
.parent
is not None:
679 offset_mtx
= rb
.parent
.matrix_local
680 offset_mtx
= offset_mtx
.inverted_safe() @ \
683 inv_parent
= pb
.parent
.matrix
@ offset_mtx
684 inv_parent
.invert_safe()
685 fpm
= inv_parent
@ pb
.matrix
687 bone_mtx
= rb
.matrix
.to_4x4()
688 local_inv
= rb
.matrix_local
.inverted_safe()
689 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
691 loc
, rot
, sca
= fpm
.decompose()
694 final_pos
= Vector(( loc
[0], loc
[2], -loc
[1] ))
697 lc_m
= pb
.matrix_channel
.to_3x3()
698 if pb
.parent
is not None:
699 smtx
= pb
.parent
.matrix_channel
.to_3x3()
700 lc_m
= smtx
.inverted() @ lc_m
701 rq
= lc_m
.to_quaternion()
704 kf
.co
[0] = final_pos
[0]
705 kf
.co
[1] = final_pos
[1]
706 kf
.co
[2] = final_pos
[2]
718 animdata_buffer
+= [kf
]
719 animdata_length
+= sizeof(mdl_keyframe
)
722 anim_buffer
+= [anim
]
723 skeleton
.anim_count
+= 1
725 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
726 print( F
"{s000} | *anim: {NLAStrip.action.name}" )
728 bpy
.context
.scene
.frame_set( previous_frame
)
729 armature
.animation_data
.action
= previous_action
731 entdata_buffer
+= [skeleton
]
733 elif classtype
== 'k_classtype_bone':
735 entdata_length
+= sizeof( classtype_bone
)
737 bone
= classtype_bone()
738 bone
.deform
= node_def
['deform']
740 if 'target' in node_def
:
741 bone
.ik_target
= armature_def
['bones'].index( node_def
['target'] )
742 bone
.ik_pole
= armature_def
['bones'].index( node_def
['pole'] )
747 bone
.collider
= 1 if obj
.cv_data
.collider
else 0
748 if obj
.cv_data
.collider
:
749 bone
.hitbox
[0][0] = obj
.cv_data
.v0
[0]
750 bone
.hitbox
[0][1] = obj
.cv_data
.v0
[2]
751 bone
.hitbox
[0][2] = -obj
.cv_data
.v1
[1]
752 bone
.hitbox
[1][0] = obj
.cv_data
.v1
[0]
753 bone
.hitbox
[1][1] = obj
.cv_data
.v1
[2]
754 bone
.hitbox
[1][2] = -obj
.cv_data
.v0
[1]
756 bone
.hitbox
[0][0] = 0.0
757 bone
.hitbox
[0][1] = 0.0
758 bone
.hitbox
[0][2] = 0.0
759 bone
.hitbox
[1][0] = 0.0
760 bone
.hitbox
[1][1] = 0.0
761 bone
.hitbox
[1][2] = 0.0
765 bone
.angle_limits
[0][0] = obj
.cv_data
.mins
[0]
766 bone
.angle_limits
[0][1] = obj
.cv_data
.mins
[2]
767 bone
.angle_limits
[0][2] = -obj
.cv_data
.maxs
[1]
768 bone
.angle_limits
[1][0] = obj
.cv_data
.maxs
[0]
769 bone
.angle_limits
[1][1] = obj
.cv_data
.maxs
[2]
770 bone
.angle_limits
[1][2] = -obj
.cv_data
.mins
[1]
773 bone
.angle_limits
[0][0] = 0.0
774 bone
.angle_limits
[0][1] = 0.0
775 bone
.angle_limits
[0][2] = 0.0
776 bone
.angle_limits
[1][0] = 0.0
777 bone
.angle_limits
[1][1] = 0.0
778 bone
.angle_limits
[1][2] = 0.0
780 bone
.deform
= node_def
['deform']
781 entdata_buffer
+= [bone
]
783 elif classtype
== 'k_classtype_gate':
785 entdata_length
+= sizeof( classtype_gate
)
787 gate
= classtype_gate()
789 if obj
.cv_data
.target
!= None:
790 gate
.target
= obj
.cv_data
.target
.cv_data
.uid
792 if obj
.type == 'MESH':
793 gate
.dims
[0] = obj
.data
.cv_data
.v0
[0]
794 gate
.dims
[1] = obj
.data
.cv_data
.v0
[1]
795 gate
.dims
[2] = obj
.data
.cv_data
.v0
[2]
797 gate
.dims
[0] = obj
.cv_data
.v0
[0]
798 gate
.dims
[1] = obj
.cv_data
.v0
[1]
799 gate
.dims
[2] = obj
.cv_data
.v0
[2]
801 entdata_buffer
+= [gate
]
803 elif classtype
== 'k_classtype_block':
805 entdata_length
+= sizeof( classtype_block
)
807 source
= obj
.data
.cv_data
809 block
= classtype_block()
810 block
.bbx
[0][0] = source
.v0
[0]
811 block
.bbx
[0][1] = source
.v0
[2]
812 block
.bbx
[0][2] = -source
.v1
[1]
814 block
.bbx
[1][0] = source
.v1
[0]
815 block
.bbx
[1][1] = source
.v1
[2]
816 block
.bbx
[1][2] = -source
.v0
[1]
817 entdata_buffer
+= [block
]
819 elif classtype
== 'k_classtype_achievement_box':
822 entdata_length
+= sizeof( classtype_achievement_box
)
823 ach
= classtype_achievement_box()
824 ach
.pstr_name
= emplace_string( obj
.cv_data
.strp
)
825 entdata_buffer
+= [ach
]
827 elif classtype
== 'k_classtype_spawn':
830 elif classtype
== 'k_classtype_water':
833 elif classtype
== 'k_classtype_car_path':
835 entdata_length
+= sizeof( classtype_car_path
)
837 pn
= classtype_car_path()
841 if obj
.cv_data
.target
!= None:
842 pn
.target
= obj
.cv_data
.target
.cv_data
.uid
843 if obj
.cv_data
.target1
!= None:
844 pn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
846 entdata_buffer
+= [pn
]
848 elif obj
.is_instancer
:
849 target
= obj
.instance_collection
852 entdata_length
+= sizeof( classtype_instance
)
854 inst
= classtype_instance()
855 inst
.pstr_file
= emplace_string( F
"models/{target.name}.mdl" )
856 entdata_buffer
+= [inst
]
858 elif classtype
== 'k_classtype_capsule':
861 elif classtype
== 'k_classtype_route_node':
863 entdata_length
+= sizeof( classtype_route_node
)
865 rn
= classtype_route_node()
866 if obj
.cv_data
.target
!= None:
867 rn
.target
= obj
.cv_data
.target
.cv_data
.uid
868 if obj
.cv_data
.target1
!= None:
869 rn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
871 entdata_buffer
+= [rn
]
873 elif classtype
== 'k_classtype_route':
875 entdata_length
+= sizeof( classtype_route
)
876 r
= classtype_route()
877 r
.colour
[0] = obj
.cv_data
.colour
[0]
878 r
.colour
[1] = obj
.cv_data
.colour
[1]
879 r
.colour
[2] = obj
.cv_data
.colour
[2]
881 if obj
.cv_data
.target
!= None:
882 r
.id_start
= obj
.cv_data
.target
.cv_data
.uid
884 entdata_buffer
+= [r
]
886 # classtype == 'k_classtype_none':
891 node_buffer
+= [node
]
895 header
.anim_count
= len(anim_buffer
)
897 print( "Writing data" )
898 fpos
= sizeof(header
)
900 print( F
"Nodes: {header.node_count}" )
901 header
.node_offset
= fpos
902 fpos
+= sizeof(mdl_node
)*header
.node_count
904 print( F
"Submeshes: {header.submesh_count}" )
905 header
.submesh_offset
= fpos
906 fpos
+= sizeof(mdl_submesh
)*header
.submesh_count
908 print( F
"Materials: {header.material_count}" )
909 header
.material_offset
= fpos
910 fpos
+= sizeof(mdl_material
)*header
.material_count
912 print( F
"Animation count: {header.anim_count}" )
913 header
.anim_offset
= fpos
914 fpos
+= sizeof(mdl_animation
)*header
.anim_count
916 print( F
"Entdata length: {entdata_length}" )
917 header
.entdata_offset
= fpos
918 fpos
+= entdata_length
920 print( F
"Vertex count: {header.vertex_count}" )
921 header
.vertex_offset
= fpos
922 fpos
+= sizeof(mdl_vert
)*header
.vertex_count
924 print( F
"Indice count: {header.indice_count}" )
925 header
.indice_offset
= fpos
926 fpos
+= sizeof(c_uint32
)*header
.indice_count
928 print( F
"Keyframe count: {animdata_length}" )
929 header
.animdata_offset
= fpos
930 fpos
+= animdata_length
932 print( F
"Strings length: {len(strings_buffer)}" )
933 header
.strings_offset
= fpos
934 fpos
+= len(strings_buffer
)
936 header
.file_length
= fpos
938 path
= F
"/home/harry/Documents/carve/models_src/{collection_name}.mdl"
939 fp
= open( path
, "wb" )
941 fp
.write( bytearray( header
) )
943 for node
in node_buffer
:
944 fp
.write( bytearray(node
) )
945 for sm
in submesh_buffer
:
946 fp
.write( bytearray(sm
) )
947 for mat
in material_buffer
:
948 fp
.write( bytearray(mat
) )
949 for a
in anim_buffer
:
950 fp
.write( bytearray(a
) )
951 for ed
in entdata_buffer
:
952 fp
.write( bytearray(ed
) )
953 for v
in vertex_buffer
:
954 fp
.write( bytearray(v
) )
955 for i
in indice_buffer
:
956 fp
.write( bytearray(i
) )
957 for kf
in animdata_buffer
:
958 fp
.write( bytearray(kf
) )
960 fp
.write( strings_buffer
)
963 print( F
"Completed {collection_name}.mdl" )
966 # ------------------------------------------------------------------------------
968 cv_view_draw_handler
= None
969 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
972 global cv_view_shader
973 cv_view_shader
.bind()
974 gpu
.state
.depth_mask_set(False)
975 gpu
.state
.line_width_set(2.0)
976 gpu
.state
.face_culling_set('BACK')
977 gpu
.state
.depth_test_set('LESS')
978 gpu
.state
.blend_set('NONE')
983 #def drawbezier(p0,h0,p1,h1,c0,c1):
984 # nonlocal verts, colours
988 # colours += [(0.5,0.5,0.5,1.0),(0.5,0.5,0.5,1)]
991 # colours += [(1.0,1.0,1,1),(1,1,1,1)]
994 # for i in range(10):
1000 # p=ttt*p1+(3*tt-3*ttt)*h1+(3*ttt-6*tt+3*t)*h0+(3*tt-ttt-3*t+1)*p0
1001 # verts += [(last[0],last[1],last[2])]
1002 # verts += [(p[0],p[1],p[2])]
1003 # colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
1008 def drawbhandle(obj
, direction
, colour
):
1009 nonlocal verts
, colours
1011 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
1014 colours
+= [colour
,colour
]
1016 def drawbezier(p0
,h0
,p1
,h1
,c0
,c1
):
1017 nonlocal verts
, colours
1026 p
=ttt
*p1
+(3*tt
-3*ttt
)*h1
+(3*ttt
-6*tt
+3*t
)*h0
+(3*tt
-ttt
-3*t
+1)*p0
1027 verts
+= [(last
[0],last
[1],last
[2])]
1028 verts
+= [(p
[0],p
[1],p
[2])]
1029 colours
+= [c0
*a0
+c1
*(1-a0
),c0
*a0
+c1
*(1-a0
)]
1032 def drawsbpath(o0
,o1
,c0
,c1
,s0
,s1
):
1033 nonlocal course_count
1035 offs
= ((course_count
% 2)*2-1) * course_count
* 0.02
1037 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
1038 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
1039 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
1040 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
1041 drawbezier(p0
,h0
,p1
,h1
,c0
,c1
)
1043 def drawbpath(o0
,o1
,c0
,c1
):
1044 drawsbpath(o0
,o1
,c0
,c1
,1.0,1.0)
1046 def drawbline(p0
,p1
,c0
,c1
):
1047 nonlocal verts
, colours
1051 for obj
in bpy
.context
.collection
.objects
:
1052 if obj
.type == 'ARMATURE':
1053 for bone
in obj
.data
.bones
:
1054 if bone
.cv_data
.collider
and obj
.data
.pose_position
== 'REST':
1060 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
1061 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
1062 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
1063 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
1064 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
1065 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
1066 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
1067 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
1069 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1070 (0,4),(1,5),(2,6),(3,7)]
1075 verts
+= [(v0
[0],v0
[1],v0
[2])]
1076 verts
+= [(v1
[0],v1
[1],v1
[2])]
1077 colours
+= [(0.5,0.5,0.5,0.5),(0.5,0.5,0.5,0.5)]
1079 center
=obj
.matrix_world
@c
1081 def _angle_lim( major
, minor
, amin
, amax
, colour
):
1082 nonlocal verts
, colours
1090 a0
= amin
*(1.0-t0
)+amax
*t0
1091 a1
= amin
*(1.0-t1
)+amax
*t1
1093 p0
= c
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
1094 p1
= c
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
1096 p0
=obj
.matrix_world
@ p0
1097 p1
=obj
.matrix_world
@ p1
1099 colours
+= [colour
,colour
]
1103 colours
+= [colour
,colour
]
1106 colours
+= [colour
,colour
]
1108 verts
+= [c
+major
*1.2*f
,c
+major
*f
*0.8]
1109 colours
+= [colour
,colour
]
1111 if bone
.cv_data
.con0
:
1112 _angle_lim( Vector((0,1,0)),Vector((0,0,1)), \
1113 bone
.cv_data
.mins
[0], bone
.cv_data
.maxs
[0], \
1115 _angle_lim( Vector((0,0,1)),Vector((1,0,0)), \
1116 bone
.cv_data
.mins
[1], bone
.cv_data
.maxs
[1], \
1118 _angle_lim( Vector((1,0,0)),Vector((0,1,0)), \
1119 bone
.cv_data
.mins
[2], bone
.cv_data
.maxs
[2], \
1123 if obj
.cv_data
.classtype
== 'k_classtype_gate':
1124 if obj
.type == 'MESH':
1125 dims
= obj
.data
.cv_data
.v0
1127 dims
= obj
.cv_data
.v0
1130 c
= Vector((0,0,dims
[2]))
1132 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
1133 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
1134 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
1135 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
1136 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
1137 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
1138 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
1139 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
1140 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
1142 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
1147 verts
+= [(v0
[0],v0
[1],v0
[2])]
1148 verts
+= [(v1
[0],v1
[1],v1
[2])]
1149 colours
+= [(1,1,0,1),(1,1,0,1)]
1151 sw
= (0.4,0.4,0.4,0.2)
1152 if obj
.cv_data
.target
!= None:
1153 drawbline( obj
.location
, obj
.cv_data
.target
.location
, sw
,sw
)
1155 elif obj
.cv_data
.classtype
== 'k_classtype_route_node':
1156 sw
= Vector((0.4,0.4,0.4,0.2))
1157 sw2
= Vector((1.5,0.2,0.2,0.0))
1158 if obj
.cv_data
.target
!= None:
1159 drawbpath( obj
, obj
.cv_data
.target
, sw
, sw
)
1160 if obj
.cv_data
.target1
!= None:
1161 drawbpath( obj
, obj
.cv_data
.target1
, sw
, sw
)
1163 drawbhandle( obj
, 1.0, (0.8,0.8,0.8,1.0) )
1164 drawbhandle( obj
, -1.0, (0.4,0.4,0.4,1.0) )
1166 p1
= obj
.location
+ \
1167 obj
.matrix_world
.to_quaternion() @ Vector((0,0,-6+1.5))
1168 drawbline( obj
.location
, p1
, sw
,sw2
)
1170 elif obj
.cv_data
.classtype
== 'k_classtype_achievement_box':
1171 a
= Vector((-1,-1,-1))
1175 vs
[0] = obj
.matrix_world
@ Vector((a
[0], a
[1], a
[2]))
1176 vs
[1] = obj
.matrix_world
@ Vector((a
[0], b
[1], a
[2]))
1177 vs
[2] = obj
.matrix_world
@ Vector((b
[0], b
[1], a
[2]))
1178 vs
[3] = obj
.matrix_world
@ Vector((b
[0], a
[1], a
[2]))
1179 vs
[4] = obj
.matrix_world
@ Vector((a
[0], a
[1], b
[2]))
1180 vs
[5] = obj
.matrix_world
@ Vector((a
[0], b
[1], b
[2]))
1181 vs
[6] = obj
.matrix_world
@ Vector((b
[0], b
[1], b
[2]))
1182 vs
[7] = obj
.matrix_world
@ Vector((b
[0], a
[1], b
[2]))
1184 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1185 (0,4),(1,5),(2,6),(3,7)]
1190 verts
+= [(v0
[0],v0
[1],v0
[2])]
1191 verts
+= [(v1
[0],v1
[1],v1
[2])]
1192 colours
+= [(0,1,0,1),(0,1,0,1)]
1194 elif obj
.cv_data
.classtype
== 'k_classtype_block':
1195 a
= obj
.data
.cv_data
.v0
1196 b
= obj
.data
.cv_data
.v1
1199 vs
[0] = obj
.matrix_world
@ Vector((a
[0], a
[1], a
[2]))
1200 vs
[1] = obj
.matrix_world
@ Vector((a
[0], b
[1], a
[2]))
1201 vs
[2] = obj
.matrix_world
@ Vector((b
[0], b
[1], a
[2]))
1202 vs
[3] = obj
.matrix_world
@ Vector((b
[0], a
[1], a
[2]))
1203 vs
[4] = obj
.matrix_world
@ Vector((a
[0], a
[1], b
[2]))
1204 vs
[5] = obj
.matrix_world
@ Vector((a
[0], b
[1], b
[2]))
1205 vs
[6] = obj
.matrix_world
@ Vector((b
[0], b
[1], b
[2]))
1206 vs
[7] = obj
.matrix_world
@ Vector((b
[0], a
[1], b
[2]))
1208 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1209 (0,4),(1,5),(2,6),(3,7)]
1214 verts
+= [(v0
[0],v0
[1],v0
[2])]
1215 verts
+= [(v1
[0],v1
[1],v1
[2])]
1216 colours
+= [(1,1,0,1),(1,1,0,1)]
1218 elif obj
.cv_data
.classtype
== 'k_classtype_capsule':
1219 h
= obj
.data
.cv_data
.v0
[0]
1220 r
= obj
.data
.cv_data
.v0
[1]
1223 vs
[0] = obj
.matrix_world
@ Vector((0.0,0.0, h
*0.5 ))
1224 vs
[1] = obj
.matrix_world
@ Vector((0.0,0.0,-h
*0.5 ))
1225 vs
[2] = obj
.matrix_world
@ Vector(( r
,0.0, h
*0.5-r
))
1226 vs
[3] = obj
.matrix_world
@ Vector(( -r
,0.0, h
*0.5-r
))
1227 vs
[4] = obj
.matrix_world
@ Vector(( r
,0.0,-h
*0.5+r
))
1228 vs
[5] = obj
.matrix_world
@ Vector(( -r
,0.0,-h
*0.5+r
))
1229 vs
[6] = obj
.matrix_world
@ Vector((0.0, r
, h
*0.5-r
))
1230 vs
[7] = obj
.matrix_world
@ Vector((0.0,-r
, h
*0.5-r
))
1231 vs
[8] = obj
.matrix_world
@ Vector((0.0, r
,-h
*0.5+r
))
1232 vs
[9] = obj
.matrix_world
@ Vector((0.0,-r
,-h
*0.5+r
))
1234 indices
= [(0,1),(2,3),(4,5),(6,7),(8,9)]
1239 verts
+= [(v0
[0],v0
[1],v0
[2])]
1240 verts
+= [(v1
[0],v1
[1],v1
[2])]
1241 colours
+= [(0.5,1,0,1),(0.5,1,0,1)]
1243 elif obj
.cv_data
.classtype
== 'k_classtype_spawn':
1245 vs
[0] = obj
.matrix_world
@ Vector((0,0,0))
1246 vs
[1] = obj
.matrix_world
@ Vector((0,2,0))
1247 vs
[2] = obj
.matrix_world
@ Vector((0.5,1,0))
1248 vs
[3] = obj
.matrix_world
@ Vector((-0.5,1,0))
1249 indices
= [(0,1),(1,2),(1,3)]
1253 verts
+= [(v0
[0],v0
[1],v0
[2])]
1254 verts
+= [(v1
[0],v1
[1],v1
[2])]
1255 colours
+= [(0,1,1,1),(0,1,1,1)]
1257 elif obj
.cv_data
.classtype
== 'k_classtype_route':
1259 vs
[0] = obj
.location
1260 vs
[1] = obj
.cv_data
.target
.location
1265 verts
+= [(v0
[0],v0
[1],v0
[2])]
1266 verts
+= [(v1
[0],v1
[1],v1
[2])]
1267 colours
+= [(0,1,1,1),(0,1,1,1)]
1271 stack
[0] = obj
.cv_data
.target
1273 loop_complete
= False
1276 if stack_i
[si
-1] == 2:
1280 if si
== 0: # Loop failed to complete
1285 targets
= [None,None]
1286 targets
[0] = node
.cv_data
.target
1288 if node
.cv_data
.classtype
== 'k_classtype_route_node':
1289 targets
[1] = node
.cv_data
.target1
1291 nextnode
= targets
[stack_i
[si
-1]]
1294 if nextnode
!= None: # branch
1295 if nextnode
== stack
[0]: # Loop completed
1296 loop_complete
= True
1300 for sj
in range(si
):
1301 if stack
[sj
] == nextnode
: # invalidated path
1307 stack
[si
] = nextnode
1312 cc
= Vector((obj
.cv_data
.colour
[0],\
1313 obj
.cv_data
.colour
[1],\
1314 obj
.cv_data
.colour
[2],\
1317 for sj
in range(si
):
1320 if stack
[sj
].cv_data
.classtype
== 'k_classtype_gate' and \
1321 stack
[sk
].cv_data
.classtype
== 'k_classtype_gate':
1322 dist
= (stack
[sj
].location
-stack
[sk
].location
).magnitude
1323 drawsbpath( stack
[sj
], stack
[sk
], cc
*0.4, cc
, dist
, dist
)
1326 drawbpath( stack
[sj
], stack
[sk
], cc
, cc
)
1330 elif obj
.cv_data
.classtype
== 'k_classtype_car_path':
1331 v0
= obj
.matrix_world
.to_quaternion() @ Vector((0,1,0))
1332 c0
= Vector((v0
.x
*0.5+0.5, v0
.y
*0.5+0.5, 0.0, 1.0))
1333 drawbhandle( obj
, 1.0, (0.9,0.9,0.9,1.0) )
1335 if obj
.cv_data
.target
!= None:
1336 v1
= obj
.cv_data
.target
.matrix_world
.to_quaternion()@Vector((0,1,0))
1337 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1339 drawbhandle( obj
.cv_data
.target
, -1.0, (0.5,0.5,0.5,1.0) )
1340 drawbpath( obj
, obj
.cv_data
.target
, c0
, c1
)
1342 if obj
.cv_data
.target1
!= None:
1343 v1
= obj
.cv_data
.target1
.matrix_world
.to_quaternion()@Vector((0,1,0))
1344 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1346 drawbhandle( obj
.cv_data
.target1
, -1.0, (0.5,0.5,0.5,1.0) )
1347 drawbpath( obj
, obj
.cv_data
.target1
, c0
, c1
)
1349 lines
= batch_for_shader(\
1350 cv_view_shader
, 'LINES', \
1351 { "pos":verts
, "color":colours
})
1353 lines
.draw( cv_view_shader
)
1355 def cv_poll_target(scene
, obj
):
1356 if obj
== bpy
.context
.active_object
:
1358 if obj
.cv_data
.classtype
== 'k_classtype_none':
1362 class CV_MESH_SETTINGS(bpy
.types
.PropertyGroup
):
1363 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1364 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1365 v2
: bpy
.props
.FloatVectorProperty(name
="v2",size
=3)
1366 v3
: bpy
.props
.FloatVectorProperty(name
="v3",size
=3)
1368 class CV_OBJ_SETTINGS(bpy
.types
.PropertyGroup
):
1369 uid
: bpy
.props
.IntProperty( name
="" )
1371 strp
: bpy
.props
.StringProperty(name
="string")
1373 target
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target", \
1374 poll
=cv_poll_target
)
1375 target1
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target1", \
1376 poll
=cv_poll_target
)
1378 colour
: bpy
.props
.FloatVectorProperty(name
="colour",subtype
='COLOR',\
1381 classtype
: bpy
.props
.EnumProperty(
1384 ('k_classtype_none', "k_classtype_none", "", 0),
1385 ('k_classtype_gate', "k_classtype_gate", "", 1),
1386 ('k_classtype_block', "k_classtype_block", "", 2),
1387 ('k_classtype_spawn', "k_classtype_spawn", "", 3),
1388 ('k_classtype_water', "k_classtype_water", "", 4),
1389 ('k_classtype_car_path', "k_classtype_car_path", "", 5),
1390 ('k_classtype_INSTANCE', "","", 6 ),
1391 ('k_classtype_capsule', "k_classtype_capsule", "", 7 ),
1392 ('k_classtype_route_node', "k_classtype_route_node", "", 8 ),
1393 ('k_classtype_route', "k_classtype_route", "", 9 ),
1394 ('k_classtype_bone',"k_classtype_bone","",10),
1395 ('k_classtype_SKELETON', "","", 11 ),
1396 ('k_classtype_SKIN',"","",12),
1397 ('k_classtype_achievement_box',"k_classtype_achievement_box","",13),
1400 class CV_BONE_SETTINGS(bpy
.types
.PropertyGroup
):
1401 collider
: bpy
.props
.BoolProperty(name
="Collider",default
=False)
1402 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1403 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1405 con0
: bpy
.props
.BoolProperty(name
="Constriant 0",default
=False)
1406 mins
: bpy
.props
.FloatVectorProperty(name
="mins",size
=3)
1407 maxs
: bpy
.props
.FloatVectorProperty(name
="maxs",size
=3)
1409 class CV_BONE_PANEL(bpy
.types
.Panel
):
1410 bl_label
="Bone Config"
1411 bl_idname
="SCENE_PT_cv_bone"
1412 bl_space_type
='PROPERTIES'
1413 bl_region_type
='WINDOW'
1416 def draw(_
,context
):
1417 active_object
= context
.active_object
1418 if active_object
== None: return
1420 bone
= active_object
.data
.bones
.active
1421 if bone
== None: return
1423 _
.layout
.prop( bone
.cv_data
, "collider" )
1424 _
.layout
.prop( bone
.cv_data
, "v0" )
1425 _
.layout
.prop( bone
.cv_data
, "v1" )
1427 _
.layout
.label( text
="Angle Limits" )
1428 _
.layout
.prop( bone
.cv_data
, "con0" )
1429 _
.layout
.prop( bone
.cv_data
, "mins" )
1430 _
.layout
.prop( bone
.cv_data
, "maxs" )
1432 class CV_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
1433 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
1435 class CV_OBJ_PANEL(bpy
.types
.Panel
):
1436 bl_label
="Entity Config"
1437 bl_idname
="SCENE_PT_cv_entity"
1438 bl_space_type
='PROPERTIES'
1439 bl_region_type
='WINDOW'
1442 def draw(_
,context
):
1443 active_object
= bpy
.context
.active_object
1444 if active_object
== None: return
1445 _
.layout
.prop( active_object
.cv_data
, "classtype" )
1447 if active_object
.cv_data
.classtype
== 'k_classtype_gate':
1448 _
.layout
.prop( active_object
.cv_data
, "target" )
1450 mesh
= active_object
.data
1451 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1452 _
.layout
.prop( mesh
.cv_data
, "v0" )
1454 elif active_object
.cv_data
.classtype
== 'k_classtype_car_path' or \
1455 active_object
.cv_data
.classtype
== 'k_classtype_route_node':
1456 _
.layout
.prop( active_object
.cv_data
, "target" )
1457 _
.layout
.prop( active_object
.cv_data
, "target1" )
1459 elif active_object
.cv_data
.classtype
== 'k_classtype_route':
1460 _
.layout
.prop( active_object
.cv_data
, "target" )
1461 _
.layout
.prop( active_object
.cv_data
, "colour" )
1463 elif active_object
.cv_data
.classtype
== 'k_classtype_block':
1464 mesh
= active_object
.data
1466 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1467 _
.layout
.prop( mesh
.cv_data
, "v0" )
1468 _
.layout
.prop( mesh
.cv_data
, "v1" )
1469 _
.layout
.prop( mesh
.cv_data
, "v2" )
1470 _
.layout
.prop( mesh
.cv_data
, "v3" )
1471 elif active_object
.cv_data
.classtype
== 'k_classtype_capsule':
1472 mesh
= active_object
.data
1473 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1474 _
.layout
.prop( mesh
.cv_data
, "v0" )
1475 elif active_object
.cv_data
.classtype
== 'k_classtype_achievement_box':
1476 _
.layout
.prop( active_object
.cv_data
, "strp" )
1478 class CV_INTERFACE(bpy
.types
.Panel
):
1479 bl_idname
= "VIEW3D_PT_carve"
1481 bl_space_type
= 'VIEW_3D'
1482 bl_region_type
= 'UI'
1483 bl_category
= "Carve"
1485 def draw(_
, context
):
1487 layout
.prop( context
.scene
.cv_data
, "use_hidden")
1488 layout
.operator( "carve.compile_all" )
1491 view_layer
= bpy
.context
.view_layer
1492 for col
in view_layer
.layer_collection
.children
["export"].children
:
1493 if not col
.hide_viewport
or bpy
.context
.scene
.cv_data
.use_hidden
:
1494 write_model( col
.name
)
1496 class CV_COMPILE(bpy
.types
.Operator
):
1497 bl_idname
="carve.compile_all"
1498 bl_label
="Compile All"
1500 def execute(_
,context
):
1502 #cProfile.runctx("test_compile()",globals(),locals(),sort=1)
1503 #for col in bpy.data.collections["export"].children:
1504 # write_model( col.name )
1508 classes
= [CV_OBJ_SETTINGS
,CV_OBJ_PANEL
,CV_COMPILE
,CV_INTERFACE
,\
1509 CV_MESH_SETTINGS
, CV_SCENE_SETTINGS
, CV_BONE_SETTINGS
,\
1513 global cv_view_draw_handler
1516 bpy
.utils
.register_class(c
)
1518 bpy
.types
.Object
.cv_data
= bpy
.props
.PointerProperty(type=CV_OBJ_SETTINGS
)
1519 bpy
.types
.Mesh
.cv_data
= bpy
.props
.PointerProperty(type=CV_MESH_SETTINGS
)
1520 bpy
.types
.Scene
.cv_data
= bpy
.props
.PointerProperty(type=CV_SCENE_SETTINGS
)
1521 bpy
.types
.Bone
.cv_data
= bpy
.props
.PointerProperty(type=CV_BONE_SETTINGS
)
1523 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
1524 cv_draw
,(),'WINDOW','POST_VIEW')
1527 global cv_view_draw_handler
1530 bpy
.utils
.unregister_class(c
)
1532 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')