Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Replace ViewRenderable #1064

Open
RGregat opened this issue Apr 27, 2020 · 1 comment
Open

Replace ViewRenderable #1064

RGregat opened this issue Apr 27, 2020 · 1 comment

Comments

@RGregat
Copy link

RGregat commented Apr 27, 2020

I want to update the ViewRenderable of a Node.
For that usecase I build a Map with all my ViewRenderables I want to attach to a Node. Actually the ViewRenderables are not stored directly into the Map but as a CompletableFuture Object.

In my application I can place Nodes on the Scene. I also store them into a List to keep track of the amount of Nodes I have already placed. Based on the position of the Node in the List I want to change the ViewRenderbale.
The check is done on every onUpdate(Frame frame) call. Sure I only want to replace the Renderable once, for that I have a check if a Renderable was already replaced.

The function to replace the ViewRenderable on a Node looks like this

CompletableFuture<ViewRenderable> completableFuture = mViewRenderableMap.get(renderableState).getFutureObject();
        CompletableFuture.allOf(completableFuture)
                .handle((notUsed, throwable) -> {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Call handle to get access to te ViewRenderables");
                    try {
                        ViewRenderable renderable = completableFuture.get();
                        renderable.setRenderPriority(Renderable.RENDER_PRIORITY_LAST);
                        renderable.setShadowCaster(isShadowCaster());
                        renderable.setShadowReceiver(isShadowReceiver());

                        getNode().setRenderable(null);
                        getNode().setRenderable(renderable);
                        LoggerHelper.showLog(Log.DEBUG, TAG, "Renderable replaced!");
                        this.mRenderableState = renderableState;
                    } catch (InterruptedException | ExecutionException ex) {
                        ex.printStackTrace();
                    }
                    return null;
                });

I'm not sure about the getNode().setRenderable(null); part.

and the decission is made by this simple loop

for (int i = 0; i < mVolumeBoundingPointList.size(); i++) {
            // Come back the next frame
            if (mVolumeBoundingPointList.get(i).getImageRenderable() == null && mVolumeBoundingPointList.get(i).getImageRenderable().getNode() == null)
                return;

            LoggerHelper.showLog(Log.DEBUG, TAG, "Check VolumeBoundingPoint: " + i);

            ImageRenderable imageRenderable = mVolumeBoundingPointList.get(i).getImageRenderable();

            // Update the first VolumeBoundingPoint
            if (i == 0 && mVolumeBoundingPointList.size() == 1) {
                if (imageRenderable.getRenderableState() != RenderableTypeEnums.VOLUME_BOUNDING_ENABLED_START) {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Update Renderable of first VolumeBoundingPoint");
                    imageRenderable.updateRenderable(RenderableTypeEnums.VOLUME_BOUNDING_ENABLED_START);
                }
            }

            // Update the last VolumeBoundingPoint
            if (i == mVolumeBoundingPointList.size() - 1 && mVolumeBoundingPointList.size() > 1) {
                if (imageRenderable.getRenderableState() != RenderableTypeEnums.VOLUME_BOUNDING_ENABLED_END) {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Update Renderable of last VolumeBoundingPoint");
                    imageRenderable.updateRenderable(RenderableTypeEnums.VOLUME_BOUNDING_ENABLED_END);
                }
            }

            // Update the all VolumeBoundingPoint between the first and last VolumeBoundingPoint
            if (i > 0 && i < mVolumeBoundingPointList.size() - 1) {
                if (imageRenderable.getRenderableState() != RenderableTypeEnums.VOLUME_BOUNDING_ENABLED) {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Update Renderable between first and last VolumeBoundingPoint");
                    imageRenderable.updateRenderable(RenderableTypeEnums.VOLUME_BOUNDING_ENABLED);
                }
            }
        }

The result ist very Inconsistent. The first and the last point is rendered as expected, but the points in between have the complete variety of ViewRenderables attached to them. They flicker. The following is shown:

  • nothing
  • the camera view
  • the ViewRenderable for the start, the end or in between.

And flickering happens if I move the smartphone.

Maybe someone could explain to me the propper way to replace a Renderable, because I'm lost.

Sceneform-Version: 1.15.0

@RGregat
Copy link
Author

RGregat commented Apr 27, 2020

Well, what I found so far.

The ViewRenderable for the type RenderableTypeEnums.VOLUME_BOUNDING_ENABLED is my default ViewRenderable. All my Nodes get this after the creation.

if I change

if (i > 0 && i < mVolumeBoundingPointList.size() - 1) {
                if (imageRenderable.getRenderableState() != RenderableTypeEnums.TRACKING_VIEW_ENABLED) {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Update Renderable between first and last VolumeBoundingPoint");
                    imageRenderable.updateRenderable(RenderableTypeEnums.TRACKING_VIEW_ENABLED);
                    imageRenderable.setRenderableState(RenderableTypeEnums.TRACKING_VIEW_ENABLED);
                }
            }

to

if (i > 0 && i < mVolumeBoundingPointList.size() - 1) {
                if (imageRenderable.getRenderableState() != RenderableTypeEnums.TRACKING_VIEW_ENABLED_START) {
                    LoggerHelper.showLog(Log.DEBUG, TAG, "Update Renderable between first and last VolumeBoundingPoint");
                    imageRenderable.updateRenderable(RenderableTypeEnums.TRACKING_VIEW_ENABLED_START);
                    imageRenderable.setRenderableState(RenderableTypeEnums.TRACKING_VIEW_ENABLED_START);
                }
            }

Or introduce a fourth ViewRenerable, the points in between behave normal, getting the new ViewRenderable and don't flicker.

So whatever ViewRenderable is attached the first time, can't be reattached.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant