WebAR-rocks / WebAR.rocks.face

WebAR.rocks face detection and tracking JavaScript library
https://webar.rocks
Other
84 stars 27 forks source link

Working on morph targets over virtual avatar based on WebAR.rocks face landmarks #1

Closed Juanmaramon closed 3 years ago

Juanmaramon commented 4 years ago

Hi @xavierjs,

I'm trying the face API and currently working on a basic face tracking demo (I sent you auth data on an email).

Here is the avatar glb file: https://juanmaramon.com/Test/accdemo/demos/xrs/assets/avatar.glb

Based on the Flexible mask demo I was trying to load the GLB file using

`_flexibleMaskHelper.load_geometryFromGLTF(threeLoadingManager, _spec.flexibleMaskURL).then(function(geom){ const face3DKeypoints = (_spec.flexibleMaskPoints) ? _spec.flexibleMaskPoints : WebARRocksFaceHelper.get_facePointPositions();

_flexibleMaskMesh = _flexibleMaskHelper.build_flexibleMask(geom, face3DKeypoints, {
  kpInfluenceDecay: _spec.kpInfluenceDecay // [ distance from the keypoint where decay start, distance from the keypoint where decay ends ]
});`

But it raise this error:

Error: MULTIPLE_GEOMETRIES

Does it need to be all geometry grouped on the root object?

Can you explain some of the options on the settings array?

flexibleMaskPoints and kpInfluenceDecay:

https://github.com/xavierjs/WebAR.rocks.face/blob/69df4f951a82041a121a8bac5ead2fbc3b4bc275/demos/flexibleMask/main.js#L13

Thanks!

xavierjs commented 4 years ago

Hi @Juanmaramon

This error is triggered by the helper by this function: https://github.com/xavierjs/WebAR.rocks.face/blob/69df4f951a82041a121a8bac5ead2fbc3b4bc275/helpers/WebARRocksFaceFlexibleMaskHelper.js#L158

I the last commit I have added an extra argument to pick the geometry you want to use by specifying the name:

_flexibleMaskHelper.load_geometryFromGLTF(threeLoadingManager, _spec.flexibleMaskURL, <geomName>)

in your case it would be:

_flexibleMaskHelper.load_geometryFromGLTF(threeLoadingManager, _spec.flexibleMaskURL, Wolf3D_Head)

All geometries should be grouped in the root object. But only one geometry will be deformed. I advise you to start from fflexibleMask2 demo instead of flexibleMask since you case is closer to flexibleMask2 demo.

Best regards, Xavier

Juanmaramon commented 4 years ago

Hi @xavierjs !

Thanks for the info, now based on FlexibleMask2 example I render some avatar face elements :)

face

I'm using the default values on foolMaskARMetadata.json only chaging the DEFORMEDID value to

"DEFORMEDID": "Wolf3D_Head",

then is the DEFORMEDKEYPOINTS array with key value pairs:

{
 "label": "LEFT_EYEBROW_INSIDE",
 "co": [18.183937,53.444672,41.949951]
},

with the current glb avatar file that I'm using how can I achive the same effect as the FlexibleMask2 demo?

Thanks!

xavierjs commented 4 years ago

Hi,

You need to provide more points so that the helper can compute the mapping between landmarks and mesh keypoints. I also advise you to align your mesh with the mesh provided as an example (https://github.com/xavierjs/WebAR.rocks.face/blob/master/demos/flexibleMask2/assets/face.glb) to make debug easier. it would also be better to apply visual transforms before exporting and to triangulate faces.

Best regards, Xavier

Juanmaramon commented 4 years ago

Hi @xavierjs ,

Aligning with the mesh (https://github.com/xavierjs/WebAR.rocks.face/blob/master/demos/flexibleMask2/assets/face.glb) rotates 90º the geometry and resulting in this:

face1

What are you meaning with

it would also be better to apply visual transforms before exporting and to triangulate faces."

Right now, the avatar is rendered at 1:1 scale and without rotations applied to it.

DEFORMEDKEYPOINTS are 2D coordinates based on which origin?

{ "label": "LEFT_EYEBROW_INSIDE", "co": [18.183937,53.444672,41.949951] },

Thanks!

xavierjs commented 4 years ago

I opened Blender then :

Then I:

I also removed the ear points from foolMaskARMetadata.json. If you want a very good result you have to merge the eyes, the hair to the geometry. Otherwise when the skin moves the eyes are still static and there are intersection bugs. You also need to find the right position for all of the landmarks (not only LEFT_EYE_INSIDE)

I can finish the demo as a development service if you are interested.

import bmesh

def logSelected():
  obj = bpy.context.object
  me = obj.data
  bm = bmesh.from_edit_mesh(me)
  vertices = [e for e in bm.verts]
  for vert in vertices:
    if vert.select:
      co = vert.co
      print('[%f,%f,%f]' % (co.x, co.z, -co.y))

screenshot1 screenshot2