我正在使用Vuforia iOS SDK开发iOS应用程序(不是Unity插件)。
我想将VideoPlayback
和ImageTargets
样本混合在一起。从论坛建议开始,我开始使用videoplayback示例并在其上集成imageTarget。编辑EAGLView文件后,应用程序同时获取视频和3D模型,但不显示3D模型。跟踪图像时,它会在renderFrameQCAR
内获取3D对象并打印日志。
我无法理解在哪里看。没有Unity支持,有没有人尝试过这样做?任何帮助表示赞赏。
答案 0 :(得分: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");
}
确保所有东西都正确加载,应该可以正常工作。
答案 1 :(得分: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中添加一个视频到这个目标和一个透明的纹理背景,让它像魅力一样工作 此致