feat: 更新 IntoHole 的球体、滑槽和环境资产
- 为铁球、陶瓷球和木球制作风格化材质,归档 CC0 原始参考 - 更新方形球洞和实心滑槽,统一 90° 弯槽并兼容旧存档 - 用顺流泡沫表示水流方向,为冰块制作三种交错的裂纹 - 同步 Blender 源资产、Godot 加载、工坊和试玩预览
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user