2

I need to render a facemask using Filament. From ARcore Augmented Faces I have buffer for indices, vertices. Unfortunately rendered facemask is somehow corrupted. Take a look at that screenshot

I take meshes from the AugmentedFace object:

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

Then I create vertices and index buffers:

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)

and I render the object and add it to the scene:

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)

The facemask is well postioned, eyes, mouth on the place, but the texture is broken.

Any hints what am I missing?

0 Answers0