utils_17.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. def generateHuman(cloth_list, person_id, sex):
  2. haveAcc = 0
  3. # load acc
  4. hair = open('modeleTxt/hair.txt', 'r').readlines()
  5. shoe = open('modeleTxt/shoe.txt', 'r').readlines()
  6. pifu = open('modeleTxt/skin.txt', 'r').readlines()
  7. if not os.path.exists(person_save_Folder):
  8. os.makedirs(person_save_Folder)
  9. if sex > 0:
  10. Gender1 = 1000000
  11. else:
  12. Gender1 = 0
  13. # setting
  14. Gender = '%.6f' % (Gender1 / 1000000)
  15. Muscle = '%.6f' % (random.randint(0, 1000000) / 1000000)
  16. African_1 = random.randint(0, 1000000)
  17. African = '%.6f' % (African_1 / 1000000)
  18. Asian_1 = random.randint(0, 1000000 - African_1)
  19. Asian = '%.6f' % (Asian_1 / 1000000)
  20. Caucasian = '%.6f' % ((1000000 - Asian_1 - African_1) / 1000000)
  21. if Gender1 > 1000000 / 2:
  22. m_height = random.gauss(170, 5.7) / 200
  23. while m_height > 1:
  24. m_height = random.gauss(170, 5.7) / 200
  25. Height = '%.6f' % (m_height)
  26. else:
  27. m_height = random.gauss(160, 5.2) / 200
  28. while m_height > 1:
  29. m_height = random.gauss(160, 5.2) / 200
  30. Height = '%.6f' % (m_height)
  31. BreastSize = '%.6f' % (random.randint(0, 70) / 100)
  32. Age = '%.6f' % (random.randint(20, 90) / 100)
  33. BreastFirmness = '%.6f' % (random.randint(30, 100) / 100)
  34. Weight = '%.6f' % (random.randint(0, 1000000) / 1000000)
  35. file_name = 'B' + str(person_id)
  36. # creating person file
  37. f = open(person_save_Folder + file_name + ".mhm", 'a')
  38. f.write('# Written by MakeHuman 1.1.1\n')
  39. f.write('version v1.1.1\n')
  40. f.write('tags ' + file_name + '\n')
  41. f.write('camera 0.0 0.0 0.0 0.0 0.0 1.0\n')
  42. f.write('modifier macrodetails-universal/Muscle ' + Muscle + '\n')
  43. f.write('modifier macrodetails/African ' + African + '\n')
  44. f.write('modifier macrodetails-proportions/BodyProportions 0.500000\n')
  45. f.write('modifier macrodetails/Gender ' + Gender + '\n')
  46. f.write('modifier macrodetails-height/Height ' + Height + '\n')
  47. f.write('modifier breast/BreastSize ' + BreastSize + '\n')
  48. f.write('modifier macrodetails/Age ' + Age + '\n')
  49. f.write('modifier breast/BreastFirmness ' + BreastFirmness + '\n')
  50. f.write('modifier macrodetails/Asian ' + Asian + '\n')
  51. f.write('modifier macrodetails/Caucasian ' + Caucasian + '\n')
  52. f.write('modifier macrodetails-universal/Weight ' + Weight + '\n')
  53. f.write('skeleton cmu_mb.mhskel\n')
  54. f.write('eyes HighPolyEyes 2c12f43b-1303-432c-b7ce-d78346baf2e6\n')
  55. # adding clothes
  56. if Gender1 > 1000000 / 2:
  57. f.write(hair[random.randint(0, len(hair) - 1)])
  58. else:
  59. f.write(hair[random.randint(0, len(hair) - 1)])
  60. f.write(shoe[random.randint(0, len(shoe) - 1)])
  61. for i in range(0, len(cloth_list)):
  62. f.write(cloth_list[i] + '\n')
  63. f.write('clothesHideFaces True\n')
  64. f.write(pifu[random.randint(0, len(pifu) - 1)])
  65. f.write('material Braid01 eead6f99-d6c6-4f6b-b6c2-210459d7a62e braid01.mhmat\n')
  66. f.write('material HighPolyEyes 2c12f43b-1303-432c-b7ce-d78346baf2e6 eyes/materials/brown.mhmat\n')
  67. f.write('subdivide False\n')