├── .flake8 ├── .github └── workflows │ └── linting.yml ├── .gitignore ├── LICENSE ├── README.md ├── __init__.py ├── blender_manifest.toml ├── bundle.sh ├── docs ├── gizmo_bar.png ├── header.jpg ├── sample_menu.png ├── simple_demo.gif ├── sub-div_level.png ├── subdiv_available.png └── subdiv_limit.png ├── mypy.ini ├── preferences.py ├── requirements.txt ├── ruff.toml └── source ├── __init__.py ├── ops ├── __init__.py ├── actions.py ├── gizmo.py └── touch.py ├── ui ├── __init__.py ├── gizmo_2d.py ├── gizmo_config.py ├── gizmo_group_2d.py └── panel.py └── utils ├── __init__.py ├── blender.py ├── constants.py ├── gizmo_2d.py ├── gizmo_config.py ├── keymaps.py └── overlay.py /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = 3 | # defaults 4 | E121,E123,E126,E226,E24,E704,W503,W504, 5 | # do not use bare except 6 | E722, 7 | # wildcard imports 8 | F403, 9 | # undefined, possibly by wildcard (should try to eliminate this error later) 10 | F405, 11 | # syntax error in forward annotation 12 | F722, 13 | # undefined name 'name' 14 | F821, 15 | # undefined name 'name' in __all__ 16 | F822 17 | -------------------------------------------------------------------------------- /.github/workflows/linting.yml: -------------------------------------------------------------------------------- 1 | name: lint_python 2 | on: [pull_request, push] 3 | jobs: 4 | lint_python: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | - uses: actions/setup-python@v3 9 | - run: pip install bandit black codespell flake8 isort flake8-isort 10 | - run: pip install -r requirements.txt 11 | - run: bandit --recursive --skip B101,B110 . 12 | - run: codespell --skip=.git 13 | - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 14 | - run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --show-source --statistics 15 | - run: isort --check-only . 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | preferences.json 2 | bin 3 | deploy.sh 4 | __pycache__/ 5 | venv 6 | .venv 7 | settings.json 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

TouchView

3 |
BLENDER 3D add-on
4 |
customizable rotate/pan/zoom
5 |
6 | GitHub release (latest by date) 7 | GitHub Workflow Status (with branch) 8 | GitHub issues 9 | GitHub 10 | PyPI - Python Version 11 |
12 |
13 | 14 | ### Table of Contents 15 | 16 | - [Features](https://github.com/nendotools/touchview#features) 17 | - [Building from Github](https://github.com/nendotools/touchview#building-from-github) 18 | - [Installation](https://github.com/nendotools/touchview#installation) 19 | - [Changelog](https://github.com/nendotools/touchview#changelog) 20 | 21 | # Features 22 | 23 | This add-on is designed to improve the user experience of Blender for users without immediate access to a keyboard or mouse. It provides many customizable UI improvements to cater to your workflow needs. 24 | 25 |
26 | 27 |
28 |

Viewport Touch Control

29 | 30 | Pan, Rotate, and Zoom the viewport with your finger. 31 | 32 | The viewport has be updated to use 3 interactive "hot regions" to control the camera position. 33 | 34 | If you are a pen tablet user; the pen will still draw, while your finger can be used to control the camera. 35 | 36 | If your tablet doesn't support touch; you can set the middle mouse button to activate the control regions in the add-on prefs. 37 | 38 | - Pan by dragging for the middle of the viewport 39 | - Zoom by dragging along the left or right edge of the viewport 40 | - Rotate by dragging the remaining space in the viewport 41 | 42 |

Additional Details

43 | 44 | Touch Controls come with a toggleable overlay which can be assigned colors. 45 | 46 | It is recommended to disable the overlay once you are comfortable with the size of each touch region, or set the transparency very low. (note: the overlay will not be shown in the render output) 47 | 48 | You may chose to switch the Pan and Rotate regions. If you lock the viewport rotation, Panning can be done anywhere between the Zoom control regions. 49 | 50 |
51 |
52 | 53 | ## Customizable Double-tap Action 54 | 55 | Double-tap to trigger one of the following actions: 56 | 57 | - "Transfer Mode" to change the active object 58 | - Toggle Touch Control 59 | - Toggle Local View 60 | - Toggle Full-screen Viewport 61 | 62 | ###### _note:_ this feature only works by tapping your finger or clicking to prevent the pen from accidentally triggering it while drawing 63 | 64 | ## Custom On-screen Buttons 65 | 66 | ![gizmo bar](/docs/gizmo_bar.png) 67 | 68 | Important features have been made available directly in the viewport. Each button can be toggled on/off from the overlay menu. 69 | 70 | The following on-screen buttons are currently available: 71 | 72 | - Undo/Redo 73 | - Toggle Fullscreen Viewport 74 | - Toggle Quad-view 75 | - Recenter Viewport 76 | - Change Rotation Center Point 77 | - Toggle N-panel 78 | - Toggle Viewport Rotation Lock 79 | - Topology Control 80 | - Sculpt Brush Dynamics 81 | 82 | ### Additional Details 83 | 84 | #### Toggle Quad-view 85 | 86 | Quad-view may sometimes replace the perspective viewport with an orthographic viewport when toggled off and on. This may cause the main viewport rotation to be automatically locked. Simply unlock it with the on-screen button. 87 | 88 | #### Recent Viewport 89 | 90 | This attempts to bring the active object back into view. If the origin is misaligned, it may not work perfectly. 91 | 92 | #### Viewport Rotation Lock 93 | 94 | Locking the viewport rotation replaces viewport rotation with panning control. 95 | 96 | ###### _NOTE:_ Quad-view will default to rotation locking for isometric viewports (top, front, and side views) 97 | 98 | #### Topology Control 99 | 100 | This feature provides quick access to Retopology control in Sculpt mode and is not shown in any other mode. 101 | 102 | If the selected object has a Multi-resolution modifier; the retopology controls change to subdivision level controls. 103 | 104 | ![subdivision level control](/docs/sub-div_level.png) 105 | 106 | Quickly jump through subdivision levels, subdivide and unsubdivide right from the viewport. 107 | 108 | ![subdivision available](/docs/subdiv_available.png) 109 | 110 | A yellow icon means the next subdivision step needs to be calculated. It will automatically try to subdivide/unsubdivide when clicked. 111 | 112 | ![subdivision limit](/docs/subdiv_limit.png) 113 | 114 | A red icon means you have reached your subdivision limit and it will not try to subdivide further. You may change the maximum subdivision levels available for the on-screen buttons to limit accidental subdivision. 115 | 116 | ###### _note:_ the subdivision limit only applies to increasing subdivision levels. You may unsubdivide as much as Blender is able. 117 | 118 | #### Sculpt Brush Dynamics 119 | 120 | This feature allows you to quickly access the UI for brush resizing and strength control in sculpt mode. 121 | 122 | ## Fully Customizable Floating Menu 123 | 124 | 125 | 126 | This button allows you to assign up to 8 commands, unique to each edit mode (object, sculpt, texture paint, weight paint, etc) and reposition it where ever you want, to best fit your workspace. If you don't need it, simply disable it in the prefs menu. 127 | 128 | # Feature Roadmap 129 | 130 | If you have a suggestion for more features, please check if it's on this list before submitting a request on Github. 131 | 132 | I'm continuing to look at features which could improve the experience of Blender without adding too much clutter to the UI. 133 | 134 | Currently, I'm planning to add the following features: 135 | 136 | > - better 3D gizmos for edit mode 137 | > - control gizmo enum (flip through object gizmos in sculpt mode) 138 | 139 | This list will change as I explore options and get more user feedback. 140 | 141 | # Building from Github 142 | 143 | Building the addon zip can be done by using the included `bundle.sh` script. Simply run: 144 | 145 | ``` 146 | ./bundle.sh 147 | ``` 148 | 149 | It will output the files to include and generate a new ZIP file: 150 | 151 | ``` 152 | $ ./bundle.sh 153 | adding: touchview/ (stored 0%) 154 | adding: touchview/source/ (stored 0%) 155 | adding: touchview/source/gizmos.py (deflated 77%) 156 | adding: touchview/source/items.py (deflated 68%) 157 | adding: touchview/source/operators.py (deflated 80%) 158 | adding: touchview/source/overlay.py (deflated 73%) 159 | adding: touchview/source/panel.py (deflated 69%) 160 | adding: touchview/source/touch_input.py (deflated 69%) 161 | adding: touchview/source/__init__.py (deflated 70%) 162 | adding: touchview/prefs.py (deflated 76%) 163 | adding: touchview/__init__.py (deflated 51%) 164 | ``` 165 | 166 | The final ZIP can be found in: 167 | 168 | ``` 169 | ./bin/touchview.zip 170 | ``` 171 | 172 | # Installation 173 | 174 | In Blender, open `Edit` > `Preferences...`. 175 | 176 | Navigate to the `Add-ons` tab. 177 | 178 | Click `Install...` and navigate to the `touchview.zip` file. 179 | 180 | Select it and click `Install Add-on`. 181 | 182 | ###### _note:_ You do not need to extract it, first. Simply install the ZIP, directly 183 | 184 | # Changelog 185 | 186 |
v4.2.0
187 | 188 | - `ADDED`: Support for Blender v4.2 (Extensions). 189 | - `FIXED`: Gizmo size and overlapping. 190 | - `FIXED`: Mouse position after moving the gizmo. 191 | - `FIXED`: Broken reference to full control mode in enabled check. 192 | - `CHANGED`: Class names, `register()`, and `unregister()` according to Blender conventions. 193 | - `CHANGED`: EnumProperty items according to Blender conventions. 194 | - `CHANGED`: Cursor type on hover over the gizmo. 195 | - `CHANGED`: Folder structure. 196 | - `IMPROVED`: Gizmo safe area. 197 | - `IMPROVED`: UI and tooltips. 198 | 199 |
200 | 201 |
v4.0.5
202 | 203 | - `ADDED`: switch 2D header toggle UI position 204 | 205 |
206 | 207 |
v4.0.4
208 | 209 | - `ADDED`: optional enable floating toggle for touch controls in mixed mode 210 | - `ADDED`: toggle touch controls button in node editor and image editor headers 211 | 212 |
213 | 214 |
v4.0.3
215 | 216 | - `UPDATED`: fixed bug where hotkeys aren't assigned when opening Blender directly by file 217 | 218 |
219 | 220 |
v4.0.2
221 | 222 | - `ADDED`: Nendo Tools Menu (limited options) for Image Editor and Node Editor 223 | - `REMOVED`: Right-Click Action for Image Editor and Node Editor 224 | 225 |
226 | 227 |
v4.0.0
228 | Compatibility update for Blender 4.0 229 | 230 | - `ADDED`: support for Blender 4.0 231 | - `ADDED`: auto-save/load preferences 232 | - `UPDATED`: replace bgl module refs with gpu module implementation 233 | - `UPDATED`: Swap Control Regions fixed context override implementation 234 | - `UPDATED`: early exit when dragging gizmo near edge of viewport to prevent negative overflow 235 | - `REMOVED`: argument renaming to disregard unused args (currently breaking CI/CD) 236 | 237 |
238 | 239 |
v2.12.0
240 | 241 | - `UPDATED`: fixed bug with unindexed modes breaking gizmo menus 242 | - `UPDATED`: updated resize and change strength for 2D views 243 | - `UPDATED`: improved support for multi-mode devices 244 | 245 |
246 | 247 |
v2.11.0
248 | 249 | - `UPDATED`: added various GPENCIL modes to edit mode list 250 | - `UPDATED`: updated viewport gizmo panel to support v3.6 changes 251 | 252 |
253 | 254 |
v2.10.0
255 | 256 | - `ADDED`: lazy camera control toggle in sculpt mode 257 | - `UPDATED`: add support for Weylus (\*nix) sending 0.0 for pressure on touch events 258 | - `UPDATED`: changed all new operator namespaces to `nendo` for easier identification 259 | - `ADDED`: control mode icon when using signle-input mode 260 | - `UPDATED`: control mode toggle and floating action button now use same sizing as gizmos 261 | - `ADDED`: additional fine-tuning controls for gizmo spacing 262 | 263 |
264 | 265 |
v2.9.0
266 | 267 | - `UPDATED`: additional changes to gizmo spacing 268 | - `UPDATED`: fixed bug preventing custom actions being assigned for radial menu 269 | 270 |
271 | 272 |
v2.8.0
273 | 274 | - `UPDATED`: fixed issues with menu bar spacing 275 | - `REMOVED`: floating menu bar 276 | 277 |
278 | 279 |
v2.7.1
280 | 281 | - `UPDATED`: replaced region_full_area with window_fullscreen 282 | 283 |
284 | 285 |
v2.7.0
286 | 287 | - `ADDED`: relative remesh 288 | - `UPDATED`: fixed error when disabling add-on 289 | 290 |
291 | 292 |
v2.6.0
293 | 294 | - `UPDATED`: code spec now based on flake8 295 | - `UPDATED`: added alternative action for TransferMode when used in OBJECT mode 296 | - `UPDATED`: fixed desktop scaling issue with radial gizmo menu 297 | - `UPDATED`: fixed toggle touch gizmo and RC/DC action 298 | - `UPDATED`: fixed error message when rotation locked and pan/rotate swapped 299 | 300 |
301 | 302 |
v2.5.0
303 | 304 | - `ADDED`: Gizmo size control 305 | - `UPDATED`: moved operators into folder 306 | 307 |
308 | 309 |
v2.4.0
310 | 311 | - `UPDATED`: preferences access simplified with utility function 312 | - `ADDED`: single-input mode now activates large floating toggle button 313 | 314 |
315 | 316 |
v2.3.0
317 | 318 | - `ADDED`: Input Mode selection (for devices with only touch or pen support) 319 | 320 |
321 | 322 |
v2.2.0
323 | 324 | - `ADDED`: Toggle control gizmo (translate, rotate, scale, none) 325 | - `UPDATED`: Added Brush dynamics (from sculpt mode) to paint modes 326 | - NOTE: some paint/sculpt modes when in 2D/Draw canvas mode aren't yet hooked up to brush dynamics 327 | 328 |
329 | 330 |
v2.1.0
331 | 332 | - `ADDED`: Right Click Actions 333 | - `UPDATED`: Preferences and N-Panel restructure 334 | 335 |
336 | 337 |
v2.0.0
338 | 339 | - `UPDATED`: Gizmos-related code simplified and reorganized for easier management 340 | - `ADDED`: floating gizmo bar and floating gizmo radial menu modes 341 | - `ADDED`: customizable gizmo menu spacing 342 | - `UPDATED`: viewport safe area calculation 343 | - `UPDATED`: floating action menu to use same move/access functionality as floating radial menu 344 | - `ADDED`: 8th custom action for floating action menu 345 | 346 |
347 | 348 |
v1.2.4
349 | 350 | - `ADDED`: Toggle Double-tap action on/off 351 | 352 |
353 | 354 |
v1.2.3
355 | 356 | - `ADDED`: Sculpt Brush Dynamics 357 | - `UPDATED`: Viewport rotation in sculpt mode automatically sets pivot to mesh under touch point 358 | 359 |
360 | 361 |
v1.2.2
362 | 363 | - `UPDATED`: Gizmo panel layout split 364 | 365 |
366 | 367 |
v1.2.1
368 | 369 | - `REMOVED`: Middle Mouse keybind 370 | - `REMOVED`: viewport rotation lock when using the Grease Pencil 371 | 372 |
373 | 374 |
v1.2.0
375 | 376 | - `BREAKING`: This version requires previous version to be disabled before install 377 | - `UPDATED`: Improved Pen detection and simplified key configs 378 | - `ADDED`: Support for various 2D and 2D-like views (Image Editor, UV Editor, 2D Animation, Compositing, etc) 379 | 380 |
381 | 382 |
v1.1.2
383 | 384 | - `ADDED`: Support for Node Editor 385 | 386 |
387 | 388 |
v1.1.1
389 | 390 | - `ADDED`: minor fix to pen detection 391 | 392 |
393 | 394 |
v1.1.0
395 | 396 | - `ADDED`: Independent toggle for entire gizmo bar 397 | - `ADDED`: Customizable double-tap actions 398 | - `ADDED`: Multi-resolution level limiter and gizmo status color 399 | 400 |
401 | 402 |
v1.0.1
403 | 404 | - `ADDED`: Optional include for MIDDLEMOUSE when disabling/enabling touch controls 405 | - `FIXED`: Preferences bug preventing toggle of floating Gizmo 406 | 407 |
408 | 409 |
v1.0.0
410 | 411 | - `ADDED`: Toggle swap pan/rotate regions 412 | - `ADDED`: Toggle floating menu button to N Panel 413 | - `UPDATED`: Disabling touch controls no longer removes overlay (hot regions still work with custom keybinds and MIDDLEMOUSE) 414 | - `UPDATED`: Disabling touch controls restores default LEFTMOUSE functionality 415 | 416 |
417 | 418 |
v0.9.6
419 | 420 | - `ADDED`: undo/redo gizmo 421 | - `ADDED`: overlay color selection 422 | - `ADDED`: touch control toggle in prefs 423 | - `ADDED`: Alt+T to toggle touch controls 424 | - `UPDATED`: N Panel now includes extra prefs from addon menu 425 | - `UPDATED`: Lock Rotation now addresses quadview data replication bug 426 | - `UPDATED`: Limited floating gizmo to viewport area 427 | - `UPDATED`: code cleanup and additional structure tweaks 428 | - `REMOVED`: Gizmo Tooltips 429 | 430 |
431 | 432 |
v0.9.5
433 | 434 | - `ADDED`: multires modifier support to gizmo bar (shows retopology tools when no modifier is present) 435 | - `FIXED`: Gizmos now properly follow mode visibility rules 436 | - `FIXED`: Double-tap selection now only runs in appropriate viewport modes 437 | 438 |
439 | 440 |
v0.9.4
441 | 442 | - `ADDED`: Support for menus in floating gizmo 443 | - `ADDED`: Mode-specific options for floating gizmo 444 | - `UPDATED`: Dependence on active_object for mode detection 445 | - `UPDATED`: Classes to follow Blender naming conventions 446 | - `UPDATED`: Keymaps for touchview in all context 447 | - `UPDATED`: Keymaps for context action assigned to pen 448 | 449 |
450 | 451 |
v0.9.3
452 | 453 | - `ADDED`: Sculpt pivot mode gizmo 454 | - `ADDED`: Customizable floating menu 455 | 456 |
457 | 458 |
v0.9.2
459 | 460 | - `FIXED`: Issue delaying overlay viewport binding 461 | - `FIXED`: Gizmo tools/panel overlap issue when "Region Overlap" enabled 462 | - `REMOVED`: Viewport manager class 463 | - `REMOVED`: Default keymap causing Move Operator to trigger when dragging over non-modal gizmos 464 | 465 |
466 | 467 |
v0.9.1
468 | 469 | - `ADDED`: Tap for menu scroll 470 | 471 |
472 | 473 |
v0.9
474 | 475 | - `ADDED`: N-Panel gizmo 476 | - `UPDATED`: Code restructure 477 | - `FIXED`: Dragging over gizmo moves selected object 478 | 479 |
480 | 481 |
v0.8
482 | 483 | - `ADDED`: Gizmo to toggle fullscreen mode 484 | - `UPDATED`: Settings to addon preferences to save across projects and scenes 485 | - `FIXED`: Bugs impacting user experience 486 | - `FIXED`: Doubletap now selects/activates tapped object instead of triggering fullscreen 487 | 488 |
489 | 490 |
v0.7
491 | 492 | - `ADDED`: Gizmos for key features 493 | - `ADDED`: Hide/show Gizmo and layout options 494 | - `ADDED`: Locked viewport rotation for isometric viewports in quadview to address lock/unlock inconsistencies 495 | - `FIXED`: Fullscreen Toggle no longer maximizes the window, only expands the View3D region 496 | 497 |
498 | 499 |
v0.6
500 | 501 | - `UPDATED`: Scale of viewport overlay prefs for more precision 502 | - `FIXED`: Issues with determining locked state with quadviews 503 | 504 |
505 | 506 |
v0.5
507 | 508 | - `ADDED`: Camera rotation lock in N-panel 509 | - `FIXED`: Quad-view overlay compatibility 510 | - `FIXED`: Rotation with panning when rotation is locked 511 | - `FIXED`: Issue when locking view to Object or 3D Cursor 512 | 513 |
514 | 515 |
v0.4
516 | 517 | - `ADDED`: Double-tap to toggle "focus" mode 518 | - `ADDED`: Toggle Tools LEFT/RIGHT in UI 519 | 520 |
521 | 522 |
v0.3
523 | 524 | - `FIXED`: Incorrect viewport calculation when N-panel is open 525 | - `FIXED`: Refactored screen/area management code (additional major refactor needed) 526 | 527 |
528 | 529 |
v0.2
530 | 531 | - `FIXED`: Minor bug fixes and code cleanup 532 | 533 |
534 | 535 |
v0.1
536 | 537 | - `ADDED`: Camera dolly on left and right of viewport 538 | - `ADDED`: Camera pan from center of viewport 539 | - `ADDED`: Camera rotate in any other area of viewport 540 | - `ADDED`: Toggleable overlay to simplify resizing controls 541 | 542 |
543 | 544 | # Issues 545 | 546 | > Please [report any issues](https://github.com/nendotools/touchview/issues) you find and I'll do my best to address them. 547 | 548 | > The add-on is free, but if it helps you, please consider [supporting me](https://nendo.gumroad.com/l/touchview). 549 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # ##### BEGIN GPL LICENSE BLOCK ##### 2 | # 3 | # This program is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU General Public License 5 | # as published by the Free Software Foundation; either version 2 6 | # of the License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software Foundation, 15 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 | # 17 | # ##### END GPL LICENSE BLOCK ##### 18 | 19 | 20 | bl_info = { 21 | "name": "Touch Viewport", 22 | "description": "Creates active touch zones over View 2D and 3D areas for easier viewport navigation with touch screens and pen tablets.", 23 | "author": "NENDO, Karan(b3dhub)", 24 | "blender": (2, 93, 0), 25 | "version": (4, 2, 1), 26 | "category": "3D View", 27 | "location": "View3D > Tools > NENDO", 28 | "warning": "", 29 | "doc_url": "https://github.com/nendotools/touchview", 30 | "tracker_url": "https://github.com/nendotools/touchview/issues", 31 | } 32 | 33 | 34 | import bpy 35 | 36 | from . import preferences, source 37 | 38 | 39 | def register(): 40 | source.register() 41 | preferences.register() 42 | bpy.context.preferences.addons[__package__].preferences.load() # type: ignore 43 | 44 | 45 | def unregister(): 46 | bpy.context.preferences.addons[__package__].preferences.save() # type: ignore 47 | source.unregister() 48 | preferences.unregister() 49 | -------------------------------------------------------------------------------- /blender_manifest.toml: -------------------------------------------------------------------------------- 1 | schema_version = "1.0.0" 2 | 3 | id = "touchview" 4 | version = "4.2.1" 5 | name = "Touch Viewport" 6 | tagline = "Creates active touch zones over View 2D and 3D areas" 7 | maintainer = "NENDO, Karan(b3dhub)" 8 | type = "add-on" 9 | 10 | website = "https://github.com/nendotools/touchview" 11 | 12 | # Optional list defined by Blender and server, see: 13 | # https://docs.blender.org/manual/en/dev/extensions/tags.html 14 | tags = ["3D View", "User Interface"] 15 | 16 | blender_version_min = "4.2.0" 17 | 18 | # License conforming to https://spdx.org/licenses/ (use "SPDX: prefix) 19 | license = ["SPDX:GPL-3.0-or-later"] 20 | 21 | [permissions] 22 | files = "preserve settings when enabling/disabling the add-on" 23 | 24 | [build] 25 | paths_exclude_pattern = [ 26 | "__pycache__/", 27 | "/.git/", 28 | "docs/", 29 | ".gitignore", 30 | "/*.zip", 31 | "/bin", 32 | "settings.json", 33 | "bundle.sh", 34 | "mypy.ini", 35 | "requirements.txt", 36 | "README.md", 37 | ] 38 | -------------------------------------------------------------------------------- /bundle.sh: -------------------------------------------------------------------------------- 1 | bundle() { 2 | local dest dir 3 | dest="bin" 4 | dir="bin/touchview" 5 | mkdir -p "$dir" 6 | cp "__init__.py" "$dir" 7 | cp "preferences.py" "$dir" 8 | cp "blender_manifest.toml" "$dir" 9 | cp -r "source" "$dir" 10 | cd "$dest" 11 | zip -r "touchview.zip" "touchview" 12 | cd ".." 13 | rm -rf "$dir" 14 | } 15 | 16 | bundle 17 | -------------------------------------------------------------------------------- /docs/gizmo_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/gizmo_bar.png -------------------------------------------------------------------------------- /docs/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/header.jpg -------------------------------------------------------------------------------- /docs/sample_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/sample_menu.png -------------------------------------------------------------------------------- /docs/simple_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/simple_demo.gif -------------------------------------------------------------------------------- /docs/sub-div_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/sub-div_level.png -------------------------------------------------------------------------------- /docs/subdiv_available.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/subdiv_available.png -------------------------------------------------------------------------------- /docs/subdiv_limit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nendotools/touchview/53808aee49e8d0752fc029a59d5708aca4e85d68/docs/subdiv_limit.png -------------------------------------------------------------------------------- /mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | implicit_reexport = false 3 | -------------------------------------------------------------------------------- /preferences.py: -------------------------------------------------------------------------------- 1 | # type: ignore 2 | import json 3 | from os import path 4 | 5 | import bpy 6 | from bpy.props import * 7 | from bpy.types import AddonPreferences, PropertyGroup, UILayout 8 | 9 | from .source.utils.constants import (double_click_items, edit_modes, 10 | gizmo_sets, menu_defaults, 11 | menu_orientation_items, menu_style_items, 12 | pivot_items, position_items) 13 | 14 | 15 | def NODE_HT_nendo_header(s, c): 16 | prefs = c.preferences.addons[__package__].preferences 17 | layout = s.layout 18 | layout.separator() 19 | layout.prop(prefs, "is_enabled", toggle=True) 20 | 21 | 22 | def update_header_toggle_position(c): 23 | prefs = c.preferences.addons[__package__].preferences 24 | bpy.types.NODE_HT_header.remove(NODE_HT_nendo_header) 25 | bpy.types.IMAGE_HT_header.remove(NODE_HT_nendo_header) 26 | if prefs.header_toggle_position == "LEFT": 27 | bpy.types.NODE_HT_header.prepend(NODE_HT_nendo_header) 28 | bpy.types.IMAGE_HT_header.prepend(NODE_HT_nendo_header) 29 | else: 30 | bpy.types.NODE_HT_header.append(NODE_HT_nendo_header) 31 | bpy.types.IMAGE_HT_header.append(NODE_HT_nendo_header) 32 | 33 | 34 | ## 35 | # Action Menu Settings 36 | ## 37 | class TOUCHVIEW_PG_MenuModeGroup(PropertyGroup): 38 | mode: StringProperty(name="mode", default="OBJECT") 39 | menu_slot_1: StringProperty(name="Menu Item", default="") 40 | menu_slot_2: StringProperty(name="Menu Item", default="") 41 | menu_slot_3: StringProperty(name="Menu Item", default="") 42 | menu_slot_4: StringProperty(name="Menu Item", default="") 43 | menu_slot_5: StringProperty(name="Menu Item", default="") 44 | menu_slot_6: StringProperty(name="Menu Item", default="") 45 | menu_slot_7: StringProperty(name="Menu Item", default="") 46 | menu_slot_8: StringProperty(name="Menu Item", default="") 47 | 48 | def to_dict(self): 49 | return { 50 | "mode": self.mode, 51 | "menu_slot_1": self.menu_slot_1, 52 | "menu_slot_2": self.menu_slot_2, 53 | "menu_slot_3": self.menu_slot_3, 54 | "menu_slot_4": self.menu_slot_4, 55 | "menu_slot_5": self.menu_slot_5, 56 | "menu_slot_6": self.menu_slot_6, 57 | "menu_slot_7": self.menu_slot_7, 58 | "menu_slot_8": self.menu_slot_8, 59 | } 60 | 61 | def from_dict(self, data: dict): 62 | self.mode = data.get("mode", "OBJECT") 63 | self.menu_slot_1 = data.get("menu_slot_1", "") 64 | self.menu_slot_2 = data.get("menu_slot_2", "") 65 | self.menu_slot_3 = data.get("menu_slot_3", "") 66 | self.menu_slot_4 = data.get("menu_slot_4", "") 67 | self.menu_slot_5 = data.get("menu_slot_5", "") 68 | self.menu_slot_6 = data.get("menu_slot_6", "") 69 | self.menu_slot_7 = data.get("menu_slot_7", "") 70 | self.menu_slot_8 = data.get("menu_slot_8", "") 71 | 72 | 73 | class TOUCHVIEW_AP_OverlaySettings(AddonPreferences): 74 | bl_idname = __package__ 75 | 76 | ## 77 | # Viewport Control Options 78 | ## 79 | 80 | is_enabled: BoolProperty( 81 | name="Enable Controls", 82 | default=True, 83 | ) 84 | 85 | header_toggle_position: EnumProperty( 86 | items=[ 87 | ("LEFT", "Left", "Toggle position on the left"), 88 | ("RIGHT", "Right", "Toggle position on the right"), 89 | ], 90 | name="Header Toggle Position", 91 | default="RIGHT", 92 | update=lambda _, c: update_header_toggle_position(c), 93 | ) 94 | 95 | lazy_mode: BoolProperty( 96 | name="Lazy Mode", 97 | default=False, 98 | description="always control camera when not touching selected object", 99 | ) 100 | 101 | toggle_position: FloatVectorProperty( 102 | name="Toggle Position", 103 | soft_min=0, 104 | soft_max=100, 105 | size=2, 106 | default=(0, 0), 107 | ) 108 | 109 | toggle_color: FloatVectorProperty( 110 | name="Toggle Button Color", 111 | default=(0.1, 0.1, 0.2, 0.5), 112 | subtype="COLOR", 113 | min=0.0, 114 | max=1.0, 115 | size=4, 116 | ) 117 | 118 | isVisible: BoolProperty( 119 | name="Show Overlay", 120 | default=False, 121 | ) 122 | 123 | input_mode: EnumProperty( 124 | name="Input Mode", 125 | items=[ 126 | ("FULL", "Full", "Mouse/Touch and Pen input", "CON_CAMERASOLVER", 0), 127 | ("PEN", "Pen", "Pen input only", "STYLUS_PRESSURE", 1), 128 | ("TOUCH", "Touch", "Mouse/Touch input only", "VIEW_PAN", 2), 129 | ], 130 | default="FULL", 131 | ) 132 | 133 | enable_floating_toggle: BoolProperty( 134 | name="Floating Toggle", 135 | description="Allows using floating toggle on mixed input mode", 136 | default=False, 137 | ) 138 | 139 | enable_double_click: BoolProperty( 140 | name="Double Click", 141 | default=True, 142 | ) 143 | 144 | double_click_mode: EnumProperty( 145 | name="Double Click Mode", 146 | items=double_click_items, 147 | default="screen.screen_full_area", 148 | ) 149 | 150 | enable_right_click: BoolProperty( 151 | name="Enable Right Click", 152 | default=True, 153 | ) 154 | 155 | right_click_mode: EnumProperty( 156 | name="Right Click Mode", 157 | items=double_click_items, 158 | default="wm.window_fullscreen_toggle", 159 | ) 160 | 161 | right_click_source: EnumProperty( 162 | name="Right Click Source", 163 | items=[ 164 | ("MOUSE", "Mouse", "Mouse/Touch right click"), 165 | ("PEN", "Pen", "Pen right click"), 166 | ("NONE", "None", "Disabled"), 167 | ], 168 | default="MOUSE", 169 | ) 170 | 171 | swap_panrotate: BoolProperty( 172 | name="Swap Pan/Rotate", 173 | default=False, 174 | ) 175 | 176 | width: FloatProperty( 177 | name="Width", 178 | default=40.0, 179 | min=10.0, 180 | max=100, 181 | ) 182 | 183 | radius: FloatProperty( 184 | name="Radius", 185 | default=35.0, 186 | min=10.0, 187 | max=100.0, 188 | ) 189 | 190 | use_multiple_colors: BoolProperty( 191 | name="Multicolor Overlay", 192 | default=False, 193 | ) 194 | 195 | overlay_main_color: FloatVectorProperty( 196 | name="Overlay Main Color", 197 | default=(1.0, 1.0, 1.0, 0.01), 198 | subtype="COLOR", 199 | min=0.0, 200 | max=1.0, 201 | size=4, 202 | ) 203 | 204 | overlay_secondary_color: FloatVectorProperty( 205 | name="Overlay Secondary Color", 206 | default=(1.0, 1.0, 1.0, 0.01), 207 | subtype="COLOR", 208 | min=0.0, 209 | max=1.0, 210 | size=4, 211 | ) 212 | 213 | ## 214 | # Gizmo Options 215 | ## 216 | 217 | show_menu: BoolProperty( 218 | name="Toggle Menu Display", 219 | default=True, 220 | ) 221 | 222 | show_gizmos: BoolProperty( 223 | name="Toggle Gizmos on Menu", 224 | default=True, 225 | ) 226 | 227 | menu_style: EnumProperty( 228 | name="Menu Style", 229 | items=menu_style_items, 230 | default="float.radial", 231 | ) 232 | 233 | gizmo_position: EnumProperty( 234 | name="Gizmo Position", 235 | items=position_items, 236 | default="RIGHT", 237 | ) 238 | 239 | menu_orientation: EnumProperty( 240 | name="Menu Orientation", 241 | items=menu_orientation_items, 242 | default="HORIZONTAL", 243 | ) 244 | 245 | menu_spacing: FloatProperty( 246 | name="Menu Scale", 247 | min=1, 248 | max=2, 249 | default=1, 250 | ) 251 | 252 | gizmo_scale: FloatProperty( 253 | name="Gizmo Scale", 254 | min=1, 255 | max=2, 256 | default=1, 257 | ) 258 | 259 | gizmo_padding: FloatProperty( 260 | name="Gizmo Padding", 261 | subtype="PIXEL", 262 | min=0, 263 | soft_max=24, 264 | default=4, 265 | ) 266 | 267 | menu_position: FloatVectorProperty( 268 | name="Menu Position", 269 | soft_min=0, 270 | soft_max=100, 271 | size=2, 272 | default=(100, 0), 273 | ) 274 | 275 | show_undoredo: BoolProperty( 276 | name="Undo/Redo", 277 | default=True, 278 | ) 279 | 280 | show_is_enabled: BoolProperty( 281 | name="Toggle Touch", 282 | default=True, 283 | ) 284 | 285 | show_control_gizmo: BoolProperty( 286 | name="Toggle Control Gizmo", 287 | default=True, 288 | ) 289 | 290 | show_show_fullscreen: BoolProperty( 291 | name="Fullscreen", 292 | default=True, 293 | ) 294 | 295 | show_region_quadviews: BoolProperty( 296 | name="Quadview", 297 | default=True, 298 | ) 299 | 300 | show_pivot_mode: BoolProperty( 301 | name="Pivot Mode", 302 | default=True, 303 | ) 304 | 305 | show_snap_view: BoolProperty( 306 | name="Snap View", 307 | default=True, 308 | ) 309 | 310 | show_n_panel: BoolProperty( 311 | name="N Panel", 312 | default=True, 313 | ) 314 | 315 | show_lock_rotation: BoolProperty( 316 | name="Rotation Lock", 317 | default=True, 318 | ) 319 | 320 | show_multires: BoolProperty( 321 | name="Multires", 322 | default=True, 323 | ) 324 | 325 | show_voxel_remesh: BoolProperty( 326 | name="Voxel Remesh", 327 | default=True, 328 | ) 329 | show_brush_dynamics: BoolProperty( 330 | name="Brush Dynamics", 331 | default=True, 332 | ) 333 | 334 | subdivision_limit: IntProperty( 335 | name="Subdivision Limit", 336 | default=4, 337 | min=1, 338 | max=7, 339 | ) 340 | 341 | pivot_mode: EnumProperty( 342 | name="Sculpt Pivot Mode", 343 | items=pivot_items, 344 | default="SURFACE", 345 | ) 346 | 347 | ## 348 | # Topology Control 349 | ## 350 | 351 | topology_mode: EnumProperty( 352 | name="Topology Mode", 353 | items=[ 354 | ("MANUAL", "manual", "user-defined vertex density"), 355 | ("RELATIVE", "relative", "relative mesh vertex density steps"), 356 | ( 357 | "RELATIVE-EXP", 358 | "exponential", 359 | "relative mesh vertex density steps with scaling", 360 | ), 361 | ], 362 | default="MANUAL", 363 | ) 364 | 365 | ## 366 | # Action Menu Options 367 | ## 368 | 369 | show_float_menu: BoolProperty( 370 | name="Floating Menu", 371 | default=False, 372 | ) 373 | 374 | floating_position: FloatVectorProperty( 375 | name="Floating Offset", 376 | soft_min=0, 377 | soft_max=100, 378 | size=2, 379 | default=(100, 0), 380 | ) 381 | 382 | double_click_mode: EnumProperty( 383 | name="Double Click Mode", 384 | items=double_click_items, 385 | default="wm.window_fullscreen_toggle", 386 | ) 387 | 388 | menu_sets: CollectionProperty( 389 | type=TOUCHVIEW_PG_MenuModeGroup, 390 | options={"LIBRARY_EDITABLE"}, 391 | ) 392 | 393 | ## 394 | # UI Panel Controls 395 | ## 396 | 397 | active_menu: EnumProperty( 398 | name="Mode Settings", 399 | items=edit_modes, 400 | ) 401 | 402 | gizmo_tabs: EnumProperty( 403 | name="Gizmo Tabs", 404 | items=[ 405 | ("GIZMO", "Gizmo", "", 0), 406 | ("ACTIONS", "Action", "", 1), 407 | ], 408 | default="GIZMO", 409 | ) 410 | 411 | def to_dict(self): 412 | return { 413 | "is_enabled": self.is_enabled, 414 | "header_toggle_position": self.header_toggle_position, 415 | "lazy_mode": self.lazy_mode, 416 | "enable_floating_toggle": self.enable_floating_toggle, 417 | "toggle_position": list(self.toggle_position), 418 | "toggle_color": list(self.toggle_color), 419 | "is_visible": self.isVisible, 420 | "input_mode": self.input_mode, 421 | "enable_double_click": self.enable_double_click, 422 | "double_click_mode": self.double_click_mode, 423 | "enable_right_click": self.enable_right_click, 424 | "right_click_mode": self.right_click_mode, 425 | "right_click_source": self.right_click_source, 426 | "swap_panrotate": self.swap_panrotate, 427 | "width": self.width, 428 | "radius": self.radius, 429 | "use_multiple_colors": self.use_multiple_colors, 430 | "overlay_main_color": list(self.overlay_main_color), 431 | "overlay_secondary_color": list(self.overlay_secondary_color), 432 | "show_menu": self.show_menu, 433 | "show_gizmos": self.show_gizmos, 434 | "menu_style": self.menu_style, 435 | "menu_orientation": self.menu_orientation, 436 | "menu_spacing": self.menu_spacing, 437 | "gizmo_padding": self.gizmo_padding, 438 | "gizmo_scale": self.gizmo_scale, 439 | "menu_position": list(self.menu_position), 440 | "show_undoredo": self.show_undoredo, 441 | "show_is_enabled": self.show_is_enabled, 442 | "show_control_gizmo": self.show_control_gizmo, 443 | "show_show_fullscreen": self.show_show_fullscreen, 444 | "show_region_quadviews": self.show_region_quadviews, 445 | "show_pivot_mode": self.show_pivot_mode, 446 | "show_snap_view": self.show_snap_view, 447 | "show_n_panel": self.show_n_panel, 448 | "show_lock_rotation": self.show_lock_rotation, 449 | "show_multires": self.show_multires, 450 | "show_voxel_remesh": self.show_voxel_remesh, 451 | "show_brush_dynamics": self.show_brush_dynamics, 452 | "gizmo_position": self.gizmo_position, 453 | "subdivision_limit": self.subdivision_limit, 454 | "pivot_mode": self.pivot_mode, 455 | "topology_mode": self.topology_mode, 456 | "show_float_menu": self.show_float_menu, 457 | "floating_position": list(self.floating_position), 458 | "active_menu": self.active_menu, 459 | "gizmo_tabs": self.gizmo_tabs, 460 | "menu_sets": [m.to_dict() for m in self.menu_sets], 461 | } 462 | 463 | def from_dict(self, data: dict): 464 | self.is_enabled = data.get("is_enabled", True) 465 | self.header_toggle_position = data.get("header_toggle_position", "RIGHT") 466 | self.lazy_mode = data.get("lazy_mode", False) 467 | self.enable_floating_toggle = data.get("enable_floating_toggle", False) 468 | self.toggle_position = data.get("toggle_position", (0, 0)) 469 | self.toggle_color = data.get("toggle_color", (0.1, 0.1, 0.2, 0.5)) 470 | self.isVisible = data.get("is_visible", False) 471 | self.input_mode = data.get("input_mode", "FULL") 472 | self.enable_double_click = data.get("enable_double_click", True) 473 | self.double_click_mode = data.get("double_click_mode", "screen.screen_full_area") 474 | self.enable_right_click = data.get("enable_right_click", True) 475 | self.right_click_mode = data.get("right_click_mode", "wm.window_fullscreen_toggle") 476 | self.right_click_source = data.get("right_click_source", "MOUSE") 477 | self.swap_panrotate = data.get("swap_panrotate", False) 478 | self.width = data.get("width", 40.0) 479 | self.radius = data.get("radius", 35.0) 480 | self.use_multiple_colors = data.get("use_multiple_colors", False) 481 | self.overlay_main_color = data.get("overlay_main_color", (1.0, 1.0, 1.0, 0.01)) 482 | self.overlay_secondary_color = data.get("overlay_secondary_color", (1.0, 1.0, 1.0, 0.01)) 483 | self.show_menu = data.get("show_menu", True) 484 | self.show_gizmos = data.get("show_gizmos", True) 485 | self.menu_style = data.get("menu_style", "float.radial") 486 | self.menu_orientation = data.get("menu_orientation", "HORIZONTAL") 487 | self.menu_spacing = data.get("menu_spacing", 1.0) 488 | self.gizmo_scale = data.get("gizmo_scale", 1.0) 489 | self.gizmo_padding = data.get("gizmo_padding", 4.0) 490 | self.menu_position = data.get("menu_position", (100, 0)) 491 | self.show_undoredo = data.get("show_undoredo", True) 492 | self.show_is_enabled = data.get("show_is_enabled", True) 493 | self.show_control_gizmo = data.get("show_control_gizmo", True) 494 | self.show_show_fullscreen = data.get("show_show_fullscreen", True) 495 | self.show_region_quadviews = data.get("show_region_quadviews", True) 496 | self.show_pivot_mode = data.get("show_pivot_mode", True) 497 | self.show_snap_view = data.get("show_snap_view", True) 498 | self.show_n_panel = data.get("show_n_panel", True) 499 | self.show_lock_rotation = data.get("show_lock_rotation", True) 500 | self.show_multires = data.get("show_multires", True) 501 | self.show_voxel_remesh = data.get("show_voxel_remesh", True) 502 | self.show_brush_dynamics = data.get("show_brush_dynamics", True) 503 | self.gizmo_position = data.get("gizmo_position", "RIGHT") 504 | self.subdivision_limit = data.get("subdivision_limit", 4) 505 | self.pivot_mode = data.get("pivot_mode", "SURFACE") 506 | self.topology_mode = data.get("topology_mode", "MANUAL") 507 | self.show_float_menu = data.get("show_float_menu", False) 508 | self.floating_position = data.get("floating_position", (100, 0)) 509 | self.double_click_mode = data.get("double_click_mode", "wm.window_fullscreen_toggle") 510 | self.active_menu = data.get("active_menu", "VIEW3D") 511 | self.gizmo_tabs = data.get("gizmo_tabs", "GIZMO") 512 | self.menu_sets = [TOUCHVIEW_PG_MenuModeGroup().from_dict(m) for m in data.get("menu_sets", [])] 513 | 514 | def load(self): 515 | filename = path.abspath(path.dirname(__file__) + "/preferences.json") 516 | if not path.exists(filename): 517 | return None 518 | 519 | data = {} 520 | try: 521 | with open(filename, "r") as file: 522 | data = json.load(file) 523 | self.from_dict(data) 524 | except Exception as _: 525 | return None 526 | 527 | def save(self): 528 | filename = path.abspath(path.dirname(__file__) + "/preferences.json") 529 | with open(filename, "w") as file: 530 | json.dump(self.to_dict(), file) 531 | 532 | def draw_v4(self, context): 533 | pass 534 | 535 | # set up addon preferences UI 536 | def draw(self, context): 537 | layout = self.layout 538 | layout.use_property_decorate = False 539 | 540 | # Input Mode 541 | box = layout.box() 542 | box.label(text="Input Mode") 543 | box.use_property_split = True 544 | 545 | col = box.column() 546 | col.prop(self, "input_mode", text=UILayout.enum_item_description(self, "input_mode", self.input_mode), expand=True) 547 | col = box.column(align=True) 548 | col.prop(self, "lazy_mode") 549 | if self.input_mode == "FULL": 550 | col.prop(self, "enable_floating_toggle") 551 | 552 | # Control Zones 553 | box = layout.box() 554 | box.prop(self, "is_enabled", text="Control Zones") 555 | 556 | col = box.column() 557 | col.use_property_split = True 558 | col.active = self.is_enabled 559 | 560 | col = col.column() 561 | col.prop(self, "header_toggle_position", expand=True) 562 | col = col.column(align=True) 563 | col.prop(self, "isVisible", text="Show Overlay") 564 | col.prop(self, "swap_panrotate") 565 | col.prop(self, "use_multiple_colors") 566 | col = col.column() 567 | col.prop(self, "overlay_main_color", text="Main Color") 568 | if self.use_multiple_colors: 569 | col.prop(self, "overlay_secondary_color", text="Secondary Color") 570 | col.prop(self, "width", slider=True) 571 | col.prop(self, "radius", slider=True) 572 | 573 | # Gixmo Options 574 | main_box = layout.box() 575 | 576 | col = main_box.row(align=True) 577 | col.prop(self, "gizmo_tabs", expand=True) 578 | 579 | main_box.use_property_split = True 580 | col = main_box.column() 581 | 582 | if self.gizmo_tabs == "GIZMO": 583 | row = col.row() 584 | row.prop(self, "menu_style", expand=True) 585 | 586 | if self.menu_style == "fixed.bar": 587 | col.prop(self, "gizmo_position") 588 | elif self.menu_style == "float.radial": 589 | col.prop(self, "menu_spacing", slider=True) 590 | 591 | col.prop(self, "gizmo_scale", slider=True) 592 | col.prop(self, "gizmo_padding", slider=True) 593 | 594 | column = main_box.column() 595 | box = column.box() 596 | box.label(text="Right Click Actions") 597 | col = box.column() 598 | row = col.row() 599 | row.prop(self, "right_click_source", text="Source", expand=True) 600 | col.prop(self, "right_click_mode", text="Mode", expand=True) 601 | 602 | box = main_box.box() 603 | box.label(text="Double Click Actions") 604 | col = box.column() 605 | col.prop(self, "enable_double_click") 606 | col.prop(self, "double_click_mode", text="Mode", expand=True) 607 | 608 | col = main_box.column() 609 | col.label(text="Tool Settings") 610 | col.prop(self, "subdivision_limit", slider=True) 611 | 612 | if self.gizmo_tabs == "ACTIONS": 613 | if not self.show_float_menu: 614 | col.operator("touchview.toggle_floating_menu", text="Show Action Menu") 615 | else: 616 | col.operator("touchview.toggle_floating_menu", text="Hide Action Menu", depress=True) 617 | box = col.box() 618 | box.active = self.show_float_menu 619 | col = box.column() 620 | col.prop(self, "active_menu") 621 | mList = self.getMenuSettings(self.active_menu) 622 | for i in range(7): 623 | col.prop(mList, "menu_slot_" + str(i + 1)) 624 | 625 | ## 626 | # Data Accessors 627 | ## 628 | def getMenuSettings(self, mode: str): 629 | m = None 630 | for opts in self.menu_sets: 631 | if opts.mode == mode: 632 | m = opts 633 | if m is None: 634 | m = self.menu_sets.add() 635 | m.mode = mode 636 | ops = menu_defaults[mode] 637 | for i, o in enumerate(ops): 638 | setattr(m, "menu_slot_" + str(i + 1), o) 639 | return m 640 | 641 | def getGizmoSet(self, mode: str | int): 642 | available = list(gizmo_sets["ALL"]) 643 | 644 | if mode not in list(gizmo_sets): 645 | return available 646 | return available + list(gizmo_sets[mode]) 647 | 648 | def getShowLock(self): 649 | return self.show_lock 650 | 651 | def getWidth(self): 652 | return self.width / 100 653 | 654 | def getRadius(self): 655 | return self.radius / 100 656 | 657 | 658 | classes = ( 659 | TOUCHVIEW_PG_MenuModeGroup, 660 | TOUCHVIEW_AP_OverlaySettings, 661 | ) 662 | 663 | 664 | def register(): 665 | for cls in classes: 666 | bpy.utils.register_class(cls) 667 | 668 | 669 | def unregister(): 670 | for cls in reversed(classes): 671 | bpy.utils.unregister_class(cls) 672 | 673 | bpy.types.NODE_HT_header.remove(NODE_HT_nendo_header) 674 | bpy.types.IMAGE_HT_header.remove(NODE_HT_nendo_header) 675 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ruff 2 | fake-bpy-module-latest 3 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | line-length = 120 2 | indent-width = 4 3 | 4 | [lint] 5 | select = ["F", "I", "Q", "W"] 6 | 7 | [format] 8 | quote-style = "double" 9 | 10 | indent-style = "space" 11 | -------------------------------------------------------------------------------- /source/__init__.py: -------------------------------------------------------------------------------- 1 | from . import ops, ui, utils 2 | 3 | 4 | def register(): 5 | ops.register() 6 | ui.register() 7 | utils.register() 8 | 9 | 10 | def unregister(): 11 | ops.unregister() 12 | ui.unregister() 13 | utils.unregister() 14 | -------------------------------------------------------------------------------- /source/ops/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from . import actions, gizmo, touch 3 | 4 | 5 | def register(): 6 | actions.register() 7 | touch.register() 8 | gizmo.register() 9 | 10 | 11 | def unregister(): 12 | actions.unregister() 13 | touch.unregister() 14 | gizmo.unregister() 15 | -------------------------------------------------------------------------------- /source/ops/actions.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import bpy 4 | from bpy.types import Operator 5 | 6 | from ..utils.blender import preferences 7 | from ..utils.constants import CANCEL, FINISHED, pivot_items 8 | 9 | 10 | class TOUCHVIEW_OT_flip_tools(Operator): 11 | """Relocate Tools panel between left and right""" 12 | 13 | bl_label = "Tools Region Swap" 14 | bl_idname = "touchview.tools_region_flip" 15 | 16 | @classmethod 17 | def poll(cls, context): 18 | return context.area.type == "VIEW_3D" and context.region.type == "WINDOW" 19 | 20 | def execute(self, context): 21 | override = context.copy() 22 | override["area"] = context.area 23 | override["region"] = context.region 24 | for r in context.area.regions: 25 | if r.type == "TOOLS": 26 | override["region"] = r 27 | with context.temp_override(region=override["region"]): # type: ignore 28 | bpy.ops.screen.region_flip() 29 | return FINISHED 30 | 31 | 32 | class TOUCHVIEW_OT_next_pivot_mode(Operator): 33 | """Step through Pivot modes""" 34 | 35 | bl_label = "Use next Pivot mode" 36 | bl_idname = "touchview.step_pivot_mode" 37 | 38 | @classmethod 39 | def poll(cls, context): 40 | return context.area.type == "VIEW_3D" and context.region.type == "WINDOW" 41 | 42 | def execute(self, context): 43 | prefs = preferences() 44 | count = 0 45 | for enum, _, _ in pivot_items: 46 | if enum == prefs.pivot_mode: 47 | count += 1 48 | if count == len(pivot_items): 49 | count = 0 50 | pivot = pivot_items[count][0] 51 | bpy.ops.sculpt.set_pivot_position(mode=pivot) 52 | prefs.pivot_mode = pivot 53 | context.area.tag_redraw() 54 | return FINISHED 55 | count += 1 56 | return FINISHED 57 | 58 | 59 | class TOUCHVIEW_OT_toggle_touch_controls(Operator): 60 | """Toggle Touch Controls""" 61 | 62 | bl_label = "Toggle Touch Controls" 63 | bl_idname = "touchview.toggle_touch" 64 | 65 | def execute(self, context): 66 | prefs = preferences() 67 | prefs.is_enabled = not prefs.is_enabled 68 | context.area.tag_redraw() 69 | return FINISHED 70 | 71 | 72 | class TOUCHVIEW_OT_toggle_npanel(Operator): 73 | """Toggle Settings Panel""" 74 | 75 | bl_label = "Display prefs Panel" 76 | bl_idname = "touchview.toggle_n_panel" 77 | 78 | @classmethod 79 | def poll(cls, context): 80 | return context.area.type == "VIEW_3D" and context.region.type == "WINDOW" 81 | 82 | def execute(self, context): 83 | if not isinstance(context.space_data, bpy.types.SpaceView3D): 84 | return CANCEL 85 | context.space_data.show_region_ui ^= True 86 | return FINISHED 87 | 88 | 89 | class TOUCHVIEW_OT_toggle_floating_menu(Operator): 90 | """Toggle Floating Menu""" 91 | 92 | bl_label = "Toggle Floating Menu" 93 | bl_idname = "touchview.toggle_floating_menu" 94 | 95 | def execute(self, context): 96 | prefs = preferences() 97 | prefs.show_float_menu = not prefs.show_float_menu 98 | return FINISHED 99 | 100 | 101 | class TOUCHVIEW_OT_viewport_recenter(Operator): 102 | """Recenter Viewport and Cursor on Selected Object""" 103 | 104 | bl_label = "Recenter Viewport and Cursor on Selected" 105 | bl_idname = "touchview.viewport_recenter" 106 | 107 | def execute(self, context): 108 | current = context.scene.tool_settings.transform_pivot_point 109 | context.scene.tool_settings.transform_pivot_point = "ACTIVE_ELEMENT" 110 | bpy.ops.view3d.snap_cursor_to_selected() 111 | bpy.ops.view3d.view_center_cursor() 112 | bpy.ops.view3d.view_selected() 113 | context.scene.tool_settings.transform_pivot_point = current 114 | return FINISHED 115 | 116 | 117 | class TOUCHVIEW_OT_viewport_lock(Operator): 118 | """Toggle Viewport Rotation""" 119 | 120 | bl_label = "Viewport rotation lock toggle" 121 | bl_idname = "touchview.viewport_lock" 122 | 123 | region_ids = [] 124 | 125 | def execute(self, context): 126 | if not isinstance(context.area.spaces.active, bpy.types.SpaceView3D): 127 | return CANCEL 128 | if len(context.area.spaces.active.region_quadviews) == 0: 129 | context.region_data.lock_rotation ^= True 130 | return FINISHED 131 | 132 | for region in context.area.spaces.active.region_quadviews: 133 | self.region_ids.append((region.as_pointer(), region.lock_rotation)) 134 | 135 | start_change = False 136 | regions = dict(self.region_ids) 137 | for i in range(3, -1, -1): 138 | region_data = context.area.spaces.active.region_quadviews[i] 139 | if context.region_data.as_pointer() == region_data.as_pointer(): 140 | start_change = True 141 | context.region_data.lock_rotation ^= True 142 | continue 143 | 144 | if start_change: 145 | region_data.lock_rotation = regions[region_data.as_pointer()] 146 | self.region_ids = [] 147 | return FINISHED 148 | 149 | 150 | class TOUCHVIEW_OT_brush_resize(Operator): 151 | """Brush Resize""" 152 | 153 | bl_label = "Brush Size Adjust" 154 | bl_idname = "touchview.brush_resize" 155 | 156 | def invoke(self, context, event): 157 | self.mouse_x = event.mouse_region_x 158 | self.mouse_y = event.mouse_region_y 159 | self.execute(context) 160 | return FINISHED 161 | 162 | # activate radial_control to change sculpt brush size 163 | def execute(self, context): 164 | prefs = preferences() 165 | if prefs.menu_style in {"fixed.bar"}: 166 | if prefs.gizmo_position in ["LEFT", "RIGHT"]: 167 | context.window.cursor_warp(math.floor(context.region.width / 2), self.mouse_y) 168 | else: 169 | context.window.cursor_warp(self.mouse_x, math.floor(context.region.height / 2)) 170 | if context.mode in [ 171 | "PAINT_GPENCIL", 172 | "EDIT_GPENCIL", 173 | "SCULPT_GPENCIL", 174 | "WEIGHT_GPENCIL", 175 | "VERTEX_GPENCIL", 176 | ]: 177 | return self.resize2d(context) 178 | return self.resize3d(context) 179 | 180 | def resize2d(self, context): 181 | data_path = "tool_settings.gpencil_paint.brush.size" 182 | if context.mode == "SCULPT_GPENCIL": 183 | data_path = "tool_settings.gpencil_sculpt_paint.brush.size" 184 | if context.mode == "WEIGHT_GPENCIL": 185 | data_path = "tool_settings.gpencil_weight_paint.brush.size" 186 | if context.mode == "VERTEX_GPENCIL": 187 | data_path = "tool_settings.gpencil_vertex_paint.brush.size" 188 | bpy.ops.wm.radial_control( 189 | "INVOKE_DEFAULT", # type: ignore 190 | data_path_primary=data_path, 191 | ) 192 | return FINISHED 193 | 194 | def resize3d(self, context): 195 | data_path = "tool_settings.sculpt.brush.size" 196 | if context.mode == "PAINT_VERTEX": 197 | data_path = "tool_settings.vertex_paint.brush.size" 198 | if context.mode == "PAINT_WEIGHT": 199 | data_path = "tool_settings.weight_paint.brush.size" 200 | if context.mode == "PAINT_IMAGE": 201 | data_path = "tool_settings.image_paint.brush.size" 202 | if context.mode == "PAINT_TEXTURE": 203 | data_path = "tool_settings.image_paint.brush.size" 204 | bpy.ops.wm.radial_control( 205 | "INVOKE_DEFAULT", # type: ignore 206 | data_path_primary=data_path, 207 | data_path_secondary="tool_settings.unified_paint_settings.size", 208 | use_secondary=("tool_settings.unified_paint_settings.use_unified_size"), 209 | rotation_path="tool_settings.sculpt.brush.texture_slot.angle", 210 | color_path="tool_settings.sculpt.brush.cursor_color_add", 211 | image_id="tool_settings.sculpt.brush", 212 | ) 213 | return FINISHED 214 | 215 | 216 | class TOUCHVIEW_OT_brush_strength(Operator): 217 | """Brush Strength""" 218 | 219 | bl_label = "Brush Strength Adjust" 220 | bl_idname = "touchview.brush_strength" 221 | 222 | def invoke(self, context, event): 223 | self.mouse_x = event.mouse_region_x 224 | self.mouse_y = event.mouse_region_y 225 | self.execute(context) 226 | return FINISHED 227 | 228 | # activate radial_control to change sculpt brush size 229 | def execute(self, context): 230 | prefs = preferences() 231 | if prefs.menu_style in {"fixed.bar"}: 232 | if prefs.gizmo_position in ["LEFT", "RIGHT"]: 233 | context.window.cursor_warp(math.floor(context.region.width / 2), self.mouse_y) 234 | else: 235 | context.window.cursor_warp(self.mouse_x, math.floor(context.region.height / 2)) 236 | if context.mode in [ 237 | "PAINT_GPENCIL", 238 | "EDIT_GPENCIL", 239 | "SCULPT_GPENCIL", 240 | "WEIGHT_GPENCIL", 241 | "VERTEX_GPENCIL", 242 | ]: 243 | return self.resize2d(context) 244 | return self.resize3d(context) 245 | 246 | def resize2d(self, context): 247 | data_path = "tool_settings.gpencil_paint.brush.gpencil_settings.pen_strength" 248 | if context.mode == "SCULPT_GPENCIL": 249 | data_path = "tool_settings.gpencil_sculpt_paint.brush.strength" 250 | if context.mode == "WEIGHT_GPENCIL": 251 | data_path = "tool_settings.gpencil_weight_paint.brush.strength" 252 | if context.mode == "VERTEX_GPENCIL": 253 | data_path = "tool_settings.gpencil_vertex_paint.brush.gpencil_settings.pen_strength" 254 | bpy.ops.wm.radial_control( 255 | "INVOKE_DEFAULT", # type: ignore 256 | data_path_primary=data_path, 257 | ) 258 | return FINISHED 259 | 260 | def resize3d(self, context): 261 | data_path = "tool_settings.sculpt.brush.strength" 262 | if context.mode == "PAINT_VERTEX": 263 | data_path = "tool_settings.vertex_paint.brush.strength" 264 | if context.mode == "PAINT_WEIGHT": 265 | data_path = "tool_settings.weight_paint.brush.strength" 266 | if context.mode == "PAINT_IMAGE": 267 | data_path = "tool_settings.image_paint.brush.strength" 268 | if context.mode == "PAINT_TEXTURE": 269 | data_path = "tool_settings.image_paint.brush.strength" 270 | bpy.ops.wm.radial_control( 271 | "INVOKE_DEFAULT", # type: ignore 272 | data_path_primary=data_path, 273 | data_path_secondary=("tool_settings.unified_paint_settings.strength"), 274 | use_secondary=("tool_settings.unified_paint_settings.use_unified_strength"), 275 | rotation_path="tool_settings.sculpt.brush.texture_slot.angle", 276 | color_path="tool_settings.sculpt.brush.cursor_color_add", 277 | image_id="tool_settings.sculpt.brush", 278 | ) 279 | return FINISHED 280 | 281 | 282 | class TOUCHVIEW_OT_increase_multires(Operator): 283 | """Increment Multires by 1 or add subdivision""" 284 | 285 | bl_label = "Increment Multires modifier by 1 or add subdivision level" 286 | bl_idname = "touchview.increment_multires" 287 | 288 | def execute(self, context): 289 | prefs = preferences() 290 | if not context.active_object or not len(context.active_object.modifiers): 291 | return CANCEL 292 | for mod in context.active_object.modifiers: 293 | # if mod is type of bpy.types.MultiresModifier 294 | if isinstance(mod, bpy.types.MultiresModifier): 295 | if context.mode == "SCULPT": 296 | if mod.sculpt_levels == mod.total_levels: 297 | if mod.sculpt_levels < prefs.subdivision_limit: 298 | bpy.ops.object.multires_subdivide(modifier=mod.name) 299 | else: 300 | mod.sculpt_levels += 1 301 | else: 302 | if mod.levels == mod.total_levels: 303 | if mod.levels < prefs.subdivision_limit: 304 | bpy.ops.object.multires_subdivide(modifier=mod.name) 305 | else: 306 | mod.levels += 1 307 | return FINISHED 308 | return CANCEL 309 | 310 | 311 | class TOUCHVIEW_OT_decrease_multires(Operator): 312 | """Decrement Multires by 1""" 313 | 314 | bl_label = "decrement Multires modifier by 1" 315 | bl_idname = "touchview.decrement_multires" 316 | 317 | def execute(self, context): 318 | if not context.active_object or not len(context.active_object.modifiers): 319 | return CANCEL 320 | for mod in context.active_object.modifiers: 321 | if not isinstance(mod, bpy.types.MultiresModifier): 322 | return FINISHED 323 | if context.mode == "SCULPT": 324 | if mod.sculpt_levels == 0: 325 | bpy.ops.object.multires_unsubdivide(modifier=mod.name) 326 | else: 327 | mod.sculpt_levels -= 1 328 | else: 329 | if mod.levels == 0: 330 | bpy.ops.object.multires_unsubdivide(modifier=mod.name) 331 | else: 332 | mod.levels -= 1 333 | return FINISHED 334 | return CANCEL 335 | 336 | 337 | class TOUCHVIEW_OT_density_up(Operator): 338 | """Increase voxel density""" 339 | 340 | bl_label = "Increase voxel density and remesh" 341 | bl_idname = "touchview.density_up" 342 | 343 | def execute(self, context): 344 | if not context.active_object: 345 | return CANCEL 346 | for mod in context.active_object.modifiers: 347 | if isinstance(mod, bpy.types.MultiresModifier): 348 | return CANCEL 349 | mesh = bpy.data.meshes[context.active_object.name] 350 | mesh.remesh_voxel_size *= 0.8 351 | bpy.ops.object.voxel_remesh() 352 | return FINISHED 353 | 354 | 355 | class TOUCHVIEW_OT_density_down(Operator): 356 | """Decrease voxel density""" 357 | 358 | bl_label = "Decrease voxel density and remesh" 359 | bl_idname = "touchview.density_down" 360 | 361 | def execute(self, context): 362 | if not context.active_object: 363 | return CANCEL 364 | for mod in context.active_object.modifiers: 365 | if isinstance(mod, bpy.types.MultiresModifier): 366 | return CANCEL 367 | mesh = bpy.data.meshes[context.active_object.name] 368 | mesh.remesh_voxel_size /= 0.8 369 | bpy.ops.object.voxel_remesh() 370 | return FINISHED 371 | 372 | 373 | classes = ( 374 | TOUCHVIEW_OT_brush_resize, 375 | TOUCHVIEW_OT_brush_strength, 376 | TOUCHVIEW_OT_decrease_multires, 377 | TOUCHVIEW_OT_density_down, 378 | TOUCHVIEW_OT_density_up, 379 | TOUCHVIEW_OT_flip_tools, 380 | TOUCHVIEW_OT_increase_multires, 381 | TOUCHVIEW_OT_next_pivot_mode, 382 | TOUCHVIEW_OT_toggle_floating_menu, 383 | TOUCHVIEW_OT_toggle_npanel, 384 | TOUCHVIEW_OT_toggle_touch_controls, 385 | TOUCHVIEW_OT_viewport_lock, 386 | TOUCHVIEW_OT_viewport_recenter, 387 | ) 388 | 389 | 390 | register, unregister = bpy.utils.register_classes_factory(classes) 391 | -------------------------------------------------------------------------------- /source/ops/gizmo.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from bpy.types import Operator 3 | from mathutils import Vector 4 | 5 | from ..utils.blender import * 6 | from ..utils.constants import CANCEL, FINISHED, MODAL 7 | 8 | 9 | class TOUCHVIEW_OT_move_float_menu(Operator): 10 | bl_label = "Relocate Gizmo Menu" 11 | bl_idname = "touchview.move_float_menu" 12 | 13 | def invoke(self, context, event): 14 | self.has_moved = False 15 | prefs = preferences() 16 | fence = safe_area_3d(padding=90) 17 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 18 | 19 | self.init_x = prefs.menu_position[0] 20 | self.init_y = prefs.menu_position[1] 21 | self.mouse_init_x = self.x = event.mouse_region_x 22 | self.mouse_init_y = self.y = event.mouse_region_y 23 | self.offset = Vector( 24 | ( 25 | (span.x * self.init_x * 0.01 + fence[0].x) - self.x, 26 | (span.y * self.init_y * 0.01 + fence[0].y) - self.y, 27 | ) 28 | ) 29 | self.execute(context) 30 | 31 | context.window_manager.modal_handler_add(self) 32 | return MODAL 33 | 34 | def execute(self, context): 35 | prefs = preferences() 36 | fence = safe_area_3d(padding=90) 37 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 38 | 39 | prefs.menu_position[0] = min(max((self.x - fence[0].x + self.offset.x) / (span.x) * 100.0, 0.0), 100.0) 40 | prefs.menu_position[1] = min(max((self.y - fence[0].y + self.offset.y) / (span.y) * 100.0, 0.0), 100.0) 41 | return FINISHED 42 | 43 | def modal(self, context, event): 44 | prefs = preferences() 45 | if event.type == "MOUSEMOVE" and event.value != "RELEASE": # Apply 46 | context.region.tag_redraw() 47 | self.x = event.mouse_region_x 48 | self.y = event.mouse_region_y 49 | self.execute(context) 50 | elif event.value == "RELEASE": # Confirm 51 | if not self.__hasMoved(): 52 | prefs.menu_position[0] = self.init_x 53 | prefs.menu_position[1] = self.init_y 54 | prefs.show_gizmos = not prefs.show_gizmos 55 | return FINISHED 56 | return MODAL 57 | 58 | def __hasMoved(self) -> bool: 59 | prefs = preferences() 60 | init = Vector((self.mouse_init_x, self.mouse_init_y)) 61 | final = Vector((self.x, self.y)) 62 | if (final - init).length > prefs.menu_spacing / 2: 63 | return True 64 | return False 65 | 66 | 67 | class TOUCHVIEW_OT_menu_controller(Operator): 68 | bl_label = "Relocate Action Menu" 69 | bl_idname = "touchview.move_action_menu" 70 | 71 | def invoke(self, context, event): 72 | self.has_moved = False 73 | prefs = preferences() 74 | fence = safe_area_3d() 75 | 76 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 77 | self.init_x = prefs.floating_position[0] 78 | self.init_y = prefs.floating_position[1] 79 | self.mouse_init_x = self.x = event.mouse_region_x 80 | self.mouse_init_y = self.y = event.mouse_region_y 81 | self.offset = Vector( 82 | ( 83 | (span.x * self.init_x * 0.01 + fence[0].x) - self.x, 84 | (span.y * self.init_y * 0.01 + fence[0].y) - self.y, 85 | ) 86 | ) 87 | self.execute(context) 88 | 89 | context.window_manager.modal_handler_add(self) 90 | return MODAL 91 | 92 | def execute(self, context): 93 | prefs = preferences() 94 | fence = safe_area_3d() 95 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 96 | 97 | prefs.floating_position[0] = min(max((self.x - fence[0].x + self.offset.x) / (span.x) * 100.0, 0.0), 100.0) 98 | prefs.floating_position[1] = min(max((self.y - fence[0].y + self.offset.y) / (span.y) * 100.0, 0.0), 100.0) 99 | return FINISHED 100 | 101 | def modal(self, context, event): 102 | prefs = preferences() 103 | if event.type == "MOUSEMOVE" and event.value != "RELEASE": # Apply 104 | context.region.tag_redraw() 105 | self.x = event.mouse_region_x 106 | self.y = event.mouse_region_y 107 | self.execute(context) 108 | elif event.value == "RELEASE": # Confirm 109 | if not self.__hasMoved(): 110 | prefs.floating_position[0] = self.init_x 111 | prefs.floating_position[1] = self.init_y 112 | bpy.ops.wm.call_menu_pie( 113 | "INVOKE_DEFAULT", # type: ignore 114 | name="TOUCHVIEW_MT_floating", 115 | ) 116 | return FINISHED 117 | return MODAL 118 | 119 | def __hasMoved(self) -> bool: 120 | prefs = preferences() 121 | init = Vector((self.mouse_init_x, self.mouse_init_y)) 122 | final = Vector((self.x, self.y)) 123 | if (final - init).length > prefs.menu_spacing / 2: 124 | return True 125 | return False 126 | 127 | 128 | class TOUCHVIEW_OT_cycle_controlGizmo(Operator): 129 | bl_label = "switch object control gizmo" 130 | bl_idname = "touchview.cycle_control_gizmo" 131 | 132 | @classmethod 133 | def poll(cls, context): 134 | return context.area.type in ["VIEW_2D", "VIEW_3D"] and context.region.type == "WINDOW" 135 | 136 | def execute(self, context): 137 | space = context.space_data 138 | if not isinstance(space, bpy.types.SpaceView3D): 139 | return CANCEL 140 | mode = self.getMode(space) 141 | self.clearControls(space) 142 | if mode == "none": 143 | space.show_gizmo_object_translate = True 144 | if mode == "translate": 145 | space.show_gizmo_object_rotate = True 146 | if mode == "rotate": 147 | space.show_gizmo_object_scale = True 148 | return FINISHED 149 | 150 | def getMode(self, space: bpy.types.SpaceView3D): 151 | if space.show_gizmo_object_translate: 152 | return "translate" 153 | if space.show_gizmo_object_rotate: 154 | return "rotate" 155 | if space.show_gizmo_object_scale: 156 | return "scale" 157 | return "none" 158 | 159 | def clearControls(self, space: bpy.types.SpaceView3D): 160 | space.show_gizmo_object_translate = False 161 | space.show_gizmo_object_rotate = False 162 | space.show_gizmo_object_scale = False 163 | 164 | 165 | class TOUCHVIEW_OT_float_controller(Operator): 166 | bl_label = "Relocate Toggle Button" 167 | bl_idname = "touchview.move_toggle_button" 168 | 169 | def invoke(self, context, event): 170 | self.has_moved = False 171 | prefs = preferences() 172 | fence = safe_area_3d() 173 | 174 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 175 | self.init_x = prefs.toggle_position[0] 176 | self.init_y = prefs.toggle_position[1] 177 | self.mouse_init_x = self.x = event.mouse_region_x 178 | self.mouse_init_y = self.y = event.mouse_region_y 179 | self.offset = Vector( 180 | ( 181 | (span.x * self.init_x * 0.01 + fence[0].x) - self.x, 182 | (span.y * self.init_y * 0.01 + fence[0].y) - self.y, 183 | ) 184 | ) 185 | self.execute(context) 186 | 187 | context.window_manager.modal_handler_add(self) 188 | return MODAL 189 | 190 | def execute(self, context): 191 | prefs = preferences() 192 | fence = safe_area_3d() 193 | span = Vector((fence[1].x - fence[0].x, fence[1].y - fence[0].y)) 194 | 195 | prefs.toggle_position[0] = min(max((self.x - fence[0].x + self.offset.x) / (span.x) * 100.0, 0.0), 100.0) 196 | prefs.toggle_position[1] = min(max((self.y - fence[0].y + self.offset.y) / (span.y) * 100.0, 0.0), 100.0) 197 | return FINISHED 198 | 199 | def modal(self, context, event): 200 | prefs = preferences() 201 | if ( 202 | event.mouse_region_x < 0 203 | or event.mouse_region_y < 0 204 | or event.mouse_region_x > context.area.width 205 | or event.mouse_region_y > context.area.height 206 | ): 207 | # mouse out of region area broken in Blender 4.x, exit early 208 | return FINISHED 209 | if event.type == "MOUSEMOVE" and event.value != "RELEASE": # Apply 210 | context.region.tag_redraw() 211 | self.x = event.mouse_region_x 212 | self.y = event.mouse_region_y 213 | self.execute(context) 214 | elif event.value == "RELEASE": # Confirm 215 | if not self.__hasMoved(): 216 | prefs.toggle_position[0] = self.init_x 217 | prefs.toggle_position[1] = self.init_y 218 | prefs.is_enabled = not prefs.is_enabled 219 | return FINISHED 220 | return MODAL 221 | 222 | def __hasMoved(self) -> bool: 223 | prefs = preferences() 224 | init = Vector((self.mouse_init_x, self.mouse_init_y)) 225 | final = Vector((self.x, self.y)) 226 | if (final - init).length > prefs.menu_spacing / 2: 227 | return True 228 | return False 229 | 230 | 231 | classes = ( 232 | TOUCHVIEW_OT_move_float_menu, 233 | TOUCHVIEW_OT_menu_controller, 234 | TOUCHVIEW_OT_cycle_controlGizmo, 235 | TOUCHVIEW_OT_float_controller, 236 | ) 237 | 238 | 239 | register, unregister = bpy.utils.register_classes_factory(classes) 240 | -------------------------------------------------------------------------------- /source/ops/touch.py: -------------------------------------------------------------------------------- 1 | # Built-in modules 2 | import math 3 | 4 | import bpy 5 | from bpy.props import EnumProperty 6 | from bpy.types import Operator 7 | from bpy_extras.view3d_utils import (region_2d_to_origin_3d, 8 | region_2d_to_vector_3d) 9 | from mathutils import Vector 10 | 11 | # Local modules 12 | from ..utils.blender import preferences 13 | from ..utils.constants import (FINISHED, LMOUSE, PASSTHROUGH, PEN, PRESS, 14 | RMOUSE, brush_modes, input_mode_items) 15 | 16 | 17 | def is_touch(event): 18 | return event.pressure in [0.0, 1.0] 19 | 20 | 21 | class TOUCHVIEW_OT_right_click_action(Operator): 22 | """Viewport right-click shortcut""" 23 | 24 | bl_label = "Viewport right-click shortcut" 25 | bl_idname = "touchview.rc_action" 26 | 27 | @classmethod 28 | def poll(cls, context): 29 | return context.area.type in {"VIEW_2D", "VIEW_3D"} and context.region.type == "WINDOW" 30 | 31 | def invoke(self, context, event): 32 | prefs = preferences() 33 | if prefs.right_click_source == "NONE": 34 | return PASSTHROUGH 35 | if event.type not in [RMOUSE]: 36 | return PASSTHROUGH 37 | if is_touch(event) and prefs.right_click_source == "PEN": 38 | return PASSTHROUGH 39 | if not is_touch(event) and prefs.right_click_source == "MOUSE": 40 | return PASSTHROUGH 41 | if event.value == "DOUBLE_CLICK": 42 | return PASSTHROUGH 43 | self.execute(context) 44 | return FINISHED 45 | 46 | def execute(self, context): 47 | prefs = preferences() 48 | op = prefs.right_click_mode.split(".") 49 | if op[1] == "transfer_mode" and context.area.type != "VIEW_3D": 50 | return PASSTHROUGH 51 | if op[1] == "transfer_mode" and context.mode == "OBJECT": 52 | bpy.ops.view3d.select("INVOKE_DEFAULT") # type: ignore 53 | return PASSTHROUGH 54 | opgrp = getattr(bpy.ops, op[0]) 55 | getattr(opgrp, op[1])("INVOKE_DEFAULT") 56 | return FINISHED 57 | 58 | 59 | class TOUCHVIEW_OT_double_click_action(Operator): 60 | """Viewport double-tap shortcut""" 61 | 62 | bl_label = "Viewport double-tap shortcut" 63 | bl_idname = "touchview.dt_action" 64 | 65 | @classmethod 66 | def poll(cls, context): 67 | return context.area.type in {"NODE_EDITOR", "VIEW_2D", "VIEW_3D", "IMAGE_EDITOR"} and context.region.type == "WINDOW" 68 | 69 | def invoke(self, context, event): 70 | if event.type not in [PEN, LMOUSE]: 71 | return PASSTHROUGH 72 | if not is_touch(event): 73 | return PASSTHROUGH 74 | if event.value != "DOUBLE_CLICK": 75 | return PASSTHROUGH 76 | return self.execute(context) 77 | 78 | def execute(self, context): 79 | prefs = preferences() 80 | if not prefs.enable_double_click: 81 | return PASSTHROUGH 82 | op = prefs.double_click_mode.split(".") 83 | opgrp = getattr(bpy.ops, op[0]) 84 | if op[1] == "transfer_mode" and context.area.type != "VIEW_3D": 85 | return PASSTHROUGH 86 | if op[1] == "transfer_mode" and context.mode == "OBJECT": 87 | bpy.ops.view3d.select("INVOKE_DEFAULT") # type: ignore 88 | return PASSTHROUGH 89 | getattr(opgrp, op[1])("INVOKE_DEFAULT") 90 | return FINISHED 91 | 92 | 93 | class TOUCHVIEW_OT_touch_input_2d(Operator): 94 | """Active Viewport control zones""" 95 | 96 | bl_label = "2D Viewport Control Regions" 97 | bl_idname = "touchview.view_ops_2d" 98 | 99 | delta: tuple[float, float] 100 | 101 | mode: EnumProperty( # type: ignore 102 | name="Mode", 103 | description="Sets the viewport control type", 104 | items=input_mode_items, 105 | default="PAN", 106 | options={"HIDDEN"}, 107 | ) 108 | 109 | @classmethod 110 | def poll(cls, context): 111 | return context.area.type in {"NODE_EDITOR", "VIEW_2D", "IMAGE_EDITOR"} and context.region.type == "WINDOW" 112 | 113 | def invoke(self, context, event): 114 | prefs = preferences() 115 | if not prefs.is_enabled: 116 | return PASSTHROUGH 117 | if prefs.input_mode == "FULL" and (event.type == PEN or not is_touch(event)): 118 | return PASSTHROUGH 119 | 120 | if event.value != PRESS: 121 | return PASSTHROUGH 122 | self.delta = (event.mouse_region_x, event.mouse_region_y) 123 | 124 | mid_point = Vector((context.region.width / 2, context.region.height / 2)) 125 | 126 | dolly_scale = prefs.getWidth() 127 | dolly_wid = mid_point.x * dolly_scale 128 | 129 | if dolly_wid > self.delta[0] or self.delta[0] > context.region.width - dolly_wid: 130 | self.mode = "DOLLY" 131 | else: 132 | self.mode = "PAN" 133 | 134 | if prefs.swap_panrotate: 135 | if self.mode == "PAN": 136 | self.mode = "ORBIT" 137 | elif self.mode == "ORBIT": 138 | self.mode = "PAN" 139 | 140 | self.execute(context) 141 | return FINISHED 142 | 143 | def execute(self, context): 144 | if context.area.type == "IMAGE_EDITOR": 145 | return self.exec_image_editor(context) 146 | if self.mode == "DOLLY": 147 | bpy.ops.view2d.zoom("INVOKE_DEFAULT") # type: ignore 148 | elif self.mode == "PAN": 149 | bpy.ops.view2d.pan("INVOKE_DEFAULT") # type: ignore 150 | return FINISHED 151 | 152 | def exec_image_editor(self, context): 153 | if self.mode == "PAN": 154 | bpy.ops.image.view_pan("INVOKE_DEFAULT") # type: ignore 155 | elif self.mode == "DOLLY": 156 | bpy.ops.image.view_zoom("INVOKE_DEFAULT") # type: ignore 157 | return FINISHED 158 | 159 | 160 | class TOUCHVIEW_OT_touch_input_3d(Operator): 161 | """Active Viewport control zones""" 162 | 163 | bl_label = "Viewport Control Regions" 164 | bl_idname = "touchview.view_ops_3d" 165 | 166 | delta: tuple[float, float] 167 | 168 | mode: EnumProperty( # type: ignore 169 | name="Mode", 170 | description="Sets the viewport control type", 171 | items=input_mode_items, 172 | options={"HIDDEN"}, 173 | default="ORBIT", 174 | ) 175 | 176 | @classmethod 177 | def poll(cls, context): 178 | return context.area.type == "VIEW_3D" and context.region.type == "WINDOW" 179 | 180 | def invoke(self, context, event): 181 | prefs = preferences() 182 | passcheck = self.should_pass(context, event) 183 | if passcheck: 184 | return PASSTHROUGH 185 | 186 | self.delta = (event.mouse_region_x, event.mouse_region_y) 187 | 188 | mid_point = Vector((context.region.width / 2, context.region.height / 2)) 189 | 190 | dolly_scale = prefs.getWidth() 191 | pan_scale = prefs.getRadius() 192 | 193 | dolly_wid = mid_point.x * dolly_scale 194 | pan_diameter = math.dist( 195 | (0, 0), 196 | mid_point, # type: ignore 197 | ) * (pan_scale * 0.5) 198 | 199 | is_quadview_orthographic = context.region_data.is_orthographic_side_view and context.region.alignment == "QUAD_SPLIT" 200 | is_locked = context.region_data.lock_rotation or is_quadview_orthographic 201 | 202 | if dolly_wid > self.delta[0] or self.delta[0] > context.region.width - dolly_wid: 203 | self.mode = "DOLLY" 204 | elif ( 205 | math.dist( 206 | self.delta, 207 | mid_point, # type: ignore 208 | ) 209 | < pan_diameter 210 | or is_locked 211 | ): 212 | self.mode = "PAN" 213 | else: 214 | self.mode = "ORBIT" 215 | 216 | if prefs.swap_panrotate and not is_locked: 217 | if self.mode == "PAN": 218 | self.mode = "ORBIT" 219 | elif self.mode == "ORBIT": 220 | self.mode = "PAN" 221 | 222 | if context.mode == "SCULPT": 223 | bpy.ops.sculpt.set_pivot_position(mode=prefs.pivot_mode) 224 | self.execute(context) 225 | return FINISHED 226 | 227 | def execute(self, context): 228 | if self.mode == "DOLLY": 229 | bpy.ops.view3d.zoom("INVOKE_DEFAULT") # type: ignore 230 | elif self.mode == "ORBIT": 231 | if context.mode == "SCULPT": 232 | bpy.ops.sculpt.set_pivot_position(mode="SURFACE", mouse_x=self.delta[0], mouse_y=self.delta[1]) 233 | bpy.ops.view3d.rotate("INVOKE_DEFAULT") # type: ignore 234 | elif self.mode == "PAN": 235 | bpy.ops.view3d.move("INVOKE_DEFAULT") # type: ignore 236 | return FINISHED 237 | 238 | def should_pass(self, context, event): 239 | prefs = preferences() 240 | 241 | # experimental passthrough in drawing mode 242 | if ( 243 | prefs.lazy_mode 244 | and not prefs.is_enabled 245 | and event.value == PRESS 246 | and brush_modes.__contains__(context.mode) 247 | and self.mouseTarget(context, event) != context.active_object 248 | ): 249 | return False 250 | 251 | if not prefs.is_enabled: 252 | return True 253 | 254 | if prefs.input_mode == "FULL" and (event.type == PEN or not is_touch(event)): 255 | return True 256 | 257 | if event.value != PRESS: 258 | return True 259 | return False 260 | 261 | def mouseTarget(self, context, event): 262 | # get the context arguments 263 | region = context.region 264 | rv3d = context.region_data 265 | coord = Vector((event.mouse_region_x, event.mouse_region_y)) 266 | 267 | # get the ray from the viewport and mouse 268 | view_vector = region_2d_to_vector_3d(region, rv3d, coord) 269 | self.ray_origin = region_2d_to_origin_3d(region, rv3d, coord) 270 | 271 | self.ray_target = self.ray_origin + view_vector 272 | return self.isCurrentObject(context) 273 | 274 | def visible_objects_and_duplicates(self, context): 275 | depsgraph = context.evaluated_depsgraph_get() 276 | for dup in depsgraph.object_instances: 277 | if dup.is_instance: # Real dupli instance 278 | obj = dup.instance_object 279 | yield (obj, dup.matrix_world.copy()) # type: ignore 280 | else: # Usual object 281 | obj = dup.object 282 | yield (obj, obj.matrix_world.copy()) # type: ignore 283 | 284 | def obj_ray_cast(self, obj, matrix): 285 | # get the ray relative to the object 286 | matrix_inv = matrix.inverted() 287 | ray_origin_obj = matrix_inv @ self.ray_origin 288 | ray_target_obj = matrix_inv @ self.ray_target 289 | ray_direction_obj = ray_target_obj - ray_origin_obj 290 | 291 | # cast the ray 292 | success, location, normal, face_index = obj.ray_cast(ray_origin_obj, ray_direction_obj) 293 | 294 | if success: 295 | return location, normal, face_index 296 | else: 297 | return None, None, None 298 | 299 | def isCurrentObject(self, context): 300 | # cast rays and find the closest object 301 | best_length_squared = -1.0 302 | best_obj = None 303 | 304 | for obj, matrix in self.visible_objects_and_duplicates(context): 305 | if obj.type == "MESH": 306 | hit, _, _ = self.obj_ray_cast(obj, matrix) 307 | if hit is not None: 308 | hit_world = matrix @ hit 309 | length_squared = (hit_world - self.ray_origin).length_squared 310 | if best_obj is None or length_squared < best_length_squared: 311 | best_length_squared = length_squared 312 | best_obj = obj 313 | 314 | return best_obj.original if best_obj is not None else None 315 | 316 | 317 | classes = ( 318 | TOUCHVIEW_OT_right_click_action, 319 | TOUCHVIEW_OT_double_click_action, 320 | TOUCHVIEW_OT_touch_input_2d, 321 | TOUCHVIEW_OT_touch_input_3d, 322 | ) 323 | 324 | 325 | register, unregister = bpy.utils.register_classes_factory(classes) 326 | -------------------------------------------------------------------------------- /source/ui/__init__.py: -------------------------------------------------------------------------------- 1 | ### 2 | # Gizmo structure update 3 | # 4 | # Refactor the gizmo structure to be more modular and easier to maintain. 5 | # Gizmo context (UI, space, etc), state (2-mode, 3-mode, etc), 6 | # layout (vertical, horizontal, etc) 7 | # to be managed through inheritance. 8 | ### 9 | from . import gizmo_group_2d, panel 10 | 11 | 12 | def register(): 13 | gizmo_group_2d.register() 14 | panel.register() 15 | 16 | 17 | def unregister(): 18 | gizmo_group_2d.unregister() 19 | panel.unregister() 20 | -------------------------------------------------------------------------------- /source/ui/gizmo_2d.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from mathutils import Matrix, Vector 3 | 4 | from ..utils.blender import * 5 | from .gizmo_config import gizmo_colors, toggle_colors 6 | 7 | ## 8 | # GizmoSet 9 | # - single-state 10 | # - one icon 11 | # - one action 12 | # - possible toggle by variable state 13 | # 14 | # - 2-state (boolean) 15 | # - 2 icons 16 | # - 2 actions (or 1 action for both icons) 17 | # 18 | ## 19 | 20 | 21 | class GizmoSet: 22 | group: bpy.types.GizmoGroup 23 | 24 | def setup(self, group: bpy.types.GizmoGroup, config: dict): 25 | self.visible = True 26 | self.config = config 27 | self.has_dependent = "has_dependent" in config or False 28 | self.group = group 29 | self.scale = config["scale"] if ("scale" in config) else 14 30 | self.binding = config["binding"] 31 | self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False 32 | self.primary = self.__buildGizmo(config["command"], config["icon"]) 33 | 34 | def draw_prepare(self): 35 | prefs = preferences() 36 | self.hidden = not prefs.show_gizmos 37 | self.skip_draw = False 38 | self.__updatevisible() 39 | 40 | if self.binding["name"] == "float_menu": 41 | self.primary.hide = not prefs.show_float_menu 42 | self.primary.use_grab_cursor = False 43 | if self.binding["name"] in {"menu_controller"}: 44 | self.primary.hide = "float" not in prefs.menu_style or not prefs.show_menu 45 | self.primary.use_grab_cursor = False 46 | self.primary.show_drag = True 47 | if self.binding["name"] in {"menu_controller"}: 48 | self.primary.scale_basis = (36 * prefs.menu_spacing) * prefs.gizmo_scale 49 | self.primary.use_grab_cursor = False 50 | self.primary.show_drag = True 51 | else: 52 | self.primary.scale_basis = 18 * prefs.gizmo_scale 53 | 54 | def move(self, position: Vector): 55 | self.primary.matrix_basis = Matrix.Translation(position) 56 | 57 | def __updatevisible(self): 58 | if not preferences().show_menu and self.binding["name"] not in ["float_menu"]: 59 | self.visible = False 60 | self.primary.hide = True 61 | return 62 | if self.binding["location"] == "prefs": 63 | self.visible = getattr(preferences(), "show_" + self.binding["name"]) and self.binding["name"] in preferences().getGizmoSet( 64 | bpy.context.mode 65 | ) 66 | 67 | if self.visible: 68 | self.visible = self.__visibilityLock() and not self.__checkAttributeBind() 69 | self.primary.hide = not self.visible 70 | 71 | def __visibilityLock(self) -> bool: 72 | if preferences().menu_style == "fixed.bar": 73 | return True 74 | return not self.hidden 75 | 76 | # if an attribute being assigned to active_object should hide/show bpy.types.Gizmo 77 | def __checkAttributeBind(self): 78 | if not self.has_attribute_bind: 79 | return False 80 | bind = self.binding["attribute"] 81 | state = self.__findAttribute(bind["path"], bind["value"]) == bind["state"] 82 | return not state 83 | 84 | # search for attribute, value through context. 85 | # will traverse bpy.types.bpy_prop_collection entries 86 | # by next attr to value comparison 87 | def __findAttribute(self, path: str, value: str): 88 | names = path.split(".") 89 | current = bpy.context 90 | for i, prop in enumerate(names): 91 | current = getattr(current, prop) 92 | if current is None: 93 | return False 94 | 95 | if isinstance(current, bpy.types.bpy_prop_collection): 96 | item = "" 97 | for item in current: 98 | if getattr(item, names[i + 1]) == value: 99 | return True 100 | return False 101 | return getattr(current, value) 102 | 103 | # initialize each gizmo, add them to named list with icon name(s) 104 | def __buildGizmo(self, command: str, icon: str) -> bpy.types.Gizmo: 105 | gizmo = self.group.gizmos.new("GIZMO_GT_button_2d") 106 | gizmo.target_set_operator(command) 107 | gizmo.icon = icon # type: ignore 108 | gizmo.use_tooltip = False # show tooltip 109 | gizmo.use_event_handle_all = True # don't pass events e.g. shift+a to add 110 | gizmo.use_grab_cursor = "use_grab_cursor" in self.config 111 | gizmo.show_drag = False # show default cursor 112 | gizmo.line_width = 5.0 113 | gizmo.use_draw_modal = True # show gizmo while dragging 114 | gizmo.draw_options = {"BACKDROP", "OUTLINE"} # type: ignore 115 | self.__setColors(gizmo) 116 | gizmo.scale_basis = 0.1 117 | return gizmo 118 | 119 | def __setColors(self, gizmo: bpy.types.Gizmo): 120 | gizmo.color = gizmo_colors["active"]["color"] 121 | gizmo.color_highlight = gizmo_colors["active"]["color_highlight"] 122 | gizmo.alpha = gizmo_colors["active"]["alpha"] 123 | gizmo.alpha_highlight = gizmo_colors["active"]["alpha_highlight"] 124 | 125 | 126 | class GizmoSetBoolean(GizmoSet): 127 | def setup(self, group: bpy.types.GizmoGroup, config: dict): 128 | self.visible = True 129 | self.config = config 130 | self.has_dependent = "has_dependent" in config or False 131 | self.group = group 132 | self.scale = config["scale"] if ("scale" in config) else 14 133 | self.binding = config["binding"] 134 | self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False 135 | self.onGizmo = self._GizmoSet__buildGizmo(config["command"], config["onIcon"]) # type: ignore 136 | self.offGizmo = self._GizmoSet__buildGizmo(config["command"], config["offIcon"]) # type: ignore 137 | self.__setActiveGizmo(True) 138 | 139 | def __setActiveGizmo(self, state: bool): 140 | self.onGizmo.hide = True 141 | self.offGizmo.hide = True 142 | self.primary = self.onGizmo if state else self.offGizmo 143 | 144 | def draw_prepare(self): 145 | prefs = preferences() 146 | self.hidden = not prefs.show_gizmos 147 | self.skip_draw = False 148 | self.__updatevisible() 149 | self.primary.scale_basis = 18 * prefs.gizmo_scale 150 | self.primary.use_grab_cursor = False 151 | if self.binding["name"] == "float_toggle": 152 | self.__setToggleColors(self.primary) 153 | 154 | def __updatevisible(self): 155 | prefs = preferences() 156 | bind = self.binding 157 | if not preferences().show_menu and (bind["name"] not in ["float_menu"]): 158 | self.visible = False 159 | self.primary.hide = True 160 | return 161 | if bind["name"] == "float_toggle": 162 | self.visible = prefs.input_mode != "FULL" or prefs.enable_floating_toggle 163 | else: 164 | self.visible = getattr(preferences(), "show_" + self.binding["name"]) 165 | 166 | if self.visible: 167 | self.visible = ( 168 | self._GizmoSet__visibilityLock() # type: ignore 169 | and not self._GizmoSet__checkAttributeBind() # type: ignore 170 | ) # type: ignore 171 | 172 | if bind["name"] == "float_toggle": 173 | self.__setActiveGizmo(prefs.is_enabled) 174 | else: 175 | self.__setActiveGizmo(self._GizmoSet__findAttribute(bind["location"], bind["name"])) # type: ignore 176 | self.primary.hide = not self.visible 177 | 178 | def __setToggleColors(self, gizmo: bpy.types.Gizmo): 179 | mode = "active" if preferences().is_enabled else "inactive" 180 | gizmo.color = toggle_colors[mode]["color"] 181 | gizmo.color_highlight = toggle_colors[mode]["color_highlight"] 182 | gizmo.alpha = toggle_colors[mode]["alpha"] 183 | gizmo.alpha_highlight = toggle_colors[mode]["alpha_highlight"] 184 | 185 | 186 | class GizmoSetEnum(GizmoSet): 187 | gizmos: list[bpy.types.Gizmo] 188 | 189 | def setup(self, group: bpy.types.GizmoGroup, config): 190 | pass 191 | -------------------------------------------------------------------------------- /source/ui/gizmo_config.py: -------------------------------------------------------------------------------- 1 | from ..utils.constants import pivot_icon_items 2 | 3 | ### 4 | # Config Standard 5 | # ( TYPE BINDING COMMAND ICON ) 6 | # @TYPE - button type to instance (enum, bool, simple/default) 7 | # @BINDING - used to determine context and visibility 8 | # @COMMAND - operator to call when activated 9 | # @ICON - icon to show on Gizmo 10 | ### 11 | 12 | # Simple 2D Gizmo 13 | controllerConfig = { 14 | "type": "default", 15 | "binding": {"location": "", "name": "menu_controller"}, 16 | "command": "touchview.move_float_menu", 17 | "icon": "BLANK1", 18 | "use_grab_cursor": True, 19 | } 20 | 21 | floatingConfig = { 22 | "type": "default", 23 | "binding": {"location": "prefs", "name": "float_menu"}, 24 | "command": "touchview.move_action_menu", 25 | "icon": "SETTINGS", 26 | "use_grab_cursor": True, 27 | } 28 | 29 | floatingToggleConfig = { 30 | "type": "boolean", 31 | "binding": {"location": "", "name": "float_toggle"}, 32 | "command": "touchview.move_toggle_button", 33 | "onIcon": "OUTLINER_DATA_CAMERA", 34 | "offIcon": "GREASEPENCIL", 35 | "use_grab_cursor": True, 36 | } 37 | 38 | undoConfig = { 39 | "type": "default", 40 | "binding": {"location": "prefs", "name": "undoredo"}, 41 | "has_dependent": True, 42 | "command": "ed.undo", 43 | "icon": "LOOP_BACK", 44 | } 45 | 46 | redoConfig = { 47 | "type": "default", 48 | "binding": {"location": "prefs", "name": "undoredo"}, 49 | "command": "ed.redo", 50 | "icon": "LOOP_FORWARDS", 51 | } 52 | 53 | touchViewConfig = { 54 | "type": "default", 55 | "binding": { 56 | "location": "prefs", 57 | "name": "is_enabled", 58 | }, 59 | "command": "touchview.toggle_touch", 60 | "icon": "VIEW_PAN", 61 | } 62 | 63 | controlGizmoConfig = { 64 | "type": "default", 65 | "binding": { 66 | "location": "prefs", 67 | "name": "control_gizmo", 68 | }, 69 | "command": "touchview.cycle_control_gizmo", 70 | "icon": "ORIENTATION_LOCAL", 71 | } 72 | 73 | snapViewConfig = { 74 | "type": "default", 75 | "binding": {"location": "prefs", "name": "snap_view"}, 76 | "command": "touchview.viewport_recenter", 77 | "icon": "CURSOR", 78 | } 79 | 80 | nPanelConfig = { 81 | "type": "default", 82 | "binding": {"location": "prefs", "name": "n_panel"}, 83 | "command": "touchview.toggle_n_panel", 84 | "icon": "EVENT_N", 85 | } 86 | 87 | voxelSizeConfig = { 88 | "type": "default", 89 | "binding": { 90 | "location": "prefs", 91 | "name": "voxel_remesh", 92 | "attribute": { 93 | "path": "active_object.modifiers.type", 94 | "value": "MULTIRES", 95 | "state": False, 96 | }, 97 | }, 98 | "command": "object.voxel_size_edit", 99 | "icon": "MESH_GRID", 100 | } 101 | 102 | voxelRemeshConfig = { 103 | "type": "default", 104 | "binding": { 105 | "location": "prefs", 106 | "name": "voxel_remesh", 107 | "attribute": { 108 | "path": "active_object.modifiers.type", 109 | "value": "MULTIRES", 110 | "state": False, 111 | }, 112 | }, 113 | "command": "object.voxel_remesh", 114 | "icon": "MOD_UVPROJECT", 115 | } 116 | 117 | voxelStepDownConfig = { 118 | "type": "default", 119 | "binding": { 120 | "location": "prefs", 121 | "name": "voxel_remesh", 122 | "attribute": { 123 | "path": "active_object.modifiers.type", 124 | "value": "MULTIRES", 125 | "state": False, 126 | }, 127 | }, 128 | "command": "touchview.density_down", 129 | "icon": "TRIA_DOWN", 130 | } 131 | 132 | voxelStepUpConfig = { 133 | "type": "default", 134 | "binding": { 135 | "location": "prefs", 136 | "name": "voxel_remesh", 137 | "attribute": { 138 | "path": "active_object.modifiers.type", 139 | "value": "MULTIRES", 140 | "state": False, 141 | }, 142 | }, 143 | "command": "touchview.density_up", 144 | "icon": "TRIA_UP", 145 | } 146 | 147 | subdivConfig = { 148 | "type": "default", 149 | "binding": { 150 | "location": "prefs", 151 | "name": "multires", 152 | "attribute": { 153 | "path": "active_object.modifiers.type", 154 | "value": "MULTIRES", 155 | "state": True, 156 | }, 157 | }, 158 | "has_dependent": True, 159 | "command": "touchview.increment_multires", 160 | "icon": "TRIA_UP", 161 | } 162 | 163 | unsubdivConfig = { 164 | "type": "default", 165 | "binding": { 166 | "location": "prefs", 167 | "name": "multires", 168 | "attribute": { 169 | "path": "active_object.modifiers.type", 170 | "value": "MULTIRES", 171 | "state": True, 172 | }, 173 | }, 174 | "command": "touchview.decrement_multires", 175 | "icon": "TRIA_DOWN", 176 | } 177 | 178 | brushResizeConfig = { 179 | "type": "default", 180 | "binding": {"location": "prefs", "name": "brush_dynamics"}, 181 | "command": "touchview.brush_resize", 182 | "icon": "ANTIALIASED", 183 | } 184 | 185 | brushStrengthConfig = { 186 | "type": "default", 187 | "binding": {"location": "prefs", "name": "brush_dynamics"}, 188 | "command": "touchview.brush_strength", 189 | "icon": "SMOOTHCURVE", 190 | } 191 | 192 | # Boolean 2D Gizmo 193 | fullscreenToggleConfig = { 194 | "type": "boolean", 195 | "binding": { 196 | "location": "screen", 197 | "name": "show_fullscreen", 198 | }, # property location, watch-boolean 199 | "command": "screen.screen_full_area", 200 | "onIcon": "FULLSCREEN_EXIT", # on-state 201 | "offIcon": "FULLSCREEN_ENTER", # off-state 202 | } 203 | 204 | quadviewToggleConfig = { 205 | "type": "boolean", 206 | "binding": {"location": "space_data", "name": "region_quadviews"}, 207 | "command": "screen.region_quadview", 208 | "onIcon": "IMGDISPLAY", 209 | "offIcon": "MESH_PLANE", 210 | } 211 | 212 | rotLocToggleConfig = { 213 | "type": "boolean", 214 | "binding": {"location": "region_data", "name": "lock_rotation"}, 215 | "command": "touchview.viewport_lock", 216 | "onIcon": "LOCKED", 217 | "offIcon": "UNLOCKED", 218 | } 219 | 220 | gizmo_colors = { 221 | "disabled": { 222 | "color": [0.0, 0.0, 0.0], 223 | "color_highlight": [0.0, 0.0, 0.0], 224 | "alpha": 0.3, 225 | "alpha_highlight": 0.3, 226 | }, 227 | "active": { 228 | "color": [0.0, 0.0, 0.0], 229 | "alpha": 0.5, 230 | "color_highlight": [0.5, 0.5, 0.5], 231 | "alpha_highlight": 0.5, 232 | }, 233 | "error": { 234 | "color": [0.3, 0.0, 0.0], 235 | "alpha": 0.15, 236 | "color_highlight": [1.0, 0.2, 0.2], 237 | "alpha_highlight": 0.5, 238 | }, 239 | "warn": { 240 | "color": [0.35, 0.3, 0.14], 241 | "alpha": 0.15, 242 | "color_highlight": [0.8, 0.7, 0.3], 243 | "alpha_highlight": 0.3, 244 | }, 245 | } 246 | 247 | toggle_colors = { 248 | "active": { 249 | "color": [0.1, 0.1, 0.2], 250 | "alpha": 0.5, 251 | "color_highlight": [0.15, 0.15, 0.3], 252 | "alpha_highlight": 0.7, 253 | }, 254 | "inactive": { 255 | "color": [0.0, 0.0, 0.0], 256 | "alpha": 0.5, 257 | "color_highlight": [0.05, 0.05, 0.05], 258 | "alpha_highlight": 0.7, 259 | }, 260 | } 261 | 262 | # Enum 2D Gizmo 263 | # 264 | # not implemented yet 265 | pivotModeConfig = { 266 | "type": "enum", 267 | "binding": {"location": "prefs", "name": "pivot_mode"}, 268 | "command": "", 269 | "icons": pivot_icon_items, 270 | } 271 | -------------------------------------------------------------------------------- /source/ui/gizmo_group_2d.py: -------------------------------------------------------------------------------- 1 | from math import cos, radians, sin 2 | 3 | import bpy 4 | from bpy.types import GizmoGroup 5 | from mathutils import Vector 6 | 7 | from ..utils.blender import * 8 | from .gizmo_2d import GizmoSet, GizmoSetBoolean 9 | from .gizmo_config import (brushResizeConfig, brushStrengthConfig, 10 | controlGizmoConfig, controllerConfig, 11 | floatingConfig, floatingToggleConfig, 12 | fullscreenToggleConfig, nPanelConfig, 13 | quadviewToggleConfig, redoConfig, 14 | rotLocToggleConfig, snapViewConfig, subdivConfig, 15 | touchViewConfig, undoConfig, unsubdivConfig, 16 | voxelRemeshConfig, voxelSizeConfig, 17 | voxelStepDownConfig, voxelStepUpConfig) 18 | 19 | __module__ = __name__.split(".")[0] 20 | 21 | 22 | configs = [ 23 | undoConfig, 24 | redoConfig, 25 | touchViewConfig, 26 | controlGizmoConfig, 27 | snapViewConfig, 28 | fullscreenToggleConfig, 29 | quadviewToggleConfig, 30 | rotLocToggleConfig, 31 | nPanelConfig, 32 | voxelSizeConfig, 33 | voxelRemeshConfig, 34 | voxelStepDownConfig, 35 | voxelStepUpConfig, 36 | subdivConfig, 37 | unsubdivConfig, 38 | brushResizeConfig, 39 | brushStrengthConfig, 40 | ] 41 | 42 | ### 43 | # GizmoGroup 44 | # - hold reference to available Gizmos 45 | # - generate new Gizmos 46 | # - position Gizmos during draw_@prepare() 47 | # 48 | # Gizmo 49 | # - hold Icon (cannot change) 50 | # - set color 51 | # - set visible 52 | # 53 | # 2DGizmo (Custom Gizmo definition) 54 | # - holds reference to Gizmos for related action 55 | # - position applied to references 56 | # - hold state to determine what icons,actions to provide 57 | # - applies color and visibility based on prefs 58 | # 59 | ### 60 | 61 | 62 | class GIZMO_GT_viewport_gizmo_group(GizmoGroup): 63 | bl_label = "Fast access tools for touch viewport" 64 | bl_space_type = "VIEW_3D" 65 | bl_region_type = "WINDOW" 66 | bl_options = {"PERSISTENT", "SCALE"} 67 | 68 | # set up gizmo collection 69 | def setup(self, context): 70 | self.gizmo_2d_sets = [] 71 | self.__buildController(context) 72 | prefs = preferences() 73 | self.spacing = prefs.menu_spacing 74 | for conf in configs: 75 | if conf["type"] == "boolean": 76 | gizmo = GizmoSetBoolean() 77 | gizmo.setup(self, conf) 78 | else: # assume Type = Default 79 | gizmo = GizmoSet() 80 | gizmo.setup(self, conf) 81 | self.gizmo_2d_sets.append(gizmo) 82 | 83 | def __buildController(self, context): 84 | self.controller = GizmoSet() 85 | self.controller.setup(self, controllerConfig) 86 | self.action_menu = GizmoSet() 87 | self.action_menu.setup(self, floatingConfig) 88 | self.toggle = GizmoSetBoolean() 89 | self.toggle.setup(self, floatingToggleConfig) 90 | 91 | def draw_prepare(self, context): 92 | self.context = context 93 | prefs = preferences() 94 | self.__updateOrigin() 95 | self.__updateActionOrigin() 96 | self.__updateToggleOrigin() 97 | self.toggle.draw_prepare() 98 | self.controller.draw_prepare() 99 | self.action_menu.draw_prepare() 100 | self.__move_gizmo(self.controller, self.origin) 101 | self.__move_gizmo(self.action_menu, self.action_origin) 102 | self.__move_gizmo(self.toggle, self.toggle_origin) 103 | 104 | visible_gizmos = [] 105 | for gizmo in self.gizmo_2d_sets: 106 | gizmo.draw_prepare() 107 | if gizmo.visible: 108 | visible_gizmos.append(gizmo) 109 | 110 | if prefs.menu_style == "float.radial": 111 | self.__menuRadial(visible_gizmos) 112 | if prefs.menu_style == "fixed.bar": 113 | self.__menuBar(visible_gizmos) 114 | 115 | def __menuBar(self, visible_gizmos: list[GizmoSet]): 116 | prefs = preferences() 117 | origin = self.origin 118 | count = len(visible_gizmos) 119 | safe_area = safe_area_3d() 120 | origin = Vector( 121 | ( 122 | (safe_area[0].x + safe_area[1].x) / 2, 123 | (safe_area[0].y + safe_area[1].y) / 2, 124 | 0.0, 125 | ) 126 | ) 127 | 128 | if prefs.gizmo_position == "TOP": 129 | origin.y = safe_area[1].y 130 | elif prefs.gizmo_position == "BOTTOM": 131 | origin.y = safe_area[0].y 132 | elif prefs.gizmo_position == "LEFT": 133 | origin.x = safe_area[0].x 134 | elif prefs.gizmo_position == "RIGHT": 135 | origin.x = safe_area[1].x # - 54 # to avoid overlapping 136 | 137 | gizmo_scale = (36 * prefs.gizmo_scale) + prefs.gizmo_padding 138 | gizmo_padding = prefs.gizmo_padding 139 | spacing = (gizmo_scale + gizmo_padding) * ui_scale() 140 | 141 | if prefs.gizmo_position in {"TOP", "BOTTOM"} and prefs.menu_style == "fixed.bar": 142 | start = origin.x - ((count - 1) * spacing) / 2 143 | for i, gizmo in enumerate(visible_gizmos): 144 | self.__move_gizmo(gizmo, Vector((start + (i * spacing), origin.y, 0.0))) 145 | else: 146 | start = origin.y + (count * spacing) / 2 147 | for i, gizmo in enumerate(visible_gizmos): 148 | self.__move_gizmo(gizmo, Vector((origin.x, start - (i * spacing), 0.0))) 149 | 150 | def __menuRadial(self, visible_gizmos: list[GizmoSet]): 151 | prefs = preferences() 152 | # calculate minimum radius to prevent overlapping buttons 153 | menu_spacing = (36 * prefs.menu_spacing) * prefs.gizmo_scale + prefs.gizmo_padding 154 | gizmo_scale = 18 * prefs.gizmo_scale 155 | gizmo_padding = prefs.gizmo_padding 156 | spacing = (menu_spacing + gizmo_scale + gizmo_padding) * ui_scale() 157 | 158 | count = len(visible_gizmos) 159 | # reposition Gizmos to origin 160 | for i, gizmo in enumerate(visible_gizmos): 161 | if gizmo.skip_draw: 162 | continue 163 | 164 | if gizmo.has_dependent and i > count / 2: 165 | self.__calcMove(gizmo, i + 1, count, spacing) 166 | self.__calcMove(visible_gizmos[i + 1], i, count, spacing) 167 | visible_gizmos[i + 1].skip_draw = True 168 | else: 169 | self.__calcMove(gizmo, i, count, spacing) 170 | 171 | def __calcMove(self, gizmo: GizmoSet, step: int, size: int, spacing: float): 172 | distance = step / size 173 | offset = Vector( 174 | ( 175 | sin(radians(distance * 360)), 176 | cos(radians(distance * 360)), 177 | 0.0, 178 | ) 179 | ) 180 | self.__move_gizmo(gizmo, self.origin + offset * spacing) 181 | 182 | def __updateOrigin(self): 183 | prefs = preferences() 184 | safe_area = safe_area_3d(padding=90) 185 | 186 | # distance across viewport between menus 187 | span = Vector( 188 | ( 189 | safe_area[1].x - safe_area[0].x, 190 | safe_area[1].y - safe_area[0].y, 191 | ) 192 | ) 193 | 194 | # apply position ratio to safe area 195 | self.origin = Vector( 196 | ( 197 | safe_area[0].x + span.x * prefs.menu_position[0] * 0.01, 198 | safe_area[0].y + span.y * prefs.menu_position[1] * 0.01, 199 | 0.0, 200 | ) 201 | ) 202 | 203 | def __updateActionOrigin(self): 204 | prefs = preferences() 205 | safe_area = safe_area_3d() 206 | 207 | # distance across viewport between menus 208 | span = Vector( 209 | ( 210 | safe_area[1].x - safe_area[0].x, 211 | safe_area[1].y - safe_area[0].y, 212 | ) 213 | ) 214 | 215 | # apply position ratio to safe area 216 | self.action_origin = Vector( 217 | ( 218 | safe_area[0].x + span.x * prefs.floating_position[0] * 0.01, 219 | safe_area[0].y + span.y * prefs.floating_position[1] * 0.01, 220 | 0.0, 221 | ) 222 | ) 223 | 224 | def __updateToggleOrigin(self): 225 | prefs = preferences() 226 | safe_area = safe_area_3d() 227 | 228 | # distance across viewport between menus 229 | span = Vector( 230 | ( 231 | safe_area[1].x - safe_area[0].x, 232 | safe_area[1].y - safe_area[0].y, 233 | ) 234 | ) 235 | 236 | # apply position ratio to safe area 237 | self.toggle_origin = Vector( 238 | ( 239 | safe_area[0].x + span.x * prefs.toggle_position[0] * 0.01, 240 | safe_area[0].y + span.y * prefs.toggle_position[1] * 0.01, 241 | 0.0, 242 | ) 243 | ) 244 | 245 | def __move_gizmo(self, gizmo: GizmoSet, position: Vector): 246 | gizmo.move(position) 247 | 248 | 249 | classes = (GIZMO_GT_viewport_gizmo_group,) 250 | 251 | 252 | register, unregister = bpy.utils.register_classes_factory(classes) 253 | -------------------------------------------------------------------------------- /source/ui/panel.py: -------------------------------------------------------------------------------- 1 | # type: ignore 2 | import bpy 3 | from bpy.types import Menu, Panel, UILayout 4 | 5 | from ..utils.blender import preferences 6 | 7 | 8 | class TouchView: 9 | bl_label = "Touchview Settings" 10 | bl_space_type = "VIEW_3D" 11 | bl_region_type = "UI" 12 | bl_category = "Touchview" 13 | 14 | 15 | class TOUCHVIEW_PT_view_3d_panel(TouchView, Panel): 16 | # bl_label = "Touchview Settings" 17 | 18 | def draw(self, context): 19 | prefs = preferences() 20 | 21 | layout = self.layout 22 | layout.use_property_decorate = False 23 | 24 | box = layout.box() 25 | box.label( 26 | text=UILayout.enum_item_description(prefs, "input_mode", prefs.input_mode), 27 | icon_value=UILayout.enum_item_icon(prefs, "input_mode", prefs.input_mode), 28 | ) 29 | 30 | row = box.row() 31 | row.prop(prefs, "input_mode", expand=True) 32 | 33 | col = box.column(align=True) 34 | col.use_property_split = True 35 | col.prop(prefs, "lazy_mode") 36 | if prefs.input_mode == "FULL": 37 | col.prop(prefs, "enable_floating_toggle") 38 | 39 | 40 | class TOUCHVIEW_PT_control_zones(TouchView, Panel): 41 | bl_label = "Control Zones" 42 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 43 | bl_options = {"DEFAULT_CLOSED"} 44 | 45 | def draw_header(self, context): 46 | prefs = preferences() 47 | 48 | layout = self.layout 49 | layout.use_property_decorate = False 50 | 51 | layout.prop(prefs, "is_enabled", text="") 52 | 53 | def draw(self, context): 54 | layout = self.layout 55 | layout.use_property_decorate = False 56 | 57 | prefs = preferences() 58 | 59 | layout.active = prefs.is_enabled 60 | 61 | row = layout.row() 62 | row.prop(prefs, "header_toggle_position", expand=True) 63 | 64 | layout.use_property_split = True 65 | 66 | col = layout.column(align=True) 67 | col.prop(prefs, "isVisible", text="Show Overlay") 68 | col.prop(prefs, "swap_panrotate") 69 | col.prop(prefs, "use_multiple_colors") 70 | 71 | col = layout.column() 72 | col.prop(prefs, "overlay_main_color", text="Main Color") 73 | if prefs.use_multiple_colors: 74 | col.prop(prefs, "overlay_secondary_color", text="Secondary Color") 75 | col.prop(prefs, "width", slider=True) 76 | col.prop(prefs, "radius", slider=True) 77 | 78 | 79 | class TOUCHVIEW_PT_gizmo_bar(TouchView, Panel): 80 | bl_label = "Gizmo" 81 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 82 | bl_options = {"DEFAULT_CLOSED"} 83 | 84 | def draw(self, context): 85 | prefs = preferences() 86 | 87 | layout = self.layout 88 | layout.use_property_decorate = False 89 | layout.use_property_split = True 90 | 91 | col = layout.column() 92 | col.prop(prefs, "menu_style", expand=True) 93 | 94 | if prefs.menu_style == "fixed.bar": 95 | col.prop(prefs, "gizmo_position") 96 | elif prefs.menu_style == "float.radial": 97 | col.prop(prefs, "menu_spacing", slider=True) 98 | 99 | col.prop(prefs, "gizmo_scale", slider=True) 100 | col.prop(prefs, "gizmo_padding", slider=True) 101 | 102 | 103 | class TOUCHVIEW_PT_right_click(TouchView, Panel): 104 | bl_label = "Right Click Actions" 105 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 106 | bl_options = {"DEFAULT_CLOSED"} 107 | 108 | def draw(self, context): 109 | prefs = preferences() 110 | 111 | layout = self.layout 112 | layout.use_property_decorate = False 113 | layout.use_property_split = True 114 | 115 | col = layout.column() 116 | col.prop(prefs, "right_click_source", text="Source", expand=True) 117 | col.prop(prefs, "right_click_mode", text="Mode", expand=True) 118 | 119 | 120 | class TOUCHVIEW_PT_double_click(TouchView, Panel): 121 | bl_label = "Double Click Actions" 122 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 123 | bl_options = {"DEFAULT_CLOSED"} 124 | 125 | def draw(self, context): 126 | prefs = preferences() 127 | 128 | layout = self.layout 129 | layout.use_property_decorate = False 130 | layout.use_property_split = True 131 | 132 | col = layout.column() 133 | col.prop(prefs, "enable_double_click") 134 | col.prop(prefs, "double_click_mode", text="Mode", expand=True) 135 | 136 | 137 | class TOUCHVIEW_PT_tool_settings(TouchView, Panel): 138 | bl_label = "Tool Options" 139 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 140 | bl_options = {"DEFAULT_CLOSED"} 141 | 142 | def draw(self, context): 143 | prefs = preferences() 144 | 145 | layout = self.layout 146 | layout.use_property_decorate = False 147 | layout.use_property_split = True 148 | 149 | layout.prop(prefs, "subdivision_limit", slider=True) 150 | 151 | 152 | class TOUCHVIEW_PT_viewport_options(TouchView, Panel): 153 | bl_label = "Viewport Options" 154 | bl_parent_id = "TOUCHVIEW_PT_view_3d_panel" 155 | bl_options = {"DEFAULT_CLOSED"} 156 | 157 | def draw(self, context): 158 | prefs = preferences() 159 | 160 | layout = self.layout 161 | layout.use_property_decorate = False 162 | layout.use_property_split = True 163 | 164 | view = context.space_data 165 | space = context.area.spaces.active 166 | 167 | col = layout.column() 168 | col.operator("touchview.tools_region_flip", text="Flip Tools") 169 | if len(space.region_quadviews) > 0: 170 | col.operator("screen.region_quadview", text="Disable Quadview") 171 | else: 172 | col.operator("screen.region_quadview", text="Enable Quadview") 173 | 174 | col = layout.column(align=True) 175 | col.prop(prefs, "show_float_menu") 176 | if not len(space.region_quadviews) > 0: 177 | col.prop(space, "lock_cursor", text="Lock to Cursor") 178 | col.prop(view.region_3d, "lock_rotation", text="Lock Rotation") 179 | 180 | 181 | class TOUCHVIEW_PT_image_editor_panel(TouchView, Panel): 182 | bl_space_type = "IMAGE_EDITOR" 183 | 184 | def draw(self, context): 185 | prefs = preferences() 186 | 187 | layout = self.layout 188 | layout.use_property_decorate = False 189 | 190 | box = layout.box() 191 | box.label( 192 | text=UILayout.enum_item_description(prefs, "input_mode", prefs.input_mode), 193 | icon_value=UILayout.enum_item_icon(prefs, "input_mode", prefs.input_mode), 194 | ) 195 | 196 | row = box.row() 197 | row.prop(prefs, "input_mode", expand=True) 198 | 199 | col = box.column(align=True) 200 | col.use_property_split = True 201 | col.prop(prefs, "is_enabled") 202 | subcol = col.column(align=True) 203 | subcol.active = prefs.is_enabled 204 | subcol.prop(prefs, "header_toggle_position", expand=True) 205 | 206 | 207 | class TOUCHVIEW_PT_node_editor_panel(TouchView, Panel): 208 | bl_space_type = "NODE_EDITOR" 209 | 210 | def draw(self, context): 211 | prefs = preferences() 212 | 213 | layout = self.layout 214 | layout.use_property_decorate = False 215 | 216 | box = layout.box() 217 | box.label( 218 | text=UILayout.enum_item_description(prefs, "input_mode", prefs.input_mode), 219 | icon_value=UILayout.enum_item_icon(prefs, "input_mode", prefs.input_mode), 220 | ) 221 | 222 | row = box.row() 223 | row.prop(prefs, "input_mode", expand=True) 224 | 225 | col = box.column(align=True) 226 | col.use_property_split = True 227 | col.prop(prefs, "is_enabled") 228 | subcol = col.column(align=True) 229 | subcol.active = prefs.is_enabled 230 | subcol.prop(prefs, "header_toggle_position", expand=True) 231 | 232 | 233 | # UI panel to append Gizmo menu 234 | class TOUCHVIEW_PT_gizmo_display(Panel): 235 | bl_label = "Touchview Gizmos" 236 | bl_parent_id = "VIEW3D_PT_gizmo_display" 237 | bl_space_type = "VIEW_3D" 238 | bl_region_type = "HEADER" 239 | 240 | def draw(self, context): 241 | prefs = preferences() 242 | 243 | layout = self.layout 244 | col = layout.column() 245 | available_gizmos = prefs.getGizmoSet(context.object.mode) 246 | 247 | col = col.column(align=True) 248 | col.active = context.space_data.show_gizmo 249 | col.prop(prefs, "show_menu") 250 | col = col.column() 251 | col.active = prefs.show_menu 252 | for toggle in available_gizmos: 253 | col.prop(prefs, "show_" + toggle) 254 | 255 | 256 | class TOUCHVIEW_MT_floating(Menu): 257 | """Open a custom menu""" 258 | 259 | bl_label = "Floating Menu" 260 | bl_description = "Customized Floating Menu" 261 | 262 | def draw(self, context): 263 | prefs = preferences() 264 | menu = prefs.getMenuSettings(context.mode) 265 | 266 | layout = self.layout 267 | pie = layout.menu_pie() 268 | for i in range(8): 269 | op = getattr(menu, "menu_slot_" + str(i + 1)) 270 | if op == "": 271 | continue 272 | elif "_MT_" in op: 273 | pie.menu(op) 274 | continue 275 | elif self.__operator_exists(op): 276 | pie.operator(op) 277 | 278 | def __operator_exists(self, idname): 279 | try: 280 | names = idname.split(".") 281 | a = bpy.ops 282 | for prop in names: 283 | a = getattr(a, prop) 284 | a.__repr__() 285 | except Exception as _: 286 | return False 287 | return True 288 | 289 | 290 | classes = ( 291 | TOUCHVIEW_PT_view_3d_panel, 292 | TOUCHVIEW_PT_control_zones, 293 | TOUCHVIEW_PT_gizmo_bar, 294 | TOUCHVIEW_PT_right_click, 295 | TOUCHVIEW_PT_double_click, 296 | TOUCHVIEW_PT_tool_settings, 297 | TOUCHVIEW_PT_viewport_options, 298 | TOUCHVIEW_PT_image_editor_panel, 299 | TOUCHVIEW_PT_node_editor_panel, 300 | TOUCHVIEW_PT_gizmo_display, 301 | TOUCHVIEW_MT_floating, 302 | ) 303 | 304 | 305 | register, unregister = bpy.utils.register_classes_factory(classes) 306 | -------------------------------------------------------------------------------- /source/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from . import keymaps 2 | from .overlay import Overlay 3 | 4 | ov = Overlay() 5 | 6 | 7 | def register(): 8 | keymaps.register() 9 | ov.drawUI() 10 | 11 | 12 | def unregister(): 13 | ov.clear_overlays() 14 | keymaps.unregister() 15 | -------------------------------------------------------------------------------- /source/utils/blender.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from mathutils import Vector 3 | 4 | from ... import \ 5 | __package__ as package # relative import from the root directory 6 | 7 | 8 | def preferences() -> dict: 9 | """Get the addon preferences.""" 10 | return bpy.context.preferences.addons[package].preferences # type: ignore 11 | 12 | 13 | def panel(type) -> tuple: 14 | """Panel in the region. 15 | 16 | type (enum in ['WINDOW', 'HEADER', 'CHANNELS', 'TEMPORARY', 'UI', 'TOOLS', 17 | 'TOOL_PROPS', 'PREVIEW', 'HUD', 'NAVIGATION_BAR', 'EXECUTE', 18 | 'FOOTER', 'TOOL_HEADER', 'XR']) - Type of the region. 19 | return (tuple) - Dimension of the region. 20 | """ 21 | width = 0 22 | height = 0 23 | alignment = "NONE" 24 | for region in bpy.context.area.regions: 25 | if region.type == type: 26 | width = region.width 27 | height = region.height 28 | alignment = region.alignment 29 | return (width, height, alignment) 30 | 31 | 32 | def ui_scale() -> float: 33 | return bpy.context.preferences.system.ui_scale 34 | 35 | 36 | # used in text drawing 37 | def dpi() -> int: 38 | return bpy.context.preferences.system.dpi 39 | 40 | 41 | # returns a tuple (bottom-left, top-right) 42 | # safe area in viewport for UI elements 43 | def safe_area_3d(padding: float = 28) -> tuple[Vector, Vector]: 44 | buffer = padding * ui_scale() 45 | min = Vector((buffer, buffer)) 46 | max = Vector( 47 | ( 48 | bpy.context.area.width - buffer, 49 | bpy.context.area.height - buffer, 50 | ) 51 | ) 52 | 53 | if panel("TOOLS")[2] == "LEFT": 54 | min.x += panel("TOOLS")[0] 55 | elif panel("TOOLS")[2] == "RIGHT": 56 | max.x -= panel("TOOLS")[0] 57 | 58 | if panel("UI")[2] == "LEFT": 59 | min.x += panel("UI")[0] 60 | elif panel("UI")[2] == "RIGHT": 61 | max.x -= panel("UI")[0] 62 | 63 | if panel("HEADER")[2] == "BOTTOM": 64 | min.y += panel("HEADER")[1] 65 | elif panel("HEADER")[2] == "TOP": 66 | max.y -= panel("HEADER")[1] 67 | 68 | if panel("TOOL_HEADER")[2] == "BOTTOM": 69 | min.y += panel("TOOL_HEADER")[1] 70 | elif panel("TOOL_HEADER")[2] == "TOP": 71 | max.y -= panel("TOOL_HEADER")[1] 72 | return (min, max) 73 | -------------------------------------------------------------------------------- /source/utils/constants.py: -------------------------------------------------------------------------------- 1 | # INPUT EVENTS 2 | TWEAK = "TWEAK" 3 | MOUSE = "MOUSE" 4 | PEN = "PEN" 5 | MMOUSE = "MIDDLEMOUSE" 6 | LMOUSE = "LEFTMOUSE" 7 | RMOUSE = "RIGHTMOUSE" 8 | PRESS = "PRESS" 9 | DCLICK = "DOUBLE_CLICK" 10 | 11 | # OPERATOR RESPONSES 12 | FINISHED = {"FINISHED"} 13 | MODAL = {"RUNNING_MODAL"} 14 | CANCEL = {"CANCELLED"} 15 | PASSTHROUGH = {"PASS_THROUGH"} 16 | 17 | # DICTIONARIES 18 | flat_modes = [ 19 | "Node Editor", 20 | "Image", 21 | "Image Paint", 22 | "UV Editor", 23 | "View2D", 24 | ] 25 | 26 | top_level_names = ( 27 | "Node Editor", 28 | "UV Editor", 29 | "Image Editor", 30 | "Image Paint", 31 | "3D View", 32 | "Image", 33 | "View2D", 34 | "Grease Pencil", 35 | ) 36 | 37 | input_mode_items = [ 38 | ("ORBIT", "Rotate", "Rotate the viewport"), 39 | ("PAN", "Pan", "Move the viewport"), 40 | ("DOLLY", "Zoom", "Zoom in/out the viewport"), 41 | ] 42 | 43 | position_items = [ 44 | ("TOP", "Top", "Set Gizmo position to top of viewport"), 45 | ("RIGHT", "Right", "Set Gizmo position to right of viewport"), 46 | ("BOTTOM", "Bottom", "Set Gizmo position to bottom of viewport"), 47 | ("LEFT", "Left", "Set Gizmo position to left of viewport"), 48 | ] 49 | 50 | pivot_items = [ 51 | ("SURFACE", "Surface", "Sets the pivot position to the surface under the cursor."), 52 | ( 53 | "ACTIVE", 54 | "Active Vertex", 55 | "Sets the pivot position to the active vertex position.", 56 | ), 57 | ( 58 | "UNMASKED", 59 | "Unmasked", 60 | """ 61 | Sets the pivot position to the average position of the unmasked 62 | vertices. 63 | """, 64 | ), 65 | ("ORIGIN", "Origin", "Sets the pivot to the origin of the sculpt."), 66 | ( 67 | "BORDER", 68 | "Mask Border", 69 | "Sets the pivot position to the center of the border of the mask.", 70 | ), 71 | ] 72 | 73 | pivot_icon_items = [ 74 | ("BORDER", "PIVOT_BOUNDBOX"), 75 | ("ORIGIN", "PIVOT_CURSOR"), 76 | ("UNMASKED", "CLIPUV_HLT"), 77 | ("ACTIVE", "PIVOT_ACTIVE"), 78 | ("SURFACE", "PIVOT_MEDIAN"), 79 | ] 80 | 81 | brush_modes = [ 82 | "SCULPT", 83 | "PAINT_VERTEX", 84 | "PAINT_WEIGHT", 85 | "PAINT_TEXTURE", 86 | ] 87 | 88 | edit_modes = [ 89 | ("OBJECT", "Object Mode", ""), 90 | ("EDIT_MESH", "Edit Mode", ""), 91 | ("SCULPT", "Sculpt Mode", ""), 92 | ("PAINT_VERTEX", "Vertex Paint Mode", ""), 93 | ("PAINT_WEIGHT", "Weight Paint Mode", ""), 94 | ("PAINT_TEXTURE", "Texture Paint Mode", ""), 95 | ("PAINT_GPENCIL", "2D Paint Mode", ""), 96 | ] 97 | 98 | menu_defaults = { 99 | "OBJECT": ("VIEW3D_MT_add", "object.shade_smooth", "", "", "", ""), 100 | "EDIT_MESH": ("mesh.loop_multi_select", "", "", "", "", ""), 101 | "SCULPT": ("object.quadriflow_remesh", "", "", "", "", ""), 102 | "PAINT_VERTEX": ("", "", "", "", "", ""), 103 | "PAINT_WEIGHT": ("", "", "", "", "", ""), 104 | "PAINT_TEXTURE": ("", "", "", "", "", ""), 105 | } 106 | 107 | double_click_items = [ 108 | ("object.transfer_mode", "Transfer Mode", ""), 109 | ("touchview.toggle_touch", "Toggle Touch View", ""), 110 | ("view3d.localview", "Toggle Local View", ""), 111 | ("wm.window_fullscreen_toggle", "Toggle Full Screen", ""), 112 | ] 113 | 114 | menu_style_items = [ 115 | ("float.radial", "Floating Radial", ""), 116 | ("fixed.bar", "Fixed Bar", ""), 117 | ] 118 | 119 | menu_orientation_items = [ 120 | ("HORIZONTAL", "Horizontal", ""), 121 | ("VERTICAL", "Vertical", ""), 122 | ] 123 | 124 | control_gizmo_items = [ 125 | ("none", "", "disable_gizmo"), 126 | ("translate", "show_gizmo_object_translate", ""), 127 | ("rotate", "show_gizmo_object_rotate", ""), 128 | ("scale", "show_gizmo_object_scale", ""), 129 | ] 130 | 131 | gizmo_sets = { 132 | # ALL includes only the modes in this list 133 | "ALL": { 134 | "undoredo", 135 | "show_fullscreen", 136 | "region_quadviews", 137 | "snap_view", 138 | "n_panel", 139 | "lock_rotation", 140 | }, 141 | "SCULPT": { 142 | "control_gizmo", 143 | "pivot_mode", 144 | "voxel_remesh", 145 | "multires", 146 | "brush_dynamics", 147 | }, 148 | "OBJECT": {"control_gizmo", "multires"}, 149 | "EDIT_MESH": {"control_gizmo"}, 150 | "POSE": {}, 151 | "NODE_EDITOR": {"control_gizmo"}, 152 | "PAINT_TEXTURE": {"brush_dynamics"}, 153 | "PAINT_VERTEX": {"brush_dynamics"}, 154 | "PAINT_WEIGHT": {"brush_dynamics"}, 155 | "WEIGHT_GPENCIL": {"brush_dynamics"}, 156 | "VERTEX_GPENCIL": {"brush_dynamics"}, 157 | "SCULPT_GPENCIL": {"brush_dynamics"}, 158 | "PAINT_GPENCIL": {"brush_dynamics"}, 159 | "EDIT_GPENCIL": {"brush_dynamics"}, 160 | } 161 | -------------------------------------------------------------------------------- /source/utils/gizmo_2d.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | from mathutils import Matrix, Vector 3 | 4 | from .blender import * 5 | from .gizmo_config import gizmo_colors, toggle_colors 6 | 7 | ## 8 | # GizmoSet 9 | # - single-state 10 | # - one icon 11 | # - one action 12 | # - possible toggle by variable state 13 | # 14 | # - 2-state (boolean) 15 | # - 2 icons 16 | # - 2 actions (or 1 action for both icons) 17 | # 18 | ## 19 | 20 | 21 | class GizmoSet: 22 | group: bpy.types.GizmoGroup 23 | 24 | def setup(self, group: bpy.types.GizmoGroup, config: dict): 25 | self.visible = True 26 | self.config = config 27 | self.has_dependent = "has_dependent" in config or False 28 | self.group = group 29 | self.scale = config["scale"] if ("scale" in config) else 14 30 | self.binding = config["binding"] 31 | self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False 32 | self.primary = self.__buildGizmo(config["command"], config["icon"]) 33 | 34 | def draw_prepare(self): 35 | prefs = preferences() 36 | self.hidden = not prefs.show_gizmos 37 | self.skip_draw = False 38 | self.__updatevisible() 39 | 40 | if self.binding["name"] == "float_menu": 41 | self.primary.hide = not prefs.show_float_menu 42 | if self.binding["name"] in ["menu_controller"]: 43 | self.primary.hide = "float" not in prefs.menu_style or not prefs.show_menu 44 | if self.binding["name"] in [ 45 | "menu_controller", 46 | ]: 47 | self.primary.scale_basis = (36 * prefs.menu_spacing) * prefs.gizmo_scale 48 | self.primary.use_grab_cursor = False 49 | self.primary.show_drag = True 50 | else: 51 | self.primary.scale_basis = 18 * prefs.gizmo_scale 52 | 53 | def move(self, position: Vector): 54 | self.primary.matrix_basis = Matrix.Translation(position) 55 | 56 | def __updatevisible(self): 57 | if not preferences().show_menu and self.binding["name"] not in ["float_menu"]: 58 | self.visible = False 59 | self.primary.hide = True 60 | return 61 | if self.binding["location"] == "prefs": 62 | self.visible = getattr(preferences(), "show_" + self.binding["name"]) and self.binding["name"] in preferences().getGizmoSet( 63 | bpy.context.mode 64 | ) 65 | 66 | if self.visible: 67 | self.visible = self.__visibilityLock() and not self.__checkAttributeBind() 68 | self.primary.hide = not self.visible 69 | 70 | def __visibilityLock(self) -> bool: 71 | if preferences().menu_style == "fixed.bar": 72 | return True 73 | return not self.hidden 74 | 75 | # if an attribute being assigned to active_object should hide/show bpy.types.Gizmo 76 | def __checkAttributeBind(self): 77 | if not self.has_attribute_bind: 78 | return False 79 | bind = self.binding["attribute"] 80 | state = self.__findAttribute(bind["path"], bind["value"]) == bind["state"] 81 | return not state 82 | 83 | # search for attribute, value through context. 84 | # will traverse bpy.types.bpy_prop_collection entries 85 | # by next attr to value comparison 86 | def __findAttribute(self, path: str, value: str): 87 | names = path.split(".") 88 | current = bpy.context 89 | for i, prop in enumerate(names): 90 | current = getattr(current, prop) 91 | if current is None: 92 | return False 93 | 94 | if isinstance(current, bpy.types.bpy_prop_collection): 95 | item = "" 96 | for item in current: 97 | if getattr(item, names[i + 1]) == value: 98 | return True 99 | return False 100 | return getattr(current, value) 101 | 102 | # initialize each gizmo, add them to named list with icon name(s) 103 | def __buildGizmo(self, command: str, icon: str) -> bpy.types.Gizmo: 104 | gizmo = self.group.gizmos.new("GIZMO_GT_button_2d") 105 | gizmo.target_set_operator(command) 106 | gizmo.icon = icon # type: ignore 107 | gizmo.use_tooltip = False # show tooltip 108 | gizmo.use_event_handle_all = True # don't pass events e.g. shift+a to add 109 | gizmo.use_grab_cursor = "use_grab_cursor" in self.config 110 | gizmo.show_drag = False # show default cursor 111 | gizmo.line_width = 5.0 112 | gizmo.use_draw_modal = True # show gizmo while dragging 113 | gizmo.draw_options = {"BACKDROP", "OUTLINE"} # type: ignore 114 | self.__setColors(gizmo) 115 | gizmo.scale_basis = 0.1 116 | return gizmo 117 | 118 | def __setColors(self, gizmo: bpy.types.Gizmo): 119 | gizmo.color = gizmo_colors["active"]["color"] 120 | gizmo.color_highlight = gizmo_colors["active"]["color_highlight"] 121 | gizmo.alpha = gizmo_colors["active"]["alpha"] 122 | gizmo.alpha_highlight = gizmo_colors["active"]["alpha_highlight"] 123 | 124 | 125 | class GizmoSetBoolean(GizmoSet): 126 | def setup(self, group: bpy.types.GizmoGroup, config: dict): 127 | self.visible = True 128 | self.config = config 129 | self.has_dependent = "has_dependent" in config or False 130 | self.group = group 131 | self.scale = config["scale"] if ("scale" in config) else 14 132 | self.binding = config["binding"] 133 | self.has_attribute_bind = self.binding["attribute"] if "attribute" in self.binding else False 134 | self.onGizmo = self._GizmoSet__buildGizmo(config["command"], config["onIcon"]) # type: ignore 135 | self.offGizmo = self._GizmoSet__buildGizmo(config["command"], config["offIcon"]) # type: ignore 136 | self.__setActiveGizmo(True) 137 | 138 | def __setActiveGizmo(self, state: bool): 139 | self.onGizmo.hide = True 140 | self.offGizmo.hide = True 141 | self.primary = self.onGizmo if state else self.offGizmo 142 | 143 | def draw_prepare(self): 144 | prefs = preferences() 145 | self.hidden = not prefs.show_gizmos 146 | self.skip_draw = False 147 | self.__updatevisible() 148 | self.primary.scale_basis = 18 * prefs.gizmo_scale 149 | if self.binding["name"] == "float_toggle": 150 | self.__setToggleColors(self.primary) 151 | 152 | def __updatevisible(self): 153 | prefs = preferences() 154 | bind = self.binding 155 | if not preferences().show_menu and (bind["name"] not in ["float_menu"]): 156 | self.visible = False 157 | self.primary.hide = True 158 | return 159 | if bind["name"] == "float_toggle": 160 | self.visible = prefs.input_mode != "FULL" or prefs.enable_floating_toggle 161 | else: 162 | self.visible = getattr(preferences(), "show_" + self.binding["name"]) 163 | 164 | if self.visible: 165 | self.visible = ( 166 | self._GizmoSet__visibilityLock() # type: ignore 167 | and not self._GizmoSet__checkAttributeBind() # type: ignore 168 | ) # type: ignore 169 | 170 | if bind["name"] == "float_toggle": 171 | self.__setActiveGizmo(prefs.is_enabled) 172 | else: 173 | self.__setActiveGizmo(self._GizmoSet__findAttribute(bind["location"], bind["name"])) # type: ignore 174 | self.primary.hide = not self.visible 175 | 176 | def __setToggleColors(self, gizmo: bpy.types.Gizmo): 177 | mode = "active" if preferences().is_enabled else "inactive" 178 | gizmo.color = toggle_colors[mode]["color"] 179 | gizmo.color_highlight = toggle_colors[mode]["color_highlight"] 180 | gizmo.alpha = toggle_colors[mode]["alpha"] 181 | gizmo.alpha_highlight = toggle_colors[mode]["alpha_highlight"] 182 | 183 | 184 | class GizmoSetEnum(GizmoSet): 185 | gizmos: list[bpy.types.Gizmo] 186 | 187 | def setup(self, group: bpy.types.GizmoGroup, config): 188 | pass 189 | -------------------------------------------------------------------------------- /source/utils/gizmo_config.py: -------------------------------------------------------------------------------- 1 | from ..utils.constants import pivot_icon_items 2 | 3 | ### 4 | # Config Standard 5 | # ( TYPE BINDING COMMAND ICON ) 6 | # @TYPE - button type to instance (enum, bool, simple/default) 7 | # @BINDING - used to determine context and visibility 8 | # @COMMAND - operator to call when activated 9 | # @ICON - icon to show on Gizmo 10 | ### 11 | 12 | # Simple 2D Gizmo 13 | controllerConfig = { 14 | "type": "default", 15 | "binding": {"location": "", "name": "menu_controller"}, 16 | "command": "touchview.move_float_menu", 17 | "icon": "BLANK1", 18 | "use_grab_cursor": True, 19 | } 20 | 21 | floatingConfig = { 22 | "type": "default", 23 | "binding": {"location": "prefs", "name": "float_menu"}, 24 | "command": "touchview.move_action_menu", 25 | "icon": "SETTINGS", 26 | "use_grab_cursor": True, 27 | } 28 | 29 | floatingToggleConfig = { 30 | "type": "boolean", 31 | "binding": {"location": "", "name": "float_toggle"}, 32 | "command": "touchview.move_toggle_button", 33 | "onIcon": "OUTLINER_DATA_CAMERA", 34 | "offIcon": "GREASEPENCIL", 35 | "use_grab_cursor": True, 36 | } 37 | 38 | undoConfig = { 39 | "type": "default", 40 | "binding": {"location": "prefs", "name": "undoredo"}, 41 | "has_dependent": True, 42 | "command": "ed.undo", 43 | "icon": "LOOP_BACK", 44 | } 45 | 46 | redoConfig = { 47 | "type": "default", 48 | "binding": {"location": "prefs", "name": "undoredo"}, 49 | "command": "ed.redo", 50 | "icon": "LOOP_FORWARDS", 51 | } 52 | 53 | touchViewConfig = { 54 | "type": "default", 55 | "binding": { 56 | "location": "prefs", 57 | "name": "is_enabled", 58 | }, 59 | "command": "touchview.toggle_touch", 60 | "icon": "VIEW_PAN", 61 | } 62 | 63 | controlGizmoConfig = { 64 | "type": "default", 65 | "binding": { 66 | "location": "prefs", 67 | "name": "control_gizmo", 68 | }, 69 | "command": "touchview.cycle_control_gizmo", 70 | "icon": "ORIENTATION_LOCAL", 71 | } 72 | 73 | snapViewConfig = { 74 | "type": "default", 75 | "binding": {"location": "prefs", "name": "snap_view"}, 76 | "command": "touchview.viewport_recenter", 77 | "icon": "CURSOR", 78 | } 79 | 80 | nPanelConfig = { 81 | "type": "default", 82 | "binding": {"location": "prefs", "name": "n_panel"}, 83 | "command": "touchview.toggle_n_panel", 84 | "icon": "EVENT_N", 85 | } 86 | 87 | voxelSizeConfig = { 88 | "type": "default", 89 | "binding": { 90 | "location": "prefs", 91 | "name": "voxel_remesh", 92 | "attribute": { 93 | "path": "active_object.modifiers.type", 94 | "value": "MULTIRES", 95 | "state": False, 96 | }, 97 | }, 98 | "command": "object.voxel_size_edit", 99 | "icon": "MESH_GRID", 100 | } 101 | 102 | voxelRemeshConfig = { 103 | "type": "default", 104 | "binding": { 105 | "location": "prefs", 106 | "name": "voxel_remesh", 107 | "attribute": { 108 | "path": "active_object.modifiers.type", 109 | "value": "MULTIRES", 110 | "state": False, 111 | }, 112 | }, 113 | "command": "object.voxel_remesh", 114 | "icon": "MOD_UVPROJECT", 115 | } 116 | 117 | voxelStepDownConfig = { 118 | "type": "default", 119 | "binding": { 120 | "location": "prefs", 121 | "name": "voxel_remesh", 122 | "attribute": { 123 | "path": "active_object.modifiers.type", 124 | "value": "MULTIRES", 125 | "state": False, 126 | }, 127 | }, 128 | "command": "touchview.density_down", 129 | "icon": "TRIA_DOWN", 130 | } 131 | 132 | voxelStepUpConfig = { 133 | "type": "default", 134 | "binding": { 135 | "location": "prefs", 136 | "name": "voxel_remesh", 137 | "attribute": { 138 | "path": "active_object.modifiers.type", 139 | "value": "MULTIRES", 140 | "state": False, 141 | }, 142 | }, 143 | "command": "touchview.density_up", 144 | "icon": "TRIA_UP", 145 | } 146 | 147 | subdivConfig = { 148 | "type": "default", 149 | "binding": { 150 | "location": "prefs", 151 | "name": "multires", 152 | "attribute": { 153 | "path": "active_object.modifiers.type", 154 | "value": "MULTIRES", 155 | "state": True, 156 | }, 157 | }, 158 | "has_dependent": True, 159 | "command": "touchview.increment_multires", 160 | "icon": "TRIA_UP", 161 | } 162 | 163 | unsubdivConfig = { 164 | "type": "default", 165 | "binding": { 166 | "location": "prefs", 167 | "name": "multires", 168 | "attribute": { 169 | "path": "active_object.modifiers.type", 170 | "value": "MULTIRES", 171 | "state": True, 172 | }, 173 | }, 174 | "command": "touchview.decrement_multires", 175 | "icon": "TRIA_DOWN", 176 | } 177 | 178 | brushResizeConfig = { 179 | "type": "default", 180 | "binding": {"location": "prefs", "name": "brush_dynamics"}, 181 | "command": "touchview.brush_resize", 182 | "icon": "ANTIALIASED", 183 | } 184 | 185 | brushStrengthConfig = { 186 | "type": "default", 187 | "binding": {"location": "prefs", "name": "brush_dynamics"}, 188 | "command": "touchview.brush_strength", 189 | "icon": "SMOOTHCURVE", 190 | } 191 | 192 | # Boolean 2D Gizmo 193 | fullscreenToggleConfig = { 194 | "type": "boolean", 195 | "binding": { 196 | "location": "screen", 197 | "name": "show_fullscreen", 198 | }, # property location, watch-boolean 199 | "command": "screen.screen_full_area", 200 | "onIcon": "FULLSCREEN_EXIT", # on-state 201 | "offIcon": "FULLSCREEN_ENTER", # off-state 202 | } 203 | 204 | quadviewToggleConfig = { 205 | "type": "boolean", 206 | "binding": {"location": "space_data", "name": "region_quadviews"}, 207 | "command": "screen.region_quadview", 208 | "onIcon": "IMGDISPLAY", 209 | "offIcon": "MESH_PLANE", 210 | } 211 | 212 | rotLocToggleConfig = { 213 | "type": "boolean", 214 | "binding": {"location": "region_data", "name": "lock_rotation"}, 215 | "command": "touchview.viewport_lock", 216 | "onIcon": "LOCKED", 217 | "offIcon": "UNLOCKED", 218 | } 219 | 220 | gizmo_colors = { 221 | "disabled": { 222 | "color": [0.0, 0.0, 0.0], 223 | "color_highlight": [0.0, 0.0, 0.0], 224 | "alpha": 0.3, 225 | "alpha_highlight": 0.3, 226 | }, 227 | "active": { 228 | "color": [0.0, 0.0, 0.0], 229 | "alpha": 0.5, 230 | "color_highlight": [0.5, 0.5, 0.5], 231 | "alpha_highlight": 0.5, 232 | }, 233 | "error": { 234 | "color": [0.3, 0.0, 0.0], 235 | "alpha": 0.15, 236 | "color_highlight": [1.0, 0.2, 0.2], 237 | "alpha_highlight": 0.5, 238 | }, 239 | "warn": { 240 | "color": [0.35, 0.3, 0.14], 241 | "alpha": 0.15, 242 | "color_highlight": [0.8, 0.7, 0.3], 243 | "alpha_highlight": 0.3, 244 | }, 245 | } 246 | 247 | toggle_colors = { 248 | "active": { 249 | "color": [0.1, 0.1, 0.2], 250 | "alpha": 0.5, 251 | "color_highlight": [0.15, 0.15, 0.3], 252 | "alpha_highlight": 0.7, 253 | }, 254 | "inactive": { 255 | "color": [0.0, 0.0, 0.0], 256 | "alpha": 0.5, 257 | "color_highlight": [0.05, 0.05, 0.05], 258 | "alpha_highlight": 0.7, 259 | }, 260 | } 261 | 262 | # Enum 2D Gizmo 263 | # 264 | # not implemented yet 265 | pivotModeConfig = { 266 | "type": "enum", 267 | "binding": {"location": "prefs", "name": "pivot_mode"}, 268 | "command": "", 269 | "icons": pivot_icon_items, 270 | } 271 | -------------------------------------------------------------------------------- /source/utils/keymaps.py: -------------------------------------------------------------------------------- 1 | import bpy 2 | 3 | from .constants import (DCLICK, LMOUSE, PRESS, RMOUSE, flat_modes, 4 | top_level_names) 5 | 6 | default_keymaps = [] 7 | modified_keymaps = [] 8 | 9 | 10 | # added timer to ensure Blender keyconfig is fully populated before running 11 | def register(): 12 | assign_keymaps() 13 | 14 | 15 | # bpy.app.timers.register(assign_keymaps, first_interval=0.2) 16 | 17 | 18 | # two main goals: preserve action from MOUSE to PEN, 19 | # add viewport control to MOUSE 20 | def assign_keymaps(): 21 | wm = bpy.context.window_manager 22 | 23 | # add global default action 24 | km = wm.keyconfigs.addon.keymaps.new(name="3D View", space_type="VIEW_3D") 25 | kmi = km.keymap_items.new("touchview.toggle_touch", type="T", value=PRESS, alt=True) 26 | modified_keymaps.append((km, kmi)) 27 | 28 | # make menus draggable 29 | km = wm.keyconfigs.addon.keymaps.new(name="View2D Buttons List", space_type="EMPTY") 30 | kmi = km.keymap_items.new("view2d.pan", LMOUSE, PRESS) 31 | modified_keymaps.append((km, kmi)) 32 | 33 | # add LEFT MOUSE ACTION for touchview.view_ops 34 | for kmap in wm.keyconfigs["Blender"].keymaps: 35 | km = wm.keyconfigs.addon.keymaps.new(name=kmap.name, space_type=kmap.space_type, region_type=kmap.region_type) 36 | if kmap.name in top_level_names: 37 | if kmap.name in flat_modes: 38 | main_action = "touchview.view_ops_2d" 39 | else: 40 | main_action = "touchview.view_ops_3d" 41 | kmi = km.keymap_items.new(main_action, LMOUSE, PRESS) 42 | modified_keymaps.append((km, kmi)) 43 | 44 | kmi = km.keymap_items.new("touchview.dt_action", LMOUSE, DCLICK) 45 | modified_keymaps.append((km, kmi)) 46 | 47 | kmi = km.keymap_items.new("touchview.rc_action", RMOUSE, PRESS) 48 | modified_keymaps.append((km, kmi)) 49 | 50 | 51 | # unset MOUSE viewport control, reset PEN to MOUSE input 52 | def unregister(): 53 | for km, kmi in modified_keymaps: 54 | km.keymap_items.remove(kmi) 55 | 56 | for kmi, state in default_keymaps: 57 | kmi.active = state 58 | modified_keymaps.clear() 59 | default_keymaps.clear() 60 | -------------------------------------------------------------------------------- /source/utils/overlay.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | import bpy 4 | import gpu 5 | from gpu_extras.batch import batch_for_shader 6 | from mathutils import Vector 7 | 8 | from .blender import preferences 9 | 10 | 11 | class Overlay: 12 | def __init__(self): 13 | 14 | self.meshes = [] 15 | 16 | def clear_overlays(self): 17 | for mesh in self.meshes: 18 | bpy.types.SpaceView3D.draw_handler_remove(mesh, "WINDOW") 19 | self.meshes = [] 20 | 21 | def __getMidpoint(self, view: bpy.types.Region) -> Vector: 22 | return self.__getSize(view, 0.5) 23 | 24 | def __getSize(self, view: bpy.types.Region, scalar: float = 1) -> Vector: 25 | return Vector((view.width * scalar, view.height * scalar)) 26 | 27 | def __getColors(self, type: str): 28 | prefs = preferences() 29 | if not prefs.is_enabled and not prefs.lazy_mode: 30 | return (0.0, 0.0, 0.0, 0.0) 31 | if type == "main" or not prefs.use_multiple_colors: 32 | return prefs.overlay_main_color 33 | elif type == "secondary": 34 | return prefs.overlay_secondary_color 35 | else: 36 | return (0.0, 0.0, 0.0, 0.0) 37 | 38 | def drawUI(self): 39 | _handle = bpy.types.SpaceView3D.draw_handler_add(self.__renderCircle, (), "WINDOW", "POST_PIXEL") 40 | self.meshes.append(_handle) 41 | _handle = bpy.types.SpaceView3D.draw_handler_add(self.__renderRailing, (), "WINDOW", "POST_PIXEL") 42 | self.meshes.append(_handle) 43 | 44 | def __renderRailing(self): 45 | prefs = preferences() 46 | if not prefs.isVisible: 47 | return 48 | 49 | view = bpy.context.area 50 | for region in view.regions: 51 | if bpy.context.region.as_pointer() == region.as_pointer(): 52 | self.__makeBox(region, self.__getColors("main")) 53 | 54 | def __makeBox(self, view: bpy.types.Region, color: tuple[float, float, float, float]): 55 | prefs = preferences() 56 | mid = self.__getMidpoint(view) 57 | dimensions = self.__getSize(view) 58 | left_rail = ( 59 | Vector((0.0, 0.0)), 60 | Vector((mid.x * prefs.getWidth(), dimensions.y)), 61 | ) 62 | right_rail = ( 63 | Vector((dimensions.x, 0.0)), 64 | Vector((dimensions.x - mid.x * prefs.getWidth(), dimensions.y)), 65 | ) 66 | 67 | self.__drawVectorBox(left_rail[0], left_rail[1], color) 68 | self.__drawVectorBox(right_rail[0], right_rail[1], color) 69 | 70 | def __drawVectorBox(self, a, b, color): 71 | vertices = ((a.x, a.y), (b.x, a.y), (a.x, b.y), (b.x, b.y)) 72 | indices = ((0, 1, 2), (2, 3, 1)) 73 | 74 | self.__drawGeometry(vertices, indices, color, "TRIS") 75 | 76 | def __renderCircle(self): 77 | prefs = preferences() 78 | if not prefs.isVisible: 79 | return 80 | 81 | view = bpy.context.area 82 | for region in view.regions: 83 | if bpy.context.region.as_pointer() == region.as_pointer() and not region.data.lock_rotation: 84 | self.__makeCircle(region, self.__getColors("secondary")) 85 | 86 | def __makeCircle(self, view: bpy.types.Region, color: tuple[float, float, float, float]): 87 | prefs = preferences() 88 | mid = self.__getMidpoint(view) 89 | radius = math.dist((0, 0), mid) * (prefs.getRadius() * 0.5) # type: ignore 90 | self.__drawCircle(mid, radius, color) 91 | 92 | def __drawCircle(self, mid: Vector, radius: float, color: tuple): 93 | segments = 100 94 | vertices = [mid] 95 | indices = [] 96 | p = 0 97 | for p in range(segments): 98 | if p > 0: 99 | point = Vector( 100 | ( 101 | mid.x + radius * math.cos(math.radians(360 / segments) * p), 102 | mid.y + radius * math.sin(math.radians(360 / segments) * p), 103 | ) 104 | ) 105 | vertices.append(point) 106 | indices.append((0, p - 1, p)) 107 | indices.append((0, 1, p)) 108 | 109 | self.__drawGeometry(vertices, indices, color, "TRIS") 110 | 111 | def __drawGeometry(self, vertices, indices, color, type): 112 | shader = gpu.shader.from_builtin("UNIFORM_COLOR") 113 | batch = batch_for_shader(shader, type, {"pos": vertices}, indices=indices) 114 | shader.bind() 115 | gpu.state.blend_set("ALPHA") 116 | shader.uniform_float("color", color) 117 | batch.draw(shader) 118 | --------------------------------------------------------------------------------