Skip to content

视觉对象

视觉对象(Visual)包括背景和立绘,是视觉小说中最基础的资源,也是最常用的资源。

world/rinne.ts
// 注册纹理
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, // 侧身姿势
},
},
});

这里的 normalTexsideTex 是之前定义的纹理变量(句柄)。

body 节点为例,其具有 normalside 两个纹理变体:

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 } }
}

@TODO

regVisual("Rinne")
.nodes({ ... })
.exprs({
"expr-name": {
target: "body",
uniforms: { uSome: 1 },
}
});
  • target 用于指定作用节点的名称(如果为 self,则作用于整个视觉对象组)。

每个节点除了自己的 uniforms,还会继承视觉对象组的 uniforms。