如何通过 Amazon Sumerian 中的脚本设置实体的颜色?
How to set color of the entity from the script in Amazon Sumerian?
我正在学习 Amazon Sumerian Web VR 开发。我正在尝试从 update()
方法中该实体的脚本更改颜色 属性。代码如下所示:
function update(args, ctx) {
ctx.entity.transformComponent.setTranslation(0.6, 166, distance);
distance += 10;
if (distance > 1500) {
distance = -10;
ctx.entityData.color = "blue";
}
}
我也尝试通过 ctx.entity.color
和 ctx.entity.setAttribute('color', 'blue')
设置 color
属性,但这也不起作用。我在他们的官方网站上也找不到任何用于设置颜色的文档。我认为我缺少一个简单的捕获。
从脚本更新实体颜色的正确方法是什么?
以下方法未记录。这可能只是 Sumerian 文档不完整的症状,或者可能表明该方法未得到官方支持,因此将来可能会发生变化。但是现在,您可以使用以下方法来完成您想要的。
function update(args, ctx) {
ctx.entity.transformComponent.setTranslation(0.6, 166, distance);
distance += 10;
if (distance > 1500) {
distance = -10;
// Color is a 4 component array in the order: red, green, blue, alpha
const blueColor = [0, 0, 1, 1];
ctx.entity.setDiffuse(blueColor);
}
}
下面的答案是针对 Preview/new 版本的苏美尔语 API。可以在上面 Kris Schultz 的回答中找到旧版苏美尔语 API 的答案。
只是想回答这个问题。
在这种情况下,我正在尝试更改宿主实体的衬衫颜色。例如,我想使用脚本将 Cristine Polo 实体的衬衫颜色动态更改为红色。
Amazon Sumerian脚本API的官方文档可以找到答案,推荐给大家入门:
https://content.sumerian.amazonaws.com/engine/latest/doc/#content://sumerian-common/Guide/Quick%20Start
import * as s from 'module://sumerian-common/api';
export default function RotatorAction(ctx) {
ctx.start( EnabledAction );
}
function EnabledAction(ctx) {
ctx.start(
[ s.material.SetMaterialColorAction, { color: s.color.Red } ]
);
}
我最终使用旧版 API。
此外,对于 Legacy API,我注意到可以仅使用三个 RGB 值 [r, g, b] 而无需 alpha 值。此外,setDiffuse() 所采用的 RGB 值介于 0-1 之间,这需要从通常发现的 0-255 比例进行转换。
我正在学习 Amazon Sumerian Web VR 开发。我正在尝试从 update()
方法中该实体的脚本更改颜色 属性。代码如下所示:
function update(args, ctx) {
ctx.entity.transformComponent.setTranslation(0.6, 166, distance);
distance += 10;
if (distance > 1500) {
distance = -10;
ctx.entityData.color = "blue";
}
}
我也尝试通过 ctx.entity.color
和 ctx.entity.setAttribute('color', 'blue')
设置 color
属性,但这也不起作用。我在他们的官方网站上也找不到任何用于设置颜色的文档。我认为我缺少一个简单的捕获。
从脚本更新实体颜色的正确方法是什么?
以下方法未记录。这可能只是 Sumerian 文档不完整的症状,或者可能表明该方法未得到官方支持,因此将来可能会发生变化。但是现在,您可以使用以下方法来完成您想要的。
function update(args, ctx) {
ctx.entity.transformComponent.setTranslation(0.6, 166, distance);
distance += 10;
if (distance > 1500) {
distance = -10;
// Color is a 4 component array in the order: red, green, blue, alpha
const blueColor = [0, 0, 1, 1];
ctx.entity.setDiffuse(blueColor);
}
}
下面的答案是针对 Preview/new 版本的苏美尔语 API。可以在上面 Kris Schultz 的回答中找到旧版苏美尔语 API 的答案。
只是想回答这个问题。
在这种情况下,我正在尝试更改宿主实体的衬衫颜色。例如,我想使用脚本将 Cristine Polo 实体的衬衫颜色动态更改为红色。
Amazon Sumerian脚本API的官方文档可以找到答案,推荐给大家入门: https://content.sumerian.amazonaws.com/engine/latest/doc/#content://sumerian-common/Guide/Quick%20Start
import * as s from 'module://sumerian-common/api';
export default function RotatorAction(ctx) {
ctx.start( EnabledAction );
}
function EnabledAction(ctx) {
ctx.start(
[ s.material.SetMaterialColorAction, { color: s.color.Red } ]
);
}
我最终使用旧版 API。 此外,对于 Legacy API,我注意到可以仅使用三个 RGB 值 [r, g, b] 而无需 alpha 值。此外,setDiffuse() 所采用的 RGB 值介于 0-1 之间,这需要从通常发现的 0-255 比例进行转换。