-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from quadproduction/release/1.7.0
Release/1.7.0
- Loading branch information
Showing
4 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
quad_pyblish_module/plugins/blender/load/import_image_as_reference.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Load an asset in Blender from an Alembic file.""" | ||
|
||
from typing import Dict, List, Optional | ||
|
||
import bpy | ||
|
||
from openpype.pipeline import ( | ||
get_representation_path, | ||
AVALON_CONTAINER_ID, | ||
) | ||
from openpype.hosts.blender.api import plugin, lib | ||
from openpype.hosts.blender.api.pipeline import ( | ||
AVALON_CONTAINERS, | ||
AVALON_PROPERTY, | ||
) | ||
|
||
class ImageReferenceLoader(plugin.AssetLoader): | ||
"""Load Image in Blender as reference. | ||
Create image in empty and put it in _REF collection. | ||
""" | ||
|
||
families = ["image", "render", "review"] | ||
representations = ["jpg", "png"] | ||
|
||
label = "Load Image as Reference" | ||
icon = "code-fork" | ||
color = "orange" | ||
|
||
def process_asset( | ||
self, context: dict, name: str, namespace: Optional[str] = None, | ||
options: Optional[Dict] = None | ||
) -> Optional[List]: | ||
|
||
""" | ||
Arguments: | ||
name: Use pre-defined name | ||
namespace: Use pre-defined namespace | ||
context: Full parenthood of representation to load | ||
options: Additional settings dictionary | ||
""" | ||
|
||
image_filepath = self.filepath_from_context(context) | ||
asset = context["asset"]["name"] | ||
|
||
imported_image = bpy.data.images.load(image_filepath) | ||
image_name = asset + '_null' | ||
|
||
empty = bpy.data.objects.new(image_name, None) | ||
empty.empty_display_type = "IMAGE" | ||
|
||
ref_collection = bpy.data.collections.get("_REF") | ||
if not ref_collection: | ||
ref_collection = bpy.data.collections.new(name="_REF") | ||
bpy.context.scene.collection.children.link(ref_collection) | ||
ref_collection.objects.link(empty) | ||
|
||
empty.data = imported_image | ||
|
||
self.log.info(f"Image at path {imported_image.filepath} has been correctly loaded in scene as reference.") |
60 changes: 60 additions & 0 deletions
60
quad_pyblish_module/plugins/blender/load/import_image_in_camera.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Load an asset in Blender from an Alembic file.""" | ||
|
||
from pathlib import Path | ||
from pprint import pformat | ||
from typing import Dict, List, Optional | ||
|
||
import bpy | ||
|
||
from openpype.pipeline import ( | ||
get_representation_path, | ||
AVALON_CONTAINER_ID, | ||
) | ||
from openpype.hosts.blender.api import plugin, lib | ||
from openpype.hosts.blender.api.pipeline import ( | ||
AVALON_CONTAINERS, | ||
AVALON_PROPERTY, | ||
) | ||
|
||
class ImageCameraLoader(plugin.AssetLoader): | ||
"""Load Image in Blender as background in camera. | ||
Create background image for active camera and assign selected image. | ||
""" | ||
|
||
families = ["image", "render", "review"] | ||
representations = ["jpg", "png"] | ||
|
||
label = "Load Image in Camera" | ||
icon = "code-fork" | ||
color = "orange" | ||
|
||
def process_asset( | ||
self, context: dict, name: str, namespace: Optional[str] = None, | ||
options: Optional[Dict] = None | ||
) -> Optional[List]: | ||
|
||
""" | ||
Arguments: | ||
name: Use pre-defined name | ||
namespace: Use pre-defined namespace | ||
context: Full parenthood of representation to load | ||
options: Additional settings dictionary | ||
""" | ||
image_filepath = self.filepath_from_context(context) | ||
imported_image = bpy.data.images.load(image_filepath) | ||
|
||
camera = bpy.context.scene.camera | ||
if not camera: | ||
raise ValueError("No camera has been found in scene. Can't import image as camera background.") | ||
|
||
camera.data.show_background_images = True | ||
try: | ||
background = camera.data.background_images[0] | ||
except IndexError: | ||
background = camera.data.background_images.new() | ||
imported_image.source = 'FILE' | ||
background.source = 'IMAGE' | ||
background.image = imported_image | ||
|
||
self.log.info(f"Image at path {imported_image.filepath} has been correctly loaded in scene as camera background.") |
76 changes: 76 additions & 0 deletions
76
quad_pyblish_module/plugins/blender/load/import_image_sequence.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"""Load an asset in Blender from an Alembic file.""" | ||
|
||
from pathlib import Path | ||
from pprint import pformat | ||
from typing import Dict, List, Optional | ||
|
||
import bpy | ||
|
||
from openpype.pipeline import ( | ||
get_representation_path, | ||
AVALON_CONTAINER_ID, | ||
) | ||
from openpype.hosts.blender.api import plugin, lib | ||
from openpype.hosts.blender.api.pipeline import ( | ||
AVALON_CONTAINERS, | ||
AVALON_PROPERTY, | ||
) | ||
|
||
class ImageSequenceLoader(plugin.AssetLoader): | ||
"""Load Image Sequence in Blender. | ||
Create background image sequence for active camera and assign selected images. | ||
""" | ||
|
||
families = ["image", "render"] | ||
representations = ["jpg", "png"] | ||
|
||
label = "Load Image Sequence" | ||
icon = "code-fork" | ||
color = "orange" | ||
|
||
def process_asset( | ||
self, context: dict, name: str, namespace: Optional[str] = None, | ||
options: Optional[Dict] = None | ||
) -> Optional[List]: | ||
|
||
""" | ||
Arguments: | ||
name: Use pre-defined name | ||
namespace: Use pre-defined namespace | ||
context: Full parenthood of representation to load | ||
options: Additional settings dictionary | ||
""" | ||
image_filepath = self.filepath_from_context(context) | ||
imported_image = bpy.data.images.load(image_filepath) | ||
|
||
camera = bpy.context.scene.camera | ||
if not camera: | ||
raise ValueError("No camera has been found in scene. Can't import image as camera background.") | ||
|
||
camera.data.show_background_images = True | ||
try: | ||
background = camera.data.background_images[0] | ||
except IndexError: | ||
background = camera.data.background_images.new() | ||
imported_image.source = 'SEQUENCE' | ||
background.source = 'IMAGE' | ||
background.image = imported_image | ||
background.image_user.frame_duration | ||
|
||
context_data = context.get('version', []).get('data', []) | ||
if not context_data: | ||
raise ValueError("Can't access to context data when retrieving frame informations. Abort.") | ||
|
||
frame_start = context_data.get('frameStart') | ||
frame_end = context_data.get('frameEnd') | ||
if not frame_start or not frame_end: | ||
raise ValueError("Can't find frame range informations. Abort.") | ||
|
||
frames = (frame_end - frame_start) + 1 | ||
|
||
background.image_user.frame_start = frame_start | ||
background.image_user.frame_duration = frames | ||
background.image_user.frame_offset = 0 | ||
|
||
self.log.info(f"Image sequence at path {imported_image.filepath} has been correctly loaded in scene as camera background.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Load an asset in Blender from an Alembic file.""" | ||
|
||
from pathlib import Path | ||
from pprint import pformat | ||
from typing import Dict, List, Optional | ||
|
||
import bpy | ||
|
||
from openpype.pipeline import ( | ||
get_representation_path, | ||
AVALON_CONTAINER_ID, | ||
) | ||
from openpype.hosts.blender.api import plugin, lib | ||
from openpype.hosts.blender.api.pipeline import ( | ||
AVALON_CONTAINERS, | ||
AVALON_PROPERTY, | ||
) | ||
|
||
class ImageVideo(plugin.AssetLoader): | ||
"""Load Video in Blender. | ||
Create background movie clip for active camera and assign selected video. | ||
""" | ||
|
||
families = ["image", "render", "review"] | ||
representations = ["mp4", "avi", "h264_mp4"] | ||
|
||
label = "Load Video" | ||
icon = "code-fork" | ||
color = "orange" | ||
|
||
def process_asset( | ||
self, context: dict, name: str, namespace: Optional[str] = None, | ||
options: Optional[Dict] = None | ||
) -> Optional[List]: | ||
|
||
""" | ||
Arguments: | ||
name: Use pre-defined name | ||
namespace: Use pre-defined namespace | ||
context: Full parenthood of representation to load | ||
options: Additional settings dictionary | ||
""" | ||
video_filepath = self.filepath_from_context(context) | ||
imported_video = bpy.data.movieclips.load(video_filepath) | ||
|
||
camera = bpy.context.scene.camera | ||
if not camera: | ||
raise ValueError("No camera has been found in scene. Can't import video as camera background.") | ||
|
||
camera.data.show_background_images = True | ||
try: | ||
background = camera.data.background_images[0] | ||
except IndexError: | ||
background = camera.data.background_images.new() | ||
|
||
background.source = 'MOVIE_CLIP' | ||
background.clip = imported_video | ||
|
||
self.log.info(f"Video at path {imported_video.filepath} has been correctly loaded in scene as camera background.") |