视觉对象
视觉对象(Visual)包括背景和立绘,是视觉小说中最基础的资源,也是最常用的资源。
// 注册纹理export const normalTex = regTexture("rinne_normal", t => { t.variants = "rinne.png";});
// 在立绘中使用纹理regVisual("Rinne").nodes({ body: { variants: { normal: normalTex, side: sideTex, }, },});regVisual 接受一个参数,并返回一个配置函数 nodes
regVisual("Rinne");"Rinne"是这个视觉对象的名称,可以任意指定(但不能与其他视觉对象重名)。
一个立绘可能由多个节点组成,每个节点可以使用不同的纹理。
nodes 接受一个参数,并返回一个配置函数 exprs。
regVisual("Rinne").nodes({ // 节点的名称(如 body)可以任意指定 body: { variants: { normal: normalTex, // 正常姿势 side: sideTex, // 侧身姿势 }, },
});这里的 normalTex 和 sideTex 是之前定义的纹理变量(句柄)。
regVisual("Rinne").nodes({ body: { parent: "root", // 默认 root,可以省略 variants: { normal: normalTex, side: sideTex, }, },
cheek: { variants: {...}, pos: [100, 100, 12] // 相对 parent 的偏移 x, y, z },
normal_eye: { parent: "body", variants: {...}, },
side_eye: { parent: "body", variants: {...}, },});自动生成的表达式
Section titled “自动生成的表达式”以 body 节点为例,其具有 normal 和 side 两个纹理变体:
body: { variants: { normal: normalTex, side: sideTex, } }默认情况下,视觉对象的每个节点都会自动产生一些表达式,方便在 rewrite 剧本中切换纹理变体。
{
"body:normal": { "target": "body", "variant": "normal" }, "body:side": { "target": "body", "variant": "side" },
"v#body": { "target": "body", "visible": true }, "u#body": { "target": "body", "visible": false },
"1#body": { "target": "body", "uniforms": { "uBaseAlpha": 1 } }, "0#body": { "target": "body", "uniforms": { "uBaseAlpha": 0 } },
"1#self": { "target": "self", "uniforms": { "uGroupAlpha": 1 } }, "0#self": { "target": "self", "uniforms": { "uGroupAlpha": 0 } }}自定义表达式
Section titled “自定义表达式”@TODO
regVisual("Rinne") .nodes({ ... }) .exprs({ "expr-name": { target: "body", uniforms: { uSome: 1 }, } });target用于指定作用节点的名称(如果为self,则作用于整个视觉对象组)。
每个节点除了自己的 uniforms,还会继承视觉对象组的 uniforms。