Vuforia:如何用图像目标示例中的文本更改茶壶? [英] Vuforia: How to change teapot with a text in the image targets example?

查看:33
本文介绍了Vuforia:如何用图像目标示例中的文本更改茶壶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Vuforia 的图像目标示例中更改带有文本内容的茶壶?

How do I change the teapot with a text content in Vuforia's Image Target example?

该示例位于:https://developer.vuforia.com/resources/sample-apps/image-targets-sample-app

推荐答案

我试图访问 mbrenon 提供的链接.不幸的是,它们没有加载.

I tried to access the links mbrenon gave. Unfortunately they didn't load.

我的解决方案:

您拥有茶壶的原因是因为 Vuforia 使用该类作为要显示的图像.为了有一个平面文本,我创建了自己的PlaneTextClass.

The reason why you have a Teapot is because Vuforia is using that class as the image to be shown. In order to have a plane text, I created my own PlaneTextClass.

  1. 转到 src->main->java->com.qualcomm.vuforia.samples->SampleApplication->utils.您可以在那里找到可以使用的对象.

  1. Go to src->main->java->com.qualcomm.vuforia.samples->SampleApplication->utils. There you could find the objects you can use.

添加一个名为TextPlane"并从MeshObject"扩展而来的类

Add a class named "TextPlane" and extended from "MeshObject"

public class TextPlane extends MeshObject {

  private final static double planeVertices[] =
        {
                -50f, -50f, 0.0f, 50f, -50f, 0.0f, 50f, 50f, 0.0f, -50f, 50f, 0.0f
        };
  private final static double planeTexcoords[] =
        {
                0, 0, 1, 0, 1, 1, 0, 1
        };
  private final static double planeNormals[] =
        {
                0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1
        };
  private final static short planeIndices[] =
        {
                0, 1, 2, 0, 2, 3
        };


  private Buffer mVertBuff;
  private Buffer mTexCoordBuff;
  private Buffer mNormBuff;
  private Buffer mIndBuff;

  public TextPlane(){
    mVertBuff = fillBuffer(planeVertices);
    mTexCoordBuff = fillBuffer(planeTexcoords);
    mNormBuff = fillBuffer(planeNormals);
    mIndBuff = fillBuffer(planeIndices);
  }

  @Override
  public Buffer getBuffer(BUFFER_TYPE bufferType) {
    Buffer result = null;
    switch (bufferType)
    {
        case BUFFER_TYPE_VERTEX:
            result = mVertBuff;
            break;
        case BUFFER_TYPE_TEXTURE_COORD:
            result = mTexCoordBuff;
            break;
        case BUFFER_TYPE_INDICES:
            result = mIndBuff;
            break;
        case BUFFER_TYPE_NORMALS:
            result = mNormBuff;
        default:
            break;
     }
    return result;
  }

  @Override
  public int getNumObjectVertex() {
      return planeVertices.length / 3;
  }

  @Override
  public int getNumObjectIndex() {
      return planeIndices.length;
  }}

如果要更改图像的大小,请更改 PlaneVertices[] 中的值.

If you want to change the size of the image, change the values in PlaneVertices[].

  1. 转到 src->main->java->com.qualcomm.vuforia.samples->VuforiaSamples->app->ImageTargets->ImageTargetRenderer.java

  1. Go to src->main->java->com.qualcomm.vuforia.samples->VuforiaSamples->app->ImageTargets->ImageTargetRenderer.java

在 ImageTargetRenderer.java 中添加您的新类:

Add your new class in ImageTargetRenderer.java:

private TextPlane mTextPlane;

  1. 在方法 initRendering() 内初始化 mTextPlane

mTextPlane = new TextPlane();

  1. 用新的文本平面代码替换茶壶代码:

替换这个:

GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
                        false, 0, mTeapot.getVertices());
                GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
                        false, 0, mTeapot.getNormals());
                GLES20.glVertexAttribPointer(textureCoordHandle, 2,
                        GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());

这样:

GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
                        false, 0, mTextPlane.getVertices());
                GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
                        false, 0, mTextPlane.getNormals());
                GLES20.glVertexAttribPointer(textureCoordHandle, 2,
                        GLES20.GL_FLOAT, false, 0, mTextPlane.getTexCoords());

  1. 替换这个:

GLES20.glDrawElements(GLES20.GL_TRIANGLES,mTeapot.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,mTeapot.getIndices());

有了这个:

GLES20.glDrawElements(GLES20.GL_TRIANGLES,
                            mTextPlane.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
                            mTextPlane.getIndices());

  1. 试试吧.它应该可以工作!

这篇关于Vuforia:如何用图像目标示例中的文本更改茶壶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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