欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

The Gene of Bitizens

程序员文章站 2022-05-29 11:57:13
1. Summary The document is about the general idea of the architecture design of the Bitizens game, the detail logic is more complicated than what is d ......

 1.          summary

the document is about the general idea of the architecture design of the bitizens game, the detail logic is more complicated than what is documented here, and the actual logic will be somewhat different from what is documented here. for details and the acurate logic, please refer to the code.

 2.          face

               2.1.          ui

 The Gene of Bitizens

               2.2.          data structure

the actual 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": {

           },

           "02": {

           }

       },

       "nose": {

           "00": {

               "nose": { "sx": 0, "sy": 0, "sz": 0 },

               "nose_1": { "sx": 0, "py": 0, "pz": 0 },

               "nose_2": { "sx": 0, "py": 0, "pz": 0 },

               "nose_3": { "sx": 0, "py": 0, "pz": 0 }

           }

       },

       "mouth": {

           "00": {

               "mouth_l": { "px": 0, "py": 0, "pz": 0 },

               "mouth_r": { "px": 0, "py": 0, "pz": 0 },

               "mouth_t": { "sx": 0, "py": 0, "pz": 0 },

               "mouth_b": { "sx": 0, "py": 0, "pz": 0 }

           }

       },

       "eyebrow": {

           "00": {

               "brow_l_1": { "px": 0, "py": 0, "pz": 0 },

               "brow_r_1": { "px": 0, "py": 0, "pz": 0 }

           }

       },

       "cheeks": {

           "00": {

               "cheek_l_1": { "px": 0, "py": 0, "pz": 0 },

               "cheek_r_1": { "px": 0, "py": 0, "pz": 0 }

           }

       },

       "jaw": {

           "00": {

               "jaw_l": { "px": 0, "py": 0, "pz": 0 },

               "jaw_r": { "px": 0, "py": 0, "pz": 0 }

           }

       },

       "chin": {

           "00": {

               "chin": { "sx": 0, "py": 0, "pz": 0 }

           }

       },

       "brow": {

           "00": {

               "brow_l_1": { "px": 0, "py": 0, "pz": 0 },

               "brow_r_1": { "px": 0, "py": 0, "pz": 0 }

           }

       }

   }

}

               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 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

 The Gene of Bitizens

our artists need to list out all the possible genes for each face part in a data file using the above structure.

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

 The Gene of Bitizens

"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 click 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

 The Gene of Bitizens

 

 The Gene of Bitizens