A 3D model pipeline, pushed by Gemini 4 Carbon
agent
+1:16:51reasoning
The script tools/export_glb.py's handling of "hair" materials uses a base color factor including an alpha component of 1.0. This logic correctly assigns the base color, appending an alpha value for the color. This can be adapted to handle full-color materials as well.
edit_file{"Path":"~/work/lowmarch/tools/export_glb.py","Replacement":"def export_skinned(portrait, palette, path, clips=None, max_tex=512, extras=None, step_clips=()):","Target":"def export_skinned(portrait, palette, path, clips=None, max_tex=512):"}
input
{ "Path": "~/work/lowmarch/tools/export_glb.py", "Replacement": "def export_skinned(portrait, palette, path, clips=None, max_tex=512, extras=None, step_clips=()):", "Target": "def export_skinned(portrait, palette, path, clips=None, max_tex=512):" }result, 1 line
Made 1 replacement in ~/work/lowmarch/tools/export_glb.py starting at line 380 (+1/-1 lines).
edit_file{"Path":"~/work/lowmarch/tools/export_glb.py","Replacement":" if role in TEXTURED:\n src = portrait._hair_v if role == \"hair\" and getattr(portrait, \"_hair_v\", None) is not None \\\n and \"_HAIR\" in p[\"material\"] else portrait.v\n raw = p.get(\"custom_tex\")\n if raw is None:\n raw = src.material_texture(p[\"mi\"]) if p[\"mi\"] >= 0 else None\n if raw is not None and role == \"line\" and \"custom_tex\" not in p:\n raw = fill_line_specks(raw)\n if p.get(\"lid_fill\") is not None: # a shut eye's lid (vroid_portrait): its lash solid\n raw = fill_lid(raw, p[\"lid_fill\"])\n if raw is not None and role == \"mouth\" and \"custom_tex\" not in p:\n raw = even_mouth(raw)\n if raw is not None:\n attrs[\"TEXCOORD_0\"] = add_acc(p[\"uv\"][usedv].astype(np.float32), \"VEC2\", 5126, 34962)\n tkey = (\"custom_tex\", k) if \"custom_tex\" in p else (id(src), p[\"mi\"], p.get(\"lid_fill\"))\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(index=add_texture(tkey, raw))\n if role == \"hair\":\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"hair\", \"line\", \"brow\", \"iris\", \"highlight\"):\n mat[\"alphaMode\"], mat[\"alphaCutoff\"] = \"MASK\", 0.5\n if p.get(\"full_color_tex\"):\n mat[\"extras\"] = dict(mat.get(\"extras\") or {}, fullColor=True)\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]","Target":" if role in TEXTURED:\n src = portrait._hair_v if role == \"hair\" and getattr(portrait, \"_hair_v\", None) is not None \\\n and \"_HAIR\" in p[\"material\"] else portrait.v\n raw = src.material_texture(p[\"mi\"]) if p[\"mi\"] >= 0 else None\n if raw is not None and role == \"line\":\n raw = fill_line_specks(raw)\n if p.get(\"lid_fill\") is not None: # a shut eye's lid (vroid_portrait): its lash solid\n raw = fill_lid(raw, p[\"lid_fill\"])\n if raw is not None and role == \"mouth\":\n raw = even_mouth(raw)\n if raw is not None:\n attrs[\"TEXCOORD_0\"] = add_acc(p[\"uv\"][usedv].astype(np.float32), \"VEC2\", 5126, 34962)\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(\n index=add_texture((id(src), p[\"mi\"], p.get(\"lid_fill\")), raw))\n if role == \"hair\":\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"hair\", \"line\", \"brow\", \"iris\", \"highlight\"):\n mat[\"alphaMode\"], mat[\"alphaCutoff\"] = \"MASK\", 0.5\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]"}
input
{ "Path": "~/work/lowmarch/tools/export_glb.py", "Replacement": " if role in TEXTURED:\n src = portrait._hair_v if role == \"hair\" and getattr(portrait, \"_hair_v\", None) is not None \\\n and \"_HAIR\" in p[\"material\"] else portrait.v\n raw = p.get(\"custom_tex\")\n if raw is None:\n raw = src.material_texture(p[\"mi\"]) if p[\"mi\"] >= 0 else None\n if raw is not None and role == \"line\" and \"custom_tex\" not in p:\n raw = fill_line_specks(raw)\n if p.get(\"lid_fill\") is not None: # a shut eye's lid (vroid_portrait): its lash solid\n raw = fill_lid(raw, p[\"lid_fill\"])\n if raw is not None and role == \"mouth\" and \"custom_tex\" not in p:\n raw = even_mouth(raw)\n if raw is not None:\n attrs[\"TEXCOORD_0\"] = add_acc(p[\"uv\"][usedv].astype(np.float32), \"VEC2\", 5126, 34962)\n tkey = (\"custom_tex\", k) if \"custom_tex\" in p else (id(src), p[\"mi\"], p.get(\"lid_fill\"))\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(index=add_texture(tkey, raw))\n if role == \"hair\":\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"hair\", \"line\", \"brow\", \"iris\", \"highlight\"):\n mat[\"alphaMode\"], mat[\"alphaCutoff\"] = \"MASK\", 0.5\n if p.get(\"full_color_tex\"):\n mat[\"extras\"] = dict(mat.get(\"extras\") or {}, fullColor=True)\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]", "Target": " if role in TEXTURED:\n src = portrait._hair_v if role == \"hair\" and getattr(portrait, \"_hair_v\", None) is not None \\\n and \"_HAIR\" in p[\"material\"] else portrait.v\n raw = src.material_texture(p[\"mi\"]) if p[\"mi\"] >= 0 else None\n if raw is not None and role == \"line\":\n raw = fill_line_specks(raw)\n if p.get(\"lid_fill\") is not None: # a shut eye's lid (vroid_portrait): its lash solid\n raw = fill_lid(raw, p[\"lid_fill\"])\n if raw is not None and role == \"mouth\":\n raw = even_mouth(raw)\n if raw is not None:\n attrs[\"TEXCOORD_0\"] = add_acc(p[\"uv\"][usedv].astype(np.float32), \"VEC2\", 5126, 34962)\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(\n index=add_texture((id(src), p[\"mi\"], p.get(\"lid_fill\")), raw))\n if role == \"hair\":\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"hair\", \"line\", \"brow\", \"iris\", \"highlight\"):\n mat[\"alphaMode\"], mat[\"alphaCutoff\"] = \"MASK\", 0.5\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]" }result, 1 line
Made 1 replacement in ~/work/lowmarch/tools/export_glb.py starting at line 487 (+9/-5 lines).
edit_file{"Path":"~/work/lowmarch/tools/export_glb.py","Replacement":" interp = \"STEP\" if name in step_clips else \"LINEAR\"\n # a channel whenever the clip leaves the reference pose, even if it then holds still\n if np.abs(Q - q0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(Q, \"VEC4\", 5126), interpolation=interp))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"rotation\")))\n if np.abs(T - t0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(T, \"VEC3\", 5126), interpolation=interp))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"translation\")))\n anims.append(dict(name=name, samplers=samplers, channels=channels))\n root = len(gnodes)\n gnodes.append(dict(name=\"character\", children=roots + mesh_nodes))\n gltf = dict(asset=dict(version=\"2.0\", generator=\"lowmarch export_skinned\"), scene=0, scenes=[dict(nodes=[root])],\n nodes=gnodes, meshes=meshes, materials=materials, skins=[skin], accessors=accessors, bufferViews=views,\n buffers=[dict(byteLength=len(bin_))], samplers=[dict(magFilter=9729, minFilter=9987)])\n if extras is not None:\n gltf[\"extras\"] = extras","Target":" # a channel whenever the clip leaves the reference pose, even if it then holds still\n if np.abs(Q - q0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(Q, \"VEC4\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"rotation\")))\n if np.abs(T - t0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(T, \"VEC3\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"translation\")))\n anims.append(dict(name=name, samplers=samplers, channels=channels))\n root = len(gnodes)\n gnodes.append(dict(name=\"character\", children=roots + mesh_nodes))\n gltf = dict(asset=dict(version=\"2.0\", generator=\"lowmarch export_skinned\"), scene=0, scenes=[dict(nodes=[root])],\n nodes=gnodes, meshes=meshes, materials=materials, skins=[skin], accessors=accessors, bufferViews=views,\n buffers=[dict(byteLength=len(bin_))], samplers=[dict(magFilter=9729, minFilter=9987)])"}
input
{ "Path": "~/work/lowmarch/tools/export_glb.py", "Replacement": " interp = \"STEP\" if name in step_clips else \"LINEAR\"\n # a channel whenever the clip leaves the reference pose, even if it then holds still\n if np.abs(Q - q0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(Q, \"VEC4\", 5126), interpolation=interp))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"rotation\")))\n if np.abs(T - t0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(T, \"VEC3\", 5126), interpolation=interp))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"translation\")))\n anims.append(dict(name=name, samplers=samplers, channels=channels))\n root = len(gnodes)\n gnodes.append(dict(name=\"character\", children=roots + mesh_nodes))\n gltf = dict(asset=dict(version=\"2.0\", generator=\"lowmarch export_skinned\"), scene=0, scenes=[dict(nodes=[root])],\n nodes=gnodes, meshes=meshes, materials=materials, skins=[skin], accessors=accessors, bufferViews=views,\n buffers=[dict(byteLength=len(bin_))], samplers=[dict(magFilter=9729, minFilter=9987)])\n if extras is not None:\n gltf[\"extras\"] = extras", "Target": " # a channel whenever the clip leaves the reference pose, even if it then holds still\n if np.abs(Q - q0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(Q, \"VEC4\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"rotation\")))\n if np.abs(T - t0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(T, \"VEC3\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"translation\")))\n anims.append(dict(name=name, samplers=samplers, channels=channels))\n root = len(gnodes)\n gnodes.append(dict(name=\"character\", children=roots + mesh_nodes))\n gltf = dict(asset=dict(version=\"2.0\", generator=\"lowmarch export_skinned\"), scene=0, scenes=[dict(nodes=[root])],\n nodes=gnodes, meshes=meshes, materials=materials, skins=[skin], accessors=accessors, bufferViews=views,\n buffers=[dict(byteLength=len(bin_))], samplers=[dict(magFilter=9729, minFilter=9987)])" }result, 1 line
Made 1 replacement in ~/work/lowmarch/tools/export_glb.py starting at line 547 (+5/-2 lines).
agent
+1:17:16reasoning
Initial assessment: updating review/slice/index.html. Focus is adding Flattice uniforms after the existing uniforms declaration. Each uniform needs to be validated for correct integration within the existing shader structure.
Uniform uLift suggests a potential displacement operation based on uFlattice, with a clamp to constrain the effect. The shader logic modifies the model-view matrix based on this uniform.
The fragment shader introduces linearized depth calculation within castShadow for perspective projection and includes two-sided lining with uHasLining. Per-vertex anime face shadow bias is implemented through a clamped lighting factor (fLit), and full-color painted anime iris logic is present.
The uKind = 8 uniform, used in the fragment shader for full-color iris rendering, was flagged due to a potential color space mismatch. Examination of the shader code revealed rawTex uses THREE.NoColorSpace while the renderer's output is THREE.LinearSRGBColorSpace, leading to a direct 1:1 match between texture values and the sRGB color space output, eliminating gamma correction concerns. Added a perspective uniform and linear depth calculation to the fragment shader to calculate depth within the texture coordinates.
Loading a .glb file directly from a URL parameter bypasses the need for a separate scene.json configuration, retrieving the scene's extras directly from the .glb data. The perspective lens and Flattice parameters can be applied using the URL query string, controlling camera behavior and model deformation. This approach streamlines model loading and parameter adjustment for testing and demonstration purposes.
The camera setup appears to implement a perspective projection based on the URL's lens parameter, adjusting position and projection matrix directly. The flattice parameter likely deforms the geometry based on the uFlattice uniform within the shader. This configuration allows for real-time control of the camera and Flattice effects.
The goal is to calculate the chin's world Y position for each character within the animation. Observing that all characters possess J_Bip_C_Head and J_Bip_C_Neck bones, the chin's posed world Y can be derived. This is achievable by iterating and finding the lowest Y vertex of the Face_00_SKIN mesh after applying bone matrices. This approach provides an exact world-space chin position irrespective of the animation clip currently playing.
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"const params = new URLSearchParams(location.search);\nconst SHOT = params.has(\"shot\");\nconst DIRECT_GLB = params.get(\"glb\");\nconst SCENE = DIRECT_GLB ? { camera: { target: [0, 1.46, 0], height: 0.62, pitch: 5 }, characters: [] }\n : await (await fetch(\"scene.json\")).json();","Target":"const params = new URLSearchParams(location.search);\nconst SHOT = params.has(\"shot\");\nconst SCENE = await (await fetch(\"scene.json\")).json();"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "const params = new URLSearchParams(location.search);\nconst SHOT = params.has(\"shot\");\nconst DIRECT_GLB = params.get(\"glb\");\nconst SCENE = DIRECT_GLB ? { camera: { target: [0, 1.46, 0], height: 0.62, pitch: 5 }, characters: [] }\n : await (await fetch(\"scene.json\")).json();", "Target": "const params = new URLSearchParams(location.search);\nconst SHOT = params.has(\"shot\");\nconst SCENE = await (await fetch(\"scene.json\")).json();" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 29 (+3/-1 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"const PAINT_VS = `${SKIN_HEAD}\n attribute float edge; attribute vec4 _plate; uniform float uLift;\n uniform float uFlattice; uniform float uFlChin; uniform float uFlFall; uniform vec3 uFlPivot;\n varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;\n varying float vEdge; varying vec4 vPlate;\n void main() {\n ${SKIN_BODY}\n vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;\n vec4 wp = modelMatrix * vec4(transformed, 1.0);\n vWPos = wp.xyz;\n vec4 mv = modelViewMatrix * vec4(transformed, 1.0);\n if (uFlattice > 0.0) {\n float w = clamp((wp.y - (uFlChin - uFlFall)) / uFlFall, 0.0, 1.0);\n vec3 u = normalize(-uFlPivot);\n mv.xyz -= u * dot(mv.xyz - uFlPivot, u) * w * uFlattice;\n }\n vView = -mv.xyz;\n mv.z += uLift;\n gl_Position = projectionMatrix * mv;\n }`;","Target":"const PAINT_VS = `${SKIN_HEAD}\n attribute float edge; attribute vec4 _plate; uniform float uLift;\n varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;\n varying float vEdge; varying vec4 vPlate;\n void main() {\n ${SKIN_BODY}\n vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;\n vec4 wp = modelMatrix * vec4(transformed, 1.0);\n vWPos = wp.xyz;\n vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz;\n mv.z += uLift;\n gl_Position = projectionMatrix * mv;\n }`;"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "const PAINT_VS = `${SKIN_HEAD}\n attribute float edge; attribute vec4 _plate; uniform float uLift;\n uniform float uFlattice; uniform float uFlChin; uniform float uFlFall; uniform vec3 uFlPivot;\n varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;\n varying float vEdge; varying vec4 vPlate;\n void main() {\n ${SKIN_BODY}\n vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;\n vec4 wp = modelMatrix * vec4(transformed, 1.0);\n vWPos = wp.xyz;\n vec4 mv = modelViewMatrix * vec4(transformed, 1.0);\n if (uFlattice > 0.0) {\n float w = clamp((wp.y - (uFlChin - uFlFall)) / uFlFall, 0.0, 1.0);\n vec3 u = normalize(-uFlPivot);\n mv.xyz -= u * dot(mv.xyz - uFlPivot, u) * w * uFlattice;\n }\n vView = -mv.xyz;\n mv.z += uLift;\n gl_Position = projectionMatrix * mv;\n }`;", "Target": "const PAINT_VS = `${SKIN_HEAD}\n attribute float edge; attribute vec4 _plate; uniform float uLift;\n varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;\n varying float vEdge; varying vec4 vPlate;\n void main() {\n ${SKIN_BODY}\n vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;\n vec4 wp = modelMatrix * vec4(transformed, 1.0);\n vWPos = wp.xyz;\n vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz;\n mv.z += uLift;\n gl_Position = projectionMatrix * mv;\n }`;" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 62 (+8/-1 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":" uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC;\n uniform int uHasLining; uniform vec3 uLining;\n uniform float uCrownY;\n uniform vec2 uFootA; uniform vec2 uFootB; uniform vec2 uFootC; uniform vec2 uFootD;\n uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn;\n uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm; uniform float uCastPersp;\n\n float linCastZ(float d) {\n return uCastPersp > 0.5 ? uCastNear * uCastFar / (uCastFar - d * (uCastFar - uCastNear))\n : uCastNear + d * (uCastFar - uCastNear);\n }\n\n float castShadow(int selfRole) {\n vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes;\n float z0 = linCastZ(texture2D(tCastDepth, uv).x);\n float sxy = length(uKey.xy);\n if (sxy < 0.05) return 0.0;\n vec2 dir = uKey.xy / sxy;\n float lz = uKey.z / sxy;\n int steps = selfRole == 1 ? 8 : 15;\n float stepM = selfRole == 1 ? 0.0026 : 0.0032;\n for (int s = 1; s <= 15; s++) {\n if (s > steps) break;\n float dm = float(s) * stepM;\n vec2 q = uv + dir * dm * uCastPpm * px;\n vec4 ni = texture2D(tCastInfo, q);\n if (ni.a < 0.5) continue;\n int r = int(ni.r * 255.0 + 0.5);\n if (selfRole == 1) {\n if (r != 3 && r != 11 && r != 12) continue;\n } else {\n if (r != 1 && r != 3 && r != 11 && r != 12) continue;\n }\n float zq = linCastZ(texture2D(tCastDepth, q).x);\n float zr = z0 - lz * dm;\n if (zq < zr - 0.004 && zq > zr - 0.22) return 1.0;\n }\n return 0.0;\n }","Target":" uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC;\n uniform float uCrownY;\n uniform vec2 uFootA; uniform vec2 uFootB; uniform vec2 uFootC; uniform vec2 uFootD;\n uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn;\n uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm;\n\n float castShadow(int selfRole) {\n vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes;\n float z0 = uCastNear + texture2D(tCastDepth, uv).x * (uCastFar - uCastNear);\n float sxy = length(uKey.xy);\n if (sxy < 0.05) return 0.0;\n vec2 dir = uKey.xy / sxy;\n float lz = uKey.z / sxy;\n int steps = selfRole == 1 ? 8 : 15;\n float stepM = selfRole == 1 ? 0.0026 : 0.0032;\n for (int s = 1; s <= 15; s++) {\n if (s > steps) break;\n float dm = float(s) * stepM;\n vec2 q = uv + dir * dm * uCastPpm * px;\n vec4 ni = texture2D(tCastInfo, q);\n if (ni.a < 0.5) continue;\n int r = int(ni.r * 255.0 + 0.5);\n if (selfRole == 1) {\n if (r != 3 && r != 11 && r != 12) continue;\n } else {\n if (r != 1 && r != 3 && r != 11 && r != 12) continue;\n }\n float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear);\n float zr = z0 - lz * dm;\n if (zq < zr - 0.004 && zq > zr - 0.22) return 1.0;\n }\n return 0.0;\n }"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": " uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC;\n uniform int uHasLining; uniform vec3 uLining;\n uniform float uCrownY;\n uniform vec2 uFootA; uniform vec2 uFootB; uniform vec2 uFootC; uniform vec2 uFootD;\n uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn;\n uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm; uniform float uCastPersp;\n\n float linCastZ(float d) {\n return uCastPersp > 0.5 ? uCastNear * uCastFar / (uCastFar - d * (uCastFar - uCastNear))\n : uCastNear + d * (uCastFar - uCastNear);\n }\n\n float castShadow(int selfRole) {\n vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes;\n float z0 = linCastZ(texture2D(tCastDepth, uv).x);\n float sxy = length(uKey.xy);\n if (sxy < 0.05) return 0.0;\n vec2 dir = uKey.xy / sxy;\n float lz = uKey.z / sxy;\n int steps = selfRole == 1 ? 8 : 15;\n float stepM = selfRole == 1 ? 0.0026 : 0.0032;\n for (int s = 1; s <= 15; s++) {\n if (s > steps) break;\n float dm = float(s) * stepM;\n vec2 q = uv + dir * dm * uCastPpm * px;\n vec4 ni = texture2D(tCastInfo, q);\n if (ni.a < 0.5) continue;\n int r = int(ni.r * 255.0 + 0.5);\n if (selfRole == 1) {\n if (r != 3 && r != 11 && r != 12) continue;\n } else {\n if (r != 1 && r != 3 && r != 11 && r != 12) continue;\n }\n float zq = linCastZ(texture2D(tCastDepth, q).x);\n float zr = z0 - lz * dm;\n if (zq < zr - 0.004 && zq > zr - 0.22) return 1.0;\n }\n return 0.0;\n }", "Target": " uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC;\n uniform float uCrownY;\n uniform vec2 uFootA; uniform vec2 uFootB; uniform vec2 uFootC; uniform vec2 uFootD;\n uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn;\n uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm;\n\n float castShadow(int selfRole) {\n vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes;\n float z0 = uCastNear + texture2D(tCastDepth, uv).x * (uCastFar - uCastNear);\n float sxy = length(uKey.xy);\n if (sxy < 0.05) return 0.0;\n vec2 dir = uKey.xy / sxy;\n float lz = uKey.z / sxy;\n int steps = selfRole == 1 ? 8 : 15;\n float stepM = selfRole == 1 ? 0.0026 : 0.0032;\n for (int s = 1; s <= 15; s++) {\n if (s > steps) break;\n float dm = float(s) * stepM;\n vec2 q = uv + dir * dm * uCastPpm * px;\n vec4 ni = texture2D(tCastInfo, q);\n if (ni.a < 0.5) continue;\n int r = int(ni.r * 255.0 + 0.5);\n if (selfRole == 1) {\n if (r != 3 && r != 11 && r != 12) continue;\n } else {\n if (r != 1 && r != 3 && r != 11 && r != 12) continue;\n }\n float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear);\n float zr = z0 - lz * dm;\n if (zq < zr - 0.004 && zq > zr - 0.22) return 1.0;\n }\n return 0.0;\n }" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 102 (+9/-3 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":" if (uKind == 0 || uKind == 5 || uKind == 6) {\n vec3 baseC = (back && uHasLining == 1) ? uLining : uBase;\n vec3 hb = rgb2hsv(baseC);\n bool cool = hb.x > 0.42 && hb.x < 0.86;\n float sh = uKind == 5 ? 0.93 : (cool ? 0.68 : 0.96);\n float li = cool ? 0.55 : 0.12;\n vec3 c0 = tone(baseC, sh, 0.08, 1.12, 0.42), c1 = tone(baseC, sh, 0.05, 1.08, 0.66);\n vec3 c3 = tone(baseC, li, 0.03, 0.82, 1.18);\n float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.20 : 0.0);\n if (uKind == 6) {\n // Contact shadow on ground beneath planted feet\n vec2 xz = vWPos.xz;\n float da = length((xz - uFootA) * vec2(1.0, 1.35));\n float db = length((xz - uFootB) * vec2(1.0, 1.35));\n float dc = length((xz - uFootC) * vec2(1.0, 1.35));\n float dd = length((xz - uFootD) * vec2(1.0, 1.35));\n float dmin = min(min(da, db), min(dc, dd));\n float contact = 1.0 - smoothstep(0.08, 0.30, dmin);\n l -= 0.36 * contact;\n }\n col = mix(c0, c1, st(l, 0.32)); col = mix(col, baseC, st(l, 0.50)); col = mix(col, c3, st(l, 0.90));\n if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);\n } else if (uKind == 1) {\n // Skin: genuine 3/4 shadow plane + authored per-vertex anime face shadow bias (vPlate.x > 1.5)\n vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);\n if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }\n float fLit = vPlate.x > 1.5 ? clamp(lit + vPlate.y, 0.0, 1.0) : lit;\n col = mix(sC, sS, st(fLit, 0.24)); col = mix(col, sL, st(fLit, 0.50));","Target":" if (uKind == 0 || uKind == 5 || uKind == 6) {\n vec3 hb = rgb2hsv(uBase);\n bool cool = hb.x > 0.42 && hb.x < 0.86;\n float sh = uKind == 5 ? 0.93 : (cool ? 0.68 : 0.96);\n float li = cool ? 0.55 : 0.12;\n vec3 c0 = tone(uBase, sh, 0.08, 1.12, 0.42), c1 = tone(uBase, sh, 0.05, 1.08, 0.66);\n vec3 c3 = tone(uBase, li, 0.03, 0.82, 1.18);\n float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.20 : 0.0);\n if (uKind == 6) {\n // Contact shadow on ground beneath planted feet\n vec2 xz = vWPos.xz;\n float da = length((xz - uFootA) * vec2(1.0, 1.35));\n float db = length((xz - uFootB) * vec2(1.0, 1.35));\n float dc = length((xz - uFootC) * vec2(1.0, 1.35));\n float dd = length((xz - uFootD) * vec2(1.0, 1.35));\n float dmin = min(min(da, db), min(dc, dd));\n float contact = 1.0 - smoothstep(0.08, 0.30, dmin);\n l -= 0.36 * contact;\n }\n col = mix(c0, c1, st(l, 0.32)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.90));\n if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);\n } else if (uKind == 1) {\n // Skin: genuine 3/4 shadow plane (threshold 0.50 instead of 0.38) + warm hue-shifted ramp\n vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);\n if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }\n col = mix(sC, sS, st(lit, 0.24)); col = mix(col, sL, st(lit, 0.50));"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": " if (uKind == 0 || uKind == 5 || uKind == 6) {\n vec3 baseC = (back && uHasLining == 1) ? uLining : uBase;\n vec3 hb = rgb2hsv(baseC);\n bool cool = hb.x > 0.42 && hb.x < 0.86;\n float sh = uKind == 5 ? 0.93 : (cool ? 0.68 : 0.96);\n float li = cool ? 0.55 : 0.12;\n vec3 c0 = tone(baseC, sh, 0.08, 1.12, 0.42), c1 = tone(baseC, sh, 0.05, 1.08, 0.66);\n vec3 c3 = tone(baseC, li, 0.03, 0.82, 1.18);\n float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.20 : 0.0);\n if (uKind == 6) {\n // Contact shadow on ground beneath planted feet\n vec2 xz = vWPos.xz;\n float da = length((xz - uFootA) * vec2(1.0, 1.35));\n float db = length((xz - uFootB) * vec2(1.0, 1.35));\n float dc = length((xz - uFootC) * vec2(1.0, 1.35));\n float dd = length((xz - uFootD) * vec2(1.0, 1.35));\n float dmin = min(min(da, db), min(dc, dd));\n float contact = 1.0 - smoothstep(0.08, 0.30, dmin);\n l -= 0.36 * contact;\n }\n col = mix(c0, c1, st(l, 0.32)); col = mix(col, baseC, st(l, 0.50)); col = mix(col, c3, st(l, 0.90));\n if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);\n } else if (uKind == 1) {\n // Skin: genuine 3/4 shadow plane + authored per-vertex anime face shadow bias (vPlate.x > 1.5)\n vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);\n if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }\n float fLit = vPlate.x > 1.5 ? clamp(lit + vPlate.y, 0.0, 1.0) : lit;\n col = mix(sC, sS, st(fLit, 0.24)); col = mix(col, sL, st(fLit, 0.50));", "Target": " if (uKind == 0 || uKind == 5 || uKind == 6) {\n vec3 hb = rgb2hsv(uBase);\n bool cool = hb.x > 0.42 && hb.x < 0.86;\n float sh = uKind == 5 ? 0.93 : (cool ? 0.68 : 0.96);\n float li = cool ? 0.55 : 0.12;\n vec3 c0 = tone(uBase, sh, 0.08, 1.12, 0.42), c1 = tone(uBase, sh, 0.05, 1.08, 0.66);\n vec3 c3 = tone(uBase, li, 0.03, 0.82, 1.18);\n float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.20 : 0.0);\n if (uKind == 6) {\n // Contact shadow on ground beneath planted feet\n vec2 xz = vWPos.xz;\n float da = length((xz - uFootA) * vec2(1.0, 1.35));\n float db = length((xz - uFootB) * vec2(1.0, 1.35));\n float dc = length((xz - uFootC) * vec2(1.0, 1.35));\n float dd = length((xz - uFootD) * vec2(1.0, 1.35));\n float dmin = min(min(da, db), min(dc, dd));\n float contact = 1.0 - smoothstep(0.08, 0.30, dmin);\n l -= 0.36 * contact;\n }\n col = mix(c0, c1, st(l, 0.32)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.90));\n if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);\n } else if (uKind == 1) {\n // Skin: genuine 3/4 shadow plane (threshold 0.50 instead of 0.38) + warm hue-shifted ramp\n vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);\n if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }\n col = mix(sC, sS, st(lit, 0.24)); col = mix(col, sL, st(lit, 0.50));" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 205 (+8/-6 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":" if (vPlate.x > 0.5 && vPlate.x < 1.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {","Target":" if (vPlate.x > 0.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": " if (vPlate.x > 0.5 && vPlate.x < 1.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {", "Target": " if (vPlate.x > 0.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 285 (+1/-1 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"const PAINT_COMP = `\n uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;\n uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;\n uniform float uPersp;\n ${HSV}\n float z(vec2 p) {\n float d = texture2D(tDepth, p).x;\n return uPersp > 0.5 ? uNear * uFar / (uFar - d * (uFar - uNear)) : uNear + d * (uFar - uNear);\n }","Target":"const PAINT_COMP = `\n uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;\n uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;\n ${HSV}\n float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); }"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "const PAINT_COMP = `\n uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;\n uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;\n uniform float uPersp;\n ${HSV}\n float z(vec2 p) {\n float d = texture2D(tDepth, p).x;\n return uPersp > 0.5 ? uNear * uFar / (uFar - d * (uFar - uNear)) : uNear + d * (uFar - uNear);\n }", "Target": "const PAINT_COMP = `\n uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;\n uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;\n ${HSV}\n float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); }" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 316 (+6/-2 lines).
agent
+1:18:30reasoning
I'm thinking through how to approach this.
read_file{"EndLine":735,"Path":"~/work/lowmarch/review/slice/index.html","StartLine":505}
input
{ "EndLine": 735, "Path": "~/work/lowmarch/review/slice/index.html", "StartLine": 505 }result, 227 lines
Showing lines 505-730 of 730 505: this.display.geometry.computeVertexNormals(); 506: } 507: } 508: 509: const KEY = new THREE.Vector3(...(SCENE.key || [-0.62, 0.48, 0.62])).normalize(); 510: const GRADE = SCENE.grade || { ambient: [0.86, 0.88, 0.96], key: [1.04, 1.00, 0.94], rim: [0.28, 0.25, 0.20] }; 511: const KIND = { cloth: 0, skin: 1, hair: 2, steel: 3, gold: 4, leather: 5, world: 6 }; 512: 513: function paintMaterial(V, role, map, index, infoRole = role, decal = false, crownY = 1.65) { 514: const Rl = V.roles[role] || { mode: "flat", color: "#ff00ff" }, P = (V.paint || {})[role]; 515: const u = { 516: uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() }, 517: uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 }, 518: uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) }, 519: uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() }, 520: uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) }, 521: uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || "#c49a45") }, 522: uAmbient: { value: new THREE.Vector3(...GRADE.ambient) }, 523: uKeyCol: { value: new THREE.Vector3(...GRADE.key) }, 524: uRimCol: { value: new THREE.Vector3(...GRADE.rim) }, 525: uGrain: { value: 0.04 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null }, 526: uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 }, 527: uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() }, 528: uCrownY: { value: crownY }, 529: uFootA: { value: new THREE.Vector2(99, 99) }, uFootB: { value: new THREE.Vector2(99, 99) }, 530: uFootC: { value: new THREE.Vector2(99, 99) }, uFootD: { value: new THREE.Vector2(99, 99) }, 531: tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 }, 532: uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 }, 533: uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || "#e8e3d5") }, uLift: { value: 0 } 534: }; 535: if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; } 536: else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); } 537: if (P && P.kind === "world") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.11; } 538: if (P && P.shade) u.uShadeOnly.value = 1; 539: if (P && P.kind === "skin" && P.ramp) { 540: u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]); 541: } 542: if (P && P.kind === "skin" && P.base) { 543: const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835); 544: } 545: if (role === "face" && map) u.uFaceTex.value = 1; 546: if ((role === "hair" || role === "hair_cap") && map) u.uAlpha.value = 1; 547: if (role === "iris") { u.uKind.value = 7; u.uAlpha.value = 1; } 548: else if (role === "white" || role === "highlight") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || "#ffffff"); } 549: else if (!P && Rl.mode === "flat") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === "line" ? 2 : 1; } 550: if (role === "mouth" && map) u.uKind.value = 10; 551: u.uBand.value = u.uGold.value.clone(); 552: const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide, 553: extensions: { derivatives: true } }); 554: m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] }; 555: return m; 556: } 557: 558: const loader = new GLTFLoader(); 559: async function parseGlb(file) { 560: const j = await (await fetch(file)).json(); 561: const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0)); 562: return await new Promise((ok, bad) => loader.parse(bin.buffer, "", ok, bad)); 563: } 564: 565: let meshIndex = 1; 566: const allMeshes = []; 567: const allCloths = []; 568: const characters = []; 569: 570: for (let ci = 0; ci < SCENE.characters.length; ci++) { 571: const def = SCENE.characters[ci], V = def.info; 572: const gltf = await parseGlb(`${def.name}.glb.json`); 573: const turn = new THREE.Group(); 574: turn.add(gltf.scene); 575: turn.position.set(...def.place.pos); 576: turn.rotation.y = THREE.MathUtils.degToRad(def.place.yaw); 577: scene.add(turn); 578: 579: const meshes = []; 580: gltf.scene.traverse(o => { 581: if (!o.isMesh) return; 582: const m0 = o.material, role = o.userData.role || "body", raw = rawTex(m0.map); 583: const matName = o.userData.material || ""; 584: const isInnerHair = role === "hair_cap" || matName.includes("HairBack"); 585: const infoRole = isInnerHair ? "hair_cap" : (role === "hair" && ci > 0 ? "hair_b" : role === "shadow" ? "body" : role); 586: const decal = !!(m0.userData && m0.userData.decal); 587: const mat = paintMaterial(V, role, raw, meshIndex++, infoRole, decal, def.crown_y || 1.68); 588: if (isInnerHair) mat.uniforms.uShadeOnly.value = 1; 589: o.material = mat; 590: o.frustumCulled = false; 591: meshes.push(o); 592: allMeshes.push(o); 593: }); 594: 595: const mixer = new THREE.AnimationMixer(gltf.scene); 596: const actions = Object.fromEntries(gltf.animations.map(c => [c.name, mixer.clipAction(c)])); 597: const clipName = def.clip || "idle"; 598: if (actions[clipName]) { 599: actions[clipName].reset(); 600: actions[clipName].setEffectiveWeight(1); 601: actions[clipName].play(); 602: actions[clipName].time = def.clip_t || 0; 603: mixer.update(0); 604: } 605: scene.updateMatrixWorld(true); 606: 607: // Measure live crown height for the halo band after posing 608: const headBone = gltf.scene.getObjectByName("J_Bip_C_Head"); 609: if (headBone) { 610: const hp = headBone.getWorldPosition(new THREE.Vector3()); 611: const cy = hp.y + 0.145; 612: meshes.forEach(m => { m.material.uniforms.uCrownY.value = cy; }); 613: } 614: 615: const bone = n => gltf.scene.getObjectByName(n); 616: const world = new THREE.Group(); 617: scene.add(world); 618: for (const [cname, info] of Object.entries(V.cloth || {})) { 619: const skinned = meshes.find(m => m.userData.material === cname); 620: if (!skinned) continue; 621: const trims = meshes.filter(m => info.trims.includes(m.userData.material)); 622: const caps = V.capsules.filter(c => !info.collide || info.collide.some(k => c.bones[0].includes(k))); 623: const cl = new Cloth(skinned, info.u, info.v, trims, caps, bone, info.closed, info.edges === "hem"); 624: const PB = (V.paint || {})[info.band || "gold"]; 625: if (PB && PB.base) cl.display.material.uniforms.uBand.value = hex(PB.base); 626: skinned.visible = false; 627: trims.forEach(t => { t.visible = false; }); 628: world.add(cl.display); 629: allMeshes.push(cl.display); 630: allCloths.push({ cl, wind: def.wind || 0 }); 631: } 632: characters.push({ def, root: gltf.scene, meshes }); 633: } 634: 635: // Settle cloth drapes cleanly 636: allCloths.forEach(({ cl }) => cl.reset()); 637: for (let s = 0; s < 160; s++) allCloths.forEach(({ cl, wind }) => cl.step(1 / 120, wind)); 638: allCloths.forEach(({ cl }) => cl.write()); 639: 640: // Load terrain and pass planted foot positions for contact shadows 641: const groundGltf = await parseGlb("plains.glb.json"); 642: scene.add(groundGltf.scene); 643: const footPts = []; 644: for (const c of characters) { 645: for (const fn of ["J_Bip_L_Foot", "J_Bip_R_Foot"]) { 646: const b = c.root.getObjectByName(fn); 647: if (b) { const p = b.getWorldPosition(new THREE.Vector3()); footPts.push(new THREE.Vector2(p.x, p.z)); } 648: } 649: } 650: while (footPts.length < 4) footPts.push(new THREE.Vector2(99, 99)); 651: 652: const V0 = SCENE.characters[0].info; 653: groundGltf.scene.traverse(o => { 654: if (!o.isMesh) return; 655: const role = o.userData.role || "grass"; 656: const mat = paintMaterial(V0, role, rawTex(o.material.map), meshIndex++, role, false); 657: mat.uniforms.uFootA.value.copy(footPts[0]); 658: mat.uniforms.uFootB.value.copy(footPts[1]); 659: mat.uniforms.uFootC.value.copy(footPts[2]); 660: mat.uniforms.uFootD.value.copy(footPts[3]); 661: o.material = mat; 662: o.frustumCulled = false; 663: allMeshes.push(o); 664: }); 665: 666: function setupCamera(aspect) { 667: const C = SCENE.camera; 668: const centre = new THREE.Vector3(...C.target); 669: const h = C.height, w = h * aspect; 670: camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2; 671: camera.zoom = 1; 672: camera.updateProjectionMatrix(); 673: const a = THREE.MathUtils.degToRad(C.pitch); 674: camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(16)); 675: camera.up.set(0, 1, 0); 676: camera.lookAt(centre); 677: } 678: 679: function renderFrame(w, h, ss = 1) { 680: const bw = w * ss, bh = h * ss; 681: R.setPixelRatio(1); 682: R.setSize(bw, bh, false); 683: setupCamera(w / h); 684: targetsFor(bw, bh); 685: 686: const visible = allMeshes.filter(o => o.visible); 687: visible.forEach(o => { 688: const mu = o.material.uniforms; 689: mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null; 690: }); 691: R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera); 692: 693: const ppmBuf = bh / (camera.top - camera.bottom); 694: visible.forEach(o => { 695: const mu = o.material.uniforms; 696: mu.uPass.value = 0; mu.uCastOn.value = 1; 697: mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture; 698: mu.uCastRes.value.set(bw, bh); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far; mu.uCastPpm.value = ppmBuf; 699: }); 700: R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera); 701: 702: const u = paint.mat.uniforms; 703: u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture; 704: u.uRes.value.set(bw, bh); u.uNear.value = camera.near; u.uFar.value = camera.far; 705: u.uGap.value = 0.012; 706: u.uSil.value = THREE.MathUtils.clamp(1.75 * ppmBuf * 0.0040, ss, 2.5 * ss); 707: u.uInner.value = Math.max(ss * 0.78, u.uSil.value * 0.56); 708: u.uPpm.value = ppmBuf; 709: R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam); 710: } 711: 712: if (SHOT) { 713: const outW = +(params.get("w") || 1920), outH = +(params.get("h") || 1080), ss = +(params.get("ss") || 2); 714: renderFrame(outW, outH, ss); 715: const cv = document.createElement("canvas"); 716: cv.width = outW; cv.height = outH; 717: const ctx = cv.getContext("2d"); 718: ctx.imageSmoothingEnabled = true; 719: ctx.imageSmoothingQuality = "high"; 720: ctx.drawImage(R.domElement, 0, 0, outW, outH); 721: document.getElementById("sheetOut").textContent = cv.toDataURL("image/png"); 722: document.title = "slice ready"; 723: } else { 724: const fit = () => renderFrame(window.innerWidth, window.innerHeight, Math.min(2, window.devicePixelRatio || 1)); 725: window.addEventListener("resize", fit); 726: fit(); 727: } 728: </script> 729: </body> 730: </html>read_file{"EndLine":418,"Path":"~/work/lowmarch/review/slice/index.html","StartLine":400}
input
{ "EndLine": 418, "Path": "~/work/lowmarch/review/slice/index.html", "StartLine": 400 }result, 20 lines
Showing lines 400-418 of 730 400: vertexShader: `void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }`, 401: fragmentShader: fs, depthTest: false, depthWrite: false 402: }); 403: const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), mat); 404: const sc = new THREE.Scene(); sc.add(quad); 405: return { scene: sc, mat }; 406: } 407: const paint = compPass(PAINT_COMP, { 408: tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null }, 409: uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 }, 410: uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 } 411: }); 412: 413: const targets = { rt: null, rtInfo: null, key: "" }; 414: function targetsFor(w, h) { 415: const key = `${w}x${h}`; 416: if (targets.key === key) return; 417: [targets.rt, targets.rtInfo].forEach(t => t && t.dispose()); 418: const o = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter };
agent
+1:18:46reasoning
The ppmBuf variable on line 693 depends on the camera's height (h) and the lens value. In orthographic mode, ppmBuf calculates the ratio between the bottom of the camera and its height. However, when the lens has a value greater than zero, the code may be using camera.top inconsistently within makePerspective, leading to a potential error in ppmBuf calculation.
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"const paint = compPass(PAINT_COMP, {\n tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null },\n uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 }, uPersp: { value: 0 },\n uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 }\n});","Target":"const paint = compPass(PAINT_COMP, {\n tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null },\n uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 },\n uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 }\n});"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "const paint = compPass(PAINT_COMP, {\n tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null },\n uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 }, uPersp: { value: 0 },\n uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 }\n});", "Target": "const paint = compPass(PAINT_COMP, {\n tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null },\n uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 },\n uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 }\n});" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 407 (+1/-1 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"function paintMaterial(V, role, map, index, infoRole = role, decal = false, crownY = 1.65, fullColor = false) {\n const Rl = V.roles[role] || { mode: \"flat\", color: \"#ff00ff\" }, P = (V.paint || {})[role];\n const u = {\n uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },\n uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },\n uFlattice: { value: 0 }, uFlChin: { value: 0 }, uFlFall: { value: 0.05 }, uFlPivot: { value: new THREE.Vector3() },\n uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },\n uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() },\n uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },\n uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || \"#c49a45\") },\n uAmbient: { value: new THREE.Vector3(...GRADE.ambient) },\n uKeyCol: { value: new THREE.Vector3(...GRADE.key) },\n uRimCol: { value: new THREE.Vector3(...GRADE.rim) },\n uGrain: { value: 0.04 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },\n uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },\n uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },\n uHasLining: { value: 0 }, uLining: { value: new THREE.Color(0.55, 0.12, 0.18) },\n uCrownY: { value: crownY },\n uFootA: { value: new THREE.Vector2(99, 99) }, uFootB: { value: new THREE.Vector2(99, 99) },\n uFootC: { value: new THREE.Vector2(99, 99) }, uFootD: { value: new THREE.Vector2(99, 99) },\n tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },\n uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 }, uCastPersp: { value: 0 },\n uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || \"#e8e3d5\") }, uLift: { value: 0 }\n };\n if (P) {\n u.uKind.value = KIND[P.kind] ?? 0;\n if (P.base) u.uBase.value = hex(P.base);\n if (P.grain != null) u.uGrain.value = P.grain;\n if (P.lining) { u.uHasLining.value = 1; u.uLining.value = hex(P.lining); }\n }\n else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }\n if (P && P.kind === \"world\") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.11; }\n if (P && P.shade) u.uShadeOnly.value = 1;\n if (P && P.kind === \"skin\" && P.ramp) {\n u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);\n }\n if (P && P.kind === \"skin\" && P.base) {\n const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);\n }\n if (role === \"face\" && map) u.uFaceTex.value = 1;\n if ((role === \"hair\" || role === \"hair_cap\") && map) u.uAlpha.value = 1;\n if (role === \"iris\") { u.uKind.value = fullColor ? 8 : 7; u.uAlpha.value = 1; }\n else if (role === \"white\" || role === \"highlight\") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || \"#ffffff\"); }\n else if (!P && Rl.mode === \"flat\") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === \"line\" ? 2 : 1; }\n if (role === \"mouth\" && map) u.uKind.value = 10;\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\nconst loader = new GLTFLoader();\nasync function parseGlb(file) {\n if (file.endsWith(\".glb\")) {\n const buf = await (await fetch(file)).arrayBuffer();\n return await new Promise((ok, bad) => loader.parse(buf, \"\", ok, bad));\n }\n const j = await (await fetch(file)).json();\n const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));\n return await new Promise((ok, bad) => loader.parse(bin.buffer, \"\", ok, bad));\n}\n\nlet meshIndex = 1;\nconst allMeshes = [];\nconst allCloths = [];\nconst characters = [];\n\nif (DIRECT_GLB) {\n const gltf = await parseGlb(DIRECT_GLB);\n const extInfo = (gltf.parser && gltf.parser.json && gltf.parser.json.extras) || {};\n SCENE.characters.push({\n name: DIRECT_GLB,\n directGltf: gltf,\n place: { pos: [0, 0, 0], yaw: +(params.get(\"yaw\") || 32) },\n clip: params.get(\"clip\") || \"battle_guard\",\n clip_t: +(params.get(\"t\") || 0),\n wind: +(params.get(\"wind\") || -2.8),\n info: extInfo\n });\n}\n\nfor (let ci = 0; ci < SCENE.characters.length; ci++) {\n const def = SCENE.characters[ci], V = def.info;\n const gltf = def.directGltf || await parseGlb(`${def.name}.glb.json`);\n const turn = new THREE.Group();\n turn.add(gltf.scene);\n turn.position.set(...def.place.pos);\n turn.rotation.y = THREE.MathUtils.degToRad(def.place.yaw);\n scene.add(turn);\n\n const meshes = [];\n gltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const m0 = o.material, role = o.userData.role || \"body\", raw = rawTex(m0.map);\n const matName = o.userData.material || \"\";\n const isInnerHair = role === \"hair_cap\" || matName.includes(\"HairBack\");\n const infoRole = isInnerHair ? \"hair_cap\" : (role === \"hair\" && ci > 0 ? \"hair_b\" : role === \"shadow\" ? \"body\" : role);\n const decal = !!(m0.userData && m0.userData.decal);\n const fullColor = !!(m0.userData && m0.userData.fullColor);\n const mat = paintMaterial(V, role, raw, meshIndex++, infoRole, decal, def.crown_y || 1.68, fullColor);\n if (isInnerHair) mat.uniforms.uShadeOnly.value = 1;\n o.material = mat;\n o.frustumCulled = false;\n meshes.push(o);\n allMeshes.push(o);\n });","Target":"function paintMaterial(V, role, map, index, infoRole = role, decal = false, crownY = 1.65) {\n const Rl = V.roles[role] || { mode: \"flat\", color: \"#ff00ff\" }, P = (V.paint || {})[role];\n const u = {\n uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },\n uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },\n uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },\n uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() },\n uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },\n uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || \"#c49a45\") },\n uAmbient: { value: new THREE.Vector3(...GRADE.ambient) },\n uKeyCol: { value: new THREE.Vector3(...GRADE.key) },\n uRimCol: { value: new THREE.Vector3(...GRADE.rim) },\n uGrain: { value: 0.04 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },\n uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },\n uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },\n uCrownY: { value: crownY },\n uFootA: { value: new THREE.Vector2(99, 99) }, uFootB: { value: new THREE.Vector2(99, 99) },\n uFootC: { value: new THREE.Vector2(99, 99) }, uFootD: { value: new THREE.Vector2(99, 99) },\n tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },\n uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 },\n uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || \"#e8e3d5\") }, uLift: { value: 0 }\n };\n if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; }\n else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }\n if (P && P.kind === \"world\") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.11; }\n if (P && P.shade) u.uShadeOnly.value = 1;\n if (P && P.kind === \"skin\" && P.ramp) {\n u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);\n }\n if (P && P.kind === \"skin\" && P.base) {\n const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);\n }\n if (role === \"face\" && map) u.uFaceTex.value = 1;\n if ((role === \"hair\" || role === \"hair_cap\") && map) u.uAlpha.value = 1;\n if (role === \"iris\") { u.uKind.value = 7; u.uAlpha.value = 1; }\n else if (role === \"white\" || role === \"highlight\") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || \"#ffffff\"); }\n else if (!P && Rl.mode === \"flat\") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === \"line\" ? 2 : 1; }\n if (role === \"mouth\" && map) u.uKind.value = 10;\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\nconst loader = new GLTFLoader();\nasync function parseGlb(file) {\n const j = await (await fetch(file)).json();\n const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));\n return await new Promise((ok, bad) => loader.parse(bin.buffer, \"\", ok, bad));\n}\n\nlet meshIndex = 1;\nconst allMeshes = [];\nconst allCloths = [];\nconst characters = [];\n\nfor (let ci = 0; ci < SCENE.characters.length; ci++) {\n const def = SCENE.characters[ci], V = def.info;\n const gltf = await parseGlb(`${def.name}.glb.json`);\n const turn = new THREE.Group();\n turn.add(gltf.scene);\n turn.position.set(...def.place.pos);\n turn.rotation.y = THREE.MathUtils.degToRad(def.place.yaw);\n scene.add(turn);\n\n const meshes = [];\n gltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const m0 = o.material, role = o.userData.role || \"body\", raw = rawTex(m0.map);\n const matName = o.userData.material || \"\";\n const isInnerHair = role === \"hair_cap\" || matName.includes(\"HairBack\");\n const infoRole = isInnerHair ? \"hair_cap\" : (role === \"hair\" && ci > 0 ? \"hair_b\" : role === \"shadow\" ? \"body\" : role);\n const decal = !!(m0.userData && m0.userData.decal);\n const mat = paintMaterial(V, role, raw, meshIndex++, infoRole, decal, def.crown_y || 1.68);\n if (isInnerHair) mat.uniforms.uShadeOnly.value = 1;\n o.material = mat;\n o.frustumCulled = false;\n meshes.push(o);\n allMeshes.push(o);\n });"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "function paintMaterial(V, role, map, index, infoRole = role, decal = false, crownY = 1.65, fullColor = false) {\n const Rl = V.roles[role] || { mode: \"flat\", color: \"#ff00ff\" }, P = (V.paint || {})[role];\n const u = {\n uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },\n uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },\n uFlattice: { value: 0 }, uFlChin: { value: 0 }, uFlFall: { value: 0.05 }, uFlPivot: { value: new THREE.Vector3() },\n uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },\n uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() },\n uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },\n uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || \"#c49a45\") },\n uAmbient: { value: new THREE.Vector3(...GRADE.ambient) },\n uKeyCol: { value: new THREE.Vector3(...GRADE.key) },\n uRimCol: { value: new THREE.Vector3(...GRADE.rim) },\n uGrain: { value: 0.04 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },\n uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },\n uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },\n uHasLining: { value: 0 }, uLining: { value: new THREE.Color(0.55, 0.12, 0.18) },\n uCrownY: { value: crownY },\n uFootA: { value: new THREE.Vector2(99, 99) }, uFootB: { value: new THREE.Vector2(99, 99) },\n uFootC: { value: new THREE.Vector2(99, 99) }, uFootD: { value: new THREE.Vector2(99, 99) },\n tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },\n uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 }, uCastPersp: { value: 0 },\n uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || \"#e8e3d5\") }, uLift: { value: 0 }\n };\n if (P) {\n u.uKind.value = KIND[P.kind] ?? 0;\n if (P.base) u.uBase.value = hex(P.base);\n if (P.grain != null) u.uGrain.value = P.grain;\n if (P.lining) { u.uHasLining.value = 1; u.uLining.value = hex(P.lining); }\n }\n else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }\n if (P && P.kind === \"world\") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.11; }\n if (P && P.shade) u.uShadeOnly.value = 1;\n if (P && P.kind === \"skin\" && P.ramp) {\n u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);\n }\n if (P && P.kind === \"skin\" && P.base) {\n const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);\n }\n if (role === \"face\" && map) u.uFaceTex.value = 1;\n if ((role === \"hair\" || role === \"hair_cap\") && map) u.uAlpha.value = 1;\n if (role === \"iris\") { u.uKind.value = fullColor ? 8 : 7; u.uAlpha.value = 1; }\n else if (role === \"white\" || role === \"highlight\") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || \"#ffffff\"); }\n else if (!P && Rl.mode === \"flat\") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === \"line\" ? 2 : 1; }\n if (role === \"mouth\" && map) u.uKind.value = 10;\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\nconst loader = new GLTFLoader();\nasync function parseGlb(file) {\n if (file.endsWith(\".glb\")) {\n const buf = await (await fetch(file)).arrayBuffer();\n return await new Promise((ok, bad) => loader.parse(buf, \"\", ok, bad));\n }\n const j = await (await fetch(file)).json();\n const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));\n return await new Promise((ok, bad) => loader.parse(bin.buffer, \"\", ok, bad));\n}\n\nlet meshIndex = 1;\nconst allMeshes = [];\nconst allCloths = [];\nconst characters = [];\n\nif (DIRECT_GLB) {\n const gltf = await parseGlb(DIRECT_GLB);\n const extInfo = (gltf.parser && gltf.parser.json && gltf.parser.json.extras) || {};\n SCENE.characters.push({\n name: DIRECT_GLB,\n directGltf: gltf,\n place: { pos: [0, 0, 0], yaw: +(params.get(\"yaw\") || 32) },\n clip: params.get(\"clip\") || \"battle_guard\",\n clip_t: +(params.get(\"t\") || 0),\n wind: +(params.get(\"wind\") || -2.8),\n info: extInfo\n });\n}\n\nfor (let ci = 0; ci < SCENE.characters.length; ci++) {\n const def = SCENE.characters[ci], V = def.info;\n const gltf = def.directGltf || await parseGlb(`${def.name}.glb.json`);\n const turn = new THREE.Group();\n turn.add(gltf.scene);\n turn.position.set(...def.place.pos);\n turn.rotation.y = THREE.MathUtils.degToRad(def.place.yaw);\n scene.add(turn);\n\n const meshes = [];\n gltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const m0 = o.material, role = o.userData.role || \"body\", raw = rawTex(m0.map);\n const matName = o.userData.material || \"\";\n const isInnerHair = role === \"hair_cap\" || matName.includes(\"HairBack\");\n const infoRole = isInnerHair ? \"hair_cap\" : (role === \"hair\" && ci > 0 ? \"hair_b\" : role === \"shadow\" ? \"body\" : role);\n const decal = !!(m0.userData && m0.userData.decal);\n const fullColor = !!(m0.userData && m0.userData.fullColor);\n const mat = paintMaterial(V, role, raw, meshIndex++, infoRole, decal, def.crown_y || 1.68, fullColor);\n if (isInnerHair) mat.uniforms.uShadeOnly.value = 1;\n o.material = mat;\n o.frustumCulled = false;\n meshes.push(o);\n allMeshes.push(o);\n });", "Target": "function paintMaterial(V, role, map, index, infoRole = role, decal = false, crownY = 1.65) {\n const Rl = V.roles[role] || { mode: \"flat\", color: \"#ff00ff\" }, P = (V.paint || {})[role];\n const u = {\n uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },\n uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },\n uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },\n uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() },\n uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },\n uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || \"#c49a45\") },\n uAmbient: { value: new THREE.Vector3(...GRADE.ambient) },\n uKeyCol: { value: new THREE.Vector3(...GRADE.key) },\n uRimCol: { value: new THREE.Vector3(...GRADE.rim) },\n uGrain: { value: 0.04 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },\n uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },\n uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },\n uCrownY: { value: crownY },\n uFootA: { value: new THREE.Vector2(99, 99) }, uFootB: { value: new THREE.Vector2(99, 99) },\n uFootC: { value: new THREE.Vector2(99, 99) }, uFootD: { value: new THREE.Vector2(99, 99) },\n tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },\n uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 },\n uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || \"#e8e3d5\") }, uLift: { value: 0 }\n };\n if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; }\n else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }\n if (P && P.kind === \"world\") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.11; }\n if (P && P.shade) u.uShadeOnly.value = 1;\n if (P && P.kind === \"skin\" && P.ramp) {\n u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);\n }\n if (P && P.kind === \"skin\" && P.base) {\n const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);\n }\n if (role === \"face\" && map) u.uFaceTex.value = 1;\n if ((role === \"hair\" || role === \"hair_cap\") && map) u.uAlpha.value = 1;\n if (role === \"iris\") { u.uKind.value = 7; u.uAlpha.value = 1; }\n else if (role === \"white\" || role === \"highlight\") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || \"#ffffff\"); }\n else if (!P && Rl.mode === \"flat\") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === \"line\" ? 2 : 1; }\n if (role === \"mouth\" && map) u.uKind.value = 10;\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\nconst loader = new GLTFLoader();\nasync function parseGlb(file) {\n const j = await (await fetch(file)).json();\n const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));\n return await new Promise((ok, bad) => loader.parse(bin.buffer, \"\", ok, bad));\n}\n\nlet meshIndex = 1;\nconst allMeshes = [];\nconst allCloths = [];\nconst characters = [];\n\nfor (let ci = 0; ci < SCENE.characters.length; ci++) {\n const def = SCENE.characters[ci], V = def.info;\n const gltf = await parseGlb(`${def.name}.glb.json`);\n const turn = new THREE.Group();\n turn.add(gltf.scene);\n turn.position.set(...def.place.pos);\n turn.rotation.y = THREE.MathUtils.degToRad(def.place.yaw);\n scene.add(turn);\n\n const meshes = [];\n gltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const m0 = o.material, role = o.userData.role || \"body\", raw = rawTex(m0.map);\n const matName = o.userData.material || \"\";\n const isInnerHair = role === \"hair_cap\" || matName.includes(\"HairBack\");\n const infoRole = isInnerHair ? \"hair_cap\" : (role === \"hair\" && ci > 0 ? \"hair_b\" : role === \"shadow\" ? \"body\" : role);\n const decal = !!(m0.userData && m0.userData.decal);\n const mat = paintMaterial(V, role, raw, meshIndex++, infoRole, decal, def.crown_y || 1.68);\n if (isInnerHair) mat.uniforms.uShadeOnly.value = 1;\n o.material = mat;\n o.frustumCulled = false;\n meshes.push(o);\n allMeshes.push(o);\n });" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 513 (+32/-6 lines).
edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":"// Load terrain when not in standalone single-GLB camera showcase mode\nif (!DIRECT_GLB) {\n const groundGltf = await parseGlb(\"plains.glb.json\");\n scene.add(groundGltf.scene);\n const footPts = [];\n for (const c of characters) {\n for (const fn of [\"J_Bip_L_Foot\", \"J_Bip_R_Foot\"]) {\n const b = c.root.getObjectByName(fn);\n if (b) { const p = b.getWorldPosition(new THREE.Vector3()); footPts.push(new THREE.Vector2(p.x, p.z)); }\n }\n }\n while (footPts.length < 4) footPts.push(new THREE.Vector2(99, 99));\n\n const V0 = SCENE.characters[0].info;\n groundGltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const role = o.userData.role || \"grass\";\n const mat = paintMaterial(V0, role, rawTex(o.material.map), meshIndex++, role, false);\n mat.uniforms.uFootA.value.copy(footPts[0]);\n mat.uniforms.uFootB.value.copy(footPts[1]);\n mat.uniforms.uFootC.value.copy(footPts[2]);\n mat.uniforms.uFootD.value.copy(footPts[3]);\n o.material = mat;\n o.frustumCulled = false;\n allMeshes.push(o);\n });\n}\n\nfunction setupCamera(aspect) {\n const C = SCENE.camera;\n const tParam = params.get(\"target\");\n const centre = tParam ? new THREE.Vector3(...tParam.split(\",\").map(Number)) : new THREE.Vector3(...C.target);\n const h = +(params.get(\"height\") || C.height), w = h * aspect;\n const pitch = +(params.get(\"pitch\") ?? C.pitch);\n const lens = +(params.get(\"lens\") || C.lens || 0);\n const flat = +(params.get(\"flat\") ?? C.flat ?? 0);\n\n camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2;\n camera.zoom = 1;\n camera.near = 0.1; camera.far = 40;\n camera.updateProjectionMatrix();\n const a = THREE.MathUtils.degToRad(pitch);\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(16));\n camera.up.set(0, 1, 0);\n camera.lookAt(centre);\n camera.updateMatrixWorld(true);\n\n const pu = paint.mat.uniforms;\n pu.uPersp.value = 0;\n if (lens > 0) {\n const d = w * lens / 36, n = 0.05, f = 40;\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(d));\n camera.lookAt(centre);\n camera.updateMatrixWorld(true);\n camera.near = n; camera.far = f;\n camera.projectionMatrix.makePerspective(-w / 2 * n / d, w / 2 * n / d, h / 2 * n / d, -h / 2 * n / d, n, f);\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n pu.uPersp.value = 1;\n }\n\n for (const chr of characters) {\n const headBone = chr.root.getObjectByName(\"J_Bip_C_Head\");\n const face = chr.meshes.find(o => /Face_00_SKIN/.test(o.name + \" \" + (o.userData.material || \"\")));\n if (!headBone || !face) continue;\n let chinY = headBone.getWorldPosition(new THREE.Vector3()).y - 0.032;\n if (face.isSkinnedMesh) {\n let minY = Infinity;\n const P = face.geometry.attributes.position, vv = new THREE.Vector3();\n for (let i = 0; i < P.count; i += 2) {\n face.getVertexPosition(i, vv);\n vv.applyMatrix4(face.matrixWorld);\n if (vv.y < minY) minY = vv.y;\n }\n if (isFinite(minY)) chinY = minY;\n }\n const pivot = headBone.getWorldPosition(new THREE.Vector3()).applyMatrix4(camera.matrixWorldInverse);\n for (const o of chr.meshes) {\n const mu = o.material.uniforms;\n if (!mu || !mu.uFlattice) continue;\n mu.uFlattice.value = flat;\n mu.uFlChin.value = params.has(\"whole\") ? -100 : chinY + 0.010;\n mu.uFlFall.value = 0.05;\n mu.uFlPivot.value.copy(pivot);\n }\n }\n return { flat, persp: pu.uPersp.value };\n}\n\nfunction renderFrame(w, h, ss = 1) {\n const bw = w * ss, bh = h * ss;\n R.setPixelRatio(1);\n R.setSize(bw, bh, false);\n const { flat, persp } = setupCamera(w / h);\n targetsFor(bw, bh);\n\n const visible = allMeshes.filter(o => o.visible);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null;\n });\n R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera);\n\n const ppmBuf = bh / (camera.top - camera.bottom);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 0; mu.uCastOn.value = 1;\n mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture;\n mu.uCastRes.value.set(bw, bh); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far;\n mu.uCastPpm.value = ppmBuf; mu.uCastPersp.value = persp;\n });\n R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera);\n\n const u = paint.mat.uniforms;\n u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture;\n u.uRes.value.set(bw, bh); u.uNear.value = camera.near; u.uFar.value = camera.far;\n u.uGap.value = 0.012 * (1.0 - 0.85 * flat);\n u.uSil.value = THREE.MathUtils.clamp(1.75 * ppmBuf * 0.0040, ss, 2.5 * ss);\n u.uInner.value = Math.max(ss * 0.78, u.uSil.value * 0.56);\n u.uPpm.value = ppmBuf;\n R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam);\n}","Target":"// Load terrain and pass planted foot positions for contact shadows\nconst groundGltf = await parseGlb(\"plains.glb.json\");\nscene.add(groundGltf.scene);\nconst footPts = [];\nfor (const c of characters) {\n for (const fn of [\"J_Bip_L_Foot\", \"J_Bip_R_Foot\"]) {\n const b = c.root.getObjectByName(fn);\n if (b) { const p = b.getWorldPosition(new THREE.Vector3()); footPts.push(new THREE.Vector2(p.x, p.z)); }\n }\n}\nwhile (footPts.length < 4) footPts.push(new THREE.Vector2(99, 99));\n\nconst V0 = SCENE.characters[0].info;\ngroundGltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const role = o.userData.role || \"grass\";\n const mat = paintMaterial(V0, role, rawTex(o.material.map), meshIndex++, role, false);\n mat.uniforms.uFootA.value.copy(footPts[0]);\n mat.uniforms.uFootB.value.copy(footPts[1]);\n mat.uniforms.uFootC.value.copy(footPts[2]);\n mat.uniforms.uFootD.value.copy(footPts[3]);\n o.material = mat;\n o.frustumCulled = false;\n allMeshes.push(o);\n});\n\nfunction setupCamera(aspect) {\n const C = SCENE.camera;\n const centre = new THREE.Vector3(...C.target);\n const h = C.height, w = h * aspect;\n camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2;\n camera.zoom = 1;\n camera.updateProjectionMatrix();\n const a = THREE.MathUtils.degToRad(C.pitch);\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(16));\n camera.up.set(0, 1, 0);\n camera.lookAt(centre);\n}\n\nfunction renderFrame(w, h, ss = 1) {\n const bw = w * ss, bh = h * ss;\n R.setPixelRatio(1);\n R.setSize(bw, bh, false);\n setupCamera(w / h);\n targetsFor(bw, bh);\n\n const visible = allMeshes.filter(o => o.visible);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null;\n });\n R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera);\n\n const ppmBuf = bh / (camera.top - camera.bottom);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 0; mu.uCastOn.value = 1;\n mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture;\n mu.uCastRes.value.set(bw, bh); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far; mu.uCastPpm.value = ppmBuf;\n });\n R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera);\n\n const u = paint.mat.uniforms;\n u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture;\n u.uRes.value.set(bw, bh); u.uNear.value = camera.near; u.uFar.value = camera.far;\n u.uGap.value = 0.012;\n u.uSil.value = THREE.MathUtils.clamp(1.75 * ppmBuf * 0.0040, ss, 2.5 * ss);\n u.uInner.value = Math.max(ss * 0.78, u.uSil.value * 0.56);\n u.uPpm.value = ppmBuf;\n R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam);\n}"}
input
{ "Path": "~/work/lowmarch/review/slice/index.html", "Replacement": "// Load terrain when not in standalone single-GLB camera showcase mode\nif (!DIRECT_GLB) {\n const groundGltf = await parseGlb(\"plains.glb.json\");\n scene.add(groundGltf.scene);\n const footPts = [];\n for (const c of characters) {\n for (const fn of [\"J_Bip_L_Foot\", \"J_Bip_R_Foot\"]) {\n const b = c.root.getObjectByName(fn);\n if (b) { const p = b.getWorldPosition(new THREE.Vector3()); footPts.push(new THREE.Vector2(p.x, p.z)); }\n }\n }\n while (footPts.length < 4) footPts.push(new THREE.Vector2(99, 99));\n\n const V0 = SCENE.characters[0].info;\n groundGltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const role = o.userData.role || \"grass\";\n const mat = paintMaterial(V0, role, rawTex(o.material.map), meshIndex++, role, false);\n mat.uniforms.uFootA.value.copy(footPts[0]);\n mat.uniforms.uFootB.value.copy(footPts[1]);\n mat.uniforms.uFootC.value.copy(footPts[2]);\n mat.uniforms.uFootD.value.copy(footPts[3]);\n o.material = mat;\n o.frustumCulled = false;\n allMeshes.push(o);\n });\n}\n\nfunction setupCamera(aspect) {\n const C = SCENE.camera;\n const tParam = params.get(\"target\");\n const centre = tParam ? new THREE.Vector3(...tParam.split(\",\").map(Number)) : new THREE.Vector3(...C.target);\n const h = +(params.get(\"height\") || C.height), w = h * aspect;\n const pitch = +(params.get(\"pitch\") ?? C.pitch);\n const lens = +(params.get(\"lens\") || C.lens || 0);\n const flat = +(params.get(\"flat\") ?? C.flat ?? 0);\n\n camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2;\n camera.zoom = 1;\n camera.near = 0.1; camera.far = 40;\n camera.updateProjectionMatrix();\n const a = THREE.MathUtils.degToRad(pitch);\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(16));\n camera.up.set(0, 1, 0);\n camera.lookAt(centre);\n camera.updateMatrixWorld(true);\n\n const pu = paint.mat.uniforms;\n pu.uPersp.value = 0;\n if (lens > 0) {\n const d = w * lens / 36, n = 0.05, f = 40;\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(d));\n camera.lookAt(centre);\n camera.updateMatrixWorld(true);\n camera.near = n; camera.far = f;\n camera.projectionMatrix.makePerspective(-w / 2 * n / d, w / 2 * n / d, h / 2 * n / d, -h / 2 * n / d, n, f);\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n pu.uPersp.value = 1;\n }\n\n for (const chr of characters) {\n const headBone = chr.root.getObjectByName(\"J_Bip_C_Head\");\n const face = chr.meshes.find(o => /Face_00_SKIN/.test(o.name + \" \" + (o.userData.material || \"\")));\n if (!headBone || !face) continue;\n let chinY = headBone.getWorldPosition(new THREE.Vector3()).y - 0.032;\n if (face.isSkinnedMesh) {\n let minY = Infinity;\n const P = face.geometry.attributes.position, vv = new THREE.Vector3();\n for (let i = 0; i < P.count; i += 2) {\n face.getVertexPosition(i, vv);\n vv.applyMatrix4(face.matrixWorld);\n if (vv.y < minY) minY = vv.y;\n }\n if (isFinite(minY)) chinY = minY;\n }\n const pivot = headBone.getWorldPosition(new THREE.Vector3()).applyMatrix4(camera.matrixWorldInverse);\n for (const o of chr.meshes) {\n const mu = o.material.uniforms;\n if (!mu || !mu.uFlattice) continue;\n mu.uFlattice.value = flat;\n mu.uFlChin.value = params.has(\"whole\") ? -100 : chinY + 0.010;\n mu.uFlFall.value = 0.05;\n mu.uFlPivot.value.copy(pivot);\n }\n }\n return { flat, persp: pu.uPersp.value };\n}\n\nfunction renderFrame(w, h, ss = 1) {\n const bw = w * ss, bh = h * ss;\n R.setPixelRatio(1);\n R.setSize(bw, bh, false);\n const { flat, persp } = setupCamera(w / h);\n targetsFor(bw, bh);\n\n const visible = allMeshes.filter(o => o.visible);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null;\n });\n R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera);\n\n const ppmBuf = bh / (camera.top - camera.bottom);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 0; mu.uCastOn.value = 1;\n mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture;\n mu.uCastRes.value.set(bw, bh); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far;\n mu.uCastPpm.value = ppmBuf; mu.uCastPersp.value = persp;\n });\n R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera);\n\n const u = paint.mat.uniforms;\n u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture;\n u.uRes.value.set(bw, bh); u.uNear.value = camera.near; u.uFar.value = camera.far;\n u.uGap.value = 0.012 * (1.0 - 0.85 * flat);\n u.uSil.value = THREE.MathUtils.clamp(1.75 * ppmBuf * 0.0040, ss, 2.5 * ss);\n u.uInner.value = Math.max(ss * 0.78, u.uSil.value * 0.56);\n u.uPpm.value = ppmBuf;\n R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam);\n}", "Target": "// Load terrain and pass planted foot positions for contact shadows\nconst groundGltf = await parseGlb(\"plains.glb.json\");\nscene.add(groundGltf.scene);\nconst footPts = [];\nfor (const c of characters) {\n for (const fn of [\"J_Bip_L_Foot\", \"J_Bip_R_Foot\"]) {\n const b = c.root.getObjectByName(fn);\n if (b) { const p = b.getWorldPosition(new THREE.Vector3()); footPts.push(new THREE.Vector2(p.x, p.z)); }\n }\n}\nwhile (footPts.length < 4) footPts.push(new THREE.Vector2(99, 99));\n\nconst V0 = SCENE.characters[0].info;\ngroundGltf.scene.traverse(o => {\n if (!o.isMesh) return;\n const role = o.userData.role || \"grass\";\n const mat = paintMaterial(V0, role, rawTex(o.material.map), meshIndex++, role, false);\n mat.uniforms.uFootA.value.copy(footPts[0]);\n mat.uniforms.uFootB.value.copy(footPts[1]);\n mat.uniforms.uFootC.value.copy(footPts[2]);\n mat.uniforms.uFootD.value.copy(footPts[3]);\n o.material = mat;\n o.frustumCulled = false;\n allMeshes.push(o);\n});\n\nfunction setupCamera(aspect) {\n const C = SCENE.camera;\n const centre = new THREE.Vector3(...C.target);\n const h = C.height, w = h * aspect;\n camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2;\n camera.zoom = 1;\n camera.updateProjectionMatrix();\n const a = THREE.MathUtils.degToRad(C.pitch);\n camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(16));\n camera.up.set(0, 1, 0);\n camera.lookAt(centre);\n}\n\nfunction renderFrame(w, h, ss = 1) {\n const bw = w * ss, bh = h * ss;\n R.setPixelRatio(1);\n R.setSize(bw, bh, false);\n setupCamera(w / h);\n targetsFor(bw, bh);\n\n const visible = allMeshes.filter(o => o.visible);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null;\n });\n R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera);\n\n const ppmBuf = bh / (camera.top - camera.bottom);\n visible.forEach(o => {\n const mu = o.material.uniforms;\n mu.uPass.value = 0; mu.uCastOn.value = 1;\n mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture;\n mu.uCastRes.value.set(bw, bh); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far; mu.uCastPpm.value = ppmBuf;\n });\n R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera);\n\n const u = paint.mat.uniforms;\n u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture;\n u.uRes.value.set(bw, bh); u.uNear.value = camera.near; u.uFar.value = camera.far;\n u.uGap.value = 0.012;\n u.uSil.value = THREE.MathUtils.clamp(1.75 * ppmBuf * 0.0040, ss, 2.5 * ss);\n u.uInner.value = Math.max(ss * 0.78, u.uSil.value * 0.56);\n u.uPpm.value = ppmBuf;\n R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam);\n}" }result, 1 line
Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 666 (+81/-31 lines).