Compare commits
16
Commits
fca531bf35
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b7a40ec5a | ||
|
|
b9de93a859 | ||
|
|
81b87eae99 | ||
|
|
3742fd7bc3 | ||
|
|
5f04bf6478 | ||
|
|
672b613bbf | ||
|
|
0d8ab41c57 | ||
|
|
d11d1e0435 | ||
|
|
c16e8a7731 | ||
|
|
38d841cbbb | ||
|
|
660c3c4d76 | ||
|
|
02a62406d9 | ||
|
|
6bfd815d37 | ||
|
|
071f4fd13b | ||
|
|
cb0ea42e19 | ||
|
|
94f24ad5f6 |
@@ -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>.
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "gp interpolate",
|
"name": "GP Interpolate",
|
||||||
"author": "Christophe Seux, Samuel Bernou",
|
"author": "Christophe Seux, Samuel Bernou",
|
||||||
"version": (0, 7, 4),
|
"version": (0, 9, 1),
|
||||||
"blender": (3, 6, 0),
|
"blender": (4, 0, 2),
|
||||||
"location": "Sidebar > Gpencil Tab > Interpolate",
|
"location": "Sidebar > Gpencil Tab > Interpolate",
|
||||||
"description": "Interpolate Grease pencil strokes over 3D",
|
"description": "Interpolate Grease pencil strokes over 3D",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
RESOURCES_DIR = Path(__file__).parent /'resources'
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
from gp_interpolate.interpolate_strokes import (operators,
|
from gp_interpolate.interpolate_strokes import (properties,
|
||||||
properties,
|
operators,
|
||||||
|
operators_triangle,
|
||||||
|
operators_velocity,
|
||||||
debug,
|
debug,
|
||||||
#interpolate_simple
|
bind_points,
|
||||||
)
|
)
|
||||||
|
|
||||||
modules = (
|
modules = (
|
||||||
properties,
|
properties,
|
||||||
operators,
|
operators,
|
||||||
debug
|
operators_triangle,
|
||||||
#interpolate_simple,
|
operators_velocity,
|
||||||
|
debug,
|
||||||
|
bind_points,
|
||||||
)
|
)
|
||||||
|
|
||||||
if "bpy" in locals():
|
if "bpy" in locals():
|
||||||
|
|||||||
@@ -0,0 +1,384 @@
|
|||||||
|
import bpy
|
||||||
|
import numpy as np
|
||||||
|
from time import perf_counter, time, sleep
|
||||||
|
from mathutils import Vector, Matrix
|
||||||
|
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
|
from mathutils.geometry import (barycentric_transform,
|
||||||
|
intersect_point_tri,
|
||||||
|
intersect_point_line,
|
||||||
|
intersect_line_plane,
|
||||||
|
tessellate_polygon)
|
||||||
|
|
||||||
|
import math
|
||||||
|
import gpu
|
||||||
|
from bpy_extras import view3d_utils
|
||||||
|
from gpu_extras.batch import batch_for_shader
|
||||||
|
|
||||||
|
|
||||||
|
def raycast_objects(context, event, dg):
|
||||||
|
"""
|
||||||
|
Execute ray cast
|
||||||
|
return object hit, hit world location, normal of hitted face and face index
|
||||||
|
"""
|
||||||
|
|
||||||
|
region = context.region
|
||||||
|
rv3d = context.region_data
|
||||||
|
coord = event.mouse_region_x, event.mouse_region_y
|
||||||
|
|
||||||
|
view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
|
||||||
|
ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
|
||||||
|
ray_target = ray_origin + view_vector
|
||||||
|
|
||||||
|
def visible_objects_and_duplis():# -> Generator[tuple, Any, None]:
|
||||||
|
"""Loop over (object, matrix) pairs (mesh only)"""
|
||||||
|
|
||||||
|
# depsgraph = dg ## TRY to used passed depsgraph
|
||||||
|
depsgraph = context.evaluated_depsgraph_get()
|
||||||
|
for dup in depsgraph.object_instances:
|
||||||
|
if dup.is_instance: # Real dupli instance
|
||||||
|
obj = dup.instance_object
|
||||||
|
yield (obj, dup.matrix_world.copy())
|
||||||
|
else: # Usual object
|
||||||
|
obj = dup.object
|
||||||
|
yield (obj, obj.matrix_world.copy())
|
||||||
|
|
||||||
|
def obj_ray_cast(obj, matrix):
|
||||||
|
"""Wrapper for ray casting that moves the ray into object space"""
|
||||||
|
|
||||||
|
# get the ray relative to the object
|
||||||
|
matrix_inv = matrix.inverted()
|
||||||
|
ray_origin_obj = matrix_inv @ ray_origin
|
||||||
|
ray_target_obj = matrix_inv @ ray_target
|
||||||
|
ray_direction_obj = ray_target_obj - ray_origin_obj
|
||||||
|
|
||||||
|
# cast the ray
|
||||||
|
success, location, normal, face_index = obj.ray_cast(ray_origin_obj, ray_direction_obj)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
return location, normal, face_index
|
||||||
|
else:
|
||||||
|
return None, None, None
|
||||||
|
|
||||||
|
# cast rays and find the closest object
|
||||||
|
best_length_squared = -1.0
|
||||||
|
best_obj = None
|
||||||
|
face_normal = None
|
||||||
|
hit_loc = None
|
||||||
|
obj_face_index = None
|
||||||
|
for obj, matrix in visible_objects_and_duplis():
|
||||||
|
if obj.type == 'MESH':
|
||||||
|
hit, normal, face_index = obj_ray_cast(obj, matrix)
|
||||||
|
if hit is not None:
|
||||||
|
hit_world = matrix @ hit
|
||||||
|
# scene.cursor.location = hit_world
|
||||||
|
length_squared = (hit_world - ray_origin).length_squared
|
||||||
|
if best_obj is None or length_squared < best_length_squared:
|
||||||
|
# print('length_squared',length_squared)
|
||||||
|
best_length_squared = length_squared
|
||||||
|
best_obj = obj
|
||||||
|
face_normal = normal
|
||||||
|
hit_loc = hit_world
|
||||||
|
obj_face_index = face_index
|
||||||
|
|
||||||
|
if best_obj is not None:
|
||||||
|
best_original = best_obj.original
|
||||||
|
return best_original, hit_loc, face_normal, obj_face_index
|
||||||
|
|
||||||
|
return None, None, None, None
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
### Drawing
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
def circle_2d(coord, r, num_segments):
|
||||||
|
'''create circle, ref: http://slabode.exofire.net/circle_draw.shtml'''
|
||||||
|
cx, cy = coord
|
||||||
|
points = []
|
||||||
|
theta = 2 * 3.1415926 / num_segments
|
||||||
|
c = math.cos(theta) #precalculate the sine and cosine
|
||||||
|
s = math.sin(theta)
|
||||||
|
x = r # we start at angle = 0
|
||||||
|
y = 0
|
||||||
|
for i in range(num_segments):
|
||||||
|
#bgl.glVertex2f(x + cx, y + cy) # output vertex
|
||||||
|
points.append((x + cx, y + cy))
|
||||||
|
# apply the rotation matrix
|
||||||
|
t = x
|
||||||
|
x = c * x - s * y
|
||||||
|
y = s * t + c * y
|
||||||
|
|
||||||
|
return points
|
||||||
|
|
||||||
|
def draw_callback_px(self, context):
|
||||||
|
if context.area != self.current_area:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 50% alpha, 2 pixel width line
|
||||||
|
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
|
||||||
|
gpu.state.blend_set('ALPHA')
|
||||||
|
gpu.state.line_width_set(2.0)
|
||||||
|
|
||||||
|
view_rot = context.region_data.view_rotation
|
||||||
|
|
||||||
|
if self.current_points:
|
||||||
|
for coord in self.current_points:
|
||||||
|
# circle3d = [(view_normal.to_track_quat('-Z', 'Z') @ cp) + coord for cp in self.circle_pts]
|
||||||
|
circle3d = [(view_rot @ cp) + coord for cp in self.mini_circle_pts]
|
||||||
|
circle3d.append(circle3d[0]) # Loop with last point
|
||||||
|
batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": circle3d})
|
||||||
|
shader.bind()
|
||||||
|
shader.uniform_float("color", (0.8, 0.8, 0.0, 0.9))
|
||||||
|
batch.draw(shader)
|
||||||
|
|
||||||
|
# Draw clicked path
|
||||||
|
if not self.point_list:
|
||||||
|
return
|
||||||
|
|
||||||
|
positions = [pt['co'] for pt in self.point_list]
|
||||||
|
|
||||||
|
line_color = color = (0.9, 0.1, 0.2, 0.8)
|
||||||
|
|
||||||
|
## Draw lines
|
||||||
|
|
||||||
|
if len(self.point_list) >= 3:
|
||||||
|
## Duplicate first position at last to loop triangle
|
||||||
|
positions += [self.point_list[0]['co']]
|
||||||
|
line_color = (0.9, 0.1, 0.3, 1.0)
|
||||||
|
|
||||||
|
batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": positions})
|
||||||
|
shader.bind()
|
||||||
|
shader.uniform_float("color", line_color)
|
||||||
|
batch.draw(shader)
|
||||||
|
|
||||||
|
# Draw circle on point aligned with view
|
||||||
|
|
||||||
|
# view_normal = context.region_data.view_matrix.inverted() @ Vector((0,0,1))
|
||||||
|
|
||||||
|
for pt in self.point_list:
|
||||||
|
coord = pt['co']
|
||||||
|
|
||||||
|
# circle3d = [(view_normal.to_track_quat('-Z', 'Z') @ cp) + coord for cp in self.circle_pts]
|
||||||
|
circle3d = [(view_rot @ cp) + coord for cp in self.circle_pts]
|
||||||
|
circle3d.append(circle3d[0]) # Loop with last point
|
||||||
|
batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": circle3d})
|
||||||
|
shader.bind()
|
||||||
|
shader.uniform_float("color", color)
|
||||||
|
batch.draw(shader)
|
||||||
|
|
||||||
|
# restore opengl defaults
|
||||||
|
gpu.state.line_width_set(1.0)
|
||||||
|
gpu.state.blend_set('NONE')
|
||||||
|
|
||||||
|
## POST_PIXEL for text
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
### Operator
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
class GP_OT_bind_points(bpy.types.Operator):
|
||||||
|
bl_idname = "gp.bind_points"
|
||||||
|
bl_label = "Bind Points"
|
||||||
|
bl_description = 'Bind points to use as reference for interpolation'
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.object and context.object.type == 'GPENCIL'
|
||||||
|
|
||||||
|
clear : bpy.props.BoolProperty(name='Clear', default=False, options={'SKIP_SAVE'})
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
# print('INVOKE')
|
||||||
|
self.debug = False
|
||||||
|
self.gp = context.object
|
||||||
|
self.settings = context.scene.gp_interpo_settings
|
||||||
|
self.point_list = []
|
||||||
|
self.current_points = []
|
||||||
|
wm = context.window_manager
|
||||||
|
if tri_dump := wm.get(f'tri_{self.gp.name}'):
|
||||||
|
if self.clear:
|
||||||
|
del wm[f'tri_{self.gp.name}']
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
## load from current frame
|
||||||
|
## Dict to list -> cast to dict (get ID prop array)
|
||||||
|
self.point_list = [dict(tri_dump[str(i)]) for i in range(3)]
|
||||||
|
|
||||||
|
## Update world coordinate position at current frame
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
for point in self.point_list:
|
||||||
|
ob = bpy.context.scene.objects.get(point['object'])
|
||||||
|
ob_eval = ob.evaluated_get(dg)
|
||||||
|
point['co'] = ob_eval.matrix_world @ ob_eval.data.vertices[point['index']].co
|
||||||
|
|
||||||
|
if self.clear:
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
## Prepare circle 3D coordinate (create in invoke)
|
||||||
|
self.circle_pts = [Vector((p[0], p[1], 0)) for p in circle_2d((0,0), 0.01, 12)]
|
||||||
|
self.mini_circle_pts = [Vector((p[0], p[1], 0)) for p in circle_2d((0,0), 0.005, 12)]
|
||||||
|
|
||||||
|
# self._timer = wm.event_timer_add(0.01, window=context.window)
|
||||||
|
|
||||||
|
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
|
||||||
|
self.current_area = context.area
|
||||||
|
args = (self, context)
|
||||||
|
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_VIEW')
|
||||||
|
context.area.header_text_set('Bind points | Enter: Valid | Backspace: remove last point | Esc / Right-Click: Cancel')
|
||||||
|
wm.modal_handler_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def exit_modal(self, context, status='INFO', text=None):
|
||||||
|
# print('Exit modal') # Dbg
|
||||||
|
## Reset all drawing and report
|
||||||
|
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
|
||||||
|
context.area.header_text_set(None)
|
||||||
|
context.area.tag_redraw()
|
||||||
|
if text:
|
||||||
|
self.report({status}, text)
|
||||||
|
else:
|
||||||
|
## report standard info
|
||||||
|
self.report({'INFO'}, 'Done')
|
||||||
|
|
||||||
|
def get_closest_vert(self, object_hit, hit_location, _normal, face_index, dg):
|
||||||
|
|
||||||
|
ob_eval = object_hit.evaluated_get(dg)
|
||||||
|
## Get closest index on face and store
|
||||||
|
face = ob_eval.data.polygons[face_index]
|
||||||
|
|
||||||
|
## list(dict)
|
||||||
|
vertices_infos = [{
|
||||||
|
'object': object_hit.name, # store object 'name'
|
||||||
|
'index': vert_idx, # store vertex index
|
||||||
|
'co': ob_eval.matrix_world @ ob_eval.data.vertices[vert_idx].co # store initial absolute coordinate
|
||||||
|
}
|
||||||
|
# vertex: ob_eval.data.vertices[vert_idx],
|
||||||
|
for vert_idx in face.vertices]
|
||||||
|
|
||||||
|
## Filter vertices by closest to hit_location
|
||||||
|
vertices_infos.sort(key=lambda x: (x['co'] - hit_location).length)
|
||||||
|
return vertices_infos[0]
|
||||||
|
|
||||||
|
def bind(self, context):
|
||||||
|
## store points on scene/wm properties associated with GP object
|
||||||
|
context.window_manager[f'tri_{context.object.name}'] = {str(i) : d for i, d in enumerate(self.point_list)}
|
||||||
|
self.exit_modal(context, text='Bound!')
|
||||||
|
|
||||||
|
def modal(self, context, event):
|
||||||
|
context.area.tag_redraw()
|
||||||
|
if event.type in ('RIGHTMOUSE', 'ESC'):
|
||||||
|
context.area.header_text_set(f'Cancelling')
|
||||||
|
self.exit_modal(context, text='Cancelled')
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
if event.type in ('WHEELUPMOUSE', 'WHEELDOWNMOUSE', 'MIDDLEMOUSE'):
|
||||||
|
return {'PASS_THROUGH'}
|
||||||
|
|
||||||
|
## disable hint if too intensive
|
||||||
|
if event.type in {'MOUSEMOVE'}:
|
||||||
|
## permanent update on closest point position (too heavy to always compute ?)
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
object_hit, hit_location, _normal, face_index = raycast_objects(context, event, bpy.context.evaluated_depsgraph_get())
|
||||||
|
if object_hit is None:
|
||||||
|
self.current_points = []
|
||||||
|
else:
|
||||||
|
pt = self.get_closest_vert(object_hit, hit_location, _normal, face_index, dg)
|
||||||
|
self.current_points = [pt['co']]
|
||||||
|
return {'PASS_THROUGH'}
|
||||||
|
|
||||||
|
elif event.type in ('BACK_SPACE', 'DEL') and event.value == 'PRESS':
|
||||||
|
if self.point_list:
|
||||||
|
self.report({'INFO'}, 'Removed last point')
|
||||||
|
self.point_list.pop()
|
||||||
|
|
||||||
|
|
||||||
|
elif event.type in ('RET', 'SPACE') and event.value == 'PRESS':
|
||||||
|
## Valid
|
||||||
|
if len(self.point_list) < 3:
|
||||||
|
self.exit_modal(context, status='ERROR', text='Not enough point selected, Cancelling')
|
||||||
|
return {'CANCELLED'}
|
||||||
|
else:
|
||||||
|
self.bind(context)
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
elif event.type == 'LEFTMOUSE' and event.value == 'PRESS':
|
||||||
|
if len(self.point_list) >= 3:
|
||||||
|
# self.report({'WARNING'}, 'Already got 3 point')
|
||||||
|
self.bind(context)
|
||||||
|
return {'FINISHED'}
|
||||||
|
else:
|
||||||
|
## Raycast surface and store point
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
|
||||||
|
## Basic rayvast (Do not consider object modifier or instance !)
|
||||||
|
# mouse = event.mouse_region_x, event.mouse_region_y
|
||||||
|
# view_mat = context.region_data.view_matrix.inverted()
|
||||||
|
# origin = view_mat.to_translation()
|
||||||
|
# depth3d = view_mat @ Vector((0, 0, -1))
|
||||||
|
# point = utils.region_to_location(mouse, depth3d)
|
||||||
|
# ray = (point - origin)
|
||||||
|
# hit, hit_location, normal, face_index, object_hit, matrix = bpy.context.scene.ray_cast(dg, origin, ray)
|
||||||
|
|
||||||
|
object_hit, hit_location, _normal, face_index = raycast_objects(context, event, dg)
|
||||||
|
|
||||||
|
## Also use triangle coordinate in triangle ?! using raycast with tesselated triangle infos
|
||||||
|
# object_hit, hit_location, tri, tri_indices = ray_cast_point(point, origin, dg)
|
||||||
|
|
||||||
|
if object_hit is None:
|
||||||
|
self.report({'WARNING'}, 'Nothing hit, Retry on a surface')
|
||||||
|
else:
|
||||||
|
# print('object_hit: ', object_hit, object_hit.is_evaluated)
|
||||||
|
# print('hit_location: ', hit_location)
|
||||||
|
# print('face_index: ', face_index)
|
||||||
|
|
||||||
|
# context.scene.cursor.location = hit_location # Dbg
|
||||||
|
|
||||||
|
### // get vert on-place
|
||||||
|
# ob_eval = object_hit.evaluated_get(dg)
|
||||||
|
# print('ob_eval: ', ob_eval)
|
||||||
|
# ## Get closest index on face and store
|
||||||
|
# face = ob_eval.data.polygons[face_index]
|
||||||
|
# ## Store list of tuples [(index, world_co, object_hit), ...]
|
||||||
|
# vertices_infos = [(vert_idx,
|
||||||
|
# ob_eval.matrix_world @ ob_eval.data.vertices[vert_idx].co,
|
||||||
|
# object_hit) # Store original object.
|
||||||
|
# for vert_idx in face.vertices]
|
||||||
|
|
||||||
|
# ## Filter vedrtices by closest to hit_location
|
||||||
|
# vertices_infos.sort(key=lambda x: (x['co'] - hit_location).length)
|
||||||
|
|
||||||
|
# vert = vertices_infos[0]
|
||||||
|
### get vert on-place //
|
||||||
|
|
||||||
|
vert = self.get_closest_vert(object_hit, hit_location, _normal, face_index, dg)
|
||||||
|
|
||||||
|
# print('vert: ', vert)
|
||||||
|
|
||||||
|
# if self.point_list and [x for x in self.point_list if vert[0] == x[0] and vert[3] == x[3]]:
|
||||||
|
if any(vert['index'] == x['index'] and vert['object'] == x['object'] for x in self.point_list):
|
||||||
|
self.report({'WARNING'}, "Cannot use same point twice !")
|
||||||
|
else:
|
||||||
|
self.point_list += [vert]
|
||||||
|
self.report({'INFO'}, f"Set point {len(self.point_list)}")
|
||||||
|
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
GP_OT_bind_points,
|
||||||
|
)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in reversed(classes):
|
||||||
|
bpy.utils.unregister_class(c)
|
||||||
@@ -174,13 +174,28 @@ class GP_OT_debug_geometry_interpolation_targets(bpy.types.Operator):
|
|||||||
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
|
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
|
||||||
|
|
||||||
is_hit = 'HIT' if object_hit else ''
|
is_hit = 'HIT' if object_hit else ''
|
||||||
empty_at(name=f'{is_hit}search_{iteration}({ct})', pos=square_co, collection=debug_col, size=0.001, show_name=True) # type='SPHERE'
|
## Show all search square elements
|
||||||
|
# empty_at(name=f'{is_hit}{i}search_{iteration}({ct})', pos=square_co, collection=debug_col, size=0.001, show_name=False) # type='SPHERE'
|
||||||
|
|
||||||
|
## Show only hit location (at hit location)
|
||||||
|
if is_hit:
|
||||||
|
empty_at(name=f'{is_hit}{i}search_{iteration}({ct})', pos=hit_location, collection=debug_col, size=0.001, show_name=False) # type='SPHERE'
|
||||||
|
|
||||||
if object_hit: # and object_hit in col.all_objects[:]:
|
if object_hit: # and object_hit in col.all_objects[:]:
|
||||||
context.scene.cursor.location = hit_location
|
context.scene.cursor.location = hit_location
|
||||||
## Get location coplanar with triangle
|
## On location coplanar with face triangle
|
||||||
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
|
# hit_location = intersect_line_plane(origin, point_co_world, hit_location, triangle_normal(*tri))
|
||||||
empty_at(name=f'{object_hit.name}_{i}-{iteration}', pos=hit_location, collection=debug_col, type='SPHERE', size=0.001, show_name=True)
|
|
||||||
|
## On view plane
|
||||||
|
view_vec = context.scene.camera.matrix_world.to_quaternion() @ Vector((0,0,1))
|
||||||
|
hit_location = intersect_line_plane(origin, point_co_world, hit_location, view_vec)
|
||||||
|
|
||||||
|
## An average of the two ?
|
||||||
|
# hit_location_1 = intersect_line_plane(origin, point_co_world, hit_location, triangle_normal(*tri))
|
||||||
|
# hit_location_2 = intersect_line_plane(origin, point_co_world, hit_location, view_vec)
|
||||||
|
# hit_location = (hit_location_1 + hit_location_2) / 2
|
||||||
|
|
||||||
|
empty_at(name=f'{object_hit.name}_{i}-{iteration}', pos=hit_location, collection=debug_col, type='SPHERE', size=0.001, show_name=False)
|
||||||
found = True
|
found = True
|
||||||
# print(f'{si}:{i} iteration {iteration}') # Dbg
|
# print(f'{si}:{i} iteration {iteration}') # Dbg
|
||||||
break
|
break
|
||||||
@@ -196,7 +211,7 @@ class GP_OT_debug_geometry_interpolation_targets(bpy.types.Operator):
|
|||||||
else:
|
else:
|
||||||
## Hit at original position
|
## Hit at original position
|
||||||
print(object_hit.name)
|
print(object_hit.name)
|
||||||
empty_at(name=f'{object_hit.name}_{i}', pos=hit_location, collection=debug_col, type='SPHERE', size=0.001, show_name=True)
|
empty_at(name=f'{object_hit.name}_{i}', pos=hit_location, collection=debug_col, type='SPHERE', size=0.001, show_name=False)
|
||||||
|
|
||||||
print('Done')
|
print('Done')
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|||||||
+449
-369
@@ -1,35 +1,58 @@
|
|||||||
import bpy
|
from time import time
|
||||||
import numpy as np
|
import re
|
||||||
from time import perf_counter, time, sleep
|
|
||||||
from mathutils import Vector, Matrix
|
|
||||||
|
|
||||||
from ..utils import (matrix_transform,
|
import bpy
|
||||||
plane_on_bone,
|
from mathutils import Vector
|
||||||
ray_cast_point,
|
|
||||||
obj_ray_cast,
|
|
||||||
intersect_with_tesselated_plane,
|
|
||||||
triangle_normal,
|
|
||||||
search_square,
|
|
||||||
get_gp_draw_plane,
|
|
||||||
create_plane,
|
|
||||||
following_keys,
|
|
||||||
index_list_from_bools,
|
|
||||||
attr_set)
|
|
||||||
|
|
||||||
from mathutils.geometry import (barycentric_transform,
|
from mathutils.geometry import (barycentric_transform,
|
||||||
intersect_point_tri,
|
intersect_line_plane)
|
||||||
intersect_point_line,
|
|
||||||
intersect_line_plane,
|
|
||||||
tessellate_polygon)
|
|
||||||
|
|
||||||
## Converted to modal from "operator_single"
|
from ..utils import (plane_on_bone,
|
||||||
|
ray_cast_point,
|
||||||
|
obj_ray_cast,
|
||||||
|
triangle_normal,
|
||||||
|
search_square,
|
||||||
|
get_gp_draw_plane,
|
||||||
|
create_plane,
|
||||||
|
following_keys)
|
||||||
|
|
||||||
class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|
||||||
bl_idname = "gp.interpolate_stroke"
|
class GP_OT_pick_collection(bpy.types.Operator):
|
||||||
bl_label = "Interpolate Stroke"
|
bl_idname = "gp.pick_collection"
|
||||||
bl_description = 'Interpolate Stroke'
|
bl_label = "Auto Pick Mesh Collection"
|
||||||
|
#bl_description = 'Pick Mesh Collection'
|
||||||
bl_options = {'REGISTER', 'UNDO'}
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.active_object and context.object.type == 'GPENCIL'
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
parts = re.split(r'(-|_)', context.object.name)
|
||||||
|
|
||||||
|
for col in context.scene.collection.children_recursive:
|
||||||
|
for i in range(len(parts), -1, -1):
|
||||||
|
base = ''.join(parts[:i])
|
||||||
|
tgt_name = f'{base}_mesh'
|
||||||
|
if tgt_name == col.name:
|
||||||
|
print(f'Automatic set "{tgt_name}"')
|
||||||
|
context.scene.gp_interpo_settings.target_collection = col
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
self.report({"WARNING"}, 'No Collection found')
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
|
||||||
|
class GP_OT_interpolate_stroke_base(bpy.types.Operator):
|
||||||
|
bl_idname = "gp.interpolate_stroke_base"
|
||||||
|
bl_label = "Interpolate Stroke"
|
||||||
|
bl_description = 'Interpolate Stroke based on user bound triangle'
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
interactive : bpy.props.BoolProperty(name='Interactive', default=False, options={'SKIP_SAVE'})
|
||||||
|
|
||||||
|
next : bpy.props.BoolProperty(name='Next', default=True, options={'SKIP_SAVE'})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if context.active_object and context.object.type == 'GPENCIL'\
|
if context.active_object and context.object.type == 'GPENCIL'\
|
||||||
@@ -40,56 +63,36 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def description(cls, context, properties):
|
def description(cls, context, properties):
|
||||||
|
if properties.interactive:
|
||||||
|
return "Interactive interpolate mode\
|
||||||
|
\nUse Left <- -> Right keys\
|
||||||
|
\n+Ctrl to jump over key interpolated during modal"
|
||||||
if properties.next:
|
if properties.next:
|
||||||
return f"Interpolate Stroke Forward"
|
return "Interpolate Stroke Forward"
|
||||||
else:
|
else:
|
||||||
return f"Interpolate Stroke Backward"
|
return "Interpolate Stroke Backward"
|
||||||
|
|
||||||
next : bpy.props.BoolProperty(name='Next', default=True, options={'SKIP_SAVE'})
|
def apply_and_store(self, attrs):
|
||||||
|
'''individual item in attrs: (prop, attr, [new_val])'''
|
||||||
def apply_and_store(self):
|
for item in attrs:
|
||||||
# self.store = []
|
|
||||||
# item = (prop, attr, [new_val])
|
|
||||||
for item in self.store_list:
|
|
||||||
prop, attr = item[:2]
|
prop, attr = item[:2]
|
||||||
self.store.append( (prop, attr, getattr(prop, attr)) )
|
self.stored_attrs.append( (prop, attr, getattr(prop, attr)) )
|
||||||
if len(item) >= 3:
|
if len(item) >= 3:
|
||||||
setattr(prop, attr, item[2])
|
setattr(prop, attr, item[2])
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
for prop, attr, old_val in self.store:
|
for prop, attr, old_val in self.stored_attrs:
|
||||||
setattr(prop, attr, old_val)
|
setattr(prop, attr, old_val)
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def exit(self, context, status='INFO', text=None, cancelled=False):
|
||||||
self.debug = False
|
|
||||||
self.status = 'START'
|
|
||||||
self.store_list = []
|
|
||||||
self.store = []
|
|
||||||
self.loop_count = 0
|
|
||||||
self.start = time()
|
|
||||||
self.scan_time = None
|
|
||||||
self.plane = None
|
|
||||||
self.toolcol = None
|
|
||||||
self.gp = context.object
|
|
||||||
self.settings = context.scene.gp_interpo_settings
|
|
||||||
self.frames_to_jump = None
|
|
||||||
self.cancelled = False
|
|
||||||
|
|
||||||
context.window_manager.modal_handler_add(self)
|
|
||||||
self._timer = context.window_manager.event_timer_add(0.01, window=context.window)
|
|
||||||
context.area.header_text_set('Starting interpolation | Esc: Cancel')
|
|
||||||
return {'RUNNING_MODAL'}
|
|
||||||
|
|
||||||
def exit_modal(self, context, status='INFO', text=None):
|
|
||||||
context.area.header_text_set(None)
|
context.area.header_text_set(None)
|
||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
wm.progress_end() # Pgs
|
if self.report_progress:
|
||||||
wm.event_timer_remove(self._timer)
|
wm.progress_end() # Pgs
|
||||||
|
if self.timer:
|
||||||
|
wm.event_timer_remove(self.timer)
|
||||||
self.restore()
|
self.restore()
|
||||||
if self.debug:
|
if self.debug:
|
||||||
## show as solid ?
|
|
||||||
# if self.plane is not None:
|
|
||||||
# self.plane.display_type = 'SOLID'
|
|
||||||
if self.scan_time is not None:
|
if self.scan_time is not None:
|
||||||
print(f"Paste'n'place time {time()-self.start - self.scan_time}s")
|
print(f"Paste'n'place time {time()-self.start - self.scan_time}s")
|
||||||
else:
|
else:
|
||||||
@@ -97,339 +100,416 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
## Remove Plane and it's collection after use
|
## Remove Plane and it's collection after use
|
||||||
if self.plane is not None:
|
if self.plane is not None:
|
||||||
bpy.data.objects.remove(self.plane)
|
bpy.data.objects.remove(self.plane)
|
||||||
if self.toolcol is not None:
|
if self.tool_col is not None:
|
||||||
bpy.data.collections.remove(self.toolcol)
|
bpy.data.collections.remove(self.tool_col)
|
||||||
|
|
||||||
cancel_state = '(Stopped!) ' if self.cancelled else ''
|
cancel_state = '(Stopped!) ' if cancelled else ''
|
||||||
mess = f'{cancel_state}{self.loop_count} interpolated frame(s) ({time()-self.start:.3f}s)'
|
mess = f'{cancel_state}{self.loop_count} interpolated frame(s) ({time()-self.start:.3f}s)'
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
print(mess)
|
print(mess)
|
||||||
self.report({status}, text)
|
self.report({status}, text)
|
||||||
else:
|
else:
|
||||||
## report standard info
|
self.report({'INFO'}, mess)
|
||||||
if self.loop_count > 1:
|
|
||||||
self.report({'INFO'}, mess)
|
if status == 'INFO':
|
||||||
|
return {'FINISHED'}
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
# def get_stroke_to_interpolate(self, context):
|
||||||
|
# ## Get strokes to interpolate
|
||||||
|
# #tgt_strokes = [s for s in self.gp.data.layers.active.active_frame.strokes if s.select]
|
||||||
|
# tgt_strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
|
||||||
|
# ## If nothing selected in sculpt/paint, Select all before triggering
|
||||||
|
# if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
|
||||||
|
# for s in self.gp.data.layers.active.active_frame.strokes:
|
||||||
|
# s.select = True
|
||||||
|
# tgt_strokes = self.gp.data.layers.active.active_frame.strokes
|
||||||
|
|
||||||
|
# if tgt_strokes:
|
||||||
|
# return tgt_strokes
|
||||||
|
|
||||||
|
# return self.exit(context, status='ERROR', text='No stroke selected!')
|
||||||
|
|
||||||
|
|
||||||
|
## Added to operators owns invoke with uper().invoke(context, event)
|
||||||
|
def invoke(self, context, event):
|
||||||
|
self.debug = False
|
||||||
|
self.stored_attrs = [] # context manager store/restore
|
||||||
|
self.loop_count = 0 # frames list iterator
|
||||||
|
self.start = time()
|
||||||
|
self.scan_time = None # to print time at exit in debug mode
|
||||||
|
self.plane = None # 3D Plane for bone interpolation
|
||||||
|
self.tool_col = None # collection containing 3D plane
|
||||||
|
self.gp = context.object
|
||||||
|
self.settings = context.scene.gp_interpo_settings
|
||||||
|
self.frames_to_jump = []
|
||||||
|
self.cancelled = False
|
||||||
|
self.timer = None
|
||||||
|
self.timer_event = 'TIMER'
|
||||||
|
self.report_progress = (self.settings.use_animation and not self.interactive)
|
||||||
|
self.interpolated_keys = {context.scene.frame_current}
|
||||||
|
|
||||||
|
## Remove interpolation_plane collection ! (unseen, but can be hit)
|
||||||
|
if interp_plane := bpy.data.objects.get('interpolation_plane'):
|
||||||
|
bpy.data.objects.remove(interp_plane)
|
||||||
|
if interp_col := bpy.data.collections.get('interpolation_tool'):
|
||||||
|
bpy.data.collections.remove(interp_col)
|
||||||
|
|
||||||
|
if context.mode != 'EDIT_GPENCIL':
|
||||||
|
self.report({"ERROR"}, "Mode need to be Edit Grease Pencil")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
## Change active layer if strokes are selected only on this layer
|
||||||
|
self.layers = [l for l in self.gp.data.layers
|
||||||
|
if (not l.lock and l.active_frame and not l.hide)
|
||||||
|
and next((s for s in l.active_frame.strokes if s.select), None)]
|
||||||
|
|
||||||
|
self.strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
if not self.strokes:
|
||||||
|
self.report({"ERROR"}, "No strokes selected")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
#if not self.layers:
|
||||||
|
# return self.exit(context, status='ERROR', text='No stroke selected!')
|
||||||
|
|
||||||
|
#elif len(layers) > 1:
|
||||||
|
# return self.exit(context, status='ERROR', text='Strokes selected accross multiple layers!')
|
||||||
|
|
||||||
|
## Set active layer
|
||||||
|
#self.gp.data.layers.active = layers[0]
|
||||||
|
|
||||||
|
if self.interactive:
|
||||||
|
self.frames_to_jump = following_keys(forward=True, animation=True)
|
||||||
|
self.frames_to_jump += following_keys(forward=False, animation=True)
|
||||||
|
self.frames_to_jump.append(context.scene.frame_current)
|
||||||
|
self.frames_to_jump.sort()
|
||||||
|
context.area.header_text_set('Frame interpolation < jump with left-right arrow keys > | Esc/Enter: Stop') # (+Ctrl to skip all already interpolated)
|
||||||
|
else:
|
||||||
|
## Determine on what key/keys to jump
|
||||||
|
self.frames_to_jump = following_keys(forward=self.next, animation=self.settings.use_animation or self.interactive)
|
||||||
|
if not len(self.frames_to_jump):
|
||||||
|
return self.exit(context, status='WARNING', text='No keyframe available in this direction')
|
||||||
|
|
||||||
|
# TODO: Expose timer (in preferences ?) to let user more time to see result between frames
|
||||||
|
self.timer = context.window_manager.event_timer_add(0.04, window=context.window)
|
||||||
|
|
||||||
|
if self.report_progress:
|
||||||
|
context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs
|
||||||
|
|
||||||
|
|
||||||
def modal(self, context, event):
|
def modal(self, context, event):
|
||||||
|
scn = context.scene
|
||||||
|
|
||||||
if event.type in {'RIGHTMOUSE', 'ESC'}:
|
if event.type in {'RIGHTMOUSE', 'ESC', 'RET'}:
|
||||||
print('Cancelling')
|
return self.exit(context, status='WARNING', text='Cancelling', cancelled=True)
|
||||||
self.status = 'CANCELLED'
|
|
||||||
self.cancelled = True
|
|
||||||
context.area.header_text_set(f'Cancelling')
|
|
||||||
self.exit_modal(context)
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
if self.frames_to_jump:
|
if self.interactive:
|
||||||
|
frame = None
|
||||||
|
current_frame = context.scene.frame_current
|
||||||
|
self.loop_count = 0 # Reset to keep inifinite loop
|
||||||
|
if event.type == 'LEFT_ARROW' and event.value == 'PRESS':
|
||||||
|
if event.ctrl:
|
||||||
|
frame = next((f for f in self.frames_to_jump[::-1] if f < current_frame and f not in self.interpolated_keys), None)
|
||||||
|
else:
|
||||||
|
frame = next((f for f in self.frames_to_jump[::-1] if f < current_frame), None)
|
||||||
|
if event.type == 'RIGHT_ARROW' and event.value == 'PRESS':
|
||||||
|
if event.ctrl:
|
||||||
|
frame = next((f for f in self.frames_to_jump if f > current_frame and f not in self.interpolated_keys), None)
|
||||||
|
else:
|
||||||
|
frame = next((f for f in self.frames_to_jump if f > current_frame), None)
|
||||||
|
|
||||||
|
if (event.type in ('LEFT_ARROW', 'RIGHT_ARROW') and event.value == 'PRESS') and frame is None:
|
||||||
|
self.report({'WARNING'}, 'No frame to jump to in this direction!')
|
||||||
|
|
||||||
|
else:
|
||||||
frame_num = len(self.frames_to_jump)
|
frame_num = len(self.frames_to_jump)
|
||||||
percentage = (self.loop_count) / (frame_num) * 100
|
percentage = (self.loop_count) / (frame_num) * 100
|
||||||
context.area.header_text_set(f'Interpolation {percentage:.0f}% {self.loop_count + 1}/{frame_num} | Esc: Cancel')
|
context.area.header_text_set(f'Interpolation {percentage:.0f}% {self.loop_count + 1}/{frame_num} | Esc: Cancel')
|
||||||
# (frame: {self.frames_to_jump[self.loop_count]})
|
|
||||||
|
|
||||||
if self.status == 'START':
|
## -- Enter if LOOPTIMER or INTERACTIVE left-right shortcut
|
||||||
scn = bpy.context.scene
|
if event.type == self.timer_event or (self.interactive and frame is not None):
|
||||||
## Determine on what key/keys to jump
|
if not self.interactive:
|
||||||
self.frames_to_jump = following_keys(forward=self.next, all_keys=self.settings.use_animation)
|
frame = self.frames_to_jump[self.loop_count]
|
||||||
if not len(self.frames_to_jump):
|
scn.frame_set(frame)
|
||||||
self.exit_modal(context, status='WARNING', text='No keyframe available in this direction')
|
if frame in self.interpolated_keys:
|
||||||
return {'CANCELLED'}
|
self.report({'INFO'}, f'SKIP {frame} (already interpolated)')
|
||||||
# print('self.frames_to_jump: ', self.frames_to_jump)
|
return {'RUNNING_MODAL'}
|
||||||
|
print(f'-> {frame}')
|
||||||
|
if self.report_progress:
|
||||||
|
context.window_manager.progress_update(frame) # Pgs
|
||||||
|
|
||||||
self.gp = context.object
|
## Interpolate function
|
||||||
|
self.interpolate_frame(context)
|
||||||
# matrix = np.array(self.gp.matrix_world, dtype='float64')
|
|
||||||
# origin = np.array(scn.camera.matrix_world.to_translation(), 'float64')
|
|
||||||
matrix = self.gp.matrix_world
|
|
||||||
origin = scn.camera.matrix_world.to_translation()
|
|
||||||
|
|
||||||
col = self.settings.target_collection
|
|
||||||
if not col:
|
|
||||||
col = scn.collection
|
|
||||||
|
|
||||||
# print('----')
|
|
||||||
if not self.gp.data.layers.active:
|
|
||||||
self.exit_modal(context, status='ERROR', text='No active layer')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
if not self.gp.data.layers.active.active_frame:
|
|
||||||
self.exit_modal(context, status='ERROR', text='No active frame')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
tgt_strokes = [s for s in self.gp.data.layers.active.active_frame.strokes if s.select]
|
|
||||||
|
|
||||||
## If nothing selected in sculpt/paint, Select all before triggering
|
|
||||||
if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
|
|
||||||
for s in self.gp.data.layers.active.active_frame.strokes:
|
|
||||||
s.select = True
|
|
||||||
tgt_strokes = self.gp.data.layers.active.active_frame.strokes
|
|
||||||
|
|
||||||
if not tgt_strokes:
|
|
||||||
self.exit_modal(context, status='ERROR', text='No stroke selected !')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
included_cols = [c.name for c in self.gp.users_collection]
|
|
||||||
target_obj = None
|
|
||||||
|
|
||||||
if self.settings.method == 'BONE':
|
|
||||||
if not self.settings.target_rig or not self.settings.target_bone:
|
|
||||||
self.exit_modal(context, status='ERROR', text='No Bone selected')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
included_cols.append('interpolation_tool')
|
|
||||||
|
|
||||||
## ensure collection and plane exists
|
|
||||||
# get/create collection
|
|
||||||
self.toolcol = bpy.data.collections.get('interpolation_tool')
|
|
||||||
if not self.toolcol:
|
|
||||||
self.toolcol = bpy.data.collections.new('interpolation_tool')
|
|
||||||
|
|
||||||
if self.toolcol.name not in bpy.context.scene.collection.children:
|
|
||||||
bpy.context.scene.collection.children.link(self.toolcol)
|
|
||||||
self.toolcol.hide_viewport = True # needed ?
|
|
||||||
|
|
||||||
# get/create meshplane
|
|
||||||
self.plane = bpy.data.objects.get('interpolation_plane')
|
|
||||||
if not self.plane:
|
|
||||||
self.plane = create_plane(name='interpolation_plane')
|
|
||||||
self.plane.select_set(False)
|
|
||||||
|
|
||||||
if self.plane.name not in self.toolcol.objects:
|
|
||||||
self.toolcol.objects.link(self.plane)
|
|
||||||
target_obj = self.plane
|
|
||||||
|
|
||||||
elif self.settings.method == 'GEOMETRY':
|
|
||||||
## Remove interpolation_plane collection ! (unseen, but can be hit)
|
|
||||||
if interp_plane := bpy.data.objects.get('interpolation_plane'):
|
|
||||||
bpy.data.objects.remove(interp_plane)
|
|
||||||
if interp_col := bpy.data.collections.get('interpolation_tool'):
|
|
||||||
bpy.data.collections.remove(interp_col)
|
|
||||||
|
|
||||||
if col != context.scene.collection:
|
|
||||||
included_cols.append(col.name)
|
|
||||||
## Maybe include a plane just behind geo ? probably bad idea
|
|
||||||
|
|
||||||
elif self.settings.method == 'OBJECT':
|
|
||||||
if not self.settings.target_object:
|
|
||||||
self.exit_modal(context, status='ERROR', text='No Object selected')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
col = scn.collection # Reset collection filter
|
|
||||||
target_obj = self.settings.target_object
|
|
||||||
if target_obj.library:
|
|
||||||
## Look if an override exists in scene to use instead of default object
|
|
||||||
if (override := next((o for o in scn.objects if o.name == target_obj.name and o.override_library), None)):
|
|
||||||
target_obj = override
|
|
||||||
|
|
||||||
## Prepare context manager
|
|
||||||
self.store_list = [
|
|
||||||
# (context.view_layer.objects, 'active', self.gp),
|
|
||||||
(context.tool_settings, 'use_keyframe_insert_auto', True),
|
|
||||||
# (bpy.context.scene.render, 'simplify_subdivision', 0),
|
|
||||||
]
|
|
||||||
|
|
||||||
# TODO: collection filter for GEOMETRY mode optimization
|
|
||||||
|
|
||||||
## Hide optimizations (safe for Bone Mode only, if no error)
|
|
||||||
# if self.settings.method == 'BONE':
|
|
||||||
# ## TEST: Add collections containing rig (cannot be excluded)
|
|
||||||
# # rig_parent_cols = [c.name for c in scn.collection.children_recursive if self.settings.target_rig.name in c.all_objects]
|
|
||||||
# # included_cols += rig_parent_cols
|
|
||||||
# for vlc in context.view_layer.layer_collection.children:
|
|
||||||
# self.store_list.append(
|
|
||||||
# # (vlc, 'exclude', vlc.name not in included_cols), # If excluded rig does not update !
|
|
||||||
# (vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz
|
|
||||||
# )
|
|
||||||
|
|
||||||
# print(f'Preparation {time()-start:.4f}s')
|
|
||||||
## Set everything in SETUP list
|
|
||||||
self.apply_and_store()
|
|
||||||
|
|
||||||
if self.settings.method == 'BONE':
|
|
||||||
## replace plane
|
|
||||||
_bone_plane = plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
|
|
||||||
arm=self.settings.target_rig,
|
|
||||||
set_rotation=self.settings.use_bone_rotation,
|
|
||||||
mesh=True)
|
|
||||||
|
|
||||||
## Set collection visibility
|
|
||||||
intercol = bpy.data.collections.get('interpolation_tool')
|
|
||||||
vl_col = bpy.context.view_layer.layer_collection.children.get(intercol.name)
|
|
||||||
intercol.hide_viewport = vl_col.exclude = vl_col.hide_viewport = False
|
|
||||||
|
|
||||||
# Override collection
|
|
||||||
col = intercol
|
|
||||||
|
|
||||||
dg = bpy.context.evaluated_depsgraph_get()
|
|
||||||
self.strokes_data = []
|
|
||||||
|
|
||||||
for si, stroke in enumerate(tgt_strokes):
|
|
||||||
nb_points = len(stroke.points)
|
|
||||||
|
|
||||||
local_co = np.empty(nb_points * 3, dtype='float64')
|
|
||||||
stroke.points.foreach_get('co', local_co)
|
|
||||||
# local_co_3d = local_co.reshape((nb_points, 3))
|
|
||||||
world_co_3d = matrix_transform(local_co.reshape((nb_points, 3)), matrix)
|
|
||||||
|
|
||||||
stroke_data = []
|
|
||||||
for i, point in enumerate(stroke.points):
|
|
||||||
point_co_world = world_co_3d[i]
|
|
||||||
if target_obj:
|
|
||||||
object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(point_co_world), origin, dg)
|
|
||||||
else:
|
|
||||||
# scene raycast
|
|
||||||
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
|
|
||||||
|
|
||||||
## Increasing search range
|
|
||||||
if not object_hit: # or object_hit not in col.all_objects[:]:
|
|
||||||
found = False
|
|
||||||
for iteration in range(1, 6):
|
|
||||||
for square_co in search_square(point_co_world, factor=self.settings.search_range * iteration):
|
|
||||||
|
|
||||||
if target_obj:
|
|
||||||
object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(square_co), origin, dg)
|
|
||||||
else:
|
|
||||||
# scene raycast
|
|
||||||
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
|
|
||||||
|
|
||||||
if object_hit:
|
|
||||||
## Get location coplanar with triangle
|
|
||||||
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
|
|
||||||
found = True
|
|
||||||
# print(f'{si}:{i} iteration {iteration}') # Dbg
|
|
||||||
break
|
|
||||||
|
|
||||||
if found:
|
|
||||||
break
|
|
||||||
|
|
||||||
if not found:
|
|
||||||
## /!\ ERROR ! No surface found!
|
|
||||||
# For debugging, select only problematic stroke (and point)
|
|
||||||
for sid, s in enumerate(tgt_strokes):
|
|
||||||
s.select = sid == si
|
|
||||||
for ip, p in enumerate(stroke.points):
|
|
||||||
p.select = ip == i
|
|
||||||
self.exit_modal(context, status='ERROR', text=f'Stroke {si} point {i} could not find underlying geometry')
|
|
||||||
return {'CANCELLED'}
|
|
||||||
|
|
||||||
stroke_data.append((stroke, point_co_world, object_hit, hit_location, tri, tri_indices))
|
|
||||||
|
|
||||||
self.strokes_data.append(stroke_data)
|
|
||||||
|
|
||||||
if self.debug:
|
|
||||||
self.scan_time = time()-self.start
|
|
||||||
print(f'Scan time {self.scan_time:.4f}s')
|
|
||||||
|
|
||||||
# Copy stroke selection
|
|
||||||
bpy.ops.gpencil.copy()
|
|
||||||
|
|
||||||
# Jump frame and paste
|
|
||||||
bpy.context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs
|
|
||||||
self.status = 'LOOP'
|
|
||||||
|
|
||||||
|
|
||||||
## -- LOOPTIMER
|
|
||||||
if event.type == 'TIMER':
|
|
||||||
|
|
||||||
if self.status == 'LOOP':
|
|
||||||
f = self.frames_to_jump[self.loop_count]
|
|
||||||
bpy.context.window_manager.progress_update(f) # Pgs
|
|
||||||
scn = bpy.context.scene
|
|
||||||
scn.frame_set(f)
|
|
||||||
origin = scn.camera.matrix_world.to_translation()
|
|
||||||
# origin = np.array(scn.camera.matrix_world.to_translation(), 'float64')
|
|
||||||
plan_co, plane_no = get_gp_draw_plane(self.gp)
|
|
||||||
bpy.ops.gpencil.paste()
|
|
||||||
|
|
||||||
if self.settings.method == 'BONE':
|
|
||||||
bone_plane = plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
|
|
||||||
arm=self.settings.target_rig,
|
|
||||||
set_rotation=self.settings.use_bone_rotation,
|
|
||||||
mesh=True)
|
|
||||||
|
|
||||||
dg = bpy.context.evaluated_depsgraph_get()
|
|
||||||
matrix_inv = np.array(self.gp.matrix_world.inverted(), dtype='float64')#.inverted()
|
|
||||||
new_strokes = self.gp.data.layers.active.active_frame.strokes[-len(self.strokes_data):]
|
|
||||||
|
|
||||||
# for new_stroke, stroke_data in zip(new_strokes, self.strokes_data):
|
|
||||||
for new_stroke, stroke_data in zip(reversed(new_strokes), reversed(self.strokes_data)):
|
|
||||||
world_co_3d = []
|
|
||||||
for stroke, point_co, object_hit, hit_location, tri_a, tri_indices in stroke_data:
|
|
||||||
eval_ob = object_hit.evaluated_get(dg)
|
|
||||||
tri_b = [eval_ob.data.vertices[i].co for i in tri_indices]
|
|
||||||
tri_b = matrix_transform(tri_b, eval_ob.matrix_world)
|
|
||||||
|
|
||||||
new_loc = barycentric_transform(hit_location, *tri_a, *tri_b)
|
|
||||||
# try:
|
|
||||||
# new_loc = barycentric_transform(hit_location, *tri_a, *tri_b)
|
|
||||||
# except Exception as e:
|
|
||||||
# print(f'\nCould not apply barycentric tranform {eval_ob.name}')
|
|
||||||
# print(e)
|
|
||||||
# # bpy.context.scene.cursor.location = hit_location
|
|
||||||
# self.report({'ERROR'}, f'Stroke {si} point {i} could not find underlying geometry')
|
|
||||||
# return {'CANCELLED'}
|
|
||||||
|
|
||||||
world_co_3d.append(new_loc)
|
|
||||||
|
|
||||||
## Test with point in 3D space (Debug)
|
|
||||||
# nb_points = len(new_stroke.points)
|
|
||||||
# new_stroke.points.foreach_set('co', np.array(world_co_3d).reshape(nb_points*3))
|
|
||||||
# new_stroke.points.update()
|
|
||||||
|
|
||||||
## Reproject on plane
|
|
||||||
new_world_co_3d = [intersect_line_plane(origin, p, plan_co, plane_no) for p in world_co_3d]
|
|
||||||
new_local_co_3d = matrix_transform(new_world_co_3d, matrix_inv)
|
|
||||||
|
|
||||||
nb_points = len(new_stroke.points)
|
|
||||||
new_stroke.points.foreach_set('co', new_local_co_3d.reshape(nb_points*3))
|
|
||||||
new_stroke.points.update()
|
|
||||||
|
|
||||||
|
|
||||||
## Occlusion management
|
|
||||||
if self.settings.method == 'GEOMETRY' and self.settings.remove_occluded:
|
|
||||||
viz_list = [True]*len(world_co_3d)
|
|
||||||
for i, nco in enumerate(world_co_3d):
|
|
||||||
vec_direction = nco - origin
|
|
||||||
## Reduced distance slightly to avoid occlusion on same source...
|
|
||||||
dist = vec_direction.length - 0.001
|
|
||||||
n_hit, _hit_location, _normal, _n_face_index, n_object_hit, _matrix = scn.ray_cast(dg, origin, vec_direction, distance=dist)
|
|
||||||
# if there is a hit, it's occluded
|
|
||||||
if n_hit:
|
|
||||||
viz_list[i] = False
|
|
||||||
|
|
||||||
if all(viz_list):
|
|
||||||
# All visible, do nothing (just keep previous stroke)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if any(viz_list):
|
|
||||||
# Create sub-strokes according to indices in original stroke
|
|
||||||
for sublist in index_list_from_bools(viz_list):
|
|
||||||
## Clear if only one isolated point ?
|
|
||||||
if len(sublist) == 1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
ns = self.gp.data.layers.active.active_frame.strokes.new()
|
|
||||||
for elem in ('hardness', 'material_index', 'line_width'):
|
|
||||||
setattr(ns, elem, getattr(new_stroke, elem))
|
|
||||||
|
|
||||||
ns.points.add(len(sublist))
|
|
||||||
for i, point_index in enumerate(sublist):
|
|
||||||
for elem in ('uv_factor', 'uv_fill', 'uv_rotation', 'pressure', 'co', 'strength', 'vertex_color'):
|
|
||||||
setattr(ns.points[i], elem, getattr(new_stroke.points[point_index], elem))
|
|
||||||
|
|
||||||
## Delete original stroke
|
|
||||||
self.gp.data.layers.active.active_frame.strokes.remove(new_stroke)
|
|
||||||
|
|
||||||
|
if self.interactive:
|
||||||
|
self.interpolated_keys.add(frame)
|
||||||
|
else:
|
||||||
self.loop_count += 1
|
self.loop_count += 1
|
||||||
if self.loop_count >= len(self.frames_to_jump):
|
if self.loop_count >= len(self.frames_to_jump):
|
||||||
self.exit_modal(context)
|
return self.exit(context)
|
||||||
return {'FINISHED'}
|
|
||||||
|
|
||||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
# bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
# context.area.tag_redraw()
|
|
||||||
|
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def interpolate_frame(self, context):
|
||||||
|
raise Exception('Not Implemented')
|
||||||
|
|
||||||
|
|
||||||
|
## Converted to modal from "operator_single"
|
||||||
|
|
||||||
|
class GP_OT_interpolate_stroke(GP_OT_interpolate_stroke_base):
|
||||||
|
bl_idname = "gp.interpolate_stroke"
|
||||||
|
bl_label = "Interpolate Stroke"
|
||||||
|
bl_description = 'Interpolate Stroke'
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
def iterative_search(self, context, obj, coord, origin, dg):
|
||||||
|
'''Search geometry for outside point (where raycast did not hit any geometry)
|
||||||
|
|
||||||
|
return :
|
||||||
|
object_hit, hit_location, tri, tri_indices.
|
||||||
|
None if nothing found
|
||||||
|
'''
|
||||||
|
|
||||||
|
for iteration in range(1, 10):
|
||||||
|
for square_co in search_square(coord, factor=self.settings.search_range * iteration):
|
||||||
|
|
||||||
|
if obj:
|
||||||
|
object_hit, hit_location, tri, tri_indices = obj_ray_cast(obj, square_co, origin, dg)
|
||||||
|
else:
|
||||||
|
object_hit, hit_location, tri, tri_indices = ray_cast_point(square_co, origin, dg)
|
||||||
|
|
||||||
|
if object_hit:
|
||||||
|
## On location coplanar with face triangle
|
||||||
|
# hit_location = intersect_line_plane(origin, coord, hit_location, triangle_normal(*tri))
|
||||||
|
|
||||||
|
## On view plane
|
||||||
|
view_vec = context.scene.camera.matrix_world.to_quaternion() @ Vector((0,0,1))
|
||||||
|
hit_location = intersect_line_plane(origin, coord, hit_location, view_vec)
|
||||||
|
|
||||||
|
## An average of the two ?
|
||||||
|
# hit_location_1 = intersect_line_plane(origin, coord, hit_location, triangle_normal(*tri))
|
||||||
|
# hit_location_2 = intersect_line_plane(origin, coord, hit_location, view_vec)
|
||||||
|
# hit_location = (hit_location_1 + hit_location_2) / 2
|
||||||
|
|
||||||
|
return object_hit, hit_location, tri, tri_indices
|
||||||
|
|
||||||
|
return None, None, None, None
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
if state := super().invoke(context, event):
|
||||||
|
return state
|
||||||
|
|
||||||
|
scn = context.scene
|
||||||
|
|
||||||
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
|
|
||||||
|
strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
if not strokes:
|
||||||
|
self.report({"ERROR"}, "No strokes selected")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
col = self.settings.target_collection
|
||||||
|
if not col:
|
||||||
|
col = scn.collection
|
||||||
|
|
||||||
|
included_cols = [c.name for c in self.gp.users_collection]
|
||||||
|
target_obj = None
|
||||||
|
|
||||||
|
## Setup depending on method
|
||||||
|
if self.settings.method == 'BONE':
|
||||||
|
if not self.settings.target_rig or not self.settings.target_bone:
|
||||||
|
return self.exit(context, status='ERROR', text='No Bone selected')
|
||||||
|
|
||||||
|
included_cols.append('interpolation_tool')
|
||||||
|
|
||||||
|
## Ensure collection and plane exists
|
||||||
|
# get/create collection
|
||||||
|
self.tool_col = bpy.data.collections.get('interpolation_tool')
|
||||||
|
if not self.tool_col:
|
||||||
|
self.tool_col = bpy.data.collections.new('interpolation_tool')
|
||||||
|
|
||||||
|
if self.tool_col.name not in bpy.context.scene.collection.children:
|
||||||
|
bpy.context.scene.collection.children.link(self.tool_col)
|
||||||
|
self.tool_col.hide_viewport = True # needed ?
|
||||||
|
|
||||||
|
# get/create meshplane
|
||||||
|
self.plane = bpy.data.objects.get('interpolation_plane')
|
||||||
|
if not self.plane:
|
||||||
|
self.plane = create_plane(name='interpolation_plane')
|
||||||
|
self.plane.select_set(False)
|
||||||
|
|
||||||
|
if self.plane.name not in self.tool_col.objects:
|
||||||
|
self.tool_col.objects.link(self.plane)
|
||||||
|
target_obj = self.plane
|
||||||
|
|
||||||
|
elif self.settings.method == 'GEOMETRY':
|
||||||
|
if col != context.scene.collection:
|
||||||
|
included_cols.append(col.name)
|
||||||
|
|
||||||
|
elif self.settings.method == 'OBJECT':
|
||||||
|
if not self.settings.target_object:
|
||||||
|
return self.exit(context, status='ERROR', text='No Object selected')
|
||||||
|
|
||||||
|
col = scn.collection # Reset collection filter
|
||||||
|
target_obj = self.settings.target_object
|
||||||
|
if target_obj.library:
|
||||||
|
## Look if an override exists in scene to use instead of default object
|
||||||
|
if (override := next((o for o in scn.objects if o.name == target_obj.name and o.override_library), None)):
|
||||||
|
target_obj = override
|
||||||
|
|
||||||
|
## Prepare context manager
|
||||||
|
attrs = [
|
||||||
|
# (context.view_layer.objects, 'active', self.gp),
|
||||||
|
(context.tool_settings, 'use_keyframe_insert_auto', True),
|
||||||
|
# (bpy.context.scene.render, 'simplify_subdivision', 0),
|
||||||
|
]
|
||||||
|
|
||||||
|
## Set everything in SETUP list
|
||||||
|
self.apply_and_store(attrs)
|
||||||
|
|
||||||
|
if self.settings.method == 'BONE':
|
||||||
|
## replace plane
|
||||||
|
_bone_plane = plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
|
||||||
|
arm=self.settings.target_rig,
|
||||||
|
set_rotation=self.settings.use_bone_rotation,
|
||||||
|
mesh=True)
|
||||||
|
|
||||||
|
## Set collection visibility
|
||||||
|
intercol = bpy.data.collections.get('interpolation_tool')
|
||||||
|
vl_col = bpy.context.view_layer.layer_collection.children.get(intercol.name)
|
||||||
|
intercol.hide_viewport = vl_col.exclude = vl_col.hide_viewport = False
|
||||||
|
|
||||||
|
## Override collection
|
||||||
|
col = intercol
|
||||||
|
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
self.strokes_data = []
|
||||||
|
|
||||||
|
for stroke_index, stroke in enumerate(strokes):
|
||||||
|
stroke_data = []
|
||||||
|
for point_index, point in enumerate(stroke.points):
|
||||||
|
point_co_world = self.gp.matrix_world @ point.co
|
||||||
|
|
||||||
|
if target_obj:
|
||||||
|
## Object raycast
|
||||||
|
object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, point_co_world, origin, dg)
|
||||||
|
else:
|
||||||
|
## Scene raycast
|
||||||
|
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
|
||||||
|
|
||||||
|
## Iterative increasing search range when no surface hit
|
||||||
|
if not object_hit:
|
||||||
|
object_hit, hit_location, tri, tri_indices = self.iterative_search(context, target_obj, point_co_world, origin, dg)
|
||||||
|
|
||||||
|
if not object_hit:
|
||||||
|
## /!\ ERROR ! No surface found!
|
||||||
|
# For debugging, select only point.
|
||||||
|
bpy.ops.gpencil.select_all(action='DESELECT')
|
||||||
|
point.select = True
|
||||||
|
return self.exit(context, status='ERROR', text=f'Stroke {stroke_index} point {point_index} could not find underlying geometry')
|
||||||
|
|
||||||
|
stroke_data.append((stroke, point_co_world, object_hit, hit_location, tri, tri_indices))
|
||||||
|
|
||||||
|
self.strokes_data.append(stroke_data)
|
||||||
|
|
||||||
|
if self.debug:
|
||||||
|
self.scan_time = time()-self.start
|
||||||
|
print(f'Scan time {self.scan_time:.4f}s')
|
||||||
|
|
||||||
|
# Copy stroke selection
|
||||||
|
bpy.ops.gpencil.select_linked() # Ensure whole stroke are selected before copy
|
||||||
|
bpy.ops.gpencil.copy()
|
||||||
|
|
||||||
|
context.window_manager.modal_handler_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def interpolate_frame(self, context):
|
||||||
|
scn = context.scene
|
||||||
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
|
plane_co, plane_no = get_gp_draw_plane(self.gp)
|
||||||
|
bpy.ops.gpencil.select_all(action='DESELECT')
|
||||||
|
bpy.ops.gpencil.paste(type='LAYER')
|
||||||
|
|
||||||
|
if self.settings.method == 'BONE':
|
||||||
|
## Set plane on the bone
|
||||||
|
plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
|
||||||
|
arm=self.settings.target_rig,
|
||||||
|
set_rotation=self.settings.use_bone_rotation,
|
||||||
|
mesh=True)
|
||||||
|
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
|
||||||
|
## Get pasted stroke
|
||||||
|
#new_strokes = [s for s in self.gp.data.layers.active.active_frame.strokes if s.select]
|
||||||
|
new_strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
## Keep reference to all accessible other strokes (in all accessible layer)
|
||||||
|
other_strokes = [s for l in self.gp.data.layers if l.active_frame and not l.lock for s in l.active_frame.strokes if not s.select]
|
||||||
|
|
||||||
|
smooth_level = self.settings.smooth_level
|
||||||
|
|
||||||
|
occluded_points = []
|
||||||
|
for new_stroke, stroke_data in zip(list(new_strokes), list(self.strokes_data)):
|
||||||
|
world_co_3d = []
|
||||||
|
for stroke, point_co, object_hit, hit_location, tri_a, tri_indices in stroke_data:
|
||||||
|
eval_ob = object_hit.evaluated_get(dg)
|
||||||
|
tri_b = [eval_ob.matrix_world @ eval_ob.data.vertices[i].co for i in tri_indices]
|
||||||
|
|
||||||
|
new_loc = barycentric_transform(hit_location, *tri_a, *tri_b)
|
||||||
|
world_co_3d.append(new_loc)
|
||||||
|
|
||||||
|
# Smooth points
|
||||||
|
if smooth_level:
|
||||||
|
old_co_3d = [s[1] for s in stroke_data]
|
||||||
|
points_velocity = [b-a for a, b in zip(old_co_3d, world_co_3d)]
|
||||||
|
|
||||||
|
# Average of points
|
||||||
|
for i in range(smooth_level + 1):
|
||||||
|
points_velocity = [
|
||||||
|
(points_velocity[i] + points_velocity[i + 1]) / 2 if i == 0 else
|
||||||
|
(points_velocity[i] + points_velocity[i - 1]) / 2 if i == len(points_velocity) - 1 else
|
||||||
|
(points_velocity[i - 1] + points_velocity[i] + points_velocity[i + 1]) / 3
|
||||||
|
for i in range(len(points_velocity))
|
||||||
|
]
|
||||||
|
|
||||||
|
world_co_3d = [a+b for a, b in zip(old_co_3d, points_velocity)]
|
||||||
|
|
||||||
|
## Reproject on plane
|
||||||
|
new_world_co_3d = [intersect_line_plane(origin, p, plane_co, plane_no) for p in world_co_3d]
|
||||||
|
new_local_co_3d = [co for coord in new_world_co_3d for co in self.gp.matrix_world.inverted() @ coord]
|
||||||
|
new_stroke.points.foreach_set('co', new_local_co_3d)
|
||||||
|
new_stroke.points.update()
|
||||||
|
|
||||||
|
## Occlusion management
|
||||||
|
if self.settings.method == 'GEOMETRY' and self.settings.remove_occluded:
|
||||||
|
for i, point in enumerate(new_stroke.points):
|
||||||
|
point_co = world_co_3d[i]
|
||||||
|
vec_direction = point_co - origin
|
||||||
|
## Raycast with slightly reduced distance (avoid occlusion on initial surface)
|
||||||
|
n_hit, _, _, _, _, _ = scn.ray_cast(dg, origin, vec_direction, distance=vec_direction.length - 0.001)
|
||||||
|
if n_hit:
|
||||||
|
occluded_points.append(point)
|
||||||
|
|
||||||
|
if occluded_points:
|
||||||
|
## Select only occluded point
|
||||||
|
bpy.ops.gpencil.select_all(action='DESELECT')
|
||||||
|
for point in occluded_points:
|
||||||
|
point.select = True
|
||||||
|
## remove points
|
||||||
|
bpy.ops.gpencil.delete(type='POINTS')
|
||||||
|
|
||||||
|
## restore selection (keep new strokes selected)
|
||||||
|
bpy.ops.gpencil.select_all(action='SELECT')
|
||||||
|
for stroke in other_strokes:
|
||||||
|
stroke.select = False
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
GP_OT_interpolate_stroke,
|
GP_OT_interpolate_stroke,
|
||||||
|
GP_OT_pick_collection
|
||||||
)
|
)
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
# context.tool_settings.use_keyframe_insert_auto = True
|
# context.tool_settings.use_keyframe_insert_auto = True
|
||||||
|
|
||||||
## Determine on what key/keys to jump
|
## Determine on what key/keys to jump
|
||||||
frames_to_jump = following_keys(forward=self.next, all_keys=settings.use_animation)
|
frames_to_jump = following_keys(forward=self.next, animation=settings.use_animation)
|
||||||
if not len(frames_to_jump):
|
if not len(frames_to_jump):
|
||||||
self.report({'WARNING'}, 'No keyframe available in this direction')
|
self.report({'WARNING'}, 'No keyframe available in this direction')
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
@@ -78,7 +78,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
|
|
||||||
# print('----')
|
# print('----')
|
||||||
|
|
||||||
tgt_strokes = [s for s in gp.data.layers.active.active_frame.strokes if s.select]
|
tgt_strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
|
||||||
## If nothing selected in sculpt/paint, Select all before triggering
|
## If nothing selected in sculpt/paint, Select all before triggering
|
||||||
if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
|
if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
|
||||||
@@ -247,7 +247,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
origin = scn.camera.matrix_world.to_translation()
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
# origin = np.array(scn.camera.matrix_world.to_translation(), 'float64')
|
# origin = np.array(scn.camera.matrix_world.to_translation(), 'float64')
|
||||||
plan_co, plane_no = get_gp_draw_plane(gp)
|
plan_co, plane_no = get_gp_draw_plane(gp)
|
||||||
bpy.ops.gpencil.paste()
|
bpy.ops.gpencil.paste(type="LAYER")
|
||||||
|
|
||||||
if settings.method == 'BONE':
|
if settings.method == 'BONE':
|
||||||
bone_plane = plane_on_bone(settings.target_rig.pose.bones.get(settings.target_bone),
|
bone_plane = plane_on_bone(settings.target_rig.pose.bones.get(settings.target_bone),
|
||||||
@@ -257,10 +257,10 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
|
|
||||||
dg = bpy.context.evaluated_depsgraph_get()
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
matrix_inv = np.array(gp.matrix_world.inverted(), dtype='float64')#.inverted()
|
matrix_inv = np.array(gp.matrix_world.inverted(), dtype='float64')#.inverted()
|
||||||
new_strokes = gp.data.layers.active.active_frame.strokes[-len(strokes_data):]
|
new_strokes = [(l, s) for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
|
||||||
# for new_stroke, stroke_data in zip(new_strokes, strokes_data):
|
# for new_stroke, stroke_data in zip(new_strokes, strokes_data):
|
||||||
for new_stroke, stroke_data in zip(reversed(new_strokes), reversed(strokes_data)):
|
for (layer, new_stroke), stroke_data in zip(reversed(new_strokes), reversed(strokes_data)):
|
||||||
world_co_3d = []
|
world_co_3d = []
|
||||||
for stroke, point_co, object_hit, hit_location, tri_a, tri_indices in stroke_data:
|
for stroke, point_co, object_hit, hit_location, tri_a, tri_indices in stroke_data:
|
||||||
eval_ob = object_hit.evaluated_get(dg)
|
eval_ob = object_hit.evaluated_get(dg)
|
||||||
@@ -316,7 +316,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
if len(sublist) == 1:
|
if len(sublist) == 1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ns = gp.data.layers.active.active_frame.strokes.new()
|
ns = layer.active_frame.strokes.new()
|
||||||
for elem in ('hardness', 'material_index', 'line_width'):
|
for elem in ('hardness', 'material_index', 'line_width'):
|
||||||
setattr(ns, elem, getattr(new_stroke, elem))
|
setattr(ns, elem, getattr(new_stroke, elem))
|
||||||
|
|
||||||
@@ -326,7 +326,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
|
|||||||
setattr(ns.points[i], elem, getattr(new_stroke.points[point_index], elem))
|
setattr(ns.points[i], elem, getattr(new_stroke.points[point_index], elem))
|
||||||
|
|
||||||
## Delete original stroke
|
## Delete original stroke
|
||||||
gp.data.layers.active.active_frame.strokes.remove(new_stroke)
|
layer.active_frame.strokes.remove(new_stroke)
|
||||||
|
|
||||||
wm.progress_end() # Pgs
|
wm.progress_end() # Pgs
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import bpy
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
from mathutils.geometry import (barycentric_transform,
|
||||||
|
intersect_line_plane)
|
||||||
|
|
||||||
|
from ..utils import (triangle_normal,
|
||||||
|
get_gp_draw_plane)
|
||||||
|
|
||||||
|
from .operators import GP_OT_interpolate_stroke_base
|
||||||
|
|
||||||
|
|
||||||
|
class GP_OT_interpolate_stroke_tri(GP_OT_interpolate_stroke_base):
|
||||||
|
bl_idname = "gp.interpolate_stroke_tri"
|
||||||
|
bl_label = "Interpolate Stroke"
|
||||||
|
bl_description = 'Interpolate Stroke based on user bound triangle'
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
if state := super().invoke(context, event):
|
||||||
|
return state
|
||||||
|
|
||||||
|
if not context.window_manager.get(f'tri_{self.gp.name}'):
|
||||||
|
return self.exit(context, status='ERROR', text='Need to bind coordinate first. Use "Bind Tri Point" button')
|
||||||
|
|
||||||
|
scn = bpy.context.scene
|
||||||
|
|
||||||
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
|
|
||||||
|
## Prepare context manager
|
||||||
|
attrs = [
|
||||||
|
# (context.view_layer.objects, 'active', self.gp),
|
||||||
|
(context.tool_settings, 'use_keyframe_insert_auto', True),
|
||||||
|
# (bpy.context.scene.render, 'simplify_subdivision', 0),
|
||||||
|
]
|
||||||
|
self.apply_and_store(attrs)
|
||||||
|
|
||||||
|
point_dict = context.window_manager.get(f'tri_{self.gp.name}')
|
||||||
|
## point_dict -> {'0': {'object': object_name_as_str, 'index': 450}, ...}
|
||||||
|
## Get triangle dumped in context.window_manager
|
||||||
|
self.source_object_list = [bpy.context.scene.objects.get(point_dict[str(i)]['object']) for i in range(3)]
|
||||||
|
self.source_tri_indices = [point_dict[str(i)]['index'] for i in range(3)] # List of vertices index corresponding to tri coordinates
|
||||||
|
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
|
||||||
|
## Get tri at source frame
|
||||||
|
tri = []
|
||||||
|
for source_obj, idx in zip(self.source_object_list, self.source_tri_indices):
|
||||||
|
ob_eval = source_obj.evaluated_get(dg)
|
||||||
|
tri.append(ob_eval.matrix_world @ ob_eval.data.vertices[idx].co)
|
||||||
|
|
||||||
|
self.strokes_data = []
|
||||||
|
|
||||||
|
for stroke in self.strokes:
|
||||||
|
stroke_data = []
|
||||||
|
for point in stroke.points:
|
||||||
|
point_co_world = self.gp.matrix_world @ point.co
|
||||||
|
|
||||||
|
## Set hit location at same coordinate as point
|
||||||
|
# hit_location = point_co_world
|
||||||
|
|
||||||
|
## Set hit location on tri plane
|
||||||
|
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
|
||||||
|
|
||||||
|
stroke_data.append((hit_location, tri))
|
||||||
|
|
||||||
|
self.strokes_data.append(stroke_data)
|
||||||
|
|
||||||
|
if self.debug:
|
||||||
|
self.scan_time = time()-self.start
|
||||||
|
print(f'Scan time {self.scan_time:.4f}s')
|
||||||
|
|
||||||
|
# Ensure whole stroke are selected before copy
|
||||||
|
bpy.ops.gpencil.select_linked()
|
||||||
|
# Copy stroke selection
|
||||||
|
bpy.ops.gpencil.copy()
|
||||||
|
|
||||||
|
# Jump frame and paste
|
||||||
|
# if self.report_progress:
|
||||||
|
# context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs
|
||||||
|
# context.area.header_text_set('Starting interpolation | Esc: Cancel')
|
||||||
|
|
||||||
|
context.window_manager.modal_handler_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def interpolate_frame(self, context):
|
||||||
|
scn = context.scene
|
||||||
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
|
plane_co, plane_no = get_gp_draw_plane(self.gp)
|
||||||
|
bpy.ops.gpencil.paste(type='LAYER')
|
||||||
|
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
|
||||||
|
## List of newly pasted strokes (using range)
|
||||||
|
new_strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
#new_strokes = self.gp.data.layers.active.active_frame.strokes[-len(self.strokes_data):]
|
||||||
|
|
||||||
|
## Get user triangle position at current frame
|
||||||
|
tri_b = []
|
||||||
|
for source_obj, idx in zip(self.source_object_list, self.source_tri_indices):
|
||||||
|
ob_eval = source_obj.evaluated_get(dg)
|
||||||
|
tri_b.append(ob_eval.matrix_world @ ob_eval.data.vertices[idx].co)
|
||||||
|
|
||||||
|
for new_stroke, stroke_data in zip(list(new_strokes), list(self.strokes_data)):
|
||||||
|
world_co_3d = []
|
||||||
|
for hit_location, tri_a in stroke_data:
|
||||||
|
new_loc = barycentric_transform(hit_location, *tri_a, *tri_b)
|
||||||
|
world_co_3d.append(new_loc)
|
||||||
|
|
||||||
|
## Reproject on plane
|
||||||
|
new_world_co_3d = [intersect_line_plane(origin, p, plane_co, plane_no) for p in world_co_3d]
|
||||||
|
new_local_co_3d = [co for coord in new_world_co_3d for co in self.gp.matrix_world.inverted() @ coord]
|
||||||
|
new_stroke.points.foreach_set('co', new_local_co_3d)
|
||||||
|
new_stroke.points.update()
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
GP_OT_interpolate_stroke_tri,
|
||||||
|
)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in reversed(classes):
|
||||||
|
bpy.utils.unregister_class(c)
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
import bpy
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
#from bpy_extras.object_utils import world_to_camera_view
|
||||||
|
from mathutils import Vector
|
||||||
|
from mathutils.kdtree import KDTree
|
||||||
|
from math import tan
|
||||||
|
|
||||||
|
|
||||||
|
from mathutils.geometry import (barycentric_transform,
|
||||||
|
intersect_line_plane)
|
||||||
|
|
||||||
|
from ..utils import (triangle_normal,
|
||||||
|
get_gp_draw_plane, load_datablock)
|
||||||
|
|
||||||
|
from ..constants import RESOURCES_DIR
|
||||||
|
from .operators import GP_OT_interpolate_stroke_base
|
||||||
|
|
||||||
|
|
||||||
|
def world_to_camera_view(scene, obj, coord):
|
||||||
|
"""
|
||||||
|
Returns the camera space coords for a 3d point.
|
||||||
|
(also known as: normalized device coordinates - NDC).
|
||||||
|
|
||||||
|
Where (0, 0) is the bottom left and (1, 1)
|
||||||
|
is the top right of the camera frame.
|
||||||
|
values outside 0-1 are also supported.
|
||||||
|
A negative 'z' value means the point is behind the camera.
|
||||||
|
|
||||||
|
Takes shift-x/y, lens angle and sensor size into account
|
||||||
|
as well as perspective/ortho projections.
|
||||||
|
|
||||||
|
:arg scene: Scene to use for frame size.
|
||||||
|
:type scene: :class:`bpy.types.Scene`
|
||||||
|
:arg obj: Camera object.
|
||||||
|
:type obj: :class:`bpy.types.Object`
|
||||||
|
:arg coord: World space location.
|
||||||
|
:type coord: :class:`mathutils.Vector`
|
||||||
|
:return: a vector where X and Y map to the view plane and
|
||||||
|
Z is the depth on the view axis.
|
||||||
|
:rtype: :class:`mathutils.Vector`
|
||||||
|
"""
|
||||||
|
from mathutils import Vector
|
||||||
|
|
||||||
|
co_local = obj.matrix_world.normalized().inverted() @ coord
|
||||||
|
z = -co_local.z
|
||||||
|
|
||||||
|
camera = obj.data
|
||||||
|
frame = [v for v in camera.view_frame(scene=scene)[:3]]
|
||||||
|
if camera.type != 'ORTHO':
|
||||||
|
if z == 0.0:
|
||||||
|
return Vector((0.5, 0.5, 0.0))
|
||||||
|
else:
|
||||||
|
frame = [-(v / (v.z / z)) for v in frame]
|
||||||
|
|
||||||
|
min_x, max_x = frame[2].x, frame[1].x
|
||||||
|
min_y, max_y = frame[1].y, frame[0].y
|
||||||
|
|
||||||
|
x = (co_local.x - min_x) / (max_x - min_x)
|
||||||
|
y = (co_local.y - min_y) / (max_y - min_y)
|
||||||
|
|
||||||
|
return Vector((x, y, z))
|
||||||
|
|
||||||
|
def camera_view_to_world(scene, obj, coord):
|
||||||
|
"""Reverse function of world_to_camera_view"""
|
||||||
|
|
||||||
|
frame = [obj.matrix_world @ co for co in obj.data.view_frame(scene=scene)]
|
||||||
|
|
||||||
|
x, y, z = coord
|
||||||
|
|
||||||
|
right_interp = frame[1] + y * (frame[0] - frame[1])
|
||||||
|
# Interpolate along x-axis (left side)
|
||||||
|
left_interp = frame[2] + y * (frame[3] - frame[2])
|
||||||
|
|
||||||
|
# Interpolate along y-axis
|
||||||
|
return Vector(left_interp + x * (right_interp - left_interp))
|
||||||
|
|
||||||
|
|
||||||
|
class GP_OT_interpolate_stroke_velocity(GP_OT_interpolate_stroke_base):
|
||||||
|
bl_idname = "gp.interpolate_stroke_velocity"
|
||||||
|
bl_label = "Interpolate Stroke"
|
||||||
|
bl_description = 'Interpolate Stroke based on velocity'
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
if state := super().invoke(context, event):
|
||||||
|
return state
|
||||||
|
|
||||||
|
if not self.settings.target_object and not self.settings.target_collection:
|
||||||
|
self.report({"ERROR"}, "No collection of object specified")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
scn = bpy.context.scene
|
||||||
|
settings = context.scene.gp_interpo_settings
|
||||||
|
|
||||||
|
## Prepare context manager
|
||||||
|
attrs = [
|
||||||
|
# (context.view_layer.objects, 'active', self.gp),
|
||||||
|
(context.tool_settings, 'use_keyframe_insert_auto', True),
|
||||||
|
# (bpy.context.scene.render, 'simplify_subdivision', 0),
|
||||||
|
]
|
||||||
|
self.apply_and_store(attrs)
|
||||||
|
|
||||||
|
velocity_mesh = bpy.data.meshes.new('interpolate_velocity')
|
||||||
|
velocity_ob = bpy.data.objects.new('interpolate_velocity', velocity_mesh)
|
||||||
|
|
||||||
|
self.velocity_node_group = load_datablock(RESOURCES_DIR/'nodes.blend', 'Velocity Grid', type='node_groups', link=False)
|
||||||
|
|
||||||
|
instance_col_mod = velocity_ob.modifiers.new('IngestCollection', 'NODES')
|
||||||
|
ingest_node_group = load_datablock(RESOURCES_DIR/'nodes.blend', 'Ingest Collection', type='node_groups', link=False)
|
||||||
|
instance_col_mod.node_group = ingest_node_group
|
||||||
|
instance_col_mod["Socket_3"] = settings.target_object
|
||||||
|
instance_col_mod["Socket_2"] = settings.target_collection
|
||||||
|
|
||||||
|
scn.collection.objects.link(velocity_ob)
|
||||||
|
|
||||||
|
# Apply instance collection modifier
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
eval_ob = velocity_ob.evaluated_get(dg)
|
||||||
|
eval_data = eval_ob.data.copy()
|
||||||
|
|
||||||
|
velocity_ob.modifiers.remove(instance_col_mod)
|
||||||
|
velocity_ob.data = eval_data
|
||||||
|
|
||||||
|
bpy.data.node_groups.remove(ingest_node_group)
|
||||||
|
|
||||||
|
self.velocity_ob = velocity_ob
|
||||||
|
|
||||||
|
if self.debug:
|
||||||
|
self.scan_time = time()-self.start
|
||||||
|
print(f'Scan time {self.scan_time:.4f}s')
|
||||||
|
|
||||||
|
# Baking Camera
|
||||||
|
self.camera = scn.camera.copy()
|
||||||
|
self.camera.data = self.camera.data.copy()
|
||||||
|
self.camera.animation_data_clear()
|
||||||
|
self.camera.data.animation_data_clear()
|
||||||
|
|
||||||
|
cam_mat = self.camera.matrix_world.copy()
|
||||||
|
self.camera.animation_data_clear()
|
||||||
|
self.camera.parent = None
|
||||||
|
self.camera.matrix_world = cam_mat
|
||||||
|
|
||||||
|
# Store curent gp matrix
|
||||||
|
self.gp_matrix = self.gp.matrix_world.copy()
|
||||||
|
|
||||||
|
# Ensure whole stroke are selected before copy
|
||||||
|
|
||||||
|
bpy.ops.gpencil.select_linked()
|
||||||
|
# Copy stroke selection
|
||||||
|
bpy.ops.gpencil.copy()
|
||||||
|
|
||||||
|
# Jump frame and paste
|
||||||
|
# if self.report_progress:
|
||||||
|
# context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs
|
||||||
|
# context.area.header_text_set('Starting interpolation | Esc: Cancel')
|
||||||
|
|
||||||
|
context.window_manager.modal_handler_add(self)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
def interpolate_frame(self, context):
|
||||||
|
scn = context.scene
|
||||||
|
cam = scn.camera
|
||||||
|
#dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
target_object = self.settings.target_object
|
||||||
|
target_col = self.settings.target_collection
|
||||||
|
smooth_level = self.settings.smooth_level
|
||||||
|
|
||||||
|
origin = scn.camera.matrix_world.to_translation()
|
||||||
|
plane_co, plane_no = get_gp_draw_plane(self.gp)
|
||||||
|
|
||||||
|
velocity_ob = self.velocity_ob
|
||||||
|
velocity_ob.hide_set(True)
|
||||||
|
|
||||||
|
grid_velocity_mod = velocity_ob.modifiers.new('VelocityGrid', 'NODES')
|
||||||
|
grid_velocity_mod.node_group = self.velocity_node_group
|
||||||
|
grid_velocity_mod["Socket_8"] = target_object
|
||||||
|
grid_velocity_mod["Socket_2"] = target_col
|
||||||
|
grid_velocity_mod["Socket_4"] = self.camera
|
||||||
|
grid_velocity_mod["Socket_5"] = self.camera.data.angle
|
||||||
|
grid_velocity_mod["Socket_6"] = self.camera.data.shift_x
|
||||||
|
grid_velocity_mod["Socket_7"] = self.camera.data.shift_y
|
||||||
|
|
||||||
|
# Apply velocity grid modifier
|
||||||
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
eval_ob = velocity_ob.evaluated_get(dg)
|
||||||
|
#eval_data = eval_ob.data.copy()
|
||||||
|
grid_ob = bpy.data.objects.new('Velocity Grid Object', eval_ob.data.copy())
|
||||||
|
|
||||||
|
# copy_ob = velocity_ob.copy()
|
||||||
|
# copy_ob.data = copy_ob.data.copy()
|
||||||
|
# scn.collection.objects.link(copy_ob)
|
||||||
|
|
||||||
|
velocity_ob.modifiers.remove(grid_velocity_mod)
|
||||||
|
|
||||||
|
#Create kd tree for finding nearest points
|
||||||
|
kd = KDTree(len(grid_ob.data.vertices))
|
||||||
|
|
||||||
|
points = [0, 0, 0] * len(grid_ob.data.vertices)
|
||||||
|
grid_ob.data.vertices.foreach_get('co', points)
|
||||||
|
|
||||||
|
for i in range(0, len(points), 3):
|
||||||
|
kd.insert(points[i:i+3], int(i/3))
|
||||||
|
|
||||||
|
kd.balance()
|
||||||
|
|
||||||
|
bpy.ops.gpencil.paste(type='LAYER')
|
||||||
|
|
||||||
|
## List of newly pasted strokes (using range)
|
||||||
|
new_strokes = [s for l in self.layers for s in l.active_frame.strokes if s.select]
|
||||||
|
|
||||||
|
velocity_attr = grid_ob.data.attributes["velocity"].data
|
||||||
|
|
||||||
|
for stroke in new_strokes:
|
||||||
|
points = [0, 0, 0] * len(stroke.points)
|
||||||
|
stroke.points.foreach_get('co', points)
|
||||||
|
|
||||||
|
points_2d = [world_to_camera_view(scn, self.camera, self.gp_matrix @ Vector(points[i:i+3])) for i in range(0, len(points), 3)]
|
||||||
|
points_2d = [Vector((p.x, p.y, 0)) for p in points_2d] # Remove Z component
|
||||||
|
|
||||||
|
points_velocity = [velocity_attr[kd.find(p)[1]].vector for p in points_2d]
|
||||||
|
|
||||||
|
if smooth_level:
|
||||||
|
# Average of points
|
||||||
|
for i in range(smooth_level + 1):
|
||||||
|
points_velocity = [
|
||||||
|
(points_velocity[i] + points_velocity[i + 1]) / 2 if i == 0 else
|
||||||
|
(points_velocity[i] + points_velocity[i - 1]) / 2 if i == len(points_velocity) - 1 else
|
||||||
|
(points_velocity[i - 1] + points_velocity[i] + points_velocity[i + 1]) / 3
|
||||||
|
for i in range(len(points_velocity))
|
||||||
|
]
|
||||||
|
|
||||||
|
new_points_3d = [camera_view_to_world(scn, cam, p+vel) for p, vel in zip(points_2d, points_velocity)]
|
||||||
|
|
||||||
|
## Reproject on plane
|
||||||
|
new_points_3d = [intersect_line_plane(origin, p, plane_co, plane_no) for p in new_points_3d]
|
||||||
|
|
||||||
|
stroke.points.foreach_set('co', [v for p in new_points_3d for v in self.gp.matrix_world.inverted() @p])
|
||||||
|
|
||||||
|
#new_points_2d = [ p+vel for p, vel in zip(points_2d, points_velocity)]
|
||||||
|
#stroke.points.foreach_set('co', [v for p in new_points_2d for v in self.gp.matrix_world.inverted() @p])
|
||||||
|
stroke.points.update()
|
||||||
|
|
||||||
|
bpy.data.meshes.remove(grid_ob.data)
|
||||||
|
|
||||||
|
def exit(self, context, status='INFO', text=None, cancelled=False):
|
||||||
|
out = super().exit(context, status='INFO', text=None, cancelled=False)
|
||||||
|
|
||||||
|
bpy.data.node_groups.remove(self.velocity_node_group)
|
||||||
|
bpy.data.meshes.remove(self.velocity_ob.data)
|
||||||
|
bpy.data.cameras.remove(self.camera.data)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
GP_OT_interpolate_stroke_velocity,
|
||||||
|
)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for c in classes:
|
||||||
|
bpy.utils.register_class(c)
|
||||||
|
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for c in reversed(classes):
|
||||||
|
bpy.utils.unregister_class(c)
|
||||||
@@ -17,11 +17,13 @@ class GP_PG_interpolate_settings(PropertyGroup):
|
|||||||
method : EnumProperty(
|
method : EnumProperty(
|
||||||
name='Method',
|
name='Method',
|
||||||
items= (
|
items= (
|
||||||
('GEOMETRY', 'Geometry', 'Directly follow underlying geometry', 0),
|
('VELOCITY', 'Velocity', 'Interpolate based on velocity, works well for point outside geometry', 0),
|
||||||
('BONE', 'Bone', 'Pick an armature bone and follow it', 1),
|
('GEOMETRY', 'Geometry', 'Directly follow underlying geometry', 1),
|
||||||
('OBJECT', 'Object', 'Directly follow a specific object, even if occluded', 2),
|
('OBJECT', 'Object Geometry', 'Same as Geometry mode, but target only a specific object, even if occluded (ignore all the others)', 2),
|
||||||
|
('BONE', 'Bone', 'Pick an armature bone and follow it', 3),
|
||||||
|
('TRI', 'Triangle', 'Interpolate based on triangle traced manually over geometry', 4)
|
||||||
),
|
),
|
||||||
default='GEOMETRY',
|
default='VELOCITY',
|
||||||
description='Select method for interpolating strokes'
|
description='Select method for interpolating strokes'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ class GP_PG_interpolate_settings(PropertyGroup):
|
|||||||
name='Mode',
|
name='Mode',
|
||||||
# Combined ?markers ?
|
# Combined ?markers ?
|
||||||
items= (
|
items= (
|
||||||
('FRAME', 'Frame', 'prev/next scene frame depending on the padding options', 0),
|
('FRAME', 'Frame', 'prev/next scene frame depending on the step options', 0),
|
||||||
('GPKEY', 'GP Key', 'prev/next Grease pencil key', 1) ,
|
('GPKEY', 'GP Key', 'prev/next Grease pencil key', 1) ,
|
||||||
('RIGKEY', 'Rig Key', 'prev/next armatures keys in targeted collection (camera keys are included)', 2),
|
('RIGKEY', 'Rig Key', 'prev/next armatures keys in targeted collection (camera keys are included)', 2),
|
||||||
),
|
),
|
||||||
@@ -51,7 +53,7 @@ class GP_PG_interpolate_settings(PropertyGroup):
|
|||||||
description='Select how the previous or next frame should be chosen'
|
description='Select how the previous or next frame should be chosen'
|
||||||
)
|
)
|
||||||
|
|
||||||
padding : IntProperty(name='Padding',
|
step : IntProperty(name='Step',
|
||||||
description='Number of frame to jump backward or forward',
|
description='Number of frame to jump backward or forward',
|
||||||
default=2,
|
default=2,
|
||||||
min=1)
|
min=1)
|
||||||
@@ -82,6 +84,11 @@ class GP_PG_interpolate_settings(PropertyGroup):
|
|||||||
default=True,
|
default=True,
|
||||||
description='Apply rotation of the bone') # Bone
|
description='Apply rotation of the bone') # Bone
|
||||||
|
|
||||||
|
#selection: EnumProperty(default='SELECTED', items=[("SELECTED", "Selected", ""), ("ALL", "All", "")],
|
||||||
|
# description="Stroke to interpolate")
|
||||||
|
|
||||||
|
smooth_level: IntProperty(default=2, min=0, max=20, name='Smooth Level')
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
GP_PG_interpolate_settings,
|
GP_PG_interpolate_settings,
|
||||||
)
|
)
|
||||||
|
|||||||
Binary file not shown.
@@ -15,6 +15,7 @@ class GP_PT_interpolate(bpy.types.Panel):
|
|||||||
|
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
layout.use_property_split = True
|
layout.use_property_split = True
|
||||||
|
layout.use_property_decorate = False
|
||||||
col = layout.column(align=False)
|
col = layout.column(align=False)
|
||||||
|
|
||||||
## Interpolation buttons
|
## Interpolation buttons
|
||||||
@@ -31,11 +32,24 @@ class GP_PT_interpolate(bpy.types.Panel):
|
|||||||
prev_text = f'{scn.frame_preview_start if scn.use_preview_range else scn.frame_start} < {scn.frame_current}'
|
prev_text = f'{scn.frame_preview_start if scn.use_preview_range else scn.frame_start} < {scn.frame_current}'
|
||||||
next_text = f'{scn.frame_current} > {scn.frame_preview_end if scn.use_preview_range else scn.frame_end}'
|
next_text = f'{scn.frame_current} > {scn.frame_preview_end if scn.use_preview_range else scn.frame_end}'
|
||||||
|
|
||||||
|
|
||||||
row = col.row(align=True)
|
row = col.row(align=True)
|
||||||
row.scale_x = 3
|
row.scale_y = 1.2
|
||||||
row.operator("gp.interpolate_stroke", text=prev_text, icon=prev_icon).next = False
|
direction_button_row = row.row(align=True)
|
||||||
row.operator("gp.interpolate_stroke", text=next_text, icon=next_icon).next = True
|
direction_button_row.scale_x = 3
|
||||||
|
ops_id = "gp.interpolate_stroke"
|
||||||
|
if settings.method == 'TRI':
|
||||||
|
ops_id = "gp.interpolate_stroke_tri"
|
||||||
|
elif settings.method == 'VELOCITY':
|
||||||
|
ops_id = "gp.interpolate_stroke_velocity"
|
||||||
|
|
||||||
|
|
||||||
|
direction_button_row.operator(ops_id, text=prev_text, icon=prev_icon).next = False
|
||||||
|
direction_button_row.operator(ops_id, text=next_text, icon=next_icon).next = True
|
||||||
|
|
||||||
|
## Button for interactive mode (icons: SNAP_INCREMENT, ACTION_TWEAK, CON_ACTION, CENTER_ONLY)
|
||||||
|
interactive_mode_row = row.row()
|
||||||
|
interactive_mode_row.operator(ops_id, text='', icon='ACTION_TWEAK').interactive = True
|
||||||
|
|
||||||
|
|
||||||
col.prop(settings, 'use_animation', text='Animation')
|
col.prop(settings, 'use_animation', text='Animation')
|
||||||
col.prop(settings, 'method', text='Method')
|
col.prop(settings, 'method', text='Method')
|
||||||
@@ -51,9 +65,20 @@ class GP_PT_interpolate(bpy.types.Panel):
|
|||||||
elif settings.method == 'GEOMETRY':
|
elif settings.method == 'GEOMETRY':
|
||||||
col.prop(settings, 'search_range')
|
col.prop(settings, 'search_range')
|
||||||
col.prop(settings, 'remove_occluded')
|
col.prop(settings, 'remove_occluded')
|
||||||
|
col.prop(settings, 'smooth_level', text='Smooth')
|
||||||
|
|
||||||
elif settings.method == 'OBJECT':
|
elif settings.method == 'OBJECT':
|
||||||
|
col.prop(settings, 'search_range')
|
||||||
col.prop(settings, 'target_object', text='Object')
|
col.prop(settings, 'target_object', text='Object')
|
||||||
|
col.prop(settings, 'smooth_level', text='Smooth')
|
||||||
|
|
||||||
|
elif settings.method == 'VELOCITY':
|
||||||
|
|
||||||
|
row = col.row(align=True)
|
||||||
|
row.prop(settings, 'target_collection', text='Collection')
|
||||||
|
row.operator("gp.pick_collection", text='', icon="EYEDROPPER")
|
||||||
|
col.prop(settings, 'target_object', text='Object')
|
||||||
|
col.prop(settings, 'smooth_level', text='Smooth')
|
||||||
|
|
||||||
col.separator()
|
col.separator()
|
||||||
col = layout.column(align=True)
|
col = layout.column(align=True)
|
||||||
@@ -61,7 +86,7 @@ class GP_PT_interpolate(bpy.types.Panel):
|
|||||||
row.prop(settings, 'mode', expand=True)
|
row.prop(settings, 'mode', expand=True)
|
||||||
|
|
||||||
if settings.mode == 'FRAME':
|
if settings.mode == 'FRAME':
|
||||||
col.prop(settings, 'padding')
|
col.prop(settings, 'step', text='Step')
|
||||||
|
|
||||||
if settings.mode == 'RIGKEY':
|
if settings.mode == 'RIGKEY':
|
||||||
col.prop(settings, 'target_collection', text='Collection')
|
col.prop(settings, 'target_collection', text='Collection')
|
||||||
@@ -77,6 +102,17 @@ class GP_PT_interpolate(bpy.types.Panel):
|
|||||||
row.operator('gp.debug_geometry_interpolation_targets', text='Debug points')
|
row.operator('gp.debug_geometry_interpolation_targets', text='Debug points')
|
||||||
row.operator('gp.debug_geometry_interpolation_targets', text='', icon='X').clear = True
|
row.operator('gp.debug_geometry_interpolation_targets', text='', icon='X').clear = True
|
||||||
|
|
||||||
|
if context.scene.gp_interpo_settings.method == 'TRI':
|
||||||
|
col.separator()
|
||||||
|
row=layout.row(align=True)
|
||||||
|
wm = bpy.context.window_manager
|
||||||
|
binded = context.object and context.object.type == 'GPENCIL' and wm.get(f'tri_{context.object.name}')
|
||||||
|
txt = 'Show Tri Points' if binded else 'Bind Tri Points'
|
||||||
|
row.operator('gp.bind_points', text=txt, icon='MESH_DATA')
|
||||||
|
if binded:
|
||||||
|
row.operator('gp.bind_points', text='', icon='TRASH').clear = True
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
GP_PT_interpolate,
|
GP_PT_interpolate,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import bpy
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import fnmatch
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from math import tan
|
from math import tan
|
||||||
from mathutils import Vector, Matrix
|
from mathutils import Vector, Matrix
|
||||||
@@ -35,6 +38,63 @@ class attr_set():
|
|||||||
|
|
||||||
# --- Vector
|
# --- Vector
|
||||||
|
|
||||||
|
def load_datablock(filepath, *names, type='objects', link=True, expr=None, assets_only=False,
|
||||||
|
relative_to=None):
|
||||||
|
"""link or append elements from another blender scene
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filepath (str): filepath of the scene to import objects from
|
||||||
|
names (list[str]): names of datablocks to import.
|
||||||
|
type (str, optional): type of data to import.
|
||||||
|
Defaults to 'objects'.
|
||||||
|
link (bool, optional): true if we want to import as link, else append.
|
||||||
|
Defaults to True.
|
||||||
|
expr (str, optional): pattern of names to import.
|
||||||
|
Defaults to None.
|
||||||
|
assets_only (bool, optional): If true, import only data-blocks marked as assets.
|
||||||
|
Defaults to False.
|
||||||
|
relative_to (str|Path|bool, optionnal): If str or Path and link make path relative to it
|
||||||
|
if False make path absolute, if None use preferences
|
||||||
|
Defaults to None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list|bpy.types.Object: datablocks imported
|
||||||
|
"""
|
||||||
|
|
||||||
|
# convert names from tuple to list to get the correct datablock type (blender tricks)
|
||||||
|
names = list(names)
|
||||||
|
|
||||||
|
if isinstance(expr, str):
|
||||||
|
pattern = expr
|
||||||
|
expr = lambda x: fnmatch(x, pattern)
|
||||||
|
|
||||||
|
with bpy.data.libraries.load(str(filepath), link=link, assets_only=assets_only) as (data_from, data_to):
|
||||||
|
datablocks = getattr(data_from, type)
|
||||||
|
if expr:
|
||||||
|
names += [i for i in datablocks if expr(i)]
|
||||||
|
elif not names:
|
||||||
|
names = datablocks
|
||||||
|
|
||||||
|
setattr(data_to, type, names)
|
||||||
|
|
||||||
|
datablocks = getattr(data_to, type)
|
||||||
|
|
||||||
|
if link and datablocks:
|
||||||
|
lib = datablocks[0].library
|
||||||
|
lib_path = os.path.abspath(bpy.path.abspath(lib.filepath))
|
||||||
|
|
||||||
|
if relative_to is False:
|
||||||
|
lib.filepath = lib_path
|
||||||
|
elif isinstance(relative_to, (str, Path)):
|
||||||
|
lib.filepath = bpy.path.relpath(lib_path, start=str(relative_to))
|
||||||
|
|
||||||
|
if len(names) > 1:
|
||||||
|
return datablocks
|
||||||
|
|
||||||
|
if datablocks:
|
||||||
|
return datablocks[0]
|
||||||
|
|
||||||
|
|
||||||
def triangle_normal(p1, p2, p3):
|
def triangle_normal(p1, p2, p3):
|
||||||
"""
|
"""
|
||||||
Calculate the normal of a triangle given its three vertices.
|
Calculate the normal of a triangle given its three vertices.
|
||||||
@@ -53,16 +113,9 @@ def triangle_normal(p1, p2, p3):
|
|||||||
normal.normalize()
|
normal.normalize()
|
||||||
return normal
|
return normal
|
||||||
|
|
||||||
## Bad normal calculation !!
|
|
||||||
# def triangle_normal(a, b, c):
|
|
||||||
# x = a[1] * b[2] - a[2] * b[1]
|
|
||||||
# y = a[2] * b[0] - a[0] * b[2]
|
|
||||||
# z = a[0] * b[1] - a[1] * b[0]
|
|
||||||
# return np.array([x, y, z], dtype='float64')
|
|
||||||
|
|
||||||
def plane_coords(size=1):
|
def plane_coords(size=1):
|
||||||
v = size * 0.5
|
v = size * 0.5
|
||||||
return np.array([(-v, v, 0), (v, v, 0), (v, -v, 0), (-v, -v, 0)], dtype='float64')
|
return [Vector((-v, v, 0)), Vector((v, v, 0)), Vector((v, -v, 0)), Vector((-v, -v, 0))]
|
||||||
|
|
||||||
def matrix_transform(coords, matrix):
|
def matrix_transform(coords, matrix):
|
||||||
coords_4d = np.column_stack((coords, np.ones(len(coords), dtype='float64')))
|
coords_4d = np.column_stack((coords, np.ones(len(coords), dtype='float64')))
|
||||||
@@ -84,13 +137,14 @@ def search_square(point, factor=0.05, cam=None):
|
|||||||
depth = vector_magnitude(point - cam.matrix_world.to_translation())
|
depth = vector_magnitude(point - cam.matrix_world.to_translation())
|
||||||
mat_scale = Matrix.Scale(tan(cam.data.angle * 0.5) * depth * factor, 4)
|
mat_scale = Matrix.Scale(tan(cam.data.angle * 0.5) * depth * factor, 4)
|
||||||
|
|
||||||
return matrix_transform(plane, mat @ mat_scale)
|
final_matrix = mat @ mat_scale
|
||||||
|
return [final_matrix @ co for co in plane]
|
||||||
|
|
||||||
def get_tri_from_face(hit_location, face_index, object_hit, depsgraph):
|
def get_tri_from_face(hit_location, face_index, object_hit, depsgraph):
|
||||||
eval_ob = object_hit.evaluated_get(depsgraph)
|
eval_ob = object_hit.evaluated_get(depsgraph)
|
||||||
face = eval_ob.data.polygons[face_index]
|
face = eval_ob.data.polygons[face_index]
|
||||||
vertices = [eval_ob.data.vertices[i] for i in face.vertices]
|
vertices = [eval_ob.data.vertices[i] for i in face.vertices]
|
||||||
face_co = matrix_transform([v.co for v in vertices], eval_ob.matrix_world)
|
face_co = [eval_ob.matrix_world @ v.co for v in vertices]
|
||||||
|
|
||||||
tri = None
|
tri = None
|
||||||
for tri_idx in tessellate_polygon([face_co]):
|
for tri_idx in tessellate_polygon([face_co]):
|
||||||
@@ -124,7 +178,7 @@ def ray_cast_point(point, origin, depsgraph):
|
|||||||
|
|
||||||
tri, tri_indices = get_tri_from_face(hit_location, face_index, object_hit, depsgraph)
|
tri, tri_indices = get_tri_from_face(hit_location, face_index, object_hit, depsgraph)
|
||||||
|
|
||||||
return object_hit, np.array(hit_location), tri, tri_indices
|
return object_hit, hit_location, tri, tri_indices
|
||||||
|
|
||||||
def obj_ray_cast(obj, point, origin, depsgraph):
|
def obj_ray_cast(obj, point, origin, depsgraph):
|
||||||
"""Wrapper for ray casting that moves the ray into object space"""
|
"""Wrapper for ray casting that moves the ray into object space"""
|
||||||
@@ -142,7 +196,7 @@ def obj_ray_cast(obj, point, origin, depsgraph):
|
|||||||
# Get hit location world_space
|
# Get hit location world_space
|
||||||
hit_location = obj.matrix_world @ location
|
hit_location = obj.matrix_world @ location
|
||||||
tri, tri_indices = get_tri_from_face(hit_location, face_index, obj, depsgraph)
|
tri, tri_indices = get_tri_from_face(hit_location, face_index, obj, depsgraph)
|
||||||
return obj, np.array(hit_location), tri, tri_indices
|
return obj, hit_location, tri, tri_indices
|
||||||
|
|
||||||
|
|
||||||
def empty_at(name='Empty', pos=(0,0,0), collection=None, type='PLAIN_AXES', size=1, show_name=False):
|
def empty_at(name='Empty', pos=(0,0,0), collection=None, type='PLAIN_AXES', size=1, show_name=False):
|
||||||
@@ -423,7 +477,7 @@ def get_gp_draw_plane(obj=None):
|
|||||||
|
|
||||||
## --- Animation
|
## --- Animation
|
||||||
|
|
||||||
def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list | None:
|
def following_keys(forward=True, animation=False) -> list:# -> list[int] | list | None:
|
||||||
'''Return a list of int or an empty list'''
|
'''Return a list of int or an empty list'''
|
||||||
direction = 1 if forward else -1
|
direction = 1 if forward else -1
|
||||||
cur_frame = bpy.context.scene.frame_current
|
cur_frame = bpy.context.scene.frame_current
|
||||||
@@ -437,15 +491,15 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
|
|||||||
|
|
||||||
frames = []
|
frames = []
|
||||||
if settings.mode == 'FRAME':
|
if settings.mode == 'FRAME':
|
||||||
jump = settings.padding * direction
|
jump = settings.step * direction
|
||||||
if all_keys:
|
if animation:
|
||||||
limit += direction # offset by one for limit to be in range
|
limit += direction # offset by one for limit to be in range
|
||||||
return list(range(cur_frame + jump , limit, jump))
|
return list(range(cur_frame + jump , limit, jump))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return [cur_frame + jump]
|
return [cur_frame + jump]
|
||||||
|
|
||||||
elif settings.mode == 'GPKEY':
|
if settings.mode == 'GPKEY':
|
||||||
layers = bpy.context.object.data.layers
|
layers = bpy.context.object.data.layers
|
||||||
frames = [f.frame_number for l in layers for f in l.frames]
|
frames = [f.frame_number for l in layers for f in l.frames]
|
||||||
|
|
||||||
@@ -462,30 +516,28 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
|
|||||||
print(obj.name)
|
print(obj.name)
|
||||||
if not obj.animation_data or not obj.animation_data.action:
|
if not obj.animation_data or not obj.animation_data.action:
|
||||||
continue
|
continue
|
||||||
frames += [k.co.x for fc in obj.animation_data.action.fcurves for k in fc.keyframe_points]
|
frames += [round(k.co.x) for fc in obj.animation_data.action.fcurves for k in fc.keyframe_points]
|
||||||
|
|
||||||
|
|
||||||
if not frames:
|
if not frames:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# Sort frames (invert if looking backward)
|
# Sort frames (invert if looking backward)
|
||||||
|
frames = list(set(frames))
|
||||||
frames.sort(reverse=not forward)
|
frames.sort(reverse=not forward)
|
||||||
|
|
||||||
if all_keys:
|
if animation:
|
||||||
frames = list(set(frames))
|
|
||||||
if forward:
|
if forward:
|
||||||
frame_list = [int(f) for f in frames if f > cur_frame and f <= limit]
|
frame_list = [f for f in frames if cur_frame < f <= limit]
|
||||||
else:
|
else:
|
||||||
frame_list = [int(f) for f in frames if f < cur_frame and f >= limit]
|
frame_list = [f for f in frames if limit <= f < cur_frame]
|
||||||
return frame_list
|
return frame_list
|
||||||
|
|
||||||
|
## Single frame
|
||||||
if forward:
|
if forward:
|
||||||
new = next((f for f in frames if f > cur_frame), None)
|
frame_list = next(([f] for f in frames if f > cur_frame), [])
|
||||||
else:
|
else:
|
||||||
new = next((f for f in frames if f < cur_frame), None)
|
frame_list = next(([f] for f in frames if f < cur_frame), [])
|
||||||
if new is None:
|
return frame_list
|
||||||
return []
|
|
||||||
return [int(new)]
|
|
||||||
|
|
||||||
|
|
||||||
def index_list_from_bools(bool_list) -> list:
|
def index_list_from_bools(bool_list) -> list:
|
||||||
|
|||||||
Reference in New Issue
Block a user