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

C++ OBJ importer #382

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 32 additions & 25 deletions MCprep_addon/world_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import math
from pathlib import Path

import bpy
from bpy_extras.io_utils import ExportHelper, ImportHelper
Expand Down Expand Up @@ -272,15 +273,16 @@ class MCPREP_OT_import_world_split(bpy.types.Operator, ImportHelper):
@tracking.report_error
def execute(self, context):
# for consistency with the built in one, only import the active path
if self.filepath.lower().endswith(".mtl"):
filename = Path(self.filepath)
new_filename = filename.with_suffix(".obj")
self.filepath = str(new_filename) # Change it from MTL to OBJ, this will be checked with the rest of the if clauses
if not self.filepath:
self.report({"ERROR"}, "File not found, could not import obj")
return {'CANCELLED'}
if not os.path.isfile(self.filepath):
self.report({"ERROR"}, "File not found, could not import obj")
return {'CANCELLED'}
if self.filepath.lower().endswith(".mtl"):
self.report({"ERROR"}, "Select the .obj file, NOT the .mtl!")
return {'CANCELLED'}
if not self.filepath.lower().endswith(".obj"):
self.report({"ERROR"}, "You must select a .obj file to import")
return {'CANCELLED'}
Expand Down Expand Up @@ -310,8 +312,13 @@ def execute(self, context):
obj_import_mem_msg = (
"Memory error during OBJ import, try exporting a smaller world")
try:
res = bpy.ops.import_scene.obj(
filepath=self.filepath, use_split_groups=True)
res = None
if util.min_bv((3, 5)):
res = bpy.ops.wm.obj_import(
filepath=self.filepath, use_split_groups=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this diff hunk can be reverted. This "use_split_groups" works in 3.5 and equally in 3.4 and earlier, as written this would make 3.4 and earlier stop splitting out by objects from the source, which would not be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean, though I did catch the use of the wrong operator for 3.4 and below. In my testing, use_split_groups doesn't seem to work in 3.4 and below for the C++ importer

else:
res = bpy.ops.import_scene.obj(
filepath=self.filepath, use_split_groups=True)
except MemoryError as err:
print("Memory error during import OBJ:")
print(err)
Expand Down Expand Up @@ -863,34 +870,34 @@ def create_dynamic_world(self, context, blendfile, wname):

# # update drivers, needed if time has changed vs import source
# if context.scene.world.node_tree.animation_data:
# # context.scene.world.node_tree.animation_data.drivers[0].update()
# drivers = context.scene.world.node_tree.animation_data.drivers[0]
# drivers.driver.variables[0].targets[0].id = time_obj
# # nope, still doesn't work.
# # context.scene.world.node_tree.animation_data.drivers[0].update()
# drivers = context.scene.world.node_tree.animation_data.drivers[0]
# drivers.driver.variables[0].targets[0].id = time_obj
# # nope, still doesn't work.

# if needed: create time object and setup drivers
# if not time_obj:
# conf.log("Creating time_obj")
# time_obj = bpy.data.objects.new('MCprep Time Control', None)
# util.obj_link_scene(time_obj, context)
# global time_obj_cache
# time_obj_cache = time_obj
# if hasattr(time_obj, "empty_draw_type"): # 2.7
# time_obj.empty_draw_type = 'SPHERE'
# else: # 2.8
# time_obj.empty_display_type = 'SPHERE'
# conf.log("Creating time_obj")
# time_obj = bpy.data.objects.new('MCprep Time Control', None)
# util.obj_link_scene(time_obj, context)
# global time_obj_cache
# time_obj_cache = time_obj
# if hasattr(time_obj, "empty_draw_type"): # 2.7
# time_obj.empty_draw_type = 'SPHERE'
# else: # 2.8
# time_obj.empty_display_type = 'SPHERE'

# first, get the driver
# if (not world.node_tree.animation_data
# or not world.node_tree.animation_data.drivers
# or not world.node_tree.animation_data.drivers[0].driver):
# conf.log("Could not get driver from imported dynamic world")
# self.report({'WARNING'}, "Could not update driver for dynamic world")
# driver = None
# or not world.node_tree.animation_data.drivers
# or not world.node_tree.animation_data.drivers[0].driver):
# conf.log("Could not get driver from imported dynamic world")
# self.report({'WARNING'}, "Could not update driver for dynamic world")
# driver = None
# else:
# driver = world.node_tree.animation_data.drivers[0].driver
# driver = world.node_tree.animation_data.drivers[0].driver
# if driver and driver.variables[0].targets[0].id_type == 'OBJECT':
# driver.variables[0].targets[0].id = time_obj
# driver.variables[0].targets[0].id = time_obj
# add driver to control obj's x rotation

return obj_list
Expand Down