function editor.defineEditor()

	game.editor = editor


	blankPixel 				= getImage("blankPixel")

	if type(config.autoSaveEnabled)~="nil" then 
		editor.autoSaveEnabled = config.autoSaveEnabled
	else 
		config.autoSaveEnabled = true
	end

	editor.debug  			= config.debug or {trace={}}
	
	editor.drawingResolution = config.drawingResolution or 0.2

	editor.transforming		= false
	editor.resized 			= 2
	editor.warnings 		= true
	editor.buttons 			= {} 
	editor.undos 			= {}
	editor.maxUndos 		= 100
	editor.zmode 			= false
	editor.updateLinks 		= true
	editor.roomPreviews 	= {}
	editor.setPreviews 		= {}
	 editor.roomLink 			= {}
	editor.roomPreview 		= {w=70,h=48}
	editor.roomContextMode = "Rooms"
	editor.toolModels  		= {}
	editor.transformTime = 0

	editor.autoSaveEnabled = config.autoSaveEnabled
	editor.autoSaveTime = config.autoSaveTime or 1
	

	editor.setPreview 		= nil
	editor.stackStart 		= nil
	editor.stackPreview 	= {w=100,h=80}

	editor.editingSet 		= (config.editingSet and level.sets[config.editingSet]) and config.editingSet or level.defaultSet
	editor.currentRooms 	= level.sets[editor.editingSet].views
	editor.currentRoom 		= level.rooms[config.currentRoom] and config.currentRoom or editor.currentRooms[1]
	roomsView 				= true
	roomZoom 				= roomsView and 1 or 0

	editor.animHovered 	 	= {key="",object=""}

	editor.stackEnd 		=  0
	editor.roomLink 		= nil
	editor.roomLinkPreview 	= {x=-100,y=75,w=100,h=80,notri=true,noshadow=true,preview=true}
	editor.drawingLink 		= false
	editor.cachedLink 		= nil
	editor.linkRes 			= 6

	editor.colorTip = {}
	
	editor.previewTri = {vec3(),vec3(),vec3()}
	
	renderLines  	 		= config.renderLines or 3
	lineRenderModes  		= 3
	editor.gridEnabled 	 		= config.gridEnabled
	editor.gridFade 		 		= editor.gridEnabled and 1 or 0
	editor.pasteboard 			= {}
	
	hoveredEntity 			= {}
	selectedEntities 		= {}
	selectedEntityIndex 	= 0
	selectedEntityDepth		= 0
	clickedEntityIndex 		= 0

	selectAlpha 			=  	0
	selectBounds 			= 	{}
	selectPoints 			= 	{}
	selectLine 				= 	{}
	editor.selectingRect  		= 	false
	stageHovered 			=  	true
	selectAll					= 	false
	numSelected 			= 	0
	

	sidebar =	{
		flatUI				= false,
		darkMode			= true,
		darkness  			= 30,
		darkShade 			= 30,
		lightShade			= 220,
		visible 			= false,
		ox					= 0,
		x 					= screenWidth+10000,
		y 					= -4,
		width 				=  360,
		height 				= screenHeight,
		maxWidth 			= 450,--ignore, these are set in updatePanels as *x.2	of splitwidth
		minWidth 			= 370,--ignore, these are set in updatePanels as *x		of splitwidth
		splitWidth 			= 300,
		resizeSpace 		= 6,
		titleH				= 20,
		titleHp				= 25,
		panelTitleHeight 	= 30,
		row 				= 20
	}
	
	sidebar 				= lume.merge(sidebar,config.sidebar or {})
	sidebar.owidth 			= sidebar.width
	sidebar.oldwidth 		= sidebar.width
	sidebar.oldheight 		= sidebar.height
	frostCalled 			= false

	dropScale 			= 1
	targetZoom 			= 0.5
	startPosition 		= {0,0}
	scaleBounds 		= {0.1, 8}


	mouseStored 	= 	{x=0, y=0}
	savedMouse 		= 	{x=0, y=0}
	mouseLocal 		= 	{x=0, y=0}
	mousePrev 		= 	{x=0, y=0}
	shapeEditMouse  = 	{x=0, y=0}
	mouseMoved 		= 	false

	thumbSize 		= 	64

	cursors = {
		scale_h		= 	lmouse.newCursor(getImageData("scale_hCursor"), 	8, 8 ),
		scale_d1	= 	lmouse.newCursor(getImageData("scale_d1Cursor"), 	8, 8 ),
		scale_d2	= 	lmouse.newCursor(getImageData("scale_d2Cursor"),	8, 8 ),
		scale_w		= 	lmouse.newCursor(getImageData("scale_wCursor"), 	8, 8 ),
		rotate		= 	lmouse.newCursor(getImageData("rotateCursor"), 		0, 0 ),

		hand		= 	lmouse.newCursor(getImageData("handCursor"), 16, 16 ),
		grab		= 	lmouse.newCursor(getImageData("grabCursor"), 12, 12 ),
		plus		= 	lmouse.newCursor(getImageData("plusCursor"), 6, 6 ),
		fill		= 	lmouse.newCursor(getImageData("fillCursor"), 6, 21 ),
		move		= 	lmouse.newCursor(getImageData("moveCursor"), 16, 16 )
	}

	worldTools 		=	{"Select","New"}
	currentTool 	=	"Select"
	editState 		= 	"Normal"
	mouseStill 		=  	0

	preTransform	= false

	levelClicked 	= false
	


	gfxStats 		= false
	sidebar.height 	= screenHeight


	local animConfig 			= Tserial.unpack( lfs.read( CONFIG_FILE ) ) 
	for k,v in pairs(animConfig) do 
		config[k] = v
		print(k)
	end
	
	editor.definePanels()
	editor.createGrid()

-- obj.load("models/cube.obj")
	-- editor.simpleMesh = gfx.newMesh(zformat, , "points")
	-- editor.simpleMesh:setTexture(getImage())
	galleryPanel.open = config.galleryOpen 


	multiTool 				= {
		dragging 		= false,
		rotating 		= false,
		scaling 		= false,
		sorting 		= false,
		transform 	= mat4(),
		translation = vec3(0),
		axis 				= vec3(0,1,0),
		angle 			= 0,
		start 			= {diff={x=0,y=0}},
	}

	multiTool.ringMesh,multiTool.ringTris = newRingMesh(44,46,2,0,pi)
	multiTool.items = {
			move 		= {name = "move",	x=0, y=0, r=10, d=0,  a=0,		func=function() multiTool.dragging 	= true end }
		--, depth  	= {name = "depth",	x=0, y=0, r=10, d=40, a=-2,		func=function() multiTool.sorting 	= true end }
		, scale 	= {name = "scale",	x=0, y=0, r=10, d=40, a=2,	func=function() multiTool.scaling 	= true end }
		, rotateZ 	= {name = "rotateZ",	x=0, y=0, r=10, d=64, a=-pi,	
			plane = vec3(0,0,-1),
			plane1 = vec3(1,0,0),
			plane2 = vec3(0,1,0),
			model = 	{
				color = {1,0.3,0.3},
				mesh=multiTool.ringMesh,
				tris=multiTool.ringTris,
				transform=mat4():rotate(mat4(),pi/2,vec3(0,0,1)),
				parent = multiTool
			},
			func=function() 
				multiTool.rotating 	= true 
			end }
		, rotateX 	= {name = "rotateX",	x=0, y=0, r=6, d=42, a=-pi,		
			plane = vec3(0,1,0),
			plane1 = vec3(1,0,0),
			plane2 = vec3(0,0,1),
			model = 	{
				color = {0.3,1,0.3},
				mesh=multiTool.ringMesh,
				tris=multiTool.ringTris,
				transform=mat4():rotate(mat4(),pi/2,vec3(1,0,0)),
				parent = multiTool
			},
			func=function() 
			multiTool.rotating 	= true 
		end }
		, rotateY 	= {name = "rotateY",	x=0, y=0, r=6, d=24, a=-pi,		
			plane = vec3(1,0,0),
			plane1 = vec3(0,0,1),
			plane2 = vec3(0,1,0),
			model = 	{
				color = {0.3,0.3,1},
				mesh=multiTool.ringMesh,
				tris=multiTool.ringTris,
				transform=mat4():rotate(mat4():rotate(mat4(),pi/2,vec3(0,1,0)),pi,vec3(1,0,0)),
				parent = multiTool
			},
			func=function() 
			multiTool.rotating 	= true 
		end }
	}

end



	----