The Gene of Bitizens
2019-03-31 15:02 AndrewCja 阅读(329) 评论(0) 编辑 收藏 举报1. Summary
This document is about the general idea of the architectural design of the Bitizens game, the detail logic in the code may be more complicated than what is documented here, and also the actual logic may be somewhat different from what is documented here. For more details and the acurate logic, please refer to the code. Thx!
2. Face
2.1. UI
2.2. Data Structure
The actual data structure is far more complicated than what is demoed below, for details, please refer to the code in the project.
{
"GenePool": {
"Face": {
"00": "3DModel00",
"01": "3DModel01",
"02": "3DModel02"
},
"Eyes": {
"00": {
"Eye_L_1": { "PX": 0, "PY": 0, "PZ": 0 },
"Eye_R_1": { "PX": 0, "PY": 0, "PZ": 0 },
"Eye_L_2": { "PX": 0, "PY": 0, "PZ": 0 },
... ...
},
"01": {
},
... ...
},
"Nose": { },
"Mouth": { },
"Eyebrow": { },
"Cheeks": { },
"Jaw": { },
"Chin": { }
}
}
2.3. Description
The data structure is in JSON format.
2.3.1. Face DNA
Each face part has a gene, which is a 2-digit number, so we have 100 possibilities for each part (Considering that we can have more than one 3D models, the number of possibilities for each face part is actually "100 x the number of models"). The whole DNA for an avatar face is a combination of each gene from each face part.
Face DNA is a 30-digit number, we may use the first say 18 digits for the moment, and the left 12 digits will be reserved for future extension. The last 12 digits that are not used should be placed with twelve 0s.
So the DNA for an avatar face may be like: 000201902214296466 + twelve 0s
Face00Eyes02Nose01Mouth90Eyebrow22Cheeks14Jaw29Chin64Brow66 + twelve 0s
2.3.2. Gene Pool
Our artists need to list out all the possible genes for each face part in a data file using the structure above.
On the UI, each gene for a face part is represented by an icon. We can name the image file of an icon to be “face part name plus a 2-digit”. For example: Nose99.jpg
"Nose_2": The name of a specific bone.
"PX", "PY", "PZ": XYZ values for each axis of the bone position.
"SX", "SY", "SZ": XYZ values for each axis of the bone scale.
2.3.3. Main Workflow
- Loading
○ User hasn’t created an avatar before
First we generate a random DNA number, then find the corresponding settings in our gene pool file. Finally we use the settings to update the UI and the avatar.
Note: Say we may have only 7 different types of noses as designed (even though 2 digits allow 100 possible options), and suppose that the 2 digits generated randomly for the nose gene are 83. To map 83 to a nose type, we do 83 % 7 = 6. So this avatar would have the 06 gene for the nose.
○ User has created an avatar before
First, we access Blockchain for the data of the current user, and then use the DNA number from Blockchain to find the corresponding settings in our gene pool file. Finally we use the settings to update the UI and the avatar.
- Customizing
When user clicks on a face part icon on the UI, first we find the icon name, say Nose09.jpg, then we strip out the gene number 09, finally we look up the gene pool file to find the 09 gene data, and use the data to update the corresponding bones in the face model.
- Save
Find out all the gene numbers for all face parts user has selected on the UI, then combine them to be a complete DNA and save it on Blockchain.
2.4. Whole DNA
The whole DNA of an avatar will be a 76-digit number, which consists of 4 parts: Face DNA, Body DNA, Skin DNA, Gender DNA.
DNA of an avatar will be stored on Blockchain.
2.4.1. Face DNA
Face DNA is a x-digit number.
2.4.2. Body DNA
Body DNA is a y-digit number.
2.4.3. Skin DNA
Skin DNA is a z-digit number.
2.4.4. Gender DNA
Gender DNA is represented by 1-digit. 0 represents female, 1 represents male.
3. MVC Pattern
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?