1

我正在使用 Vuforia iOS SDK(不是统一插件)开发一个 iOS 应用程序。

我想把VideoPlaybackImageTargets样品混合在一起。从论坛建议开始,我开始使用 videoplayback 示例并在其上集成 imageTarget。编辑 EAGLView 文件后,应用程序同时获得视频和 3D 模型,但不显示 3D 模型。跟踪图像时,它会获取内部的 3D 对象renderFrameQCAR并打印日志。

我不明白在哪里看。有没有人在没有 Unity 支持的情况下尝试过并做到这一点?任何帮助表示赞赏。

4

2 回答 2

0

开始处理 VideoPlayback 项目,仅更改EAGLView示例文件中的文件导入Teapot.h文件EAGLview.m

ImageTargets在命名空间声明中从顶部添加代码部分:

const float kObjectScale = 3.0f;
const char* textureFilenames[] = {
    "icon_play.png",
    "icon_loading.png",
    "icon_error.png",
    "VuforiaSizzleReel_1.png",
    "VuforiaSizzleReel_2.png",

    // added for 3d model
    "TextureTeapotBrass.png",
    "TextureTeapotBlue.png",
    "TextureTeapotRed.png"
};

添加此功能(来自ImageTargets

- (void)setup3dObjects
{
for (int i=0; i < [textures count]; ++i) {
    Object3D* obj3D = [[Object3D alloc] init];
    if (i >= 5)
    {
        obj3D.numVertices = NUM_TEAPOT_OBJECT_VERTEX;
        obj3D.vertices = teapotVertices;
        obj3D.normals = teapotNormals;
        obj3D.texCoords = teapotTexCoords;
        obj3D.numIndices = NUM_TEAPOT_OBJECT_INDEX;
        obj3D.indices = teapotIndices;
    }
    obj3D.texture = [textures objectAtIndex:i];
    [objects3D addObject:obj3D];
    [obj3D release];
}
}

然后,在RenderFrameQCAR, 之后:

int numActiveTrackables = state.getNumTrackableResults();

为 3d 模型添加代码,来自ImageTargets示例

for (int i = 0; i < state.getNumTrackableResults(); ++i) {
    // Get the trackable
    const QCAR::TrackableResult* result = state.getTrackableResult(i);
    const QCAR::Trackable& trackable = result->getTrackable();
    QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

    // Choose the texture based on the target name
    int targetIndex = 0; // "stones"
    if (!strcmp(trackable.getName(), "chips"))
        targetIndex = 1;
    else if (!strcmp(trackable.getName(), "tarmac"))
        targetIndex = 2;
    Object3D *obj3D = [objects3D objectAtIndex:targetIndex+5];

    // OpenGL 2
    QCAR::Matrix44F modelViewProjection;
    ShaderUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
    ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);
    ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
    glUseProgram(shaderProgramID);
    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);
    glEnableVertexAttribArray(vertexHandle);
    glEnableVertexAttribArray(normalHandle);
    glEnableVertexAttribArray(textureCoordHandle);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
    glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
    glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);
    ShaderUtils::checkGlError("EAGLView renderFrameQCAR");
}

只要确保你所有的东西都正确加载,应该可以正常工作。

于 2013-03-14T10:25:21.177 回答
0

这个答案是基于真实经验的。

我在 videoplayback 通话中调用 3d 模型,我的意思是这样

if (strcmp(imageTarget.getName(), "affogato") == 0)
{
const int kObjectScale = 500;
[self secondSetup3dObjects];
playerIndex = 99;
const QCAR::TrackableResult* result = state.getTrackableResult(i);
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());
int targetIndex = 9;
Object3D *obj3D = [objects3D objectAtIndex:targetIndex];
QCAR::Matrix44F modelViewProjection;
ShaderUtils::translatePoseMatrix(0.0f, 0.0f, 50.0f, &modelViewMatrix.data[0]);
ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);
ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);
glUseProgram(shaderProgramID);
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);

glEnableVertexAttribArray(vertexHandle);
            glEnableVertexAttribArray(normalHandle);
            glEnableVertexAttribArray(textureCoordHandle);

            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
            glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
            glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
            glDrawArrays(GL_TRIANGLES, 0,  obj3D.numVertices);

            ShaderUtils::checkGlError("EAGLView renderFrameQCAR");

我希望这可以帮助任何人......

哦,顺便说一句,您需要在 appdelegate 中放入该目标的视频和纹理的透明背景,以使这项工作像魅力一样

于 2013-07-31T23:12:08.280 回答