extends RefCounted # The editor always works in bottom-face coordinates; imported mesh origins stay intact. var lib func _init(library) -> void:lib=library func bottom_of(record: Dictionary) -> Vector3: return record.position+Vector3.UP*float(lib.catalog[record.kind].boundsBlender.min[2]) func record_at(kind: String,bottom: Vector3,quarter: int,id: String) -> Dictionary: var at:=bottom if kind!="goal_hole":at=Vector3(round(at.x),snappedf(at.y,.5),round(at.z)) var local_min: float=lib.catalog[kind].boundsBlender.min[2] return {"id":id,"kind":kind,"position":at-Vector3.UP*local_min,"quarter":quarter} func on_face(support: Dictionary,point: Vector3,normal: Vector3,kind: String,quarter: int) -> Vector3: var bounds: AABB=lib.record_bounds(support) var size: Vector2i=lib.footprint(kind,quarter) var height: float=lib.catalog[kind].boundsBlender.size[2] var result:=Vector3(round(point.x),bounds.position.y,round(point.z)) var axis:=normal.abs().max_axis_index() if axis==1: result.y=bounds.end.y if normal.y>=0 else bounds.position.y-height elif axis==0: result.x=bounds.end.x+.5 if normal.x>=0 else bounds.position.x+.5-size.x else: result.z=bounds.end.z+.5 if normal.z>=0 else bounds.position.z+.5-size.y if kind!="goal_hole": if axis==1:result.y=ceilf(result.y*2-.0001)/2 if normal.y>=0 else floorf(result.y*2+.0001)/2 elif axis==0:result.x=ceilf(result.x-.0001) if normal.x>=0 else floorf(result.x+.0001) else:result.z=ceilf(result.z-.0001) if normal.z>=0 else floorf(result.z+.0001) return result