如何更改 ModelRenderable 的颜色? [英] How to change Color of ModelRenderable?

查看:21
本文介绍了如何更改 ModelRenderable 的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ModelRenderable 附加到节点并在 ArFragment 中呈现.

i have a ModelRenderable attached to a Node and rendered in an ArFragment.

我想以醒目的颜色向用户突出显示此元素 0.5 秒.

I would like to highlight this element to the user for 0.5 sec in a prominent color.

我尝试更改材料,但没有成功.渲染冻结而不会引发错误.这是我尝试过的:

I tried to change the material, but it didn't work out. The rendering freezes without throwing an error. Here is what I tried:

private void addHighlightToNode(Node node) {

    CompletableFuture<Material> materialCompletableFuture =
            MaterialFactory.makeOpaqueWithColor(this, new Color(0, 255, 244));
    ModelRenderable highlightedRenderable = (ModelRenderable) node.getRenderable();
    highlightedRenderable = highlightedRenderable.makeCopy();
    try {
        highlightedRenderable.setMaterial(materialCompletableFuture.get());
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    node.setRenderable(highlightedRenderable);
}

我设法在运行时将节点的灯光设置为不同的颜色,但效果不是我需要的.

I managed to set the light of the Node to a different color in runtime, but the effect is not close to what I need.

node.setLight(Light.builder(Light.Type.POINT).setColor(new Color(0,255,244)).build());

如何更改颜色?

推荐答案

创建材料是异步的,这就是它返回 CompletableFuture 的原因.您正在调用 CompletableFuture.get(),这是一个阻塞调用,但由于您在 UI 线程上,它最终会冻结应用程序.如果在 thenAccept 中移动要调用的设置,它就可以正常工作.

Creating the material is asynchronous, that's why it returns a CompletableFuture. You are calling CompletableFuture.get(), which is a blocking call, but since you are on the UI thread it ends up freezing the app. If you move the setting to be called in thenAccept, it works correctly.

  private void addHighlightToNode(Node node) {
    CompletableFuture<Material> materialCompletableFuture =
            MaterialFactory.makeOpaqueWithColor(this, new Color(0, 255, 244));

    materialCompletableFuture.thenAccept(material -> {
      Renderable r2 = node.getRenderable().makeCopy();
      r2.setMaterial(material);
      node.setRenderable(r2);
    });
  }

这篇关于如何更改 ModelRenderable 的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆