Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for exporting body/head separates to VOX file with simplified rig. #10

Open
wants to merge 2 commits into
base: v1.1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added command-line/MeebitRig_simplified.blend
Binary file not shown.
Binary file added command-line/MeebitRig_simplified_visitor.blend
Binary file not shown.
52 changes: 30 additions & 22 deletions command-line/meebit_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def generate(self,file_name,model_counter, vox_size, material_type, palette, mat
#obj.location.y = obj.location.y - vox_size*obj.dimensions.y/2.0
# Object dimension for head might be different, so let's hardcode all the things
#TODO: Will likely impact t-pose
obj.location.y = obj.location.y - 0.25
obj.location.y = obj.location.y - 0.65
#print(f'5 Object location {obj.location.x}, {obj.location.y},{obj.location.z}')


Expand Down Expand Up @@ -591,24 +591,31 @@ def import_meebit_vox_addons(path, bodyMesh,options):
print("Processing add-on file " + addonFile )
addonMesh = import_meebit_vox(addonFile,options)

# Before joining, we need to make sure there is no overlapping voxels.
# We do this by creating a boolean modifier with the add-on
bodyMesh= bpy.data.objects['00001_MALE_BODY_VRM']
bodyMesh.select_set(True)
bpy.context.view_layer.objects.active = bodyMesh
addonMesh= bpy.data.objects['00001_MALE_BODY_VRM_addon_head']
addonMesh.select_set(False)
booleanModifier = bodyMesh.modifiers.new(name='booly_'+addonMesh.name, type='BOOLEAN')
booleanModifier.object = addonMesh
booleanModifier.operation = 'DIFFERENCE'
bpy.ops.object.modifier_apply(modifier=booleanModifier.name)

# Do the join
bpy.ops.object.select_all(action='DESELECT')
addonMesh.select_set(True)
bodyMesh.select_set(True)
bpy.context.view_layer.objects.active = bodyMesh
bpy.ops.object.join()
# Disabling Blender boolean operations since we are now handling in the vox files themselves
if False:
# Before joining, we need to make sure there is no overlapping voxels.
# We do this by creating a boolean modifier with the add-on
# bodyMesh= bpy.data.objects['00001_MALE_BODY_VRM']
bodyMesh.select_set(True)
bpy.context.view_layer.objects.active = bodyMesh
# addonMesh= bpy.data.objects['00001_MALE_BODY_VRM_addon_head']
addonMesh.select_set(False)
print("Addon mesh name: "+addonMesh.name)
booleanModifier = bodyMesh.modifiers.new(name='booly_'+addonMesh.name, type='BOOLEAN')
booleanModifier.object = addonMesh
booleanModifier.operation = 'DIFFERENCE'
bpy.ops.object.modifier_apply(modifier=booleanModifier.name)

if addonMesh:
# Do the join
bpy.ops.object.select_all(action='DESELECT')
addonMesh.select_set(True)
bodyMesh.select_set(True)
bpy.context.view_layer.objects.active = bodyMesh
bpy.ops.object.join()
else:
bodyMesh.select_set(True)
bpy.context.view_layer.objects.active = bodyMesh

# Only execute if there is an armature as parent to the body mesh
if bodyMesh.parent:
Expand Down Expand Up @@ -653,7 +660,7 @@ def import_meebit_vox(path, options):
file_size = os.path.getsize(path)

palette = []
materials = [[0.5, 0.0, 0.0, 0.0] for _ in range(255)] # [roughness, metallic, glass, emission] * 255
materials = [[1.0, 0.0, 0.0, 0.0] for _ in range(255)] # [roughness, metallic, glass, emission] * 255

# Makes sure it's supported vox file
assert (struct.unpack('<4ci', file.read(8)) == (b'V', b'O', b'X', b' ', 150))
Expand Down Expand Up @@ -798,8 +805,9 @@ def import_meebit_vox(path, options):

bsdf = nodes["Principled BSDF"]
bsdf.inputs["Base Color"].default_value = col

bsdf.inputs["Roughness"].default_value = materials[id][0]

# Force 1.0 roughness to avoid specular highlights
bsdf.inputs["Roughness"].default_value = 1.0
bsdf.inputs["Metallic"].default_value = materials[id][1]
bsdf.inputs["Transmission"].default_value = materials[id][2]
bsdf.inputs["Emission Strength"].default_value = materials[id][3] * 20
Expand Down
2 changes: 1 addition & 1 deletion command-line/meebit_export_to_glb.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MeebitImportOption(object):
options.cleanup_mesh=True
options.create_lights=False
options.join_meebit_armature=True
options.scale_meebit_armature= True
options.scale_meebit_armature= False
options.organize=True
options.create_volume=False
options.model_counter=0
Expand Down
41 changes: 22 additions & 19 deletions command-line/meebit_export_to_vrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class MeebitImportOption(object):
options.optimize_import_for_type='VRM'
#options.material_type='Tex'
options.mtoon_shader= True
options.shade_smooth_meebit= True
options.shade_smooth_meebit= False
options.gamma_correct= True
options.gamma_value= 2.2
options.override_materials = False
Expand Down Expand Up @@ -142,18 +142,20 @@ class MeebitImportOption(object):

try:
# Do screenscraping from ll site for owner wallet
print(f'Making HTTP request to https://meebits.larvalabs.com/meebits/detail?index={meebitId}')
response = requests.get(f'https://meebits.larvalabs.com/meebits/detail?index={meebitId}')
ownerWallet = re.search('account.address=([^"]*)',response.text).group(1)
# print(f'Making HTTP request to https://meebits.larvalabs.com/meebits/detail?index={meebitId}')
# response = requests.get(f'https://meebits.larvalabs.com/meebits/detail?index={meebitId}')
# ownerWallet = re.search('account.address=([^"]*)',response.text).group(1)

meebitUrl = f'https://meebits.larvalabs.com/meebits/detail?index={meebitId}'

# Set these values in blender for the VRM export add-on to include them
meebitArmature = bpy.data.objects['MeebitArmature']
meebitArmature['version'] = '0.9.3' # matches the meebit blender add-on version
meebitArmature['author'] = ownerWallet # wallet id for the owner when the VRM was created
meebitArmature['contactInformation'] = f'https://meebits.larvalabs.com/meebits/detail?index={meebitId}' # To be update to metaverse sign-up info
meebitArmature['author'] = meebitUrl # wallet id for the owner when the VRM was created
meebitArmature['contactInformation'] = meebitUrl # To be update to metaverse sign-up info
meebitArmature['reference'] = 'https://meebitsdao.world/' # meebits dao promotion
meebitArmature['title'] = f'Meebit #{meebitId}' # meebit number reference
meebitArmature['otherPermissionUrl'] = f'https://meebits.larvalabs.com/meebits/detail?index={meebitId}' # meebit url
meebitArmature['otherPermissionUrl'] = meebitUrl # meebit url
meebitArmature['otherLicenseUrl'] = 'https://meebits.larvalabs.com/meebits/termsandconditions' # meebits terms and conditions
# Leave default value of these for now
# meebitArmature['allowedUserName': 'OnlyAuthor']
Expand All @@ -165,18 +167,19 @@ class MeebitImportOption(object):
print("Failed to set VRM metadata")
print(e)

exportFilename = fileNameNoEnding+ '.vrm'
exportFilename = fileNameNoEnding.replace("_vrm", "")+ '.vrm'
bpy.ops.export_scene.vrm('EXEC_DEFAULT', filepath=exportFilename)
print("Meebit VRM successfully written to " + exportFilename)

try:
#Get photo as well
print(f'Making HTTP request to https://meebits.larvalabs.com/meebitimages/characterimage?index={meebitId}&type=full')
response = requests.get(f'https://meebits.larvalabs.com/meebitimages/characterimage?index={meebitId}&type=full')
with open(fileNameNoEnding+ '.jpg',"wb") as file:
file.write(response.content)
except Exception as e:
print("Failed to set VRM metadata")
print(e)

print("Don't forget to follow @MeebitsDAO")
if False:
try:
#Get photo as well
print(f'Making HTTP request to https://meebits.larvalabs.com/meebitimages/characterimage?index={meebitId}&type=full')
response = requests.get(f'https://meebits.larvalabs.com/meebitimages/characterimage?index={meebitId}&type=full')
with open(fileNameNoEnding+ '.jpg',"wb") as file:
file.write(response.content)
except Exception as e:
print("Failed to set VRM metadata")
print(e)

print("Don't forget to follow @MeebitsDAO")