2025-12-01
This commit is contained in:
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state 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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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 Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,5 @@
|
||||
# Easy Weight
|
||||
|
||||
Easy Weight is an addon focused on quality of life improvements for weight painting in Blender.
|
||||
|
||||
You can find the documentation [here](https://studio.blender.org/tools/addons/easy_weight).
|
||||
@@ -0,0 +1,80 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from . import (
|
||||
force_apply_mirror,
|
||||
mode_switch_hook,
|
||||
operators,
|
||||
weight_cleaner,
|
||||
weight_pie,
|
||||
vertex_group_menu,
|
||||
rogue_weights,
|
||||
prefs_to_disk,
|
||||
prefs,
|
||||
utils,
|
||||
)
|
||||
import bpy
|
||||
import importlib
|
||||
|
||||
bl_info = {
|
||||
"name": "Easy Weight",
|
||||
"author": "Demeter Dzadik",
|
||||
"version": (1, 0, 5),
|
||||
"blender": (4, 2, 0),
|
||||
"location": "3D View -> Sidebar -> Easy Weight",
|
||||
"description": "Operators to make weight painting easier.",
|
||||
"category": "Rigging",
|
||||
"doc_url": "https://studio.blender.org/tools/addons/easy_weight",
|
||||
"tracker_url": "https://projects.blender.org/studio/blender-studio-tools",
|
||||
}
|
||||
|
||||
|
||||
modules = [
|
||||
force_apply_mirror,
|
||||
mode_switch_hook,
|
||||
operators,
|
||||
weight_cleaner,
|
||||
weight_pie,
|
||||
vertex_group_menu,
|
||||
rogue_weights,
|
||||
prefs_to_disk,
|
||||
prefs,
|
||||
utils,
|
||||
]
|
||||
|
||||
|
||||
def register_unregister_modules(modules, register: bool):
|
||||
"""Recursively register or unregister modules by looking for either
|
||||
un/register() functions or lists named `registry` which should be a list of
|
||||
registerable classes.
|
||||
"""
|
||||
register_func = bpy.utils.register_class if register else bpy.utils.unregister_class
|
||||
|
||||
for mod in modules:
|
||||
if register:
|
||||
importlib.reload(mod)
|
||||
if hasattr(mod, 'registry'):
|
||||
for class_to_register in mod.registry:
|
||||
try:
|
||||
register_func(class_to_register)
|
||||
except Exception as e:
|
||||
un = 'un' if not register else ''
|
||||
print(f"Warning: Failed to {un}register class: {class_to_register.__name__}")
|
||||
print(e)
|
||||
|
||||
if hasattr(mod, 'modules'):
|
||||
register_unregister_modules(mod.modules, register)
|
||||
|
||||
if register and hasattr(mod, 'register'):
|
||||
mod.register()
|
||||
elif hasattr(mod, 'unregister'):
|
||||
mod.unregister()
|
||||
|
||||
|
||||
def register():
|
||||
register_unregister_modules(modules, True)
|
||||
|
||||
|
||||
def unregister():
|
||||
register_unregister_modules(modules, False)
|
||||
@@ -0,0 +1,19 @@
|
||||
schema_version = "1.0.0"
|
||||
|
||||
id = "easyweight"
|
||||
version = "1.0.7"
|
||||
name = "EasyWeight"
|
||||
tagline = "Weight Painting Workflow Boosters"
|
||||
maintainer = "Demeter Dzadik <demeter@blender.org>"
|
||||
type = "add-on"
|
||||
website = "https://studio.blender.org/tools/addons/easy_weight"
|
||||
tags = ["Rigging"]
|
||||
|
||||
blender_version_min = "4.2.0"
|
||||
|
||||
license = [
|
||||
"SPDX:GPL-3.0-or-later",
|
||||
]
|
||||
copyright = [
|
||||
"2019-2024 Demeter Dzadik & Blender Studio",
|
||||
]
|
||||
@@ -0,0 +1,280 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.props import BoolProperty
|
||||
from bpy.utils import flip_name
|
||||
|
||||
# TODO:
|
||||
# Should find a way to select the X axis verts before doing Remove Doubles, or don't Remove Doubles at all. Also need to select the Basis shape before doing Remove Doubles.
|
||||
# Implement our own Remove Doubles algo with kdtree, which would average the vertex weights of the merged verts rather than just picking the weights of one of them at random.
|
||||
|
||||
|
||||
def flip_driver_targets(obj):
|
||||
# We just need to flip the bone targets on every driver.
|
||||
shape_keys = obj.data.shape_keys
|
||||
if not shape_keys:
|
||||
return
|
||||
if not hasattr(shape_keys.animation_data, "drivers"):
|
||||
return
|
||||
drivers = shape_keys.animation_data.drivers
|
||||
|
||||
for sk in shape_keys.key_blocks:
|
||||
# Capital D signifies that this is a driver container (known as a driver) rather than a driver(also known as driver) - Yes, the naming convention for drivers in python API is BAD. D=driver, d=driver.driver.
|
||||
for D in drivers:
|
||||
if sk.name in D.data_path:
|
||||
sk.vertex_group = flip_name(sk.vertex_group)
|
||||
for var in D.driver.variables:
|
||||
for t in var.targets:
|
||||
if not t.bone_target:
|
||||
continue
|
||||
t.bone_target = flip_name(t.bone_target)
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_force_apply_mirror(bpy.types.Operator):
|
||||
"""Force apply mirror modifier by duplicating the object, flipping it on the X axis, merging into the original, and welding it at the middle"""
|
||||
|
||||
bl_idname = "object.force_apply_mirror_modifier"
|
||||
bl_label = "Force Apply Mirror Modifier"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
remove_doubles: BoolProperty(name="Remove Doubles", default=False)
|
||||
weighted_normals: BoolProperty(name="Weighted Normals", default=True)
|
||||
split_shape_keys: BoolProperty(
|
||||
name="Split Shape Keys",
|
||||
default=True,
|
||||
description="If shape keys end in either .L or .R, duplicate them and flip their mask vertex group name",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
obj = context.active_object
|
||||
if not (obj and obj.type == 'MESH' and obj.data and obj.data.shape_keys):
|
||||
cls.poll_message_set("There must be an active mesh object with shape keys.")
|
||||
return False
|
||||
for mod in obj.modifiers:
|
||||
if mod.type == 'MIRROR':
|
||||
if mod.use_axis[:] != (True, False, False):
|
||||
cls.poll_message_set("Only X axis mirror modifier is supported.")
|
||||
return False
|
||||
|
||||
return True
|
||||
else:
|
||||
cls.poll_message_set("This mesh has no Mirror modifier.")
|
||||
|
||||
return False
|
||||
|
||||
def execute(self, context):
|
||||
# Remove Mirror Modifier
|
||||
# Copy mesh
|
||||
# Scale it -1 on X
|
||||
# Flip vgroup names
|
||||
# Join into original mesh
|
||||
# Remove doubles
|
||||
# Recalc Normals
|
||||
# Weight Normals
|
||||
|
||||
obj = context.active_object
|
||||
|
||||
# Find Mirror modifier.
|
||||
mirror = None
|
||||
for mod in obj.modifiers:
|
||||
if mod.type == 'MIRROR':
|
||||
mirror = mod
|
||||
break
|
||||
if not mirror:
|
||||
return {'CANCELLED'}
|
||||
|
||||
if mirror.use_axis[:] != (True, False, False):
|
||||
self.report({'ERROR'}, "Only X axis mirroring is supported for now.")
|
||||
return {'CANCELLED'}
|
||||
|
||||
# Remove mirror modifier.
|
||||
obj.modifiers.remove(mirror)
|
||||
|
||||
# Set mode and selection.
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
obj.select_set(True)
|
||||
context.view_layer.objects.active = obj
|
||||
|
||||
# Remove Doubles - This should print out removed 0, otherwise we're gonna remove some important verts.
|
||||
if self.remove_doubles:
|
||||
print(
|
||||
"Checking for doubles pre-mirror. If it doesn't say Removed 0 vertices, you should undo."
|
||||
)
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
bpy.ops.mesh.remove_doubles(use_unselected=True)
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Reset scale.
|
||||
org_scale = obj.scale[:]
|
||||
obj.scale = (1, 1, 1)
|
||||
|
||||
# Duplicate and scale object.
|
||||
bpy.ops.object.duplicate()
|
||||
flipped_o = context.active_object
|
||||
flipped_o.scale = (-1, 1, 1)
|
||||
|
||||
# Flip vertex group names.
|
||||
done = [] # Don't flip names twice...
|
||||
for vgroup in flipped_o.vertex_groups:
|
||||
if vgroup in done:
|
||||
continue
|
||||
old_name = vgroup.name
|
||||
flipped_name = flip_name(vgroup.name)
|
||||
if old_name == flipped_name:
|
||||
continue
|
||||
|
||||
opp_vgroup = flipped_o.vertex_groups.get(flipped_name)
|
||||
if opp_vgroup:
|
||||
vgroup.name = "temp"
|
||||
opp_vgroup.name = old_name
|
||||
vgroup.name = flipped_name
|
||||
done.append(opp_vgroup)
|
||||
|
||||
vgroup.name = flipped_name
|
||||
done.append(vgroup)
|
||||
|
||||
# Split/Flip shape keys.
|
||||
if self.split_shape_keys:
|
||||
done = [] # Don't flip names twice...
|
||||
shape_keys = flipped_o.data.shape_keys
|
||||
if shape_keys:
|
||||
key_blocks = shape_keys.key_blocks
|
||||
for key_block in key_blocks:
|
||||
if key_block in done:
|
||||
continue
|
||||
old_name = key_block.name
|
||||
flipped_name = flip_name(key_block.name)
|
||||
if old_name == flipped_name:
|
||||
continue
|
||||
|
||||
opp_sk = key_blocks.get(flipped_name)
|
||||
if opp_sk:
|
||||
key_block.name = "temp"
|
||||
opp_sk.name = old_name
|
||||
done.append(opp_sk)
|
||||
|
||||
key_block.name = flipped_name
|
||||
done.append(key_block)
|
||||
|
||||
flip_driver_targets(flipped_o)
|
||||
|
||||
# Joining objects does not seem to preserve drivers on any except the active object, at least for shape keys.
|
||||
# To work around this, we duplicate the flipped mesh again, so we can copy the drivers over from that copy to the merged version...
|
||||
bpy.ops.object.duplicate()
|
||||
copy_of_flipped = context.active_object
|
||||
copy_of_flipped.select_set(False)
|
||||
|
||||
flipped_o.select_set(True)
|
||||
obj.select_set(True)
|
||||
# We want to be sure the original is the active so the object name doesn't get a .001
|
||||
context.view_layer.objects.active = obj
|
||||
bpy.ops.object.join()
|
||||
|
||||
combined_object = context.active_object
|
||||
|
||||
# Copy drivers from the duplicate.
|
||||
if hasattr(copy_of_flipped.data.shape_keys, "animation_data") and hasattr(
|
||||
copy_of_flipped.data.shape_keys.animation_data, "drivers"
|
||||
):
|
||||
for old_D in copy_of_flipped.data.shape_keys.animation_data.drivers:
|
||||
for key_block in combined_object.data.shape_keys.key_blocks:
|
||||
if key_block.name in old_D.data_path:
|
||||
# Create the driver...
|
||||
new_D = combined_object.data.shape_keys.driver_add(
|
||||
'key_blocks["' + key_block.name + '"].value'
|
||||
)
|
||||
new_d = new_D.driver
|
||||
old_d = old_D.driver
|
||||
|
||||
expression = old_d.expression
|
||||
# The beginning of shape key names will indicate which axes should be flipped... What an awful solution! :)
|
||||
flip_x = False
|
||||
flip_y = False
|
||||
flip_z = False
|
||||
flip_flags = key_block.name.split("_")[0]
|
||||
# This code is just getting better :)
|
||||
if flip_flags in ['XYZ', 'XZ', 'XY', 'YZ', 'Z']:
|
||||
if ('X') in flip_flags:
|
||||
flip_x = True
|
||||
if ('Y') in flip_flags:
|
||||
flip_y = True
|
||||
if ('Z') in flip_flags:
|
||||
flip_z = True
|
||||
|
||||
for v in old_d.variables:
|
||||
new_v = new_d.variables.new()
|
||||
new_v.name = v.name
|
||||
new_v.type = v.type
|
||||
for i in range(len(v.targets)):
|
||||
if new_v.type == 'SINGLE_PROP':
|
||||
new_v.targets[i].id_type = v.targets[i].id_type
|
||||
new_v.targets[i].id = v.targets[i].id
|
||||
new_v.targets[i].bone_target = v.targets[i].bone_target
|
||||
new_v.targets[i].data_path = v.targets[i].data_path
|
||||
new_v.targets[i].transform_type = v.targets[i].transform_type
|
||||
new_v.targets[i].transform_space = v.targets[i].transform_space
|
||||
|
||||
if (
|
||||
new_v.targets[0].bone_target
|
||||
and "SCALE" not in v.targets[0].transform_type
|
||||
and (v.targets[0].transform_type.endswith("_X") and flip_x)
|
||||
or (v.targets[0].transform_type.endswith("_Y") and flip_y)
|
||||
or (v.targets[0].transform_type.endswith("_Z") and flip_z)
|
||||
):
|
||||
# Flipping sign - this is awful, I know.
|
||||
if "-" + new_v.name in expression:
|
||||
expression = expression.replace(
|
||||
"-" + new_v.name, "+" + new_v.name
|
||||
)
|
||||
elif "+ " + new_v.name in expression:
|
||||
expression = expression.replace(
|
||||
"+ " + new_v.name, "- " + new_v.name
|
||||
)
|
||||
else:
|
||||
expression = expression.replace(new_v.name, "-" + new_v.name)
|
||||
|
||||
new_d.expression = expression
|
||||
|
||||
# Delete the copy
|
||||
copy_of_flipped.select_set(True)
|
||||
combined_object.select_set(False)
|
||||
bpy.ops.object.delete(use_global=False)
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
bpy.ops.mesh.select_all(action='SELECT')
|
||||
bpy.ops.mesh.normals_make_consistent(inside=False)
|
||||
|
||||
# Mesh cleanup
|
||||
if self.remove_doubles:
|
||||
bpy.ops.mesh.remove_doubles()
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
if self.weighted_normals and "calculate_weighted_normals" in dir(bpy.ops.object):
|
||||
bpy.ops.object.calculate_weighted_normals()
|
||||
|
||||
# Restore scale
|
||||
context.active_object.scale = org_scale
|
||||
|
||||
self.report({'INFO'}, "Applied X-Mirror modifier with shape keys.")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def draw_force_apply_mirror(self, context):
|
||||
self.layout.separator()
|
||||
self.layout.operator(EASYWEIGHT_OT_force_apply_mirror.bl_idname, icon='MOD_MIRROR')
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_force_apply_mirror]
|
||||
|
||||
|
||||
def register():
|
||||
bpy.types.MESH_MT_shape_key_context_menu.append(draw_force_apply_mirror)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.types.MESH_MT_shape_key_context_menu.remove(draw_force_apply_mirror)
|
||||
@@ -0,0 +1,141 @@
|
||||
import bpy
|
||||
from bpy.types import Object
|
||||
from .utils import get_addon_prefs
|
||||
|
||||
mode_history = []
|
||||
suspend_hook = False
|
||||
|
||||
def on_weight_paint_enter():
|
||||
context = bpy.context
|
||||
obj = context.active_object
|
||||
wm = context.window_manager
|
||||
|
||||
viewports = []
|
||||
for window in wm.windows:
|
||||
for area in window.workspace.screens[0].areas:
|
||||
if area.spaces.active and area.spaces.active.type == 'VIEW_3D':
|
||||
viewports.append(area.spaces.active)
|
||||
|
||||
prefs = get_addon_prefs(context)
|
||||
tool_settings = context.scene.tool_settings
|
||||
if prefs.always_show_zero_weights:
|
||||
tool_settings.vertex_group_user = 'ACTIVE'
|
||||
if prefs.always_auto_normalize:
|
||||
tool_settings.use_auto_normalize = True
|
||||
if prefs.always_multipaint:
|
||||
tool_settings.use_multipaint = True
|
||||
|
||||
# Store old visibility settings in a Custom Property in the WindowManager.
|
||||
if 'weight_paint_toggle' not in wm:
|
||||
wm['weight_paint_toggle'] = {}
|
||||
|
||||
wp_toggle = wm['weight_paint_toggle']
|
||||
|
||||
# ENSURING ARMATURE VISIBILITY
|
||||
armature = get_armature_of_meshob(obj)
|
||||
if not armature:
|
||||
return
|
||||
print("Entering WP mode: ", context.active_object.name, armature.name)
|
||||
# Save all object visibility related info so it can be restored later.
|
||||
wp_toggle['arm_disabled'] = armature.hide_viewport
|
||||
wp_toggle['arm_hide'] = armature.hide_get()
|
||||
wp_toggle['arm_coll_assigned'] = False
|
||||
armature.hide_viewport = False
|
||||
armature.hide_set(False)
|
||||
|
||||
for viewport in viewports:
|
||||
if viewport.local_view:
|
||||
wp_toggle['arm_local_view'] = armature.local_view_get(viewport)
|
||||
armature.local_view_set(viewport, True)
|
||||
if prefs.always_xray:
|
||||
wp_toggle['bone_xray'] = viewport.overlay.show_xray_bone
|
||||
viewport.overlay.show_xray_bone = True
|
||||
|
||||
# If the armature is still not visible, add it to the scene root collection.
|
||||
if not armature.visible_get() and not armature.name in context.scene.collection.objects:
|
||||
context.scene.collection.objects.link(armature)
|
||||
wp_toggle['arm_coll_assigned'] = True
|
||||
|
||||
if armature.visible_get():
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
context.view_layer.objects.active = armature
|
||||
armature.select_set(True)
|
||||
context.view_layer.objects.active = obj
|
||||
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
|
||||
|
||||
return armature.visible_get()
|
||||
|
||||
|
||||
def on_weight_paint_leave():
|
||||
context = bpy.context
|
||||
obj = context.active_object
|
||||
wm = context.window_manager
|
||||
|
||||
viewports = []
|
||||
for window in wm.windows:
|
||||
for area in window.workspace.screens[0].areas:
|
||||
if area.spaces.active and area.spaces.active.type == 'VIEW_3D':
|
||||
viewports.append(area.spaces.active)
|
||||
|
||||
if 'weight_paint_toggle' not in wm:
|
||||
# There is no saved data to restore from, nothing else to do.
|
||||
return
|
||||
|
||||
wp_toggle = wm['weight_paint_toggle']
|
||||
wp_toggle_as_dict = wp_toggle.to_dict()
|
||||
|
||||
# Reset the stored data
|
||||
wm['weight_paint_toggle'] = {}
|
||||
|
||||
armature = get_armature_of_meshob(obj)
|
||||
if not armature:
|
||||
return
|
||||
|
||||
if armature.visible_get():
|
||||
context.view_layer.objects.active = armature
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
context.view_layer.objects.active = obj
|
||||
|
||||
# If an armature was un-hidden, hide it again.
|
||||
armature.hide_viewport = wp_toggle_as_dict['arm_disabled']
|
||||
armature.hide_set(wp_toggle_as_dict['arm_hide'])
|
||||
|
||||
# Restore whether the armature is in local view or not.
|
||||
for viewport in viewports:
|
||||
if 'arm_local_view' in wp_toggle_as_dict and viewport.local_view:
|
||||
armature.local_view_set(viewport, wp_toggle_as_dict['arm_local_view'])
|
||||
if 'bone_xray' in wp_toggle_as_dict:
|
||||
viewport.overlay.show_xray_bone = wp_toggle_as_dict['bone_xray']
|
||||
|
||||
# Remove armature from scene root collection if it was moved there.
|
||||
if wp_toggle_as_dict['arm_coll_assigned']:
|
||||
context.scene.collection.objects.unlink(armature)
|
||||
|
||||
|
||||
def get_armature_of_meshob(obj: Object):
|
||||
"""Find and return the armature that deforms this mesh object."""
|
||||
for mod in obj.modifiers:
|
||||
if mod.type == 'ARMATURE':
|
||||
return mod.object
|
||||
|
||||
@bpy.app.handlers.persistent
|
||||
def detect_mode_switch(scene=None, depsgraph=None):
|
||||
global suspend_hook
|
||||
if suspend_hook:
|
||||
return
|
||||
context = bpy.context
|
||||
mode_history.append(context.mode)
|
||||
if mode_history[-1] == 'PAINT_WEIGHT' and (len(mode_history)==1 or mode_history[-2] != 'PAINT_WEIGHT'):
|
||||
suspend_hook = True
|
||||
on_weight_paint_enter()
|
||||
suspend_hook = False
|
||||
elif len(mode_history) > 1 and mode_history[-2] == 'PAINT_WEIGHT' and mode_history[-1] != 'PAINT_WEIGHT':
|
||||
suspend_hook = True
|
||||
on_weight_paint_leave()
|
||||
suspend_hook = False
|
||||
|
||||
def register():
|
||||
bpy.app.handlers.depsgraph_update_post.append(detect_mode_switch)
|
||||
|
||||
def unregister():
|
||||
bpy.app.handlers.depsgraph_update_post.remove(detect_mode_switch)
|
||||
@@ -0,0 +1,19 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from . import (
|
||||
delete_empty_deform_groups,
|
||||
delete_unselected_deform_groups,
|
||||
delete_unused_groups,
|
||||
focus_deforming_bones,
|
||||
symmetrize_weights,
|
||||
)
|
||||
|
||||
modules = [
|
||||
delete_empty_deform_groups,
|
||||
delete_unselected_deform_groups,
|
||||
delete_unused_groups,
|
||||
focus_deforming_bones,
|
||||
symmetrize_weights,
|
||||
]
|
||||
@@ -0,0 +1,79 @@
|
||||
# SPDX-FileCopyrightText: 2021 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from bpy.types import Operator, Object, VertexGroup
|
||||
from bpy.utils import flip_name
|
||||
|
||||
from ..utils import delete_vgroups, poll_deformed_mesh_with_vgroups, get_deforming_vgroups
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_delete_empty_deform_groups(Operator):
|
||||
"""Delete vertex groups which are associated to deforming bones but don't have any weights"""
|
||||
|
||||
bl_idname = "object.delete_empty_deform_vgroups"
|
||||
bl_label = "Delete Empty Deform Groups"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_deformed_mesh_with_vgroups(cls, context)
|
||||
|
||||
def execute(self, context):
|
||||
empty_groups = get_empty_deforming_vgroups(context.active_object)
|
||||
|
||||
num_groups = len(empty_groups)
|
||||
print(f"Deleting empty deform groups:")
|
||||
print(" " + "\n ".join([vg.name for vg in empty_groups]))
|
||||
|
||||
delete_vgroups(context.active_object, empty_groups)
|
||||
|
||||
self.report({'INFO'}, f"Deleted {num_groups} empty deform groups.")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def get_non_deforming_vgroups(mesh_ob: Object) -> set:
|
||||
"""Get the vertex groups of a mesh object that don't correspond to a deform bone in the given armature."""
|
||||
deforming_vgroups = get_deforming_vgroups(mesh_ob)
|
||||
return set(mesh_ob.vertex_groups) - set(deforming_vgroups)
|
||||
|
||||
|
||||
def get_empty_deforming_vgroups(mesh_ob: Object) -> list[VertexGroup]:
|
||||
deforming_vgroups = get_deforming_vgroups(mesh_ob)
|
||||
empty_deforming_groups = [vg for vg in deforming_vgroups if not vgroup_has_weight(mesh_ob, vg)]
|
||||
|
||||
# If there's no Mirror modifier, we're done.
|
||||
if not 'MIRROR' in (m.type for m in mesh_ob.modifiers):
|
||||
return empty_deforming_groups
|
||||
|
||||
# Mirror Modifier: A group is not considered empty if it is the opposite
|
||||
# of a non-empty group.
|
||||
for vgroup in empty_deforming_groups[:]:
|
||||
opp_vgroup = mesh_ob.vertex_groups.get(flip_name(vgroup.name))
|
||||
if not opp_vgroup:
|
||||
continue
|
||||
if opp_vgroup not in empty_deforming_groups:
|
||||
empty_deforming_groups.remove(vgroup)
|
||||
|
||||
return empty_deforming_groups
|
||||
|
||||
|
||||
def get_vgroup_weight_on_vert(vgroup, vert_idx) -> float:
|
||||
# Despite how terrible this is, as of 04/Jun/2021 it seems to be the
|
||||
# only only way to ask Blender if a vertex is assigned to a vertex group.
|
||||
try:
|
||||
weight = vgroup.weight(vert_idx)
|
||||
return weight
|
||||
except RuntimeError:
|
||||
return -1
|
||||
|
||||
|
||||
def vgroup_has_weight(mesh_ob, vgroup) -> bool:
|
||||
for i in range(0, len(mesh_ob.data.vertices)):
|
||||
if get_vgroup_weight_on_vert(vgroup, i) > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_delete_empty_deform_groups]
|
||||
@@ -0,0 +1,38 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from bpy.types import Operator
|
||||
|
||||
from ..utils import delete_vgroups, poll_weight_paint_mode, get_deforming_vgroups
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_delete_unselected_deform_groups(Operator):
|
||||
"""Delete deforming vertex groups that do not correspond to any selected pose bone"""
|
||||
|
||||
bl_idname = "object.delete_unselected_deform_vgroups"
|
||||
bl_label = "Delete Unselected Deform Groups"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_weight_paint_mode(cls, context, with_rig=True, with_groups=True)
|
||||
|
||||
def execute(self, context):
|
||||
deforming_groups = get_deforming_vgroups(context.active_object)
|
||||
selected_bone_names = [b.name for b in context.selected_pose_bones]
|
||||
unselected_def_groups = [
|
||||
vg for vg in deforming_groups if vg.name not in selected_bone_names
|
||||
]
|
||||
|
||||
print(f"Deleting unselected deform groups:")
|
||||
deleted_names = [vg.name for vg in unselected_def_groups]
|
||||
print(" " + "\n ".join(deleted_names))
|
||||
|
||||
delete_vgroups(context.active_object, unselected_def_groups)
|
||||
|
||||
self.report({'INFO'}, f"Deleted {len(deleted_names)} unselected deform groups.")
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_delete_unselected_deform_groups]
|
||||
@@ -0,0 +1,160 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.types import Operator, Object, VertexGroup, Modifier
|
||||
|
||||
from ..utils import delete_vgroups, poll_deformed_mesh_with_vgroups, get_deforming_vgroups
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_delete_unused_vertex_groups(Operator):
|
||||
"""Delete vertex groups which are not used by any modifiers, deforming bones, shape keys, or constraints"""
|
||||
|
||||
bl_idname = "object.delete_unused_vgroups"
|
||||
bl_label = "Delete Unused Vertex Groups"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_deformed_mesh_with_vgroups(cls, context, must_deform=False)
|
||||
|
||||
def execute(self, context):
|
||||
deleted_names = delete_unused_vgroups(context.active_object)
|
||||
|
||||
self.report({'INFO'}, f"Deleted {len(deleted_names)} unused non-deform groups.")
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def delete_unused_vgroups(mesh_ob: Object) -> list[str]:
|
||||
"""Returns a list of vertex group names that got deleted."""
|
||||
groups_to_delete = get_unused_vgroups(mesh_ob)
|
||||
|
||||
names = [vgroup.name for vgroup in groups_to_delete]
|
||||
print(f"Deleting unused non-deform groups:")
|
||||
print(" " + "\n ".join(names))
|
||||
|
||||
delete_vgroups(mesh_ob, groups_to_delete)
|
||||
|
||||
return names
|
||||
|
||||
|
||||
def get_unused_vgroups(mesh_ob: Object) -> set[VertexGroup]:
|
||||
return set(mesh_ob.vertex_groups) - set(get_used_vgroups(mesh_ob))
|
||||
|
||||
|
||||
def get_used_vgroups(mesh_ob: Object) -> list[VertexGroup]:
|
||||
"""Get a list of vertex groups used by the object.
|
||||
|
||||
Currently accounts for Modifiers, Armatures, GeoNodes, Physics,
|
||||
Shape Keys, and Constraints of dependent objects.
|
||||
"""
|
||||
|
||||
used_vgroups = []
|
||||
# Inputs of Modifiers, including GeoNodes.
|
||||
for modifier in mesh_ob.modifiers:
|
||||
if modifier.type == 'NODES':
|
||||
print(modifier.name)
|
||||
used_vgroups.extend(get_vgroups_used_by_geonodes(mesh_ob, modifier))
|
||||
else:
|
||||
used_vgroups.extend(get_referenced_vgroups(mesh_ob, modifier))
|
||||
if modifier.type == 'ARMATURE':
|
||||
used_vgroups.extend(get_deforming_vgroups(mesh_ob, modifier.object))
|
||||
# Masks of Physics settings.
|
||||
if hasattr(modifier, 'settings'):
|
||||
used_vgroups.extend(get_referenced_vgroups(mesh_ob, modifier.settings))
|
||||
|
||||
# Masks of Shape Keys.
|
||||
used_vgroups.extend(get_vgroups_used_by_shape_keys(mesh_ob))
|
||||
|
||||
# Constraints of dependent objects.
|
||||
used_vgroups.extend(get_vgroups_used_by_constraints_of_dependent_objects(mesh_ob))
|
||||
|
||||
return used_vgroups
|
||||
|
||||
|
||||
def get_referenced_vgroups(mesh_ob: Object, py_ob: object) -> list[VertexGroup]:
|
||||
"""Return a list of vertex groups directly referenced by any of the PyObject's members.
|
||||
Note that this is NOT a recursive function, and it can't really become one.
|
||||
|
||||
Useful for determining if a vertex group is used by anything or not, but
|
||||
you still have to be thorough, and call this function on any sub-member
|
||||
of some object that might reference vertex groups."""
|
||||
referenced_vgroups = []
|
||||
for member in dir(py_ob):
|
||||
value = getattr(py_ob, member)
|
||||
if type(value) != str:
|
||||
continue
|
||||
vg = mesh_ob.vertex_groups.get(value)
|
||||
if vg:
|
||||
referenced_vgroups.append(vg)
|
||||
return referenced_vgroups
|
||||
|
||||
|
||||
def get_vgroups_used_by_shape_keys(mesh_ob) -> list[VertexGroup]:
|
||||
mask_vgroups = []
|
||||
if not mesh_ob.data.shape_keys:
|
||||
return mask_vgroups
|
||||
for key_block in mesh_ob.data.shape_keys.key_blocks:
|
||||
vgroup = mesh_ob.vertex_groups.get(key_block.vertex_group)
|
||||
if vgroup and vgroup.name not in mask_vgroups:
|
||||
mask_vgroups.append(vgroup)
|
||||
return mask_vgroups
|
||||
|
||||
|
||||
def get_vgroups_used_by_constraints_of_dependent_objects(
|
||||
mesh_ob: Object,
|
||||
) -> list[VertexGroup]:
|
||||
used_vgroups = []
|
||||
dependent_objs = [id for id in bpy.data.user_map()[mesh_ob] if type(id) == Object]
|
||||
for dependent_obj in dependent_objs:
|
||||
constraint_lists = [dependent_obj.constraints]
|
||||
if dependent_obj.type == 'ARMATURE':
|
||||
constraint_lists += [pb.constraints for pb in dependent_obj.pose.bones]
|
||||
|
||||
for constraint_list in constraint_lists:
|
||||
for constraint in constraint_list:
|
||||
if (
|
||||
hasattr(constraint, 'target')
|
||||
and hasattr(constraint, 'subtarget')
|
||||
and constraint.target == mesh_ob
|
||||
and constraint.subtarget
|
||||
):
|
||||
vgroup = mesh_ob.vertex_groups.get(constraint.subtarget)
|
||||
if vgroup:
|
||||
used_vgroups.append(vgroup)
|
||||
if constraint.space_object == mesh_ob and constraint.space_subtarget:
|
||||
vgroup = mesh_ob.vertex_groups.get(constraint.space_subtarget)
|
||||
if vgroup:
|
||||
used_vgroups.append(vgroup)
|
||||
return used_vgroups
|
||||
|
||||
|
||||
def get_vgroups_used_by_geonodes(mesh_ob: Object, modifier: Modifier) -> list[VertexGroup]:
|
||||
used_vgroups = []
|
||||
for identifier in geomod_get_input_identifiers(modifier):
|
||||
use_attrib = identifier + "_use_attribute"
|
||||
if use_attrib in modifier and modifier[use_attrib]:
|
||||
attrib_name = modifier[identifier + "_attribute_name"]
|
||||
if attrib_name in mesh_ob.vertex_groups:
|
||||
# NOTE: Could be a false positive if this is a non-vertexgroup attribute with a matching name.
|
||||
used_vgroups.append(mesh_ob.vertex_groups[attrib_name])
|
||||
return used_vgroups
|
||||
|
||||
|
||||
def geomod_get_input_identifiers(modifier: Modifier) -> set[str]:
|
||||
if hasattr(modifier.node_group, 'interface'):
|
||||
# 4.0
|
||||
return {
|
||||
socket.identifier
|
||||
for socket in modifier.node_group.interface.items_tree
|
||||
if socket.item_type == 'SOCKET'
|
||||
and socket.in_out == 'INPUT'
|
||||
and socket.socket_type != 'NodeSocketGeometry'
|
||||
}
|
||||
else:
|
||||
# 3.6
|
||||
return {input.identifier for input in modifier.node_group.inputs[1:]}
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_delete_unused_vertex_groups]
|
||||
@@ -0,0 +1,39 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from bpy.types import Operator
|
||||
|
||||
from ..utils import poll_weight_paint_mode, reveal_bone, get_deforming_vgroups
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_focus_deform_bones(Operator):
|
||||
"""While in Weight Paint Mode, reveal the layers of, unhide, and select the bones of all deforming vertex groups"""
|
||||
|
||||
bl_idname = "object.focus_deform_vgroups"
|
||||
bl_label = "Focus Deforming Bones"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_weight_paint_mode(cls, context, with_rig=True, with_groups=True)
|
||||
|
||||
def execute(self, context):
|
||||
# Deselect all bones
|
||||
for pb in context.selected_pose_bones[:]:
|
||||
pb.bone.select = False
|
||||
|
||||
# Reveal and select all deforming pose bones.
|
||||
deform_groups = get_deforming_vgroups(context.active_object)
|
||||
rig = context.pose_object
|
||||
for vg in deform_groups:
|
||||
pb = rig.pose.bones.get(vg.name)
|
||||
if not pb:
|
||||
continue
|
||||
reveal_bone(pb.bone, select=True)
|
||||
|
||||
self.report({'INFO'}, "Un-hid and selected all deforming bones.")
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_focus_deform_bones]
|
||||
@@ -0,0 +1,217 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from bpy.types import Operator, Object
|
||||
from bpy.props import EnumProperty
|
||||
from bpy.utils import flip_name
|
||||
from mathutils.kdtree import KDTree
|
||||
|
||||
from ..utils import poll_deformed_mesh_with_vgroups
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_symmetrize_groups(Operator):
|
||||
"""Symmetrize weights of vertex groups on a near-symmetrical mesh.\May have poor results on assymetrical meshes"""
|
||||
|
||||
bl_idname = "object.symmetrize_vertex_weights"
|
||||
bl_label = "Symmetrize Vertex Weights"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
groups: EnumProperty(
|
||||
name="Groups",
|
||||
description="Subset of vertex groups that should be symmetrized",
|
||||
items=[
|
||||
('ACTIVE', 'Active', 'Active'),
|
||||
('SELECTED', 'Selected Bones', 'Selected Bones'),
|
||||
('ALL', 'All', 'All'),
|
||||
],
|
||||
)
|
||||
|
||||
direction: EnumProperty(
|
||||
name="Direction",
|
||||
description="Whether to symmetrize from left to right or from right to left",
|
||||
items=[
|
||||
('AUTOMATIC', "Automatic", "Determine symmetrizing direction by the names of source vertex groups"),
|
||||
('LEFT_TO_RIGHT', "Left to Right", "Left to Right"),
|
||||
('RIGHT_TO_LEFT', "Right to Left", "Right to Left"),
|
||||
],
|
||||
options={'SKIP_SAVE'},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_deformed_mesh_with_vgroups(cls, context, must_deform=False)
|
||||
|
||||
def invoke(self, context, _event):
|
||||
return context.window_manager.invoke_props_dialog(self, width=400)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
layout.prop(self, 'groups')
|
||||
layout.prop(self, 'direction')
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
|
||||
vgroups = [obj.vertex_groups.active]
|
||||
if self.groups == 'SELECTED':
|
||||
vgroups = []
|
||||
# Get vertex groups of selected bones.
|
||||
for pbone in context.selected_pose_bones:
|
||||
vgroup = obj.vertex_groups.get(pbone.name)
|
||||
if not vgroup:
|
||||
continue
|
||||
flipped_vg = flip_name(pbone.name)
|
||||
if flipped_vg in vgroups:
|
||||
self.report(
|
||||
{'ERROR'},
|
||||
f'Both sides selected: "{vgroup.name}" & "{flipped_vg.name}". Only one side should be selected.',
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
vgroups.append(vgroup)
|
||||
|
||||
elif self.groups == 'ALL':
|
||||
vgroups = obj.vertex_groups[:]
|
||||
|
||||
symmetry_mapping = get_symmetry_mapping(obj=obj)
|
||||
|
||||
if self.direction == 'AUTOMATIC':
|
||||
self.direction = 'LEFT_TO_RIGHT'
|
||||
righties = 0
|
||||
lefties = 0
|
||||
for vgroup in vgroups:
|
||||
name = vgroup.name.lower()
|
||||
if (
|
||||
".r" in name
|
||||
or "_r" in name
|
||||
or "r_" in name
|
||||
or "right" in name
|
||||
):
|
||||
righties += 1
|
||||
if (
|
||||
".l" in name
|
||||
or "_l" in name
|
||||
or "l_" in name
|
||||
or "left" in name
|
||||
):
|
||||
lefties += 1
|
||||
if righties > lefties:
|
||||
self.direction = 'RIGHT_TO_LEFT'
|
||||
|
||||
for vgroup in vgroups:
|
||||
symmetrize_vertex_group(
|
||||
obj=obj,
|
||||
vg_name=vgroup.name,
|
||||
symmetry_mapping=symmetry_mapping,
|
||||
right_to_left=self.direction == 'RIGHT_TO_LEFT',
|
||||
)
|
||||
|
||||
msg_direction = self.direction.replace("_", " ").lower()
|
||||
self.report({'INFO'}, f"Symmetrized {len(vgroups)} groups {msg_direction}.")
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def get_symmetry_mapping(*, obj: Object, axis='X', symmetrize_pos_to_neg=False) -> dict[int, int]:
|
||||
"""
|
||||
Create a mapping of vertex indicies, such that the index on one side maps
|
||||
to the index on the opposite side of the mesh on a given axis.
|
||||
"""
|
||||
assert axis in 'XYZ', "Axis must be X, Y or Z!"
|
||||
vertices = obj.data.vertices
|
||||
|
||||
size = len(vertices)
|
||||
kd = KDTree(size)
|
||||
for i, v in enumerate(vertices):
|
||||
kd.insert(v.co, i)
|
||||
kd.balance()
|
||||
|
||||
coord_i = 'XYZ'.find(axis)
|
||||
|
||||
# Figure out the function that will be used to determine whether a vertex
|
||||
# should be skipped or not.
|
||||
def zero_or_more(x):
|
||||
return x >= 0
|
||||
|
||||
def zero_or_less(x):
|
||||
return x <= 0
|
||||
|
||||
skip_func = zero_or_more if symmetrize_pos_to_neg else zero_or_less
|
||||
|
||||
# For any vertex with an X coordinate > 0, try to find a vertex at
|
||||
# the coordinate with X flipped.
|
||||
vert_map = {}
|
||||
bad_counter = 0
|
||||
for vert_idx, vert in enumerate(vertices):
|
||||
if abs(vert.co[coord_i]) < 0.0001:
|
||||
vert_map[vert_idx] = vert_idx
|
||||
continue
|
||||
# if skip_func(vert.co[coord_i]):
|
||||
# continue
|
||||
flipped_co = vert.co.copy()
|
||||
flipped_co[coord_i] *= -1
|
||||
_opposite_co, opposite_idx, dist = kd.find(flipped_co)
|
||||
if dist > 0.1: # pretty big threshold, for testing.
|
||||
bad_counter += 1
|
||||
continue
|
||||
if opposite_idx in vert_map.values():
|
||||
# This vertex was already mapped, and another vertex just matched with it.
|
||||
# No way to tell which is correct. Input mesh should just be more symmetrical.
|
||||
bad_counter += 1
|
||||
continue
|
||||
vert_map[vert_idx] = opposite_idx
|
||||
return vert_map
|
||||
|
||||
|
||||
def symmetrize_vertex_group(
|
||||
*, obj: Object, vg_name: str, symmetry_mapping: dict[int, int], right_to_left=False
|
||||
):
|
||||
"""
|
||||
Symmetrize weights of a single group. The symmetry_mapping should first be
|
||||
calculated with get_symmetry_mapping().
|
||||
"""
|
||||
|
||||
vgroup = obj.vertex_groups.get(vg_name)
|
||||
if not vgroup:
|
||||
return
|
||||
opp_name = flip_name(vg_name)
|
||||
opp_vgroup = obj.vertex_groups.get(opp_name)
|
||||
if not opp_vgroup:
|
||||
opp_vgroup = obj.vertex_groups.new(name=opp_name)
|
||||
|
||||
skip_func = None
|
||||
if vgroup != opp_vgroup:
|
||||
# Clear weights of the opposite group from all vertices.
|
||||
opp_vgroup.remove(range(len(obj.data.vertices)))
|
||||
else:
|
||||
# If the name isn't flippable, only remove weights of vertices
|
||||
# whose X coord >= 0.
|
||||
|
||||
# Figure out the function that will be used to determine whether a vertex
|
||||
# should be skipped or not.
|
||||
def zero_or_more(x):
|
||||
return x >= 0
|
||||
|
||||
def zero_or_less(x):
|
||||
return x <= 0
|
||||
|
||||
skip_func = zero_or_more if right_to_left else zero_or_less
|
||||
|
||||
# Write the new, mirrored weights
|
||||
for src_idx, dst_idx in symmetry_mapping.items():
|
||||
vert = obj.data.vertices[src_idx]
|
||||
if skip_func != None and skip_func(vert.co.x):
|
||||
continue
|
||||
try:
|
||||
src_weight = vgroup.weight(src_idx)
|
||||
if src_weight == 0:
|
||||
continue
|
||||
except RuntimeError:
|
||||
continue
|
||||
opp_vgroup.add([dst_idx], src_weight, 'REPLACE')
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_OT_symmetrize_groups]
|
||||
@@ -0,0 +1,284 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.props import BoolProperty
|
||||
from bpy.app.handlers import persistent
|
||||
|
||||
from .weight_cleaner import start_cleaner, stop_cleaner
|
||||
from .utils import get_addon_prefs
|
||||
from .prefs_to_disk import PrefsFileSaveLoadMixin, update_prefs_on_file
|
||||
from pathlib import Path
|
||||
|
||||
def ensure_brush_assets():
|
||||
# Since the Brush Assets in Blender 4.3, brushes are not local to the .blend file
|
||||
# until they are first accessed, so let's do that when needed. We also can't check
|
||||
# whether these brushes exist without looping over all of them.
|
||||
for brush_name in 'Blur', 'Paint':
|
||||
for brush in bpy.data.brushes:
|
||||
if not brush.use_paint_weight:
|
||||
continue
|
||||
else:
|
||||
# Link the brush from the `datafiles` folder.
|
||||
blend_path = (Path(bpy.utils.resource_path('LOCAL')) / "datafiles/assets/brushes/essentials_brushes-mesh_weight.blend").as_posix()
|
||||
with bpy.data.libraries.load(blend_path, link=True) as (data_from, data_to):
|
||||
data_to.brushes = [brush_name]
|
||||
if brush_name == 'Paint':
|
||||
brush = bpy.data.brushes.get(('Paint', blend_path))
|
||||
brush.blend = 'ADD'
|
||||
|
||||
def get_available_wp_brushes():
|
||||
for brush in bpy.data.brushes:
|
||||
if brush.use_paint_weight:
|
||||
yield brush
|
||||
|
||||
|
||||
class EASYWEIGHT_addon_preferences(PrefsFileSaveLoadMixin, bpy.types.AddonPreferences):
|
||||
bl_idname = __package__
|
||||
|
||||
always_show_zero_weights: BoolProperty(
|
||||
name="Always Show Zero Weights",
|
||||
description="A lack of weights will always be indicated with black color to differentiate it from a weight of 0.0 being assigned",
|
||||
default=True,
|
||||
update=update_prefs_on_file,
|
||||
)
|
||||
always_auto_normalize: BoolProperty(
|
||||
name="Always Auto Normalize",
|
||||
description="Weight auto-normalization will always be turned on, so the sum of all deforming weights on a vertex always add up to 1",
|
||||
default=True,
|
||||
update=update_prefs_on_file,
|
||||
)
|
||||
always_multipaint: BoolProperty(
|
||||
name="Always Multi-Paint",
|
||||
description="Multi-paint will always be turned on, allowing you to select more than one deforming bone while weight painting",
|
||||
default=True,
|
||||
update=update_prefs_on_file,
|
||||
)
|
||||
always_xray: BoolProperty(
|
||||
name="Always X-Ray",
|
||||
description="Always enable bone x-ray when entering weight paint mode",
|
||||
default=True,
|
||||
update=update_prefs_on_file,
|
||||
)
|
||||
|
||||
def update_auto_clean(self, context):
|
||||
update_prefs_on_file()
|
||||
if self.auto_clean_weights:
|
||||
start_cleaner()
|
||||
else:
|
||||
stop_cleaner()
|
||||
|
||||
auto_clean_weights: BoolProperty(
|
||||
name="Always Auto Clean",
|
||||
description="While this is enabled, zero-weights will be removed automatically after every brush stroke",
|
||||
default=True,
|
||||
)
|
||||
|
||||
def update_front_faces(self, context):
|
||||
update_prefs_on_file()
|
||||
for brush in get_available_wp_brushes():
|
||||
brush.use_frontface = self.global_front_faces_only
|
||||
|
||||
def update_accumulate(self, context):
|
||||
update_prefs_on_file()
|
||||
for brush in get_available_wp_brushes():
|
||||
brush.use_accumulate = self.global_accumulate
|
||||
|
||||
def update_falloff_shape(self, context):
|
||||
update_prefs_on_file()
|
||||
for brush in get_available_wp_brushes():
|
||||
brush.falloff_shape = 'SPHERE' if self.global_falloff_shape_sphere else 'PROJECTED'
|
||||
for i, val in enumerate(brush.cursor_color_add):
|
||||
if val > 0:
|
||||
brush.cursor_color_add[i] = 0.5 if self.global_falloff_shape_sphere else 2.0
|
||||
|
||||
global_front_faces_only: BoolProperty(
|
||||
name="Front Faces Only",
|
||||
description="All weight brushes are able to paint on geometry that is facing away from the viewport",
|
||||
update=update_front_faces,
|
||||
)
|
||||
global_accumulate: BoolProperty(
|
||||
name="Accumulate",
|
||||
description="All weight paint brushes will accumulate their effect within a single stroke as you move the mouse",
|
||||
update=update_accumulate,
|
||||
)
|
||||
global_falloff_shape_sphere: BoolProperty(
|
||||
name="Falloff Shape",
|
||||
description="All weight paint brushes switch between a 3D spherical or a 2D projected circular falloff shape",
|
||||
update=update_falloff_shape,
|
||||
)
|
||||
|
||||
show_hotkeys: BoolProperty(
|
||||
name="Show Hotkeys",
|
||||
description="Reveal the hotkey list. You may customize or disable these hotkeys",
|
||||
default=False,
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.use_property_split = True
|
||||
layout.use_property_decorate = False
|
||||
|
||||
col = layout.column()
|
||||
col.prop(self, 'auto_clean_weights')
|
||||
col.prop(self, 'always_show_zero_weights')
|
||||
col.prop(self, 'always_auto_normalize')
|
||||
col.prop(self, 'always_multipaint')
|
||||
col.prop(self, 'always_xray')
|
||||
|
||||
main_col = layout.column(align=True)
|
||||
hotkey_col = self.draw_fake_dropdown(main_col, self, 'show_hotkeys', "Hotkeys")
|
||||
if self.show_hotkeys:
|
||||
type(self).draw_hotkey_list(hotkey_col, context)
|
||||
|
||||
# NOTE: This function is copied from CloudRig's prefs.py. TODO: No longer needed since like 4.2 or so, could just use layout.panel(), but then bump the minimum blender version.
|
||||
def draw_fake_dropdown(self, layout, prop_owner, prop_name, dropdown_text):
|
||||
row = layout.row()
|
||||
split = row.split(factor=0.20)
|
||||
split.use_property_split = False
|
||||
prop_value = prop_owner.path_resolve(prop_name)
|
||||
icon = 'TRIA_DOWN' if prop_value else 'TRIA_RIGHT'
|
||||
split.prop(prop_owner, prop_name, icon=icon, emboss=False, text=dropdown_text)
|
||||
split.prop(prop_owner, prop_name, icon='BLANK1', emboss=False, text="")
|
||||
split = layout.split(factor=0.012)
|
||||
split.row()
|
||||
dropdown_row = split.row()
|
||||
dropdown_col = dropdown_row.column()
|
||||
row = dropdown_col.row()
|
||||
row.use_property_split = False
|
||||
|
||||
return dropdown_col
|
||||
|
||||
@classmethod
|
||||
def draw_hotkey_list(cls, layout, context):
|
||||
hotkey_class = cls
|
||||
user_kc = context.window_manager.keyconfigs.user
|
||||
|
||||
global EASYWEIGHT_KEYMAPS
|
||||
|
||||
prev_kmi = None
|
||||
for addon_km, addon_kmi in EASYWEIGHT_KEYMAPS:
|
||||
user_km = user_kc.keymaps.get(addon_km.name)
|
||||
if not user_km:
|
||||
# This really shouldn't happen.
|
||||
continue
|
||||
for user_kmi in user_km.keymap_items:
|
||||
if user_kmi.idname != addon_kmi.idname:
|
||||
continue
|
||||
if user_kmi.idname == 'wm.call_menu_pie' and user_kmi.properties.name != addon_kmi.properties.name:
|
||||
continue
|
||||
col = layout.column()
|
||||
col.context_pointer_set("keymap", user_km)
|
||||
if user_kmi and prev_kmi and prev_kmi.name != user_kmi.name:
|
||||
col.separator()
|
||||
user_row = col.row()
|
||||
|
||||
hotkey_class.draw_kmi(user_km, user_kmi, user_row)
|
||||
break
|
||||
|
||||
# NOTE: This function is copied from CloudRig's cloudrig.py.
|
||||
@staticmethod
|
||||
def draw_kmi(km, kmi, layout):
|
||||
"""A simplified version of draw_kmi from rna_keymap_ui.py."""
|
||||
col = layout.column()
|
||||
|
||||
split = col.split(factor=0.7)
|
||||
|
||||
# header bar
|
||||
row = split.row(align=True)
|
||||
row.prop(kmi, "active", text="", emboss=False)
|
||||
row.label(text=f'{kmi.name} ({km.name})')
|
||||
|
||||
row = split.row(align=True)
|
||||
sub = row.row(align=True)
|
||||
sub.enabled = kmi.active
|
||||
sub.prop(kmi, "type", text="", full_event=True)
|
||||
|
||||
if kmi.is_user_modified:
|
||||
row.operator("preferences.keyitem_restore", text="", icon='BACK').item_id = kmi.id
|
||||
|
||||
# NOTE: This function is copied from CloudRig's cloudrig.py.
|
||||
@staticmethod
|
||||
def find_kmi_in_km_by_hash(keymap, kmi_hash):
|
||||
"""There's no solid way to match modified user keymap items to their
|
||||
add-on equivalent, which is necessary to draw them in the UI reliably.
|
||||
|
||||
To remedy this, we store a hash in the KeyMapItem's properties.
|
||||
|
||||
This function lets us find a KeyMapItem with a stored hash in a KeyMap.
|
||||
Eg., we can pass a User KeyMap and an Addon KeyMapItem's hash, to find the
|
||||
corresponding user keymap, even if it was modified.
|
||||
|
||||
The hash value is unfortunately exposed to the users, so we just hope they don't touch that.
|
||||
"""
|
||||
|
||||
for kmi in keymap.keymap_items:
|
||||
if not kmi.properties:
|
||||
continue
|
||||
if 'hash' not in kmi.properties:
|
||||
continue
|
||||
|
||||
if kmi.properties['hash'] == kmi_hash:
|
||||
return kmi
|
||||
|
||||
EASYWEIGHT_KEYMAPS = []
|
||||
|
||||
@persistent
|
||||
def set_brush_prefs_on_file_load(scene):
|
||||
if bpy.app.version >= (4, 3, 0):
|
||||
ensure_brush_assets()
|
||||
prefs = get_addon_prefs()
|
||||
prefs.global_front_faces_only = prefs.global_front_faces_only
|
||||
prefs.global_accumulate = prefs.global_accumulate
|
||||
prefs.global_falloff_shape_sphere = prefs.global_falloff_shape_sphere
|
||||
|
||||
|
||||
def register_hotkey(
|
||||
bl_idname, hotkey_kwargs, *, key_cat='Window', space_type='EMPTY', op_kwargs={}
|
||||
):
|
||||
"""This function inserts a 'hash' into the created KeyMapItems' properties,
|
||||
so they can be compared to each other, and duplicates can be avoided."""
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
addon_keyconfig = wm.keyconfigs.addon
|
||||
if not addon_keyconfig:
|
||||
# This happens when running Blender in background mode.
|
||||
return
|
||||
|
||||
addon_keymaps = addon_keyconfig.keymaps
|
||||
addon_km = addon_keymaps.get(key_cat)
|
||||
if not addon_km:
|
||||
addon_km = addon_keymaps.new(name=key_cat, space_type=space_type)
|
||||
|
||||
addon_kmi = addon_km.keymap_items.new(bl_idname, **hotkey_kwargs)
|
||||
for key in op_kwargs:
|
||||
value = op_kwargs[key]
|
||||
setattr(addon_kmi.properties, key, value)
|
||||
|
||||
global EASYWEIGHT_KEYMAPS
|
||||
EASYWEIGHT_KEYMAPS.append((addon_km, addon_kmi))
|
||||
|
||||
|
||||
registry = [EASYWEIGHT_addon_preferences]
|
||||
|
||||
|
||||
def register():
|
||||
register_hotkey(
|
||||
'wm.call_menu_pie',
|
||||
hotkey_kwargs={'type': "W", 'value': "PRESS"},
|
||||
key_cat='Weight Paint',
|
||||
op_kwargs={'name': 'EASYWEIGHT_MT_PIE_easy_weight'},
|
||||
)
|
||||
bpy.app.handlers.load_post.append(set_brush_prefs_on_file_load)
|
||||
EASYWEIGHT_addon_preferences.register_autoload_from_file()
|
||||
|
||||
|
||||
def unregister_hotkeys():
|
||||
for km, kmi in EASYWEIGHT_KEYMAPS:
|
||||
km.keymap_items.remove(kmi)
|
||||
|
||||
|
||||
def unregister():
|
||||
unregister_hotkeys()
|
||||
bpy.app.handlers.load_post.remove(set_brush_prefs_on_file_load)
|
||||
@@ -0,0 +1,164 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import bpy
|
||||
|
||||
from . import __package__ as base_package
|
||||
|
||||
def get_addon_prefs(context=None):
|
||||
if not context:
|
||||
context = bpy.context
|
||||
|
||||
addons = context.preferences.addons
|
||||
if base_package.startswith('bl_ext'):
|
||||
# 4.2 and later
|
||||
name = base_package
|
||||
else:
|
||||
# Pre-4.2
|
||||
name = base_package.split(".")[0]
|
||||
|
||||
if name in addons:
|
||||
prefs = addons[name].preferences
|
||||
if prefs == None:
|
||||
pass
|
||||
# print("This happens when packaging the extension, due to the registration delay.")
|
||||
return addons[name].preferences
|
||||
|
||||
|
||||
def update_prefs_on_file(self=None, context=None) -> tuple[str, dict]:
|
||||
prefs = get_addon_prefs(context)
|
||||
if not type(prefs).loading:
|
||||
prefs.save_prefs_to_file()
|
||||
|
||||
|
||||
class PrefsFileSaveLoadMixin:
|
||||
"""Mix-in class that can be used by any add-on to store their preferences in a file,
|
||||
so that they don't get lost when the add-on is disabled.
|
||||
To use it, copy this class and the function above it, and do this in your code:
|
||||
|
||||
```
|
||||
import bpy, json
|
||||
from pathlib import Path
|
||||
|
||||
class MyAddonPrefs(PrefsFileSaveLoadMixin, bpy.types.AddonPreferences):
|
||||
some_prop: bpy.props.IntProperty(update=update_prefs_on_file)
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(MyAddonPrefs)
|
||||
MyAddonPrefs.register_autoload_from_file()
|
||||
|
||||
def unregister():
|
||||
update_prefs_on_file()
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
# List of property names to not write to disk.
|
||||
omit_from_disk: list[str] = []
|
||||
|
||||
loading = False
|
||||
|
||||
@staticmethod
|
||||
def register_autoload_from_file(delay=0.5):
|
||||
def timer_func(_scene=None):
|
||||
prefs = get_addon_prefs()
|
||||
if not prefs:
|
||||
return 1
|
||||
prefs.load_prefs_from_file()
|
||||
bpy.app.timers.register(timer_func, first_interval=delay)
|
||||
|
||||
def prefs_to_dict_recursive(self, propgroup: 'IDPropertyGroup') -> dict:
|
||||
"""Recursively convert AddonPreferences to a dictionary.
|
||||
Note that AddonPreferences don't support PointerProperties,
|
||||
so this function doesn't either."""
|
||||
from rna_prop_ui import IDPropertyGroup
|
||||
|
||||
ret = {}
|
||||
|
||||
rna_class = None
|
||||
if isinstance(propgroup, bpy.types.AddonPreferences):
|
||||
prop_dict = {key:getattr(propgroup, key) for key in propgroup.bl_rna.properties.keys() if key not in ('rna_type', 'bl_idname')}
|
||||
else:
|
||||
property_group_class_name = type(propgroup).__name__
|
||||
rna_class = bpy.types.PropertyGroup.bl_rna_get_subclass_py(
|
||||
property_group_class_name
|
||||
)
|
||||
if not hasattr(rna_class, 'properties'):
|
||||
rna_class = None
|
||||
prop_dict = {key:getattr(propgroup, key) for key in propgroup.bl_rna.properties.keys() if key not in ('rna_type')}
|
||||
|
||||
for key, value in prop_dict.items():
|
||||
if key in type(self).omit_from_disk:
|
||||
continue
|
||||
if type(value) in (list, bpy.types.bpy_prop_collection_idprop):
|
||||
ret[key] = [self.prefs_to_dict_recursive(elem) for elem in value]
|
||||
elif type(value) == IDPropertyGroup:
|
||||
ret[key] = self.prefs_to_dict_recursive(value)
|
||||
else:
|
||||
if (
|
||||
rna_class
|
||||
and key in rna_class.properties
|
||||
and hasattr(rna_class.properties[key], 'enum_items')
|
||||
):
|
||||
# Save enum values as string, not int.
|
||||
ret[key] = rna_class.properties[key].enum_items[value].identifier
|
||||
else:
|
||||
ret[key] = value
|
||||
return ret
|
||||
|
||||
def apply_prefs_from_dict_recursive(self, propgroup, data):
|
||||
for key, value in data.items():
|
||||
if not hasattr(propgroup, key):
|
||||
# Property got removed or renamed in the implementation.
|
||||
continue
|
||||
if type(value) == list:
|
||||
for elem in value:
|
||||
collprop = getattr(propgroup, key)
|
||||
entry = collprop.get(elem['name'])
|
||||
if not entry:
|
||||
entry = collprop.add()
|
||||
self.apply_prefs_from_dict_recursive(entry, elem)
|
||||
elif type(value) == dict:
|
||||
self.apply_prefs_from_dict_recursive(getattr(propgroup, key), value)
|
||||
else:
|
||||
setattr(propgroup, key, value)
|
||||
|
||||
@staticmethod
|
||||
def get_prefs_filepath() -> Path:
|
||||
addon_name = __package__.split(".")[-1]
|
||||
return Path(bpy.utils.user_resource('CONFIG')) / Path(addon_name + ".json")
|
||||
|
||||
def save_prefs_to_file(self, _context=None):
|
||||
data_dict = self.prefs_to_dict_recursive(propgroup=self)
|
||||
|
||||
filepath = self.get_prefs_filepath()
|
||||
|
||||
with open(filepath, "w") as f:
|
||||
json.dump(data_dict, f, indent=4)
|
||||
|
||||
return filepath, json.dumps(data_dict, indent=4)
|
||||
|
||||
def load_prefs_from_file(self) -> bool:
|
||||
filepath = self.get_prefs_filepath()
|
||||
if not filepath.exists():
|
||||
return False
|
||||
|
||||
success = True
|
||||
with open(filepath, "r") as f:
|
||||
addon_data = json.load(f)
|
||||
type(self).loading = True
|
||||
try:
|
||||
self.apply_prefs_from_dict_recursive(self, addon_data)
|
||||
except Exception as exc:
|
||||
# If we get an error raised here, and it isn't handled,
|
||||
# the add-on seems to break.
|
||||
print(
|
||||
f"{base_package}: Failed to load {__package__} preferences from file."
|
||||
)
|
||||
raise exc
|
||||
type(self).loading = False
|
||||
return success
|
||||
@@ -0,0 +1,550 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from collections import defaultdict
|
||||
import bpy
|
||||
import sys
|
||||
import itertools
|
||||
|
||||
from bpy.props import IntProperty, CollectionProperty, StringProperty, BoolProperty
|
||||
from bpy.types import PropertyGroup, Panel, UIList, Operator, Mesh, VertexGroup, MeshVertex, Object
|
||||
from bpy.utils import flip_name
|
||||
|
||||
from .utils import get_deforming_vgroups, poll_deformed_mesh_with_vgroups
|
||||
|
||||
"""
|
||||
This module implements the Sidebar -> EasyWeight -> Weight Islands panel, which provides
|
||||
a workflow for hunting down and cleaning up rogue weights efficiently.
|
||||
"""
|
||||
|
||||
|
||||
class VertIndex(PropertyGroup):
|
||||
index: IntProperty()
|
||||
|
||||
|
||||
class WeightIsland(PropertyGroup):
|
||||
vert_indicies: CollectionProperty(type=VertIndex)
|
||||
|
||||
|
||||
class IslandGroup(PropertyGroup):
|
||||
name: StringProperty(
|
||||
name="Name", description="Name of the vertex group this set of islands is associated with"
|
||||
)
|
||||
islands: CollectionProperty(type=WeightIsland)
|
||||
num_expected_islands: IntProperty(
|
||||
name="Expected Islands",
|
||||
default=1,
|
||||
min=1,
|
||||
description="Number of weight islands that have been marked as the expected amount by the user. If the real amount differs from this value, a warning appears",
|
||||
)
|
||||
index: IntProperty()
|
||||
|
||||
|
||||
def update_vgroup_islands(
|
||||
mesh, vgroup, vert_index_map, island_groups, island_group=None
|
||||
) -> IslandGroup:
|
||||
islands = get_islands_of_vgroup(mesh, vgroup, vert_index_map)
|
||||
|
||||
if not island_group:
|
||||
island_group = island_groups.add()
|
||||
island_group.index = len(island_groups) - 1
|
||||
island_group.name = vgroup.name
|
||||
else:
|
||||
island_group.islands.clear()
|
||||
for island in islands:
|
||||
island_storage = island_group.islands.add()
|
||||
for vert_idx in island:
|
||||
vert_idx_storage = island_storage.vert_indicies.add()
|
||||
vert_idx_storage.index = vert_idx
|
||||
|
||||
return island_group
|
||||
|
||||
|
||||
def build_vert_connection_map_new(mesh) -> dict:
|
||||
"""Build a dictionary of vertex indicies pointing to a list of other vertex indicies
|
||||
that the vertex is connected to by an edge.
|
||||
"""
|
||||
|
||||
vert_dict = defaultdict(list)
|
||||
|
||||
for edge in mesh.edges:
|
||||
vert_dict[edge.vertices[0]] += [edge.vertices[1]]
|
||||
vert_dict[edge.vertices[1]] += [edge.vertices[0]]
|
||||
|
||||
return vert_dict
|
||||
|
||||
|
||||
def find_weight_island_vertices(
|
||||
mesh: Mesh, vert_idx: int, group_index: int, vert_idx_map: dict, island=[]
|
||||
) -> list[int]:
|
||||
"""Recursively find all vertices that are connected to a vertex by edges,
|
||||
and are also in the same vertex group.
|
||||
|
||||
Recursion depth may exceed system default on high poly meshes.
|
||||
"""
|
||||
|
||||
island.append(vert_idx)
|
||||
# For each edge connected to the vert.
|
||||
for connected_vert_idx in vert_idx_map[vert_idx]:
|
||||
if connected_vert_idx in island:
|
||||
# Avoid infinite recursion!
|
||||
continue
|
||||
# For each group this other vertex belongs to.
|
||||
for group_data in mesh.vertices[connected_vert_idx].groups:
|
||||
if group_data.group == group_index and group_data.weight:
|
||||
# If this vert is in the group, continue recursion.
|
||||
find_weight_island_vertices(
|
||||
mesh, connected_vert_idx, group_index, vert_idx_map, island
|
||||
)
|
||||
return island
|
||||
|
||||
|
||||
def find_any_vertex_in_group(mesh: Mesh, vgroup: VertexGroup, excluded_indicies=[]) -> MeshVertex:
|
||||
"""Return the index of the first vertex we find which is part of the
|
||||
vertex group and optinally, has a specified selection state."""
|
||||
|
||||
# TODO: This is probably our performance bottleneck atm.
|
||||
# We should build an acceleration structure for this similar to build_vert_connection_map_new,
|
||||
# to map each vertex group to all of the verts within it, so we only need to iterate
|
||||
# like this once.
|
||||
|
||||
for vert in mesh.vertices:
|
||||
if vert.index in excluded_indicies:
|
||||
continue
|
||||
for group in vert.groups:
|
||||
if vgroup.index == group.group:
|
||||
return vert
|
||||
return None
|
||||
|
||||
|
||||
def get_islands_of_vgroup(mesh: Mesh, vgroup: VertexGroup, vert_index_map: dict) -> list[list[int]]:
|
||||
"""Return a list of lists of vertex indicies: Weight islands within this vertex group."""
|
||||
islands = []
|
||||
while True:
|
||||
verts_already_part_of_an_island = set(itertools.chain.from_iterable(islands))
|
||||
any_vert_in_group = find_any_vertex_in_group(
|
||||
mesh, vgroup, excluded_indicies=verts_already_part_of_an_island
|
||||
)
|
||||
if not any_vert_in_group:
|
||||
break
|
||||
# NOTE: We could avoid recursion here by doing the expansion in a `while True` block,
|
||||
# and break if the current list of verts is the same as at the end of the last loop.
|
||||
# But I'm fine with just changing the recursion limit.
|
||||
sys.setrecursionlimit(len(mesh.vertices))
|
||||
island = find_weight_island_vertices(
|
||||
mesh, any_vert_in_group.index, vgroup.index, vert_index_map, island=[]
|
||||
)
|
||||
sys.setrecursionlimit(990)
|
||||
islands.append(island)
|
||||
return islands
|
||||
|
||||
|
||||
def select_vertices(mesh: Mesh, vert_indicies: list[int]):
|
||||
assert (
|
||||
bpy.context.mode != 'EDIT_MESH'
|
||||
), "Object must not be in edit mode, otherwise vertex selection doesn't work!"
|
||||
|
||||
for i, vert in enumerate(mesh.vertices):
|
||||
vert.select = i in vert_indicies
|
||||
vert.hide = False
|
||||
|
||||
|
||||
def ensure_active_islands_is_visible(obj):
|
||||
"""Make sure the active entry is visible, keep incrementing index until that is the case."""
|
||||
new_active_index = obj.active_islands_index + 1
|
||||
looped = False
|
||||
while True:
|
||||
if new_active_index >= len(obj.island_groups):
|
||||
new_active_index = 0
|
||||
if looped:
|
||||
break
|
||||
looped = True
|
||||
island_group = obj.island_groups[new_active_index]
|
||||
if (
|
||||
len(island_group.islands) < 2
|
||||
or len(island_group.islands) == island_group.num_expected_islands
|
||||
):
|
||||
new_active_index += 1
|
||||
continue
|
||||
break
|
||||
obj.active_islands_index = new_active_index
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_mark_island_as_okay(Operator):
|
||||
"""Mark this number of vertex islands to be the intended amount. Vertex group will be hidden from the list until this number changes"""
|
||||
|
||||
bl_idname = "object.set_expected_island_count"
|
||||
bl_label = "Set Intended Island Count"
|
||||
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
|
||||
|
||||
vgroup: StringProperty(
|
||||
name="Vertex Group",
|
||||
default="",
|
||||
description="Name of the vertex group whose intended island count will be set",
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
mesh = obj.data
|
||||
org_mode = obj.mode
|
||||
|
||||
assert (
|
||||
self.vgroup in obj.island_groups
|
||||
), f"Island Group {self.vgroup} not found in object {obj.name}, aborting."
|
||||
|
||||
# Update existing island data first
|
||||
island_group = obj.island_groups[self.vgroup]
|
||||
vgroup = obj.vertex_groups[self.vgroup]
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
vert_index_map = build_vert_connection_map_new(mesh)
|
||||
bpy.ops.object.mode_set(mode=org_mode)
|
||||
org_num_islands = len(island_group.islands)
|
||||
island_group = update_vgroup_islands(
|
||||
mesh, vgroup, vert_index_map, obj.island_groups, island_group
|
||||
)
|
||||
new_num_islands = len(island_group.islands)
|
||||
if new_num_islands != org_num_islands:
|
||||
if new_num_islands == 1:
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Vertex group is now a single island, changing expected island count no longer necessary.",
|
||||
)
|
||||
return {'FINISHED'}
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Vertex group island count changed from {org_num_islands} to {new_num_islands}. Click again to mark this as the expected number.",
|
||||
)
|
||||
return {'FINISHED'}
|
||||
|
||||
island_group.num_expected_islands = new_num_islands
|
||||
ensure_active_islands_is_visible(obj)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_focus_smallest_island(Operator):
|
||||
"""Enter Weight Paint mode and focus on the smallest island"""
|
||||
|
||||
bl_idname = "object.focus_smallest_weight_island"
|
||||
bl_label = "Focus Smallest Island"
|
||||
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
|
||||
|
||||
enter_wp: BoolProperty(
|
||||
name="Enter Weight Paint",
|
||||
default=True,
|
||||
description="Enter Weight Paint Mode using the Toggle Weight Paint operator",
|
||||
)
|
||||
vgroup: StringProperty(
|
||||
name="Vertex Group",
|
||||
default="",
|
||||
description="Name of the vertex group whose smallest island should be focused",
|
||||
)
|
||||
focus_view: BoolProperty(
|
||||
name="Focus View",
|
||||
default=True,
|
||||
description="Whether to focus the 3D Viewport on the selected vertices",
|
||||
)
|
||||
|
||||
def execute(self, context):
|
||||
rig = context.pose_object
|
||||
obj = context.active_object
|
||||
mesh = obj.data
|
||||
org_mode = obj.mode
|
||||
|
||||
assert (
|
||||
self.vgroup in obj.vertex_groups
|
||||
), f"Vertex Group {self.vgroup} not found in object {obj.name}, aborting."
|
||||
|
||||
# Also update the opposite side vertex group.
|
||||
vgroup_names = [self.vgroup]
|
||||
flipped = flip_name(self.vgroup)
|
||||
if flipped != self.vgroup:
|
||||
vgroup_names.append(flipped)
|
||||
|
||||
vert_index_map = build_vert_connection_map_new(mesh)
|
||||
bpy.ops.object.mode_set(mode=org_mode)
|
||||
hid_islands = False
|
||||
for vg_name in vgroup_names:
|
||||
if vg_name in obj.island_groups:
|
||||
# Update existing island data first.
|
||||
island_group = obj.island_groups[vg_name]
|
||||
vgroup = obj.vertex_groups[vg_name]
|
||||
org_num_islands = len(island_group.islands)
|
||||
island_group = update_vgroup_islands(
|
||||
mesh, vgroup, vert_index_map, obj.island_groups, island_group
|
||||
)
|
||||
new_num_islands = len(island_group.islands)
|
||||
if new_num_islands < 2 and org_num_islands > 1:
|
||||
hid_islands = True
|
||||
self.report(
|
||||
{'INFO'},
|
||||
f"Vertex group {vg_name} no longer has multiple islands, hidden from list.",
|
||||
)
|
||||
if hid_islands:
|
||||
ensure_active_islands_is_visible(obj)
|
||||
return {'FINISHED'}
|
||||
# self.report({'INFO'}, f"Vertex group island count changed from {org_num_islands} to {new_num_islands}. Click again to focus smallest island.")
|
||||
# return {'FINISHED'}
|
||||
|
||||
island_groups = obj.island_groups
|
||||
island_group = island_groups[self.vgroup]
|
||||
vgroup = obj.vertex_groups[self.vgroup]
|
||||
obj.active_islands_index = island_group.index
|
||||
|
||||
smallest_island = min(island_group.islands, key=lambda island: len(island.vert_indicies))
|
||||
select_vertices(mesh, [vi.index for vi in smallest_island.vert_indicies])
|
||||
|
||||
# NOTE: Unfortunately these mode switches introduce some lag.
|
||||
# Especially because the weight paint switch triggers mode_switch_hook,
|
||||
# which causes more mode switches to put the Armature into pose mode.
|
||||
|
||||
if self.focus_view:
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
bpy.ops.view3d.view_selected()
|
||||
|
||||
if self.enter_wp:
|
||||
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
|
||||
else:
|
||||
bpy.ops.object.mode_set(mode=org_mode)
|
||||
|
||||
# Select the bone
|
||||
if context.mode == 'PAINT_WEIGHT':
|
||||
rig = context.pose_object
|
||||
if rig:
|
||||
for pb in rig.pose.bones:
|
||||
pb.bone.select = False
|
||||
if self.vgroup in rig.pose.bones:
|
||||
rig.pose.bones[self.vgroup].bone.select = True
|
||||
|
||||
mesh.use_paint_mask_vertex = True
|
||||
|
||||
self.report({'INFO'}, "Focused on the smallest island of weights.")
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_calculate_weight_islands(Operator):
|
||||
"""Calculate and store number of weight islands for each deforming vertex group. Groups with more than one island will be displayed below"""
|
||||
|
||||
bl_idname = "object.calculate_weight_islands"
|
||||
bl_label = "Calculate Weight Islands"
|
||||
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
|
||||
|
||||
@staticmethod
|
||||
def store_all_weight_islands(context, obj: Object, vert_index_map: dict):
|
||||
"""Store the weight island information of every deforming vertex group."""
|
||||
wm = context.window_manager
|
||||
|
||||
mesh = obj.data
|
||||
island_groups = obj.island_groups
|
||||
island_groups.clear()
|
||||
obj.active_islands_index = 0
|
||||
vgroups = get_deforming_vgroups(obj)
|
||||
wm.progress_begin(0, len(vgroups))
|
||||
for i, vgroup in enumerate(vgroups):
|
||||
if 'skip_groups' in obj and vgroup.name in obj['skip_groups']:
|
||||
continue
|
||||
obj.vertex_groups.active_index = vgroup.index
|
||||
|
||||
update_vgroup_islands(mesh, vgroup, vert_index_map, island_groups)
|
||||
wm.progress_update(i)
|
||||
wm.progress_end()
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return poll_deformed_mesh_with_vgroups(cls, context)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.active_object
|
||||
org_mode = obj.mode
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
vert_index_map = build_vert_connection_map_new(obj.data)
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
self.store_all_weight_islands(context, obj, vert_index_map)
|
||||
|
||||
bpy.ops.object.mode_set(mode=org_mode)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class EASYWEIGHT_OT_remove_island_data(Operator):
|
||||
"""Remove weight island data"""
|
||||
|
||||
bl_idname = "object.remove_island_data"
|
||||
bl_label = "Remove Island Data"
|
||||
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if not context.active_object:
|
||||
cls.poll_message_set("No active object.")
|
||||
return False
|
||||
if bpy.app.version < (5, 0, 0):
|
||||
if 'island_groups' not in context.active_object:
|
||||
cls.poll_message_set("No island data to remove.")
|
||||
return False
|
||||
else:
|
||||
return context.active_object.is_property_set('island_groups')
|
||||
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
if bpy.app.version < (5, 0, 0):
|
||||
del context.active_object['island_groups']
|
||||
del context.active_object['active_islands_index']
|
||||
else:
|
||||
context.active_object.property_unset('island_groups')
|
||||
context.active_object.property_unset('active_islands_index')
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class EASYWEIGHT_UL_weight_island_groups(UIList):
|
||||
@staticmethod
|
||||
def draw_header(layout):
|
||||
row = layout.row()
|
||||
split1 = row.split(factor=0.6)
|
||||
row1 = split1.row()
|
||||
row1.label(text="Vertex Group")
|
||||
row1.alignment = 'RIGHT'
|
||||
row1.label(text="|")
|
||||
row2 = split1.row()
|
||||
row2.label(text="Islands")
|
||||
|
||||
def filter_items(self, context, data, propname):
|
||||
flt_flags = []
|
||||
flt_neworder = []
|
||||
island_groups = getattr(data, propname)
|
||||
|
||||
helper_funcs = bpy.types.UI_UL_list
|
||||
|
||||
if self.filter_name:
|
||||
flt_flags = helper_funcs.filter_items_by_name(
|
||||
self.filter_name,
|
||||
self.bitflag_filter_item,
|
||||
island_groups,
|
||||
"name",
|
||||
reverse=self.use_filter_sort_reverse,
|
||||
)
|
||||
|
||||
if not flt_flags:
|
||||
flt_flags = [self.bitflag_filter_item] * len(island_groups)
|
||||
|
||||
if self.use_filter_invert:
|
||||
for idx, flag in enumerate(flt_flags):
|
||||
flt_flags[idx] = 0 if flag else self.bitflag_filter_item
|
||||
|
||||
for idx, island_group in enumerate(island_groups):
|
||||
if len(island_group.islands) < 1:
|
||||
# Filter island groups with only 1 or 0 islands in them
|
||||
flt_flags[idx] = 0
|
||||
elif len(island_group.islands) == island_group.num_expected_islands:
|
||||
# Filter island groups with the expected number of islands in them
|
||||
flt_flags[idx] = 0
|
||||
|
||||
return flt_flags, flt_neworder
|
||||
|
||||
def draw_filter(self, context, layout):
|
||||
# Nothing much to say here, it's usual UI code...
|
||||
main_row = layout.row()
|
||||
row = main_row.row(align=True)
|
||||
|
||||
row.prop(self, 'filter_name', text="")
|
||||
row.prop(self, 'use_filter_invert', toggle=True, text="", icon='ARROW_LEFTRIGHT')
|
||||
|
||||
row = main_row.row(align=True)
|
||||
row.use_property_split = True
|
||||
row.use_property_decorate = False
|
||||
row.prop(self, 'use_filter_sort_alpha', toggle=True, text="")
|
||||
row.prop(self, 'use_filter_sort_reverse', toggle=True, text="", icon='SORT_ASC')
|
||||
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
island_group = item
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
icon = 'ERROR'
|
||||
num_islands = len(island_group.islands)
|
||||
if num_islands == island_group.num_expected_islands:
|
||||
icon = 'CHECKMARK'
|
||||
row = layout.row()
|
||||
split = row.split(factor=0.6)
|
||||
row1 = split.row()
|
||||
row1.label(text=island_group.name)
|
||||
row1.alignment = 'RIGHT'
|
||||
row1.label(text="|")
|
||||
row2 = split.row(align=True)
|
||||
row2.label(text=str(num_islands), icon=icon)
|
||||
row2.operator(
|
||||
EASYWEIGHT_OT_focus_smallest_island.bl_idname, text="", icon='VIEWZOOM'
|
||||
).vgroup = island_group.name
|
||||
row2.operator(
|
||||
EASYWEIGHT_OT_mark_island_as_okay.bl_idname, text="", icon='CHECKMARK'
|
||||
).vgroup = island_group.name
|
||||
elif self.layout_type in {'GRID'}:
|
||||
pass
|
||||
|
||||
|
||||
class EASYWEIGHT_PT_WeightIslands(Panel):
|
||||
"""Panel with utilities for detecting rogue weights."""
|
||||
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_category = 'EasyWeight'
|
||||
bl_label = "Weight Islands"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object and context.active_object.type == 'MESH'
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
row = layout.row(align=True)
|
||||
row.operator(EASYWEIGHT_OT_calculate_weight_islands.bl_idname)
|
||||
row.operator(EASYWEIGHT_OT_remove_island_data.bl_idname, text="", icon='X')
|
||||
|
||||
obj = context.active_object
|
||||
island_groups = obj.island_groups
|
||||
if len(island_groups) == 0:
|
||||
return
|
||||
|
||||
EASYWEIGHT_UL_weight_island_groups.draw_header(layout)
|
||||
|
||||
row = layout.row()
|
||||
row.template_list(
|
||||
'EASYWEIGHT_UL_weight_island_groups',
|
||||
'',
|
||||
obj,
|
||||
'island_groups',
|
||||
obj,
|
||||
'active_islands_index',
|
||||
)
|
||||
|
||||
|
||||
registry = [
|
||||
VertIndex,
|
||||
WeightIsland,
|
||||
IslandGroup,
|
||||
EASYWEIGHT_OT_calculate_weight_islands,
|
||||
EASYWEIGHT_OT_remove_island_data,
|
||||
EASYWEIGHT_OT_focus_smallest_island,
|
||||
EASYWEIGHT_OT_mark_island_as_okay,
|
||||
EASYWEIGHT_PT_WeightIslands,
|
||||
EASYWEIGHT_UL_weight_island_groups,
|
||||
]
|
||||
|
||||
|
||||
def update_active_islands_index(obj, context):
|
||||
if len(obj.island_groups) == 0:
|
||||
return
|
||||
obj.vertex_groups.active_index = obj.vertex_groups.find(
|
||||
obj.island_groups[obj.active_islands_index].name
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
Object.island_groups = CollectionProperty(type=IslandGroup)
|
||||
Object.active_islands_index = IntProperty(update=update_active_islands_index)
|
||||
|
||||
|
||||
def unregister():
|
||||
del Object.island_groups
|
||||
del Object.active_islands_index
|
||||
@@ -0,0 +1,134 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.types import PoseBone, Object, VertexGroup, Bone, EditBone
|
||||
|
||||
from . import __package__ as base_package
|
||||
|
||||
|
||||
def get_addon_prefs(context=None):
|
||||
if not context:
|
||||
context = bpy.context
|
||||
if base_package.startswith('bl_ext'):
|
||||
# 4.2
|
||||
return context.preferences.addons[base_package].preferences
|
||||
else:
|
||||
return context.preferences.addons[base_package.split(".")[0]].preferences
|
||||
|
||||
|
||||
def poll_deformed_mesh_with_vgroups(operator, context, must_deform=True) -> bool:
|
||||
obj = context.active_object
|
||||
if not obj or obj.type != 'MESH':
|
||||
operator.poll_message_set("No active mesh object.")
|
||||
return False
|
||||
if must_deform and ('ARMATURE' not in [m.type for m in obj.modifiers]):
|
||||
operator.poll_message_set("This mesh is not deformed by an Armature modifier.")
|
||||
return False
|
||||
if not obj.vertex_groups:
|
||||
operator.poll_message_set("This mesh has no vertex groups yet.")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def delete_vgroups(mesh_ob, vgroups: list[VertexGroup]):
|
||||
for vgroup in vgroups:
|
||||
mesh_ob.vertex_groups.remove(vgroup)
|
||||
|
||||
|
||||
def get_deforming_vgroups(mesh_ob: Object, arm_ob: Object = None) -> list[VertexGroup]:
|
||||
"""Get the vertex groups of a mesh object that correspond to a deform bone in the given armature."""
|
||||
|
||||
if not arm_ob:
|
||||
arm_ob = get_deforming_armature(mesh_ob)
|
||||
if not arm_ob:
|
||||
return []
|
||||
|
||||
deforming_vgroups = []
|
||||
|
||||
for bone in arm_ob.data.bones:
|
||||
if bone.name in mesh_ob.vertex_groups and bone.use_deform:
|
||||
deforming_vgroups.append(mesh_ob.vertex_groups[bone.name])
|
||||
|
||||
return deforming_vgroups
|
||||
|
||||
|
||||
def get_deforming_armature(mesh_ob: Object) -> Object | None:
|
||||
"""Return first Armature modifier's target object."""
|
||||
for mod in mesh_ob.modifiers:
|
||||
if mod.type == 'ARMATURE':
|
||||
return mod.object
|
||||
|
||||
|
||||
def poll_weight_paint_mode(operator, context, with_rig=False, with_groups=False):
|
||||
"""Function used for operator poll functions, ie. to determine whether
|
||||
operators should be available or not."""
|
||||
|
||||
obj = context.active_object
|
||||
if context.mode != 'PAINT_WEIGHT':
|
||||
operator.poll_message_set("Must be in Weight Paint mode.")
|
||||
return False
|
||||
if with_rig:
|
||||
if not 'ARMATURE' in (m.type for m in obj.modifiers):
|
||||
operator.poll_message_set("This mesh is not deformed by an Armature modifier.")
|
||||
return False
|
||||
if not context.pose_object or context.pose_object != get_deforming_armature(obj):
|
||||
operator.poll_message_set(
|
||||
"Couldn't find deforming armature, or it is not in pose mode."
|
||||
)
|
||||
return False
|
||||
|
||||
if with_groups and not obj.vertex_groups:
|
||||
operator.poll_message_set("This mesh object has no vertex groups yet.")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def reveal_bone(bone: Bone or EditBone or PoseBone, select=True):
|
||||
"""Reveall and optionally select a bone, regardless of current
|
||||
selection or visibility states.
|
||||
"""
|
||||
if type(bone) == PoseBone:
|
||||
bone = bone.bone
|
||||
armature = bone.id_data
|
||||
|
||||
if hasattr(armature, 'layers'):
|
||||
# Blender 3.6 and below: Bone Layers.
|
||||
enabled_layers = [i for i in range(32) if armature.layers[i]]
|
||||
|
||||
# If none of this bone's layers are enabled, enable the first one.
|
||||
bone_layers = [i for i in range(32) if bone.layers[i]]
|
||||
if not any([i in enabled_layers for i in bone_layers]):
|
||||
armature.layers[bone_layers[0]] = True
|
||||
else:
|
||||
# Blender 4.0 and above: Bone Collections.
|
||||
ensure_visible_bone_collection(bone)
|
||||
|
||||
bone.hide = False
|
||||
|
||||
if select:
|
||||
bone.select = True
|
||||
|
||||
|
||||
def ensure_visible_bone_collection(bone: Bone or EditBone or PoseBone):
|
||||
"""If target bone not in any enabled collections, enable first one."""
|
||||
# NOTE: This function was lifted from CloudRig.
|
||||
if type(bone) == PoseBone:
|
||||
bone = bone.bone
|
||||
|
||||
armature = bone.id_data
|
||||
collections = armature.collections
|
||||
|
||||
if len(bone.collections) == 0:
|
||||
return
|
||||
|
||||
if not any([coll.is_visible_effectively for coll in bone.collections]):
|
||||
coll = bone.collections[0]
|
||||
while coll:
|
||||
if collections.is_solo_active:
|
||||
coll.is_solo = True
|
||||
else:
|
||||
coll.is_visible = True
|
||||
coll = coll.parent
|
||||
@@ -0,0 +1,179 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.types import Menu, MESH_MT_vertex_group_context_menu
|
||||
VG_CONTEXT_MENU = MESH_MT_vertex_group_context_menu
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_batch_delete(Menu):
|
||||
bl_label = "Batch Delete"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator("object.vertex_group_remove", text="All Groups", icon='TRASH').all = True
|
||||
layout.operator(
|
||||
"object.vertex_group_remove", text="All Unlocked Groups", icon='UNLOCKED'
|
||||
).all_unlocked = True
|
||||
layout.separator()
|
||||
layout.operator(
|
||||
'object.delete_empty_deform_vgroups', text="Empty Deform Groups", icon='GROUP_BONE'
|
||||
)
|
||||
layout.operator(
|
||||
'object.delete_unused_vgroups', text="Unused Non-Deform Groups", icon='BRUSH_DATA'
|
||||
)
|
||||
layout.operator(
|
||||
'object.delete_unselected_deform_vgroups',
|
||||
text="Unselected Deform Groups",
|
||||
icon='RESTRICT_SELECT_ON',
|
||||
)
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_symmetry(Menu):
|
||||
bl_label = "Symmetry"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator(
|
||||
"object.vertex_group_mirror",
|
||||
text="Mirror Active Group (Proximity)",
|
||||
icon='AUTOMERGE_OFF',
|
||||
).use_topology = False
|
||||
layout.operator(
|
||||
"object.vertex_group_mirror", text="Mirror Active Group (Topology)", icon='AUTOMERGE_ON'
|
||||
).use_topology = True
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("object.symmetrize_vertex_weights", text="Symmetrize Groups", icon='MOD_MIRROR')
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_sort(Menu):
|
||||
bl_label = "Sort"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator(
|
||||
"object.vertex_group_sort",
|
||||
icon='SORTALPHA',
|
||||
text="By Name",
|
||||
).sort_type = 'NAME'
|
||||
layout.operator(
|
||||
"object.vertex_group_sort",
|
||||
icon='BONE_DATA',
|
||||
text="By Bone Hierarchy",
|
||||
).sort_type = 'BONE_HIERARCHY'
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_copy(Menu):
|
||||
bl_label = "Copy"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
obj = context.active_object
|
||||
if obj and obj.vertex_groups and obj.vertex_groups.active:
|
||||
layout.operator(
|
||||
"object.vertex_group_copy",
|
||||
icon='DUPLICATE',
|
||||
text=f'Duplicate "{obj.vertex_groups.active.name}"',
|
||||
)
|
||||
layout.separator()
|
||||
layout.operator(
|
||||
"object.vertex_group_copy_to_selected",
|
||||
text="Synchronize Groups on Selected",
|
||||
icon='RESTRICT_SELECT_OFF',
|
||||
)
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_lock(Menu):
|
||||
bl_label = "Batch Lock"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
props = layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All")
|
||||
props.action, props.mask = 'LOCK', 'ALL'
|
||||
props = layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="Unlock All")
|
||||
props.action, props.mask = 'UNLOCK', 'ALL'
|
||||
props = layout.operator(
|
||||
"object.vertex_group_lock", icon='UV_SYNC_SELECT', text="Invert All Locks"
|
||||
)
|
||||
props.action, props.mask = 'INVERT', 'ALL'
|
||||
|
||||
|
||||
class MESH_MT_vertex_group_weight(Menu):
|
||||
bl_label = "Weights"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator(
|
||||
"object.vertex_group_remove_from",
|
||||
icon='MESH_DATA',
|
||||
text="Remove Selected Verts from All Groups",
|
||||
).use_all_groups = True
|
||||
layout.operator(
|
||||
"object.vertex_group_clean", icon='BRUSH_DATA', text="Clean 0 Weights from All Groups"
|
||||
).group_select_mode = 'ALL'
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator(
|
||||
"object.vertex_group_remove_from",
|
||||
icon='TRASH',
|
||||
text="Remove All Verts from Selected Group",
|
||||
).use_all_verts = True
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator(
|
||||
'paint.weight_from_bones', text="Assign Automatic from Bones", icon='BONE_DATA'
|
||||
).type = 'AUTOMATIC'
|
||||
op = layout.operator(
|
||||
'object.vertex_group_normalize_all', text="Normalize Deform", icon='IPO_SINE'
|
||||
)
|
||||
op.group_select_mode = 'BONE_DEFORM'
|
||||
op.lock_active = False
|
||||
|
||||
|
||||
def draw_misc(self, context):
|
||||
layout = self.layout
|
||||
layout.operator('object.focus_deform_vgroups', icon='ZOOM_IN')
|
||||
|
||||
|
||||
def draw_vertex_group_menu(self, context):
|
||||
layout = self.layout
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_batch_delete', icon='TRASH')
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_symmetry', icon='ARROW_LEFTRIGHT')
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_sort', icon='SORTALPHA')
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_copy', icon='DUPLICATE')
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_lock', icon='LOCKED')
|
||||
layout.row().menu(menu='MESH_MT_vertex_group_weight', icon='MOD_VERTEX_WEIGHT')
|
||||
|
||||
|
||||
registry = [
|
||||
MESH_MT_vertex_group_batch_delete,
|
||||
MESH_MT_vertex_group_symmetry,
|
||||
MESH_MT_vertex_group_sort,
|
||||
MESH_MT_vertex_group_copy,
|
||||
MESH_MT_vertex_group_lock,
|
||||
MESH_MT_vertex_group_weight,
|
||||
]
|
||||
|
||||
|
||||
def register():
|
||||
VG_CONTEXT_MENU.old_draw = VG_CONTEXT_MENU.draw
|
||||
VG_CONTEXT_MENU.remove(VG_CONTEXT_MENU.draw)
|
||||
|
||||
VG_CONTEXT_MENU.append(draw_vertex_group_menu)
|
||||
VG_CONTEXT_MENU.append(draw_misc)
|
||||
|
||||
|
||||
def unregister():
|
||||
VG_CONTEXT_MENU.draw = VG_CONTEXT_MENU.old_draw
|
||||
del VG_CONTEXT_MENU.old_draw
|
||||
|
||||
VG_CONTEXT_MENU.remove(draw_vertex_group_menu)
|
||||
VG_CONTEXT_MENU.remove(draw_misc)
|
||||
@@ -0,0 +1,89 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import bpy
|
||||
from bpy.app.handlers import persistent
|
||||
from .utils import get_addon_prefs
|
||||
|
||||
@persistent
|
||||
def start_cleaner(scene=None, depsgraph=None):
|
||||
if WeightCleaner.clean_weights not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(WeightCleaner.clean_weights)
|
||||
if WeightCleaner.reset_flag not in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.append(WeightCleaner.reset_flag)
|
||||
|
||||
@persistent
|
||||
def stop_cleaner(scene=None, depsgraph=None):
|
||||
if WeightCleaner.clean_weights in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.remove(WeightCleaner.clean_weights)
|
||||
if WeightCleaner.reset_flag in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(WeightCleaner.reset_flag)
|
||||
|
||||
|
||||
class WeightCleaner:
|
||||
"""Run bpy.ops.object.vertex_group_clean on every depsgraph update while in weight paint mode (ie. every brush stroke)."""
|
||||
|
||||
# Flag set in post_depsgraph_update, to indicate to pre_depsgraph_update that the depsgraph update has indeed completed.
|
||||
can_clean = True
|
||||
# Flag set by pre_depsgraph_update to indicate to post_depsgraph_update that the cleanup operator is still running (in a different thread).
|
||||
cleaning_in_progress = False
|
||||
|
||||
@classmethod
|
||||
def clean_weights(cls, scene, depsgraph):
|
||||
context = bpy.context
|
||||
prefs = get_addon_prefs(context)
|
||||
if context.mode != 'PAINT_WEIGHT':
|
||||
return
|
||||
if not context or not hasattr(context, 'active_object') or not context.active_object:
|
||||
return
|
||||
if not prefs.auto_clean_weights:
|
||||
return
|
||||
tool = context.workspace.tools.from_space_view3d_mode("PAINT_WEIGHT", create=False).idname
|
||||
if tool == "builtin.gradient":
|
||||
# Trying to clean while using gradient causes a crash:
|
||||
# https://projects.blender.org/studio/blender-studio-tools/issues/332
|
||||
return
|
||||
if cls.can_clean:
|
||||
cls.can_clean = False
|
||||
cls.cleaning_in_progress = True
|
||||
# This will trigger a depsgraph update, and therefore clean_weights, again.
|
||||
try:
|
||||
ensure_mirror_groups(context.active_object)
|
||||
bpy.ops.object.vertex_group_clean(group_select_mode='ALL', limit=0.001)
|
||||
except Exception:
|
||||
# This happens for example if the object has no vertex groups.
|
||||
pass
|
||||
cls.cleaning_in_progress = False
|
||||
|
||||
@classmethod
|
||||
def reset_flag(cls, scene, depsgraph):
|
||||
context = bpy.context
|
||||
if context.mode != 'PAINT_WEIGHT':
|
||||
return
|
||||
if not context or not hasattr(context, 'active_object') or not context.active_object:
|
||||
return
|
||||
if cls.cleaning_in_progress:
|
||||
return
|
||||
cls.can_clean = True
|
||||
|
||||
def ensure_mirror_groups(mesh_obj):
|
||||
mod_types = [mod.type for mod in mesh_obj.modifiers]
|
||||
rigs = [m.object for m in mesh_obj.modifiers if m.type == 'ARMATURE' and m.object]
|
||||
if rigs and 'MIRROR' in mod_types:
|
||||
for rig in rigs:
|
||||
for pb in rig.pose.bones:
|
||||
if pb.name in mesh_obj.vertex_groups:
|
||||
flipped_name = bpy.utils.flip_name(pb.name)
|
||||
if flipped_name != pb.name and flipped_name not in mesh_obj.vertex_groups:
|
||||
mesh_obj.vertex_groups.new(name=flipped_name)
|
||||
|
||||
|
||||
def register():
|
||||
start_cleaner()
|
||||
bpy.app.handlers.load_post.append(start_cleaner)
|
||||
|
||||
|
||||
def unregister():
|
||||
stop_cleaner()
|
||||
bpy.app.handlers.load_post.remove(start_cleaner)
|
||||
@@ -0,0 +1,179 @@
|
||||
# SPDX-FileCopyrightText: 2025 Blender Studio Tools Authors
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from bpy.types import Menu
|
||||
from .utils import get_addon_prefs
|
||||
|
||||
|
||||
class EASYWEIGHT_MT_PIE_easy_weight(Menu):
|
||||
bl_label = "Easy Weight"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
pie = layout.menu_pie()
|
||||
|
||||
prefs = get_addon_prefs(context)
|
||||
|
||||
# 1) < Operators
|
||||
op = pie.operator('wm.call_menu_pie', text="Operators", icon='SETTINGS')
|
||||
op.name = 'EASYWEIGHT_MT_PIE_easy_weight_operators'
|
||||
|
||||
# 2) > Front Faces Only
|
||||
pie.prop(
|
||||
prefs,
|
||||
'global_front_faces_only',
|
||||
icon='OVERLAY',
|
||||
text="Paint Through Mesh",
|
||||
invert_checkbox=True,
|
||||
)
|
||||
|
||||
# 3) V Overlay & Armature Display settings
|
||||
op = pie.operator('wm.call_menu_pie', text="Overlays", icon='OVERLAY')
|
||||
op.name = 'EASYWEIGHT_MT_PIE_easy_weight_overlays'
|
||||
|
||||
# 4) ^ Accumulate
|
||||
pie.prop(prefs, 'global_accumulate', icon='GP_SELECT_STROKES')
|
||||
|
||||
# 5) <^ Empty
|
||||
pie.separator()
|
||||
|
||||
# 6) ^> Toggle Falloff Shape
|
||||
icon = 'SPHERE' if prefs.global_falloff_shape_sphere else 'MESH_CIRCLE'
|
||||
text = "Spherical" if prefs.global_falloff_shape_sphere else "Projected Circle"
|
||||
pie.prop(
|
||||
prefs,
|
||||
'global_falloff_shape_sphere',
|
||||
text="Falloff Shape: " + text,
|
||||
icon=icon,
|
||||
invert_checkbox=prefs.global_falloff_shape_sphere,
|
||||
)
|
||||
|
||||
# 7) <v Empty
|
||||
pie.separator()
|
||||
|
||||
# 8) v>Empty
|
||||
pie.separator()
|
||||
|
||||
|
||||
|
||||
class EASYWEIGHT_MT_PIE_easy_weight_operators(Menu):
|
||||
bl_label = "Easy Weight Operators"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
pie = layout.menu_pie()
|
||||
|
||||
# 1) < Focus Deforming Bones.
|
||||
pie.operator('object.focus_deform_vgroups', icon='ZOOM_IN')
|
||||
|
||||
# 2) > Delete Empty Deform Groups.
|
||||
pie.operator(
|
||||
'object.delete_empty_deform_vgroups',
|
||||
text="Delete Empty Deform Groups",
|
||||
icon='GROUP_BONE',
|
||||
)
|
||||
|
||||
# 3) V Symmetrize Weights.
|
||||
pie.operator(
|
||||
'object.symmetrize_vertex_weights',
|
||||
text="Symmetrize Vertex Groups",
|
||||
icon='MOD_MIRROR',
|
||||
)
|
||||
|
||||
# 4) ^ Smooth Weights.
|
||||
op = pie.operator(
|
||||
'object.vertex_group_smooth',
|
||||
icon='MOD_SMOOTH'
|
||||
)
|
||||
if context.pose_object:
|
||||
op.group_select_mode='BONE_DEFORM'
|
||||
op.factor=1
|
||||
|
||||
# 5) <^ Normalize Deforming Groups.
|
||||
op = pie.operator(
|
||||
'object.vertex_group_normalize_all', text="Normalize Deform Groups", icon='IPO_SINE'
|
||||
)
|
||||
if context.pose_object:
|
||||
op.group_select_mode = 'BONE_DEFORM'
|
||||
op.lock_active = False
|
||||
|
||||
# 6) ^> Transfer Weights
|
||||
op = pie.operator(
|
||||
'object.data_transfer',
|
||||
text="Transfer All Groups to Selected Objects",
|
||||
icon='UV_SYNC_SELECT'
|
||||
)
|
||||
op.use_reverse_transfer=False
|
||||
op.data_type='VGROUP_WEIGHTS'
|
||||
op.layers_select_src='ALL'
|
||||
op.layers_select_dst='NAME'
|
||||
|
||||
# 7) <v Auto Weights.
|
||||
pie.operator(
|
||||
'paint.weight_from_bones', text="Assign Automatic from Bones", icon='BONE_DATA'
|
||||
).type = 'AUTOMATIC'
|
||||
|
||||
# 8) v> Delete Unused Groups.
|
||||
pie.operator('object.delete_unused_vgroups', text="Delete Unused Groups", icon='BRUSH_DATA')
|
||||
|
||||
|
||||
class EASYWEIGHT_MT_PIE_easy_weight_overlays(Menu):
|
||||
bl_label = "Weight Painting Overlay"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
pie = layout.menu_pie()
|
||||
|
||||
overlay = context.space_data.overlay
|
||||
tool_settings = context.tool_settings
|
||||
prefs = get_addon_prefs(context)
|
||||
|
||||
# 1) < X-Ray
|
||||
if overlay.show_xray_bone:
|
||||
pie.prop(overlay, 'show_xray_bone', text="X-Ray Overlay")
|
||||
elif context.pose_object:
|
||||
pie.prop(context.pose_object, "show_in_front", toggle=True, icon='XRAY', text="Armature X-Ray")
|
||||
else:
|
||||
pie.separator()
|
||||
|
||||
# 2) > Weight Contours
|
||||
pie.prop(
|
||||
overlay,
|
||||
"show_wpaint_contours",
|
||||
text="Weight Contours",
|
||||
toggle=True,
|
||||
icon='MOD_INSTANCE',
|
||||
)
|
||||
|
||||
# 3) V Armature Display type
|
||||
if context.pose_object:
|
||||
box = pie.box()
|
||||
box.label(text="Armature Display Type")
|
||||
box.row(align=True).prop(context.pose_object.data, "display_type", expand=True)
|
||||
else:
|
||||
pie.separator()
|
||||
|
||||
# 4) ^ Bones.
|
||||
icon = 'HIDE_OFF' if overlay.show_bones else 'HIDE_ON'
|
||||
pie.prop(overlay, "show_bones", text="Bones", toggle=True, icon=icon)
|
||||
|
||||
# 5) <^ Show Zero Weights.
|
||||
if not prefs.always_show_zero_weights:
|
||||
pie.prop(tool_settings, "vertex_group_user", text="Zero Weights Display", expand=True)
|
||||
else:
|
||||
pie.separator()
|
||||
|
||||
# 6) ^> Wireframe.
|
||||
if hasattr(context.space_data, "overlay"):
|
||||
pie.prop(overlay, "show_wireframes", text="Wireframe", toggle=True, icon='SHADING_WIRE')
|
||||
else:
|
||||
pie.separator()
|
||||
|
||||
|
||||
registry = [
|
||||
EASYWEIGHT_MT_PIE_easy_weight,
|
||||
EASYWEIGHT_MT_PIE_easy_weight_operators,
|
||||
EASYWEIGHT_MT_PIE_easy_weight_overlays,
|
||||
]
|
||||
Reference in New Issue
Block a user