+ 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('NONE')
+
+ verts = []
+ colours = []
+
+ def drawbezier(p0,h0,p1,h1,c0,c1):
+ nonlocal verts, colours
+
+ verts += [p0]
+ verts += [h0]
+ colours += [(0.5,0.5,0.5,1.0),(0.5,0.5,0.5,1)]
+ verts += [p1]
+ verts += [h1]
+ colours += [(1.0,1.0,1,1),(1,1,1,1)]
+
+ last = p0
+ for i in range(10):
+ t = (i+1)/10
+ a0 = 1-t
+
+ tt = t*t
+ ttt = tt*t
+ p=ttt*p1+(3*tt-3*ttt)*h1+(3*ttt-6*tt+3*t)*h0+(3*tt-ttt-3*t+1)*p0
+ verts += [(last[0],last[1],last[2])]
+ verts += [(p[0],p[1],p[2])]
+ colours += [c0*a0+c1*(1-a0),c0*a0+c1*(1-a0)]
+ last = p
+
+ 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)]
+
+ elif obj.cv_data.classtype == 'k_classtype_spawn':
+ vs = [None]*4
+ vs[0] = obj.matrix_world @ Vector((0,0,0))
+ vs[1] = obj.matrix_world @ Vector((0,2,0))
+ vs[2] = obj.matrix_world @ Vector((0.5,1,0))
+ vs[3] = obj.matrix_world @ Vector((-0.5,1,0))
+ indices = [(0,1),(1,2),(1,3)]
+ 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 += [(0,1,1,1),(0,1,1,1)]
+
+ elif obj.cv_data.classtype == 'k_classtype_car_path':
+ p0 = obj.location
+ h0 = obj.matrix_world @ Vector((1,0,0))
+
+ v0 = obj.matrix_world.to_quaternion() @ Vector((1,0,0))
+ c0 = Vector((v0.x*0.5+0.5, v0.y*0.5+0.5, 0.0, 1.0))
+
+ if obj.cv_data.target != None:
+ p1 = obj.cv_data.target.location
+ h1 = obj.cv_data.target.matrix_world @ Vector((-1,0,0))
+
+ v1 = obj.cv_data.target.matrix_world.to_quaternion()@Vector((1,0,0))
+ c1 = Vector((v1.x*0.5+0.5, v1.y*0.5+0.5, 0.0, 1.0))
+
+ drawbezier( p0, h0, p1, h1, c0, c1 )
+
+ if obj.cv_data.target1 != None:
+ p1 = obj.cv_data.target1.location
+ h1 = obj.cv_data.target1.matrix_world @ Vector((-1,0,0))
+
+ v1 = obj.cv_data.target1.matrix_world.to_quaternion()@Vector((1,0,0))
+ c1 = Vector((v1.x*0.5+0.5, v1.y*0.5+0.5, 0.0, 1.0))
+
+ drawbezier( p0, h0, p1, h1, c0, c1 )
+
+ 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 )
+ target1: bpy.props.PointerProperty( type=bpy.types.Object, name="target1", \
+ 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),
+ ('k_classtype_car_path', "k_classtype_car_path", "", 5)
+ ])
+
+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_car_path':
+ _.layout.prop( active_object.cv_data, "target" )
+ _.layout.prop( active_object.cv_data, "target1" )
+ 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" )
+
+def test_compile():
+ for col in bpy.data.collections["export"].children:
+ write_model( col.name )
+
+class CV_COMPILE(bpy.types.Operator):
+ bl_idname="carve.compile_all"
+ bl_label="Compile All"
+
+ def execute(_,context):
+ test_compile()
+ #cProfile.runctx("test_compile()",globals(),locals(),sort=1)
+ #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')