首页 > 解决方案 > 从 ARcore 增强面网格渲染面罩

问题描述

我需要使用 Filament 渲染面罩。从 ARcore Augmented Faces 我有索引、顶点的缓冲区。不幸的是,渲染的面罩以某种方式损坏。 看看那个截图

我从 AugmentedFace 对象中获取网格:

val meshVertices = face.meshVertices
val uvs = face.meshTextureCoordinates
val meshNormals = face.meshNormals
val meshIndices = face.meshTriangleIndices

然后我创建顶点和索引缓冲区:

faceVertexBuffer = VertexBuffer.Builder()
    .bufferCount(3)
    .vertexCount(468)
    .attribute(VertexBuffer.VertexAttribute.POSITION, 0, VertexBuffer.AttributeType.FLOAT3, 0, 3 * Float.SIZE_BYTES)
    .attribute(VertexBuffer.VertexAttribute.TANGENTS, 1, VertexBuffer.AttributeType.FLOAT3, 0,             3 * Float.SIZE_BYTES)
    .attribute(VertexBuffer.VertexAttribute.UV0, 2, VertexBuffer.AttributeType.FLOAT2, 0,             2 * Float.SIZE_BYTES)
    .build(filament.engine)
    
meshVertices.rewind()
meshNormals.rewind()
uvs.rewind()

faceVertexBuffer.setBufferAt(filament.engine, 0, meshVertices)
faceVertexBuffer.setBufferAt(filament.engine, 1, meshNormals)
faceVertexBuffer.setBufferAt(filament.engine, 2, uvs)

faceIndexBuffer = IndexBuffer.Builder()
    .indexCount(2694)
    .bufferType(IndexBuffer.Builder.IndexType.USHORT)
    .build(filament.engine)

meshIndices.rewind()
faceIndexBuffer.setBuffer(filament.engine, meshIndices)

我渲染对象并将其添加到场景中:

RenderableManager.Builder(1)
.boundingBox(Box(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f))
.geometry(0, RenderableManager.PrimitiveType.TRIANGLES, faceVertexBuffer, faceIndexBuffer, 0, 468)
.material(0, materialInstance)
.build(filament.engine, faceRenderable)
filament.scene.addEntity(faceRenderable)

面罩的位置很好,眼睛,嘴巴在那个地方,但是质地很破。

任何提示我错过了什么?

标签: androidrenderingaugmented-realityarcoreandroid-augmented-reality

解决方案


推荐阅读