Draw a sister with you | Valentine's Day special edition

Happy Valentine's Day! He went to the annual Valentine's Day, this year is still a new object? To use the code to draw a bar.

He said engage to engage, Let's go ~

Implementation

Based on the Android platform, use Kotlin + C ++ way to achieve.

The upper layer is responsible for UI-related, and monitor user interaction events, and to make a specific response by Native JNI layer.

Native responsible for parsing the layer model view transform, Shader rendering logic.

Here Insert Picture Description

The main JNI List

// Surface 创建
external fun nativeSurfaceCreated(assertManager: AssetManager, modelDir: String, modelFile: String, animFile: String)
// Surface 调整
external fun nativeSurfaceChanged(width: Int, height: Int)
// Surface 绘制当前帧
external fun nativeDrawFrame()
// 通知触摸事件
external fun nativeTouchEvent(deltaX: Float, deltaY: Float)
// 相关生命周期事件
external fun nativeDestroy()
external fun nativePause()
external fun nativeResume()

3D analytical model

OpenGL 2.0 introduces the concept of the pipeline, the pipeline from the process point of view, after rasterization, one becomes a point, and then colored by Fragment Shader.

Here Insert Picture Description

So to draw complex 3D models, ultimately turn into numerous points to render. In fact, the point may excel line, the line can be connected to a surface, the surface can spell a complete object.

So, we need to turn 3D models into numerous point coordinates before they can render.

Assimp (Open Asset Import Library) are a very powerful open source library that supports the 40 kinds of 3D model file format is converted into a uniform format, and then re-parsed according to this unified format can be.

Assimp on the official website, the public can not put a number of articles outside the chain, you can direct Google needs to search.

Assimp the model file into a unified format, which can be understood as a binary tree, starting from the Root Node, gradually diverge. Root Node assume the position of the heart, then that is spread from the heart to the body.

Through the breadth-first traversal of a binary tree, you can get all the node information, coordinate information and then get all the points. And then to the OpenGL rendering.

Skeletal animation

After parsing the 3D model coordinate information, combined with the texture information, you can get a static picture. So how do animation it?

The so-called animation is actually a series of orderly change of coordinates of each point of the point, the human eye looked like a normal animation.

Here Insert Picture Description

Assimp parsed unified format, roughly a binary tree, binary tree line between two vertices, called "bones", doing animation, bones do affine transformation, driven by near the "muscle" to follow linkage, like people to do sports, exercise bones with flesh.

Skeletal muscle groups to achieve analogy driven animation, called "skeletal animation."

Camera perspective transform view transformed with

The most intuitive feel the 3D effect is "near the far smaller."

Camera view transformed, used to do the rotation.

Here Insert Picture Description

Now, you drew an object

Here Insert Picture Description

Published 26 original articles · won praise 1 · views 40000 +

Guess you like

Origin blog.csdn.net/Hello_Chillax/article/details/104329759