Skip to content

Commit

Permalink
Merge pull request #5 from vircadia/Version-1.03
Browse files Browse the repository at this point in the history
Version 1.03
  • Loading branch information
Aitolda authored May 29, 2024
2 parents f695d4b + 45c7def commit fd4f677
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 141 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ You'll need:
- Unity 2021.3.4.f1

- gltfast package (by name, `com.unity.cloud.gltfast`)
- Unity2Vircadia package [**(this repo)**](https://github.com/vircadia/unity-to-vircadia-pipeline/raw/master/dist/Unity2Vircadia_v1.0.1.unitypackage)
- Unity2Vircadia package [**(this repo)**](https://github.com/vircadia/unity-to-vircadia-pipeline/raw/master/dist/UnityToVircadia_v1.0.3.unitypackage)

- Blender 4.0.2 or newer

- UnityToVircadia Blender addon [**(this repo)**](https://github.com/vircadia/unity-to-vircadia-pipeline/raw/master/dist/UnityToVircadia_BlenderAddon_v1.0.1.zip)
- UnityToVircadia Blender addon [**(this repo)**](https://github.com/vircadia/unity-to-vircadia-pipeline/raw/master/dist/UnityToVircadia_BlenderAddon_v1.0.3.zip)

### Step 1. Unity

Expand Down Expand Up @@ -42,3 +42,4 @@ You are now ready to upload your `.glb` file to the public folder. An S3 bucket

- Use URP shaders with a "Metallic" workflow. Specular is not recommended and may cause visual inconsistencies.
- At the moment ".gltf" export (separate .bin and textures) from unity's glTFast plugin will not import properly into blender, so be sure to use ".glb"
- Animation exports are not currently supported
137 changes: 90 additions & 47 deletions blender/UnityToVircadia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,111 @@
from . import previewLightmaps

bl_info = {
"name": "UnityToVircadia",
"blender": (4, 0, 2),
"category": "Object",
"description": "Tools for converting Unity assets to Vircadia",
"author": "Ben Brennan, Vircadia",
"version": (1, 0),
"location": "View3D > Sidebar > UnityToVircadia Tab",
"name": "UnityToVircadia",
"blender": (4, 0, 2),
"category": "Object",
"description": "Tools for converting Unity assets to Vircadia",
"author": "Ben Brennan, Vircadia",
"version": (1, 0, 3),
"location": "View3D > Sidebar > UnityToVircadia Tab",
}

def get_script_path(script_name):
addon_dir = os.path.dirname(__file__)
return os.path.join(addon_dir, script_name)
addon_dir = os.path.dirname(__file__)
return os.path.join(addon_dir, script_name)

class ToggleLightmapsOperator(bpy.types.Operator):
"""Toggle Lightmaps"""
bl_idname = "object.toggle_lightmaps"
bl_label = "Preview Lightmaps"
bl_description = "Toggle lightmap textures on objects"
"""Toggle Lightmaps"""
bl_idname = "object.toggle_lightmaps"
bl_label = "Preview Lightmaps"
bl_description = "Toggle lightmap textures on objects"

def execute(self, context):
previewLightmaps.main(context.scene.lightmaps_applied)
context.scene.lightmaps_applied = not context.scene.lightmaps_applied
return {'FINISHED'}
def execute(self, context):
previewLightmaps.main(context.scene.lightmaps_applied)
context.scene.lightmaps_applied = not context.scene.lightmaps_applied
return {'FINISHED'}

class AdjustShadersOperator(bpy.types.Operator):
"""Adjust Shaders"""
bl_idname = "object.adjust_shaders"
bl_label = "Adjust Shaders"
bl_description = "Adjust shaders based on the MaterialsCheckReport.txt file"

def execute(self, context):
bpy.ops.object.adjust_shaders('INVOKE_DEFAULT')
return {'FINISHED'}

class ExportGLTFOperator(bpy.types.Operator):
"""Export glTF 2.0"""
bl_idname = "export_scene.unity_to_vircadia_gltf"
bl_label = "Export glTF 2.0"
bl_description = "Export the scene as glTF 2.0 after clearing lightmaps if necessary"

def execute(self, context):
if context.scene.lightmaps_applied:
bpy.ops.object.toggle_lightmaps()

bpy.ops.export_scene.gltf('INVOKE_DEFAULT')
return {'FINISHED'}

class UnityToVircadiaPanel(bpy.types.Panel):
bl_label = "UnityToVircadia"
bl_idname = "OBJECT_PT_UnityToVircadia"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'UnityToVircadia'
bl_label = "UnityToVircadia"
bl_idname = "OBJECT_PT_UnityToVircadia"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'UnityToVircadia'

def draw(self, context):
layout = self.layout

layout.operator("import_scene.gltf", text="Import glTF 2.0")
# layout.operator("object.correct_scale") # TODO later
layout.operator("import.lightmap_info")
layout.operator("object.adjust_shaders", text="Adjust Shaders")

# Toggle button for applying/clearing lightmaps
if context.scene.lightmaps_applied:
layout.operator("object.toggle_lightmaps", text="Clear Lightmaps")
else:
layout.operator("object.toggle_lightmaps", text="Preview Lightmaps")

layout.operator("export_scene.unity_to_vircadia_gltf", text="Export glTF 2.0")

def draw(self, context):
layout = self.layout
class AdjustShaders(bpy.types.Operator):
"""Adjust Shaders"""
bl_idname = "object.adjust_shaders"
bl_label = "Adjust Shaders"

layout.operator("import_scene.gltf", text="Import glTF 2.0")
# layout.operator("object.correct_scale") # TODO later
layout.operator("import.lightmap_info")
layout.operator("object.adjust_shaders")
filepath: bpy.props.StringProperty(subtype="FILE_PATH")

# Toggle button for applying/clearing lightmaps
if context.scene.lightmaps_applied:
layout.operator("object.toggle_lightmaps", text="Clear Lightmaps")
else:
layout.operator("object.toggle_lightmaps", text="Preview Lightmaps")
def execute(self, context):
fixMappingNodesRemoveExtras.adjust_shaders(context, self.filepath)
return {'FINISHED'}

layout.operator("export_scene.gltf", text="Export glTF 2.0")
def invoke(self, context, event):
self.filepath = "MaterialsCheckReport.txt"
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}

def register():
bpy.utils.register_class(ToggleLightmapsOperator)
bpy.utils.register_class(UnityToVircadiaPanel)
bpy.utils.register_class(makeObjectsSingleUserFixScale.CorrectScale)
bpy.utils.register_class(getLightmapInformation.GetLightmapInfo)
bpy.utils.register_class(fixMappingNodesRemoveExtras.AdjustShaders)
bpy.types.Scene.lightmaps_applied = bpy.props.BoolProperty(default=False)
bpy.utils.register_class(ToggleLightmapsOperator)
bpy.utils.register_class(AdjustShadersOperator)
bpy.utils.register_class(ExportGLTFOperator)
bpy.utils.register_class(UnityToVircadiaPanel)
bpy.utils.register_class(makeObjectsSingleUserFixScale.CorrectScale)
bpy.utils.register_class(getLightmapInformation.GetLightmapInfo)
bpy.utils.register_class(AdjustShaders)
bpy.types.Scene.lightmaps_applied = bpy.props.BoolProperty(default=False)

def unregister():
bpy.utils.unregister_class(ToggleLightmapsOperator)
bpy.utils.unregister_class(UnityToVircadiaPanel)
bpy.utils.unregister_class(makeObjectsSingleUserFixScale.CorrectScale)
bpy.utils.unregister_class(getLightmapInformation.GetLightmapInfo)
bpy.utils.unregister_class(fixMappingNodesRemoveExtras.AdjustShaders)
del bpy.types.Scene.lightmaps_applied
bpy.utils.unregister_class(ToggleLightmapsOperator)
bpy.utils.unregister_class(AdjustShadersOperator)
bpy.utils.unregister_class(ExportGLTFOperator)
bpy.utils.unregister_class(UnityToVircadiaPanel)
bpy.utils.unregister_class(makeObjectsSingleUserFixScale.CorrectScale)
bpy.utils.unregister_class(getLightmapInformation.GetLightmapInfo)
bpy.utils.unregister_class(AdjustShaders)
del bpy.types.Scene.lightmaps_applied

if __name__ == "__main__":
register()
register()
Loading

0 comments on commit fd4f677

Please sign in to comment.