feat: 更新 IntoHole 的球体、滑槽和环境资产

- 为铁球、陶瓷球和木球制作风格化材质,归档 CC0 原始参考
- 更新方形球洞和实心滑槽,统一 90° 弯槽并兼容旧存档
- 用顺流泡沫表示水流方向,为冰块制作三种交错的裂纹
- 同步 Blender 源资产、Godot 加载、工坊和试玩预览
This commit is contained in:
Yanchen
2026-11-19 16:18:41 +08:00
parent 39ff1fd7b4
commit d1141b04c7
467 changed files with 67228 additions and 44624 deletions
Binary file not shown.
@@ -0,0 +1,45 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://ya78fw358e75"
path="res://.godot/imported/model.glb-6cc90efe6822b1a635856ea7d3d3a204.scn"
[deps]
source_file="res://assets/balls/ceramic_ball/model.glb"
dest_files=["res://.godot/imported/model.glb-6cc90efe6822b1a635856ea7d3d3a204.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
mesh_library/use_node_names_as_mesh_names=false
array_mesh/deduplicate_surfaces=true
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1
gltf/texture_map_mode=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://0k2c3xdgqiva"
path="res://.godot/imported/model_albedo.png-82d35f3b3660dd164d75f2c3b226773a.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "06016bbe6f96a4e419fc20a3fa710152"
}
[deps]
source_file="res://assets/balls/ceramic_ball/model_albedo.png"
dest_files=["res://.godot/imported/model_albedo.png-82d35f3b3660dd164d75f2c3b226773a.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://fhyfxaf5asrh"
path="res://.godot/imported/model_roughness.png-59be5e931d9c533b6f842243cf09d23d.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "e4ec04fab38c2e44ae38db1e67d598be"
}
[deps]
source_file="res://assets/balls/ceramic_ball/model_roughness.png"
dest_files=["res://.godot/imported/model_roughness.png-59be5e931d9c533b6f842243cf09d23d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
@@ -0,0 +1,5 @@
"""Run with Blender to rebuild this resource only."""
from pathlib import Path
import runpy
runpy.run_path(str(Path(__file__).resolve().parents[2]/'shared/source/build_materials.py'),
init_globals={'ONLY_BALL':'ceramic_ball'})
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://kh3aww7nd6d6"
path="res://.godot/imported/albedo.png-33c6f966abe43a11068e69052ecdb175.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/ceramic_ball/textures/albedo.png"
dest_files=["res://.godot/imported/albedo.png-33c6f966abe43a11068e69052ecdb175.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d6unrrm6kef8"
path="res://.godot/imported/roughness.png-b8f7c08e3553b28c39cc3b9fc3edffb5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/ceramic_ball/textures/roughness.png"
dest_files=["res://.godot/imported/roughness.png-b8f7c08e3553b28c39cc3b9fc3edffb5.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://w4phnx0taeuv"
path="res://.godot/imported/model_albedo.png-730be8bbbc048f7984a134257e196849.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "9ccb02b2674bc87a3626a9e43794a3b2"
}
[deps]
source_file="res://assets/balls/iron_ball/model_albedo.png"
dest_files=["res://.godot/imported/model_albedo.png-730be8bbbc048f7984a134257e196849.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bttrpxg3ae8c8"
path="res://.godot/imported/model_roughness.png-f791fbe23d9aa82d833832823b0cfcca.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "b60b5c6f56f5e63d1bb707f61491184b"
}
[deps]
source_file="res://assets/balls/iron_ball/model_roughness.png"
dest_files=["res://.godot/imported/model_roughness.png-f791fbe23d9aa82d833832823b0cfcca.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
-70
View File
@@ -1,70 +0,0 @@
extends RigidBody3D
const Booster = preload("res://assets/blocks/directional_boost/behavior.gd")
var boost_controller = Booster.new()
var radius: float = 0.3
var drag_coefficient: float = 0.47
var air_density: float = 1.225
var wind_velocity := Vector3.ZERO
var mu_static: float = 0.42
var mu_dynamic: float = 0.32
var rolling_resistance: float = 0.025
var friction_enabled := true
var rolling_enabled := true
var drag_enabled := true
var contact_count := 0
var ball_contact_count := 0
var contact_slip := 0.0
var air_force := Vector3.ZERO
var rolling_torque := Vector3.ZERO
var travelled := 0.0
var previous_position := Vector3.ZERO
var tracking_started := false
func _ready() -> void:
continuous_cd = true
contact_monitor = true
max_contacts_reported = 12
can_sleep = false
linear_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
angular_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
linear_damp = 0.0
angular_damp = 0.0
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
if freeze:
return
contact_count = state.get_contact_count()
ball_contact_count = 0
contact_slip = 0.0
var support_normal := Vector3.ZERO
for i in range(contact_count):
if state.get_contact_collider_object(i) is RigidBody3D:ball_contact_count+=1
# Contact positions are global; the sphere's radial direction is unambiguous.
var n := (state.transform.origin - state.get_contact_local_position(i)).normalized()
var relative := state.get_contact_local_velocity_at_position(i) - state.get_contact_collider_velocity_at_position(i)
var slip := relative - n * relative.dot(n)
contact_slip = maxf(contact_slip, slip.length())
if n.dot(Vector3.UP) > 0.15:
support_normal += n
# Godot exposes one native friction coefficient. Select a slip-dependent
# coefficient; native contact solver still owns the friction impulse.
physics_material_override.friction = (mu_static if contact_slip < 0.035 else mu_dynamic) if friction_enabled else 0.0
boost_controller.integrate(state, radius)
var relative_air := state.linear_velocity - wind_velocity
air_force = -0.5 * air_density * drag_coefficient * PI * radius * radius * relative_air.length() * relative_air if drag_enabled else Vector3.ZERO
state.apply_central_force(air_force)
rolling_torque = Vector3.ZERO
if rolling_enabled and support_normal.length_squared() > 0.001:
var n := support_normal.normalized()
var roll := state.angular_velocity - n * state.angular_velocity.dot(n)
if roll.length() > 0.0001:
var support := maxf(0.0, -(mass * state.total_gravity + air_force).dot(n))
var moment := 0.4 * mass * radius * radius
var limit := roll.length() * moment / state.step
rolling_torque = -roll.normalized() * minf(rolling_resistance * support * radius, limit)
state.apply_torque(rolling_torque)
if tracking_started:
travelled += state.transform.origin.distance_to(previous_position)
previous_position = state.transform.origin
tracking_started = true
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c524j5jnn6syn"
path="res://.godot/imported/albedo.png-52a28122060bfc7a8ebbba40cba00af1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/iron_ball/textures/albedo.png"
dest_files=["res://.godot/imported/albedo.png-52a28122060bfc7a8ebbba40cba00af1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bqgoffuomxwr4"
path="res://.godot/imported/roughness.png-2a435370a2fb0da58c9b9262c3a9f719.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/iron_ball/textures/roughness.png"
dest_files=["res://.godot/imported/roughness.png-2a435370a2fb0da58c9b9262c3a9f719.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
+122
View File
@@ -0,0 +1,122 @@
extends RigidBody3D
const Water = preload("res://assets/blocks/water/behavior.gd")
const Booster = preload("res://assets/blocks/directional_boost/behavior.gd")
var boost_controller = Booster.new()
var surface_pairs: Dictionary={}
var base_bounce := 0.08
var active_surface := "painted_wood"
var submerged_fraction := 0.0
var water_velocity := Vector3.ZERO
var buoyancy_force := Vector3.ZERO
var water_drag_force := Vector3.ZERO
var impact_contacts: Dictionary={}
var last_linear_velocity := Vector3.ZERO
var radius: float = 0.3
var drag_coefficient: float = 0.47
var air_density: float = 1.225
var wind_velocity := Vector3.ZERO
var mu_static: float = 0.42
var mu_dynamic: float = 0.32
var rolling_resistance: float = 0.025
var friction_enabled := true
var rolling_enabled := true
var drag_enabled := true
var contact_count := 0
var ball_contact_count := 0
var contact_slip := 0.0
var air_force := Vector3.ZERO
var rolling_torque := Vector3.ZERO
var travelled := 0.0
var previous_position := Vector3.ZERO
var tracking_started := false
func _ready() -> void:
continuous_cd = true
contact_monitor = true
max_contacts_reported = 12
can_sleep = false
linear_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
angular_damp_mode = RigidBody3D.DAMP_MODE_REPLACE
linear_damp = 0.0
angular_damp = 0.0
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
if freeze:
return
contact_count = state.get_contact_count()
ball_contact_count = 0
contact_slip = 0.0
var support_normal := Vector3.ZERO
var active_pair: Dictionary={}
var impacts: Dictionary={}
active_surface="painted_wood"
for i in range(contact_count):
var collider: Node=state.get_contact_collider_object(i)
if collider is RigidBody3D:ball_contact_count+=1
var surface: String=collider.get_meta("piece_type","") if collider!=null else ""
if surface_pairs.has(surface):
var pair: Dictionary=surface_pairs[surface]
if active_pair.is_empty() or pair.dynamicFriction>active_pair.dynamicFriction:
active_pair=pair;active_surface=surface
# Contact positions are global; the sphere's radial direction is unambiguous.
var n := (state.transform.origin - state.get_contact_local_position(i)).normalized()
var relative := state.get_contact_local_velocity_at_position(i) - state.get_contact_collider_velocity_at_position(i)
var slip := relative - n * relative.dot(n)
contact_slip = maxf(contact_slip, slip.length())
if surface=="ice":
var block: Node=collider
while block!=null and not block.has_method("receive_impact"):block=block.get_parent()
if block!=null:
var id:=block.get_instance_id()
if not impacts.has(id):impacts[id]={"block":block,"impulse":0.0,"approach":0.0}
impacts[id].impulse+=absf(state.get_contact_impulse(i).dot(n))
impacts[id].approach=maxf(impacts[id].approach,maxf(-relative.dot(n),-last_linear_velocity.dot(n)))
if n.dot(Vector3.UP) > 0.15 or (surface=="wall" and (mass*state.total_gravity+constant_force+air_force+buoyancy_force+water_drag_force).dot(n)<-.01):
support_normal += n
# Godot exposes one native friction coefficient. Select a slip-dependent
# coefficient; native contact solver still owns the friction impulse.
for id in impacts:
if not impact_contacts.has(id):
var impact: Dictionary=impacts[id]
# Jolt may report a speculative contact before the actual impact.
# Arm only after a real approach/impulse; resting contact never accumulates.
if impact.approach>=impact.block.MIN_APPROACH_SPEED and impact.impulse>0:
impact.block.receive_impact(str(get_meta("ball_id",name)),impact.impulse,impact.approach)
impact_contacts[id]=true
for id in impact_contacts.keys():
if not impacts.has(id):impact_contacts.erase(id)
var contact_static: float=active_pair.get("staticFriction",mu_static)
var contact_dynamic: float=active_pair.get("dynamicFriction",mu_dynamic)
var contact_rolling: float=active_pair.get("rollingResistance",rolling_resistance)
physics_material_override.friction = (contact_static if contact_slip < 0.035 else contact_dynamic) if friction_enabled else 0.0
physics_material_override.bounce=active_pair.get("restitution",base_bounce)
boost_controller.integrate(state, radius)
var water: Dictionary=Water.sample(state.transform.origin,radius,get_tree().get_nodes_in_group("water_blocks"))
submerged_fraction=water.fraction;water_velocity=water.velocity
var volume:=4.0/3.0*PI*radius*radius*radius*submerged_fraction
buoyancy_force=-state.total_gravity*Water.DENSITY*volume
var relative_water:=state.linear_velocity-water_velocity
water_drag_force=-.5*Water.DENSITY*Water.DRAG_COEFFICIENT*PI*radius*radius*submerged_fraction*relative_water.length()*relative_water
# Bound only the numerical drag step; never teleport or set a target speed.
var drag_limit:=relative_water.length()*mass/state.step
if water_drag_force.length()>drag_limit:water_drag_force=water_drag_force.normalized()*drag_limit
state.apply_central_force(buoyancy_force+water_drag_force)
var relative_air := state.linear_velocity - wind_velocity
air_force = -0.5 * air_density * drag_coefficient * PI * radius * radius * relative_air.length() * relative_air * (1.0-submerged_fraction) if drag_enabled else Vector3.ZERO
state.apply_central_force(air_force)
rolling_torque = Vector3.ZERO
if rolling_enabled and support_normal.length_squared() > 0.001:
var n := support_normal.normalized()
var roll := state.angular_velocity - n * state.angular_velocity.dot(n)
if roll.length() > 0.0001:
var support := maxf(0.0, -(mass * state.total_gravity + constant_force + air_force + buoyancy_force + water_drag_force).dot(n))
var moment := 0.4 * mass * radius * radius
var limit := roll.length() * moment / state.step
rolling_torque = -roll.normalized() * minf(contact_rolling * support * radius, limit)
state.apply_torque(rolling_torque)
last_linear_velocity=state.linear_velocity
if tracking_started:
travelled += state.transform.origin.distance_to(previous_position)
previous_position = state.transform.origin
tracking_started = true
Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

@@ -0,0 +1,57 @@
"""Export wood and porcelain finishes on the existing iron sphere mesh."""
import bpy
import json
import runpy
from pathlib import Path
ROOT = Path(__file__).resolve().parents[4]
OUT = ROOT / 'assets/collections/storybook'
KINDS = ['wood_ball', 'ceramic_ball']
ONLY_BALL = globals().get('ONLY_BALL')
if ONLY_BALL is not None and ONLY_BALL not in KINDS:
raise ValueError(ONLY_BALL)
apply_material = runpy.run_path(str(Path(__file__).with_name('material_style.py')))['apply_material']
catalog = json.loads((OUT/'catalog.json').read_text())
for kind in ([ONLY_BALL] if ONLY_BALL else KINDS):
directory = ROOT/'assets/balls'/kind
source = directory/'source/model.blend'
input_model = source if source.exists() else ROOT/'assets/balls/iron_ball/source/model.blend'
bpy.ops.wm.open_mainfile(filepath=str(input_model))
bpy.context.preferences.filepaths.save_version = 0
obj = bpy.data.objects[kind if input_model == source else 'iron_ball']
obj.name = kind
obj.data = obj.data.copy()
obj['asset_id'] = kind
obj['collision_source'] = 'same sphere geometry as iron_ball'
assert obj.data.uv_layers, 'Iron source must retain its authored UVs'
apply_material(obj, kind)
obj.location = (0,0,0)
bpy.ops.object.select_all(action='DESELECT');obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.export_scene.gltf(filepath=str(directory/'model.glb'),export_format='GLB',use_selection=True,
export_yup=True,export_extras=True,export_apply=True)
source.parent.mkdir(parents=True,exist_ok=True)
bpy.ops.wm.save_as_mainfile(filepath=str(source))
metadata = dict(catalog['models']['iron_ball'])
metadata.update(path='res://'+str((directory/'model.glb').relative_to(ROOT)),
sourceBlend=str(source.relative_to(ROOT)),role='ball',geometrySource='iron_ball',
albedoTexture='res://'+str((directory/'textures/albedo.png').relative_to(ROOT)))
catalog['models'][kind] = metadata
(OUT/'catalog.json').write_text(json.dumps(catalog,indent=2,ensure_ascii=False)+'\n')
if not ONLY_BALL:
# Full-family build also keeps the editable collection complete.
collection = OUT/'source/collection.blend'
bpy.ops.wm.open_mainfile(filepath=str(collection))
bpy.context.preferences.filepaths.save_version = 0
for i,kind in enumerate(KINDS):
if kind in bpy.data.objects:bpy.data.objects.remove(bpy.data.objects[kind],do_unlink=True)
with bpy.data.libraries.load(str(ROOT/catalog['models'][kind]['sourceBlend']),link=False) as (src,dst):
dst.objects = [kind]
obj = dst.objects[0]
bpy.context.collection.objects.link(obj)
obj.location = (5.2+i*2.6,6,0)
bpy.ops.wm.save_as_mainfile(filepath=str(collection))
print('MATERIAL_BALLS_READY',ONLY_BALL or KINDS)
@@ -0,0 +1,48 @@
extends SceneTree
const OUTPUT = "res://assets/balls/shared/previews/material-style-v1/"
const BALLS = ["iron_ball", "ceramic_ball", "wood_ball"]
func _initialize() -> void:
call_deferred("capture")
func capture() -> void:
var args := OS.get_cmdline_user_args()
if args.size() != 1 or args[0] not in ["before", "after"]:
push_error("Pass either before or after as the capture name.")
quit(1)
return
var app = load("res://playtest/tutorial/scenes/tutorial.tscn").instantiate()
root.add_child(app)
var pieces: Array = []
var balls: Array = []
for i in range(BALLS.size()):
var at := Vector3(1.5, 0, -1.0) * (i - 1)
pieces.append({"id": "lane_%d" % i, "kind": "straight", "position": [at.x, at.y, at.z], "quarter": 0})
var center: Vector3 = at + app.lib.ball_on_surface("straight", 0.5)
balls.append({"id": BALLS[i], "ballTypeId": BALLS[i], "position": [center.x, center.y, center.z]})
app.apply_data({"schemaVersion": 2, "pieces": pieces, "entities": [], "balls": balls})
for child in app.get_children():
if child is CanvasLayer:
child.hide()
for tag in app.tags:
tag.hide()
app.slots_view.hide()
app.preview_view.hide()
app.selection.hide()
app.ball_marker.hide()
app.camera.h_offset = 0
app.camera.v_offset = 0
app.camera_size = 6.2
app.target = Vector3(0, 0.56, 0)
app.update_camera()
for i in range(8):
await process_frame
RenderingServer.force_draw(false)
RenderingServer.force_sync()
var screenshot := root.get_texture().get_image()
var path := ProjectSettings.globalize_path(OUTPUT + args[0] + ".png")
var result := screenshot.save_png(path)
if result != OK:
push_error("Could not save material comparison to " + path)
quit(0 if result == OK else 1)
@@ -0,0 +1,173 @@
"""Bake and apply the three stylized finishes on the existing UV spheres.
Run this file in Blender to bake new maps. The normal asset build reads the
saved maps, so rebuilding a model does not overwrite an edited texture.
"""
from pathlib import Path
import struct
import zlib
import bpy
import numpy as np
ROOT = Path(__file__).resolve().parents[4]
REFERENCES = ROOT / 'references/materials/ball-materials'
BALLS = ROOT / 'assets/balls'
SIZE = (1024, 512)
FINISHES = {
'iron_ball': ('Satin iron', (0.173, 0.226, 0.295), 0.46),
'ceramic_ball': ('Ivory porcelain glaze with cobalt scallops', (0.78, 0.69, 0.52), 0.0),
'wood_ball': ('Honey wood with painted grain', (0.49, 0.24, 0.09), 0.0),
}
def apply_material(obj, kind):
name, color, metallic = FINISHES[kind]
material = bpy.data.materials.new(name)
material.diffuse_color = (*color, 1)
material.use_nodes = True
nodes = material.node_tree.nodes
shader = nodes.get('Principled BSDF')
shader.inputs['Metallic'].default_value = metallic
for file, color_space, socket, position in (
('albedo.png', 'sRGB', 'Base Color', (-480, 230)),
('roughness.png', 'Non-Color', 'Roughness', (-480, -80)),
):
path = BALLS / kind / 'textures' / file
image = bpy.data.images.load(str(path), check_existing=False)
image.colorspace_settings.name = color_space
# Give each ball a reimportable glTF image name, including across a full build.
image.name = f'{kind}_{path.stem}'
image.pack()
image.filepath = str(path)
texture = nodes.new('ShaderNodeTexImage')
texture.label = socket
texture.location = position
texture.image = image
texture.extension = 'REPEAT'
material.node_tree.links.new(texture.outputs['Color'], shader.inputs[socket])
obj.data.materials.clear()
obj.data.materials.append(material)
for face in obj.data.polygons:
face.material_index = 0
face.use_smooth = True
def read_reference(path):
image = bpy.data.images.load(str(REFERENCES / path), check_existing=False)
width, height = image.size
values = np.empty(width * height * 4, dtype=np.float32)
image.pixels.foreach_get(values)
bpy.data.images.remove(image)
return values.reshape(height, width, 4)[..., :3]
def lightness(map_rgb):
return map_rgb @ np.array([0.2126, 0.7152, 0.0722], dtype=np.float32)
def sample(tile, u, v):
"""Bilinear sample a repeating reference in its local projection."""
height, width = tile.shape
u, v = u * width, v * height
i, j = np.floor(u).astype(int), np.floor(v).astype(int)
du, dv = u - i, v - j
low = (1 - du) * tile[j % height, i % width] + du * tile[j % height, (i + 1) % width]
high = (1 - du) * tile[(j + 1) % height, i % width] + du * tile[(j + 1) % height, (i + 1) % width]
return low * (1 - dv) + high * dv
def project(tile, x, y, z, scale):
"""Project from three axes without concentrating image detail at UV poles."""
weights = np.stack([x**4, y**4, z**4])
a = sample(tile, y * scale + .31, z * scale + .13)
b = sample(tile, x * scale + .51, z * scale + .39)
c = sample(tile, x * scale + .21, y * scale + .77)
return (weights[0] * a + weights[1] * b + weights[2] * c) / weights.sum(axis=0)
def iron(x, y, z):
base_tile = lightness(read_reference('iron/textures/metal032/Metal032_1K-JPG_Color.jpg'))
sheen = lightness(read_reference('iron/textures/metal032/Metal032_1K-JPG_Roughness.jpg'))
brushed = lightness(read_reference('iron/textures/metal009/Metal009_1K-JPG_Color.jpg'))
base = project(base_tile - np.mean(base_tile), x, y, z, .58)
scratches = project(brushed - np.mean(brushed), x, y, z, .85)
satin = project(sheen - np.mean(sheen), x, y, z, .54)
# Preserve an even cool silhouette; the fine marks only vary local tone and sheen.
color = np.array([.45, .515, .58]) + (.24 * base + .18 * scratches)[..., None]
return color, np.clip(.44 + .21 * satin + .13 * scratches, .38, .50)
def porcelain(x, y, z):
source = read_reference('ceramic/textures/porcelain-001/Porcelain_001_basecolor.png')
blue = source[source[..., 2] - source[..., 0] > .17].mean(axis=0)
pigment = .23 * blue + .77 * np.array([.13, .315, .51])
# Tilt the decoration so part of it stays readable in the elevated game view.
latitude = np.arcsin(np.clip(.966 * z + .259 * x, -1, 1))
longitude = np.arctan2(y, .966 * x - .259 * z)
phase = 5 * longitude + .44
band = np.abs(latitude) - .53
scallop = .145 * (np.cos(phase) + .20 * np.cos(2 * phase))
stroke = np.abs(band - scallop) - (.080 + .011 * np.sin(phase))
# The source's little teardrop fan becomes a few soft dabs inside each arc.
cell = (phase + np.pi) % (2 * np.pi) - np.pi
for angle in (-.71, 0, .71):
dab = np.hypot((cell - angle) / .19, (band - .30 + abs(angle) * .09) / .045)
stroke = np.minimum(stroke, (dab - 1) * .045)
mask = np.clip(.5 - stroke / .016, 0, 1)
variation = .008 * np.sin(5 * y + 3 * z) * np.cos(4 * x - 2 * z)
ivory = np.array([.81, .766, .677]) + variation[..., None]
color = ivory * (1 - mask[..., None]) + (pigment + variation[..., None]) * mask[..., None]
# Patches of glaze stay glossy without the constant zero roughness in the source pack.
return color, .19 + .023 * mask + variation
def wood(x, y, z):
natural = lightness(read_reference('wood/textures/wood092/Wood092_1K-JPG_Color.jpg'))
painted = lightness(read_reference('wood/textures/handpainted-wood/oga-wood-painted.png'))
# Lay large bands over the sphere like grain in a turned wooden blank.
# A tilted axis puts the grain over the crown as well as down the sides.
side = .72 * x + .69 * z
height = .72 * z - .69 * x
radial = np.hypot(side + .51, y - .40)
wobble = .059 * np.sin(5.2 * height + 3.4 * side) + .021 * np.sin(12 * height - 2 * y)
grain = (.5 + .5 * np.sin(37 * (radial + wobble))) ** 3
painted_tone = project(painted - np.mean(painted), side, y, height, .42)
fine_tone = project(natural - np.mean(natural), side, y, height, .67)
color = np.array([.73, .50, .32]) - grain[..., None] * np.array([.105, .113, .090])
color += (.12 * painted_tone + .10 * fine_tone)[..., None]
return color, np.clip(.63 + .12 * grain + .12 * fine_tone, .59, .77)
def save_png(path, values):
data = (np.clip(values, 0, 1) * 255 + .5).astype(np.uint8)
# UV texture v=0 is the bottom row; PNG stores the top row first.
pixels = b''.join(b'\0' + row.tobytes() for row in data[::-1])
def chunk(kind, payload):
return (struct.pack('!I', len(payload)) + kind + payload
+ struct.pack('!I', zlib.crc32(kind + payload)))
color_type = 2 if data.ndim == 3 else 0
header = struct.pack('!IIBBBBB', *SIZE, 8, color_type, 0, 0, 0)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', header)
+ chunk(b'IDAT', zlib.compress(pixels, 9)) + chunk(b'IEND', b''))
def bake():
width, height = SIZE
u, v = np.meshgrid((np.arange(width) + .5) / width, (np.arange(height) + .5) / height)
theta, phi = u * np.pi * 2, v * np.pi
x, y, z = np.sin(phi) * np.cos(theta), np.sin(phi) * np.sin(theta), -np.cos(phi)
for kind, finish in (('iron_ball', iron), ('ceramic_ball', porcelain), ('wood_ball', wood)):
color, roughness = finish(x, y, z)
directory = BALLS / kind / 'textures'
save_png(directory / 'albedo.png', color)
save_png(directory / 'roughness.png', roughness)
if __name__ == '__main__':
bake()
Binary file not shown.
+45
View File
@@ -0,0 +1,45 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://cj5olusn75u82"
path="res://.godot/imported/model.glb-1b1d4d547ed4d9dec0abc98f91db5a5f.scn"
[deps]
source_file="res://assets/balls/wood_ball/model.glb"
dest_files=["res://.godot/imported/model.glb-1b1d4d547ed4d9dec0abc98f91db5a5f.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
mesh_library/use_node_names_as_mesh_names=false
array_mesh/deduplicate_surfaces=true
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1
gltf/texture_map_mode=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://8il0l1lnddbp"
path="res://.godot/imported/model_albedo.png-3e262a7b51a87c5cf8f8cd6a272f7e53.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "a58aa5cfe4dcca1810b45db182745c1f"
}
[deps]
source_file="res://assets/balls/wood_ball/model_albedo.png"
dest_files=["res://.godot/imported/model_albedo.png-3e262a7b51a87c5cf8f8cd6a272f7e53.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bwnilietrwddx"
path="res://.godot/imported/model_roughness.png-504e85521daad75c23a39c5972ba1a2b.ctex"
metadata={
"vram_texture": false
}
generator_parameters={
"md5": "c0276a32c5fd5f8f8e4785fd1e80afe9"
}
[deps]
source_file="res://assets/balls/wood_ball/model_roughness.png"
dest_files=["res://.godot/imported/model_roughness.png-504e85521daad75c23a39c5972ba1a2b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
+5
View File
@@ -0,0 +1,5 @@
"""Run with Blender to rebuild this resource only."""
from pathlib import Path
import runpy
runpy.run_path(str(Path(__file__).resolve().parents[2]/'shared/source/build_materials.py'),
init_globals={'ONLY_BALL':'wood_ball'})
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpg05wpdgk3ip"
path="res://.godot/imported/albedo.png-b9f9faa18ff7a60c8139629d52fcd67d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/wood_ball/textures/albedo.png"
dest_files=["res://.godot/imported/albedo.png-b9f9faa18ff7a60c8139629d52fcd67d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c3llp5lu756e6"
path="res://.godot/imported/roughness.png-29fa2a28b7968617794dfe15bf2a9b31.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/balls/wood_ball/textures/roughness.png"
dest_files=["res://.godot/imported/roughness.png-29fa2a28b7968617794dfe15bf2a9b31.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1