在 arcore 中的 3d 对象上使用模板蒙版的问题 [英] Problem using stencil mask on 3d object in arcore

查看:12
本文介绍了在 arcore 中的 3d 对象上使用模板蒙版的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 hello ar java 演示在 3d 对象上使用模板蒙版,但是我遇到了一些意外行为.我的模板蒙版正确地遮挡了平面渲染器,但 3d 对象(andy)似乎没有按预期做出反应.相反,他似乎被翻转了,如图所示.我不知道如何解决这个问题.附件是做模板屏蔽的代码片段

I am using a stencil mask on a 3d object using the hello ar java demo however i am running into some unexpected behaviour. My stencil mask correctly occludes the plane renderer but the 3d object (andy) does not seem to react expectedly. Instead he seems to get flipped as shown in the picture. I am not sure how to approach fixing this issue. Attached is the code snippet doing the stencil masking

模板图像在平面缓冲区上正常工作但在 3d 模型上失败

Image of stencil correctly working on plane buffer but failing on 3d model

  GLES20.glClear ( GLES20.GL_STENCIL_BUFFER_BIT );
  GLES20.glEnable(GLES20.GL_STENCIL_TEST);
  GLES20.glColorMask(false, false, false, false);
  GLES20.glDepthMask(false);
  GLES20.glStencilFunc(GLES20.GL_NEVER, 1, 0xFF);
  GLES20.glStencilOp(GLES20.GL_REPLACE, GLES20.GL_KEEP, GLES20.GL_KEEP);
  GLES20.glStencilMask(0xFF);
  GLES20.glClear(GLES20.GL_STENCIL_BUFFER_BIT);

  // controls how pixels are rendered in the stencil mask
  quadDrawer.draw();

  GLES20.glColorMask(true, true, true, true);
  GLES20.glDepthMask(true);
  GLES20.glStencilMask(0xFF);
  GLES20.glStencilFunc(GLES20.GL_EQUAL, 0, 0xFF);

  // Visualize planes.
  // reacts correctly to the stencil mask
  planeRenderer.drawPlanes(
      session.getAllTrackables(Plane.class), camera.getDisplayOrientedPose(), projmtx);

  // Visualize anchors created by touch.
  float scaleFactor = 1.0f;

  for (ColoredAnchor coloredAnchor : anchors) {
    if (coloredAnchor.anchor.getTrackingState() != TrackingState.TRACKING) {
      continue;
    }
    // Get the current pose of an Anchor in world space. The Anchor pose is updated
    // during calls to session.update() as ARCore refines its estimate of the world.
    coloredAnchor.anchor.getPose().toMatrix(anchorMatrix, 0);

    // Update and draw the model and its shadow.
    // does not react correctly to the 
    virtualObject.updateModelMatrix(anchorMatrix, scaleFactor);
    virtualObjectShadow.updateModelMatrix(anchorMatrix, scaleFactor);
    virtualObject.draw(viewmtx, projmtx, colorCorrectionRgba, coloredAnchor.color);
    virtualObjectShadow.draw(viewmtx, projmtx, colorCorrectionRgba, coloredAnchor.color);
  }

  GLES20.glDisable(GLES20.GL_STENCIL_TEST);

推荐答案

忘记更新我为此找到的解决方案".我没有在 3d 对象上应用模板蒙版,而是再次渲染背景,但将其通过模板蒙版.这意味着背景将覆盖 3d 对象,从而实现所需的遮罩"效果.

Forgot to update the "solution" i found for this. Instead of applying the stencil mask over the 3d object, i render the background again but passing it through the stencil mask. This means that the background will overlay the 3d object hence achieving the desired "masking" effect.

这篇关于在 arcore 中的 3d 对象上使用模板蒙版的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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