Files
Diabolo/Demon_v0.19/apparatus_motion.gd
T

87 lines
4.2 KiB
GDScript
Raw Normal View History

extends RefCounted
var g
var d
var water: MeshInstance3D
var ropes=[]
var heat_materials=[]
var heat_light: OmniLight3D
var heat=0.0
var tension=0.0
var submerged=false
var splash_count=0
var drops=[]
var wheel_cuffs=[]
func setup(game,development):
g=game;d=development
if d.selected==1:
for x in [-0.42,0.42]:
for z in [-1.42,1.42]:
var node=MeshInstance3D.new();d.device.add_child(node)
var mesh=CylinderMesh.new();mesh.top_radius=0.018;mesh.bottom_radius=0.018;mesh.height=1;mesh.radial_segments=12
node.mesh=mesh;node.material_override=g.mat(Color("9b896c"));var cuff=preload("res://leather_cuff.gd").make(g,d.device,Vector3.ZERO,.08);cuff.rotation.x=PI/2
ropes.append({"node":node,"cuff":cuff,"x":x,"z":z})
for x in [-0.72,0.72]:
for z in [-1.28,1.28]:g.ball(d.device,Vector3(x,1.03,z),Vector3.ONE*0.09,Color("9d8c70"))
elif d.selected==2:
for n in d.crank.get_children():
if n is MeshInstance3D and n.mesh is TorusMesh and n.mesh.outer_radius<.2:n.hide()
for bone in ["wrist.L","wrist.R","foot.L","foot.R"]:
var cuff=preload("res://leather_cuff.gd").make(g,d.crank,Vector3.ZERO,.095);cuff.rotation.x=PI/2;wheel_cuffs.append({"node":cuff,"bone":bone})
# Open stave-built vat, solid water surface occludes the submerged body.
g.cylinder(d.device,Vector3(0,0.12,0.18),1.43,0.20,Color("32241e"))
for i in range(96):
var a=i*TAU/96
var n=g.box(d.device,Vector3(cos(a)*1.37,0.54,sin(a)*1.06+0.18),Vector3(0.092,0.86,0.14),Color("4b3425").lightened((i%3)*0.03));n.rotation.y=-a+PI/2
for y in [0.23,0.77,0.99]:
var band=g.torus(d.device,Vector3(0,y,0.18),1.39,Color("454249"));band.scale.z=0.77;band.material_override=g.mat(Color("454249"));band.material_override.metallic=0.8
water=preload("res://water_surface.gd").new().build(g,d.device,1.29,Vector3(0,.87,.18),false)
water.scale.z=.76
for i in range(14):
var drop=g.ball(d.device,Vector3.ZERO,Vector3(0.035,0.075,0.035),Color("9cbab9"));drop.hide();drops.append(drop)
elif d.selected==3:
var queue=[d.device]
while not queue.is_empty():
var n=queue.pop_back()
for c in n.get_children():queue.append(c)
if n is MeshInstance3D and n!=d.flame:
var mat=ShaderMaterial.new();mat.shader=preload("res://forged.gdshader")
if n.material_override is StandardMaterial3D:mat.set_shader_parameter("tint",n.material_override.albedo_color)
n.material_override=mat;heat_materials.append(mat)
heat_light=OmniLight3D.new();d.device.add_child(heat_light);heat_light.position=Vector3(0,1,0.8);heat_light.light_color=Color("ff5819");heat_light.omni_range=3;heat_light.light_energy=0
func reset():
tension=0;heat=0;submerged=false
func update(dt,active):
var i=g.index_of(g.working)
if d.selected==1 and i>=0:
tension=move_toward(tension,clampf(d.elapsed,0,1) if d.stage==0 else 1.0,dt*2)
var s=g.souls[i]
# Extend along the body's long axis while keeping the pelvis centered.
s.visual.scale=Vector3(1.0,1.04+tension*0.14,1.0)
s.visual.position.z=1.13+tension*0.13
for rope in ropes:
var a=Vector3(rope.x,1.16,rope.z)
var bone=("wrist." if rope.z<0 else "foot.")+("L" if rope.x>0 else "R")
var b=d.device.to_local(s.visual.bone_world(bone))
rope.cuff.position=b
rope.node.position=(a+b)/2;rope.node.scale.y=a.distance_to(b);rope.node.quaternion=Quaternion(Vector3.UP,(b-a).normalized())
elif d.selected==2 and i>=0:
for cuff in wheel_cuffs:cuff.node.position=d.crank.to_local(g.souls[i].visual.bone_world(cuff.bone))
var head=g.souls[i].visual.bone_world("head")
var under=head.y<g.STATION.y+0.87
if under!=submerged and active:splash_count+=1
submerged=under
water.material_override.set_shader_parameter("agitation",0.8 if active else 0.1)
water.material_override.set_shader_parameter("simulation_time",g.time)
for j in range(drops.size()):
var t=fposmod(g.time*2+j*0.071,1.0)
drops[j].visible=active and under
drops[j].position=Vector3(sin(j*2.4)*t*0.7,0.88+sin(t*PI)*0.42,0.18+cos(j*2.4)*t*0.4)
elif d.selected==3:
var target=clampf(d.elapsed/3.0,0,1) if i>=0 and d.stage>0 else 0.0
if d.release_clock>0:target=heat
heat=move_toward(heat,target,dt*(1.5 if target>heat else 0.3))
for mat in heat_materials:mat.set_shader_parameter("heat",heat)
heat_light.light_energy=heat*0.9