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

auto importing images to materials #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The Blender Source Tools add Source engine support to Blender, the free 3D modelling suite.

The Blender Source Tools is an add-on for Blender that simplifies working with assets used in games built on the Source engine, such as Half-Life 2, Counter-Strike: Source, and Team Fortress 2. This tool streamlines the process of importing and exporting models, animations, textures, and other data between Blender and Source engine projects.

The Blender Source Tools — это аддон для Blender, который позволяет работать с файлами и ресурсами, используемыми в играх на движке Source (например, Half-Life 2, Counter-Strike: Source, Team Fortress 2 и другие). Этот инструмент значительно упрощает процесс импорта и экспорта моделей, анимаций, текстур и других данных между Blender и игровыми проектами на движке Source.
13 changes: 13 additions & 0 deletions io_scene_valvesource/import_smd.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,19 @@ def getMeshMaterial(self,mat_name):
else: # material does not exist
print("- New material: {}".format(mat_name))
mat = bpy.data.materials.new(mat_name)
#new fix importing textures
mat.use_nodes = True
base_node = mat.node_tree.nodes["Principled BSDF"]
if base_node:
base_node.inputs["Roughness"].default_value = 1.0
texture_node = mat.node_tree.nodes.new("ShaderNodeTexImage")
texture_path = os.path.join(os.path.dirname(self.filepath), mat_name)
try:
texture_node.image = bpy.data.images.load(texture_path)
except RuntimeError:
print(f"Текстура не найдена: {texture_path}")

mat.node_tree.links.new(texture_node.outputs["Color"], base_node.inputs["Base Color"])
md.materials.append(mat)
# Give it a random colour
randCol = []
Expand Down