프로젝트의 모든 시드 임의화
이 예제에서는 현재 프로젝트에 있는 Substance 재질에서 모든 임의화 속성을 임의화하는 동작을 [편집] 메뉴에 추가합니다.
이 예제를 사용하려면 다음을 수행합니다.
- Python 플러그인 폴더로 이동(python 플러그인 폴더 찾기)
- random_seed 폴더를 만듭니다.
- 이름이 init.py인 파일 만들기
- 아래 코드를 파일 내에 복사합니다.
import os
import re
import sys
import math
import json
import random
from datetime import datetime
import substance_painter as sp
import substance_painter_plugins as spp
# Qt5 vs Qt6 check
IsQt5 = sp.application.version_info() < (10,1,0)
if IsQt5 :
from PySide2 import QtGui
from PySide2 import QtCore
from PySide2 import QtWidgets
else :
from PySide6 import QtGui
from PySide6 import QtCore
from PySide6 import QtWidgets
WIDGETS = []
ValidNodeTypes = (
sp.layerstack.NodeType.FillLayer,
sp.layerstack.NodeType.FillEffect,
sp.layerstack.NodeType.FilterEffect,
sp.layerstack.NodeType.GeneratorEffect
)
def GetSourceMode( Source ) :
try:
return Source.source_mode
except:
return None
def CheckForRandomseed( CurrentSource, Sources ) :
if type( CurrentSource ) == sp.source.SourceSubstance :
Parameters = CurrentSource.get_parameters()
# Check if the Substance has a random seed
if "$randomseed" in Parameters :
Sources.append( CurrentSource )
# Check if any of the inputs of the Substance has another
# Substance with a random seed too
for Name in CurrentSource.image_inputs :
InputSource = CurrentSource.get_source( Name )
CheckForRandomseed( InputSource, Sources )
def FindSources( Node, Sources ) :
if Node.get_type() in ValidNodeTypes :
Source = []
Mode = GetSourceMode( Node )
if Mode == sp.source.SourceMode.Material :
Source.append( Node.get_material_source() )
elif Mode == sp.source.SourceMode.Split :
for Channel in Node.active_channels :
Source.append( Node.get_source( Channel ) )
else :
Source.append( Node.get_source() )
for CurrentSource in Source :
CheckForRandomseed( CurrentSource, Sources )
def IterateLayer( Parent, Sources ) :
if Parent.get_type() == sp.layerstack.NodeType.FillLayer :
FindSources( Parent, Sources )
if Parent.get_type() == sp.layerstack.NodeType.FillLayer \
or Parent.get_type() == sp.layerstack.NodeType.GroupLayer \
or Parent.get_type() == sp.layerstack.NodeType.PaintLayer :
for Effect in Parent.content_effects() :
FindSources( Effect, Sources )
for Effect in Parent.mask_effects() :
FindSources( Effect, Sources )
if Parent.get_type() == sp.layerstack.NodeType.GroupLayer :
for Layer in Parent.sub_layers() :
IterateLayer( Layer, Sources )
def RandomizeSeed() :
if not sp.project.is_open():
sp.logging.warning( "No project open" )
return
# Sources list
Sources = []
# List all stacks and gather their resources
for TextureSet in sp.textureset.all_texture_sets() :
for Stack in TextureSet.all_stacks() :
for Layer in sp.layerstack.get_root_layer_nodes( Stack ) :
IterateLayer( Layer, Sources )
# Setup parameters
Parameters = { "$randomseed" : random.getrandbits(16) }
# Batch
with sp.layerstack.ScopedModification( "Randomize all the seeds" ) :
for Source in Sources :
Source.set_parameters( Parameters )
def start_plugin():
ActionBuilder = None
if IsQt5 :
ActionBuilder = QtWidgets.QAction
else :
ActionBuilder = QtGui.QAction
Action = ActionBuilder(
"Randomize all seeds",
triggered=RandomizeSeed
)
sp.ui.add_action(
sp.ui.ApplicationMenu.Edit,
Action
)
WIDGETS.append( Action )
def close_plugin():
for Widget in WIDGETS :
sp.ui.delete_ui_element( Widget )
if __name__ == "__main__":
start_plugin()
recommendation-more-help
substance-3d-dev-help-painter-python-guide