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

Find a more generic place for color overrides #23

Open
github-actions bot opened this issue Nov 29, 2021 · 0 comments
Open

Find a more generic place for color overrides #23

github-actions bot opened this issue Nov 29, 2021 · 0 comments
Labels

Comments

@github-actions
Copy link

Find a more generic place for color overrides

Private

=======

# TODO: Find a more generic place for color overrides

        Returns:
            bpy.types.Material: A material for the given chemical symbol.
        """
        key = self._get_material_key(chemical_id, symbol)
        material = bpy.data.materials.get(key)
        if material is None:
            material = self._create_material(symbol, key)
        return material

    def _get_material_key(self, chemical_id: str, symbol: str) -> str:
        """Creates a unique human-readable key for a material

        Args:
            symbol (str): Chemical symbol for the material.
            chemical_id (str): A unique identifier for a material.

        Returns:
            str: A unique human-readable key for the material
        """
        if self.materials_are_singleton:
            key = f"{PACKAGE_PREFIX}_{symbol}"
        else:
            key = f"{PACKAGE_PREFIX}_{symbol}_{chemical_id}"
        return key

    def _create_material(self, symbol: str, key: str) -> bpy.types.Material:
        """Creates a material given a symbol and chemical id. Uses JMol colors.

        Args:
            symbol (str): Chemical symbol for the material.
            chemical_id (str): A unique identifier for a material.

        Returns:
            bpy.types.Material: A material for the given chemical symbol.
        """

        color = [i for i in ase.data.colors.jmol_colors[ase.data.atomic_numbers[symbol]]] + [1]
        # TODO: Find a more generic place for color overrides
        if symbol == "C":
            color = [0.0, 0.0, 0.0, 1.0]

        material: bpy.types.Material = bpy.data.materials.new(key)

        # Find the principled node
        material.use_nodes = True
        shader: bpy.types.ShaderNodeBsdfPrincipled = material.node_tree.nodes.get('Principled BSDF')

        # Set some general material properties
        shader.inputs[BSDF_SHADER_INPUTS["Base Color"]].default_value = color
        if ase.data.atomic_numbers[symbol] in METALS:
            shader.inputs[BSDF_SHADER_INPUTS["Metallic"]].default_value = 1.0
            shader.inputs[BSDF_SHADER_INPUTS["Roughness"]].default_value = 0.2
            shader.inputs[BSDF_SHADER_INPUTS["Clearcoat"]].default_value = 0.0
        else:
            shader.inputs[BSDF_SHADER_INPUTS["Metallic"]].default_value = 0.0
            shader.inputs[BSDF_SHADER_INPUTS["Roughness"]].default_value = 1.0
            shader.inputs[BSDF_SHADER_INPUTS["Clearcoat"]].default_value = 1.0

        return material

4972fd968cfee7af756769a7e162301ee8299a40

@github-actions github-actions bot added the todo label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants