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

时间:2013-07-30 06:19:38

标签: vuforia

如何在Vuforia Image Target示例中更改带有文本内容的茶壶?

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

1 个答案:

答案 0 :(得分:3)

我试图访问mbrenon给出的链接。不幸的是他们没有加载。

我的解决方案:

你有茶壶的原因是因为Vuforia正在使用该类作为要显示的图像。为了得到一个平面文本,我创建了自己的PlaneTextClass。

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

  2. 添加一个名为“TextPlane”的类,并从“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;
      }}
    
  3. 如果要更改图像的大小,请更改PlaneVertices []中的值。

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

      < / LI>
    2. 在ImageTargetRenderer.java中添加新课程:

    3. private TextPlane mTextPlane;

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

        mTextPlane = new TextPlane();

        1. 用新的textplane代码替换茶壶代码:
        2. 替换它:

          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. 替换它:
          2. 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. 试试吧。它应该工作!