a8061e4ed9241baa12cd77c379284a94fcb9339e
4 from mathutils
import *
5 from gpu_extras
.batch
import batch_for_shader
8 "name":"Carve exporter",
9 "author": "Harry Godden (hgn)",
16 "category":"Import/Export",
19 class mdl_vert(Structure
):
21 _fields_
= [("co",c_float
*3),
25 ("weights",c_uint16
*4),
28 class mdl_submesh(Structure
):
30 _fields_
= [("indice_start",c_uint32
),
31 ("indice_count",c_uint32
),
32 ("vertex_start",c_uint32
),
33 ("vertex_count",c_uint32
),
34 ("bbx",(c_float
*3)*2),
35 ("material_id",c_uint32
)] # index into the material array
37 class mdl_material(Structure
):
39 _fields_
= [("pstr_name",c_uint32
)]
41 class mdl_node(Structure
):
43 _fields_
= [("co",c_float
*3),
46 ("submesh_start",c_uint32
),
47 ("submesh_count",c_uint32
),
48 ("classtype",c_uint32
),
51 ("pstr_name",c_uint32
)]
53 class mdl_header(Structure
):
55 _fields_
= [("identifier",c_uint32
),
57 ("file_length",c_uint32
),
58 ("vertex_count",c_uint32
),
59 ("vertex_offset",c_uint32
),
61 ("indice_count",c_uint32
),
62 ("indice_offset",c_uint32
),
64 ("submesh_count",c_uint32
),
65 ("submesh_offset",c_uint32
),
67 ("material_count",c_uint32
),
68 ("material_offset",c_uint32
),
70 ("node_count",c_uint32
),
71 ("node_offset",c_uint32
),
73 ("anim_count",c_uint32
),
74 ("anim_offset",c_uint32
),
76 ("strings_offset",c_uint32
),
77 ("entdata_offset",c_uint32
),
78 ("animdata_offset",c_uint32
)
81 class mdl_animation(Structure
):
83 _fields_
= [("pstr_name",c_uint32
),
88 class mdl_keyframe(Structure
):
90 _fields_
= [("co",c_float
*3),
95 # ==========================================
97 class classtype_gate(Structure
):
99 _fields_
= [("target",c_uint32
),
102 class classtype_block(Structure
):
104 _fields_
= [("bbx",(c_float
*3)*2)]
106 class classtype_spawn(Structure
):
108 _fields_
= [("temp",c_uint32
)]
110 class classtype_water(Structure
):
112 _fields_
= [("temp",c_uint32
)]
114 class classtype_car_path(Structure
):
116 _fields_
= [("target",c_uint32
),
117 ("target1",c_uint32
)]
119 class classtype_instance(Structure
):
121 _fields_
= [("pstr_file",c_uint32
)]
123 class classtype_capsule(Structure
):
125 _fields_
= [("height",c_float
),
128 class classtype_route_node(Structure
):
130 _fields_
= [("target",c_uint32
),
131 ("target1",c_uint32
)]
133 class classtype_route(Structure
):
135 _fields_
= [("pstr_name",c_uint32
),
136 ("id_start",c_uint32
),
137 ("colour",c_float
*3)]
139 class classtype_skin(Structure
):
141 _fields_
= [("skeleton",c_uint32
)]
143 class classtype_skeleton(Structure
):
145 _fields_
= [("channels",c_uint32
),
146 ("ik_count",c_uint32
),
147 ("collider_count",c_uint32
),
148 ("anim_start",c_uint32
),
149 ("anim_count",c_uint32
)]
151 class classtype_bone(Structure
):
153 _fields_
= [("deform",c_uint32
),
154 ("ik_target",c_uint32
),
155 ("ik_pole",c_uint32
),
156 ("collider",c_uint32
),
157 ("use_limits",c_uint32
),
158 ("angle_limits",(c_float
*3)*2),
159 ("hitbox",(c_float
*3)*2)]
161 class subclass_audio_channel(Structure
):
163 _fields_
= [("sound",c_uint32
),
167 class classtype_audio_system(Structure
):
169 _fields_
= [("sounds", subclass_audio_channel
* 4),
172 class classtype_audio_zone(Structure
):
174 _fields_
= [("system",c_uint32
)]
177 # ==============================================================================
179 def write_model(collection_name
):
180 print( F
"Model graph | Create mode '{collection_name}'" )
182 header
= mdl_header()
183 header
.identifier
= 0xABCD0000
185 header
.vertex_count
= 0
186 header
.indice_count
= 0
187 header
.submesh_count
= 0
188 header
.node_count
= 0
189 header
.material_count
= 0
190 header
.file_length
= 0
210 def emplace_string( s
):
211 nonlocal string_cache
, strings_buffer
213 if s
in string_cache
:
214 return string_cache
[s
]
216 string_cache
[s
] = len( strings_buffer
)
217 strings_buffer
+= (s
+'\0').encode('utf-8')
218 return string_cache
[s
]
220 def emplace_material( mat
):
221 nonlocal material_cache
, material_buffer
226 if mat
.name
in material_cache
:
227 return material_cache
[mat
.name
]
229 material_cache
[mat
.name
] = header
.material_count
230 dest
= mdl_material()
231 dest
.pstr_name
= emplace_string( mat
.name
)
232 material_buffer
+= [dest
]
234 header
.material_count
+= 1
235 return material_cache
[mat
.name
]
237 # Create root or empty node and materials
238 # this is to designate id 0 as 'NULL'
240 none_material
= c_uint32(69)
241 none_material
.name
= ""
242 emplace_material( none_material
)
255 root
.pstr_name
= emplace_string('')
256 root
.submesh_start
= 0
257 root
.submesh_count
= 0
260 node_buffer
+= [root
]
264 print( " assigning ids" )
265 collection
= bpy
.data
.collections
[collection_name
]
268 # ==========================================
270 header
.node_count
= 0
273 uid
= header
.node_count
274 header
.node_count
+= 1
277 print( " creating scene graph" )
281 graph
["children"] = []
282 graph
["uid"] = _uid()
283 graph
["parent"] = None
285 graph_lookup
= {} # object can lookup its graph def here
287 for obj
in collection
.all_objects
:
290 def _extend( p
, n
, d
):
294 tree
["children"] = []
300 if n
.type == 'ARMATURE':
301 tree
["bones"] = [None] # None is the root transform
303 tree
["collider_count"] = 0
305 def _extendb( p
, n
, d
):
310 btree
["uid"] = _uid()
311 btree
["children"] = []
314 tree
["bones"] += [n
.name
]
317 _extendb( btree
, c
, d
+1 )
319 for c
in tree
['obj'].pose
.bones
[n
.name
].constraints
:
321 btree
["target"] = c
.subtarget
322 btree
["pole"] = c
.pole_subtarget
323 tree
["ik_count"] += 1
325 if n
.cv_data
.collider
:
326 tree
['collider_count'] += 1
328 btree
['deform'] = n
.use_deform
329 p
['children'] += [btree
]
331 for b
in n
.data
.bones
:
333 _extendb( tree
, b
, d
+1 )
335 for obj1
in n
.children
:
336 _extend( tree
, obj1
, d
+1 )
338 p
["children"] += [tree
]
339 graph_lookup
[n
] = tree
341 _extend( graph
, obj
, 1 )
345 for c
in p
['children']:
347 yield from _graph_iter(c
)
349 it
= _graph_iter(graph
)
351 root
.parent
= 0xffffffff
354 # ==============================================
355 it
= _graph_iter(graph
)
356 print( " compiling data" )
358 if 'obj' in node_def
:
359 obj
= node_def
['obj']
362 elif 'bone' in node_def
:
363 obj
= node_def
['bone']
365 objco
= obj
.head_local
367 depth
= node_def
['depth']
368 uid
= node_def
['uid']
371 node
.co
[0] = objco
[0]
372 node
.co
[1] = objco
[2]
373 node
.co
[2] = -objco
[1]
375 # Convert rotation quat to our space type
376 quat
= obj
.matrix_local
.to_quaternion()
383 node
.s
[0] = obj
.tail_local
[0] - node
.co
[0]
384 node
.s
[1] = obj
.tail_local
[2] - node
.co
[1]
385 node
.s
[2] = -obj
.tail_local
[1] - node
.co
[2]
387 node
.s
[0] = obj
.scale
[0]
388 node
.s
[1] = obj
.scale
[2]
389 node
.s
[2] = obj
.scale
[1]
391 node
.pstr_name
= emplace_string( obj
.name
)
393 if node_def
["parent"]:
394 node
.parent
= node_def
["parent"]["uid"]
397 classtype
= 'k_classtype_bone'
398 elif objt
== 'ARMATURE':
399 classtype
= 'k_classtype_skeleton'
401 classtype
= obj
.cv_data
.classtype
404 # =================================================================
407 # Dont use the cache if we have modifiers that affect the normals
415 for mod
in obj
.modifiers
:
416 if mod
.type == 'DATA_TRANSFER' or mod
.type == 'SHRINKWRAP' or \
417 mod
.type == 'BOOLEAN' or mod
.type == 'CURVE' or \
419 can_use_cache
= False
421 if mod
.type == 'ARMATURE':
422 classtype
= 'k_classtype_skin'
423 armature_def
= graph_lookup
[mod
.object]
424 POSE_OR_REST_CACHE
= armature_def
['obj'].data
.pose_position
426 armature_def
['obj'].data
.pose_position
= 'REST'
428 if can_use_cache
and obj
.data
.name
in mesh_cache
:
429 ref
= mesh_cache
[obj
.data
.name
]
430 node
.submesh_start
= ref
.submesh_start
431 node
.submesh_count
= ref
.submesh_count
435 node
.submesh_start
= header
.submesh_count
436 node
.submesh_count
= 0
438 default_mat
= c_uint32(69)
439 default_mat
.name
= ""
441 dgraph
= bpy
.context
.evaluated_depsgraph_get()
442 data
= obj
.evaluated_get(dgraph
).data
443 data
.calc_loop_triangles()
444 data
.calc_normals_split()
446 mat_list
= data
.materials
if len(data
.materials
) > 0 else [default_mat
]
447 for material_id
, mat
in enumerate(mat_list
):
451 sm
.indice_start
= header
.indice_count
452 sm
.vertex_start
= header
.vertex_count
455 sm
.material_id
= emplace_material( mat
)
458 sm
.bbx
[0][i
] = 999999
459 sm
.bbx
[1][i
] = -999999
463 # Write the vertex / indice data
465 for tri_index
, tri
in enumerate(data
.loop_triangles
):
466 if tri
.material_index
!= material_id
:
470 vert
= data
.vertices
[tri
.vertices
[j
]]
472 vi
= data
.loops
[li
].vertex_index
475 norm
= data
.loops
[li
].normal
477 colour
= (255,255,255,255)
482 uv
= data
.uv_layers
.active
.data
[li
].uv
484 if data
.vertex_colors
:
485 colour
= data
.vertex_colors
.active
.data
[li
].color
486 colour
= (int(colour
[0]*255.0),\
487 int(colour
[1]*255.0),\
488 int(colour
[2]*255.0),\
489 int(colour
[3]*255.0))
494 src_groups
= [_
for _
in data
.vertices
[vi
].groups \
495 if obj
.vertex_groups
[_
.group
].name
in \
496 armature_def
['bones']]
498 weight_groups
= sorted( src_groups
, key
= \
499 lambda a
: a
.weight
, reverse
=True )
502 if len(weight_groups
) > ml
:
503 g
= weight_groups
[ml
]
504 name
= obj
.vertex_groups
[g
.group
].name
508 groups
[ml
] = armature_def
['bones'].index(name
)
511 if len(weight_groups
) > 0:
512 inv_norm
= (1.0/tot
) * 65535.0
514 weights
[ml
] = int( weights
[ml
] * inv_norm
)
515 weights
[ml
] = min( weights
[ml
], 65535 )
516 weights
[ml
] = max( weights
[ml
], 0 )
519 m
= float(10**TOLERENCE
)
521 key
= (int(co
[0]*m
+0.5),\
543 indice_buffer
+= [boffa
[key
]]
545 index
= c_uint32(sm
.vertex_count
)
549 indice_buffer
+= [index
]
560 v
.colour
[0] = colour
[0]
561 v
.colour
[1] = colour
[1]
562 v
.colour
[2] = colour
[2]
563 v
.colour
[3] = colour
[3]
564 v
.weights
[0] = weights
[0]
565 v
.weights
[1] = weights
[1]
566 v
.weights
[2] = weights
[2]
567 v
.weights
[3] = weights
[3]
568 v
.groups
[0] = groups
[0]
569 v
.groups
[1] = groups
[1]
570 v
.groups
[2] = groups
[2]
571 v
.groups
[3] = groups
[3]
576 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
577 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
581 if sm
.vertex_count
== 0:
586 submesh_buffer
+= [sm
]
587 node
.submesh_count
+= 1
588 header
.submesh_count
+= 1
589 header
.vertex_count
+= sm
.vertex_count
590 header
.indice_count
+= sm
.indice_count
592 mesh_cache
[obj
.data
.name
] = node
594 # Process entity data
595 # ==================================================================
596 node
.offset
= entdata_length
598 if classtype
!= 'k_classtype_none':
603 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
604 s001
= F
" L {obj.name}"
607 s004
= F
"{node.parent: 3}"
610 if classtype
== 'k_classtype_skin':
611 armature_def
['obj'].data
.pose_position
= POSE_OR_REST_CACHE
612 s005
= F
" [armature -> {armature_def['obj'].cv_data.uid}]"
614 scmp
= F
"{s002:<32} {s003:<22} {s004} {s005}"
617 if classtype
== 'k_classtype_INSTANCE' or \
618 classtype
== 'k_classtype_BONE' or \
619 classtype
== 'k_classtype_SKELETON' or \
620 classtype
== 'k_classtype_SKIN':
621 print( "ERROR: user classtype cannot be _INSTANCE or _BONE" )
625 elif classtype
== 'k_classtype_skin':
628 armature
= armature_def
['obj']
629 entdata_length
+= sizeof( classtype_skin
)
631 skin
= classtype_skin()
632 skin
.skeleton
= armature
.cv_data
.uid
633 entdata_buffer
+= [skin
]
635 elif classtype
== 'k_classtype_skeleton':
637 entdata_length
+= sizeof( classtype_skeleton
)
638 skeleton
= classtype_skeleton()
640 armature_def
= graph_lookup
[obj
]
642 bones
= armature_def
['bones']
643 skeleton
.channels
= len(bones
)
644 skeleton
.ik_count
= armature_def
["ik_count"]
645 skeleton
.collider_count
= armature_def
["collider_count"]
647 if armature
.animation_data
:
648 previous_frame
= bpy
.context
.scene
.frame_current
649 previous_action
= armature
.animation_data
.action
651 skeleton
.anim_start
= len(anim_buffer
)
652 skeleton
.anim_count
= 0
654 for NLALayer
in obj
.animation_data
.nla_tracks
:
655 for NLAStrip
in NLALayer
.strips
:
657 for a
in bpy
.data
.actions
:
658 if a
.name
== NLAStrip
.name
:
659 armature
.animation_data
.action
= a
662 anim_start
= int(NLAStrip
.action_frame_start
)
663 anim_end
= int(NLAStrip
.action_frame_end
)
666 anim
= mdl_animation()
667 anim
.pstr_name
= emplace_string( NLAStrip
.action
.name
)
669 anim
.offset
= animdata_length
670 anim
.length
= anim_end
-anim_start
672 # Export the fucking keyframes
673 for frame
in range(anim_start
,anim_end
):
674 bpy
.context
.scene
.frame_set(frame
)
676 for bone_name
in bones
:
677 for pb
in armature
.pose
.bones
:
678 if pb
.name
== bone_name
:
679 rb
= armature
.data
.bones
[ bone_name
]
681 # relative bone matrix
682 if rb
.parent
is not None:
683 offset_mtx
= rb
.parent
.matrix_local
684 offset_mtx
= offset_mtx
.inverted_safe() @ \
687 inv_parent
= pb
.parent
.matrix
@ offset_mtx
688 inv_parent
.invert_safe()
689 fpm
= inv_parent
@ pb
.matrix
691 bone_mtx
= rb
.matrix
.to_4x4()
692 local_inv
= rb
.matrix_local
.inverted_safe()
693 fpm
= bone_mtx
@ local_inv
@ pb
.matrix
695 loc
, rot
, sca
= fpm
.decompose()
698 final_pos
= Vector(( loc
[0], loc
[2], -loc
[1] ))
701 lc_m
= pb
.matrix_channel
.to_3x3()
702 if pb
.parent
is not None:
703 smtx
= pb
.parent
.matrix_channel
.to_3x3()
704 lc_m
= smtx
.inverted() @ lc_m
705 rq
= lc_m
.to_quaternion()
708 kf
.co
[0] = final_pos
[0]
709 kf
.co
[1] = final_pos
[1]
710 kf
.co
[2] = final_pos
[2]
722 animdata_buffer
+= [kf
]
723 animdata_length
+= sizeof(mdl_keyframe
)
726 anim_buffer
+= [anim
]
727 skeleton
.anim_count
+= 1
729 s000
= F
" [{uid: 3}/{header.node_count-1}]" + " |"*(depth
-1)
730 print( F
"{s000} | *anim: {NLAStrip.action.name}" )
732 bpy
.context
.scene
.frame_set( previous_frame
)
733 armature
.animation_data
.action
= previous_action
735 entdata_buffer
+= [skeleton
]
737 elif classtype
== 'k_classtype_bone':
739 entdata_length
+= sizeof( classtype_bone
)
741 bone
= classtype_bone()
742 bone
.deform
= node_def
['deform']
744 if 'target' in node_def
:
745 bone
.ik_target
= armature_def
['bones'].index( node_def
['target'] )
746 bone
.ik_pole
= armature_def
['bones'].index( node_def
['pole'] )
751 bone
.collider
= 1 if obj
.cv_data
.collider
else 0
752 if obj
.cv_data
.collider
:
753 bone
.hitbox
[0][0] = obj
.cv_data
.v0
[0]
754 bone
.hitbox
[0][1] = obj
.cv_data
.v0
[2]
755 bone
.hitbox
[0][2] = -obj
.cv_data
.v1
[1]
756 bone
.hitbox
[1][0] = obj
.cv_data
.v1
[0]
757 bone
.hitbox
[1][1] = obj
.cv_data
.v1
[2]
758 bone
.hitbox
[1][2] = -obj
.cv_data
.v0
[1]
760 bone
.hitbox
[0][0] = 0.0
761 bone
.hitbox
[0][1] = 0.0
762 bone
.hitbox
[0][2] = 0.0
763 bone
.hitbox
[1][0] = 0.0
764 bone
.hitbox
[1][1] = 0.0
765 bone
.hitbox
[1][2] = 0.0
769 bone
.angle_limits
[0][0] = obj
.cv_data
.mins
[0]
770 bone
.angle_limits
[0][1] = obj
.cv_data
.mins
[2]
771 bone
.angle_limits
[0][2] = -obj
.cv_data
.maxs
[1]
772 bone
.angle_limits
[1][0] = obj
.cv_data
.maxs
[0]
773 bone
.angle_limits
[1][1] = obj
.cv_data
.maxs
[2]
774 bone
.angle_limits
[1][2] = -obj
.cv_data
.mins
[1]
777 bone
.angle_limits
[0][0] = 0.0
778 bone
.angle_limits
[0][1] = 0.0
779 bone
.angle_limits
[0][2] = 0.0
780 bone
.angle_limits
[1][0] = 0.0
781 bone
.angle_limits
[1][1] = 0.0
782 bone
.angle_limits
[1][2] = 0.0
784 bone
.deform
= node_def
['deform']
785 entdata_buffer
+= [bone
]
787 elif classtype
== 'k_classtype_gate':
789 entdata_length
+= sizeof( classtype_gate
)
791 gate
= classtype_gate()
793 if obj
.cv_data
.target
!= None:
794 gate
.target
= obj
.cv_data
.target
.cv_data
.uid
796 if obj
.type == 'MESH':
797 gate
.dims
[0] = obj
.data
.cv_data
.v0
[0]
798 gate
.dims
[1] = obj
.data
.cv_data
.v0
[1]
799 gate
.dims
[2] = obj
.data
.cv_data
.v0
[2]
801 gate
.dims
[0] = obj
.cv_data
.v0
[0]
802 gate
.dims
[1] = obj
.cv_data
.v0
[1]
803 gate
.dims
[2] = obj
.cv_data
.v0
[2]
805 entdata_buffer
+= [gate
]
807 elif classtype
== 'k_classtype_block':
809 entdata_length
+= sizeof( classtype_block
)
811 source
= obj
.data
.cv_data
813 block
= classtype_block()
814 block
.bbx
[0][0] = source
.v0
[0]
815 block
.bbx
[0][1] = source
.v0
[2]
816 block
.bbx
[0][2] = -source
.v1
[1]
818 block
.bbx
[1][0] = source
.v1
[0]
819 block
.bbx
[1][1] = source
.v1
[2]
820 block
.bbx
[1][2] = -source
.v0
[1]
821 entdata_buffer
+= [block
]
823 elif classtype
== 'k_classtype_spawn':
826 elif classtype
== 'k_classtype_water':
829 elif classtype
== 'k_classtype_car_path':
831 entdata_length
+= sizeof( classtype_car_path
)
833 pn
= classtype_car_path()
837 if obj
.cv_data
.target
!= None:
838 pn
.target
= obj
.cv_data
.target
.cv_data
.uid
839 if obj
.cv_data
.target1
!= None:
840 pn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
842 entdata_buffer
+= [pn
]
844 elif obj
.is_instancer
:
845 target
= obj
.instance_collection
848 entdata_length
+= sizeof( classtype_instance
)
850 inst
= classtype_instance()
851 inst
.pstr_file
= emplace_string( F
"models/{target.name}.mdl" )
852 entdata_buffer
+= [inst
]
854 elif classtype
== 'k_classtype_capsule':
857 elif classtype
== 'k_classtype_route_node':
859 entdata_length
+= sizeof( classtype_route_node
)
861 rn
= classtype_route_node()
862 if obj
.cv_data
.target
!= None:
863 rn
.target
= obj
.cv_data
.target
.cv_data
.uid
864 if obj
.cv_data
.target1
!= None:
865 rn
.target1
= obj
.cv_data
.target1
.cv_data
.uid
867 entdata_buffer
+= [rn
]
869 elif classtype
== 'k_classtype_route':
871 entdata_length
+= sizeof( classtype_route
)
872 r
= classtype_route()
873 r
.pstr_name
= emplace_string("not-implemented")
874 r
.colour
[0] = obj
.cv_data
.colour
[0]
875 r
.colour
[1] = obj
.cv_data
.colour
[1]
876 r
.colour
[2] = obj
.cv_data
.colour
[2]
878 if obj
.cv_data
.target
!= None:
879 r
.id_start
= obj
.cv_data
.target
.cv_data
.uid
881 entdata_buffer
+= [r
]
883 # classtype == 'k_classtype_none':
888 node_buffer
+= [node
]
892 header
.anim_count
= len(anim_buffer
)
894 print( "Writing data" )
895 fpos
= sizeof(header
)
897 print( F
"Nodes: {header.node_count}" )
898 header
.node_offset
= fpos
899 fpos
+= sizeof(mdl_node
)*header
.node_count
901 print( F
"Submeshes: {header.submesh_count}" )
902 header
.submesh_offset
= fpos
903 fpos
+= sizeof(mdl_submesh
)*header
.submesh_count
905 print( F
"Materials: {header.material_count}" )
906 header
.material_offset
= fpos
907 fpos
+= sizeof(mdl_material
)*header
.material_count
909 print( F
"Animation count: {header.anim_count}" )
910 header
.anim_offset
= fpos
911 fpos
+= sizeof(mdl_animation
)*header
.anim_count
913 print( F
"Entdata length: {entdata_length}" )
914 header
.entdata_offset
= fpos
915 fpos
+= entdata_length
917 print( F
"Vertex count: {header.vertex_count}" )
918 header
.vertex_offset
= fpos
919 fpos
+= sizeof(mdl_vert
)*header
.vertex_count
921 print( F
"Indice count: {header.indice_count}" )
922 header
.indice_offset
= fpos
923 fpos
+= sizeof(c_uint32
)*header
.indice_count
925 print( F
"Keyframe count: {animdata_length}" )
926 header
.animdata_offset
= fpos
927 fpos
+= animdata_length
929 print( F
"Strings length: {len(strings_buffer)}" )
930 header
.strings_offset
= fpos
931 fpos
+= len(strings_buffer
)
933 header
.file_length
= fpos
935 path
= F
"/home/harry/Documents/carve/models_src/{collection_name}.mdl"
936 fp
= open( path
, "wb" )
938 fp
.write( bytearray( header
) )
940 for node
in node_buffer
:
941 fp
.write( bytearray(node
) )
942 for sm
in submesh_buffer
:
943 fp
.write( bytearray(sm
) )
944 for mat
in material_buffer
:
945 fp
.write( bytearray(mat
) )
946 for a
in anim_buffer
:
947 fp
.write( bytearray(a
) )
948 for ed
in entdata_buffer
:
949 fp
.write( bytearray(ed
) )
950 for v
in vertex_buffer
:
951 fp
.write( bytearray(v
) )
952 for i
in indice_buffer
:
953 fp
.write( bytearray(i
) )
954 for kf
in animdata_buffer
:
955 fp
.write( bytearray(kf
) )
957 fp
.write( strings_buffer
)
960 print( F
"Completed {collection_name}.mdl" )
963 # ------------------------------------------------------------------------------
965 cv_view_draw_handler
= None
966 cv_view_shader
= gpu
.shader
.from_builtin('3D_SMOOTH_COLOR')
969 global cv_view_shader
970 cv_view_shader
.bind()
971 gpu
.state
.depth_mask_set(False)
972 gpu
.state
.line_width_set(2.0)
973 gpu
.state
.face_culling_set('BACK')
974 gpu
.state
.depth_test_set('LESS')
975 gpu
.state
.blend_set('NONE')
980 #def drawbezier(p0,h0,p1,h1,c0,c1):
981 # nonlocal verts, colours
985 # colours += [(0.5,0.5,0.5,1.0),(0.5,0.5,0.5,1)]
988 # colours += [(1.0,1.0,1,1),(1,1,1,1)]
991 # for i in range(10):
997 # p=ttt*p1+(3*tt-3*ttt)*h1+(3*ttt-6*tt+3*t)*h0+(3*tt-ttt-3*t+1)*p0
998 # verts += [(last[0],last[1],last[2])]
999 # verts += [(p[0],p[1],p[2])]
1000 # colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
1005 def drawbhandle(obj
, direction
, colour
):
1006 nonlocal verts
, colours
1008 h0
= obj
.matrix_world
@ Vector((0,direction
,0))
1011 colours
+= [colour
,colour
]
1013 def drawbezier(p0
,h0
,p1
,h1
,c0
,c1
):
1014 nonlocal verts
, colours
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
)]
1029 def drawsbpath(o0
,o1
,c0
,c1
,s0
,s1
):
1030 nonlocal course_count
1032 offs
= ((course_count
% 2)*2-1) * course_count
* 0.02
1034 p0
= o0
.matrix_world
@ Vector((offs
, 0,0))
1035 h0
= o0
.matrix_world
@ Vector((offs
, s0
,0))
1036 p1
= o1
.matrix_world
@ Vector((offs
, 0,0))
1037 h1
= o1
.matrix_world
@ Vector((offs
,-s1
,0))
1038 drawbezier(p0
,h0
,p1
,h1
,c0
,c1
)
1040 def drawbpath(o0
,o1
,c0
,c1
):
1041 drawsbpath(o0
,o1
,c0
,c1
,1.0,1.0)
1043 def drawbline(p0
,p1
,c0
,c1
):
1044 nonlocal verts
, colours
1048 for obj
in bpy
.context
.collection
.objects
:
1049 if obj
.type == 'ARMATURE':
1050 for bone
in obj
.data
.bones
:
1051 if bone
.cv_data
.collider
and obj
.data
.pose_position
== 'REST':
1057 vs
[0]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+a
[2]))
1058 vs
[1]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+a
[2]))
1059 vs
[2]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+a
[2]))
1060 vs
[3]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+a
[2]))
1061 vs
[4]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+a
[1],c
[2]+b
[2]))
1062 vs
[5]=obj
.matrix_world
@Vector((c
[0]+a
[0],c
[1]+b
[1],c
[2]+b
[2]))
1063 vs
[6]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+b
[1],c
[2]+b
[2]))
1064 vs
[7]=obj
.matrix_world
@Vector((c
[0]+b
[0],c
[1]+a
[1],c
[2]+b
[2]))
1066 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1067 (0,4),(1,5),(2,6),(3,7)]
1072 verts
+= [(v0
[0],v0
[1],v0
[2])]
1073 verts
+= [(v1
[0],v1
[1],v1
[2])]
1074 colours
+= [(0.5,0.5,0.5,0.5),(0.5,0.5,0.5,0.5)]
1076 center
=obj
.matrix_world
@c
1078 def _angle_lim( major
, minor
, amin
, amax
, colour
):
1079 nonlocal verts
, colours
1087 a0
= amin
*(1.0-t0
)+amax
*t0
1088 a1
= amin
*(1.0-t1
)+amax
*t1
1090 p0
= c
+ major
*f
*math
.cos(a0
) + minor
*f
*math
.sin(a0
)
1091 p1
= c
+ major
*f
*math
.cos(a1
) + minor
*f
*math
.sin(a1
)
1093 p0
=obj
.matrix_world
@ p0
1094 p1
=obj
.matrix_world
@ p1
1096 colours
+= [colour
,colour
]
1100 colours
+= [colour
,colour
]
1103 colours
+= [colour
,colour
]
1105 verts
+= [c
+major
*1.2*f
,c
+major
*f
*0.8]
1106 colours
+= [colour
,colour
]
1108 if bone
.cv_data
.con0
:
1109 _angle_lim( Vector((0,1,0)),Vector((0,0,1)), \
1110 bone
.cv_data
.mins
[0], bone
.cv_data
.maxs
[0], \
1112 _angle_lim( Vector((0,0,1)),Vector((1,0,0)), \
1113 bone
.cv_data
.mins
[1], bone
.cv_data
.maxs
[1], \
1115 _angle_lim( Vector((1,0,0)),Vector((0,1,0)), \
1116 bone
.cv_data
.mins
[2], bone
.cv_data
.maxs
[2], \
1120 if obj
.cv_data
.classtype
== 'k_classtype_gate':
1121 if obj
.type == 'MESH':
1122 dims
= obj
.data
.cv_data
.v0
1124 dims
= obj
.cv_data
.v0
1127 c
= Vector((0,0,dims
[2]))
1129 vs
[0] = obj
.matrix_world
@ Vector((-dims
[0],0.0,-dims
[1]+dims
[2]))
1130 vs
[1] = obj
.matrix_world
@ Vector((-dims
[0],0.0, dims
[1]+dims
[2]))
1131 vs
[2] = obj
.matrix_world
@ Vector(( dims
[0],0.0, dims
[1]+dims
[2]))
1132 vs
[3] = obj
.matrix_world
@ Vector(( dims
[0],0.0,-dims
[1]+dims
[2]))
1133 vs
[4] = obj
.matrix_world
@ (c
+Vector((-1,0,-2)))
1134 vs
[5] = obj
.matrix_world
@ (c
+Vector((-1,0, 2)))
1135 vs
[6] = obj
.matrix_world
@ (c
+Vector(( 1,0, 2)))
1136 vs
[7] = obj
.matrix_world
@ (c
+Vector((-1,0, 0)))
1137 vs
[8] = obj
.matrix_world
@ (c
+Vector(( 1,0, 0)))
1139 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(7,8)]
1144 verts
+= [(v0
[0],v0
[1],v0
[2])]
1145 verts
+= [(v1
[0],v1
[1],v1
[2])]
1146 colours
+= [(1,1,0,1),(1,1,0,1)]
1148 sw
= (0.4,0.4,0.4,0.2)
1149 if obj
.cv_data
.target
!= None:
1150 drawbline( obj
.location
, obj
.cv_data
.target
.location
, sw
,sw
)
1152 elif obj
.cv_data
.classtype
== 'k_classtype_route_node':
1153 sw
= Vector((0.4,0.4,0.4,0.2))
1154 sw2
= Vector((1.5,0.2,0.2,0.0))
1155 if obj
.cv_data
.target
!= None:
1156 drawbpath( obj
, obj
.cv_data
.target
, sw
, sw
)
1157 if obj
.cv_data
.target1
!= None:
1158 drawbpath( obj
, obj
.cv_data
.target1
, sw
, sw
)
1160 drawbhandle( obj
, 1.0, (0.8,0.8,0.8,1.0) )
1161 drawbhandle( obj
, -1.0, (0.4,0.4,0.4,1.0) )
1163 p1
= obj
.location
+ \
1164 obj
.matrix_world
.to_quaternion() @ Vector((0,0,-6+1.5))
1165 drawbline( obj
.location
, p1
, sw
,sw2
)
1168 elif obj
.cv_data
.classtype
== 'k_classtype_block':
1169 a
= obj
.data
.cv_data
.v0
1170 b
= obj
.data
.cv_data
.v1
1173 vs
[0] = obj
.matrix_world
@ Vector((a
[0], a
[1], a
[2]))
1174 vs
[1] = obj
.matrix_world
@ Vector((a
[0], b
[1], a
[2]))
1175 vs
[2] = obj
.matrix_world
@ Vector((b
[0], b
[1], a
[2]))
1176 vs
[3] = obj
.matrix_world
@ Vector((b
[0], a
[1], a
[2]))
1177 vs
[4] = obj
.matrix_world
@ Vector((a
[0], a
[1], b
[2]))
1178 vs
[5] = obj
.matrix_world
@ Vector((a
[0], b
[1], b
[2]))
1179 vs
[6] = obj
.matrix_world
@ Vector((b
[0], b
[1], b
[2]))
1180 vs
[7] = obj
.matrix_world
@ Vector((b
[0], a
[1], b
[2]))
1182 indices
= [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
1183 (0,4),(1,5),(2,6),(3,7)]
1188 verts
+= [(v0
[0],v0
[1],v0
[2])]
1189 verts
+= [(v1
[0],v1
[1],v1
[2])]
1190 colours
+= [(1,1,0,1),(1,1,0,1)]
1192 elif obj
.cv_data
.classtype
== 'k_classtype_capsule':
1193 h
= obj
.data
.cv_data
.v0
[0]
1194 r
= obj
.data
.cv_data
.v0
[1]
1197 vs
[0] = obj
.matrix_world
@ Vector((0.0,0.0, h
*0.5 ))
1198 vs
[1] = obj
.matrix_world
@ Vector((0.0,0.0,-h
*0.5 ))
1199 vs
[2] = obj
.matrix_world
@ Vector(( r
,0.0, h
*0.5-r
))
1200 vs
[3] = obj
.matrix_world
@ Vector(( -r
,0.0, h
*0.5-r
))
1201 vs
[4] = obj
.matrix_world
@ Vector(( r
,0.0,-h
*0.5+r
))
1202 vs
[5] = obj
.matrix_world
@ Vector(( -r
,0.0,-h
*0.5+r
))
1203 vs
[6] = obj
.matrix_world
@ Vector((0.0, r
, h
*0.5-r
))
1204 vs
[7] = obj
.matrix_world
@ Vector((0.0,-r
, h
*0.5-r
))
1205 vs
[8] = obj
.matrix_world
@ Vector((0.0, r
,-h
*0.5+r
))
1206 vs
[9] = obj
.matrix_world
@ Vector((0.0,-r
,-h
*0.5+r
))
1208 indices
= [(0,1),(2,3),(4,5),(6,7),(8,9)]
1213 verts
+= [(v0
[0],v0
[1],v0
[2])]
1214 verts
+= [(v1
[0],v1
[1],v1
[2])]
1215 colours
+= [(0.5,1,0,1),(0.5,1,0,1)]
1217 elif obj
.cv_data
.classtype
== 'k_classtype_spawn':
1219 vs
[0] = obj
.matrix_world
@ Vector((0,0,0))
1220 vs
[1] = obj
.matrix_world
@ Vector((0,2,0))
1221 vs
[2] = obj
.matrix_world
@ Vector((0.5,1,0))
1222 vs
[3] = obj
.matrix_world
@ Vector((-0.5,1,0))
1223 indices
= [(0,1),(1,2),(1,3)]
1227 verts
+= [(v0
[0],v0
[1],v0
[2])]
1228 verts
+= [(v1
[0],v1
[1],v1
[2])]
1229 colours
+= [(0,1,1,1),(0,1,1,1)]
1231 elif obj
.cv_data
.classtype
== 'k_classtype_route':
1233 vs
[0] = obj
.location
1234 vs
[1] = obj
.cv_data
.target
.location
1239 verts
+= [(v0
[0],v0
[1],v0
[2])]
1240 verts
+= [(v1
[0],v1
[1],v1
[2])]
1241 colours
+= [(0,1,1,1),(0,1,1,1)]
1245 stack
[0] = obj
.cv_data
.target
1247 loop_complete
= False
1250 if stack_i
[si
-1] == 2:
1254 if si
== 0: # Loop failed to complete
1259 targets
= [None,None]
1260 targets
[0] = node
.cv_data
.target
1262 if node
.cv_data
.classtype
== 'k_classtype_route_node':
1263 targets
[1] = node
.cv_data
.target1
1265 nextnode
= targets
[stack_i
[si
-1]]
1268 if nextnode
!= None: # branch
1269 if nextnode
== stack
[0]: # Loop completed
1270 loop_complete
= True
1274 for sj
in range(si
):
1275 if stack
[sj
] == nextnode
: # invalidated path
1281 stack
[si
] = nextnode
1286 cc
= Vector((obj
.cv_data
.colour
[0],\
1287 obj
.cv_data
.colour
[1],\
1288 obj
.cv_data
.colour
[2],\
1291 for sj
in range(si
):
1294 if stack
[sj
].cv_data
.classtype
== 'k_classtype_gate' and \
1295 stack
[sk
].cv_data
.classtype
== 'k_classtype_gate':
1296 dist
= (stack
[sj
].location
-stack
[sk
].location
).magnitude
1297 drawsbpath( stack
[sj
], stack
[sk
], cc
*0.4, cc
, dist
, dist
)
1300 drawbpath( stack
[sj
], stack
[sk
], cc
, cc
)
1304 elif obj
.cv_data
.classtype
== 'k_classtype_car_path':
1305 v0
= obj
.matrix_world
.to_quaternion() @ Vector((0,1,0))
1306 c0
= Vector((v0
.x
*0.5+0.5, v0
.y
*0.5+0.5, 0.0, 1.0))
1307 drawbhandle( obj
, 1.0, (0.9,0.9,0.9,1.0) )
1309 if obj
.cv_data
.target
!= None:
1310 v1
= obj
.cv_data
.target
.matrix_world
.to_quaternion()@Vector((0,1,0))
1311 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1313 drawbhandle( obj
.cv_data
.target
, -1.0, (0.5,0.5,0.5,1.0) )
1314 drawbpath( obj
, obj
.cv_data
.target
, c0
, c1
)
1316 if obj
.cv_data
.target1
!= None:
1317 v1
= obj
.cv_data
.target1
.matrix_world
.to_quaternion()@Vector((0,1,0))
1318 c1
= Vector((v1
.x
*0.5+0.5, v1
.y
*0.5+0.5, 0.0, 1.0))
1320 drawbhandle( obj
.cv_data
.target1
, -1.0, (0.5,0.5,0.5,1.0) )
1321 drawbpath( obj
, obj
.cv_data
.target1
, c0
, c1
)
1323 lines
= batch_for_shader(\
1324 cv_view_shader
, 'LINES', \
1325 { "pos":verts
, "color":colours
})
1327 lines
.draw( cv_view_shader
)
1329 def cv_poll_target(scene
, obj
):
1330 if obj
== bpy
.context
.active_object
:
1332 if obj
.cv_data
.classtype
== 'k_classtype_none':
1336 class CV_MESH_SETTINGS(bpy
.types
.PropertyGroup
):
1337 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1338 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1339 v2
: bpy
.props
.FloatVectorProperty(name
="v2",size
=3)
1340 v3
: bpy
.props
.FloatVectorProperty(name
="v3",size
=3)
1342 class CV_OBJ_SETTINGS(bpy
.types
.PropertyGroup
):
1343 uid
: bpy
.props
.IntProperty( name
="" )
1345 target
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target", \
1346 poll
=cv_poll_target
)
1347 target1
: bpy
.props
.PointerProperty( type=bpy
.types
.Object
, name
="target1", \
1348 poll
=cv_poll_target
)
1350 colour
: bpy
.props
.FloatVectorProperty(name
="colour",subtype
='COLOR',\
1353 classtype
: bpy
.props
.EnumProperty(
1356 ('k_classtype_none', "k_classtype_none", "", 0),
1357 ('k_classtype_gate', "k_classtype_gate", "", 1),
1358 ('k_classtype_block', "k_classtype_block", "", 2),
1359 ('k_classtype_spawn', "k_classtype_spawn", "", 3),
1360 ('k_classtype_water', "k_classtype_water", "", 4),
1361 ('k_classtype_car_path', "k_classtype_car_path", "", 5),
1362 ('k_classtype_INSTANCE', "","", 6 ),
1363 ('k_classtype_capsule', "k_classtype_capsule", "", 7 ),
1364 ('k_classtype_route_node', "k_classtype_route_node", "", 8 ),
1365 ('k_classtype_route', "k_classtype_route", "", 9 ),
1366 ('k_classtype_bone',"k_classtype_bone","",10),
1367 ('k_classtype_SKELETON', "","", 11 ),
1368 ('k_classtype_SKIN',"","",12)
1371 class CV_BONE_SETTINGS(bpy
.types
.PropertyGroup
):
1372 collider
: bpy
.props
.BoolProperty(name
="Collider",default
=False)
1373 v0
: bpy
.props
.FloatVectorProperty(name
="v0",size
=3)
1374 v1
: bpy
.props
.FloatVectorProperty(name
="v1",size
=3)
1376 con0
: bpy
.props
.BoolProperty(name
="Constriant 0",default
=False)
1377 mins
: bpy
.props
.FloatVectorProperty(name
="mins",size
=3)
1378 maxs
: bpy
.props
.FloatVectorProperty(name
="maxs",size
=3)
1380 class CV_BONE_PANEL(bpy
.types
.Panel
):
1381 bl_label
="Bone Config"
1382 bl_idname
="SCENE_PT_cv_bone"
1383 bl_space_type
='PROPERTIES'
1384 bl_region_type
='WINDOW'
1387 def draw(_
,context
):
1388 active_object
= context
.active_object
1389 if active_object
== None: return
1391 bone
= active_object
.data
.bones
.active
1392 if bone
== None: return
1394 _
.layout
.prop( bone
.cv_data
, "collider" )
1395 _
.layout
.prop( bone
.cv_data
, "v0" )
1396 _
.layout
.prop( bone
.cv_data
, "v1" )
1398 _
.layout
.label( text
="Angle Limits" )
1399 _
.layout
.prop( bone
.cv_data
, "con0" )
1400 _
.layout
.prop( bone
.cv_data
, "mins" )
1401 _
.layout
.prop( bone
.cv_data
, "maxs" )
1403 class CV_SCENE_SETTINGS(bpy
.types
.PropertyGroup
):
1404 use_hidden
: bpy
.props
.BoolProperty( name
="use hidden", default
=False )
1406 class CV_OBJ_PANEL(bpy
.types
.Panel
):
1407 bl_label
="Entity Config"
1408 bl_idname
="SCENE_PT_cv_entity"
1409 bl_space_type
='PROPERTIES'
1410 bl_region_type
='WINDOW'
1413 def draw(_
,context
):
1414 active_object
= bpy
.context
.active_object
1415 if active_object
== None: return
1416 _
.layout
.prop( active_object
.cv_data
, "classtype" )
1418 if active_object
.cv_data
.classtype
== 'k_classtype_gate':
1419 _
.layout
.prop( active_object
.cv_data
, "target" )
1421 mesh
= active_object
.data
1422 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1423 _
.layout
.prop( mesh
.cv_data
, "v0" )
1425 elif active_object
.cv_data
.classtype
== 'k_classtype_car_path' or \
1426 active_object
.cv_data
.classtype
== 'k_classtype_route_node':
1427 _
.layout
.prop( active_object
.cv_data
, "target" )
1428 _
.layout
.prop( active_object
.cv_data
, "target1" )
1430 elif active_object
.cv_data
.classtype
== 'k_classtype_route':
1431 _
.layout
.prop( active_object
.cv_data
, "target" )
1432 _
.layout
.prop( active_object
.cv_data
, "colour" )
1434 elif active_object
.cv_data
.classtype
== 'k_classtype_block':
1435 mesh
= active_object
.data
1437 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1438 _
.layout
.prop( mesh
.cv_data
, "v0" )
1439 _
.layout
.prop( mesh
.cv_data
, "v1" )
1440 _
.layout
.prop( mesh
.cv_data
, "v2" )
1441 _
.layout
.prop( mesh
.cv_data
, "v3" )
1442 elif active_object
.cv_data
.classtype
== 'k_classtype_capsule':
1443 mesh
= active_object
.data
1444 _
.layout
.label( text
=F
"(i) Data is stored in {mesh.name}" )
1445 _
.layout
.prop( mesh
.cv_data
, "v0" )
1447 class CV_INTERFACE(bpy
.types
.Panel
):
1448 bl_idname
= "VIEW3D_PT_carve"
1450 bl_space_type
= 'VIEW_3D'
1451 bl_region_type
= 'UI'
1452 bl_category
= "Carve"
1454 def draw(_
, context
):
1456 layout
.prop( context
.scene
.cv_data
, "use_hidden")
1457 layout
.operator( "carve.compile_all" )
1460 view_layer
= bpy
.context
.view_layer
1461 for col
in view_layer
.layer_collection
.children
["export"].children
:
1462 if not col
.hide_viewport
or bpy
.context
.scene
.cv_data
.use_hidden
:
1463 write_model( col
.name
)
1465 class CV_COMPILE(bpy
.types
.Operator
):
1466 bl_idname
="carve.compile_all"
1467 bl_label
="Compile All"
1469 def execute(_
,context
):
1471 #cProfile.runctx("test_compile()",globals(),locals(),sort=1)
1472 #for col in bpy.data.collections["export"].children:
1473 # write_model( col.name )
1477 classes
= [CV_OBJ_SETTINGS
,CV_OBJ_PANEL
,CV_COMPILE
,CV_INTERFACE
,\
1478 CV_MESH_SETTINGS
, CV_SCENE_SETTINGS
, CV_BONE_SETTINGS
,\
1482 global cv_view_draw_handler
1485 bpy
.utils
.register_class(c
)
1487 bpy
.types
.Object
.cv_data
= bpy
.props
.PointerProperty(type=CV_OBJ_SETTINGS
)
1488 bpy
.types
.Mesh
.cv_data
= bpy
.props
.PointerProperty(type=CV_MESH_SETTINGS
)
1489 bpy
.types
.Scene
.cv_data
= bpy
.props
.PointerProperty(type=CV_SCENE_SETTINGS
)
1490 bpy
.types
.Bone
.cv_data
= bpy
.props
.PointerProperty(type=CV_BONE_SETTINGS
)
1492 cv_view_draw_handler
= bpy
.types
.SpaceView3D
.draw_handler_add(\
1493 cv_draw
,(),'WINDOW','POST_VIEW')
1496 global cv_view_draw_handler
1499 bpy
.utils
.unregister_class(c
)
1501 bpy
.types
.SpaceView3D
.draw_handler_remove(cv_view_draw_handler
,'WINDOW')