Vuforia: How to change teapot with a text in the image targets example?

怎甘沉沦 提交于 2019-12-18 13:38:38

问题


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

The example is available at : https://developer.vuforia.com/resources/sample-apps/image-targets-sample-app


回答1:


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

My solution:

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. Go to src->main->java->com.qualcomm.vuforia.samples->SampleApplication->utils. There you could find the objects you can use.

  2. 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;
      }}
    

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

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

  2. Add your new class in ImageTargetRenderer.java:

private TextPlane mTextPlane;

  1. Initilize mTextPlane inside the method initRendering()

mTextPlane = new TextPlane();

  1. Replace the teapot code with you new textplane code:

Replace this:

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

with this:

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. Replace this:

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

With this:

GLES20.glDrawElements(GLES20.GL_TRIANGLES,
                            mTextPlane.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
                            mTextPlane.getIndices());
  1. Try it. It should work!


来源:https://stackoverflow.com/questions/17939607/vuforia-how-to-change-teapot-with-a-text-in-the-image-targets-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!