+ print( F"Completed {name}.mdl" )
+
+# Clicky clicky GUI
+# ------------------------------------------------------------------------------
+
+cv_view_draw_handler = None
+cv_view_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
+
+def cv_draw():
+ global cv_view_shader
+ cv_view_shader.bind()
+ gpu.state.depth_mask_set(False)
+ gpu.state.line_width_set(2.0)
+ gpu.state.face_culling_set('BACK')
+ gpu.state.depth_test_set('NONE')
+ gpu.state.blend_set('ADDITIVE')
+
+ verts = []
+ colours = []
+
+ for obj in bpy.context.collection.objects:
+ if obj.cv_data.classtype == 'k_classtype_gate':
+ if obj.cv_data.target != None:
+ p0 = obj.location
+ p1 = obj.cv_data.target.location
+ verts += [(p0[0],p0[1],p0[2])]
+ verts += [(p1[0],p1[1],p1[2])]
+ colours += [(0,1,0,1.0),(1,0,0,1.0)]
+ elif obj.cv_data.classtype == 'k_classtype_block':
+ a = obj.data.cv_data.v0
+ b = obj.data.cv_data.v1
+
+ vs = [None]*8
+ vs[0] = obj.matrix_world @ Vector((a[0], a[1], a[2]))
+ vs[1] = obj.matrix_world @ Vector((a[0], b[1], a[2]))
+ vs[2] = obj.matrix_world @ Vector((b[0], b[1], a[2]))
+ vs[3] = obj.matrix_world @ Vector((b[0], a[1], a[2]))
+ vs[4] = obj.matrix_world @ Vector((a[0], a[1], b[2]))
+ vs[5] = obj.matrix_world @ Vector((a[0], b[1], b[2]))
+ vs[6] = obj.matrix_world @ Vector((b[0], b[1], b[2]))
+ vs[7] = obj.matrix_world @ Vector((b[0], a[1], b[2]))
+
+ indices = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\
+ (0,4),(1,5),(2,6),(3,7)]
+
+ for l in indices:
+ v0 = vs[l[0]]
+ v1 = vs[l[1]]
+ verts += [(v0[0],v0[1],v0[2])]
+ verts += [(v1[0],v1[1],v1[2])]
+ colours += [(1,1,0,1),(1,1,0,1)]
+
+ lines = batch_for_shader(\
+ cv_view_shader, 'LINES', \
+ { "pos":verts, "color":colours })
+
+ lines.draw( cv_view_shader )
+
+def cv_poll_target(scene, obj):
+ if obj == bpy.context.active_object:
+ return False
+ if obj.cv_data.classtype == 'k_classtype_none':
+ return False
+ return True
+
+class CV_MESH_SETTINGS(bpy.types.PropertyGroup):
+ v0: bpy.props.FloatVectorProperty(name="v0",size=3)
+ v1: bpy.props.FloatVectorProperty(name="v1",size=3)
+ v2: bpy.props.FloatVectorProperty(name="v2",size=3)
+ v3: bpy.props.FloatVectorProperty(name="v3",size=3)
+
+class CV_OBJ_SETTINGS(bpy.types.PropertyGroup):
+ uid: bpy.props.IntProperty( name="" )
+
+ target: bpy.props.PointerProperty( type=bpy.types.Object, name="target", \
+ poll=cv_poll_target )
+
+ classtype: bpy.props.EnumProperty(
+ name="Format",
+ items = [
+ ('k_classtype_none', "k_classtype_none", "", 0),
+ ('k_classtype_gate', "k_classtype_gate", "", 1),
+ ('k_classtype_block', "k_classtype_block", "", 2),
+ ('k_classtype_spawn', "k_classtype_spawn", "", 3),
+ ('k_classtype_water', "k_classtype_water", "", 4)
+ ])
+
+class CV_OBJ_PANEL(bpy.types.Panel):
+ bl_label="Entity Config"
+ bl_idname="SCENE_PT_cv_entity"
+ bl_space_type='PROPERTIES'
+ bl_region_type='WINDOW'
+ bl_context="object"
+
+ def draw(_,context):
+ active_object = bpy.context.active_object
+ if active_object == None: return
+ _.layout.prop( active_object.cv_data, "classtype" )
+
+ if active_object.cv_data.classtype == 'k_classtype_gate':
+ _.layout.prop( active_object.cv_data, "target" )
+ elif active_object.cv_data.classtype == 'k_classtype_block':
+ mesh = active_object.data
+
+ _.layout.label( text=F"(i) Data is stored in {mesh.name}" )
+ _.layout.prop( mesh.cv_data, "v0" )
+ _.layout.prop( mesh.cv_data, "v1" )
+ _.layout.prop( mesh.cv_data, "v2" )
+ _.layout.prop( mesh.cv_data, "v3" )
+
+class CV_INTERFACE(bpy.types.Panel):
+ bl_idname = "VIEW3D_PT_carve"
+ bl_label = "Carve"
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'UI'
+ bl_category = "Carve"
+
+ def draw(_, context):
+ layout = _.layout
+ layout.operator( "carve.compile_all" )
+
+class CV_COMPILE(bpy.types.Operator):
+ bl_idname="carve.compile_all"
+ bl_label="Compile All"
+
+ def execute(_,context):
+ for col in bpy.data.collections["export"].children:
+ write_model( col.name )
+
+ return {'FINISHED'}
+
+classes = [CV_OBJ_SETTINGS,CV_OBJ_PANEL,CV_COMPILE,CV_INTERFACE,\
+ CV_MESH_SETTINGS]
+
+def register():
+ global cv_view_draw_handler
+
+ for c in classes:
+ bpy.utils.register_class(c)
+
+ bpy.types.Object.cv_data = bpy.props.PointerProperty(type=CV_OBJ_SETTINGS)
+ bpy.types.Mesh.cv_data = bpy.props.PointerProperty(type=CV_MESH_SETTINGS)
+
+ cv_view_draw_handler = bpy.types.SpaceView3D.draw_handler_add(\
+ cv_draw,(),'WINDOW','POST_VIEW')
+
+def unregister():
+ global cv_view_draw_handler
+
+ for c in classes:
+ bpy.utils.unregister_class(c)
+
+ bpy.types.SpaceView3D.draw_handler_remove(cv_view_draw_handler,'WINDOW')