<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ashutosh Dingankar on Medium]]></title>
        <description><![CDATA[Stories by Ashutosh Dingankar on Medium]]></description>
        <link>https://medium.com/@ashutoshdingankar?source=rss-37252b0ecf85------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Qk-tkogbQZny0mVMsurDbQ.jpeg</url>
            <title>Stories by Ashutosh Dingankar on Medium</title>
            <link>https://medium.com/@ashutoshdingankar?source=rss-37252b0ecf85------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:00:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashutoshdingankar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create Apple’s Animoji using ARKit?]]></title>
            <link>https://medium.com/@ashutoshdingankar/how-to-create-apples-animoji-using-arkit-4691e04bfc42?source=rss-37252b0ecf85------2</link>
            <guid isPermaLink="false">https://medium.com/p/4691e04bfc42</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[animoji]]></category>
            <category><![CDATA[arkit]]></category>
            <category><![CDATA[blender]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ashutosh Dingankar]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 19:37:14 GMT</pubDate>
            <atom:updated>2019-10-03T19:37:14.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*BuhWeRxWOfszk4PpSEH3fw.gif" /></figure><p>As a computer vision &amp; deep learning enthusiast, I am always curious to explore the areas related to images &amp; video processing.</p><p>Recently the idea of Apple’s Animoji grabbed my attention. So, I started my research of exploring how Apple’s Animoji works with such a good performance.</p><h4>Problem Statement:</h4><ol><li>Render 3D Face model in the camera scene whenever user’s face is detected through front camera.</li><li>Model should mimic user’s face movements, expressions &amp; orientations.</li></ol><h4>Basic building blocks:</h4><ol><li>Hardware with camera that can capture images in real time with good performance: iOS device’s <strong>true depth front camera (iPhone X &amp; above)</strong> is the better choice.</li><li>Software that can apply face detection algorithms to detect face with facial expressions: You can use OpenCV to achieve this. But thanks to <strong>Apple’s ARKit</strong> which is doing most of the leg work under the hood with good performance. It is capable of detecting face as well as facial expressions in the form of <strong>BlendShapes</strong> <strong>(or Shape keys or Morph targets)</strong>. Each BlendShape location has value ranging from 0 to 1 which is the measurement of that particular facial expression. <a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation">Learn More</a>. ARKit provides <a href="https://github.com/JakeHoldom/EmojiFace/blob/master/BlendShapeKeys.txt"><strong>50 BlendShape location</strong></a><strong>s</strong></li><li>3D Face model: Download face model from <a href="https://www.turbosquid.com/">https://www.turbosquid.com</a></li><li>3D modelling editing software where I can create &amp; define blendshape locations: There are lot of good applications such as<strong> </strong>Unity, Maya etc to work with but I have used <a href="https://www.blender.org/"><strong>Blender</strong></a><strong> v2.80</strong> as it is free ;).</li></ol><h4>Approach:</h4><p>Idea is whenever ARKit face tracking session runs, on every rendering cycle,it gives continuous 50 blendshape location values ranging from 0 to 1. If I update these values to the corresponding blendshape locations defined in 3D model, I will get animations for that locations. So, the key is to define appropriate blendshapes (or shape keys) on the model &amp; give the shapekey name same as that <a href="https://github.com/JakeHoldom/EmojiFace/blob/master/BlendShapeKeys.txt">ARKit provides</a>.</p><h4><strong>Dividing solution into 4 parts:</strong></h4><ol><li>Create shape keys for 3D model</li><li>Export model object as .dae from Blender</li><li>Import .dae file into Xcode</li><li>Code</li></ol><h3><strong>1. Create shape keys for 3D model</strong></h3><p>Since I am noob to Blender, my most of the time spent it to get comfortable with this tool.</p><p>There are six expressions for six basic emotions — anger, happy, surprise, sad, fear and disgust. To draw or illustrate these emotions, we use the eyebrows, eyelids, and mouth. Just by changing these lines we will get very different expressions. Many other emotions such as bored, shock, devious, confused, contempt, etc. can also be achieved through various permutation and combinations of the eyebrow line, lips, and eyes.</p><h4>Shape Keys</h4><p>Shape keys are used where we need to animate the shape of an object by animating the vertices of the mesh. These are also know as morph targets or blend shapes.</p><h4>Creating Shape Keys</h4><h4>Step 1</h4><p>Press <strong>TAB</strong> to exit <strong>Edit</strong> mode. With the <strong>Head</strong> object selected, Press the <strong>+</strong> (plus) button to add a <strong>Shape Key</strong>. This first shape key is automatically named <strong>Basis,</strong> and is the default shape of the object. Do-not edit the shape of this key. Shape keys can only be created in <strong>Object</strong> mode, but we can of course edit the shape of any key by entering into <strong>Edit</strong> mode.</p><h4>Step 2</h4><p>We will create a separate shape key for each individual shape, or change to the geometry. That means one shape key for the left eyebrow raised, another for the right lip smile and so on. Add another <strong>Shape Key</strong> with the <strong>+</strong> (plus) button. We will start with the upper part of the face, so name this eye-brow-angry or browDown_L for short (or anything else you like.).</p><h4><strong>Step 3</strong></h4><p>Like wise, I have defined 30 shape keys by referring <a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation">ARKit blendshape locations</a> &amp; gave same name as that of <a href="https://github.com/JakeHoldom/EmojiFace/blob/master/BlendShapeKeys.txt">ARKit blendshapes</a>.</p><p>Note that, ARKit provides 50 blendshape locations. So, you define all of them if you want smoother animation.</p><p>By changing values of shape keys from 0 to 1, you can test the animation of that blendshape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFsZ4hREWyR619VsgzRQxA.png" /><figcaption><strong>Basis</strong> Shape Key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zB-OSBaKxr4d5i5GrZn3ag.png" /><figcaption><a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation/2928274-browouterupleft"><strong>browOuterUp_L</strong></a> Shape Key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9to2_aQywV0enathhmK3A.png" /><figcaption><a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation/2928261-eyeblinkleft"><strong>eyeBlink_L</strong> </a>Shape Key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GQ11y90C0BMojlBPx6TrBw.png" /><figcaption><a href="https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation/2928249-mouthsmileleft"><strong>mouthSmile_L</strong></a> Shape Key</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*QexsC8ucseLKRFmYDoqfnA.gif" /></figure><h3>2. Export model object as .dae from Blender:</h3><p>ARKit uses scene kit(.scn) to load 3D models. Blender object is exported in Digital Exchange Format (.dae) format. Xcode has the capability to convert .dae file to .scn file.</p><p><strong>Challenges faced:</strong></p><blockquote><strong><em>A) Make sure all of your modifiers exist in exported .dae file:</em></strong></blockquote><p>Somehow, I saw my modifiers were not exported in .dae file. My 3D model uses subdivision modifier</p><p>After Googling, I found that applying this modifier is important. Otherwise, the shape keys will not be retained when exporting the character — which means no animations will work.Itrequires a <a href="https://forums.unrealengine.com/development-discussion/animation/1623830-blender-2-8-beta-morph-targets-and-modifiers">Python script</a> to work</p><p>Next, open a text editor, save the following script in an appropriate location, and call it apply_with_shape_keys.py:</p><blockquote>import bpy</blockquote><blockquote>class ApplyWithShapeKeys(bpy.types.Operator):<br> “””Tooltip”””<br> bl_idname = “object.applywithshapekeys”<br> bl_label = “Apply Modifiers With Shapekeys”</blockquote><blockquote>def execute(self, context):</blockquote><blockquote>selection = bpy.context.selected_objects</blockquote><blockquote>for obj in selection:<br> if obj.type == “MESH”:</blockquote><blockquote># lists store temporary objects created from shapekeys<br> shapeInstances = []<br> shapeValues = []</blockquote><blockquote># Deactivate any armature modifiers<br> for mod in obj.modifiers:<br> if mod.type == ‘ARMATURE’:<br> obj.modifiers[mod.name].show_viewport = False</blockquote><blockquote>for shape_key in obj.data.shape_keys.key_blocks:<br> # save old shapekey value to restore later. Will set to 0 temporarily<br> shapeValues.append(shape_key.value)<br> shape_key.value = 0.0</blockquote><blockquote>i = 0<br> for shape_key in obj.data.shape_keys.key_blocks:</blockquote><blockquote># ignore basis shapekey<br> if i != 0:<br> # make sure only relevant object is selected and active<br> bpy.ops.Object.select_all(action=”DESELECT”)<br> obj.select_set(state=True)<br> context.view_layer.objects.active = obj</blockquote><blockquote># make sure only this shape key is set to 1<br> shape_key.value = 1.0</blockquote><blockquote># duplicate object with only one shape key active. Blender does the rest<br> bpy.ops.Object.duplicate(linked=False, mode=”TRANSLATION”)<br> bpy.ops.Object.convert(target=”MESH”)<br> shapeInstances.append(bpy.context.active_object)</blockquote><blockquote>bpy.context.object.name = shape_key.name</blockquote><blockquote>bpy.ops.Object.select_all(action=”DESELECT”)<br> obj.select_set(state=True)<br> context.view_layer.objects.active = obj</blockquote><blockquote>shape_key.value = 0.0</blockquote><blockquote>i = i + 1</blockquote><blockquote>context.view_layer.objects.active = obj</blockquote><blockquote># create final object<br> bpy.ops.Object.duplicate(linked=False, mode=”TRANSLATION”)<br> newobj = bpy.context.active_object<br> newobj.name = obj.name + “_APPLIED”</blockquote><blockquote># clear all old shapekeys from new object<br> newobj.shape_key_clear()</blockquote><blockquote># apply all modifiers on new object<br> for mod in newobj.modifiers:<br> if mod.name != “Armature”:<br> bpy.ops.object.modifier_apply(apply_as=’DATA’, modifier=mod.name)</blockquote><blockquote># iterate all temporary saved shapekey objects, select only that and the final object and join them<br> for shapeInstance in shapeInstances:<br> bpy.ops.object.select_all(action=”DESELECT”)<br> newobj.select_set(state=True)<br> shapeInstance.select_set(state=True)<br> context.view_layer.objects.active = newobj</blockquote><blockquote>result = bpy.ops.object.join_shapes()</blockquote><blockquote># reset old shape key values<br> i = 0<br> for shape_key in newobj.data.shape_keys.key_blocks:<br> if i != 0:<br> shape_key.value = shapeValues[i]<br> i = i + 1</blockquote><blockquote># reset old shape key values<br> i = 0<br> for shape_key in obj.data.shape_keys.key_blocks:<br> if i != 0:<br> shape_key.value = shapeValues[i]<br> i = i + 1</blockquote><blockquote># delete temporary objects <br> bpy.ops.Object.select_all(action=”DESELECT”)<br> for shapeInstance in shapeInstances:<br> shapeInstance.select_set(state=True)</blockquote><blockquote>bpy.ops.object.delete(use_global=False)</blockquote><blockquote># redeactivate armature modifiers<br> for mod in obj.modifiers:<br> if mod.type == ‘ARMATURE’:<br> obj.modifiers[mod.name].show_viewport = True</blockquote><blockquote>for mod in newobj.modifiers:<br> if mod.type == ‘ARMATURE’:<br> newobj.modifiers[mod.name].show_viewport = True</blockquote><blockquote>return {“FINISHED”}</blockquote><blockquote>def register():<br> bpy.utils.register_class(ApplyWithShapeKeys)</blockquote><blockquote>def unregister():<br> bpy.utils.unregister_class(ApplyWithShapeKeys)</blockquote><blockquote>if __name__ == “__main__”:<br> register()</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NfsI57ge-Vi_j7d8jAmVuA.png" /></figure><p>In Blender, Open the scripting workplace, click “Text” &gt; “Open” and open the script you just saved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kwpiRXFRBD4gX1RLxD-ohA.png" /></figure><p>Now click “Run Script” (found in the top right) which will add the script to the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_DpO9YMeKKb0I4NzNPabDw.png" /></figure><p>You will now need to go back to the “Layout” workplace (making sure you’re still in object mode) and select your object with the subdivision modifier. Now press “fn” + “f3” which will bring up a search box. Search for the function you just created by typing “Apply Modifiers With Shapekeys” and click on the corresponding result. Blender will wait a few seconds while it’s loading and then create a new object called (your object name)_APPLIED. This new object should now have your subdivision modifiers applied, so you can either hide or remove your old object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZdzSDW6b9e9K3JDJAOzM_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMY1m8qzzOcrChYqTdzing.png" /></figure><p>We’re now ready to export the 3D character out of Blender into a .dae file. First, we want to select and highlight all of the objects we wish to export. In my case, this is the head_APPLIEDobjects. Now click “File” &gt; “Export” &gt; “Collada (default) (.dae)”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aACTfi9cAo4Jd6JBRMAUTA.png" /></figure><p>On the left, we have some settings, for which I chose:</p><ul><li>“Selection Only”</li><li>“Include Children”</li><li>“Include Shape Keys”</li></ul><p>The other settings don’t matter too much but may vary depending on your character. Now, make sure it is exporting to an appropriate location and click “Export” &gt; “COLLADA.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVLyOVbf-FE7apJ_NtQSbA.png" /></figure><blockquote><strong><em>B)</em> <em>Make sure all of your shape keys exists into the exported .dae file:</em></strong></blockquote><p>Somehow Blender does not export the file with the correct keys &amp; values needed to import seamlessly into Xcode.</p><p>After Googling, I found this <a href="https://github.com/JonAllee/ColladaMorphAdjuster">tool</a> helped me resolve this issue. Thanks JonAllee</p><p>Download this tool from GitHub and open it up in Xcode. Select “Scheme” &gt; “Edit Scheme.”</p><p>Now go to “Run” &gt; “Arguments” &gt; “Arguments Passed On Launch.” We want to pass three arguments:</p><ul><li>The path to the input file</li><li>“-o”</li><li>The path to the output file</li></ul><p>You need to make sure these are in the correct order. Here is an example of how mine looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BhIRFa9Shb5QQIv7r6ja1A.png" /></figure><p>Close the dialog box and then run the code.</p><p>If all went well, you should have an output log showing the number of all of the geometries (blend shapes) like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Maqn8DjqHzE-5qvnn9iY_w.png" /></figure><p>You can check the .dae file by previewing it to make sure the existence of modifiers &amp; shape keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oIlChjdigXsF89J2WGUjg.png" /></figure><h3>3) Import .dae file into Xcode :</h3><p>Now, drag and drop the output .dae file generated from the ColladaMorphAdjuster above into the .scnassets folder. Click on the .dae file and you should see your 3D character.</p><p>You now want to export the .dae as a .scn file. This is done by clicking “Editor” &gt; “ Convert to SceneKit scene file format (.scn).” I normally select “Duplicate” as this will keep the .dae file in case you wish to use it for another reason in your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RwOMNp2jkkjRbx3NeZRtsQ.png" /></figure><p>Now, click on your .scn file.</p><p>Check whether all the shape keys (Geometry Morpheus) exist in the scn file or not. If not then again go back to Blender &amp; repeat the above steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vqlpzMmKXqQU_wSz4u3J7A.png" /></figure><p>Modify the Position, Euler &amp; Scale transform properties of the model &amp; set it to the one below. I chose Scale as 0.2 (20cm).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqLlDT598BbPn7YISXLpJQ.png" /></figure><p>You can add material to the model. I chose Shading as “Physically Based” &amp; Diffuse as “White”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3aSX3WrSzbl-JVDCN_3qQ.png" /></figure><h3>4) Code:</h3><p>You can download my sample project FaceAnimoji.</p><p>In viewDidLoad of ViewController.swift,</p><p>a)Load scene &amp; access rootNode of the scene. Also, set ViewController as delete of ARSCNView</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AB6Wk7fF6CR1hoqyqTcOoQ.png" /></figure><p>b)ARKit asks us to provide node for detected anchor. In our case we are interested in faces i.e ARFaceAnchor. So, if any face is detected, always return our scene.rootNode to render.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmJiZp4rt95Xy0qOHqytOQ.png" /></figure><p>c) On every scene render, ARKit returns 50 blendshape location values. Since our model blendshape key names are equal to ARKit blendshape keys name, we just need to set corresponding weights returned by ARKit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5q-DJq2heyuXqVJyxsaT4Q.png" /></figure><p>Build &amp; Run the project on iPhone X or greater with true depth camera.</p><p>You can see model mimics user’s face movements. Since I have defined 30 blendshapes in my model, some of the expressions are missing like cheek, tongue out etc.</p><p>I hope you have enjoyed this tutorial and have fun playing around with your 3D characters.</p><p>You can download my sample project <strong>FaceAnimoji</strong> from <a href="https://github.com/ashuw550i/FaceAnimoji">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*M9Ag7Djy7mnxlxc2bW1pPg.gif" /></figure><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4691e04bfc42" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>