from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty

import bpy
from bpy_extras.io_utils import ExportHelper
from rprblender.engine.export_engine import ExportEngine
import os.path
import json
from rprblender.utils.user_settings import get_user_settings

from . import RPR_Operator

from rprblender.utils.logging import Log
import pyrpr

log = Log(tag='operators.export_scene')


class RPR_EXPORT_OP_export_rpr_scene(RPR_Operator, ExportHelper):
    bl_idname = "rpr.export_scene_rpr"
    bl_label = "RPR (.rpr)"
    bl_description = "Export current scene to RPR file"

    filename_ext: str = ".rpr"

    filter_glob: StringProperty(
        default="*.rpr",
        options={'HIDDEN'},
        maxlen=255,
    )
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
import os

import bpy
import io
from xml.etree import ElementTree

from .library import RPRMaterialLibrary
from .loader import RPRXMLMaterialCompiler
from .image_loader import MaterialImageLoader

from rprblender.utils.logging import Log
log = Log(tag="material_library")

# The material library instance, referenced by the material browser properties and material import operator.
rpr_material_library = None


def import_xml_material(material: bpy.types.Material, name: str, xml_path: str,
                        copy_textures: bool):
    """ Create RPR material at current material slot using xml.
    Nodes tree is cleaned if present, new created otherwise.
    New output node added if no output found.
    Change Blender material name to material library name.
    Copy textures locally if requested."""
    def clean_material_tree():
        """ Remove every node from material tree except for output """
        log("Cleaning material nodes tree")
示例#3
0
# limitations under the License.
#********************************************************************
"""
Scene export to file
"""
import math

import pyrpr_load_store

from rprblender.export import (instance, object, particle, world, camera)
from .context import RPRContext, RPRContext2
from .engine import Engine
import pyrpr

from rprblender.utils.logging import Log
log = Log(tag='ExportEngine')


class ExportEngine(Engine):
    TYPE = 'EXPORT'

    def __init__(self):
        self.rpr_context = RPRContext()
        self.rpr_context.engine_type = self.TYPE

    def sync(self, context):
        """ Prepare scene for export """
        log('Start sync')

        depsgraph = context.evaluated_depsgraph_get()
        self.rpr_context.blender_data['depsgraph'] = depsgraph
示例#4
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
import sys
import site
import subprocess
from datetime import datetime, timedelta

import bpy
from . import IS_MAC, IS_LINUX, package_root_dir
from rprblender import config

from rprblender.utils.logging import Log
log = Log(tag="install_libs")

PIP_CHECK_FILENAME = "pip_check.txt"
NEXT_TIME_CHECK_DELTA = 5  # 5 days

# adding user site-packages path to sys.path
if site.getusersitepackages() not in sys.path:
    sys.path.append(site.getusersitepackages())


def run_module_call(*args):
    """Run Blender Python with arguments on user access level"""
    module_args = ('-m', *args, '--user')
    log(f"Running subprocess.check_call {module_args}")

    subprocess.check_call([bpy.app.binary_path_python, *module_args],
示例#5
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
from collections import defaultdict
from bpy.props import FloatProperty, EnumProperty

from rprblender.utils.user_settings import get_user_settings
from . import RPR_Operator
from rprblender.export.material import get_material_output_node
from rprblender.utils.logging import Log
import math
import bpy
from rprblender.nodes.node_parser import get_node_parser_class

log = Log(tag='material.nodes.operator', level='info')


def bake_nodes(node_tree, nodes, material, resolution, obj):
    ''' bakes all nodes to a texture of resolution and makes texture nodes to replace them '''
    ''' TODO this could possibly be made faster by doing in multiple subproceses '''
    # setup
    bpy.context.view_layer.objects.active = obj
    obj.active_material = material

    # find output node
    output_node = get_material_output_node(material)
    surface_socket = output_node.inputs['Surface']
    surface_node = surface_socket.links[
        0].from_node if surface_socket.is_linked else None
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
import os
import platform
from pathlib import Path

from rprblender.config import material_library_path

from rprblender.utils.logging import Log
log = Log(tag="utils.material_library")

# use environment variable to override library path for debug/testing purpose
DEV_ENVIRONMENT_VARIABLE = "RPR_MATERIAL_LIBRARY_PATH"

# Windows registry keys, library versions 1.0 and 2.0
WIN_MATLIB_1_REGKEY = "SOFTWARE\\AMD\\Radeon ProRender for Blender"
WIN_MATLIB_2_REGKEY = "SOFTWARE\\AMD\\RadeonProRender\\MaterialLibrary\\Blender"

# Ubuntu has 3 possible material library locations
UBUNTU_MATLIB_1 = "/Users/Shared/RadeonProRender/Blender/matlib"
UBUNTU_MATLIB_2_INTEGRATED = "/Users/Shared/RadeonProRender/Blender/matlib/Xml"
UBUNTU_MATLIB_2_SEPARATED = "/Users/Shared/RadeonProRender/MaterialLibrary/2.0.0/Xml"


def get_library_path() -> str:
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
import ast
from xml.etree import ElementTree  # for some reason Blender doesn't allow access via xml.etree.ElementTree

import bpy
from rprblender.utils.logging import Log
log = Log(tag='material_loader')


class UnsupportedNode(Exception):
    def __init__(self, node_type):
        super().__init__("Unsupported node:", node_type)
        self.node_type = node_type


class RPRXMLMaterialCompiler:
    """ Load nodes tree info from XML and create nodes in shader node tree using this info """
    def __init__(self, xml_nodes, tree: bpy.types.ShaderNodeTree,
                 image_loader):
        self.xml_nodes = xml_nodes

        self.tree = tree
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#********************************************************************
import bpy
from . import RPR_Operator
from rprblender import material_library

from rprblender.utils.logging import Log
log = Log(tag='operator.material_library')


class RPR_MATERIAL_LIBRARY_OP_import_material(RPR_Operator):
    bl_idname = "rpr.import_material_operator"
    bl_label = "Import Material"
    bl_description = "Import selected material"

    @classmethod
    def poll(cls, context):
        return super().poll(context) and material_library.rpr_material_library and context.object

    # Perform the operator action.
    def execute(self, context):
        library = material_library.rpr_material_library
        if not library or not library.is_valid: