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

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

问题描述

我有一个ModelRenderable附加到Node并在ArFragment中渲染.

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

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

  private void addHighlightToNode(Node node){CompletableFuture<材料>materialCompletableFuture =MaterialFactory.makeOpaqueWithColor(this,new Color(0,255,244));ModelRenderable HighlightedRenderable =(ModelRenderable)node.getRenderable();HighlightRenderable = highlightedRenderable.makeCopy();尝试 {highlightRenderable.setMaterial(materialCompletableFuture.get());} catch(InterruptedException e){e.printStackTrace();} catch(ExecutionException e){e.printStackTrace();}node.setRenderable(highlightedRenderable);} 

我在运行时设法将Node的光设置为不同的颜色,但是效果与我所需的接近.

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

如何更改颜色?

解决方案

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

  private void addHighlightToNode(节点节点){CompletableFuture<材料>materialCompletableFuture =MaterialFactory.makeOpaqueWithColor(this,new Color(0,255,244));materialCompletableFuture.thenAccept(material-> {可渲染r2 = node.getRenderable().makeCopy();r2.setMaterial(material);node.setRenderable(r2);});} 

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

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());

How can I change the color?

解决方案

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天全站免登陆