Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
f88f7f41
Commit
f88f7f41
authored
Sep 06, 2023
by
comfyanonymous
Browse files
Add a ConditioningSetAreaPercentage node.
parent
21a563d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
comfy/samplers.py
comfy/samplers.py
+12
-3
nodes.py
nodes.py
+27
-0
No files found.
comfy/samplers.py
View file @
f88f7f41
...
@@ -390,11 +390,20 @@ def get_mask_aabb(masks):
...
@@ -390,11 +390,20 @@ def get_mask_aabb(masks):
return
bounding_boxes
,
is_empty
return
bounding_boxes
,
is_empty
def
resolve_cond_masks
(
conditions
,
h
,
w
,
device
):
def
resolve_
areas_and_
cond_masks
(
conditions
,
h
,
w
,
device
):
# We need to decide on an area outside the sampling loop in order to properly generate opposite areas of equal sizes.
# We need to decide on an area outside the sampling loop in order to properly generate opposite areas of equal sizes.
# While we're doing this, we can also resolve the mask device and scaling for performance reasons
# While we're doing this, we can also resolve the mask device and scaling for performance reasons
for
i
in
range
(
len
(
conditions
)):
for
i
in
range
(
len
(
conditions
)):
c
=
conditions
[
i
]
c
=
conditions
[
i
]
if
'area'
in
c
[
1
]:
area
=
c
[
1
][
'area'
]
if
area
[
0
]
==
"percentage"
:
modified
=
c
[
1
].
copy
()
area
=
(
max
(
1
,
round
(
area
[
1
]
*
h
)),
max
(
1
,
round
(
area
[
2
]
*
w
)),
round
(
area
[
3
]
*
h
),
round
(
area
[
4
]
*
w
))
modified
[
'area'
]
=
area
c
=
[
c
[
0
],
modified
]
conditions
[
i
]
=
c
if
'mask'
in
c
[
1
]:
if
'mask'
in
c
[
1
]:
mask
=
c
[
1
][
'mask'
]
mask
=
c
[
1
][
'mask'
]
mask
=
mask
.
to
(
device
=
device
)
mask
=
mask
.
to
(
device
=
device
)
...
@@ -622,8 +631,8 @@ class KSampler:
...
@@ -622,8 +631,8 @@ class KSampler:
positive
=
positive
[:]
positive
=
positive
[:]
negative
=
negative
[:]
negative
=
negative
[:]
resolve_cond_masks
(
positive
,
noise
.
shape
[
2
],
noise
.
shape
[
3
],
self
.
device
)
resolve_
areas_and_
cond_masks
(
positive
,
noise
.
shape
[
2
],
noise
.
shape
[
3
],
self
.
device
)
resolve_cond_masks
(
negative
,
noise
.
shape
[
2
],
noise
.
shape
[
3
],
self
.
device
)
resolve_
areas_and_
cond_masks
(
negative
,
noise
.
shape
[
2
],
noise
.
shape
[
3
],
self
.
device
)
calculate_start_end_timesteps
(
self
.
model_wrap
,
negative
)
calculate_start_end_timesteps
(
self
.
model_wrap
,
negative
)
calculate_start_end_timesteps
(
self
.
model_wrap
,
positive
)
calculate_start_end_timesteps
(
self
.
model_wrap
,
positive
)
...
...
nodes.py
View file @
f88f7f41
...
@@ -159,6 +159,31 @@ class ConditioningSetArea:
...
@@ -159,6 +159,31 @@ class ConditioningSetArea:
c
.
append
(
n
)
c
.
append
(
n
)
return
(
c
,
)
return
(
c
,
)
class
ConditioningSetAreaPercentage
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"conditioning"
:
(
"CONDITIONING"
,
),
"width"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"height"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"x"
:
(
"FLOAT"
,
{
"default"
:
0
,
"min"
:
0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"y"
:
(
"FLOAT"
,
{
"default"
:
0
,
"min"
:
0
,
"max"
:
1.0
,
"step"
:
0.01
}),
"strength"
:
(
"FLOAT"
,
{
"default"
:
1.0
,
"min"
:
0.0
,
"max"
:
10.0
,
"step"
:
0.01
}),
}}
RETURN_TYPES
=
(
"CONDITIONING"
,)
FUNCTION
=
"append"
CATEGORY
=
"conditioning"
def
append
(
self
,
conditioning
,
width
,
height
,
x
,
y
,
strength
):
c
=
[]
for
t
in
conditioning
:
n
=
[
t
[
0
],
t
[
1
].
copy
()]
n
[
1
][
'area'
]
=
(
"percentage"
,
height
,
width
,
y
,
x
)
n
[
1
][
'strength'
]
=
strength
n
[
1
][
'set_area_to_bounds'
]
=
False
c
.
append
(
n
)
return
(
c
,
)
class
ConditioningSetMask
:
class
ConditioningSetMask
:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
s
):
def
INPUT_TYPES
(
s
):
...
@@ -1583,6 +1608,7 @@ NODE_CLASS_MAPPINGS = {
...
@@ -1583,6 +1608,7 @@ NODE_CLASS_MAPPINGS = {
"ConditioningCombine"
:
ConditioningCombine
,
"ConditioningCombine"
:
ConditioningCombine
,
"ConditioningConcat"
:
ConditioningConcat
,
"ConditioningConcat"
:
ConditioningConcat
,
"ConditioningSetArea"
:
ConditioningSetArea
,
"ConditioningSetArea"
:
ConditioningSetArea
,
"ConditioningSetAreaPercentage"
:
ConditioningSetAreaPercentage
,
"ConditioningSetMask"
:
ConditioningSetMask
,
"ConditioningSetMask"
:
ConditioningSetMask
,
"KSamplerAdvanced"
:
KSamplerAdvanced
,
"KSamplerAdvanced"
:
KSamplerAdvanced
,
"SetLatentNoiseMask"
:
SetLatentNoiseMask
,
"SetLatentNoiseMask"
:
SetLatentNoiseMask
,
...
@@ -1644,6 +1670,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
...
@@ -1644,6 +1670,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ConditioningAverage "
:
"Conditioning (Average)"
,
"ConditioningAverage "
:
"Conditioning (Average)"
,
"ConditioningConcat"
:
"Conditioning (Concat)"
,
"ConditioningConcat"
:
"Conditioning (Concat)"
,
"ConditioningSetArea"
:
"Conditioning (Set Area)"
,
"ConditioningSetArea"
:
"Conditioning (Set Area)"
,
"ConditioningSetAreaPercentage"
:
"Conditioning (Set Area with Percentage)"
,
"ConditioningSetMask"
:
"Conditioning (Set Mask)"
,
"ConditioningSetMask"
:
"Conditioning (Set Mask)"
,
"ControlNetApply"
:
"Apply ControlNet"
,
"ControlNetApply"
:
"Apply ControlNet"
,
"ControlNetApplyAdvanced"
:
"Apply ControlNet (Advanced)"
,
"ControlNetApplyAdvanced"
:
"Apply ControlNet (Advanced)"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment