158 lines
8.8 KiB
GDScript
158 lines
8.8 KiB
GDScript
|
|
extends RefCounted
|
||
|
|
var failures=0
|
||
|
|
var checks=0
|
||
|
|
var folder=""
|
||
|
|
func check(ok,label):
|
||
|
|
checks+=1
|
||
|
|
if not ok:failures+=1;push_error("EQUIPMENT QA: "+label)
|
||
|
|
func shot(g,name):
|
||
|
|
if DisplayServer.get_name()=="headless":return
|
||
|
|
await g.get_tree().process_frame
|
||
|
|
await g.get_tree().process_frame
|
||
|
|
await RenderingServer.frame_post_draw
|
||
|
|
g.get_viewport().get_texture().get_image().save_png(folder+"/"+name+".png")
|
||
|
|
func triangles(d):
|
||
|
|
var faces=PackedVector3Array()
|
||
|
|
for mesh in d.device.find_children("*","MeshInstance3D",true,false):
|
||
|
|
if mesh.get_parent().name=="LiveRestraints" or mesh.get_meta("no_walk_collision",false) or not mesh.is_visible_in_tree() or mesh.mesh is QuadMesh:continue
|
||
|
|
if mesh.mesh is ArrayMesh:
|
||
|
|
for v in mesh.mesh.get_faces():faces.append(d.device.to_local(mesh.to_global(v)))
|
||
|
|
return faces
|
||
|
|
func clear_ray(faces,a,b):
|
||
|
|
for j in range(0,faces.size(),3):
|
||
|
|
if Geometry3D.segment_intersects_triangle(a,b,faces[j],faces[j+1],faces[j+2])!=null:return false
|
||
|
|
return true
|
||
|
|
func skin_contacts(actor,d):
|
||
|
|
var feet=PackedVector3Array()
|
||
|
|
var thighs=PackedVector3Array()
|
||
|
|
for mesh in actor.model.find_children("*","MeshInstance3D",true,false):
|
||
|
|
if mesh.skin==null:continue
|
||
|
|
var matrices=[];var names=[]
|
||
|
|
for bind in range(mesh.skin.get_bind_count()):
|
||
|
|
var index=actor.skeleton.find_bone(mesh.skin.get_bind_name(bind))
|
||
|
|
if index<0:index=mesh.skin.get_bind_bone(bind)
|
||
|
|
matrices.append(actor.skeleton.get_bone_global_pose(index)*mesh.skin.get_bind_pose(bind))
|
||
|
|
names.append(actor.skeleton.get_bone_name(index))
|
||
|
|
for surface in range(mesh.mesh.get_surface_count()):
|
||
|
|
var arrays=mesh.mesh.surface_get_arrays(surface)
|
||
|
|
var vertices=arrays[Mesh.ARRAY_VERTEX];var bones=arrays[Mesh.ARRAY_BONES];var weights=arrays[Mesh.ARRAY_WEIGHTS]
|
||
|
|
for j in range(vertices.size()):
|
||
|
|
var max_weight=0.0;var dominant=0
|
||
|
|
for k in range(4):
|
||
|
|
if weights[j*4+k]>max_weight:max_weight=weights[j*4+k];dominant=bones[j*4+k]
|
||
|
|
var bone=names[dominant]
|
||
|
|
var is_foot=bone.begins_with("foot.") or bone.begins_with("toe")
|
||
|
|
var is_thigh=bone.begins_with("upperleg")
|
||
|
|
if not is_foot and not is_thigh:continue
|
||
|
|
var p=Vector3.ZERO
|
||
|
|
for k in range(4):
|
||
|
|
if weights[j*4+k]>0:p+=(matrices[bones[j*4+k]]*vertices[j])*weights[j*4+k]
|
||
|
|
p=d.device.to_local(actor.skeleton.to_global(p))
|
||
|
|
if is_foot:feet.append(p)
|
||
|
|
else:thighs.append(p)
|
||
|
|
return {"feet":feet,"thighs":thighs}
|
||
|
|
func run(g):
|
||
|
|
await g.get_tree().create_timer(.3).timeout
|
||
|
|
g.start_game();g.set_process(false);g.reset_shift();g.game_started=true;g.paused=false
|
||
|
|
g.hud.hide();g.menu.show_page("")
|
||
|
|
for imp in g.life.imps+g.life.neighbours:imp.root.hide()
|
||
|
|
folder="res://captures/equipment-meshy" if OS.has_feature("editor") else OS.get_executable_path().get_base_dir()+"/captures/equipment-meshy"
|
||
|
|
DirAccess.make_dir_recursive_absolute(folder)
|
||
|
|
var w=g.workshop
|
||
|
|
for kind in range(6):
|
||
|
|
if "--equipment-only=4" in OS.get_cmdline_user_args() and kind!=4:continue
|
||
|
|
var d=w.add_station(kind,Vector3(3,0,0))
|
||
|
|
d.motion.restraints.set_process(false)
|
||
|
|
var original_faces=triangles(d)
|
||
|
|
check(d.device.get_meta("apparatus_model","") in ["meshy_equipment_v01","iron_maiden_v01"],"prepared model %d"%kind)
|
||
|
|
if kind==2:
|
||
|
|
check(absf(d.crank.position.y-1.62)<.01,"wheel origin at axle")
|
||
|
|
check(d.motion.water!=null and d.motion.water.get_parent()!=d.crank,"water independent from wheel")
|
||
|
|
var water_before=d.motion.water.transform
|
||
|
|
d.crank.rotation.z=PI/2
|
||
|
|
check(d.motion.water.transform==water_before,"turning wheel leaves water stationary")
|
||
|
|
d.crank.rotation.z=0
|
||
|
|
if kind==5:
|
||
|
|
check(d.special.liquid.position.y<1.65 and d.special.liquid.position.y>.5,"liquid below rim above hollow floor")
|
||
|
|
for soul_kind in range(10):
|
||
|
|
var actor=g.make_person(false,soul_kind);g.add_child(actor);g.make_ghost(actor,soul_kind);g.set_soul_reveal(actor,1);actor.mount_station(kind)
|
||
|
|
actor.position=d.device.position;actor.rotation=Vector3.ZERO
|
||
|
|
if kind==1:actor.rotation.x=-PI/2;actor.position+=Vector3(0,1.04,1.13)
|
||
|
|
elif kind==2:actor.position+=Vector3(0,.47,.27)
|
||
|
|
elif kind==3:actor.position+=Vector3(0,.22,0)
|
||
|
|
elif kind==5:actor.position+=Vector3(0,.45,0);actor.scale=Vector3.ONE*.85
|
||
|
|
actor.update_torture(.01,false)
|
||
|
|
d.motion.restraints.update(actor)
|
||
|
|
check(d.motion.restraints.bindings.size()==4,"four live restraints %d/%d"%[kind,soul_kind])
|
||
|
|
for binding in d.motion.restraints.bindings:
|
||
|
|
var body_point=d.motion.restraints.to_local(actor.bone_world(binding.bone))
|
||
|
|
check(binding.cuff.position.distance_to(body_point)<.06,"cuff follows bone %d/%d/%s"%[kind,soul_kind,binding.bone])
|
||
|
|
check(binding.end.distance_to(d.motion.restraints.to_local(binding.anchor.global_position))<.001,"chain ends at apparatus")
|
||
|
|
check(binding.chain.multimesh.visible_instance_count>=2,"chain links visible")
|
||
|
|
var head=d.device.to_local(actor.bone_world("head"))
|
||
|
|
if kind in [0,4,5]:
|
||
|
|
var contacts=skin_contacts(actor,d)
|
||
|
|
var sole=INF
|
||
|
|
for p in contacts.feet:sole=minf(sole,p.y)
|
||
|
|
var floor_y=.10 if kind==0 else (.33 if kind==4 else .40)
|
||
|
|
check(sole>=floor_y-.01,"actual foot vertices clear base %d/%d min=%f"%[kind,soul_kind,sole])
|
||
|
|
if kind==4:
|
||
|
|
if soul_kind==0:print("SEAT_GEOMETRY hip=",actor.bone_local("upperleg01.L")," knee=",actor.bone_local("lowerleg01.L")," ankle=",actor.bone_local("foot.L"))
|
||
|
|
var penetration=0
|
||
|
|
for p in contacts.thighs:
|
||
|
|
if absf(p.x)<.46 and p.z>-.43 and p.z<.125 and p.y<.69:penetration+=1
|
||
|
|
check(penetration==0,"actual thigh vertices clear cushion %d count=%d"%[soul_kind,penetration])
|
||
|
|
if kind==0:
|
||
|
|
for bone in ["head","wrist.L","wrist.R"]:
|
||
|
|
var at=d.device.to_local(actor.bone_world(bone))
|
||
|
|
for offset in [-.035,0,.035]:
|
||
|
|
check(clear_ray(original_faces,Vector3(at.x+offset,at.y,-.3),Vector3(at.x+offset,at.y,.3)),"open aperture clears %d/%s"%[soul_kind,bone])
|
||
|
|
elif kind==1:
|
||
|
|
for bone in ["root","spine01","spine02","head"]:
|
||
|
|
var at=d.device.to_local(actor.bone_world(bone))
|
||
|
|
check(at.y>.94 and absf(at.z)<1.65,"lying torso above bed %d/%s %s"%[soul_kind,bone,str(at)])
|
||
|
|
elif kind==2:
|
||
|
|
check(Vector2(head.x,head.y-1.62).length()<1.28,"head within wheel radius")
|
||
|
|
for angle in [0.0,PI/2,PI,PI*1.5]:
|
||
|
|
d.crank.rotation.z=angle
|
||
|
|
actor.rotation.z=angle;actor.position=d.device.position+Vector3(sin(angle)*1.15,1.62-cos(angle)*1.15,.27)
|
||
|
|
actor.update_torture(.01,false);d.motion.restraints.update(actor)
|
||
|
|
var torso=d.device.to_local(actor.bone_world("spine02"))
|
||
|
|
check(Vector2(torso.x,torso.y-1.62).length()<1.28 and torso.z>.18,"body follows front of wheel through full turn")
|
||
|
|
if soul_kind==7 and angle in [PI/2,PI]:await shot(g,"wheel-angle-%d"%roundi(rad_to_deg(angle)))
|
||
|
|
d.crank.rotation.z=0;actor.rotation.z=0;actor.position=d.device.position+Vector3(0,.47,.27);actor.update_torture(0,false)
|
||
|
|
elif kind==4:
|
||
|
|
for bone in ["root","upperleg01.L","upperleg01.R"]:
|
||
|
|
var at=d.device.to_local(actor.bone_world(bone))
|
||
|
|
check(at.y>.76 and absf(at.x)<.48,"hips clear seat and fit width")
|
||
|
|
for speaker in d.special.speaker_roots:
|
||
|
|
var target=d.device.to_local(actor.bone_world("head"))-speaker.position
|
||
|
|
check(speaker.basis.z.dot(target.normalized())>.92,"speaker points toward actual head")
|
||
|
|
elif kind==5:
|
||
|
|
for bone in ["root","spine01","upperleg01.L","upperleg01.R","foot.L","foot.R"]:
|
||
|
|
var at=d.device.to_local(actor.bone_world(bone))
|
||
|
|
check(Vector2(at.x,at.z).length()<1.15 and at.y>.40,"submerged body fits cavity %d/%s %s"%[soul_kind,bone,str(at)])
|
||
|
|
if soul_kind in [0,7]:
|
||
|
|
d.motion.restraints.update(actor)
|
||
|
|
g.camera.position=d.device.position+Vector3(4.0,2.8,4.8);g.camera.look_at(d.device.position+Vector3(0,1.25,0));g.camera.size=4.7
|
||
|
|
await shot(g,"%d-soul-%d"%( [kind,soul_kind] ))
|
||
|
|
# All four quarter-turns keep body, anchors and cuffs in the same frame.
|
||
|
|
d.motion.restraints.update(actor)
|
||
|
|
var before=[]
|
||
|
|
for binding in d.motion.restraints.bindings:before.append(binding.cuff.global_position-d.device.position)
|
||
|
|
var initial=actor.transform
|
||
|
|
for turn in range(4):
|
||
|
|
d.device.rotation.y=turn*PI/2
|
||
|
|
actor.transform=Transform3D(Basis(Vector3.UP,turn*PI/2),d.device.position)*Transform3D(initial.basis,initial.origin-d.device.position)
|
||
|
|
d.motion.restraints.update(actor)
|
||
|
|
for j in range(4):check(d.motion.restraints.bindings[j].cuff.global_position.distance_to(d.device.position+before[j].rotated(Vector3.UP,turn*PI/2))<.002,"rotation preserves attachment sides")
|
||
|
|
d.device.rotation.y=0;actor.transform=initial
|
||
|
|
actor.queue_free()
|
||
|
|
await g.get_tree().process_frame
|
||
|
|
d.motion.restraints.update(null)
|
||
|
|
check(not d.motion.restraints.visible,"empty apparatus hides live cuffs and chains")
|
||
|
|
w.dispose_station(d);w.stations.erase(d);w.bars.clear()
|
||
|
|
await g.get_tree().process_frame
|
||
|
|
if failures==0:print("ALL EQUIPMENT TESTS PASSED (%d): 6 apparatus, 10 souls, apertures, cavities, seat, inward speakers, moving wheel, four rotations, four anchored restraints"%checks)
|
||
|
|
g.get_tree().quit(1 if failures else 0)
|