Files
Diabolo/Demon_v0.19/maiden_interior.gd
T

126 lines
6.4 KiB
GDScript
Raw Normal View History

extends RefCounted
# Local construction follows the existing lining; each door's details share its hinge.
const PROFILE=[Vector3(.25,.73,.54),Vector3(.5,.75,.56),Vector3(1,.75,.56),Vector3(1.7,.75,.56),Vector3(2.15,.72,.54),Vector3(2.35,.55,.40),Vector3(2.43,.35,.25)]
const IRON=Color("34343a")
const BRASS=Color("8b6842")
const DARK=Color("14171c")
var g
var outer_metal
static var detail_cache={}
static var lining_cache={}
# Regions of the existing Meshy atlas: bare iron and aged brass, with matching PBR maps.
const IRON_REGION=Vector4(.41015625,.1875,.0234375,.0234375)
const BRASS_REGION=Vector4(.6796875,.5859375,.0234375,.0234375)
func metal(brass=false):
var material=outer_metal.duplicate()
material.set_meta("atlas_region",BRASS_REGION if brass else IRON_REGION)
material.albedo_color=Color.WHITE
return material
func line_lining(model):
for node in model.find_children("*Lining","MeshInstance3D",true,false):
node.cast_shadow=GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
node.set_meta("no_walk_collision",true)
if lining_cache.has(node.name):node.mesh=lining_cache[node.name];continue
var mesh=ArrayMesh.new();var transform=model.global_transform.affine_inverse()*node.global_transform
for surface in range(node.mesh.get_surface_count()):
var arrays=node.mesh.surface_get_arrays(surface);var uv=PackedVector2Array()
for vertex in arrays[Mesh.ARRAY_VERTEX]:
var p=transform*vertex
uv.append(Vector2(fposmod(atan2(-p.z,p.x),TAU)/TAU,p.y/2.4))
arrays[Mesh.ARRAY_TEX_UV]=uv
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,arrays)
mesh.surface_set_material(surface,metal())
node.mesh=mesh
lining_cache[node.name]=mesh
func tube(root,a,b,radius,color):
var mesh=CylinderMesh.new();mesh.top_radius=radius;mesh.bottom_radius=radius;mesh.height=a.distance_to(b)
mesh.radial_segments=8;mesh.rings=0
var node=g.mesh_node(root,mesh,(a+b)*.5,color)
node.quaternion=Quaternion(Vector3.UP,(b-a).normalized())
func rivet(root,p,size,color):
var mesh=SphereMesh.new();mesh.radius=.5;mesh.height=1;mesh.radial_segments=8;mesh.rings=4
var node=g.mesh_node(root,mesh,p,color);node.scale=size
func restore_detail(root,title):
if not detail_cache.has(title):return false
for record in detail_cache[title]:
var node=MeshInstance3D.new();node.mesh=record.mesh;node.transform=record.transform
node.set_meta("no_walk_collision",true)
node.cast_shadow=GeometryInstance3D.SHADOW_CASTING_SETTING_OFF;root.add_child(node)
return true
func remember_detail(root,title):
var meshes=[]
for node in root.get_children():
if node is MeshInstance3D:meshes.append({"mesh":node.mesh,"transform":node.transform})
detail_cache[title]=meshes
func point(height,angle,inset=.012):
var shape=PROFILE[0]
for j in range(PROFILE.size()-1):
if height<=PROFILE[j+1].x:
shape=PROFILE[j].lerp(PROFILE[j+1],inverse_lerp(PROFILE[j].x,PROFILE[j+1].x,height));break
return Vector3(cos(angle)*(shape.y*.86-inset),height,-sin(angle)*(shape.z*.70-inset))
func arc(root,height,a,b,radius,color,inset=.012):
for k in range(20):tube(root,point(height,lerpf(a,b,float(k)/20),inset),point(height,lerpf(a,b,float(k+1)/20),inset),radius,color)
func section(parent,origin,a,b,title):
var root=Node3D.new();parent.add_child(root);root.name=title;root.position=-origin
if restore_detail(root,title):return root
# Raised steel perimeter, inset brass seams and small round rivets.
for h in [.31,.76,1.28,1.80,2.16]:
arc(root,h,a+.035,b-.035,.013,IRON)
arc(root,h+.027,a+.06,b-.06,.006,BRASS,.018)
for k in range(7):rivet(root,point(h,lerpf(a+.08,b-.08,float(k)/6),.027),Vector3.ONE*.035,BRASS)
for k in range(1,5):
var angle=lerpf(a,b,float(k)/5)
for j in range(12):
var h=.32+j*.151
tube(root,point(h,angle,.025),point(h+.151,angle,.025),.010,IRON)
# Shallow embossed diamonds on each panel; decoration stays close to the lining.
for h in [1.02,1.55,2.00]:
var angle=(a+b)*.5;var spread=(b-a)*.13
var corners=[point(h+.11,angle,.035),point(h,angle+spread,.035),point(h-.11,angle,.035),point(h,angle-spread,.035)]
for k in range(4):tube(root,corners[k],corners[(k+1)%4],.008,BRASS)
rivet(root,point(h,angle,.039),Vector3.ONE*.043,BRASS)
for side in [-1,1]:
for k in range(24):
var u=float(k)/24;var v=float(k+1)/24
var t=u*TAU*1.25;var next=v*TAU*1.25
var radius=.115*(1-u)+.018;var next_radius=.115*(1-v)+.018
var p=point(h+sin(t)*radius,angle+side*(spread*.62+cos(t)*radius*spread/.13),.045)
var q=point(h+sin(next)*next_radius,angle+side*(spread*.62+cos(next)*next_radius*spread/.13),.045)
tube(root,p,q,.007,BRASS)
merge(root)
remember_detail(root,title)
return root
func merge(root):
# Batch fixed decorations by metal, separately for the body and each moving leaf.
var batches={}
for node in root.get_children():
if not node is MeshInstance3D:continue
var key=node.material_override.albedo_color.to_html()
if not batches.has(key):
var tool=SurfaceTool.new();tool.begin(Mesh.PRIMITIVE_TRIANGLES)
batches[key]={"tool":tool,"color":node.material_override.albedo_color}
batches[key].tool.append_from(node.mesh,0,node.transform)
node.free()
for key in batches:
var mesh=batches[key].tool.commit();var mat=metal(batches[key].color==BRASS)
mesh.surface_set_material(0,mat)
var node=MeshInstance3D.new();node.mesh=mesh;node.set_meta("no_walk_collision",true);node.cast_shadow=GeometryInstance3D.SHADOW_CASTING_SETTING_OFF;root.add_child(node)
func build(game,model,left,right):
g=game
outer_metal=model.find_child("Body",true,false).mesh.surface_get_material(0)
line_lining(model)
section(model,Vector3.ZERO,0,PI,"InnerBackDetail")
section(left,left.position,PI,PI*1.5,"InnerLeftDetail")
section(right,right.position,PI*1.5,TAU,"InnerRightDetail")
var floor_root=Node3D.new();model.add_child(floor_root);floor_root.name="InnerGrate"
if not restore_detail(floor_root,"InnerGrate"):
var plate=g.cylinder(floor_root,Vector3(0,.24,0),.61,.035,DARK);plate.scale.z=.61
for j in range(-7,8):
var x=j*.072;var reach=sqrt(maxf(0,1-pow(x/.58,2)))*.34
g.box(floor_root,Vector3(x,.268,0),Vector3(.026,.027,reach*2),IRON)
for z in [-.23,0,.23]:g.box(floor_root,Vector3(0,.259,z),Vector3(1.02,.018,.022),BRASS)
merge(floor_root);remember_detail(floor_root,"InnerGrate")
var bounce=OmniLight3D.new();model.add_child(bounce);bounce.name="InteriorBounce"
bounce.position=Vector3(0,1.35,.06);bounce.omni_range=1.65;bounce.light_color=Color("d7ae7d");bounce.light_energy=.32
model.set_meta("interior_detail",true)