Files
Diabolo/Demon_v0.19/pillory.gd
T

35 lines
2.1 KiB
GDScript

extends RefCounted
# Three open apertures, each meshed from a circle to the edge of its wooden cell.
func board(g,parent,cx,half_width,radius):
var st=SurfaceTool.new();st.begin(Mesh.PRIMITIVE_TRIANGLES)
for i in range(64):
var points=[]
for angle in [TAU*i/64,TAU*(i+1)/64]:
var v=Vector2(cos(angle),sin(angle));var distance=minf(half_width/maxf(absf(v.x),.0001),.23/maxf(absf(v.y),.0001))
points.append(v*radius);points.append(v*distance)
for z in [-.105,.105]:
for index in [0,1,3,0,3,2]:
var v=points[index];st.set_uv(v*3);st.add_vertex(Vector3(v.x+cx,1.70+v.y,z))
for index in [0,2]:
var a=points[0] if index==0 else points[1];var b=points[2] if index==0 else points[3]
for v in [Vector3(a.x+cx,1.7+a.y,-.105),Vector3(b.x+cx,1.7+b.y,-.105),Vector3(b.x+cx,1.7+b.y,.105),Vector3(a.x+cx,1.7+a.y,-.105),Vector3(b.x+cx,1.7+b.y,.105),Vector3(a.x+cx,1.7+a.y,.105)]:st.set_uv(Vector2(v.x,v.y));st.add_vertex(v)
st.generate_normals();var node=g.mesh_node(parent,st.commit(),Vector3.ZERO,Color.WHITE)
var mat=ShaderMaterial.new();mat.shader=preload("res://pillory_wood.gdshader");mat.set_shader_parameter("tint",Color("695039"));node.material_override=mat
# The board has interior faces as well as the two visible surfaces.
func build(g,d):
var root=d.device;root.set_meta("pillory_apertures",3)
var wood=Color("5e4430");var iron=Color("36383b")
for side in [-1,1]:
g.box(root,Vector3(side*.85,1.12,0),Vector3(.19,2.24,.24),wood)
g.box(root,Vector3(side*.85,.12,0),Vector3(.30,.24,1.65),wood)
for z in [-.65,.65]:g.line(root,Vector3(side*.85,.18,z),Vector3(side*.85,.85,0),.065,wood)
for y in [1.48,1.94]:
g.box(root,Vector3(side*.85,y,.14),Vector3(.23,.065,.06),iron)
g.ball(root,Vector3(side*.85,y,.18),Vector3.ONE*.065,Color("a49b80"))
board(g,root,0,.28,.158)
board(g,root,-.59,.31,.085);board(g,root,.59,.31,.085)
for x in [-.72,.72]:
g.box(root,Vector3(x,1.70,.125),Vector3(.055,.44,.04),iron)
for y in [1.54,1.86]:g.ball(root,Vector3(x,y,.15),Vector3.ONE*.045,Color("a49b80"))
var hinge=g.cylinder(root,Vector3(-.93,1.70,0),.045,.5,iron);hinge.rotation.x=PI/2