Hi! I used Blender to combine 2 meshes and create a new GLB file of the scene containing both objects. When I opened the combined file with Meshlab or online viewer, I could see both objects. But when I used Blender one of the objects was missing. For example, I combined a mesh of a chair with a mesh of a desk, now I have a new mesh called - “chair_desk”. when I tried to repeat this process and combine between “chair_desk” and “bed”, the chair was completely missing from the scene (I tried to export the new combined mesh as well as render 2D images of “chsir_desk” and in both cases, the chair was missing).
Please do you have any suggestions for me?
Here is the script I’m using:
def extrat_transform_renders(self):
self.reset_scene()
camera_data = bpy.data.cameras.new("Camera")
camera = bpy.data.objects.new("Camera", camera_data)
C = bpy.context
world = C.scene.world
world.use_nodes = True
enode = C.scene.world.node_tree.nodes.new("ShaderNodeTexEnvironment")
enode.image = bpy.data.images.load("blender_scripts/rural_crossroads_8k.hdr")
node_tree = C.scene.world.node_tree
node_tree.links.new(enode.outputs['Color'], node_tree.nodes['Background'].inputs['Color'])
bpy.context.scene.render.film_transparent = True
scene = bpy.context.scene
scene.use_nodes = True
bpy.context.scene.view_layers["ViewLayer"].use_pass_z = True
scene.render.engine = 'CYCLES'
scene.cycles.device = 'GPU'
scene.render.resolution_x = 512
scene.render.resolution_y = 512
names = []
objects_name = []
print(f'[254] eval objects: {self.objects}')
for obj_name, idx, base64_matrix, scale in self.objects:
binary_string = base64.b64decode(base64_matrix)
transform_matrix = np.frombuffer(binary_string, dtype=np.float64).reshape((4, 4))
obj_json_path = os.path.join(root_mesh_dir, obj_name)
print(f'obj_json_path: {obj_json_path}')
with open(obj_json_path, 'r') as f:
concept = json.load(f)
relative_path = concept['path'][idx]
obj_path = os.path.join(root_path, relative_path.lstrip(os.sep))
print(f'obj_name: {obj_name}')
print(f'obj_path: {obj_path}')
names.append(obj_name.replace('.json', ''))
# import model
with stdout_redirected():
bpy.ops.import_scene.gltf(filepath=obj_path, merge_vertices=True)
obj = bpy.context.selected_objects[0]
obj.matrix_world = np.eye(4)
obj.scale *= scale
bpy.context.view_layer.update()
obj.matrix_world = Matrix(transform_matrix) @ obj.matrix_world
objects_name.append(obj.name)
obj.hide_viewport = False
bpy.context.view_layer.update()
bbox_min, bbox_max = self.scene_bbox()
offset = -(bbox_min + bbox_max) / 2
for name in objects_name:
bpy.data.objects[name].matrix_world.translation += offset
# for two objects save scene as glb file
if len(names) == 2:
# take only the last part of the path
hash = self.output_path.split('/')[-1]
print(f"hash: {hash}")
save_path = f"{self.root_path}/{names[0]}_{names[1]}"
os.makedirs(save_path, exist_ok=True)
bpy.ops.export_scene.gltf(filepath=f"{save_path}/{hash}.glb")
anglez = 0
for anglex in range(0, 370, 18):
scene.camera = camera
C.window.scene = scene
C.scene.name = obj_path
camera.location = (self.camera_distance * np.sin(anglex * np.pi / 180),
self.camera_distance * np.tan(anglez * np.pi / 180),
self.camera_distance * np.cos(anglex * np.pi / 180))
camera.rotation_euler = ([radians(a) for a in (180 - anglez, anglex, 0)])
C.scene.camera = camera
C.scene.render.filepath = f"{self.output_path}/%d_%d____.png" % (anglex, anglez)
with stdout_redirected():
bpy.ops.render.render(write_still=True)
Any help will be much appreciated!