Brushstroke Tools: Initial Version #328
340
scripts-blender/addons/brushstroke_tools/LICENSE
Normal file
340
scripts-blender/addons/brushstroke_tools/LICENSE
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Library General
|
||||||
|
Public License instead of this License.
|
0
scripts-blender/addons/brushstroke_tools/README.md
Normal file
0
scripts-blender/addons/brushstroke_tools/README.md
Normal file
11
scripts-blender/addons/brushstroke_tools/__init__.py
Normal file
11
scripts-blender/addons/brushstroke_tools/__init__.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from . import utils, settings, ui, draw_tool, ops
|
||||||
|
|
||||||
|
modules = [utils, settings, ui, draw_tool, ops]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for m in modules:
|
||||||
|
m.register()
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for m in modules:
|
||||||
SimonThommes marked this conversation as resolved
Outdated
|
|||||||
|
m.unregister()
|
Binary file not shown.
@ -0,0 +1,27 @@
|
|||||||
|
schema_version = "1.0.0"
|
||||||
|
|
||||||
|
id = "brushstroke_tools"
|
||||||
|
version = "1.0.0"
|
||||||
|
name = "Brushstroke Tools"
|
||||||
|
tagline = "Set of tools for a painterly brushstroke stylization workflow of 3D assets developed by the Blender Studio"
|
||||||
|
maintainer = "Simon Thommes <simon@blender.org>"
|
||||||
|
type = "add-on"
|
||||||
|
|
||||||
|
# Optional link to documentation, support, source files, etc
|
||||||
|
# website = "https://studio.blender.org/tools/addons/brushstroke_tools"
|
||||||
|
|
||||||
|
# Optional list defined by Blender and server, see:
|
||||||
|
# https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
|
||||||
|
tags = ["Geometry Nodes", "Grease Pencil", "Node", ]
|
||||||
|
|
||||||
|
blender_version_min = "4.2.0"
|
||||||
|
|
||||||
|
# License conforming to https://spdx.org/licenses/ (use "SPDX: prefix)
|
||||||
|
# https://docs.blender.org/manual/en/dev/advanced/extensions/licenses.html
|
||||||
|
license = [
|
||||||
|
"SPDX:GPL-2.0-or-later",
|
||||||
|
]
|
||||||
|
# Optional: required by some licenses.
|
||||||
|
# copyright = [
|
||||||
|
# "2024 Blender Foundation",
|
||||||
|
# ]
|
98
scripts-blender/addons/brushstroke_tools/draw_tool.py
Normal file
98
scripts-blender/addons/brushstroke_tools/draw_tool.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import bpy
|
||||||
|
from . import utils
|
||||||
|
from mathutils import Vector
|
||||||
|
from bpy.types import WorkSpaceTool
|
||||||
|
|
||||||
|
def node_group_settings(ng_settings, op_settings):
|
||||||
|
|
||||||
|
ng_settings.nodes['Color'].value = [*op_settings.brush_color, 1.]
|
||||||
|
ng_settings.nodes['Smear'].outputs[0].default_value = op_settings.brush_smear
|
||||||
|
#ng_settings.nodes["Object Info"].inputs[0].default_value = surface_object
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
class BSBST_OT_draw(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Custom draw operation for hair curves
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.draw"
|
||||||
|
bl_label = "Custom Draw"
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
brush_color: bpy.props.FloatVectorProperty(name='Brush Color', size=3, subtype='COLOR', default=(.0,.0,.0), soft_min=0, soft_max=1, update=None)
|
||||||
|
brush_smear: bpy.props.FloatProperty(name='Smear', subtype='FACTOR', default=0, min=0, max=1, update=None)
|
||||||
|
|
||||||
|
ng_process = None
|
||||||
|
|
||||||
|
init = True
|
||||||
|
gp = None
|
||||||
|
|
||||||
|
def modal(self, context, event):
|
||||||
|
if self.init:
|
||||||
|
#bpy.ops.grease_pencil.brush_stroke('INVOKE_DEFAULT')
|
||||||
|
bpy.ops.curves.draw('INVOKE_DEFAULT', wait_for_input=False)
|
||||||
|
self.init = False
|
||||||
|
else:
|
||||||
|
self.ng_process.nodes['settings.color'].value = [*self.brush_color, 1.]
|
||||||
|
self.ng_process.nodes['view_vector'].vector = context.space_data.region_3d.view_rotation @ Vector((0.0, 0.0, 1.0))
|
||||||
|
self.ng_process.nodes['new_key'].boolean = context.scene.tool_settings.use_keyframe_insert_auto
|
||||||
|
if 'BSBST_surface_object' in context.object.keys():
|
||||||
|
if context.object['BSBST_surface_object']:
|
||||||
|
self.ng_process.nodes['surface_object'].inputs[0].default_value = context.object['BSBST_surface_object']
|
||||||
|
#node_group_settings(self.ng_settings, self)
|
||||||
|
bpy.ops.geometry.execute_node_group(name="set_brush_stroke_color", session_uid=self.ng_process.session_uid)
|
||||||
|
return {'FINISHED'}
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
utils.ensure_resources()
|
||||||
|
if True:
|
||||||
|
BSBST_OT_draw.gp = None
|
||||||
|
BSBST_OT_draw.ng_process = bpy.data.node_groups['.brushstroke_tools.processing']
|
||||||
|
|
||||||
|
context.tool_settings.curve_paint_settings.curve_type = 'POLY' # TODO: restore later
|
||||||
|
context.tool_settings.curve_paint_settings.depth_mode = 'SURFACE' # TODO: restore later
|
||||||
|
context.tool_settings.curve_paint_settings.use_pressure_radius = True # TODO: restore later
|
||||||
|
|
||||||
|
context.window_manager.modal_handler_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
else:
|
||||||
|
self.report({'WARNING'}, "Not editable")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
|
||||||
|
class BrushstrokesCurves(WorkSpaceTool):
|
||||||
|
bl_space_type = 'VIEW_3D'
|
||||||
|
bl_context_mode = 'EDIT_CURVES'
|
||||||
|
|
||||||
|
bl_idname = "brushstroke_tools.draw"
|
||||||
|
bl_label = "Brushstroke Draw"
|
||||||
|
bl_description = (
|
||||||
|
"Brushstrokes on the visible surface"
|
||||||
|
)
|
||||||
|
bl_icon = "brush.gpencil_draw.draw"
|
||||||
|
bl_widget = None
|
||||||
|
bl_keymap = (
|
||||||
|
("brushstroke_tools.draw", {"type": 'LEFTMOUSE', "value": 'CLICK_DRAG'},
|
||||||
|
{"properties": [("wait_for_input", False)]}),
|
||||||
|
)
|
||||||
|
|
||||||
|
def draw_settings(context, layout, tool):
|
||||||
|
props = tool.operator_properties("brushstroke_tools.draw")
|
||||||
|
layout.prop(context.tool_settings.curve_paint_settings , "radius_max")
|
||||||
|
layout.prop(props, "brush_color")
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
BSBST_OT_draw,
|
||||||
|
]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
bpy.utils.register_tool(BrushstrokesCurves, after={"builtin.draw"}, group=True)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.unregister_class(c)
|
||||||
|
bpy.utils.unregister_tool(BrushstrokesCurves)
|
287
scripts-blender/addons/brushstroke_tools/ops.py
Normal file
287
scripts-blender/addons/brushstroke_tools/ops.py
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
import bpy
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
||||||
|
""" Create new object according to type.
|
||||||
|
Link to correct collection.
|
||||||
|
Attach to selection context if applicable.
|
||||||
|
Assign selected modifier setup. Enter correct context for editing.
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.new_brushstrokes"
|
||||||
|
bl_label = "New Brushstrokes"
|
||||||
|
bl_description = "Create new brushstrokes object of selected type with all the necessary setup in place"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.mode == 'OBJECT'
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
|
||||||
|
utils.ensure_resources()
|
||||||
|
|
||||||
|
surface_object = context.object if context.object in context.selected_objects else None
|
||||||
|
|
||||||
|
name = 'Brushstrokes'
|
||||||
|
|
||||||
|
if settings.curve_mode == 'GP':
|
||||||
|
bpy.ops.object.grease_pencil_add(type='EMPTY')
|
||||||
|
context.object.name = name
|
||||||
|
context.object.data.name = name
|
||||||
|
brushstrokes_object = context.object
|
||||||
|
else:
|
||||||
|
if settings.curve_mode == 'CURVE':
|
||||||
|
brushstrokes_data = bpy.data.curves.new(name, type='CURVE')
|
||||||
|
brushstrokes_data.dimensions = '3D'
|
||||||
|
elif settings.curve_mode == 'CURVES':
|
||||||
|
brushstrokes_data = bpy.data.hair_curves.new(name)
|
||||||
|
brushstrokes_object = bpy.data.objects.new(name, brushstrokes_data)
|
||||||
|
context.collection.objects.link(brushstrokes_object)
|
||||||
|
context.view_layer.objects.active = brushstrokes_object
|
||||||
|
for ob in bpy.data.objects:
|
||||||
|
ob.select_set(False)
|
||||||
|
brushstrokes_object.select_set(True)
|
||||||
|
|
||||||
|
# attach surface object pointer
|
||||||
|
brushstrokes_object['BSBST_surface_object'] = surface_object
|
||||||
|
|
||||||
|
if surface_object:
|
||||||
|
surface_object.add_rest_position_attribute = True # TODO report if library data
|
||||||
|
constraint = brushstrokes_object.constraints.new('COPY_TRANSFORMS')
|
||||||
|
constraint.target = surface_object
|
||||||
|
|
||||||
|
# assign preset material
|
||||||
|
if settings.preset_material:
|
||||||
|
override = context.copy()
|
||||||
|
override['object'] = brushstrokes_object
|
||||||
|
with context.temp_override(**override):
|
||||||
|
bpy.ops.object.material_slot_add()
|
||||||
|
brushstrokes_object.material_slots[0].material = settings.preset_material
|
||||||
|
|
||||||
|
if settings.preset_object:
|
||||||
|
# transfer preset modifiers to new brushstrokes
|
||||||
|
for mod in settings.preset_object.modifiers:
|
||||||
|
utils.transfer_modifier(mod.name, brushstrokes_object, settings.preset_object)
|
||||||
|
|
||||||
|
for v in mod.node_group.interface.items_tree.values():
|
||||||
|
if type(v) not in utils.linkable_sockets:
|
||||||
|
continue
|
||||||
|
if not settings.preset_object.modifier_info[mod.name].socket_info[v.identifier].link_context:
|
||||||
|
continue
|
||||||
|
if type(v) == bpy.types.NodeTreeInterfaceSocketObject:
|
||||||
|
brushstrokes_object.modifiers[mod.name][f'{v.identifier}'] = surface_object
|
||||||
|
elif type(v) == bpy.types.NodeTreeInterfaceSocketMaterial:
|
||||||
|
brushstrokes_object.modifiers[mod.name][f'{v.identifier}'] = settings.preset_material
|
||||||
|
# refresh UI
|
||||||
|
for mod in brushstrokes_object.modifiers:
|
||||||
|
mod.node_group.interface_update(context)
|
||||||
|
else:
|
||||||
|
# add deformation modifier
|
||||||
|
mod = brushstrokes_object.modifiers.new('Brushstrokes Deformation', 'NODES')
|
||||||
|
mod.node_group = bpy.data.node_groups['.brushstroke_tools.deformation']
|
||||||
|
mod['Socket_2'] = surface_object
|
||||||
|
|
||||||
|
if settings.assign_materials:
|
||||||
|
for mod in brushstrokes_object.modifiers:
|
||||||
|
for v in mod.node_group.interface.items_tree.values():
|
||||||
|
if type(v) != bpy.types.NodeTreeInterfaceSocketMaterial:
|
||||||
|
continue
|
||||||
|
mat = mod[v.identifier]
|
||||||
|
if not mat:
|
||||||
|
continue
|
||||||
|
if mat in [m_slot.material for m_slot in brushstrokes_object.material_slots]:
|
||||||
|
continue
|
||||||
|
override = context.copy()
|
||||||
|
override['object'] = brushstrokes_object
|
||||||
|
with context.temp_override(**override):
|
||||||
|
bpy.ops.object.material_slot_add()
|
||||||
|
brushstrokes_object.material_slots[-1].material = mat
|
||||||
|
|
||||||
|
|
||||||
|
for mod in brushstrokes_object.modifiers:
|
||||||
|
mod.show_group_selector = False
|
||||||
|
|
||||||
|
# enter mode and tool context
|
||||||
|
|
||||||
|
if settings.curve_mode == 'GP':
|
||||||
|
bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
|
||||||
|
bpy.ops.wm.tool_set_by_id(name="builtin.draw")
|
||||||
|
context.scene.tool_settings.gpencil_stroke_placement_view3d = 'SURFACE'
|
||||||
|
else:
|
||||||
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
|
bpy.ops.wm.tool_set_by_id(name="brushstroke_tools.draw")
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class BSBST_OT_init_preset(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Initialize the preset to define a modifier stack applied to new brushstrokess.
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.init_preset"
|
||||||
|
bl_label = "Initialize Preset"
|
||||||
|
bl_description = "Initialize the preset environment to setup a predefined modifier stack for new brushstrokess"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
return settings.preset_object is None
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
|
||||||
|
utils.ensure_resources()
|
||||||
|
preset_object = bpy.data.objects.new('BSBST_PRESET', bpy.data.hair_curves.new('BSBST_PRESET'))
|
||||||
|
settings.preset_object = preset_object
|
||||||
|
|
||||||
|
# add modifiers
|
||||||
|
mod = preset_object.modifiers.new('Brushstrokes Deformation', 'NODES')
|
||||||
|
mod.node_group = bpy.data.node_groups['.brushstroke_tools.deformation']
|
||||||
|
|
||||||
|
mod_info = settings.preset_object.modifier_info.get(mod.name)
|
||||||
|
if not mod_info:
|
||||||
|
mod_info = settings.preset_object.modifier_info.add()
|
||||||
|
mod_info.name = mod.name
|
||||||
|
|
||||||
|
socket_info = mod_info.socket_info.get('Socket_2')
|
||||||
|
if not socket_info:
|
||||||
|
socket_info = mod_info.socket_info.add()
|
||||||
|
socket_info.name = 'Socket_2'
|
||||||
|
socket_info.link_context = True
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class BSBST_OT_make_preset(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Make the current brushstrokes style specification the active preset.
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.make_preset"
|
||||||
|
bl_label = "Make Preset"
|
||||||
|
bl_description = "Make the current brushstrokes style specification the active preset"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return 'BSBST_surface_object' in context.object.keys()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
|
||||||
|
if not settings.preset_object:
|
||||||
|
settings.preset_object = bpy.data.objects.new('BSBST_PRESET', bpy.data.hair_curves.new('BSBST_PRESET'))
|
||||||
|
else:
|
||||||
|
for mod in settings.preset_object.modifiers[:]:
|
||||||
|
settings.preset_object.modifiers.remove(mod)
|
||||||
|
|
||||||
|
# transfer brushstrokes modifiers to preset
|
||||||
|
for mod in context.object.modifiers:
|
||||||
|
utils.transfer_modifier(mod.name, settings.preset_object, context.object)
|
||||||
|
utils.refresh_preset(None)
|
||||||
|
|
||||||
|
for mod in settings.preset_object.modifiers:
|
||||||
|
# refresh UI
|
||||||
|
mod.node_group.interface_update(context)
|
||||||
|
|
||||||
|
# identify linked sockets
|
||||||
|
for v in mod.node_group.interface.items_tree.values():
|
||||||
|
if type(v) not in utils.linkable_sockets:
|
||||||
|
continue
|
||||||
|
if not settings.preset_object.modifier_info[mod.name].socket_info[v.identifier]:
|
||||||
|
continue
|
||||||
|
if type(v) == bpy.types.NodeTreeInterfaceSocketObject:
|
||||||
|
if context.object['BSBST_surface_object']==mod[v.identifier]:
|
||||||
|
mod[v.identifier] = None
|
||||||
|
settings.preset_object.modifier_info[mod.name].socket_info[v.identifier].link_context = True
|
||||||
|
elif type(v) == bpy.types.NodeTreeInterfaceSocketMaterial:
|
||||||
|
pass # TODO: figure out material preset linking
|
||||||
|
return {"FINISHED"}
|
||||||
|
class BSBST_OT_preset_add_mod(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Add a modifier to the preset stack.
|
||||||
|
"""
|
||||||
SimonThommes marked this conversation as resolved
Outdated
Jacques Lucke
commented
It's not really necessary to have empty return statements. It's not really necessary to have empty return statements.
|
|||||||
|
bl_idname = "brushstroke_tools.preset_add_mod"
|
||||||
|
bl_label = "Add Preset Modifier"
|
||||||
|
bl_description = "Add a modifier to the preset"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
return settings.preset_object
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
settings.preset_object.modifiers.new('Brushstrokes Style', type='NODES')
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class BSBST_OT_preset_remove_mod(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Remove a modifier from the preset stack.
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.preset_remove_mod"
|
||||||
|
bl_label = "Remove Preset Modifier"
|
||||||
|
bl_description = "Remove a modifier from the preset"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
modifier: bpy.props.StringProperty(default='')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
return settings.preset_object
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
with context.temp_override(object=settings.preset_object):
|
||||||
|
bpy.ops.object.modifier_remove(modifier=self.modifier)
|
||||||
|
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class BSBST_OT_preset_toggle_attribute(bpy.types.Operator):
|
||||||
|
"""
|
||||||
|
Toggle use_attribute property for a socket on a specific object's modifier. (Workaround due to how these are actually stored as integer in Blender)
|
||||||
|
"""
|
||||||
|
bl_idname = "brushstroke_tools.preset_toggle_attribute"
|
||||||
|
bl_label = "Toggle Attribute"
|
||||||
|
bl_description = "Toggle using a named attribute for this input"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
modifier_name: bpy.props.StringProperty(default='GeometryNodes')
|
||||||
|
input_name: bpy.props.StringProperty(default='Socket_2')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
return settings.preset_object
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
override = context.copy()
|
||||||
|
override['object'] = settings.preset_object
|
||||||
|
with context.temp_override(**override):
|
||||||
|
bpy.ops.object.geometry_nodes_input_attribute_toggle(input_name=self.input_name, modifier_name=self.modifier_name)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
BSBST_OT_new_brushstrokes,
|
||||||
|
BSBST_OT_init_preset,
|
||||||
|
BSBST_OT_make_preset,
|
||||||
|
BSBST_OT_preset_add_mod,
|
||||||
|
BSBST_OT_preset_remove_mod,
|
||||||
|
BSBST_OT_preset_toggle_attribute,
|
||||||
|
]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.unregister_class(c)
|
53
scripts-blender/addons/brushstroke_tools/settings.py
Normal file
53
scripts-blender/addons/brushstroke_tools/settings.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import bpy
|
||||||
|
|
||||||
|
class BSBST_link_context_setting(bpy.types.PropertyGroup):
|
||||||
|
name: bpy.props.StringProperty(default='')
|
||||||
|
link_context: bpy.props.BoolProperty(default=False)
|
||||||
|
|
||||||
|
class BSBST_socket_info(bpy.types.PropertyGroup):
|
||||||
|
name: bpy.props.StringProperty(default='')
|
||||||
|
socket_info: bpy.props.CollectionProperty(type=BSBST_link_context_setting)
|
||||||
|
|
||||||
|
class BSBST_Settings(bpy.types.PropertyGroup):
|
||||||
|
attach_to_active_selection: bpy.props.BoolProperty(default=True)
|
||||||
|
preset_object: bpy.props.PointerProperty(type=bpy.types.Object, name="Preset Object")
|
||||||
|
preset_material: bpy.props.PointerProperty(type=bpy.types.Material, name="Preset Material")
|
||||||
|
assign_materials: bpy.props.BoolProperty(name='Assign Modifier Materials', default=True)
|
||||||
|
style_context: bpy.props.EnumProperty(default='AUTO',
|
||||||
|
items= [('PRESET', 'Preset', 'Specify the style of the current preset used for new brushstrokess', '', 0),\
|
||||||
|
('BRUSHSTROKES', 'Scribble', 'Specify the style of the currently active brushstrokes', '', 1),
|
||||||
|
('AUTO', 'Auto', 'Specify the style of either the active brushstrokes or the preset depending on the context', '', 2),
|
||||||
|
])
|
||||||
|
|
||||||
|
try:
|
||||||
|
gpv3 = bpy.context.preferences.experimental.use_grease_pencil_version3
|
||||||
|
except:
|
||||||
|
v0, v1, v3 = bpy.app.version
|
||||||
|
gpv3 = v0 >= 4 and v1 >= 3
|
||||||
|
curve_mode: bpy.props.EnumProperty(default='CURVES',
|
||||||
|
items= [('CURVE', 'Legacy', 'Use legacy curve type (Limited Support)', 'CURVE_DATA', 0),\
|
||||||
|
('CURVES', 'Curves', 'Use hair curves (Fully supported)', 'CURVES_DATA', 1),
|
||||||
|
('GP', 'Grease Pencil', 'Use Grease Pencil (Limited Support)', 'OUTLINER_OB_GREASEPENCIL', 2),
|
||||||
|
] if gpv3 else
|
||||||
|
[('CURVE', 'Legacy', 'Use legacy curve type (Limited Support)', 'CURVE_DATA', 0),\
|
||||||
|
('CURVES', 'Curves', 'Use hair curves (Full Support)', 'CURVES_DATA', 1),
|
||||||
|
])
|
||||||
|
#preset_mode
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
BSBST_link_context_setting,
|
||||||
SimonThommes marked this conversation as resolved
Outdated
Jacques Lucke
commented
Generally, the code would be easier to read if line lengths were more limited. E.g. for Blender we have a 120 line length limit. That also makes it easier to have two files open next to each other. Such limits can be enforced automatically with auto-formatters like Generally, the code would be easier to read if line lengths were more limited. E.g. for Blender we have a 120 line length limit. That also makes it easier to have two files open next to each other. Such limits can be enforced automatically with auto-formatters like `autopep8` (what we currently use in Blender) or e.g. `black`.
|
|||||||
|
BSBST_socket_info,
|
||||||
|
BSBST_Settings,
|
||||||
|
]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
bpy.types.Scene.BSBST_settings = bpy.props.PointerProperty(type=BSBST_Settings)
|
||||||
|
bpy.types.Object.modifier_info = bpy.props.CollectionProperty(type=BSBST_socket_info)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.unregister_class(c)
|
||||||
|
del bpy.types.Scene.BSBST_settings
|
||||||
|
del bpy.types.Object.modifier_info
|
151
scripts-blender/addons/brushstroke_tools/ui.py
Normal file
151
scripts-blender/addons/brushstroke_tools/ui.py
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import bpy
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def draw_panel_ui_recursive(panel, panel_name, mod, items):
|
||||||
|
|
||||||
|
scene = bpy.context.scene
|
||||||
|
settings = scene.BSBST_settings
|
||||||
|
|
||||||
|
is_preset = mod.id_data == settings.preset_object and mod.id_data
|
||||||
|
|
||||||
|
if not panel:
|
||||||
|
return
|
||||||
|
|
||||||
|
mod_info = mod.id_data.modifier_info.get(mod.name)
|
||||||
|
|
||||||
|
link_icon_dict = {bpy.types.NodeTreeInterfaceSocketObject: 'OUTLINER_OB_SURFACE',
|
||||||
|
bpy.types.NodeTreeInterfaceSocketMaterial: 'MATERIAL'}
|
||||||
|
|
||||||
|
for k, v in items:
|
||||||
|
if type(v) == bpy.types.NodeTreeInterfacePanel:
|
||||||
|
subpanel_header, subpanel = panel.panel(k, default_closed = v.default_closed)
|
||||||
|
subpanel_header.label(text=k)
|
||||||
|
draw_panel_ui_recursive(subpanel, k, mod, v.interface_items.items())
|
||||||
|
else:
|
||||||
|
if v.parent.name != panel_name:
|
||||||
|
continue
|
||||||
|
if f'{v.identifier}' not in mod.keys():
|
||||||
|
continue
|
||||||
|
row = panel.row()
|
||||||
|
col = row.column()
|
||||||
|
input_row = col.row(align=True)
|
||||||
|
if f'{v.identifier}_use_attribute' in mod.keys():
|
||||||
|
if mod[f'{v.identifier}_use_attribute']:
|
||||||
|
input_row.prop(mod, f'["{v.identifier}_attribute_name"]', text=k)
|
||||||
|
else:
|
||||||
|
input_row.prop(mod, f'["{v.identifier}"]', text=k)
|
||||||
|
if is_preset:
|
||||||
|
toggle = input_row.operator('brushstroke_tools.preset_toggle_attribute', text='', depress=mod[f'{v.identifier}_use_attribute'], icon='SPREADSHEET')
|
||||||
|
else:
|
||||||
|
toggle = input_row.operator('object.geometry_nodes_input_attribute_toggle', text='', depress=mod[f'{v.identifier}_use_attribute'], icon='SPREADSHEET')
|
||||||
|
toggle.modifier_name = mod.name
|
||||||
|
toggle.input_name = v.identifier
|
||||||
|
else:
|
||||||
|
input_row.prop(mod, f'["{v.identifier}"]', text=k)
|
||||||
|
if not mod_info:
|
||||||
|
continue
|
||||||
|
if type(v) in utils.linkable_sockets:
|
||||||
|
s = mod_info.socket_info.get(v.identifier)
|
||||||
|
col.enabled = not s.link_context
|
||||||
|
if not s:
|
||||||
|
continue
|
||||||
|
icon = link_icon_dict[type(v)] if type(v) in link_icon_dict.keys() else 'LINKED'
|
||||||
|
row.prop(s, 'link_context', text='', icon=icon)
|
||||||
|
return
|
||||||
|
|
||||||
|
class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
|
||||||
|
bl_space_type = 'VIEW_3D'
|
||||||
|
bl_region_type = 'UI'
|
||||||
|
bl_label = "Brushstroke Tools"
|
||||||
|
bl_category = "Brushstroke Tools"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
|
||||||
|
settings = context.scene.BSBST_settings
|
||||||
|
|
||||||
|
surface_object = None
|
||||||
|
if context.object:
|
||||||
|
if 'BSBST_surface_object' in context.object.keys():
|
||||||
|
surface_object = context.object['BSBST_surface_object']
|
||||||
|
else:
|
||||||
|
surface_object = context.object
|
||||||
|
layout.label(text=f'Surface Object: {surface_object.name}' if surface_object else 'No Surface Object', icon='OUTLINER_OB_SURFACE')
|
||||||
|
|
||||||
|
layout.prop(settings, 'curve_mode', expand=True)
|
||||||
|
if settings.curve_mode in ['CURVE', 'GP']:
|
||||||
|
layout.label(text='Curve mode does not support drawing on deformed geometry', icon='ERROR')
|
||||||
|
layout.operator("brushstroke_tools.new_brushstrokes", icon='GREASEPENCIL')
|
||||||
|
|
||||||
|
settings_header, settings_panel = layout.panel("brushstrokes_settings", default_closed=True)
|
||||||
|
settings_header.label(text="Settings")
|
||||||
|
if settings_panel:
|
||||||
|
settings_panel.prop(settings, 'assign_materials')
|
||||||
|
row = settings_panel.row()
|
||||||
|
row.prop(settings, 'style_context', expand=True)
|
||||||
|
|
||||||
|
# identify style context
|
||||||
|
style_object = context.object if settings.style_context=='BRUSHSTROKES' else settings.preset_object
|
||||||
|
|
||||||
|
if context.object and settings.style_context=='AUTO':
|
||||||
|
if 'BSBST_surface_object' in context.object.keys():
|
||||||
|
style_object = context.object
|
||||||
|
|
||||||
|
is_preset = style_object == settings.preset_object
|
||||||
|
|
||||||
|
style_header, style_panel = layout.panel("brushstrokes_style", default_closed=False)
|
||||||
|
if is_preset:
|
||||||
|
style_header.label(text="Style (Preset)", icon='SETTINGS')
|
||||||
|
else:
|
||||||
|
style_header.label(text="Style (Brushstrokes)", icon='OUTLINER_OB_GREASEPENCIL')
|
||||||
|
style_header.operator('brushstroke_tools.make_preset', text='', icon='DECORATE_OVERRIDE')
|
||||||
|
|
||||||
|
if style_panel:
|
||||||
|
style_panel.prop(settings, 'preset_material', icon='MATERIAL')
|
||||||
|
if not settings.preset_object:
|
||||||
|
style_panel.operator("brushstroke_tools.init_preset", icon='MODIFIER')
|
||||||
|
|
||||||
|
if style_object:
|
||||||
|
for mod in style_object.modifiers:
|
||||||
|
mod_header, mod_panel = style_panel.panel(mod.name, default_closed = False)
|
||||||
|
mod_header.label(text='', icon='GEOMETRY_NODES')
|
||||||
|
mod_header.prop(mod, 'name', text='')
|
||||||
|
|
||||||
|
if is_preset:
|
||||||
|
op = mod_header.operator('brushstroke_tools.preset_remove_mod', text='', icon='X')
|
||||||
|
else:
|
||||||
|
op = mod_header.operator('object.modifier_remove', text='', icon='X')
|
||||||
|
op.modifier = mod.name
|
||||||
|
|
||||||
|
if not mod_panel:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not mod.type == 'NODES':
|
||||||
|
mod_panel.label(text="Only 'Nodes' modifiers supported for preset interface")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# show settings for nodes modifiers
|
||||||
|
mod_panel.prop(mod, 'node_group')
|
||||||
|
if not mod.node_group:
|
||||||
|
continue
|
||||||
|
|
||||||
|
draw_panel_ui_recursive(mod_panel, '', mod, mod.node_group.interface.items_tree.items())
|
||||||
|
|
||||||
|
# expose add modifier operator for preset context
|
||||||
|
if is_preset:
|
||||||
|
style_panel.operator('brushstroke_tools.preset_add_mod', icon='ADD')
|
||||||
|
else:
|
||||||
|
style_panel.operator('object.modifier_add', text='Add Modifier', icon='ADD')
|
||||||
|
return
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
BSBST_PT_brushstroke_tools_panel,
|
||||||
|
]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.unregister_class(c)
|
94
scripts-blender/addons/brushstroke_tools/utils.py
Normal file
94
scripts-blender/addons/brushstroke_tools/utils.py
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import os
|
||||||
|
import bpy
|
||||||
|
from bpy.app.handlers import persistent
|
||||||
|
|
||||||
|
ng_list = [".brushstroke_tools.processing", ".brushstroke_tools.deformation"]
|
||||||
|
|
||||||
|
linkable_sockets = [bpy.types.NodeTreeInterfaceSocketObject, bpy.types.NodeTreeInterfaceSocketMaterial]
|
||||||
|
|
||||||
|
@persistent
|
||||||
|
def refresh_preset(dummy):
|
||||||
|
settings = bpy.context.scene.BSBST_settings
|
||||||
|
if not settings:
|
||||||
|
return
|
||||||
|
if not settings.preset_object:
|
||||||
|
return
|
||||||
|
for mod in settings.preset_object.modifiers:
|
||||||
|
if not mod.type == 'NODES':
|
||||||
|
continue
|
||||||
|
if not mod.node_group:
|
||||||
|
continue
|
||||||
|
mod_info = settings.preset_object.modifier_info.get(mod.name)
|
||||||
|
if not mod_info:
|
||||||
|
mod_info = settings.preset_object.modifier_info.add()
|
||||||
|
mod_info.name = mod.name
|
||||||
|
for v in mod.node_group.interface.items_tree.values():
|
||||||
|
if not type(v) in linkable_sockets:
|
||||||
|
continue
|
||||||
|
if v.identifier in [s.name for s in mod_info.socket_info]:
|
||||||
|
continue
|
||||||
|
n = mod_info.socket_info.add()
|
||||||
|
n.name = v.identifier
|
||||||
|
# TODO: clean up old settings
|
||||||
|
return
|
||||||
|
|
||||||
|
def get_addon_directory() -> str:
|
||||||
|
"""
|
||||||
|
Returns the path of the addon directory to be used to append resource data-blocks.
|
||||||
|
"""
|
||||||
|
return bpy.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
|
def import_resources(ng_names = ng_list):
|
||||||
|
"""
|
||||||
|
Imports the necessary blend data resources required by the addon.
|
||||||
|
"""
|
||||||
|
|
||||||
|
path = f"{get_addon_directory()}/assets/"
|
||||||
|
|
||||||
|
with bpy.data.libraries.load(f'{path}brushstroke_tools-resources.blend', link=False) as (data_src, data_dst):
|
||||||
|
data_dst.node_groups = ng_names
|
||||||
|
|
||||||
|
def ensure_resources():
|
||||||
|
ng_missing = set()
|
||||||
|
|
||||||
|
for n in ng_list:
|
||||||
|
if not bpy.data.node_groups.get(n):
|
||||||
|
ng_missing.add(n)
|
||||||
|
|
||||||
|
if ng_missing:
|
||||||
|
import_resources(list(ng_missing))
|
||||||
|
return
|
||||||
|
|
||||||
|
def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||||
|
"""
|
||||||
|
Core taken from https://projects.blender.org/studio/blender-studio-pipeline
|
||||||
|
"""
|
||||||
|
|
||||||
|
# create target mod
|
||||||
|
source_mod = source_obj.modifiers.get(modifier_name)
|
||||||
|
target_mod = target_obj.modifiers.new(source_mod.name, source_mod.type)
|
||||||
|
props = [p.identifier for p in source_mod.bl_rna.properties if not p.is_readonly]
|
||||||
|
for prop in props:
|
||||||
|
value = getattr(source_mod, prop)
|
||||||
|
setattr(target_mod, prop, value)
|
||||||
|
|
||||||
|
if source_mod.type == 'NODES':
|
||||||
|
# Transfer geo node attributes
|
||||||
|
for key, value in source_mod.items():
|
||||||
|
target_mod[key] = value
|
||||||
|
|
||||||
|
# Transfer geo node bake settings
|
||||||
|
target_mod.bake_directory = source_mod.bake_directory
|
||||||
|
for index, target_bake in enumerate(target_mod.bakes):
|
||||||
|
source_bake = source_mod.bakes[index]
|
||||||
|
props = [p.identifier for p in source_bake.bl_rna.properties if not p.is_readonly]
|
||||||
|
for prop in props:
|
||||||
|
value = getattr(source_bake, prop)
|
||||||
|
setattr(target_bake, prop, value)
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
bpy.app.handlers.depsgraph_update_post.remove(refresh_preset)
|
Loading…
Reference in New Issue
Block a user
Generally it's recommended to unregister in reverse registration order:
for m in reversed(modules):