feat: 建立关卡工坊并整理项目目录
- 加入 Godot 基础试玩、画风展示和通孔验证场景 - 支持自由放球、多层叠放、墙壁、锥口球洞及固定 +5 m/s 定向加速方块 - 保存 Blender 源资产、模型导出、资源制作脚本和关卡编辑存档逻辑 - 按七类目录归档工程,集中 zsh 启动入口并补充 AGENTS.md 文件索引 - 同步设计规则、依赖锁定、验证报告和目录迁移记录 验证:目录迁移后的资源导入与四个场景加载通过;本次提交前检查暂存内容,未重复运行整套物理测试。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"ballTypes": [
|
||||
{
|
||||
"ballTypeId": "iron_ball",
|
||||
"assetId": "iron_ball",
|
||||
"physicsProfileId": "solid_iron_test"
|
||||
}
|
||||
],
|
||||
"physicsProfiles": {
|
||||
"solid_iron_test": {
|
||||
"massKg": 890.0760306150601,
|
||||
"inertiaModel": "solidSphere",
|
||||
"dragCoefficient": 0.47,
|
||||
"contactMaterialId": "iron"
|
||||
}
|
||||
},
|
||||
"contactMaterialPairs": [
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "painted_wood",
|
||||
"staticFriction": 0.42,
|
||||
"dynamicFriction": 0.32,
|
||||
"rollingResistance": 0.025,
|
||||
"restitution": 0.08
|
||||
},
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "iron",
|
||||
"staticFriction": 0.35,
|
||||
"dynamicFriction": 0.25,
|
||||
"rollingResistance": 0.01,
|
||||
"restitution": 0.15
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"Experimental contact coefficients; iron material is unchanged.",
|
||||
"Solid iron sphere radius 0.3 m at nominal density 7870 kg/m³: mass about 890.08 kg."
|
||||
],
|
||||
"airDensity": 1.225
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
"""Run inside Blender: parameterized wooden chutes + an iron sphere.
|
||||
Authoring axes: Z up. GLB export: (x, y, z) -> Godot (x, z, -y).
|
||||
Dimensions and colliders originate here, never in the gameplay physics table.
|
||||
"""
|
||||
import bpy
|
||||
import bmesh
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
from mathutils import Vector
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[4]
|
||||
OUT = ROOT / 'assets/collections/baseline'
|
||||
SOURCE = Path(__file__).resolve().parent
|
||||
BALL_R = 0.3
|
||||
FIT_CLEARANCE = 0.02
|
||||
R = BALL_R + FIT_CLEARANCE
|
||||
HOLE_R = BALL_R + FIT_CLEARANCE
|
||||
GOAL_R = BALL_R + FIT_CLEARANCE
|
||||
GOAL_DEPTH = 0.55
|
||||
SIDES = 64
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
SOURCE.mkdir(parents=True, exist_ok=True)
|
||||
(ROOT/'playtest/artifacts/baseline').mkdir(parents=True, exist_ok=True)
|
||||
bpy.ops.object.select_all(action='SELECT')
|
||||
bpy.ops.object.delete(use_global=False)
|
||||
bpy.context.scene.unit_settings.system = 'METRIC'
|
||||
bpy.context.scene.unit_settings.scale_length = 1.0
|
||||
|
||||
|
||||
def material(name, color, roughness, metallic=0):
|
||||
m = bpy.data.materials.new(name)
|
||||
m.diffuse_color = (*color, 1)
|
||||
m.use_nodes = True
|
||||
node = m.node_tree.nodes.get('Principled BSDF')
|
||||
node.inputs['Base Color'].default_value = (*color, 1)
|
||||
node.inputs['Roughness'].default_value = roughness
|
||||
node.inputs['Metallic'].default_value = metallic
|
||||
return m
|
||||
|
||||
wood = material('Painted wood - warm ochre', (0.48, 0.29, 0.12), .48)
|
||||
channel = material('Painted wood - satin groove', (0.78, 0.59, 0.33), .40)
|
||||
iron = material('Iron - brushed', (.24, .29, .33), .24, .96)
|
||||
mark = material('Iron ball - orientation stripe', (.04, .075, .10), .46, .60)
|
||||
goal_material = material('Goal rim - green', (.063, .26, .17), .4, .25)
|
||||
|
||||
|
||||
def mesh_obj(name, verts, faces):
|
||||
mesh = bpy.data.meshes.new(name)
|
||||
mesh.from_pydata(verts, [], faces)
|
||||
mesh.validate()
|
||||
mesh.update()
|
||||
obj = bpy.data.objects.new(name, mesh)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
bm = bmesh.new()
|
||||
bm.from_mesh(mesh)
|
||||
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
||||
bm.to_mesh(mesh)
|
||||
bm.free()
|
||||
return obj
|
||||
|
||||
|
||||
def top_height(x, rise):
|
||||
return 1 if rise == 0 else .5 + rise * (x + .5)
|
||||
|
||||
|
||||
def block(name, rise):
|
||||
half = 1.0 if name == 'y_merge' else .5
|
||||
verts = [(x, y, z) for z in [0, 1] for y in [-half, half] for x in [-half, half]]
|
||||
verts = [(x, y, top_height(x, rise) if z else 0) for x, y, z in verts]
|
||||
faces = [(0,2,3,1),(4,5,7,6),(0,1,5,4),(2,6,7,3),(0,4,6,2),(1,3,7,5)]
|
||||
obj = mesh_obj(name, verts, faces)
|
||||
obj.data.materials.append(wood)
|
||||
obj.data.materials.append(channel)
|
||||
return obj
|
||||
|
||||
|
||||
def tube(name, points, radius, mat):
|
||||
# Vertical semicircle section maintained along authoring path.
|
||||
vertices = []
|
||||
for i, point in enumerate(points):
|
||||
tangent = Vector(points[min(i+1,len(points)-1)]) - Vector(points[max(0,i-1)])
|
||||
side = Vector((-tangent.y, tangent.x, 0)).normalized()
|
||||
for j in range(SIDES):
|
||||
a = j * math.tau / SIDES
|
||||
v = Vector(point) + radius * math.cos(a) * side + Vector((0,0,radius*math.sin(a)))
|
||||
vertices.append(tuple(v))
|
||||
faces = []
|
||||
for i in range(len(points)-1):
|
||||
for j in range(SIDES):
|
||||
k=i*SIDES+j; n=i*SIDES+(j+1)%SIDES
|
||||
faces.append((k,n,n+SIDES,k+SIDES))
|
||||
faces += [tuple(reversed(range(SIDES))),tuple((len(points)-1)*SIDES+j for j in range(SIDES))]
|
||||
obj=mesh_obj(name,vertices,faces)
|
||||
obj.data.materials.append(wood)
|
||||
obj.data.materials.append(mat)
|
||||
for face in obj.data.polygons:
|
||||
face.material_index=1
|
||||
return obj
|
||||
|
||||
|
||||
def cut(body, cutter):
|
||||
bpy.context.view_layer.objects.active=body
|
||||
mod=body.modifiers.new('Actual channel void','BOOLEAN')
|
||||
mod.operation='DIFFERENCE'
|
||||
mod.solver='EXACT'
|
||||
mod.object=cutter
|
||||
bpy.ops.object.modifier_apply(modifier=mod.name)
|
||||
bpy.data.objects.remove(cutter,do_unlink=True)
|
||||
|
||||
|
||||
def extend(points, amount=.18):
|
||||
p=[Vector(v) for v in points]
|
||||
first=(p[1]-p[0]); first/=math.hypot(first.x,first.y)
|
||||
last=(p[-1]-p[-2]); last/=math.hypot(last.x,last.y)
|
||||
return [tuple(p[0]-first*amount)]+points+[tuple(p[-1]+last*amount)]
|
||||
|
||||
|
||||
def paths(kind,rise):
|
||||
if kind in ('straight','gentle','steep'):
|
||||
return [[(x,0,top_height(x,rise)) for x in [-.5+i/24 for i in range(25)]]]
|
||||
if kind in ('turn_cw','turn_ccw'):
|
||||
sign=-1 if kind=='turn_cw' else 1
|
||||
return [[(-.5+.5*math.sin(t),sign*(.5-.5*math.cos(t)),1) for t in [i*math.pi/2/48 for i in range(49)]]]
|
||||
# 2x2 Y connector: adjacent 1m lanes on the -X face, both at the same height.
|
||||
# Lane A continues straight; lane B merges through a tangent-continuous S.
|
||||
direct=[(-1+i/64*2,-.5,1) for i in range(65)]
|
||||
# Spread the lateral shift over the whole 2m length so the merging ball
|
||||
# retains forward momentum instead of striking the far wall sideways.
|
||||
branch=[]
|
||||
for i in range(129):
|
||||
t=i/128
|
||||
blend=3*t*t-2*t*t*t
|
||||
branch.append((-1+2*t,.5-blend,1))
|
||||
return [direct,branch]
|
||||
|
||||
|
||||
|
||||
def asset_dir(kind):
|
||||
category = 'balls' if kind == 'iron_ball' else 'goals' if kind == 'goal_hole' else 'blocks' if kind in ('wall','directional_boost') else 'chutes'
|
||||
return ROOT / 'assets' / category / kind
|
||||
|
||||
def export_objects(objects, name):
|
||||
export_path = asset_dir(name) / 'baseline/model.glb'
|
||||
export_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
for obj in objects: obj.select_set(True)
|
||||
bpy.context.view_layer.objects.active=objects[0]
|
||||
bpy.ops.export_scene.gltf(filepath=str(export_path),export_format='GLB',use_selection=True,export_yup=True,export_extras=True,export_apply=True)
|
||||
|
||||
|
||||
def godot(v): return [round(v[0],6),round(v[2],6),round(-v[1],6)]
|
||||
|
||||
catalog={'schemaVersion':1,'unitsPerMeter':1,'authoringUp':'Z','runtimeUp':'Y','models':{}}
|
||||
report={'generator':'Blender Python','ball_radius_m':BALL_R,'groove_radius_m':R,'hole_radius_m':HOLE_R,'assets':[],
|
||||
'fit_clearance_m':FIT_CLEARANCE,'goal_radius_m':GOAL_R,
|
||||
'important':['Flat blocks now contain closed circular passages; ramp passages can open through the bottom and use the test platform as support.',
|
||||
'The steep ramp preserves 1m rise; its retained 1.5m prototype envelope remains explicitly flagged.']}
|
||||
showcase=[]
|
||||
for kind,rise in [('straight',0),('turn_cw',0),('turn_ccw',0),('gentle',.5),('steep',1),('y_merge',0)]:
|
||||
body=block(kind,rise)
|
||||
upper_paths=paths(kind,rise)
|
||||
for n,path in enumerate(upper_paths):
|
||||
cut(body,tube(f'{kind}_upper_{n}',extend(path),R,channel))
|
||||
floor_center=top_height(0,rise)-R
|
||||
hole_z=floor_center-HOLE_R*math.sqrt(1+rise*rise)-.02
|
||||
# Diagonal mirror swaps X/Y, while keeping lower passages level.
|
||||
lower_paths=[[(y,x,hole_z) for x,y,z in path] for path in upper_paths]
|
||||
for n,path in enumerate(lower_paths):
|
||||
cut(body,tube(f'{kind}_lower_{n}',extend(path),HOLE_R,wood))
|
||||
for face in body.data.polygons:
|
||||
face.use_smooth=(face.material_index==1)
|
||||
body['asset_id']=kind
|
||||
body['groove_radius_m']=R
|
||||
declared_size=[2.0,2.0,1.0] if kind=='y_merge' else [1.0,1.0,1.0]
|
||||
body['declared_size_m']=declared_size
|
||||
body['rise_m']=rise
|
||||
bpy.context.view_layer.update()
|
||||
coords=[body.matrix_world @ v.co for v in body.data.vertices]
|
||||
low=[min(v[i] for v in coords) for i in range(3)]
|
||||
high=[max(v[i] for v in coords) for i in range(3)]
|
||||
bounds=[round(high[i]-low[i],6) for i in range(3)]
|
||||
# Sample the actual final boolean mesh for open channels and clearance.
|
||||
from mathutils.bvhtree import BVHTree
|
||||
tree=BVHTree.FromObject(body,bpy.context.evaluated_depsgraph_get())
|
||||
minimum_clearance=10.0
|
||||
for path in lower_paths:
|
||||
for point in path[::4]:
|
||||
loc,normal,index,distance=tree.find_nearest(Vector(point))
|
||||
if loc is not None: minimum_clearance=min(minimum_clearance,distance)
|
||||
manifold=bmesh.new();manifold.from_mesh(body.data)
|
||||
bad_edges=sum(not e.is_manifold for e in manifold.edges);manifold.free()
|
||||
upper_ports=[]
|
||||
for path in upper_paths:
|
||||
for idx in [0,-1]:
|
||||
v=Vector(path[idx]);v.z-=R
|
||||
tangent=Vector(path[1])-Vector(path[0]) if idx==0 else Vector(path[-1])-Vector(path[-2])
|
||||
tangent.normalize()
|
||||
if kind=='y_merge':
|
||||
tangent=Vector((1,0,0)) # parallel interfaces on the opposite X faces
|
||||
entry={'surface':godot(v),'travel':godot(tangent)}
|
||||
if not any(p['surface']==entry['surface'] for p in upper_ports):upper_ports.append(entry)
|
||||
meta={'path':'res://'+str((asset_dir(kind)/'baseline/model.glb').relative_to(ROOT)),'radius':None,'rise':rise,'grooveRadius':R,'passageRadius':HOLE_R,
|
||||
'upperPaths':[[godot(p) for p in path] for path in upper_paths],
|
||||
'lowerPaths':[[godot(p) for p in path] for path in lower_paths],
|
||||
'ports':upper_ports,'bottomArchCenter':hole_z,'bottomRouteFloor':hole_z-HOLE_R,
|
||||
'boundsBlender':{'min':low,'max':high,'size':bounds},'nominalCellFits':all(d<=1.001 for d in bounds),
|
||||
'cellFootprint':[int(declared_size[0]),int(declared_size[1])],
|
||||
'declaredSize':declared_size,'declaredBoundsFits':all(bounds[i]<=declared_size[i]+.001 for i in range(3)),
|
||||
'prototypeNotes':[] if rise!=1 else ['Full semicircle plus 1m rise exceeds the nominal 1m cell height.']}
|
||||
body['single_cell_compliant']=meta['nominalCellFits']
|
||||
body['declared_size_compliant']=meta['declaredBoundsFits']
|
||||
export_objects([body],kind)
|
||||
catalog['models'][kind]=meta
|
||||
report['assets'].append({'id':kind,'size_m':bounds,'single_cell_compliant':meta['nominalCellFits'],
|
||||
'declared_size_m':declared_size,'declared_size_compliant':meta['declaredBoundsFits'],
|
||||
'mesh_vertices':len(body.data.vertices),'mesh_faces':len(body.data.polygons),'non_manifold_edges':bad_edges,
|
||||
'lower_path_min_distance_to_mesh_m':round(minimum_clearance,6),'lower_route_floor_local_z':hole_z-HOLE_R,
|
||||
'passage_open_at_bottom':hole_z-HOLE_R<0})
|
||||
showcase.append(body)
|
||||
|
||||
if kind=='y_merge':
|
||||
report['y_connections']={'inlet_surface_positions':[godot((-1,-.5,1-R)),godot((-1,.5,1-R))],
|
||||
'outlet_surface_position':godot((1,-.5,1-R)),'inlet_center_spacing_m':1.0,'inlet_height_difference_m':0.0,
|
||||
'lower_passage':'closed circular bore in the same block'}
|
||||
|
||||
bpy.ops.mesh.primitive_uv_sphere_add(segments=64,ring_count=32,radius=BALL_R,location=(0,0,0))
|
||||
ball=bpy.context.object;ball.name='iron_ball';ball.data.materials.append(iron);ball.data.materials.append(mark)
|
||||
for face in ball.data.polygons:
|
||||
face.use_smooth=True
|
||||
# A narrow painted orientation band makes true rotation visible.
|
||||
center=sum((ball.data.vertices[i].co for i in face.vertices),Vector())/len(face.vertices)
|
||||
if abs(center.y)<.025:face.material_index=1
|
||||
ball['asset_id']='iron_ball';ball['radius_m']=BALL_R
|
||||
export_objects([ball],'iron_ball')
|
||||
catalog['models']['iron_ball']={'path':'res://assets/balls/iron_ball/baseline/model.glb','radius':BALL_R,'boundsBlender':{'size':[2*BALL_R]*3}}
|
||||
report['measured_ball_radius_m']=max(v.co.length for v in ball.data.vertices)
|
||||
|
||||
# A true narrow goal aperture: both entrance and throat have the same radius.
|
||||
goal_vertices=[]
|
||||
for z,rad in [(0,GOAL_R),(0,GOAL_R+.04),(-GOAL_DEPTH,GOAL_R),(-GOAL_DEPTH,GOAL_R+.04)]:
|
||||
for i in range(96):
|
||||
a=i*math.tau/96
|
||||
goal_vertices.append((rad*math.cos(a),rad*math.sin(a),z))
|
||||
goal_faces=[]
|
||||
for i in range(96):
|
||||
j=(i+1)%96
|
||||
goal_faces += [(i,j,96+j,96+i),(192+i,288+i,288+j,192+j),(i,192+i,192+j,j),(96+i,96+j,288+j,288+i)]
|
||||
goal=mesh_obj('goal_hole',goal_vertices,goal_faces)
|
||||
goal.data.materials.append(goal_material)
|
||||
goal['asset_id']='goal_hole';goal['opening_radius_m']=GOAL_R
|
||||
export_objects([goal],'goal_hole')
|
||||
catalog['models']['goal_hole']={'path':'res://assets/goals/goal_hole/baseline/model.glb','role':'goal','openingRadius':GOAL_R,'depth':GOAL_DEPTH,'rimThickness':.04}
|
||||
(OUT/'catalog.json').write_text(json.dumps(catalog,indent=2,ensure_ascii=False))
|
||||
(ROOT/'playtest/artifacts/baseline/geometry_report.json').write_text(json.dumps(report,indent=2,ensure_ascii=False))
|
||||
for i,obj in enumerate(showcase):obj.location=(i%3*1.6,i//3*1.8,0)
|
||||
ball.location=(5.5,.5,BALL_R)
|
||||
goal.location=(6.5,.5,GOAL_DEPTH)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(SOURCE/'collection.blend'))
|
||||
print('INTOHOLE_ASSETS_READY',OUT)
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"interactive": [
|
||||
{
|
||||
"id": "directional_boost",
|
||||
"name": "定向加速",
|
||||
"assetId": "directional_boost"
|
||||
}
|
||||
],
|
||||
"nonInteractive": [
|
||||
{
|
||||
"id": "wall",
|
||||
"name": "标准墙壁",
|
||||
"assetId": "wall"
|
||||
},
|
||||
{
|
||||
"id": "goal_hole",
|
||||
"name": "锥口球洞",
|
||||
"assetId": "goal_hole"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"ballTypes": [
|
||||
{
|
||||
"ballTypeId": "iron_ball",
|
||||
"assetId": "iron_ball",
|
||||
"physicsProfileId": "solid_iron_test"
|
||||
}
|
||||
],
|
||||
"physicsProfiles": {
|
||||
"solid_iron_test": {
|
||||
"massKg": 890.0760306150601,
|
||||
"inertiaModel": "solidSphere",
|
||||
"dragCoefficient": 0.47,
|
||||
"contactMaterialId": "iron"
|
||||
}
|
||||
},
|
||||
"contactMaterialPairs": [
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "painted_wood",
|
||||
"staticFriction": 0.42,
|
||||
"dynamicFriction": 0.32,
|
||||
"rollingResistance": 0.025,
|
||||
"restitution": 0.08
|
||||
},
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "iron",
|
||||
"staticFriction": 0.35,
|
||||
"dynamicFriction": 0.25,
|
||||
"rollingResistance": 0.01,
|
||||
"restitution": 0.15
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"Experimental contact coefficients; iron material is unchanged.",
|
||||
"Solid iron sphere radius 0.3 m at nominal density 7870 kg/m³: mass about 890.08 kg."
|
||||
],
|
||||
"airDensity": 1.225
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
"""Blender-only authoring of a separate Railbound-inspired asset family.
|
||||
|
||||
Copies a stable source once; never writes to the baseline assets. To adopt a
|
||||
later baseline, remove only this family's source_snapshot files explicitly.
|
||||
"""
|
||||
import bpy
|
||||
import bmesh
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
from mathutils import Vector
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[4]
|
||||
SOURCE = Path(__file__).resolve().parent
|
||||
SNAPSHOT = SOURCE / 'snapshot'
|
||||
SNAPSHOT.mkdir(parents=True, exist_ok=True)
|
||||
ONLY_ASSET = globals().get('ONLY_ASSET')
|
||||
REPORTS = ROOT / 'playtest/artifacts/styled'
|
||||
REPORTS.mkdir(parents=True, exist_ok=True)
|
||||
OUT = SOURCE.parent
|
||||
SOURCE.mkdir(parents=True, exist_ok=True)
|
||||
snapshot = SNAPSHOT / 'source_snapshot.blend'
|
||||
inputs = [ROOT/'assets/collections/baseline/source/collection.blend',
|
||||
ROOT/'assets/collections/baseline/catalog.json', ROOT/'assets/collections/baseline/physics.json']
|
||||
def digest(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
if not snapshot.exists():
|
||||
before = [digest(p) for p in inputs]
|
||||
time.sleep(3)
|
||||
if before != [digest(p) for p in inputs]:
|
||||
raise RuntimeError('Baseline is changing. Wait for its current build, then retry.')
|
||||
copies = [snapshot, SNAPSHOT/'source_catalog.json', SNAPSHOT/'source_physics.json']
|
||||
for src, dst in zip(inputs, copies):
|
||||
shutil.copy2(src, dst)
|
||||
if before != [digest(p) for p in inputs] or before != [digest(p) for p in copies]:
|
||||
for p in copies: p.unlink(missing_ok=True)
|
||||
raise RuntimeError('Baseline changed during copy. No snapshot was retained.')
|
||||
(SNAPSHOT/'source_manifest.json').write_text(json.dumps({
|
||||
'files': {str(p.relative_to(ROOT)): h for p,h in zip(inputs,before)},
|
||||
'copiedAtUnix': time.time(), 'readOnlyBaseline': True}, indent=2))
|
||||
|
||||
bpy.ops.wm.open_mainfile(filepath=str(snapshot))
|
||||
bpy.context.preferences.filepaths.save_version=0
|
||||
catalog = json.loads((SNAPSHOT/'source_catalog.json').read_text())
|
||||
physics = json.loads((SNAPSHOT/'source_physics.json').read_text())
|
||||
palette = {'body':'B98A56', 'top':'E9C88B', 'groove':'FFF0C5',
|
||||
'ink':'342E38', 'iron':'788A9E', 'iron_light':'C6DFE5',
|
||||
'red':'CB6652', 'green':'799361'}
|
||||
def mat(name, color, metallic=0.0, roughness=.85):
|
||||
m = bpy.data.materials.new('Storybook / '+name)
|
||||
rgba = tuple(int(color[i:i+2],16)/255 for i in (0,2,4))+(1,)
|
||||
# Hex palette is sRGB; Blender's material values are linear.
|
||||
rgba = tuple(((v+.055)/1.055)**2.4 if v>.04045 else v/12.92 for v in rgba[:3])+(1,)
|
||||
m.diffuse_color = rgba
|
||||
m.use_nodes = True
|
||||
bsdf = m.node_tree.nodes.get('Principled BSDF')
|
||||
bsdf.inputs['Base Color'].default_value = rgba
|
||||
bsdf.inputs['Metallic'].default_value = metallic
|
||||
bsdf.inputs['Roughness'].default_value = roughness
|
||||
return m
|
||||
mats={k:mat(k,v) for k,v in palette.items()}
|
||||
mats['iron']=mat('iron satin','788A9E',.35,.5)
|
||||
mats['wall']=mat('wall stone','A29E8B')
|
||||
mats['wall_top']=mat('wall stone top','D8D3B4')
|
||||
|
||||
def mesh_object(name,vertices,faces):
|
||||
mesh=bpy.data.meshes.new(name)
|
||||
mesh.from_pydata(vertices,[],faces);mesh.update()
|
||||
bm=bmesh.new();bm.from_mesh(mesh)
|
||||
bmesh.ops.recalc_face_normals(bm,faces=bm.faces);bm.to_mesh(mesh);bm.free()
|
||||
obj=bpy.data.objects.new(name,mesh);bpy.context.collection.objects.link(obj)
|
||||
return obj
|
||||
|
||||
def build_funnel():
|
||||
bpy.data.objects.remove(bpy.data.objects['goal_hole'],do_unlink=True)
|
||||
# A closed shell with a wide conical entrance and a true narrow outlet.
|
||||
profile=[(.46,0),(.32,-.35),(.32,-1),(.36,-1),(.50,0)]
|
||||
sides=96
|
||||
vertices=[(radius*math.cos(i*math.tau/sides),radius*math.sin(i*math.tau/sides),z)
|
||||
for radius,z in profile for i in range(sides)]
|
||||
faces=[]
|
||||
for ring in range(len(profile)):
|
||||
next_ring=(ring+1)%len(profile)
|
||||
for i in range(sides):
|
||||
j=(i+1)%sides
|
||||
faces.append((ring*sides+i,ring*sides+j,next_ring*sides+j,next_ring*sides+i))
|
||||
return mesh_object('goal_hole',vertices,faces)
|
||||
|
||||
def build_wall(name='wall'):
|
||||
vertices=[(x,y,z) for z in (0,1) for y in (-.5,.5) for x in (-.5,.5)]
|
||||
faces=[(0,2,3,1),(4,5,7,6),(0,1,5,4),(2,6,7,3),(0,4,6,2),(1,3,7,5)]
|
||||
return mesh_object(name,vertices,faces)
|
||||
|
||||
build_funnel();build_wall();build_wall('directional_boost')
|
||||
catalog['models']['wall']={'role':'solid','category':'nonInteractive','collisionShape':'box',
|
||||
'cellFootprint':[1,1],'boundsBlender':{'min':[-.5,-.5,0],'max':[.5,.5,1],'size':[1,1,1]},
|
||||
'declaredSize':[1,1,1],'geometryOrigin':'authored'}
|
||||
catalog['models']['directional_boost']={'role':'boost','category':'interactive','collisionShape':'box',
|
||||
'cellFootprint':[1,1],'boundsBlender':{'min':[-.5,-.5,0],'max':[.5,.5,1],'size':[1,1,1]},
|
||||
'declaredSize':[1,1,1],'geometryOrigin':'authored','arrowDirectionGodot':[1,0,0]}
|
||||
catalog['models']['goal_hole']={'role':'goal','category':'nonInteractive','openingRadius':.32,
|
||||
'entranceRadius':.46,'funnelDepth':.35,'depth':1.0,'cellFootprint':[1,1],
|
||||
'boundsBlender':{'min':[-.5,-.5,-1],'max':[.5,.5,0],'size':[1,1,1]},
|
||||
'declaredSize':[1,1,1],'geometryOrigin':'authored'}
|
||||
|
||||
def export(objects, path):
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
for obj in objects: obj.select_set(True)
|
||||
bpy.context.view_layer.objects.active=objects[0]
|
||||
path.parent.mkdir(parents=True,exist_ok=True)
|
||||
bpy.ops.export_scene.gltf(filepath=str(path),export_format='GLB',
|
||||
use_selection=True,export_yup=True,export_extras=True,export_apply=True)
|
||||
|
||||
def lines(name, segments, radius=.012):
|
||||
curve=bpy.data.curves.new('ink_'+name,'CURVE')
|
||||
curve.dimensions='3D'; curve.bevel_depth=radius; curve.bevel_resolution=0
|
||||
curve.resolution_u=1
|
||||
for points in segments:
|
||||
spline=curve.splines.new('POLY'); spline.points.add(len(points)-1)
|
||||
for point, value in zip(spline.points,points):point.co=(*value,1)
|
||||
obj=bpy.data.objects.new('ink_'+name,curve)
|
||||
bpy.context.collection.objects.link(obj); obj.data.materials.append(mats['ink'])
|
||||
obj['visual_only']=True
|
||||
return obj
|
||||
|
||||
def outline(obj):
|
||||
bm=bmesh.new();bm.from_mesh(obj.data);bm.normal_update()
|
||||
segments=[]
|
||||
for edge in bm.edges:
|
||||
if len(edge.link_faces)!=2 or edge.calc_face_angle(0)>math.radians(36):
|
||||
segments.append([tuple(v.co) for v in edge.verts])
|
||||
bm.free()
|
||||
return lines(obj.name,segments)
|
||||
|
||||
def boost_arrow():
|
||||
# Flat authored graphic above the top face; excluded from collision like ink outlines.
|
||||
points=[(-.34,-.12),(.04,-.12),(.04,-.28),(.36,0),(.04,.28),(.04,.12),(-.34,.12)]
|
||||
result=[]
|
||||
for suffix,scale,z,color in [('border',1,1.002,'ink'),('fill',.82,1.003,'red')]:
|
||||
arrow=mesh_object('ink_boost_arrow_'+suffix,[(x*scale,y*scale,z) for x,y in points],[tuple(range(7))])
|
||||
arrow.data.materials.append(mats[color]);arrow['visual_only']=True
|
||||
result.append(arrow)
|
||||
return result
|
||||
|
||||
|
||||
def asset_dir(kind):
|
||||
category = 'balls' if kind == 'iron_ball' else 'goals' if kind == 'goal_hole' else 'blocks' if kind in ('wall','directional_boost') else 'chutes'
|
||||
return ROOT / 'assets' / category / kind
|
||||
|
||||
kinds=['straight','turn_cw','turn_ccw','gentle','steep','y_merge']
|
||||
groups=[];report=[]
|
||||
all_kinds=kinds+['iron_ball','goal_hole','wall','directional_boost']
|
||||
if ONLY_ASSET is not None and ONLY_ASSET not in all_kinds:raise ValueError(ONLY_ASSET)
|
||||
for kind in ([ONLY_ASSET] if ONLY_ASSET else all_kinds):
|
||||
obj=bpy.data.objects[kind]
|
||||
obj.location=(0,0,0)
|
||||
obj.data=obj.data.copy()
|
||||
before_coords=[tuple(v.co) for v in obj.data.vertices]
|
||||
old_indices=[p.material_index for p in obj.data.polygons]
|
||||
obj.data.materials.clear()
|
||||
if kind in kinds:
|
||||
for key in ['body','groove','top']:obj.data.materials.append(mats[key])
|
||||
for face,old in zip(obj.data.polygons,old_indices):
|
||||
face.material_index=1 if old==1 else (2 if face.normal.z>.55 else 0)
|
||||
group=[obj,outline(obj)]
|
||||
category='chutes'
|
||||
elif kind=='iron_ball':
|
||||
for key in ['iron','ink','iron_light']:obj.data.materials.append(mats[key])
|
||||
for face,old in zip(obj.data.polygons,old_indices):
|
||||
face.material_index=1 if old==1 else 0
|
||||
# An authored, low-detail bright cap gives the sphere a graphic highlight.
|
||||
if face.center.z>0.19 and face.center.x<-.04 and old!=1:face.material_index=2
|
||||
group=[obj]
|
||||
category='balls'
|
||||
elif kind=='goal_hole':
|
||||
obj.data.materials.append(mats['red'])
|
||||
obj.data.materials.append(mats['top'])
|
||||
obj.data.materials.append(mats['ink'])
|
||||
for face in obj.data.polygons:
|
||||
face.material_index=1 if face.index<96 else (2 if face.index<192 else 0)
|
||||
face.use_smooth=face.index<192
|
||||
group=[obj,outline(obj)]
|
||||
category='environment'
|
||||
else:
|
||||
obj.data.materials.append(mats['wall']);obj.data.materials.append(mats['wall_top'])
|
||||
for face in obj.data.polygons:face.material_index=1 if face.normal.z>.5 else 0
|
||||
group=[obj,outline(obj)]
|
||||
if kind=='directional_boost':group+=boost_arrow()
|
||||
category='entities'
|
||||
obj['style_family']='railbound_inspired'
|
||||
obj['collision_source']='authored mesh' if kind in ('wall','goal_hole','directional_boost') else 'unchanged source mesh'
|
||||
export(group,asset_dir(kind)/'model.glb')
|
||||
catalog['models'][kind]['path']='res://'+str((asset_dir(kind)/'model.glb').relative_to(ROOT))
|
||||
catalog['models'][kind]['sourceBlend']=str((asset_dir(kind)/'source/model.blend').relative_to(ROOT))
|
||||
for member in group:
|
||||
if member.type=='CURVE':
|
||||
bpy.ops.object.select_all(action='DESELECT');member.select_set(True)
|
||||
bpy.context.view_layer.objects.active=member
|
||||
bpy.ops.object.convert(target='MESH')
|
||||
source_path=asset_dir(kind)/'source/model.blend'
|
||||
source_path.parent.mkdir(parents=True,exist_ok=True)
|
||||
# A separate editable source file contains only one asset family member.
|
||||
report.append({'id':kind,'collisionGeometryUnchanged':kind not in ('wall','goal_hole','directional_boost') and before_coords==[tuple(v.co) for v in obj.data.vertices],
|
||||
'vertices':len(obj.data.vertices),'separateBlend':str(source_path.relative_to(ROOT))})
|
||||
groups.append(group)
|
||||
|
||||
if ONLY_ASSET:
|
||||
existing=json.loads((OUT/'catalog.json').read_text())
|
||||
existing['models'][ONLY_ASSET]=catalog['models'][ONLY_ASSET]
|
||||
catalog=existing
|
||||
else:
|
||||
catalog['models']={k:catalog['models'][k] for k in all_kinds}
|
||||
catalog['styleFamily']='railbound_inspired'
|
||||
catalog['palette']=palette
|
||||
(OUT/'catalog.json').write_text(json.dumps(catalog,ensure_ascii=False,indent=2))
|
||||
if not ONLY_ASSET:
|
||||
(OUT/'physics.json').write_text(json.dumps(physics,ensure_ascii=False,indent=2))
|
||||
(OUT/'entities.json').write_text(json.dumps({'interactive':[{'id':'directional_boost','name':'定向加速','assetId':'directional_boost'}],
|
||||
'nonInteractive':[{'id':'wall','name':'标准墙壁','assetId':'wall'},
|
||||
{'id':'goal_hole','name':'锥口球洞','assetId':'goal_hole'}]},ensure_ascii=False,indent=2))
|
||||
if ONLY_ASSET:
|
||||
names={member.name for member in groups[0]}
|
||||
for obj in list(bpy.data.objects):
|
||||
if obj.name not in names:bpy.data.objects.remove(obj,do_unlink=True)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(ROOT/report[0]['separateBlend']))
|
||||
else:
|
||||
for i,group in enumerate(groups):
|
||||
for member in group:member.location=(i%4*2.6,i//4*3,0)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(SOURCE/'collection.blend'))
|
||||
group_names=[[member.name for member in group] for group in groups]
|
||||
for entry, names in zip(report,group_names):
|
||||
bpy.ops.wm.open_mainfile(filepath=str(SOURCE/'collection.blend'))
|
||||
for obj in list(bpy.data.objects):
|
||||
if obj.name not in names:bpy.data.objects.remove(obj,do_unlink=True)
|
||||
else:obj.location=(0,0,0)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(ROOT/entry['separateBlend']))
|
||||
(REPORTS/(('asset_'+ONLY_ASSET+'.json') if ONLY_ASSET else 'assets.json')).write_text(json.dumps({
|
||||
'sourceManifest':json.loads((SNAPSHOT/'source_manifest.json').read_text()),
|
||||
'models':report,'radius':catalog['models']['iron_ball']['radius'],
|
||||
'physicalMaterialUnchanged':True,'outlineGeometry':'visual only'},indent=2))
|
||||
print('STYLE_ASSETS_READY')
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"files": {
|
||||
"assets/collections/baseline/source/collection.blend": "f81477cb30f5f5eb5a486a3a5e75c95b097204cfa5380c286cb1b40a85ee6962",
|
||||
"assets/collections/baseline/catalog.json": "7af16a52c10655df0353198e0de97864aaa1b7669503139e7c4f727450929085",
|
||||
"assets/collections/baseline/physics.json": "b12802f7763c162d037b0795e79272955031162790424831e88c939288f5526e"
|
||||
},
|
||||
"copiedAtUnix": 1794720924.17409,
|
||||
"readOnlyBaseline": true,
|
||||
"layoutMigration": "2026-11-16: paths moved; catalog resource paths rewritten; previous hashes retained in source_manifest.pre_reorganization.json"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"files": {
|
||||
"assets/blender/intohole_playtest.blend": "f81477cb30f5f5eb5a486a3a5e75c95b097204cfa5380c286cb1b40a85ee6962",
|
||||
"playtest/assets/generated/catalog.json": "e2b22e92f53b2d26f6ee90a72f4148084c3d6402f51ce6d6c5b8bc552e21af86",
|
||||
"playtest/data/physics.json": "b12802f7763c162d037b0795e79272955031162790424831e88c939288f5526e"
|
||||
},
|
||||
"copiedAtUnix": 1794720924.17409,
|
||||
"readOnlyBaseline": true
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"ballTypes": [
|
||||
{
|
||||
"ballTypeId": "iron_ball",
|
||||
"assetId": "iron_ball",
|
||||
"physicsProfileId": "solid_iron_test"
|
||||
}
|
||||
],
|
||||
"physicsProfiles": {
|
||||
"solid_iron_test": {
|
||||
"massKg": 890.0760306150601,
|
||||
"inertiaModel": "solidSphere",
|
||||
"dragCoefficient": 0.47,
|
||||
"contactMaterialId": "iron"
|
||||
}
|
||||
},
|
||||
"contactMaterialPairs": [
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "painted_wood",
|
||||
"staticFriction": 0.42,
|
||||
"dynamicFriction": 0.32,
|
||||
"rollingResistance": 0.025,
|
||||
"restitution": 0.08
|
||||
},
|
||||
{
|
||||
"materialAId": "iron",
|
||||
"materialBId": "iron",
|
||||
"staticFriction": 0.35,
|
||||
"dynamicFriction": 0.25,
|
||||
"rollingResistance": 0.01,
|
||||
"restitution": 0.15
|
||||
}
|
||||
],
|
||||
"notes": [
|
||||
"Experimental contact coefficients; iron material is unchanged.",
|
||||
"Solid iron sphere radius 0.3 m at nominal density 7870 kg/m³: mass about 890.08 kg."
|
||||
],
|
||||
"airDensity": 1.225
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,68 @@
|
||||
"""Reopen every delivered .blend and compare physical meshes with the snapshot."""
|
||||
import bpy
|
||||
import bmesh
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
ROOT=Path(__file__).resolve().parents[4]
|
||||
SOURCE=Path(__file__).resolve().parent/'snapshot'
|
||||
catalog=json.loads((ROOT/'assets/collections/storybook/catalog.json').read_text())
|
||||
bpy.ops.wm.open_mainfile(filepath=str(SOURCE/'source_snapshot.blend'))
|
||||
|
||||
def geometry(obj):
|
||||
return ([list(v.co) for v in obj.data.vertices],
|
||||
[list(p.vertices) for p in obj.data.polygons])
|
||||
|
||||
baseline={kind:geometry(bpy.data.objects[kind]) for kind in catalog['models'] if kind in bpy.data.objects}
|
||||
checks=[]
|
||||
for kind,data in catalog['models'].items():
|
||||
path=ROOT/data['sourceBlend']
|
||||
bpy.ops.wm.open_mainfile(filepath=str(path))
|
||||
obj=bpy.data.objects[kind]
|
||||
physical=[o for o in bpy.context.scene.objects if not o.name.startswith('ink_')]
|
||||
authored=data.get('geometryOrigin')=='authored'
|
||||
mesh_match=None if authored else geometry(obj)==baseline[kind]
|
||||
correct=(len(physical)==1 and physical[0].name==kind and
|
||||
(authored or mesh_match) and obj.location.length<1e-6 and
|
||||
all(abs(x-1)<1e-6 for x in obj.scale))
|
||||
check={'id':kind,'passed':correct,'objects':[o.name for o in bpy.context.scene.objects],
|
||||
'geometryMatchesSnapshot':mesh_match,
|
||||
'origin':list(obj.location),'dimensions':list(obj.dimensions),
|
||||
'materials':[m.name for m in obj.data.materials]}
|
||||
if kind=='iron_ball':
|
||||
radius=max(v.co.length for v in obj.data.vertices)
|
||||
check['measuredRadius']=radius
|
||||
correct=correct and abs(radius-data['radius'])<1e-6
|
||||
check['passed']=correct
|
||||
if authored:
|
||||
bm=bmesh.new();bm.from_mesh(obj.data)
|
||||
volume=abs(bm.calc_volume(signed=True));closed=all(e.is_manifold for e in bm.edges);bm.free()
|
||||
correct=correct and closed and all(abs(d-1)<1e-6 for d in obj.dimensions)
|
||||
if kind in ('wall','directional_boost'):
|
||||
correct=correct and abs(volume-1)<1e-6
|
||||
if kind=='directional_boost':
|
||||
arrow=bpy.data.objects.get('ink_boost_arrow_fill')
|
||||
correct=correct and arrow is not None
|
||||
if arrow is not None:
|
||||
points=[v.co for v in arrow.data.vertices]
|
||||
tip=max(points,key=lambda v:v.x)
|
||||
correct=correct and tip.x>0 and abs(tip.y)<1e-6 and all(1<v.z<1.01 for v in points)
|
||||
check['arrowTipBlender']=list(tip)
|
||||
else:
|
||||
rings={}
|
||||
for vertex in obj.data.vertices:
|
||||
z=round(vertex.co.z,5);radius=round((vertex.co.x**2+vertex.co.y**2)**.5,5)
|
||||
rings.setdefault(str(z),set()).add(radius)
|
||||
correct=correct and rings=={'0.0':{.46,.5},'-0.35':{.32},'-1.0':{.32,.36}}
|
||||
check['measuredRings']={k:sorted(v) for k,v in rings.items()}
|
||||
check.update({'passed':correct,'closedManifold':closed,'solidVolume':volume})
|
||||
checks.append(check)
|
||||
manifest=json.loads((SOURCE/'source_manifest.json').read_text())
|
||||
source_status={p:hashlib.sha256((ROOT/p).read_bytes()).hexdigest()==sha
|
||||
for p,sha in manifest['files'].items()}
|
||||
result={'passed':sum(c['passed'] for c in checks),'failed':sum(not c['passed'] for c in checks),
|
||||
'baselineStillMatchesSnapshot':source_status,'checks':checks}
|
||||
(ROOT/'playtest/artifacts/styled/reopened_assets.json').write_text(json.dumps(result,indent=2))
|
||||
if result['failed']:raise RuntimeError('Standalone source asset verification failed')
|
||||
print('REOPENED_ASSETS_VERIFIED',result['passed'])
|
||||
Reference in New Issue
Block a user