Skip to content

Commit

Permalink
Merge pull request #23 from garvita-tiwari/Texture
Browse files Browse the repository at this point in the history
Texture
  • Loading branch information
AlexanderRitter02 committed Jul 15, 2022
2 parents ed65ae2 + a9d46e7 commit 6af805d
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 57 deletions.
28 changes: 17 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
__pycache__/
renders/
build/
dist/
.venv-blender
*.zip
data_samples
preview.png
hdri_thumbs/
temp.png
blender_render.log
# Ignore everything
*

# Allow these files
*.py # Python source code
*.md # Markdown files, e.g. the Readme
requirements.txt # requirements for pip
main-linux.spec
main-windows.spec
assets/HDRIs/*.hdr # HDRI images
assets/textures/brick.png # Texture files should be png only for highest quality
assets/textures/iron.png
assets/textures/wood.png
assets/default_settings.yaml # Default settings should be included, but not "settings.yaml"
assets/gui/icon.ico # Program icon
assets/gui/empty_bg.png # Empty image if no render has happend yet
/assets/gui/preview_unavailable.png
20 changes: 20 additions & 0 deletions Texture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import bpy

#import the Texture image
def load_texture(texture_path: str, material: bpy.types.Material):
if material.node_tree.nodes.get("Image Texture") is None:
texImage = material.node_tree.nodes.new(type = "ShaderNodeTexImage")
else:
texImage = material.node_tree.nodes.get("Image Texture")
texImage.image = bpy.data.images.load(bpy.path.relpath(texture_path))

#disp is path of Base color
disp=material.node_tree.nodes["Principled BSDF"].inputs["Base Color"]

#connect the node between 'Base Color' of bsdf and 'Color' of texImage
material.node_tree.links.new(disp,texImage.outputs[0])


def delete_texture(material: bpy.types.Material):
disp=material.node_tree.nodes["Principled BSDF"].inputs["Base Color"]
material.node_tree.links.remove(disp.links[0])
40 changes: 0 additions & 40 deletions assets/STL samples/cube.obj

This file was deleted.

Binary file added assets/textures/brick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/iron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/wood.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions gui/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# description:
# GUI element: Main program, renders the GUI and connects it to other function

from cgi import print_directory
import tkinter as tk
from tkinter import Frame, Label, Button, StringVar, BooleanVar, IntVar, Checkbutton, OptionMenu, Scale, Canvas, Entry, PhotoImage
from tkinter import ttk
Expand All @@ -18,6 +17,7 @@
import threading
import requests
import enum
from Texture import load_texture, delete_texture

from gui.render_preview import RenderPreview
from gui.gui_options import SettingsWindow
Expand Down Expand Up @@ -462,7 +462,7 @@ def __init__(self, master, control):
lbl_textures = Label(master=self, text="Texture selection:", font="Arial 10 bold")
btn_import_texture = Button(master=self, text="Import", command=self.import_texture)
lbl_sel_tex = Label(master=self, text="Select:")
textures = (Textures.NONE.value, Textures.WOOD.value, Textures.BRICKS.value)
textures = (Textures.NONE.value, Textures.WOOD.value, Textures.BRICKS.value, Textures.IRON.value)
dropdown_textures = OptionMenu(self, tex_selected, *textures, command=self.set_texture)
lbl_textures.grid(row=0, column=0, columnspan=2, sticky="we")
btn_import_texture.grid(row=1, column=0, columnspan=2, sticky="")
Expand All @@ -472,19 +472,25 @@ def __init__(self, master, control):
def set_texture(self, *args):
tex = Textures(args[0])
if tex == Textures.WOOD:
pass
load_texture("assets/textures/wood.png", self.control.material.material)
elif tex == Textures.BRICKS:
pass
load_texture("assets/textures/brick.png", self.control.material.material)
elif tex == Textures.IRON:
load_texture("assets/textures/iron.png", self.control.material.material)
else: # NONE
pass
delete_texture(self.control.material.material)
self.control.re_render()

def import_texture(self):
filetypes = [
("PNG image", "*.png"),
("jpg image", "*.jpg")
]
filename = filedialog.askopenfilename(title="Select a texture", filetypes=filetypes)
# TODO Apply the texure to the object
if filename == "":
return

load_texture(filename, self.control.material.material)
self.control.re_render()


Expand All @@ -493,6 +499,8 @@ class Textures(enum.Enum):
NONE = "none"
WOOD = "wood"
BRICKS = "bricks"
IRON = "iron"


class LightingWidgets(Frame):
# constants
Expand Down
Binary file removed images/icon.ico
Binary file not shown.
Binary file removed images/preview.png
Binary file not shown.
Binary file removed images/preview_unavailable.png
Binary file not shown.

0 comments on commit 6af805d

Please sign in to comment.