<?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 Ilnar Karimov on Medium]]></title>
        <description><![CDATA[Stories by Ilnar Karimov on Medium]]></description>
        <link>https://medium.com/@afeozzz?source=rss-a848973ecc78------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*y-_v0HA_vdgvgQeJoEinqQ.jpeg</url>
            <title>Stories by Ilnar Karimov on Medium</title>
            <link>https://medium.com/@afeozzz?source=rss-a848973ecc78------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:14:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@afeozzz/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[Interactive 3D cards for Revolut Android app]]></title>
            <link>https://medium.com/revolut/how-we-implemented-3d-cards-in-revolut-fa84203a8f42?source=rss-a848973ecc78------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa84203a8f42</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Ilnar Karimov]]></dc:creator>
            <pubDate>Tue, 28 May 2019 13:10:11 GMT</pubDate>
            <atom:updated>2019-07-25T10:42:30.422Z</atom:updated>
            <content:encoded><![CDATA[<p>At Revolut we put customer experience at the heart of everything we do, with the aim of bringing pleasure through simple designs and careful execution. You can probably imagine our excitement, then, as we introduce an update to our card order flow. In the latest version of the Revolut app, you’ll be able to choose your card from an interactive 3D model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On0LoJTwX0yVPDuvedDGlw.png" /></figure><p>This was an interesting challenge for us since it was our first time using a 3D physics-based engine to create a feature. We think it turned out pretty well!</p><p>Entering the card order section of the app, you’ll be able to choose from two materials — plastic and metal. From there you’ll be able to choose a color, and whether you want Visa or Mastercard (depending on your country).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*xznt23FOq_ChY9uEB7xInQ.gif" /><figcaption>The new card order flow</figcaption></figure><p>Let’s take a look at how we reached this milestone, and explore some of the challenges along the way.</p><h3>Rendering</h3><p>Where to begin?<strong> </strong>First, we tried taking a <a href="https://developer.android.com/reference/android/opengl/GLSurfaceView.html">GLSurfaceView</a>, creating our own<a href="https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html"> Renderer </a>and drawing the card using OpenGL ES. But this approach has some drawbacks:</p><ul><li>Not all mobile developers are familiar with OpenGL, meaning more time spent on training and problems with sustainability</li><li>Android supports OpenGL ES 3.1 already but still has a terrible API. The result? Lots of boilerplate, mathematics and hair pulling</li></ul><p>So we thought we’d find a better solution. A bit of searching led us to a few options:</p><ul><li><a href="https://code.google.com/archive/p/min3d/">min3d</a> <em>— </em>is a lightweight 3d library/framework for Android using Java with OpenGL ES targeting compatibility with Android v1.5/OpenGL ES 1.0 and higher. Plus, min3d has a better API, but was built in 2010 and is no longer supported</li><li><a href="https://github.com/libgdx/libgdx">Libgdx<em> </em></a><em>— </em>is a fully Java game development framework. It provides a lot of features but it’s too large for a FinTech application that wants only to rotate a 3D card</li><li><a href="https://github.com/google/filament">Filament </a>— is a real-time physics-based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL. It provides a set of tools and APIs for developers to help them easily create high-quality 2D and 3D rendering. You can render incredible images with it, and we highly recommend having a play with it.</li></ul><p>Filament is currently used in the <a href="https://developers.google.com/ar/develop/java/sceneform/">Sceneform</a> library which together with <a href="https://developers.google.com/ar/">ARCore</a>, helps to render realistic 3D scenes in AR and non-AR apps, without having to learn OpenGL. Let’s give it a try!</p><p>Sceneform supports 3D assets in the following formats:</p><ul><li><a href="https://en.wikipedia.org/wiki/Wavefront_.obj_file">.obj</a></li><li><a href="https://en.wikipedia.org/wiki/GlTF">.gltf</a></li><li><a href="https://en.wikipedia.org/wiki/FBX">.fbx</a> (including animations)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vk5O5KwsHzqogH1DxLS1gw.gif" /><figcaption>low poly card.obj in the preview of <a href="https://developers.google.com/ar/develop/java/sceneform/import-assets">Sceneform Android Studio Plugin</a></figcaption></figure><p>To include our card model to project, we need to linkify our assets and convert them to .sfbfile through <a href="https://developers.google.com/ar/develop/java/sceneform/import-assets">Android Studio Plugin</a>.</p><p>As a part of assets, we should create our own <a href="https://developers.google.com/ar/develop/java/sceneform/custom-material">material</a>. A material defines the visual appearance of a surface. It’s kind of shaders.</p><p>Our .mat looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00315e654fc79ee0ac190b0e99b9972b/href">https://medium.com/media/00315e654fc79ee0ac190b0e99b9972b/href</a></iframe><ul><li>baseColor — defines the perceived color of an object</li><li>roughness — controls the perceived smoothness of the surface</li><li>metallic — defines whether the surface is metallic or non-metallic</li><li>reflectance — this property can be used to control the specular intensity. It only affects non-metallic surfaces.</li></ul><p>Having defined this, we created textures for the <a href="https://en.wikipedia.org/wiki/UV_mapping">UV mapping</a> for each attribute, you can see one of them below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*W6ijvHP1Bdpflc08QDy-3A.jpeg" /><figcaption>diffuse texture</figcaption></figure><p>To create each texture, we used the Texture.builder() class, whereby you need to pass the source of your asset and usage type with one of Texture.Usage constants: COLOR, NORMAL, DATA</p><pre><strong>internal fun </strong>Context.loadTexture(<br>    sourceUri: Uri,<br>    usage: Texture.Usage<br>): Texture.Builder =<br>    Texture.builder()<br>        .setSource(<strong>this</strong>, Uri.parse(uri))<br>        .setUsage(usage)<br>        .setSampler(<br>            Texture.Sampler.builder()<br>                .setMagFilter(Texture.Sampler.MagFilter.<strong>LINEAR</strong>)<br>                .setMinFilter(Texture.Sampler.MinFilter.<strong>LINEAR_MIPMAP_LINEAR</strong>)<br>                .build()<br>        )</pre><p>Next, we can collect all of the necessary textures and apply them to our loaded card model:</p><pre><strong>val </strong>cardTextures = availableTextures.map <strong>{ </strong>texture <strong>-&gt; </strong>loadTexture(texture.<em>path</em>, texture.<em>usage</em>) <strong>}</strong></pre><pre>ModelRenderable.builder()<br>    .setSource(<strong>context</strong>, Uri.parse(MODEL_SFB_PATH))<br>    .build()<br>    .thenApply <strong>{ </strong>model <strong>-&gt;<br>        </strong>cardTextures.forEach <strong>{ </strong>result <strong>-&gt; </strong>model.<em>material</em>.setTexture(result.<em>name</em>, result.<em>texture</em>) <strong>}<br>    }</strong></pre><p>And that’s it! Now we are ready to build our own scene.</p><p>Define layout.xml</p><pre>&lt;<strong>com.google.ar.sceneform.SceneView<br>    android:id=&quot;@+id/sceneView&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot; </strong>/&gt;</pre><p>And add card node to an existing scene:</p><pre><strong>private val card3dNode </strong>= Node().<em>apply </em><strong>{<br>    </strong><em>localPosition </em>= Vector3(<strong>CARD_POSITION_X_AXIS</strong>, <strong>CARD_POSITION_Y_AXIS</strong>, <strong>CARD_POSITION_Z_AXIS</strong>)<br>    <em>localRotation </em>= getRotationQuaternion(<strong>CARD_STARTING_Y_AXIS_ANGLE</strong>.toFloat())<br>    <em>name </em>= <strong>CARD_ID<br>}</strong></pre><pre><strong>fun </strong>addCardToScene(modelRenderable: ModelRenderable, currentCard: CardRender) {<br>    modelRenderable.<em>material </em>= currentCard.<strong>value<br>    </strong><em>with</em>(<strong>card3dNode</strong>) <strong>{<br>        </strong>setParent(sceneView.<em>scene</em>)<br>        <em>renderable </em>= modelRenderable<br>        <em>localScale </em>= modelRenderable.<em>computeScaleVector</em>(targetSize = 1.5f)<br>        currentCard.<em>renderCard</em>()<br>    <strong>}</strong></pre><pre><em>with</em>(sceneView.<em>scene</em>) <strong>{<br>        </strong><em>camera</em>.<em>localScale </em>= Vector3(<strong>CAMERA_SCALE_WIDTH</strong>, <strong>CAMERA_SCALE_HEIGHT</strong>, <strong>CAMERA_FOCAL_LENGTH</strong>)<br>        <em>camera</em>.<em>localPosition </em>= Vector3(<strong>CAMERA_POSITION_X_AXIS</strong>, <strong>CAMERA_POSITION_Y_AXIS</strong>, <strong>CAMERA_POSITION_Z_AXIS</strong>)</pre><pre><em>sunlight</em>?.<em>let </em><strong>{<br>            it</strong>.<em>worldPosition </em>= Vector3.back()<br>            <strong>it</strong>.<em>light </em>= <strong>cardSceneSunLight<br>        }<br>        </strong>addChild(<strong>card3dNode</strong>)<br>    <strong>}</strong><br>}</pre><h3><strong>Virtual Cards</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*fg-owgdKui_JkSkgZa4EaQ.gif" /><figcaption>virtual cards</figcaption></figure><p>For virtual cards, we wanted to achieve the appearance of transparency. For this, we needed to create a custom material:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56467204c8faa23ecba0c06d513023de/href">https://medium.com/media/56467204c8faa23ecba0c06d513023de/href</a></iframe><p>The most interesting part here is blending . Transparent defines that the material’s output is alpha composited with the render target, using Porter-Duff’s <a href="https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_OVER"><em>source over</em></a> rule. This blending mode assumes pre-multiplied alpha.</p><p>As you may have noticed on the disposable cards, the card numbers (or PAN) have a number changing animation. For this trick, we changed the diffuse texture for a card every second. There are 3 of them.</p><p>Everything can’t be perfect, so we’re faced with some problems and restrictions:</p><ul><li>Sceneform requires minSdkVersion ≥ 24 in due loading of models with CompletableFuture.</li><li>Dynamic texturing. material.setTexture doesn’t allow <a href="https://github.com/google-ar/sceneform-android-sdk/issues/41">changing textures at runtime</a>. The working solution is to create a fake object and copy this material to the real object</li><li>Until v1.8 of SDK there were no ways to set the white colour of the background. We got around this with an additional node and custom materials.</li></ul><h3>Animation</h3><p>As you noticed the card has a physic-basic animation. Android provides to do it via support library.</p><pre>compile <strong>&quot;com.android.support:support-dynamic-animation:28.0.0&quot;</strong></pre><p>The <a href="https://developer.android.com/reference/androidx/dynamicanimation/animation/FlingAnimation.html">FlingAnimation</a> class lets you create a fling animation for an object. To build a fling animation, create an instance of the <a href="https://developer.android.com/reference/androidx/dynamicanimation/animation/FlingAnimation.html">FlingAnimation</a> class and provide an object and the object&#39;s property that you want to animate.</p><pre><strong>abstract class </strong>CardProperty(name: String) : FloatPropertyCompat&lt;Node&gt;(name)</pre><pre><strong>private val rotationProperty</strong>: CardProperty = <strong>object </strong>: CardProperty(<strong>&quot;rotation&quot;</strong>) {<br>    <strong>override fun </strong>setValue(card: Node, value: Float) {<br>        card.<em>localRotation </em>= getRotationQuaternion(value)<br>    }</pre><pre><strong>override fun </strong>getValue(card: Node): Float = card.<em>localRotation</em>.<strong>y<br></strong>}</pre><pre>private <strong>var </strong>animation: FlingAnimation = FlingAnimation(card3dNode, rotationProperty).apply {<br>    friction = FLING_ANIMATION_FRICTION<br>    minimumVisibleChange = DynamicAnimation.MIN_VISIBLE_CHANGE_ROTATION_DEGREES<br>}</pre><p>In a fling gesture detector, we run animation in onFling without any update listener. Just set the velocity and you’re away.</p><pre><strong>class </strong>FlingGestureDetector : GestureDetector.SimpleOnGestureListener() {<br><br>    override <strong>fun </strong>onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean {<br>        <strong>val </strong>deltaX = -(distanceX / screenDensity) / CARD_ROTATION_FRICTION<br>        card3dNode.localRotation = getRotationQuaternion(lastDeltaYAxisAngle + deltaX)<br>        <strong>return true<br>    </strong>}<br><br>    override <strong>fun </strong>onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {<br>        <strong>if </strong>(Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {<br>            <strong>val </strong>deltaVelocity = (velocityX / screenDensity) / CARD_ROTATION_FRICTION<br>            startAnimation(deltaVelocity)<br>        }<br>        <strong>return true<br>    </strong>}<br>}</pre><pre><strong>private fun </strong>startAnimation(velocity: Float) {<br>    <strong>if </strong>(!<strong>animation</strong>.<em>isRunning</em>) {<br>        <strong>animation</strong>.setStartVelocity(velocity)<br>        <strong>animation</strong>.setStartValue(<strong>lastDeltaYAxisAngle</strong>)<br>        <strong>animation</strong>.start()<br>    }<br>}</pre><p>For card rotating, we used alocalRotation property which utilizes <a href="https://en.wikipedia.org/wiki/Quaternion">quaternion</a>. Sceneform has a static method which uses <a href="https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation">Axis–angle representation</a> and calculates quaternion via axisAngle and the desired vector. In our case that&#39;s Vector3(0.0f, 1.0f, 0.0f) .</p><p>But this creates redundant objects in each frame of animation, so we need to copy this method with the existing quaternion and vector:</p><pre><strong>private val quaternion </strong>= Quaternion()<br><strong>private val rotateVector </strong>= Vector3.up()</pre><pre><strong>private fun </strong>getRotationQuaternion(deltaYAxisAngle: Float): Quaternion {<br>    <strong>lastDeltaYAxisAngle </strong>= deltaYAxisAngle<br>    <strong>return quaternion</strong>.<em>apply </em><strong>{<br>        val </strong>arc = toRadians(deltaYAxisAngle)<br>        <strong>val </strong>axis = <em>sin</em>(arc / 2.0)<br>        <strong>x </strong>= <strong>rotateVector</strong>.<strong>x </strong>* axis<br>        <strong>y </strong>= <strong>rotateVector</strong>.<strong>y </strong>* axis<br>        <strong>z </strong>= <strong>rotateVector</strong>.<strong>z </strong>* axis<br>        <strong>w </strong>= cos(arc / 2.0)<br>        normalize()<br>    <strong>}<br></strong>}</pre><h3>Conclusion</h3><p><a href="https://developers.google.com/ar/develop/java/sceneform/">Sceneform</a> is a pretty fresh library but it already has a broad set of functionalities: optimization rendering, powerful API and small runtime. All of these features helped us quickly implement 3D without having to learn OpenGL.</p><p>Kudos to all who took part in this challenge, especially:</p><p><a href="https://dribbble.com/deniskovalev"><em>Denis Kovalev,</em></a><em> </em>incredible with UI/UX<br><a href="https://dribbble.com/dmitrykavalev"><em>Dmitry Kovalev</em></a><em>, </em>inspiring. He created the 3D model and textures<br><em>George Robson,</em> genius owner of the Premium team.<br><em>Ilia Kisliakovskii,</em> one of our back-end heroes<br><em>Mikhail Koltsov and Igor Dudenkov, </em>our beloved iOS guys</p><p><a href="https://www.revolut.com/careers">We’re hiring</a>👨‍💻👩‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa84203a8f42" width="1" height="1" alt=""><hr><p><a href="https://medium.com/revolut/how-we-implemented-3d-cards-in-revolut-fa84203a8f42">Interactive 3D cards for Revolut Android app</a> was originally published in <a href="https://medium.com/revolut">Revolut Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>